-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
38 lines (28 loc) · 894 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
var transports = {
longpolling: require('./http.js').longpolling,
shortpolling: require('./http.js').shortpolling,
websocket: require('./ws.js')
};
exports.transports = transports;
/**
* Creates a stream over which we can receive messages asynchronously
*
* @param {Object} config Configuration for the message stream system
* @returns {Object} The stream instance, or undefined if none is usable
*/
exports.create = function (config) {
var detect = config.detect || [];
for (var i = 0; i < detect.length; i += 1) {
var type = detect[i];
var cfg = config.transports[type] || {};
var transport = transports[type];
if (!transport) {
console.log('Unrecognized transport type:', type, '(skipping)');
continue;
}
if (transport.test(cfg)) {
return transport.create(cfg);
}
}
console.warn('Could not create any transport out of:', detect);
};