From ae29745a0bef350b0f42a49eb6d9ef3c7bd0378f Mon Sep 17 00:00:00 2001 From: Jacob Philpott Date: Tue, 22 Oct 2024 14:19:03 +0300 Subject: [PATCH] adding WebSocket --- app/express.coffee | 27 ++++++++++++++++++++++++--- app/scripts/core.coffee | 24 +++++++++++++++++++++++- app/styles/core.sass | 6 ++++++ app/styles/tools/vars.sass | 2 ++ package-lock.json | 28 ++++++++++++++-------------- package.json | 9 +++++---- 6 files changed, 74 insertions(+), 22 deletions(-) diff --git a/app/express.coffee b/app/express.coffee index 0e35bc90..7bb4d6ee 100644 --- a/app/express.coffee +++ b/app/express.coffee @@ -1,11 +1,18 @@ express = require "express" + +WebSocket = require "ws" +http = require "http" + path = require "path" +platform = "express" host = "127.0.0.1" port = "4000" app = express() -platform = "express" + +server = http.createServer app +socket = new WebSocket.Server({ server }) app.set "view engine", "pug" app.set "views", path.join(__dirname, "templates") @@ -28,6 +35,20 @@ app.get "/tutorials", (request, responce) => responce.render "pages/tutorials", platform: platform -app.listen port, => +socket.on "connection", (node) => + + console.log "Node Connected" + + node.on "message", (message) => + + console.log "Received: " + message + + node.send "Echo from server: " + message + + node.on "close", => + + console.log "Node Disconnected" + +server.listen port, => - console.log "Polysmith listening at http://localhost:" + port + console.log "Polysmith listening at " + host + ":" + port diff --git a/app/scripts/core.coffee b/app/scripts/core.coffee index cea8fa72..4a52fb12 100644 --- a/app/scripts/core.coffee +++ b/app/scripts/core.coffee @@ -5,7 +5,29 @@ Forkme = require "./ui/forkme" Strike = require "./anvil/strike" +socket = new WebSocket "ws://localhost:4000" + window.narbar = new Navbar() window.forkme = new Forkme() -new Strike() +socket.addEventListener "open", (event) => + + console.log "Open" + + socket.send "Hello from the client!" + +socket.addEventListener "message", (event) => + + console.log "Message from the server: " + event.data + +socket.addEventListener "error", (event) => + + console.error "WebSocket error observed: " + event.data + +socket.addEventListener "close", (event) => + + console.log "Close" + +if window.location.page is "anvil" + + new Strike() diff --git a/app/styles/core.sass b/app/styles/core.sass index 51abd9f5..f63f1143 100644 --- a/app/styles/core.sass +++ b/app/styles/core.sass @@ -4,6 +4,8 @@ @import "colors/solid/grayscale.sass" @import "colors/solid/rainbow.sass" +@import "tools/vars.sass" + * margin: 0px @@ -27,7 +29,11 @@ body canvas + z-index: $background + + display: block outline: none + cursor: move label, input, img, h1, h2, h3, h4, h5, h6, p, a diff --git a/app/styles/tools/vars.sass b/app/styles/tools/vars.sass index e82a70c0..ca47f9f2 100644 --- a/app/styles/tools/vars.sass +++ b/app/styles/tools/vars.sass @@ -1,4 +1,6 @@ +$pi: 3.14 $galaxy: 42 +$golden: 1.618 $foreground: $galaxy $background: -$galaxy diff --git a/package-lock.json b/package-lock.json index 730c2a9c..d51befd0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,11 +21,12 @@ "sha512": "^0.0.1", "three": "^0.169.0", "three-bvh-csg": "^0.0.16", - "three-mesh-bvh": "^0.8.2" + "three-mesh-bvh": "^0.8.2", + "ws": "^8.18.0" }, "devDependencies": { "browserify": "^17.0.1", - "electron": "^32.2.0", + "electron": "^33.0.1", "electron-builder": "^25.1.8", "electron-devtools-installer": "^3.2.0", "electron-reload": "^2.0.0-alpha.1", @@ -33,9 +34,9 @@ "jest": "^29.7.0", "jest-environment-jsdom": "^29.7.0", "jsdom": "^25.0.1", - "npm-check-updates": "^17.1.3", + "npm-check-updates": "^17.1.4", "pug-cli": "^1.0.0-alpha6", - "sass": "^1.79.5", + "sass": "^1.80.3", "uglify-js": "^3.19.3" }, "funding": { @@ -5089,9 +5090,9 @@ } }, "node_modules/electron": { - "version": "32.2.0", - "resolved": "https://registry.npmjs.org/electron/-/electron-32.2.0.tgz", - "integrity": "sha512-Xy82QBQrEiQysoxsv6lnhHAcWNNe6vV6QqH3OPFXhEj/T9oAsBHEhZuuYHINSSsUE7zRSj+J9sNwJYOjisT0Vw==", + "version": "33.0.1", + "resolved": "https://registry.npmjs.org/electron/-/electron-33.0.1.tgz", + "integrity": "sha512-PipPnWH4gvf7o+P8jlKQZGgPfb5eHcLgTrnKkFzb98MXhyPjVJYCR7YWqcawZ8IfyJCut8vMxLuBFLT1Ag8TSQ==", "dev": true, "hasInstallScript": true, "license": "MIT", @@ -9281,9 +9282,9 @@ } }, "node_modules/npm-check-updates": { - "version": "17.1.3", - "resolved": "https://registry.npmjs.org/npm-check-updates/-/npm-check-updates-17.1.3.tgz", - "integrity": "sha512-4uDLBWPuDHT5KLieIJ20FoAB8yqJejmupI42wPyfObgQOBbPAikQSwT73afDwREvhuxYrRDqlRvxTMSfvO+L8A==", + "version": "17.1.4", + "resolved": "https://registry.npmjs.org/npm-check-updates/-/npm-check-updates-17.1.4.tgz", + "integrity": "sha512-crOUeN2GngqlkRCFQ/zi1zsneWd9IGZgIfAWYGAuhYiPnfbBTmJBL7Yq1wI0e1dsW8CfWc+h348WmfCREqeOBA==", "dev": true, "license": "Apache-2.0", "bin": { @@ -10967,9 +10968,9 @@ } }, "node_modules/sass": { - "version": "1.79.5", - "resolved": "https://registry.npmjs.org/sass/-/sass-1.79.5.tgz", - "integrity": "sha512-W1h5kp6bdhqFh2tk3DsI771MoEJjvrSY/2ihJRJS4pjIyfJCw0nTsxqhnrUzaLMOJjFchj8rOvraI/YUVjtx5g==", + "version": "1.80.3", + "resolved": "https://registry.npmjs.org/sass/-/sass-1.80.3.tgz", + "integrity": "sha512-ptDWyVmDMVielpz/oWy3YP3nfs7LpJTHIJZboMVs8GEC9eUmtZTZhMHlTW98wY4aEorDfjN38+Wr/XjskFWcfA==", "dev": true, "license": "MIT", "dependencies": { @@ -12742,7 +12743,6 @@ "version": "8.18.0", "resolved": "https://registry.npmjs.org/ws/-/ws-8.18.0.tgz", "integrity": "sha512-8VbfWfHLbbwu3+N6OKsOMpBdT4kXPDDB9cJk2bJ6mh9ucxdlnNvH1e+roYkKmN9Nxw2yjz7VzeO9oOz2zJ04Pw==", - "dev": true, "license": "MIT", "engines": { "node": ">=10.0.0" diff --git a/package.json b/package.json index e1d87bc4..ef29f200 100644 --- a/package.json +++ b/package.json @@ -122,11 +122,12 @@ "sha512": "^0.0.1", "three": "^0.169.0", "three-bvh-csg": "^0.0.16", - "three-mesh-bvh": "^0.8.2" + "three-mesh-bvh": "^0.8.2", + "ws": "^8.18.0" }, "devDependencies": { "browserify": "^17.0.1", - "electron": "^32.2.0", + "electron": "^33.0.1", "electron-builder": "^25.1.8", "electron-devtools-installer": "^3.2.0", "electron-reload": "^2.0.0-alpha.1", @@ -134,9 +135,9 @@ "jest": "^29.7.0", "jest-environment-jsdom": "^29.7.0", "jsdom": "^25.0.1", - "npm-check-updates": "^17.1.3", + "npm-check-updates": "^17.1.4", "pug-cli": "^1.0.0-alpha6", - "sass": "^1.79.5", + "sass": "^1.80.3", "uglify-js": "^3.19.3" } }