UNPKG

2.58 kBJavaScriptView Raw
1var settings = require('./config/settings');
2
3module.exports = function(server) {
4 var io = require('socket.io').listen(server);
5
6 /**
7 * https://github.com/LearnBoost/Socket.IO/wiki/Configuring-Socket.IO
8 */
9 io.configure('production', function() {
10 // The following options are advised to be set in production
11 io.enable('browser client minification'); // send minified client
12 io.enable('browser client etag'); // apply etag caching logic based on version number
13 io.enable('browser client gzip'); // gzip the file
14 io.set('log level', 1); // reduce logging
15
16 // enable all transports (optional if you want flashsocket support, please note that some hosting
17 // providers do not allow you to create servers that listen on a port different than 80 or their
18 // default port)
19 io.set('transports', [
20 'websocket',
21 'flashsocket',
22 'htmlfile',
23 'xhr-polling',
24 'jsonp-polling'
25 ]);
26
27 /**
28 * Heroku has provided their own recommended set of options because they do not support WebSockets unlike other hosting services.
29 * https://devcenter.heroku.com/articles/using-socket-io-with-node-js-on-heroku
30 *
31 * io.set("transports", ["xhr-polling"]);
32 * io.set("polling duration", 10);
33 */
34 });
35
36 io.configure('development', function() {
37 });
38
39 if (settings['socket.io'].redis) {
40 var redis = require('socket.io/node_modules/redis'),
41 pub = redis.createClient(),
42 sub = redis.createClient(),
43 client = redis.createClient();
44
45 /**
46 * If your Redis server uses a password, you must auth the client objects ahead of time, and
47 * you must pass in the redis module you used to create those clients as an option to the
48 * RedisStore constructor:
49 */
50 /*
51 pub.auth('password', function(err) {
52 if (err) {
53 throw err;
54 }
55 });
56 sub.auth('password', function(err) {
57 if (err) {
58 throw err;
59 }
60 });
61 client.auth('password', function(err) {
62 if (err) {
63 throw err;
64 }
65 });
66 */
67
68 var RedisStore = require('socket.io/lib/stores/redis');
69 io.set('store', new RedisStore({
70 redisPub: pub,
71 redisSub: sub,
72 redisClient: client
73 }));
74 }
75
76 return io;
77};