Skip to content

Commit

Permalink
UPDATE: add missing server.js file.
Browse files Browse the repository at this point in the history
  • Loading branch information
dimircea committed Jan 26, 2016
1 parent cb65418 commit ca757bc
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions SimpleVideoChat/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
var WebSocketServer = require('ws').Server,
wss = new WebSocketServer({port: 3434});

/** broadcast message to all clients **/
wss.broadcast = function (data) {
var i = 0, n = this.clients ? this.clients.length : 0, client = null;
for (; i < n; i++) {
client = this.clients[i];
if (client.readyState === client.OPEN) {
client.send(data);
}
else console.error('Error: the client state is ' + client.readyState);
}
};

/** successful connection */
wss.on('connection', function (ws) {
/** incomming message */
ws.on('message', function (message) {
/** broadcast message to all clients */
wss.broadcast(message);
});
});

0 comments on commit ca757bc

Please sign in to comment.