Skip to content

Commit

Permalink
imported server
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromeetienne committed Mar 18, 2013
1 parent 6923184 commit 6c7e5fb
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@


var room = 'public';
var serverUrl = "ws://localhost:8080/";
var serverUrl = "ws://localhost:8000/";

function onModelLoaded(){
// connect the server
Expand Down
33 changes: 33 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "MultiWebRTC",
"description": "Example of multi user webrtc",
"version": "0.0.2-1",
"engines": {
"node": ">= 0.6.0"
},
"dependencies": {
"webrtc.io": "latest",
"webrtc.io-client": "latest",
"express": "3.1.0",
"ws": "latest"
},
"subdomain": "MultiWebRTC",
"scripts": {
"start": "example/server.js"
},
"author": "Ben Brittain",
"contributors": [
{
"name": "Ben Brittain",
"email": "[email protected]"
},
{
"name": "Dennis Mårtensson",
"email": "[email protected]"
},
{
"name": "David Peter",
"email": "[email protected]"
}
]
}
50 changes: 50 additions & 0 deletions server/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
var express = require('express');
var app = express()
var server = require('http').createServer(app);
var webRTC = require('webrtc.io').listen(server);

var port = process.env.PORT || 8000;
server.listen(port);


// export static files
app.use('/', express.static(__dirname + '/../'));


webRTC.rtc.on('connect', function(rtc) {
//Client connected
});

webRTC.rtc.on('send answer', function(rtc) {
//answer sent
});

webRTC.rtc.on('disconnect', function(rtc) {
//Client disconnect
});

webRTC.rtc.on('chat_msg', function(data, socket) {
var roomList = webRTC.rtc.rooms[data.room] || [];

for (var i = 0; i < roomList.length; i++) {
var socketId = roomList[i];

if (socketId !== socket.id) {
var soc = webRTC.rtc.getSocket(socketId);

if (soc) {
soc.send(JSON.stringify({
"eventName": "receive_chat_msg",
"data": {
"messages": data.messages,
"color": data.color
}
}), function(error) {
if (error) {
console.log(error);
}
});
}
}
}
});

0 comments on commit 6c7e5fb

Please sign in to comment.