2015-09-19 16:02:05 +00:00
|
|
|
var
|
|
|
|
io = require('socket.io').listen(5001),
|
|
|
|
signalServer = require('./signal'),
|
|
|
|
stunservers = [{"url": "stun:stun.l.google.com:19302"}];
|
2014-02-10 07:03:06 +00:00
|
|
|
|
|
|
|
function start() {
|
2013-04-26 04:07:29 +00:00
|
|
|
|
2015-09-19 16:02:05 +00:00
|
|
|
signalServer(io, stunservers);
|
|
|
|
|
2014-06-04 20:24:13 +00:00
|
|
|
io.on('connection', function (socket) {
|
|
|
|
|
|
|
|
// this will ping a new person with awareness of who's already on the map
|
|
|
|
socket.on('updateNewMapperList', function (data) {
|
|
|
|
var existingUser = {
|
|
|
|
userid: data.userid,
|
2014-06-11 20:47:46 +00:00
|
|
|
username: data.username,
|
2014-09-03 23:05:25 +00:00
|
|
|
userrealtime: data.userrealtime,
|
|
|
|
userimage: data.userimage
|
2014-06-04 20:24:13 +00:00
|
|
|
};
|
|
|
|
socket.broadcast.emit(data.userToNotify + '-' + data.mapid + '-UpdateMapperList', existingUser);
|
2014-06-04 19:24:16 +00:00
|
|
|
});
|
2014-06-04 20:24:13 +00:00
|
|
|
|
|
|
|
// this will ping everyone on a map that there's a person just joined the map
|
|
|
|
socket.on('newMapperNotify', function (data) {
|
|
|
|
socket.set('mapid', data.mapid);
|
|
|
|
socket.set('userid', data.userid);
|
|
|
|
socket.set('username', data.username);
|
|
|
|
|
|
|
|
var newUser = {
|
|
|
|
userid: data.userid,
|
2014-09-03 23:05:25 +00:00
|
|
|
username: data.username,
|
|
|
|
userimage: data.userimage
|
2014-06-04 20:24:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
socket.broadcast.emit('maps-' + data.mapid + '-newmapper', newUser);
|
2014-06-04 19:24:16 +00:00
|
|
|
});
|
2014-06-04 20:24:13 +00:00
|
|
|
|
2014-10-27 16:03:55 +00:00
|
|
|
var end = function () {
|
2014-06-04 20:24:13 +00:00
|
|
|
var socketUserName, socketUserID;
|
|
|
|
socket.get('userid', function (err, id) {
|
|
|
|
socketUserID = id;
|
|
|
|
});
|
|
|
|
socket.get('username', function (err, name) {
|
|
|
|
socketUserName = name;
|
|
|
|
});
|
|
|
|
var data = {
|
|
|
|
username: socketUserName,
|
|
|
|
userid: socketUserID
|
|
|
|
};
|
|
|
|
socket.get('mapid', function (err, mapid) {
|
|
|
|
socket.broadcast.emit('maps-' + mapid + '-lostmapper', data);
|
|
|
|
});
|
2014-10-27 16:03:55 +00:00
|
|
|
};
|
|
|
|
// this will ping everyone on a map that there's a person just left the map
|
|
|
|
socket.on('disconnect', end);
|
|
|
|
socket.on('endMapperNotify', end);
|
2014-06-09 20:37:09 +00:00
|
|
|
|
|
|
|
// this will ping everyone on a map that someone just turned on realtime
|
|
|
|
socket.on('notifyStartRealtime', function (data) {
|
|
|
|
var newUser = {
|
|
|
|
userid: data.userid,
|
|
|
|
username: data.username
|
|
|
|
};
|
|
|
|
|
|
|
|
socket.broadcast.emit('maps-' + data.mapid + '-newrealtime', newUser);
|
|
|
|
});
|
|
|
|
|
|
|
|
// this will ping everyone on a map that someone just turned on realtime
|
|
|
|
socket.on('notifyStopRealtime', function (data) {
|
|
|
|
var newUser = {
|
|
|
|
userid: data.userid,
|
|
|
|
username: data.username
|
|
|
|
};
|
|
|
|
|
|
|
|
socket.broadcast.emit('maps-' + data.mapid + '-lostrealtime', newUser);
|
|
|
|
});
|
2014-06-04 20:24:13 +00:00
|
|
|
|
2014-09-09 22:17:39 +00:00
|
|
|
socket.on('updateMapperCoords', function (data) {
|
|
|
|
var peer = {
|
|
|
|
userid: data.userid,
|
|
|
|
usercoords: data.usercoords
|
|
|
|
};
|
|
|
|
|
|
|
|
socket.broadcast.emit('maps-' + data.mapid + '-updatePeerCoords', peer);
|
|
|
|
});
|
|
|
|
|
2014-09-30 20:55:25 +00:00
|
|
|
socket.on('topicDrag', function (data) {
|
|
|
|
var mapId = data.mapid;
|
|
|
|
delete data.mapid;
|
|
|
|
|
|
|
|
socket.broadcast.emit('maps-' + mapId + '-topicDrag', data);
|
|
|
|
});
|
|
|
|
|
|
|
|
socket.on('newTopic', function (data) {
|
|
|
|
var mapId = data.mapid;
|
|
|
|
delete data.mapid;
|
|
|
|
|
|
|
|
socket.broadcast.emit('maps-' + mapId + '-newTopic', data);
|
|
|
|
});
|
|
|
|
|
2014-10-27 16:03:55 +00:00
|
|
|
socket.on('topicChangeFromClient', function (data) {
|
|
|
|
socket.broadcast.emit('topicChangeFromServer', data);
|
|
|
|
});
|
|
|
|
|
|
|
|
socket.on('synapseChangeFromClient', function (data) {
|
|
|
|
socket.broadcast.emit('synapseChangeFromServer', data);
|
|
|
|
});
|
|
|
|
|
|
|
|
socket.on('mapChangeFromClient', function (data) {
|
|
|
|
socket.broadcast.emit('mapChangeFromServer', data);
|
|
|
|
});
|
|
|
|
|
|
|
|
socket.on('deleteTopicFromClient', function (data) {
|
|
|
|
socket.broadcast.emit('deleteTopicFromServer', data);
|
|
|
|
});
|
|
|
|
|
2014-09-30 20:55:25 +00:00
|
|
|
socket.on('removeTopic', function (data) {
|
|
|
|
var mapId = data.mapid;
|
|
|
|
delete data.mapid;
|
|
|
|
|
|
|
|
socket.broadcast.emit('maps-' + mapId + '-removeTopic', data);
|
|
|
|
});
|
|
|
|
|
|
|
|
socket.on('newSynapse', function (data) {
|
|
|
|
var mapId = data.mapid;
|
|
|
|
delete data.mapid;
|
|
|
|
|
|
|
|
socket.broadcast.emit('maps-' + mapId + '-newSynapse', data);
|
|
|
|
});
|
|
|
|
|
2014-10-27 16:03:55 +00:00
|
|
|
socket.on('deleteSynapseFromClient', function (data) {
|
|
|
|
socket.broadcast.emit('deleteSynapseFromServer', data);
|
|
|
|
});
|
|
|
|
|
2014-09-30 20:55:25 +00:00
|
|
|
socket.on('removeSynapse', function (data) {
|
|
|
|
var mapId = data.mapid;
|
|
|
|
delete data.mapid;
|
|
|
|
|
|
|
|
socket.broadcast.emit('maps-' + mapId + '-removeSynapse', data);
|
|
|
|
});
|
|
|
|
|
2014-06-04 19:24:16 +00:00
|
|
|
});
|
2014-02-10 07:03:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
start();
|