Skip to content

Commit

Permalink
adding WebSocket
Browse files Browse the repository at this point in the history
  • Loading branch information
jgphilpott committed Oct 22, 2024
1 parent c947883 commit ae29745
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 22 deletions.
27 changes: 24 additions & 3 deletions app/express.coffee
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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
24 changes: 23 additions & 1 deletion app/scripts/core.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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()
6 changes: 6 additions & 0 deletions app/styles/core.sass
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
@import "colors/solid/grayscale.sass"
@import "colors/solid/rainbow.sass"

@import "tools/vars.sass"

*

margin: 0px
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions app/styles/tools/vars.sass
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
$pi: 3.14
$galaxy: 42
$golden: 1.618

$foreground: $galaxy
$background: -$galaxy
28 changes: 14 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,21 +122,22 @@
"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",
"electron-updater": "^6.3.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"
}
}

0 comments on commit ae29745

Please sign in to comment.