-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
60 lines (48 loc) · 2 KB
/
server.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
48
49
50
51
52
53
54
55
56
57
58
59
60
var express = require('express')
, app = express()
, server = require('http').createServer(app)
, io = require('socket.io').listen(server)
, util = require('util');
app.configure(function() {
app.use(express.static(__dirname + '/public'));
app.get('/associate', function (req, res) {
res.sendfile(__dirname + '/public/associate.html');
})
});
// io.set('log level', 2);
// io.enable('browser client minification'); // send minified client
// io.enable('browser client etag'); // apply etag caching logic based on version number
// io.enable('browser client gzip'); // gzip the file
// io.set('log level', 1); // reduce logging
io.sockets.on('connection', function (socket) {
socket.send('Connection established!', function () {
// ack
});
socket.on('subscribe', function (data) {
socket.join(data.room);
console.log('-> ' + socket.id + ' was added to room: ' + data.room);
});
console.log('-> client ' + socket.id + ' has connected');
console.log('-> there are now ' + io.sockets.clients().length + ' connection(s)');
socket.on('disconnect', function () {
console.log('-> client ' + socket.id + ' has disconnected');
console.log('-> there are now ' + io.sockets.clients().length + ' connection(s)');
});
socket.on('requestSubmitted', function (data) {
console.log('-> A new request has been submitted!');
console.log({ "clientId" : socket.id, "request": data });
io.sockets.in('associates').emit('requestQueueUpdated', {
"clientId" : socket.id,
"request": data
});
io.sockets.socket(socket.id).emit('requestReceived');
});
socket.on('itemProcessed', function (data) {
console.log('-> Associate has retrieved an item!');
io.sockets.socket(data.clientId).emit('itemReady');
})
socket.on('requestCompleted', function (data) {
io.sockets.socket(data.clientId).emit('complete');
})
});
server.listen(process.env.VMC_APP_PORT || 8080, null);