Skip to content

Commit

Permalink
Broadcast on messages
Browse files Browse the repository at this point in the history
  • Loading branch information
brunnolou committed Nov 20, 2017
1 parent 46e5790 commit fd357b2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
25 changes: 12 additions & 13 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,27 +47,25 @@ wsServer.on("request", function(request) {
})
);

// setInterval(() => {
// connection.sendUTF(
// JSON.stringify({
// action: "ping"
// })
// );
// }, 1500);

console.log(new Date() + " Connection accepted.");

connection.on("message", function(message) {
if (message.type === "utf8") {
console.log("Received Message: " + message.utf8Data);
if (message.type !== "utf8") return;

connection.sendUTF(
JSON.stringify({
action: "connected",
message: message.utf8Data
})
);

// Broadcast.
Object.values(allActiveConnections).forEach(connection => {
connection.sendUTF(
JSON.stringify({
action: "connected",
message: message.utf8Data
})
);
}
});
});

connection.on("close", function(reasonCode, description) {
Expand All @@ -80,6 +78,7 @@ wsServer.on("request", function(request) {
});

app.use(express.static("public"));

app.all("/refresh/:collection?/:id?", function(req, res, next) {
const { collection, id } = req.params;

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"start": "node index.js",
"dev": "nodemon index.js",
"deploy": "now rm ws && now --public",
"deploy": "now rm ws-refresh && now --public",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
Expand Down

0 comments on commit fd357b2

Please sign in to comment.