Skip to content

Commit

Permalink
Add WebSocket support
Browse files Browse the repository at this point in the history
  • Loading branch information
mrautio committed Feb 8, 2019
1 parent 17f8216 commit a5a9bd7
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 41 deletions.
2 changes: 2 additions & 0 deletions config.cson
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
servers:
httpPort: 8080
udpPort: 9909
webSocketPort: 9910
webSocketHost: "0.0.0.0"
hosts:
enttec1:
# path: "/dev/serial/by-id/usb-FTDI_FT245R_USB_FIFO_ENP9D7H7-if00-port0"
Expand Down
84 changes: 44 additions & 40 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,41 +1,45 @@
{
"name": "effectserver",
"version": "0.1.1",
"author": "Esa-Matti Suuronen",
"contributors": [
"Tommi Teistelä"
],
"homepage": "https://github.com/Instanssi/effectserver",
"description": "UDP packet abstraction for multiple DMX controllers",
"bugs": {
"url": "https://github.com/Instanssi/effectserver/issues/"
},
"repository": {
"type": "git",
"url": "https://github.com/Instanssi/effectserver.git"
},
"scripts": {
"test": "mocha --compilers coffee:coffee-script/register",
"start": "coffee server.coffee"
},
"main": "./lib/index",
"dependencies": {
"coffee-script": "~1.12.3",
"underscore": "~1.8.3",
"serialport": "~4.0.0",
"underscore.string": "~3.3.4",
"async": "~1.5.2",
"jade": "~1.11.0",
"stylus": "~0.53.0",
"socket.io": "~0.9.16",
"cson": "~3.0.2",
"piler": "~0.5.1",
"express": "~2.5.11",
"hbs": "~4.0.0"
},
"devDependencies": {
"mocha": "~3.2.0",
"should": "~11.2.0",
"supervisor": "~0.12.0"
}
}
"name": "effectserver",
"version": "0.1.1",
"author": "Esa-Matti Suuronen",
"contributors": [
"Tommi Teistelä"
],
"homepage": "https://github.com/Instanssi/effectserver",
"description": "packet abstraction for multiple DMX controllers",
"bugs": {
"url": "https://github.com/Instanssi/effectserver/issues/"
},
"repository": {
"type": "git",
"url": "https://github.com/Instanssi/effectserver.git"
},
"scripts": {
"test": "mocha --compilers coffee:coffee-script/register",
"start": "coffee server.coffee"
},
"main": "./lib/index",
"dependencies": {
"coffee-script": "~1.12.3",
"underscore": "~1.8.3",
"serialport": "~4.0.0",
"underscore.string": "~3.3.4",
"async": "~1.5.2",
"jade": "~1.11.0",
"stylus": "~0.53.0",
"socket.io": "~0.9.16",
"cson": "~3.0.2",
"piler": "~0.5.1",
"express": "~2.5.11",
"hbs": "~4.0.0",
"ws": "~6.1.3"
},
"devDependencies": {
"mocha": "~3.2.0",
"should": "~11.2.0",
"supervisor": "~0.12.0"
},
"optionalDependencies": {
"bufferutil": "^4.0.1"
}
}
15 changes: 14 additions & 1 deletion server.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
CSON = require "cson"
dgram = require "dgram"
ws = require "ws"
fs = require "fs"
util = require "util"
EventEmitter = require "events"
Expand Down Expand Up @@ -35,7 +36,7 @@ onConfigRead = (error, config) ->
console.log "FIREWALL", firewall
, 1000

udpserver.on "message", (packet, rinfo) ->
processPacket = (packet, rinfo) ->
try
cmds = packetParse packet
catch e
Expand Down Expand Up @@ -77,6 +78,18 @@ onConfigRead = (error, config) ->
if not firewall?
websocket.sockets.volatile.emit "cmds", results

wsserver = new ws.Server { port: config.servers.webSocketPort, host: config.servers.webSocketHost }

wsserver.on "listening", ->
console.log "Now listening WebSocket on #{ config.servers.webSocketHost }:#{ config.servers.webSocketPort }"

wsserver.on 'connection', (socket, req) ->
socket.on 'message', (packet) ->
processPacket packet, { address: req.connection.remoteAddress }

udpserver.on "message", (packet, rinfo) ->
processPacket packet, rinfo

udpserver.on "listening", ->
console.log "Now listening on UDP port #{ config.servers.udpPort }"
udpserver.bind config.servers.udpPort
Expand Down

0 comments on commit a5a9bd7

Please sign in to comment.