webrtc initial commit
This commit is contained in:
50
server/server.js
Normal file
50
server/server.js
Normal file
@@ -0,0 +1,50 @@
|
||||
var utils = require('./utils');
|
||||
|
||||
var WebSocketServer = require('ws').Server;
|
||||
|
||||
var wss = new WebSocketServer({port: 3434});
|
||||
|
||||
wss.broadcast = function(data, channel) {
|
||||
// if(!channel)
|
||||
// {
|
||||
// console.log('empty channel. skipped.');
|
||||
// return;
|
||||
// }
|
||||
|
||||
for(var i in this.clients) {
|
||||
// if(this.clients[i].channel == channel)
|
||||
{
|
||||
console.log('channel1 : ' + this.clients[i].channel);
|
||||
console.log('channel2 : ' + channel);
|
||||
|
||||
console.log('['+(new Date().toLocaleString())+'] ' + 'send : [' + channel +'] '+ data);
|
||||
this.clients[i].send(data);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
wss.on('connection', function(ws) {
|
||||
ws.on('message', function(message) {
|
||||
console.log('['+(new Date().toLocaleString())+'] ' + 'received: %s\n', message);
|
||||
try {
|
||||
var obj = JSON.parse(message);
|
||||
utils.ObjDump(obj);
|
||||
if(obj.channel != null)
|
||||
{
|
||||
var channel = obj.channel;
|
||||
|
||||
// if(wss.channel == null)
|
||||
// wss.channel = new Object();
|
||||
// if(wss.channel[channel] == null)
|
||||
// wss.channel[channel] = new Array();
|
||||
// wss.channel[channel].push(ws);
|
||||
ws.channel = channel;
|
||||
console.log('new channel : ' + ws.channel);
|
||||
}
|
||||
} catch (ex) {
|
||||
console.log('['+(new Date().toLocaleString())+'] ' + ex);
|
||||
}
|
||||
|
||||
wss.broadcast(message, ws.channel);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user