diff --git a/index.html b/index.html index ac5e434..16515a0 100644 --- a/index.html +++ b/index.html @@ -20,11 +20,11 @@ http-equiv="Content-Security-Policy" content=" default-src 'self'; - script-src 'self' https://cdn.jsdelivr.net; + script-src 'self' https://cdn.jsdelivr.net https://cdn.socket.io; style-src 'self' 'unsafe-inline' https://cdn.jsdelivr.net https://fonts.googleapis.com; font-src 'self' https://cdn.jsdelivr.net https://fonts.gstatic.com data:; img-src 'self' data: https:; - connect-src 'self'; + connect-src 'self' ws: wss: http://localhost:* ws://localhost:* https://cdn.jsdelivr.net; object-src 'none'; base-uri 'self'; frame-ancestors 'none'; @@ -340,19 +340,70 @@

Popular Tags

- + +
+
+
+

Loading live streams...

+
+
+ + + +
+

Popular Tags

+
+ JavaScript + Python + Rust + English + Linux +
+
- - + +
+

Live Chat

+
+
+
+ + +
+
+
+ + + - + + + diff --git a/package-lock.json b/package-lock.json index a8ca2bf..840bd5e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,6 +15,10 @@ "cors": "^2.8.5", "dotenv": "^17.2.3", "express": "^5.2.1", + "jsonwebtoken": "^9.0.3", + "mongoose": "^9.1.5", + "socket.io": "^4.8.3" + "express": "^5.2.1", "express-validator": "^7.3.1", "flv.js": "^1.6.2", "helmet": "^8.1.0", @@ -1442,6 +1446,18 @@ "url": "https://dotenvx.com" } }, + "node_modules/dotenv": { + "version": "17.2.3", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-17.2.3.tgz", + "integrity": "sha512-JVUnt+DUIzu87TABbhPmNfVdBDt18BLOWjMUFJMSi/Qqg7NTYtabbvSNJGOJ7afbRuv9D/lngizHtP7QyLQ+9w==", + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, "node_modules/dunder-proto": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", @@ -1476,6 +1492,15 @@ "safe-buffer": "^5.0.1" } }, + "node_modules/ecdsa-sig-formatter": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz", + "integrity": "sha512-nagl3RYrbNv6kQkeJIpt6NJZy8twLB/2vtz6yN9Z4vRKHN4/QZJIEbqohALSgwKdnksuY3k5Addp5lg8sVoVcQ==", + "license": "Apache-2.0", + "dependencies": { + "safe-buffer": "^5.0.1" + } + }, "node_modules/ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", @@ -1514,6 +1539,78 @@ "node": ">=10.2.0" } }, + "node_modules/engine.io-parser": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/engine.io-parser/-/engine.io-parser-5.2.3.tgz", + "integrity": "sha512-HqD3yTBfnBxIrbnM1DoD6Pcq8NECnh8d4As1Qgh0z5Gg3jRRIqijury0CL3ghu/edArpUYiYqQiDUQBIs4np3Q==", + "license": "MIT", + "engines": { + "node": ">=10.0.0" + } + }, + "node_modules/engine.io/node_modules/accepts": { + "version": "1.3.8", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", + "integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==", + "license": "MIT", + "dependencies": { + "mime-types": "~2.1.34", + "negotiator": "0.6.3" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/engine.io/node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/engine.io/node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "license": "MIT", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/engine.io/node_modules/negotiator": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", + "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/es-define-property": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", + "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==", + "license": "MIT", + "dependencies": { + "@types/cors": "^2.8.12", + "@types/node": ">=10.0.0", + "accepts": "~1.3.4", + "base64id": "2.0.0", + "cookie": "~0.7.2", + "cors": "~2.8.5", + "debug": "~4.4.1", + "engine.io-parser": "~5.2.1", + "ws": "~8.18.3" + }, + "engines": { + "node": ">=10.2.0" + } + }, "node_modules/engine.io-client": { "version": "6.6.4", "resolved": "https://registry.npmjs.org/engine.io-client/-/engine.io-client-6.6.4.tgz", @@ -6136,6 +6233,80 @@ "node": ">=20.19.0" } }, + "node_modules/json-buffer": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.1.tgz", + "integrity": "sha512-4bV5BfR2mqfQTJm+V5tPPdf+ZpuhiIvTuAB5g8kcrXOZpTT/QwwVRWBywX1ozr6lEuPdbHxwaJlm9G6mI2sfSQ==", + "dev": true + }, + "node_modules/json-schema-traverse": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", + "dev": true + }, + "node_modules/json-stable-stringify-without-jsonify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz", + "integrity": "sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==", + "dev": true + }, + "node_modules/jsonwebtoken": { + "version": "9.0.3", + "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-9.0.3.tgz", + "integrity": "sha512-MT/xP0CrubFRNLNKvxJ2BYfy53Zkm++5bX9dtuPbqAeQpTVe0MQTFhao8+Cp//EmJp244xt6Drw/GVEGCUj40g==", + "license": "MIT", + "dependencies": { + "jws": "^4.0.1", + "lodash.includes": "^4.3.0", + "lodash.isboolean": "^3.0.3", + "lodash.isinteger": "^4.0.4", + "lodash.isnumber": "^3.0.3", + "lodash.isplainobject": "^4.0.6", + "lodash.isstring": "^4.0.1", + "lodash.once": "^4.0.0", + "ms": "^2.1.1", + "semver": "^7.5.4" + }, + "engines": { + "node": ">=12", + "npm": ">=6" + } + }, + "node_modules/jwa": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/jwa/-/jwa-2.0.1.tgz", + "integrity": "sha512-hRF04fqJIP8Abbkq5NKGN0Bbr3JxlQ+qhZufXVr0DvujKy93ZCbXZMHDL4EOtodSbCWxOqR8MS1tXA5hwqCXDg==", + "license": "MIT", + "dependencies": { + "buffer-equal-constant-time": "^1.0.1", + "ecdsa-sig-formatter": "1.0.11", + "safe-buffer": "^5.0.1" + } + }, + "node_modules/jws": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/jws/-/jws-4.0.1.tgz", + "integrity": "sha512-EKI/M/yqPncGUUh44xz0PxSidXFr/+r0pA70+gIYhjv+et7yxM+s29Y+VGDkovRofQem0fs7Uvf4+YmAdyRduA==", + "license": "MIT", + "dependencies": { + "jwa": "^2.0.1", + "safe-buffer": "^5.0.1" + } + }, + "node_modules/kareem": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/kareem/-/kareem-3.0.0.tgz", + "integrity": "sha512-RKhaOBSPN8L7y4yAgNhDT2602G5FD6QbOIISbjN9D6mjHPeqeg7K+EB5IGSU5o81/X2Gzm3ICnAvQW3x3OP8HA==", + "license": "Apache-2.0", + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/keyv": { + "version": "4.5.4", + "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz", + "integrity": "sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw==", "node_modules/mongodb-memory-server": { "version": "11.0.1", "dev": true, @@ -6190,6 +6361,58 @@ "url": "https://opencollective.com/mongoose" } }, + "node_modules/lodash.includes": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/lodash.includes/-/lodash.includes-4.3.0.tgz", + "integrity": "sha512-W3Bx6mdkRTGtlJISOvVD/lbqjTlPPUDTMnlXZFnVwi9NKJ6tiAk6LVdlhZMm17VZisqhKcgzpO5Wz91PCt5b0w==", + "license": "MIT" + }, + "node_modules/lodash.isboolean": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/lodash.isboolean/-/lodash.isboolean-3.0.3.tgz", + "integrity": "sha512-Bz5mupy2SVbPHURB98VAcw+aHh4vRV5IPNhILUCsOzRmsTmSQ17jIuqopAentWoehktxGd9e/hbIXq980/1QJg==", + "license": "MIT" + }, + "node_modules/lodash.isinteger": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/lodash.isinteger/-/lodash.isinteger-4.0.4.tgz", + "integrity": "sha512-DBwtEWN2caHQ9/imiNeEA5ys1JoRtRfY3d7V9wkqtbycnAmTvRRmbHKDV4a0EYc678/dia0jrte4tjYwVBaZUA==", + "license": "MIT" + }, + "node_modules/lodash.isnumber": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/lodash.isnumber/-/lodash.isnumber-3.0.3.tgz", + "integrity": "sha512-QYqzpfwO3/CWf3XP+Z+tkQsfaLL/EnUlXWVkIk5FUPc4sBdTehEqZONuyRt2P67PXAk+NXmTBcc97zw9t1FQrw==", + "license": "MIT" + }, + "node_modules/lodash.isplainobject": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz", + "integrity": "sha512-oSXzaWypCMHkPC3NvBEaPHf0KsA5mvPrOPgQWDsbg8n7orZ290M0BmC/jgRZ4vcJ6DTAhjrsSYgdsW/F+MFOBA==", + "license": "MIT" + }, + "node_modules/lodash.isstring": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/lodash.isstring/-/lodash.isstring-4.0.1.tgz", + "integrity": "sha512-0wJxfxH1wgO3GrbuP+dTTk7op+6L41QCXbGINEmD+ny/G/eCqGzxyCsh7159S+mgDDcoarnBw6PC1PS5+wUGgw==", + "license": "MIT" + }, + "node_modules/lodash.merge": { + "version": "4.6.2", + "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", + "integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==", + "dev": true + }, + "node_modules/lodash.once": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz", + "integrity": "sha512-Sb487aTOCr9drQVL8pIxOzVhafOjZN9UU54hiN8PU3uAiSV7lx1yYNpbNmex2PK6dSJoNTSJUUswT651yww3Mg==", + "license": "MIT" + }, + "node_modules/math-intrinsics": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", + "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==", "node_modules/morgan": { "version": "1.10.1", "license": "MIT", @@ -6211,6 +6434,13 @@ "ms": "2.0.0" } }, + "node_modules/memory-pager": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/memory-pager/-/memory-pager-1.5.0.tgz", + "integrity": "sha512-ZS4Bp4r/Zoeq6+NLJpP+0Zzm0pR8whtGPf1XExKLJBAczGMnSi3It14OiNCStjQjM6NU1okjQGSxgEZN8eBYKg==", + "license": "MIT" + }, + "node_modules/merge-descriptors": { "node_modules/morgan/node_modules/ms": { "version": "2.0.0", "license": "MIT" @@ -6247,27 +6477,125 @@ "node": ">=10" } }, - "node_modules/ms": { - "version": "2.1.3", - "license": "MIT" - }, - "node_modules/nanoid": { - "version": "3.3.11", - "dev": true, - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/ai" - } - ], - "license": "MIT", - "bin": { - "nanoid": "bin/nanoid.cjs" + "node_modules/mongodb": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-7.0.0.tgz", + "integrity": "sha512-vG/A5cQrvGGvZm2mTnCSz1LUcbOPl83hfB6bxULKQ8oFZauyox/2xbZOoGNl+64m8VBrETkdGCDBdOsCr3F3jg==", + "license": "Apache-2.0", + "dependencies": { + "@mongodb-js/saslprep": "^1.3.0", + "bson": "^7.0.0", + "mongodb-connection-string-url": "^7.0.0" }, "engines": { - "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" - } - }, + "node": ">=20.19.0" + }, + "peerDependencies": { + "@aws-sdk/credential-providers": "^3.806.0", + "@mongodb-js/zstd": "^7.0.0", + "gcp-metadata": "^7.0.1", + "kerberos": "^7.0.0", + "mongodb-client-encryption": ">=7.0.0 <7.1.0", + "snappy": "^7.3.2", + "socks": "^2.8.6" + }, + "peerDependenciesMeta": { + "@aws-sdk/credential-providers": { + "optional": true + }, + "@mongodb-js/zstd": { + "optional": true + }, + "gcp-metadata": { + "optional": true + }, + "kerberos": { + "optional": true + }, + "mongodb-client-encryption": { + "optional": true + }, + "snappy": { + "optional": true + }, + "socks": { + "optional": true + } + } + }, + "node_modules/mongodb-connection-string-url": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/mongodb-connection-string-url/-/mongodb-connection-string-url-7.0.1.tgz", + "integrity": "sha512-h0AZ9A7IDVwwHyMxmdMXKy+9oNlF0zFoahHiX3vQ8e3KFcSP3VmsmfvtRSuLPxmyv2vjIDxqty8smTgie/SNRQ==", + "license": "Apache-2.0", + "dependencies": { + "@types/whatwg-url": "^13.0.0", + "whatwg-url": "^14.1.0" + }, + "engines": { + "node": ">=20.19.0" + } + }, + "node_modules/mongoose": { + "version": "9.1.5", + "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-9.1.5.tgz", + "integrity": "sha512-N6gypEO+wLmZp8kCYNQmrEWxVMT0KhyHvVttBZoKA/1ngY7aUsBjqHzCPtDgz+i8JAnqMOiEKmuJIDEQu1b9Dw==", + "license": "MIT", + "dependencies": { + "kareem": "3.0.0", + "mongodb": "~7.0", + "mpath": "0.9.0", + "mquery": "6.0.0", + "ms": "2.1.3", + "sift": "17.1.3" + }, + "engines": { + "node": ">=20.19.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/mongoose" + } + }, + "node_modules/mpath": { + "version": "0.9.0", + "resolved": "https://registry.npmjs.org/mpath/-/mpath-0.9.0.tgz", + "integrity": "sha512-ikJRQTk8hw5DEoFVxHG1Gn9T/xcjtdnOKIU1JTmGjZZlg9LST2mBLmcX3/ICIbgJydT2GOc15RnNy5mHmzfSew==", + "license": "MIT", + "engines": { + "node": ">=4.0.0" + } + }, + "node_modules/mquery": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/mquery/-/mquery-6.0.0.tgz", + "integrity": "sha512-b2KQNsmgtkscfeDgkYMcWGn9vZI9YoXh802VDEwE6qc50zxBFQ0Oo8ROkawbPAsXCY1/Z1yp0MagqsZStPWJjw==", + "license": "MIT", + "engines": { + "node": ">=20.19.0" + } + }, + "node_modules/ms": { + "version": "2.1.3", + "license": "MIT" + }, + "node_modules/nanoid": { + "version": "3.3.11", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "bin": { + "nanoid": "bin/nanoid.cjs" + }, + "engines": { + "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" + } + }, "node_modules/natural-compare": { "version": "1.4.0", "dev": true, @@ -6280,6 +6608,10 @@ "node": ">= 0.6" } }, + "node_modules/node-addon-api": { + "version": "8.5.0", + "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-8.5.0.tgz", + "integrity": "sha512-/bRZty2mXUIFY/xU5HLvveNHlswNJej+RnxBjOMkidWfwZzgTbPG1E3K5TOxRLOR+5hX7bSofy8yf1hZevMS8A==", "node_modules/new-find-package-json": { "version": "2.0.0", "dev": true, @@ -6298,6 +6630,10 @@ "node": "^18 || ^20 || >= 21" } }, + "node_modules/node-gyp-build": { + "version": "4.8.4", + "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.8.4.tgz", + "integrity": "sha512-LA4ZjwlnUblHVgq0oBF3Jl/6h/Nvs5fzBLwdEF4nuxnFdsfajde4WfxtJr3CaiH+F6ewcIB/q4jQ4UzPyid+CQ==", "node_modules/punycode": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", @@ -6489,6 +6825,72 @@ } ], "dependencies": { + "nanoid": "^3.3.11", + "picocolors": "^1.1.1", + "source-map-js": "^1.2.1" + }, + "engines": { + "node": "^10 || ^12 || >=14" + } + }, + "node_modules/prelude-ls": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", + "integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==", + "dev": true, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/prettier": { + "version": "3.7.4", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.7.4.tgz", + "integrity": "sha512-v6UNi1+3hSlVvv8fSaoUbggEM5VErKmmpGA7Pl3HF8V6uKY7rvClBOJlH6yNwQtfTueNkGVpOv/mtWL9L4bgRA==", + "dev": true, + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, + "node_modules/proxy-addr": { + "version": "2.0.7", + "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", + "integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==", + "license": "MIT", + "dependencies": { + "forwarded": "0.2.0", + "ipaddr.js": "1.9.1" + }, + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/punycode": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", + "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==", + "engines": { + "node": ">=6" + } + }, + "node_modules/qs": { + "version": "6.14.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.14.0.tgz", + "integrity": "sha512-YWWTjgABSKcvs/nWBi9PycY/JiPJqOD4JA6o9Sej2AtvSGarXxKC3OQSk4pAarbdQlKAh5D4FCQkJNkW+GAn3w==", + "license": "BSD-3-Clause", + "dependencies": { + "side-channel": "^1.1.0" + }, + "engines": { + "node": ">=0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" "queue-microtask": "^1.2.2" } }, @@ -6634,6 +7036,48 @@ "node": ">=8" } }, + "node_modules/safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT" + }, + "node_modules/safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", + "license": "MIT" + }, + "node_modules/semver": { + "version": "7.7.3", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.3.tgz", + "integrity": "sha512-SdsKMrI9TdgjdweUSR9MweHA4EJ8YxHn8DFaDisvhVlUOe4BF1tLD7GAj0lIqWVl+dPb/rExr0Btby5loQm20Q==", + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/send": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/send/-/send-1.2.1.tgz", + "integrity": "sha512-1gnZf7DFcoIcajTjTwjwuDjzuz4PPcY2StKPlsGAQ1+YH20IRVrBaXSWmdjowTJ6u8Rc01PoYOGHXfP1mYcZNQ==", "node_modules/path-is-absolute": { "version": "1.0.1", "dev": true, @@ -6746,19 +7190,113 @@ } } }, - "node_modules/socket.io-client": { - "version": "4.8.3", - "resolved": "https://registry.npmjs.org/socket.io-client/-/socket.io-client-4.8.3.tgz", - "integrity": "sha512-uP0bpjWrjQmUt5DTHq9RuoCBdFJF10cdX9X+a368j/Ft0wmaVgxlrjvK3kjvgCODOMMOz9lcaRzxmso0bTWZ/g==", + "node_modules/socket.io-client": { + "version": "4.8.3", + "resolved": "https://registry.npmjs.org/socket.io-client/-/socket.io-client-4.8.3.tgz", + "integrity": "sha512-uP0bpjWrjQmUt5DTHq9RuoCBdFJF10cdX9X+a368j/Ft0wmaVgxlrjvK3kjvgCODOMMOz9lcaRzxmso0bTWZ/g==", + "license": "MIT", + "dependencies": { + "@socket.io/component-emitter": "~3.1.0", + "debug": "~4.4.1", + "engine.io-client": "~6.6.1", + "socket.io-parser": "~4.2.4" + }, + "engines": { + "node": ">=10.0.0" + } + }, + "node_modules/socket.io-parser": { + "version": "4.2.5", + "resolved": "https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-4.2.5.tgz", + "integrity": "sha512-bPMmpy/5WWKHea5Y/jYAP6k74A+hvmRCQaJuJB6I/ML5JZq/KfNieUVo/3Mh7SAqn7TyFdIo6wqYHInG1MU1bQ==", + "license": "MIT", + "dependencies": { + "@socket.io/component-emitter": "~3.1.0", + "debug": "~4.4.1" + }, + "engines": { + "node": ">=10.0.0" + } + }, + "node_modules/socket.io/node_modules/accepts": { + "version": "1.3.8", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", + "integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==", + "license": "MIT", + "dependencies": { + "mime-types": "~2.1.34", + "negotiator": "0.6.3" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/socket.io/node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/socket.io/node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "license": "MIT", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/socket.io/node_modules/negotiator": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", + "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, + "node_modules/sift": { + "version": "17.1.3", + "resolved": "https://registry.npmjs.org/sift/-/sift-17.1.3.tgz", + "integrity": "sha512-Rtlj66/b0ICeFzYTuNvX/EF1igRbbnGSvEyT79McoZa/DeGhMyC5pWKOEsZKnpkqtSeovd5FL/bjHWC3CIIvCQ==", + "license": "MIT" + }, + "node_modules/socket.io": { + "version": "4.8.3", + "resolved": "https://registry.npmjs.org/socket.io/-/socket.io-4.8.3.tgz", + "integrity": "sha512-2Dd78bqzzjE6KPkD5fHZmDAKRNe3J15q+YHDrIsy9WEkqttc7GY+kT9OBLSMaPbQaEd0x1BjcmtMtXkfpc+T5A==", + "license": "MIT", + "dependencies": { + "accepts": "~1.3.4", + "base64id": "~2.0.0", + "cors": "~2.8.5", + "debug": "~4.4.1", + "engine.io": "~6.6.0", + "socket.io-adapter": "~2.5.2", + "socket.io-parser": "~4.2.4" + }, + "engines": { + "node": ">=10.2.0" + } + }, + "node_modules/socket.io-adapter": { + "version": "2.5.6", + "resolved": "https://registry.npmjs.org/socket.io-adapter/-/socket.io-adapter-2.5.6.tgz", + "integrity": "sha512-DkkO/dz7MGln0dHn5bmN3pPy+JmywNICWrJqVWiVOyvXjWQFIv9c2h24JrQLLFJ2aQVQf/Cvl1vblnd4r2apLQ==", "license": "MIT", "dependencies": { - "@socket.io/component-emitter": "~3.1.0", "debug": "~4.4.1", - "engine.io-client": "~6.6.1", - "socket.io-parser": "~4.2.4" - }, - "engines": { - "node": ">=10.0.0" + "ws": "~8.18.3" } }, "node_modules/socket.io-parser": { @@ -6815,18 +7353,8 @@ "license": "MIT", "engines": { "node": ">= 0.6" - "node": ">=12" - }, - "funding": { - "url": "https://github.com/sponsors/jonschlinkert" } }, - "node_modules/sift": { - "version": "17.1.3", - "resolved": "https://registry.npmjs.org/sift/-/sift-17.1.3.tgz", - "integrity": "sha512-Rtlj66/b0ICeFzYTuNvX/EF1igRbbnGSvEyT79McoZa/DeGhMyC5pWKOEsZKnpkqtSeovd5FL/bjHWC3CIIvCQ==", - "license": "MIT" - }, "node_modules/source-map-js": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.1.tgz", @@ -6860,6 +7388,15 @@ "memory-pager": "^1.0.2" } }, + "node_modules/sparse-bitfield": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/sparse-bitfield/-/sparse-bitfield-3.0.3.tgz", + "integrity": "sha512-kvzhi7vqKTfkh0PZU+2D2PIllw2ymqJKujUcyPMd9Y75Nv4nPbGJZXNhxsgdQab2BmlDct1YnfQCguEvHr7VsQ==", + "license": "MIT", + "dependencies": { + "memory-pager": "^1.0.2" + } + }, "node_modules/statuses": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz", @@ -6973,6 +7510,18 @@ "node": ">=18" } }, + "node_modules/tr46": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-5.1.1.tgz", + "integrity": "sha512-hdF5ZgjTqgAntKkklYw0R03MG2x/bSzTtkxmIRw/sTNV8YXsCJ1tfLAX23lhxhHJlEf3CRCOCGGWw3vI3GaSPw==", + "license": "MIT", + "dependencies": { + "punycode": "^2.3.1" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/type-check": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", @@ -7005,6 +7554,12 @@ "integrity": "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw==", "license": "MIT" }, + "node_modules/undici-types": { + "version": "7.16.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.16.0.tgz", + "integrity": "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw==", + "license": "MIT" + }, "node_modules/unpipe": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", @@ -7148,6 +7703,28 @@ "node": ">=18" } }, + "node_modules/webidl-conversions": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz", + "integrity": "sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==", + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + } + }, + "node_modules/whatwg-url": { + "version": "14.2.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-14.2.0.tgz", + "integrity": "sha512-De72GdQZzNTUBBChsXueQUnPKDkg/5A5zp7pFDuQAj5UFoENpiACU0wlCvzpAGnTkj++ihpKwKyYewn/XNUbKw==", + "license": "MIT", + "dependencies": { + "tr46": "^5.1.0", + "webidl-conversions": "^7.0.0" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", @@ -7185,6 +7762,9 @@ "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==" }, "node_modules/ws": { + "version": "8.18.3", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.18.3.tgz", + "integrity": "sha512-PEIGCY5tSlUt50cqyMXfCzX+oOPqN0vuGqWzbcJ2xvnkzkq46oOpz7dQaTDBdfICb4N14+GARUDw2XV2N4tvzg==", "version": "8.19.0", "resolved": "https://registry.npmjs.org/ws/-/ws-8.19.0.tgz", "integrity": "sha512-blAT2mjOEIi0ZzruJfIhb3nps74PRWTCz1IjglWEEpQl5XS/UNama6u2/rjFkDDouqr4L67ry+1aGIALViWjDg==", @@ -7831,6 +8411,19 @@ "@types/node": "*" } }, + "@socket.io/component-emitter": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/@socket.io/component-emitter/-/component-emitter-3.1.2.tgz", + "integrity": "sha512-9BCxFwvbGg/RsZK9tjXd8s4UcwR0MWeFQ1XEKIQVVvAGJyINdrqKMcTRyLoK8Rse1GjzLV9cwjWV1olXRWEXVA==" + }, + "@types/cors": { + "version": "2.8.19", + "resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.19.tgz", + "integrity": "sha512-mFNylyeyqN93lfe/9CSxOGREz8cpzAhH+E93xJ4xWQf62V8sQ/24reV2nyzUWM6H6Xji+GGHpkbLe7pVoUEskg==", + "requires": { + "@types/node": "*" + } + }, "@types/estree": { "node_modules/string.prototype.trimstart": { "version": "1.0.8", @@ -8308,6 +8901,56 @@ "resolved": "https://registry.npmjs.org/engine.io-parser/-/engine.io-parser-5.2.3.tgz", "integrity": "sha512-HqD3yTBfnBxIrbnM1DoD6Pcq8NECnh8d4As1Qgh0z5Gg3jRRIqijury0CL3ghu/edArpUYiYqQiDUQBIs4np3Q==" }, + "engine.io": { + "version": "6.6.5", + "resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.6.5.tgz", + "integrity": "sha512-2RZdgEbXmp5+dVbRm0P7HQUImZpICccJy7rN7Tv+SFa55pH+lxnuw6/K1ZxxBfHoYpSkHLAO92oa8O4SwFXA2A==", + "requires": { + "@types/cors": "^2.8.12", + "@types/node": ">=10.0.0", + "accepts": "~1.3.4", + "base64id": "2.0.0", + "cookie": "~0.7.2", + "cors": "~2.8.5", + "debug": "~4.4.1", + "engine.io-parser": "~5.2.1", + "ws": "~8.18.3" + }, + "dependencies": { + "accepts": { + "version": "1.3.8", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", + "integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==", + "requires": { + "mime-types": "~2.1.34", + "negotiator": "0.6.3" + } + }, + "mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==" + }, + "mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "requires": { + "mime-db": "1.52.0" + } + }, + "negotiator": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", + "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==" + } + } + }, + "engine.io-parser": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/engine.io-parser/-/engine.io-parser-5.2.3.tgz", + "integrity": "sha512-HqD3yTBfnBxIrbnM1DoD6Pcq8NECnh8d4As1Qgh0z5Gg3jRRIqijury0CL3ghu/edArpUYiYqQiDUQBIs4np3Q==" + }, "es-define-property": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", @@ -10243,6 +10886,38 @@ "sift": "17.1.3" } }, + "mongodb": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-7.0.0.tgz", + "integrity": "sha512-vG/A5cQrvGGvZm2mTnCSz1LUcbOPl83hfB6bxULKQ8oFZauyox/2xbZOoGNl+64m8VBrETkdGCDBdOsCr3F3jg==", + "requires": { + "@mongodb-js/saslprep": "^1.3.0", + "bson": "^7.0.0", + "mongodb-connection-string-url": "^7.0.0" + } + }, + "mongodb-connection-string-url": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/mongodb-connection-string-url/-/mongodb-connection-string-url-7.0.1.tgz", + "integrity": "sha512-h0AZ9A7IDVwwHyMxmdMXKy+9oNlF0zFoahHiX3vQ8e3KFcSP3VmsmfvtRSuLPxmyv2vjIDxqty8smTgie/SNRQ==", + "requires": { + "@types/whatwg-url": "^13.0.0", + "whatwg-url": "^14.1.0" + } + }, + "mongoose": { + "version": "9.1.5", + "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-9.1.5.tgz", + "integrity": "sha512-N6gypEO+wLmZp8kCYNQmrEWxVMT0KhyHvVttBZoKA/1ngY7aUsBjqHzCPtDgz+i8JAnqMOiEKmuJIDEQu1b9Dw==", + "requires": { + "kareem": "3.0.0", + "mongodb": "~7.0", + "mpath": "0.9.0", + "mquery": "6.0.0", + "ms": "2.1.3", + "sift": "17.1.3" + } + }, "mpath": { "version": "0.9.0", "resolved": "https://registry.npmjs.org/mpath/-/mpath-0.9.0.tgz", @@ -11027,6 +11702,72 @@ "debug": "~4.4.1" } }, + "sift": { + "version": "17.1.3", + "resolved": "https://registry.npmjs.org/sift/-/sift-17.1.3.tgz", + "integrity": "sha512-Rtlj66/b0ICeFzYTuNvX/EF1igRbbnGSvEyT79McoZa/DeGhMyC5pWKOEsZKnpkqtSeovd5FL/bjHWC3CIIvCQ==" + }, + "socket.io": { + "version": "4.8.3", + "resolved": "https://registry.npmjs.org/socket.io/-/socket.io-4.8.3.tgz", + "integrity": "sha512-2Dd78bqzzjE6KPkD5fHZmDAKRNe3J15q+YHDrIsy9WEkqttc7GY+kT9OBLSMaPbQaEd0x1BjcmtMtXkfpc+T5A==", + "requires": { + "accepts": "~1.3.4", + "base64id": "~2.0.0", + "cors": "~2.8.5", + "debug": "~4.4.1", + "engine.io": "~6.6.0", + "socket.io-adapter": "~2.5.2", + "socket.io-parser": "~4.2.4" + }, + "dependencies": { + "accepts": { + "version": "1.3.8", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", + "integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==", + "requires": { + "mime-types": "~2.1.34", + "negotiator": "0.6.3" + } + }, + "mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==" + }, + "mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "requires": { + "mime-db": "1.52.0" + } + }, + "negotiator": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", + "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==" + } + } + }, + "socket.io-adapter": { + "version": "2.5.6", + "resolved": "https://registry.npmjs.org/socket.io-adapter/-/socket.io-adapter-2.5.6.tgz", + "integrity": "sha512-DkkO/dz7MGln0dHn5bmN3pPy+JmywNICWrJqVWiVOyvXjWQFIv9c2h24JrQLLFJ2aQVQf/Cvl1vblnd4r2apLQ==", + "requires": { + "debug": "~4.4.1", + "ws": "~8.18.3" + } + }, + "socket.io-parser": { + "version": "4.2.5", + "resolved": "https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-4.2.5.tgz", + "integrity": "sha512-bPMmpy/5WWKHea5Y/jYAP6k74A+hvmRCQaJuJB6I/ML5JZq/KfNieUVo/3Mh7SAqn7TyFdIo6wqYHInG1MU1bQ==", + "requires": { + "@socket.io/component-emitter": "~3.1.0", + "debug": "~4.4.1" + } + }, "source-map-js": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.1.tgz", @@ -11223,6 +11964,20 @@ "webidl-conversions": "^7.0.0" } }, + "webidl-conversions": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz", + "integrity": "sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==" + }, + "whatwg-url": { + "version": "14.2.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-14.2.0.tgz", + "integrity": "sha512-De72GdQZzNTUBBChsXueQUnPKDkg/5A5zp7pFDuQAj5UFoENpiACU0wlCvzpAGnTkj++ihpKwKyYewn/XNUbKw==", + "requires": { + "tr46": "^5.1.0", + "webidl-conversions": "^7.0.0" + } + }, "which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", @@ -11251,6 +12006,11 @@ "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==" }, "ws": { + "version": "8.18.3", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.18.3.tgz", + "integrity": "sha512-PEIGCY5tSlUt50cqyMXfCzX+oOPqN0vuGqWzbcJ2xvnkzkq46oOpz7dQaTDBdfICb4N14+GARUDw2XV2N4tvzg==", + "requires": {} + }, "version": "8.19.0", "resolved": "https://registry.npmjs.org/ws/-/ws-8.19.0.tgz", "integrity": "sha512-blAT2mjOEIi0ZzruJfIhb3nps74PRWTCz1IjglWEEpQl5XS/UNama6u2/rjFkDDouqr4L67ry+1aGIALViWjDg==", diff --git a/package.json b/package.json index 9473069..7d8af02 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "A live streaming platform for developers.", "main": "src/js/main.js", "scripts": { - "dev": "vite", + "dev": "vite --host", "build": "vite build", "preview": "vite preview", "lint": "eslint \"**/*.{js,jsx,mjs,cjs}\"", @@ -34,6 +34,9 @@ "bootstrap": "^5.3.3", "cors": "^2.8.5", "dotenv": "^17.2.3", + "jsonwebtoken": "^9.0.3", + "mongoose": "^9.1.5", + "socket.io": "^4.8.3" "express": "^5.2.1", "express-validator": "^7.3.1", "flv.js": "^1.6.2", diff --git a/public/service-worker.js b/public/service-worker.js index df820c4..c586add 100644 --- a/public/service-worker.js +++ b/public/service-worker.js @@ -1,51 +1,55 @@ // service-worker.js +const CACHE_NAME = 'devstream-v1'; const CACHE_NAME = "devstream-v2"; // List of resources to cache const CACHE_RESOURCES = [ - "/", - "/index.html", - "/src/css/style.css", - "/src/js/main.js", - "/manifest.json", - "/src/assets/images/preview-placeholder.jpg", - "/src/assets/icons/icon-192x192.png", - "/src/assets/icons/icon-512x512.png", - "/src/assets/icons/maskable-icon-192x192.png", - "/src/assets/icons/maskable-icon-512x512.png", - "https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css", - "https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css", - "https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js", - "https://fonts.googleapis.com/css2?family=Roboto:wght@400&display=swap", - "https://fonts.gstatic.com/s/roboto/v27/KFOmCnqEu92Fr1Mu4mxK.woff2" + '/', + '/index.html', + '/src/css/style.css', + '/src/js/main.js', + '/manifest.json', + '/src/assets/images/preview-placeholder.jpg', + '/src/assets/icons/icon-192x192.png', + '/src/assets/icons/icon-512x512.png', + '/src/assets/icons/maskable-icon-192x192.png', + '/src/assets/icons/maskable-icon-512x512.png', + 'https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css', + 'https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css', + 'https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js', + 'https://fonts.googleapis.com/css2?family=Roboto:wght@400&display=swap', + 'https://fonts.gstatic.com/s/roboto/v27/KFOmCnqEu92Fr1Mu4mxK.woff2', ]; // Install event handler -self.addEventListener("install", (event) => { - event.waitUntil( - caches.open(CACHE_NAME).then((cache) => { - console.log("Installing service worker..."); - return cache.addAll(CACHE_RESOURCES); - }).catch(error => { - console.error("Error during cache installation:", error); - }) - ); +self.addEventListener('install', (event) => { + event.waitUntil( + caches + .open(CACHE_NAME) + .then((cache) => { + console.log('Installing service worker...'); + return cache.addAll(CACHE_RESOURCES); + }) + .catch((error) => { + console.error('Error during cache installation:', error); + }) + ); }); // Activate event handler -self.addEventListener("activate", (event) => { - event.waitUntil( - caches.keys().then((cacheNames) => { - return Promise.all( - cacheNames.map((cacheName) => { - if (cacheName !== CACHE_NAME) { - console.log("Removing outdated cache:", cacheName); - return caches.delete(cacheName); - } - }) - ); +self.addEventListener('activate', (event) => { + event.waitUntil( + caches.keys().then((cacheNames) => { + return Promise.all( + cacheNames.map((cacheName) => { + if (cacheName !== CACHE_NAME) { + console.log('Removing outdated cache:', cacheName); + return caches.delete(cacheName); + } }) - ); + ); + }) + ); }); // Fetch event handler with cache-first strategy @@ -87,44 +91,40 @@ self.addEventListener("fetch", (event) => { }); // Message event handler for debugging -self.addEventListener("message", (event) => { - if (event.data === "skipWaiting") { - self.skipWaiting(); - } +self.addEventListener('message', (event) => { + if (event.data === 'skipWaiting') { + self.skipWaiting(); + } }); // Push notification handler -self.addEventListener("push", (event) => { - let data = {}; +self.addEventListener('push', (event) => { + let data = {}; - if (event.data) { - try { - data = event.data.json(); - } catch (e) { - data = { body: event.data.text() }; - } + if (event.data) { + try { + data = event.data.json(); + } catch (e) { + data = { body: event.data.text() }; } + } - const title = data.title || "DevStreamer is Live!"; - const options = { - body: data.body || "Your favorite DevStreamer just went live.", - icon: "/favicon.ico", - badge: "/favicon.ico", - data: { - url: data.url || "/" - } - }; + const title = data.title || 'DevStreamer is Live!'; + const options = { + body: data.body || 'Your favorite DevStreamer just went live.', + icon: '/favicon.ico', + badge: '/favicon.ico', + data: { + url: data.url || '/', + }, + }; - event.waitUntil( - self.registration.showNotification(title, options) - ); + event.waitUntil(self.registration.showNotification(title, options)); }); // Notification click handler -self.addEventListener("notificationclick", (event) => { - event.notification.close(); +self.addEventListener('notificationclick', (event) => { + event.notification.close(); - event.waitUntil( - clients.openWindow(event.notification.data.url) - ); + event.waitUntil(clients.openWindow(event.notification.data.url)); }); diff --git a/server.js b/server.js index 0c2965d..75523a4 100644 --- a/server.js +++ b/server.js @@ -6,6 +6,9 @@ import mongoose from 'mongoose'; import fs from 'fs'; import { fileURLToPath } from 'url'; import { dirname, join } from 'path'; +import { createServer } from 'http'; +import { Server } from 'socket.io'; +import jwt from 'jsonwebtoken'; import * as AuthControllers from './src/controllers/AuthControllers.js'; import { auth, authorizeRole } from './src/middleware/auth.js'; import { @@ -17,9 +20,25 @@ import { createServer } from 'http'; import { Server } from 'socket.io'; const app = express(); +const httpServer = createServer(app); +const io = new Server(httpServer, { + cors: { + origin: [ + 'http://localhost:3000', + 'http://localhost:5173', + 'http://127.0.0.1:5173', + ], + methods: ['GET', 'POST'], + credentials: true, + allowedHeaders: ['Authorization'], + }, + transports: ['websocket', 'polling'], + allowEIO3: true, +}); app.use(morgan('dev')); const PORT = process.env.PORT || 3000; const MONGODB_URI = process.env.MONGODB_URI; +const JWT_SECRET = process.env.JWT_SECRET; // Create HTTP server and attach Socket.IO const httpServer = createServer(app); @@ -169,6 +188,272 @@ app.get('/health', (req,res)=>{ }); }); +// ================= SOCKET.IO CHAT ================= + +// Store connected users with their roles +const connectedUsers = new Map(); + +// Store chat message history (in-memory, max 100 messages) +const chatHistory = []; +const MAX_HISTORY = 100; + +// Role hierarchy for permissions (higher number = more permissions) +const roleHierarchy = { + user: 1, + vip: 2, + moderator: 3, + broadcaster: 4, + administrator: 5, + admin: 5, + bot: 6, +}; + +// Helper function to verify socket token +const verifySocketToken = (token) => { + try { + return jwt.verify(token, JWT_SECRET); + } catch (err) { + return null; + } +}; + +// Helper function to check if user has permission +const hasPermission = (userRole, requiredRole) => { + return (roleHierarchy[userRole] || 0) >= (roleHierarchy[requiredRole] || 0); +}; + +io.use((socket, next) => { + const token = socket.handshake.auth.token; + const persistentUserId = socket.handshake.auth.persistentUserId; + + if (!token) { + // Use persistent user ID if provided, otherwise generate guest ID + const username = persistentUserId || `Guest_${socket.id.substring(0, 6)}`; + socket.user = { + id: persistentUserId || socket.id, + username: username, + role: 'user', + persistentId: persistentUserId, + }; + return next(); + } + + const decoded = verifySocketToken(token); + if (decoded) { + // If authenticated, use token data but preserve persistent ID for message matching + socket.user = { + ...decoded, + persistentId: persistentUserId || decoded.id, + }; + next(); + } else { + // Allow connection but with limited user role, use persistent ID + const username = persistentUserId || `Guest_${socket.id.substring(0, 6)}`; + socket.user = { + id: persistentUserId || socket.id, + username: username, + role: 'user', + persistentId: persistentUserId, + }; + next(); + } +}); + +io.on('connection', (socket) => { + const user = socket.user; + // Use persistent ID if available, otherwise use socket ID + const userId = user.persistentId || user.id || socket.id; + const username = user.username || `Guest_${socket.id.substring(0, 6)}`; + const role = user.role || 'user'; + + // Store user info with persistent ID + connectedUsers.set(socket.id, { + id: userId, + persistentId: user.persistentId || userId, + username, + role, + socketId: socket.id, + }); + + // Send user info to client so they can identify their own messages + socket.emit('userInfo', { + username, + role, + id: userId, + persistentId: user.persistentId || userId, + }); + + // Send chat history to newly connected user + if (chatHistory.length > 0) { + socket.emit('chatHistory', chatHistory); + } + + console.log( + `šŸ‘¤ User connected: ${username} (${role}) [ID: ${userId}] [Socket: ${socket.id}]` + ); + + // Broadcast user joined (only for non-bot users) + if (role !== 'bot') { + const joinMessage = { + id: Date.now(), + username: 'System', + message: `${username} joined the chat`, + role: 'bot', + timestamp: new Date().toISOString(), + type: 'system', + }; + + // Add system messages to history (but don't count toward MAX_HISTORY limit) + chatHistory.push(joinMessage); + if (chatHistory.length > MAX_HISTORY * 2) { + // Only trim if it gets really large + chatHistory.splice(0, chatHistory.length - MAX_HISTORY); + } + + io.emit('chatMessage', joinMessage); + } + + // Handle chat messages + socket.on('chatMessage', (data) => { + const userInfo = connectedUsers.get(socket.id); + if (!userInfo) return; + + const { message } = data; + + // Validate message + if ( + !message || + typeof message !== 'string' || + message.trim().length === 0 + ) { + socket.emit('error', { message: 'Message cannot be empty' }); + return; + } + + if (message.length > 500) { + socket.emit('error', { + message: 'Message is too long (max 500 characters)', + }); + return; + } + + // Create message object with persistent ID for client matching + const chatMessage = { + id: Date.now(), + username: userInfo.username, + message: message.trim(), + role: userInfo.role, + timestamp: new Date().toISOString(), + type: 'user', + userId: userInfo.id, + persistentId: userInfo.persistentId || userInfo.id, + }; + + // Add to chat history + chatHistory.push(chatMessage); + + // Keep only the last MAX_HISTORY messages + if (chatHistory.length > MAX_HISTORY) { + chatHistory.shift(); // Remove oldest message + } + + // Broadcast message to all clients + io.emit('chatMessage', chatMessage); + console.log(`šŸ’¬ [${userInfo.role}] ${userInfo.username}: ${message}`); + }); + + // Moderator/Broadcaster/Admin actions + socket.on('modAction', (data) => { + const userInfo = connectedUsers.get(socket.id); + if (!userInfo) return; + + const { action, targetUsername, reason } = data; + + // Check if user has moderator permissions + if (!hasPermission(userInfo.role, 'moderator')) { + socket.emit('error', { + message: 'Insufficient permissions for this action', + }); + return; + } + + switch (action) { + case 'timeout': + // Find target user and timeout them + const targetSocket = Array.from(connectedUsers.values()).find( + (u) => u.username === targetUsername + )?.socketId; + + if (targetSocket) { + io.to(targetSocket).emit('timeout', { + duration: data.duration || 60, + reason, + }); + io.emit('chatMessage', { + id: Date.now(), + username: 'System', + message: `${targetUsername} has been timed out${reason ? `: ${reason}` : ''}`, + role: 'bot', + timestamp: new Date().toISOString(), + type: 'system', + }); + } + break; + + case 'ban': + const banTarget = Array.from(connectedUsers.values()).find( + (u) => u.username === targetUsername + )?.socketId; + + if (banTarget) { + io.to(banTarget).emit('banned', { reason }); + io.to(banTarget).disconnectSockets(); + io.emit('chatMessage', { + id: Date.now(), + username: 'System', + message: `${targetUsername} has been banned${reason ? `: ${reason}` : ''}`, + role: 'bot', + timestamp: new Date().toISOString(), + type: 'system', + }); + } + break; + + case 'delete': + // Delete a message by ID (broadcast to all) + io.emit('deleteMessage', { messageId: data.messageId }); + break; + } + }); + + // Handle disconnection + socket.on('disconnect', () => { + const userInfo = connectedUsers.get(socket.id); + if (userInfo && userInfo.role !== 'bot') { + const leaveMessage = { + id: Date.now(), + username: 'System', + message: `${userInfo.username} left the chat`, + role: 'bot', + timestamp: new Date().toISOString(), + type: 'system', + }; + + // Add to history + chatHistory.push(leaveMessage); + if (chatHistory.length > MAX_HISTORY * 2) { + chatHistory.splice(0, chatHistory.length - MAX_HISTORY); + } + + io.emit('chatMessage', leaveMessage); + } + connectedUsers.delete(socket.id); + console.log(`šŸ‘‹ User disconnected: ${socket.id}`); + }); +}); + +// ================= SERVER START ================= + // 404 Not Found handler (must be after all routes) app.use((req, res) => { res.status(404).json({ @@ -274,5 +559,7 @@ app.listen(PORT, () => { console.log(`Home: http://localhost:${PORT}`); console.log('\nāœ… Server successfully started!'); console.log(`šŸ  Home: http://localhost:${PORT}`); + console.log(`šŸ’¬ Socket.IO server running on port ${PORT}`); +}); console.log(`šŸ“” WebRTC Signaling: ws://localhost:${PORT}`); -}); \ No newline at end of file +}); diff --git a/src/css/style.css b/src/css/style.css index 6a69f3d..1f1a3fd 100644 --- a/src/css/style.css +++ b/src/css/style.css @@ -348,6 +348,276 @@ body.dark .badge { } /* ================================ + Chat Container Styles + ================================ */ + +/* Default: Light theme */ +.chat-container { + background-color: #fff; + color: #111; + border: 1px solid #dee2e6; + border-radius: 0.375rem; +} + +/* Chat messages area - light background by default */ +#chatMessages { + background-color: #fff; + color: #111; + border-bottom: 1px solid #dee2e6; + min-height: 300px; + max-height: 300px; + display: flex; + flex-direction: column; +} + +.chat-message { + padding: 0.5rem 0.75rem; + border-radius: var(--radius); + transition: background-color 0.2s ease; + margin-bottom: 0.5rem; + width: 100%; + box-sizing: border-box; +} + +.chat-message:hover { + background-color: rgba(0, 0, 0, 0.03); +} + +.chat-message strong { + color: #111; +} + +.chat-message .text-muted { + color: #6c757d; +} + +/* Input group styling - light theme by default */ +.chat-container .input-group { + background-color: transparent; +} + +.chat-container .input-group .form-control { + background-color: #fff; + color: #212529; + border: 1px solid #ced4da; + border-radius: 0.375rem; +} + +.chat-container .input-group .form-control:focus { + background-color: #fff; + color: #212529; + border-color: #86b7fe; + outline: 0; + box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25); +} + +.chat-container .input-group .form-control::placeholder { + color: #6c757d; +} + +.chat-container .input-group .btn-primary { + background-color: var(--primary); + border-color: var(--primary); + border-radius: 0 0.375rem 0.375rem 0; +} + +.chat-container .input-group .btn-primary:hover { + background-color: #29b6f6; + border-color: #29b6f6; +} + +/* Chat message role badges - consistent with existing badge styles */ +.chat-message .badge { + font-size: 0.7rem; + font-weight: 600; + text-transform: uppercase; + padding: 0.25rem 0.5rem; +} + +/* System messages styling */ +.chat-message.text-muted { + font-style: italic; + padding: 0.25rem 0; + color: #6c757d; +} + +/* Own message styling - right-aligned with distinct background */ +.chat-message.own-message { + padding: 0.5rem 0; + width: 100% !important; + display: flex !important; + justify-content: flex-end !important; + align-items: flex-start !important; + flex-direction: row !important; +} + +.chat-message.own-message > div { + display: flex !important; + justify-content: flex-end !important; + width: 100% !important; + max-width: 100% !important; + flex-direction: row !important; +} + +.chat-message.own-message > div.d-flex { + justify-content: flex-end !important; + width: 100% !important; +} + +.chat-message.own-message > div > div.d-flex { + justify-content: flex-end !important; +} + +.own-message-content { + max-width: 70% !important; + min-width: 200px; + text-align: right; + margin-left: auto !important; + margin-right: 0 !important; + flex-shrink: 0; + flex-grow: 0; +} + +.own-message-bubble { + background-color: var(--primary); + color: #fff; + padding: 0.5rem 0.75rem; + border-radius: 1rem 1rem 0.25rem 1rem; + display: inline-block; + word-wrap: break-word; + text-align: left; + max-width: 100%; +} + +body.dark .own-message-bubble { + background-color: var(--primary); + color: #222; +} + +/* Other users' messages - left-aligned */ +.other-message-bubble { + background-color: #f1f3f5; + color: #111; + padding: 0.5rem 0.75rem; + border-radius: 1rem 1rem 1rem 0.25rem; + display: inline-block; + word-wrap: break-word; + max-width: 100%; +} + +body.dark .other-message-bubble { + background-color: rgba(255, 255, 255, 0.1); + color: var(--color-card-text); +} + +/* Dark mode styles - apply when body.dark is active */ +body.dark .chat-container { + background-color: var(--color-card-bg); + color: var(--color-card-text); + border-color: rgba(255, 255, 255, 0.1); +} + +body.dark #chatMessages { + background-color: var(--color-card-bg); + color: var(--color-card-text); + border-bottom-color: rgba(255, 255, 255, 0.1); +} + +body.dark .chat-message:hover { + background-color: rgba(255, 255, 255, 0.05); +} + +body.dark .chat-message strong { + color: var(--color-card-text); +} + +body.dark .chat-message .text-muted { + color: var(--color-card-text); + opacity: 0.6; +} + +body.dark .chat-container .input-group .form-control { + background-color: var(--color-card-bg); + color: var(--color-card-text); + border-color: rgba(255, 255, 255, 0.1); +} + +body.dark .chat-container .input-group .form-control:focus { + background-color: var(--color-card-bg); + color: var(--color-card-text); + border-color: var(--primary); + box-shadow: 0 0 0 0.2rem rgba(79, 195, 247, 0.25); +} + +body.dark .chat-container .input-group .form-control::placeholder { + color: rgba(255, 255, 255, 0.5); +} + +body.dark .chat-container .border-top { + border-top-color: rgba(255, 255, 255, 0.1) !important; +} + +/* Ensure own messages stay right-aligned on all screen sizes */ +@media (min-width: 1360px) { + .chat-message.own-message { + display: flex !important; + justify-content: flex-end !important; + align-items: flex-start; + } + + .chat-message.own-message > div { + display: flex !important; + justify-content: flex-end !important; + width: 100%; + } + + .chat-message.own-message > div > div.d-flex { + justify-content: flex-end !important; + } + + .own-message-content { + margin-left: auto !important; + margin-right: 0 !important; + max-width: 70%; + } +} + +/* Additional fix for very wide screens */ +@media (min-width: 1920px) { + .chat-message.own-message { + justify-content: flex-end !important; + } + + .own-message-content { + margin-left: auto !important; + margin-right: 0 !important; + } +} + +/* Responsive chat */ +@media (max-width: 768px) { + #chatMessages { + height: 250px !important; + max-height: 250px !important; + } + + .chat-container .input-group { + flex-direction: column; + } + + .chat-container .input-group #chatInput { + border-radius: 0.25rem 0.25rem 0 0; + margin-bottom: 0.25rem; + } + + .chat-container .input-group #sendBtn { + border-radius: 0 0 0.25rem 0.25rem; + width: 100%; + } + + .own-message-content { + max-width: 85%; + } Auth Pages (Login/Register) ================================ */ diff --git a/src/js/main.js b/src/js/main.js index 4585dc9..6d2d600 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -453,6 +453,349 @@ document.addEventListener('DOMContentLoaded', () => { updateAuthNav(); fetchStreams(); + + /* ================= CHAT FUNCTIONALITY ================= */ + + const chatMessages = document.getElementById('chatMessages'); + const chatInput = document.getElementById('chatInput'); + const sendBtn = document.getElementById('sendBtn'); + + // Check if chat elements exist before initializing + if (!chatMessages || !chatInput || !sendBtn) { + console.warn('Chat elements not found, skipping chat initialization'); + return; + } + + // Get or create persistent user ID (MUST be before socket connection) + let persistentUserId = localStorage.getItem('chatUserId'); + if (!persistentUserId) { + // Generate a unique ID and save it + persistentUserId = 'guest_' + Date.now() + '_' + Math.random().toString(36).substring(2, 9); + localStorage.setItem('chatUserId', persistentUserId); + console.log('šŸ†” Generated new persistent user ID:', persistentUserId); + } else { + console.log('šŸ†” Using existing user ID:', persistentUserId); + } + + // Initialize Socket.IO connection + // Connect directly to the API server (port 3000) - CORS is configured to allow this + const isDevelopment = window.location.port === '5173' || window.location.hostname === 'localhost'; + const socketUrl = isDevelopment ? 'http://localhost:3000' : window.location.origin; + + console.log('šŸ”Œ Attempting to connect to Socket.IO server at:', socketUrl); + + const socket = io(socketUrl, { + auth: { + token: localStorage.getItem('token') || null, + persistentUserId: persistentUserId + }, + // Try polling first, then upgrade to websocket if available + transports: ['polling', 'websocket'], + // Auto-reconnect settings + reconnection: true, + reconnectionDelay: 1000, + reconnectionDelayMax: 5000, + reconnectionAttempts: 5, + timeout: 20000 + }); + + // Get user info from token or default to 'user' + let currentUserRole = 'user'; + let currentUsername = null; + try { + const token = localStorage.getItem('token'); + if (token) { + const payload = JSON.parse(atob(token.split('.')[1])); + currentUserRole = payload.role || 'user'; + currentUsername = payload.username || null; + } + } catch (e) { + // Token parsing failed, use default role + } + + // If no authenticated username, use persistent ID as username for message matching + if (!currentUsername) { + currentUsername = persistentUserId; + } + + // Store persistent ID for message matching + const userPersistentId = persistentUserId; + + // Role badge colors + const roleColors = { + user: 'secondary', + vip: 'warning', + moderator: 'info', + broadcaster: 'success', + administrator: 'danger', + admin: 'danger', + bot: 'dark' + }; + + // Role display names + const roleNames = { + user: 'User', + vip: 'VIP', + moderator: 'Mod', + broadcaster: 'Broadcaster', + administrator: 'Admin', + admin: 'Admin', + bot: 'Bot' + }; + + // Function to format timestamp + function formatTime(timestamp) { + const date = new Date(timestamp); + return date.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit' }); + } + + // Function to add message to chat + function addMessageToChat(messageData) { + if (!chatMessages) return; + + const messageDiv = document.createElement('div'); + messageDiv.className = 'chat-message'; + messageDiv.dataset.messageId = messageData.id; + + const isSystem = messageData.type === 'system'; + const roleColor = roleColors[messageData.role] || 'secondary'; + const roleName = roleNames[messageData.role] || 'User'; + + // Check if this is the current user's message + // Match by persistent ID, userId, or username + const isOwnMessage = (currentUsername && messageData.username && + messageData.username.toLowerCase() === currentUsername.toLowerCase()) || + (messageData.userId && messageData.userId === userPersistentId) || + (messageData.persistentId && messageData.persistentId === userPersistentId) || + (messageData.username && messageData.username === userPersistentId); + + if (isOwnMessage) { + messageDiv.classList.add('own-message'); + } + + if (isSystem) { + messageDiv.className += ' text-muted text-center small'; + messageDiv.innerHTML = `${escapeHtml(messageData.message)}`; + } else { + if (isOwnMessage) { + // Right-aligned for own messages + messageDiv.innerHTML = ` +
+
+
+ ${formatTime(messageData.timestamp)} + ${escapeHtml(messageData.username)} + ${roleName} + You +
+
${escapeHtml(messageData.message)}
+
+
+ `; + } else { + // Left-aligned for other users' messages + messageDiv.innerHTML = ` +
+
+
+ ${roleName} + ${escapeHtml(messageData.username)} + ${formatTime(messageData.timestamp)} +
+
${escapeHtml(messageData.message)}
+
+
+ `; + } + } + + chatMessages.appendChild(messageDiv); + chatMessages.scrollTop = chatMessages.scrollHeight; + } + + // Update username when socket connects (server sends user info) + socket.on('userInfo', (userInfo) => { + if (userInfo) { + // Use persistent ID for message matching (most reliable) + if (userInfo.persistentId) { + // Keep persistent ID for matching, but use username for display + if (userInfo.username && userInfo.username !== userInfo.persistentId) { + // Authenticated user - use username for display but persistentId for matching + currentUsername = userInfo.persistentId; // Use persistent ID for matching + localStorage.setItem('chatUsername', userInfo.username); + } else { + currentUsername = userInfo.persistentId; + } + } else if (userInfo.id) { + currentUsername = userInfo.id; + } else if (userInfo.username) { + currentUsername = userInfo.username; + } + console.log('šŸ‘¤ Current user info:', { + username: userInfo.username, + id: userInfo.id, + persistentId: userInfo.persistentId, + currentUsername: currentUsername, + userPersistentId: userPersistentId + }); + } + }); + + // Helper function to escape HTML + function escapeHtml(text) { + const div = document.createElement('div'); + div.textContent = text; + return div.innerHTML; + } + + // Handle incoming chat messages + socket.on('chatMessage', (messageData) => { + addMessageToChat(messageData); + }); + + // Handle chat history on connection + socket.on('chatHistory', (history) => { + if (!chatMessages) return; + + // Clear existing messages (except any error messages) + const errorMessages = chatMessages.querySelectorAll('.alert'); + chatMessages.innerHTML = ''; + errorMessages.forEach(err => chatMessages.appendChild(err)); + + // Load history messages + if (Array.isArray(history) && history.length > 0) { + history.forEach(messageData => { + addMessageToChat(messageData); + }); + console.log(`šŸ“œ Loaded ${history.length} chat history messages`); + } else { + // If no history, show welcome message + addMessageToChat({ + id: Date.now(), + username: 'System', + message: 'Welcome to DevStream Chat!', + role: 'bot', + timestamp: new Date().toISOString(), + type: 'system' + }); + } + }); + + // Handle message deletion (for moderators) + socket.on('deleteMessage', ({ messageId }) => { + const messageElement = chatMessages.querySelector(`[data-message-id="${messageId}"]`); + if (messageElement) { + messageElement.remove(); + } + }); + + // Handle timeout + socket.on('timeout', ({ duration, reason }) => { + chatInput.disabled = true; + sendBtn.disabled = true; + chatInput.placeholder = `You are timed out for ${duration} seconds${reason ? `: ${reason}` : ''}`; + + setTimeout(() => { + chatInput.disabled = false; + sendBtn.disabled = false; + chatInput.placeholder = 'Send a message...'; + }, duration * 1000); + }); + + // Handle ban + socket.on('banned', ({ reason }) => { + chatInput.disabled = true; + sendBtn.disabled = true; + chatInput.placeholder = `You have been banned${reason ? `: ${reason}` : ''}`; + socket.disconnect(); + }); + + // Handle errors + socket.on('error', ({ message }) => { + const errorDiv = document.createElement('div'); + errorDiv.className = 'alert alert-danger alert-dismissible fade show'; + errorDiv.innerHTML = ` + ${escapeHtml(message)} + + `; + chatMessages.appendChild(errorDiv); + setTimeout(() => errorDiv.remove(), 5000); + }); + + socket.on('disconnect', () => { + console.log('āŒ Disconnected from chat server'); + }); + + socket.on('connect_error', (error) => { + console.error('āŒ Chat connection error:', error); + console.error('Error details:', { + message: error.message, + type: error.type, + description: error.description + }); + + if (chatMessages) { + // Remove any existing error messages + const existingError = chatMessages.querySelector('.alert-warning'); + if (existingError) existingError.remove(); + + const errorMsg = document.createElement('div'); + errorMsg.className = 'alert alert-warning alert-dismissible fade show'; + errorMsg.innerHTML = ` + Chat Connection Error: Unable to connect to chat server. + Please make sure the server is running on port 3000. + + `; + chatMessages.appendChild(errorMsg); + } + }); + + socket.on('reconnect_attempt', () => { + console.log('šŸ”„ Attempting to reconnect to chat server...'); + }); + + socket.on('reconnect', (attemptNumber) => { + console.log(`āœ… Reconnected to chat server after ${attemptNumber} attempts`); + if (chatMessages) { + const existingError = chatMessages.querySelector('.alert-warning'); + if (existingError) existingError.remove(); + } + }); + + socket.on('reconnect_failed', () => { + console.error('āŒ Failed to reconnect to chat server'); + if (chatMessages) { + const errorMsg = document.createElement('div'); + errorMsg.className = 'alert alert-danger'; + errorMsg.textContent = 'Failed to reconnect to chat. Please refresh the page.'; + chatMessages.appendChild(errorMsg); + } + }); + + // Send message function + function sendMessage() { + const message = chatInput.value.trim(); + if (!message) return; + + socket.emit('chatMessage', { message }); + chatInput.value = ''; + } + + // Event listeners for sending messages + sendBtn.addEventListener('click', sendMessage); + chatInput.addEventListener('keypress', (e) => { + if (e.key === 'Enter' && !e.shiftKey) { + e.preventDefault(); + sendMessage(); + } + }); + + // Handle connection - history will be loaded via chatHistory event + socket.on('connect', () => { + console.log('āœ… Connected to chat server'); + // Welcome message will be added only if no history is received + // (handled in chatHistory event handler) + }); }); /* ================= SERVICE WORKER ================= */ diff --git a/src/models/User.js b/src/models/User.js index 92dce20..da3a6fc 100644 --- a/src/models/User.js +++ b/src/models/User.js @@ -15,6 +15,7 @@ const UserSchema = new mongoose.Schema({ unique: true, trim: true, lowercase: true, + match: [/.+\@.+\..+/, 'Please fill a valid email address'], match: [/.+@.+\..+/, 'Please fill a valid email address'], }, // Store the hashed password @@ -25,6 +26,15 @@ const UserSchema = new mongoose.Schema({ }, role: { type: String, + enum: [ + 'user', + 'admin', + 'moderator', + 'vip', + 'administrator', + 'broadcaster', + 'bot', + ], enum: ['user', 'admin'], // For future authorization default: 'user', },