-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
41 lines (39 loc) · 1.43 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
var http = require('http');
var express = require('express');
var app = express();
var server = http.createServer(app).listen(3001);
var io = require('socket.io').listen(server);
io.set('log level', 1);
io.set('transports', ['websocket', 'polling']);
app.use(function (req, res, next) {
res.setHeader("X-UA-Compatible", "chrome=1");
return next();
});
app.use(express.static(__dirname + '/public'));
io.sockets.on('connection', function(socket) {
socket.on('CreateSession', function(msg){
socket.join(msg);
});
socket.on('PageChange', function(msg){
socket.join(msg);
io.sockets.in(msg).emit('SessionStarted', '');
console.log('PageChange');
});
socket.on('JoinRoom', function(msg){
socket.join(msg);
io.sockets.in(msg).emit('SessionStarted', '');
});
socket.on('ClientMousePosition', function(msg){
socket.broadcast.to(msg.room).emit('ClientMousePosition', {PositionLeft:msg.PositionLeft, PositionTop:msg.PositionTop});
});
socket.on('AdminMousePosition', function(msg){
socket.broadcast.to(msg.room).emit('AdminMousePosition', {PositionLeft:msg.PositionLeft, PositionTop:msg.PositionTop});
});
socket.on('changeHappened', function(msg){
socket.broadcast.to(msg.room).emit('changes', msg.change);
});
socket.on('DOMLoaded', function(msg){
socket.broadcast.to(msg.room).emit('DOMLoaded', '');
});
});
app.listen(3000);