forked from GavinJoyce/ember-present
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
47 lines (36 loc) · 1.24 KB
/
index.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
42
43
44
45
46
47
'use strict';
const DEFAULT_SOCKET_SERVER_PORT = 5200;
let currentSlide;
module.exports = {
name: 'ember-present',
included(app) {
app.import('vendor/ember-present.css');
},
serverMiddleware: function(config) {
let configPath = config.options.project.configPath();
let env = require(configPath)(config.options.environment); //TODO: there must be a simpler way
let socketServerPort = env.emberPresent.socketServerPort || DEFAULT_SOCKET_SERVER_PORT;
let app = config.app;
let http = require('http').Server(app);
let io = require('socket.io')(http);
http.listen(socketServerPort, function() {
console.log('socket server listening on *:' + socketServerPort);
});
io.on('connection', function(socket) {
console.log('GJ: SOCKET CONNECT', socket.id);
socket.on('disconnect', function() {
console.log('GJ: SOCKET DISCONNECT', socket.id);
});
//TODO: lock down to presenter role
socket.on('goToSlide', function(data) {
currentSlide = data.slide;
io.emit('goToSlide', data);
});
socket.on('setInitialSlideState', function() {
if (currentSlide) {
socket.emit('goToSlide', { slide: currentSlide });
}
});
});
}
};