server.js 633 B

12345678910111213141516171819202122232425262728
  1. var app = require('express').createServer();
  2. var io = require('webrtc.io').listen(app);
  3. var colors = {};
  4. app.listen(80);
  5. app.get('/', function (req, res) {
  6. res.sendfile(__dirname + '/index.html');
  7. });
  8. app.get('/style.css', function (req, res) {
  9. res.sendfile(__dirname + '/style.css');
  10. });
  11. io.sockets.on('connection', function(socket) {
  12. console.log("connection received");
  13. colors[socket.id] = Math.floor(Math.random()* 0xFFFFFF)
  14. socket.on('chat msg', function(msg) {
  15. console.log("chat received");
  16. socket.broadcast.emit('receive chat msg', {
  17. msg: msg,
  18. color: colors[socket.id]
  19. });
  20. });
  21. });