-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathworker.js
38 lines (28 loc) · 964 Bytes
/
worker.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
var fs = require('fs');
var express = require('express');
var serveStatic = require('serve-static');
var path = require('path');
module.exports.run = function (worker) {
console.log(' >> Worker PID:', process.pid);
var app = require('express')();
// Get a reference to our raw Node HTTP server
var httpServer = worker.getHTTPServer();
// Get a reference to our realtime SocketCluster server
var scServer = worker.getSCServer();
app.use(serveStatic(path.resolve(__dirname, 'public')));
httpServer.on('request', app);
var count = 0;
/*
In here we handle our incoming realtime connections and listen for events.
*/
scServer.on('connection', function (socket) {
console.log('User connected');
socket.on('chat', function (data) {
scServer.global.publish('yell', data);
console.log('Chat:', data);
});
socket.on('disconnect', function () {
console.log('User disconnected');
});
});
};