-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
40 lines (32 loc) · 1.14 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
var settings = require('./settings')
, app = require('express')()
, server = require('http').Server(app)
, io = require('socket.io')(server)
, redis = require('socket.io-redis')
, kue = require('kue')
, jobs = kue.createQueue();
server.listen(5555);
app.get('/', function (req, res) {
res.sendFile(__dirname + '/index.html');
});
io.adapter(redis(settings.redis));
io.on('connection', function (socket) {
socket.emit('server-hello', { message: 'server: hello ' + socket.id });
var new_user_job =
jobs.create('new_user', { id: socket.id })
.save(function(err){
if( !err ) console.log( 'new user job created: ' + new_user_job.id );
})
.removeOnComplete(true);;
socket.on('client-update', function (data) {
var challenge_job =
jobs.create('challenge', { id: socket.id, challenge: data.challenge })
.save(function(err){
if( !err ) console.log( 'new challenge job created: ' + challenge_job.id );
})
.removeOnComplete(true);
});
socket.on('client-hello', function (data) {
console.log(data);
});
});