-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from MrBrax/develop
Develop
- Loading branch information
Showing
45 changed files
with
789 additions
and
960 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
FROM alpine:3.7 | ||
RUN apk --no-cache add nodejs yarn | ||
COPY . /var/broker | ||
WORKDIR /var/broker | ||
RUN yarn install | ||
ENTRYPOINT [ "yarn", "start" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "client-broker", | ||
"version": "1.0.0", | ||
"main": "server.js", | ||
"license": "MIT", | ||
"dependencies": { | ||
"ws": "^7.4.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// const { cli } = require('webpack'); | ||
const WebSocket = require('ws'); | ||
|
||
class ClientBroker { | ||
constructor(){ | ||
this.clients = []; | ||
this.wss = null; | ||
} | ||
start () { | ||
const a = process.argv.slice(2); | ||
const serverPort = a[0] ? parseInt(a[0]) : 8765; | ||
|
||
console.log(`Starting on port ${serverPort}...`); | ||
try { | ||
this.wss = new WebSocket.Server({ port: serverPort }); | ||
} catch (error) { | ||
console.error("Fatal error when starting broker server", error); | ||
return false; | ||
} | ||
|
||
this.wss.on('error', (error) => { | ||
console.log("Websocket server error", error); | ||
}); | ||
|
||
this.wss.on('connection', this.onConnect.bind(this)); | ||
} | ||
|
||
onConnect(ws, req){ | ||
const clientIP = req.connection.remoteAddress; | ||
ws.clientIP = clientIP; | ||
// console.log(clientIP); | ||
this.clients.push(ws); | ||
|
||
ws.on("message", (message) => this.onMessage(ws, message)); | ||
ws.on("pong", (heartbeat) => { | ||
ws.isAlive = true; | ||
console.log(`Pong from ${clientIP}`); | ||
}); | ||
ws.on("error", (err) => { | ||
console.error("Client error", err) | ||
}); | ||
} | ||
|
||
onMessage(ws, message){ | ||
// console.log("message", ws, message); | ||
|
||
if(message == "ping"){ | ||
console.log(`Pong to ${ws.clientIP}`); | ||
ws.send("pong"); | ||
return; | ||
} | ||
|
||
let data; | ||
|
||
try { | ||
data = JSON.parse(message); | ||
} catch (error) { | ||
console.error(`Invalid data from ${ws.clientIP}: ${message}`) | ||
return; | ||
} | ||
|
||
if(data.server){ | ||
this.wss.clients.forEach((client) => { | ||
client.send(JSON.stringify({ | ||
action: "server", | ||
data: data.data | ||
})); | ||
}); | ||
} | ||
|
||
console.log(`json from ${ws.clientIP}:`, data); | ||
console.debug(`Clients: ${this.wss.clients.size}`); | ||
} | ||
} | ||
|
||
const cb = new ClientBroker(); | ||
cb.start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|
||
ws@^7.4.3: | ||
version "7.4.3" | ||
resolved "https://registry.yarnpkg.com/ws/-/ws-7.4.3.tgz#1f9643de34a543b8edb124bdcbc457ae55a6e5cd" | ||
integrity sha512-hr6vCR76GsossIRsr8OLR9acVVm1jyfEWvhbNjtgPOrfvAlKzvyeg/P6r8RuDjRyrcQoPQT7K0DGEPc7Ae6jzA== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
User-agent: * | ||
Disallow: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -259,6 +259,10 @@ | |
display: none; | ||
} | ||
|
||
#jobs-status { | ||
display: none; | ||
} | ||
|
||
.jobs_list { | ||
display: none; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.