chat server
-rw-r--r--.gitignore10
-rw-r--r--.prettierrc4
-rw-r--r--Procfile1
-rw-r--r--package-lock.json74
-rw-r--r--package.json19
-rw-r--r--src/index.js23
6 files changed, 131 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..1139b88
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,10 @@
+# dependencies
+/node_modules
+
+# misc
+.idea
+.DS_Store
+
+npm-debug.log*
+yarn-debug.log*
+yarn-error.log* \ No newline at end of file
diff --git a/.prettierrc b/.prettierrc
new file mode 100644
index 0000000..7a28161
--- /dev/null
+++ b/.prettierrc
@@ -0,0 +1,4 @@
+{
+ "tabWidth": 2,
+ "useTabs": false
+} \ No newline at end of file
diff --git a/Procfile b/Procfile
new file mode 100644
index 0000000..119fa10
--- /dev/null
+++ b/Procfile
@@ -0,0 +1 @@
+web: node src/index.js \ No newline at end of file
diff --git a/package-lock.json b/package-lock.json
new file mode 100644
index 0000000..341d47c
--- /dev/null
+++ b/package-lock.json
@@ -0,0 +1,74 @@
+{
+ "name": "gd-com-websocket-basic",
+ "version": "1.0.0",
+ "lockfileVersion": 2,
+ "requires": true,
+ "packages": {
+ "": {
+ "name": "gd-com-websocket-basic",
+ "version": "1.0.0",
+ "license": "MIT",
+ "dependencies": {
+ "@gd-com/utils": "^4.1.0",
+ "ws": "^7.4.6"
+ },
+ "engines": {
+ "node": "16.15"
+ }
+ },
+ "node_modules/@gd-com/utils": {
+ "version": "4.1.0",
+ "resolved": "https://registry.npmjs.org/@gd-com/utils/-/utils-4.1.0.tgz",
+ "integrity": "sha512-YYiMfg9x98KBnKqjLSyvVcvpBE2w64aJYS14CiOtWRQpvBzP30riVoe4CKAvII2WyuUoobS2P4hQ/eMS/kfzeg==",
+ "dependencies": {
+ "long": "^4.0.0"
+ }
+ },
+ "node_modules/long": {
+ "version": "4.0.0",
+ "resolved": "https://registry.npmjs.org/long/-/long-4.0.0.tgz",
+ "integrity": "sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA=="
+ },
+ "node_modules/ws": {
+ "version": "7.5.7",
+ "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.7.tgz",
+ "integrity": "sha512-KMvVuFzpKBuiIXW3E4u3mySRO2/mCHSyZDJQM5NQ9Q9KHWHWh0NHgfbRMLLrceUK5qAL4ytALJbpRMjixFZh8A==",
+ "engines": {
+ "node": ">=8.3.0"
+ },
+ "peerDependencies": {
+ "bufferutil": "^4.0.1",
+ "utf-8-validate": "^5.0.2"
+ },
+ "peerDependenciesMeta": {
+ "bufferutil": {
+ "optional": true
+ },
+ "utf-8-validate": {
+ "optional": true
+ }
+ }
+ }
+ },
+ "dependencies": {
+ "@gd-com/utils": {
+ "version": "4.1.0",
+ "resolved": "https://registry.npmjs.org/@gd-com/utils/-/utils-4.1.0.tgz",
+ "integrity": "sha512-YYiMfg9x98KBnKqjLSyvVcvpBE2w64aJYS14CiOtWRQpvBzP30riVoe4CKAvII2WyuUoobS2P4hQ/eMS/kfzeg==",
+ "requires": {
+ "long": "^4.0.0"
+ }
+ },
+ "long": {
+ "version": "4.0.0",
+ "resolved": "https://registry.npmjs.org/long/-/long-4.0.0.tgz",
+ "integrity": "sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA=="
+ },
+ "ws": {
+ "version": "7.5.7",
+ "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.7.tgz",
+ "integrity": "sha512-KMvVuFzpKBuiIXW3E4u3mySRO2/mCHSyZDJQM5NQ9Q9KHWHWh0NHgfbRMLLrceUK5qAL4ytALJbpRMjixFZh8A==",
+ "requires": {}
+ }
+ }
+}
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..25c8c22
--- /dev/null
+++ b/package.json
@@ -0,0 +1,19 @@
+{
+ "name": "gd-com-websocket-basic",
+ "version": "1.0.0",
+ "description": "",
+ "main": "src/index.js",
+ "scripts": {
+ "test": "echo \"Error: no test specified\" && exit 1",
+ "start": "node src/index.js"
+ },
+ "author": "",
+ "license": "MIT",
+ "dependencies": {
+ "@gd-com/utils": "^4.1.0",
+ "ws": "^7.4.6"
+ },
+ "engines": {
+ "node": "16.15"
+ }
+} \ No newline at end of file
diff --git a/src/index.js b/src/index.js
new file mode 100644
index 0000000..53051cf
--- /dev/null
+++ b/src/index.js
@@ -0,0 +1,23 @@
+const WebSocket = require('ws')
+const gdCom = require('@gd-com/utils')
+
+const PORT = process.env.PORT || 3000;
+
+const wss = new WebSocket.Server({ port: PORT })
+console.log(`Server started on port ${PORT}`)
+wss.on('connection', ws => {
+
+ console.log("client connected")
+
+ // on message recieved
+ ws.on('message', (message) => {
+ console.log("attempting to relay the message")
+ wss.clients.forEach((client) => {
+ console.log("relaying message to client")
+ if (client.readyState === WebSocket.OPEN) {
+ var recieve= gdCom.getVar(Buffer.from(message))
+ console.log(recieve.value)
+ client.send(gdCom.putVar(recieve))
+ }})
+ })
+})