Browse Source

serve client from server automatecly

Dennis Mårtensson 12 years ago
parent
commit
0e5f6cc059
3 changed files with 40 additions and 4 deletions
  1. 5 3
      example/index.html
  2. 28 0
      example/server.js
  3. 7 1
      package.json

+ 5 - 3
example/index.html

@@ -4,8 +4,8 @@
     <title>Example webrtc.io</title>
     <link type="text/css" href="/style.css" rel="stylesheet"></link>
 
-    <script src="http://multiwebrtc.nodejitsu.com/socket.io/socket.io.js"></script>
-    <script src="/io.js"></script>
+    <script src="/socket.io/socket.io.js"></script>
+    <script src="/webrtc.io/webrtc.io.js"></script>
   </head>
   <body onload="init()">
     <div id="videos">
@@ -147,7 +147,9 @@
 
         var room = window.location.hash.slice(1);
 
-        rtc.connect("http://multiwebrtc.nodejitsu.com/", room);
+        //rtc.connect("http://multiwebrtc.nodejitsu.com/", room);
+
+        rtc.connect("http://localhost:8000", room);
 
         rtc.on('add remote stream', function(stream, socketId) {
           console.log("ADDING REMOTE STREAM...");

+ 28 - 0
example/server.js

@@ -0,0 +1,28 @@
+var app = require('express').createServer();
+var io = require('webrtc.io').listen(app);
+
+var colors = {};
+
+app.listen(8000);
+
+app.get('/', function (req, res) {
+  res.sendfile(__dirname + '/index.html');
+});
+
+app.get('/style.css', function (req, res) {
+  res.sendfile(__dirname + '/style.css');
+});
+
+io.sockets.on('connection', function(socket) {
+  console.log("connection received");
+
+  colors[socket.id] = Math.floor(Math.random()* 0xFFFFFF)
+  socket.on('chat msg', function(msg) {
+    console.log("chat received");
+    
+    socket.broadcast.emit('receive chat msg', {
+      msg: msg,
+      color: colors[socket.id]
+    });
+  });
+});

+ 7 - 1
package.json

@@ -12,5 +12,11 @@
   "subdomain": "MultiWebRTC",
   "scripts": {
     "start": "server.js"
-  }
+  },
+  "author": "Ben Brittain",
+  "contributors": [
+      { "name": "Ben Brittain", "email": "ben@brittain.org" }
+    , { "name": "Dennis Mårtensson", "email": "me@dennis.is" }
+    , { "name": "David Peter", "email": "david.a.peter@gmail.com" }
+  ],
 }