-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
60 lines (49 loc) · 984 Bytes
/
index.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
/*
Reach Socket
============
Stability: 2 - Unstable
@author Christoffer Rødvik (C) 2015
@github https://github.com/kodemon/reach-socket
@license MIT
*/
'use strict';
// ### Dependencies
var cluster = require('cluster');
// ### Reach Socket
var reach = module.exports = {};
/**
* @property io
* @type object
*/
reach.io = null;
/**
* Initiates the socket.io server
* @method init
* @param {object} config
* @param {object} [ssl]
*/
reach.init = function (config, ssl) {
if (cluster.isMaster) {
require('./server')(config, ssl);
}
this.io = require('./client')(config);
};
/**
* Inits and returns the koa middleware client
* @method koa
* @return {function}
*/
reach.koa = function () {
return require('./koa')(reach.io);
};
/**
* Inits and returns the express middleware client
* @method koa
* @return {function}
*/
reach.express = function () {
return function (req, res, next) {
res.io = reach.io;
next();
};
};