|
2 | 2 | (function (__dirname, module) {
|
3 | 3 | "use strict";
|
4 | 4 |
|
5 |
| - var redis = require('socket.io-redis'), |
| 5 | + var |
| 6 | + RedisStore = require('socket.io/lib/stores/redis'), |
| 7 | + redis = require('socket.io/node_modules/redis'), |
6 | 8 | fs = require('fs'),
|
7 | 9 | path = require("path"),
|
8 | 10 | socket = require("socket.io"),
|
9 | 11 | // MongoStore = require('mong.socket.io'),
|
10 |
| -// MongoStore = require('socket.io-mongo'), |
| 12 | + MongoStore = require('socket.io-mongo'), |
11 | 13 | hbars = require("handlebars");
|
12 | 14 |
|
13 | 15 | function locate(dirs, file, cb, idx) {
|
|
19 | 21 |
|
20 | 22 | var qfile = path.join(dirs[i], file);
|
21 | 23 |
|
22 |
| - return fs.exists(qfile, function (exists) { |
| 24 | + return path.exists(qfile, function (exists) { |
23 | 25 | if (exists) {
|
24 | 26 | return cb(undefined, qfile);
|
25 | 27 | }
|
|
28 | 30 | });
|
29 | 31 | }
|
30 | 32 |
|
31 |
| - function listen(app, logger, hidden) { |
| 33 | + function listen(app, logger, secure, hidden) { |
32 | 34 |
|
33 | 35 | var server = app.httpServer;
|
34 | 36 |
|
|
46 | 48 | warn: logger.warn,
|
47 | 49 | error: logger.error
|
48 | 50 | },
|
49 |
| - secure: hidden.secure |
| 51 | + secure: secure |
50 | 52 | });
|
51 | 53 |
|
52 |
| - io.on('connection', function () { |
53 |
| - io.set('transports', ['websocket', 'htmlfile', 'xhr-polling', 'jsonp-polling', 'polling']); |
54 |
| - |
55 |
| - //io.eio.pingInterval = 60000; |
56 |
| - //io.eio.pingTimeout = 60000; |
57 |
| - |
58 |
| - io.set('log level', 1); |
| 54 | + io.configure('production', function () { |
| 55 | + io.enable('browser client etag'); // apply etag caching logic based on version number |
| 56 | + io.enable('browser client gzip'); // gzip the file |
| 57 | + io.enable('browser client minification'); // send minified client |
| 58 | +// io.enable('match origin protocol'); |
59 | 59 | });
|
| 60 | + io.configure(function () { |
60 | 61 |
|
61 |
| - io.adapter(redis({ |
62 |
| - host: hidden.redis.host, |
63 |
| - port: hidden.redis.port |
64 |
| - })); |
| 62 | +// io.set('transports', ['websocket', 'htmlfile', 'xhr-polling', 'jsonp-polling']); |
| 63 | + io.set('transports', ['websocket', 'htmlfile', 'xhr-polling', 'jsonp-polling']); |
| 64 | + io.set('log level', 1); |
65 | 65 |
|
| 66 | + if (hidden.mongo_storage) { |
| 67 | + var store = new MongoStore({url: hidden.mongodb}); |
| 68 | + } else if (hidden.redis_storage) { |
| 69 | + var pub = redis.createClient(hidden.redis.port, hidden.redis.host); |
| 70 | + var sub = redis.createClient(hidden.redis.port, hidden.redis.host); |
| 71 | + var client = redis.createClient(hidden.redis.port, hidden.redis.host); |
| 72 | + |
| 73 | + var store = new RedisStore({ |
| 74 | + redisClient: client, |
| 75 | + redisPub: pub, |
| 76 | + redisSub: sub |
| 77 | + }); |
| 78 | + } |
| 79 | + if(hidden.mongo_storage || hidden.redis_storage) { |
| 80 | + store.on('error', hidden.logger.error); |
| 81 | + io.set('store', store); |
| 82 | + } |
| 83 | + }); |
| 84 | +// io.configure('development', function () { |
| 85 | +//// io.set('transports', ['websocket', 'htmlfile', 'xhr-polling', 'jsonp-polling']); |
| 86 | +// |
| 87 | +// io.set('transports', ['websocket']); |
| 88 | +// }); |
66 | 89 | io.sockets.on('connection', function (client) {
|
67 | 90 | hidden.active = true;
|
68 | 91 | var topics = Object.keys(hidden.listeners);
|
|
100 | 123 | if (err) {
|
101 | 124 | throw err;
|
102 | 125 | }
|
| 126 | + |
103 | 127 | var template = hbars.compile(content);
|
104 | 128 | var body = template({
|
105 | 129 | secureClient: hidden.secureClient,
|
106 | 130 | secure: hidden.secure,
|
107 |
| - port: hidden.secureClient ? hidden.sslPort : hidden.listenPort |
| 131 | + port: hidden.secure ? hidden.sslPort : hidden.listenPort |
108 | 132 | }),
|
109 | 133 | ctl = hidden.logger.isDebugging ? 'NO-CACHE' : 'public, max-age=' + (defaults.maxAge / 1000),
|
110 | 134 | headers = {
|
|
147 | 171 | redis: lopts.redis || gopts.redis,
|
148 | 172 | secureClient: lopts.secureClient || gopts.secureClient || lopts.secure || gopts.secure || !!app.httpsServer,
|
149 | 173 | secure: lopts.secure || gopts.secure || !!app.httpsServer,
|
150 |
| - //listenPort: lopts.advertizedListenPort || gopts.advertizedListenPort || app.listenPort, |
151 |
| - listenPort: app.listenPort || lopts.advertizedListenPort || gopts.advertizedListenPort, |
| 174 | + listenPort: lopts.advertizedListenPort || gopts.advertizedListenPort || app.listenPort, |
152 | 175 | sslPort: lopts.advertizedSslPort || gopts.advertizedSslPort || app.sslPort,
|
153 | 176 | logger: app.logger,
|
154 | 177 | listeners: {},
|
155 | 178 | active: false,
|
156 | 179 | mongo_storage: lopts.mongo_storage || gopts.mongo_storage,
|
157 | 180 | redis_storage: lopts.redis_storage || gopts.redis_storage,
|
158 | 181 | mongodb: lopts.mongoose || gopts.mongoose
|
159 |
| - }, |
160 |
| - requestHandler = getRequestHandler(hidden, defaults); |
161 |
| - |
162 |
| - listen(app, app.logger, hidden); |
| 182 | + }; |
| 183 | + listen(app, app.logger, false, hidden); |
163 | 184 |
|
164 |
| - app.use(requestHandler); |
| 185 | + //app.use(requestHandler); |
165 | 186 |
|
166 | 187 | return cb(undefined, {
|
167 | 188 | secure: hidden.secure,
|
|
0 commit comments