server.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. var app = require('express').createServer();
  2. var webRTC = require('webrtc.io').listen(app);
  3. var colors = {};
  4. //When connectiong to nodejitsu
  5. app.listen(80);
  6. //When using localhost
  7. //app.listen(8000);
  8. app.get('/', function(req, res) {
  9. res.sendfile(__dirname + '/index.html');
  10. });
  11. app.get('/style.css', function(req, res) {
  12. res.sendfile(__dirname + '/style.css');
  13. });
  14. function selectRoom(socket) {
  15. for (var room in servers) {
  16. console.log('***' + room);
  17. if (io.sockets.clients(room).length < 4) {
  18. socket.emit('send', room);
  19. }
  20. console.log(io.sockets.clients('' + room));
  21. }
  22. }
  23. webRTC.rtc.on('connection', function(rtc) {
  24. //Client connected
  25. rtc.on('send_answer', function() {
  26. //answer sent
  27. });
  28. rtc.on('disconnect', function() {
  29. //disconnect sent
  30. });
  31. });
  32. webRTC.sockets.on('connection', function(socket) {
  33. console.log("connection received");
  34. colors[socket.id] = Math.floor(Math.random()* 0xFFFFFF)
  35. socket.on('chat msg', function(msg) {
  36. console.log("chat received");
  37. socket.broadcast.emit('receive chat msg', {
  38. msg: msg,
  39. color: colors[socket.id]
  40. });
  41. });
  42. });