faye 1.4.1 → 1.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/LICENSE.md +1 -1
- package/client/faye-browser-min.js +1 -1
- package/client/faye-browser-min.js.map +1 -1
- package/client/faye-browser.js +228 -851
- package/client/faye-browser.js.map +1 -1
- package/package.json +3 -7
- package/src/adapters/node_adapter.js +37 -33
- package/src/adapters/static_server.js +12 -11
- package/src/engines/connection.js +2 -3
- package/src/engines/memory.js +32 -27
- package/src/engines/proxy.js +19 -20
- package/src/mixins/deferrable.js +16 -12
- package/src/mixins/logging.js +8 -8
- package/src/mixins/publisher.js +2 -3
- package/src/mixins/timeouts.js +9 -9
- package/src/protocol/channel.js +11 -16
- package/src/protocol/client.js +24 -21
- package/src/protocol/dispatcher.js +14 -14
- package/src/protocol/error.js +5 -6
- package/src/protocol/extensible.js +2 -3
- package/src/protocol/scheduler.js +5 -6
- package/src/protocol/server.js +25 -27
- package/src/protocol/socket.js +2 -1
- package/src/protocol/subscription.js +5 -5
- package/src/transport/cors.js +13 -14
- package/src/transport/event_source.js +12 -12
- package/src/transport/jsonp.js +13 -15
- package/src/transport/node_http.js +27 -19
- package/src/transport/node_local.js +3 -5
- package/src/transport/transport.js +29 -23
- package/src/transport/web_socket.js +16 -15
- package/src/transport/xhr.js +10 -9
- package/src/util/array.js +6 -5
- package/src/util/browser/event.js +6 -4
- package/src/util/class.js +1 -3
- package/src/util/constants.js +1 -1
- package/src/util/copy_object.js +6 -2
- package/src/util/namespace.js +6 -6
- package/src/util/set.js +10 -22
- package/src/util/uri.js +8 -67
- package/src/util/validate_options.js +3 -2
- package/src/util/assign.js +0 -16
- package/src/util/promise.js +0 -172
package/src/protocol/channel.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var Class = require('../util/class'),
|
|
4
|
-
assign = require('../util/assign'),
|
|
5
4
|
Publisher = require('../mixins/publisher'),
|
|
6
5
|
Grammar = require('./grammar');
|
|
7
6
|
|
|
@@ -19,9 +18,9 @@ var Channel = Class({
|
|
|
19
18
|
}
|
|
20
19
|
});
|
|
21
20
|
|
|
22
|
-
assign(Channel.prototype, Publisher);
|
|
21
|
+
Object.assign(Channel.prototype, Publisher);
|
|
23
22
|
|
|
24
|
-
assign(Channel, {
|
|
23
|
+
Object.assign(Channel, {
|
|
25
24
|
HANDSHAKE: '/meta/handshake',
|
|
26
25
|
CONNECT: '/meta/connect',
|
|
27
26
|
SUBSCRIBE: '/meta/subscribe',
|
|
@@ -79,17 +78,15 @@ assign(Channel, {
|
|
|
79
78
|
|
|
80
79
|
Set: Class({
|
|
81
80
|
initialize: function() {
|
|
82
|
-
this._channels =
|
|
81
|
+
this._channels = new Map();
|
|
83
82
|
},
|
|
84
83
|
|
|
85
84
|
getKeys: function() {
|
|
86
|
-
|
|
87
|
-
for (var key in this._channels) keys.push(key);
|
|
88
|
-
return keys;
|
|
85
|
+
return [...this._channels.keys()];
|
|
89
86
|
},
|
|
90
87
|
|
|
91
88
|
remove: function(name) {
|
|
92
|
-
|
|
89
|
+
this._channels.delete(name);
|
|
93
90
|
},
|
|
94
91
|
|
|
95
92
|
hasSubscription: function(name) {
|
|
@@ -97,16 +94,14 @@ assign(Channel, {
|
|
|
97
94
|
},
|
|
98
95
|
|
|
99
96
|
subscribe: function(names, subscription) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
name
|
|
103
|
-
var channel = this._channels[name] = this._channels[name] || new Channel(name);
|
|
104
|
-
channel.bind('message', subscription);
|
|
97
|
+
for (let name of names) {
|
|
98
|
+
if (!this._channels.has(name)) this._channels.set(name, new Channel(name));
|
|
99
|
+
this._channels.get(name).bind('message', subscription);
|
|
105
100
|
}
|
|
106
101
|
},
|
|
107
102
|
|
|
108
103
|
unsubscribe: function(name, subscription) {
|
|
109
|
-
var channel = this._channels
|
|
104
|
+
var channel = this._channels.get(name);
|
|
110
105
|
if (!channel) return false;
|
|
111
106
|
channel.unbind('message', subscription);
|
|
112
107
|
|
|
@@ -121,8 +116,8 @@ assign(Channel, {
|
|
|
121
116
|
distributeMessage: function(message) {
|
|
122
117
|
var channels = Channel.expand(message.channel);
|
|
123
118
|
|
|
124
|
-
for (
|
|
125
|
-
var channel = this._channels
|
|
119
|
+
for (let chan of channels) {
|
|
120
|
+
var channel = this._channels.get(chan);
|
|
126
121
|
if (channel) channel.trigger('message', message);
|
|
127
122
|
}
|
|
128
123
|
}
|
package/src/protocol/client.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
Class = require('../util/class'),
|
|
5
|
-
Promise = require('../util/promise'),
|
|
3
|
+
var Class = require('../util/class'),
|
|
6
4
|
array = require('../util/array'),
|
|
7
5
|
browser = require('../util/browser'),
|
|
8
6
|
constants = require('../util/constants'),
|
|
9
|
-
assign = require('../util/assign'),
|
|
10
7
|
validateOptions = require('../util/validate_options'),
|
|
11
8
|
Deferrable = require('../mixins/deferrable'),
|
|
12
9
|
Logging = require('../mixins/logging'),
|
|
@@ -45,7 +42,7 @@ var Client = Class({ className: 'Client',
|
|
|
45
42
|
this._messageId = 0;
|
|
46
43
|
this._state = this.UNCONNECTED;
|
|
47
44
|
|
|
48
|
-
this._responseCallbacks =
|
|
45
|
+
this._responseCallbacks = new Map();
|
|
49
46
|
|
|
50
47
|
this._advice = {
|
|
51
48
|
reconnect: this.RETRY,
|
|
@@ -56,11 +53,13 @@ var Client = Class({ className: 'Client',
|
|
|
56
53
|
|
|
57
54
|
this._dispatcher.bind('message', this._receiveMessage, this);
|
|
58
55
|
|
|
59
|
-
if (browser.Event && global.onbeforeunload !== undefined)
|
|
56
|
+
if (browser.Event && global.onbeforeunload !== undefined) {
|
|
60
57
|
browser.Event.on(global, 'beforeunload', function() {
|
|
61
|
-
if (array.indexOf(this._dispatcher._disabled, 'autodisconnect') < 0)
|
|
58
|
+
if (array.indexOf(this._dispatcher._disabled, 'autodisconnect') < 0) {
|
|
62
59
|
this.disconnect();
|
|
60
|
+
}
|
|
63
61
|
}, this);
|
|
62
|
+
}
|
|
64
63
|
},
|
|
65
64
|
|
|
66
65
|
addWebsocketExtension: function(extension) {
|
|
@@ -120,7 +119,7 @@ var Client = Class({ className: 'Client',
|
|
|
120
119
|
this.info('Handshake successful: ?', this._dispatcher.clientId);
|
|
121
120
|
|
|
122
121
|
this.subscribe(this._channels.getKeys(), true);
|
|
123
|
-
if (callback)
|
|
122
|
+
if (callback) Promise.resolve().then(function() { callback.call(context) });
|
|
124
123
|
|
|
125
124
|
} else {
|
|
126
125
|
this.info('Handshake unsuccessful');
|
|
@@ -143,8 +142,9 @@ var Client = Class({ className: 'Client',
|
|
|
143
142
|
if (this._advice.reconnect === this.NONE) return;
|
|
144
143
|
if (this._state === this.DISCONNECTED) return;
|
|
145
144
|
|
|
146
|
-
if (this._state === this.UNCONNECTED)
|
|
145
|
+
if (this._state === this.UNCONNECTED) {
|
|
147
146
|
return this.handshake(function() { this.connect(callback, context) }, this);
|
|
147
|
+
}
|
|
148
148
|
|
|
149
149
|
this.callback(callback, context);
|
|
150
150
|
if (this._state !== this.CONNECTED) return;
|
|
@@ -210,10 +210,11 @@ var Client = Class({ className: 'Client',
|
|
|
210
210
|
// * id
|
|
211
211
|
// * timestamp
|
|
212
212
|
subscribe: function(channel, callback, context) {
|
|
213
|
-
if (channel instanceof Array)
|
|
213
|
+
if (channel instanceof Array) {
|
|
214
214
|
return array.map(channel, function(c) {
|
|
215
215
|
return this.subscribe(c, callback, context);
|
|
216
216
|
}, this);
|
|
217
|
+
}
|
|
217
218
|
|
|
218
219
|
var subscription = new Subscription(this, channel, callback, context),
|
|
219
220
|
force = (callback === true),
|
|
@@ -260,10 +261,11 @@ var Client = Class({ className: 'Client',
|
|
|
260
261
|
// * id
|
|
261
262
|
// * timestamp
|
|
262
263
|
unsubscribe: function(channel, subscription) {
|
|
263
|
-
if (channel instanceof Array)
|
|
264
|
+
if (channel instanceof Array) {
|
|
264
265
|
return array.map(channel, function(c) {
|
|
265
266
|
return this.unsubscribe(c, subscription);
|
|
266
267
|
}, this);
|
|
268
|
+
}
|
|
267
269
|
|
|
268
270
|
var dead = this._channels.unsubscribe(channel, subscription);
|
|
269
271
|
if (!dead) return;
|
|
@@ -304,10 +306,11 @@ var Client = Class({ className: 'Client',
|
|
|
304
306
|
clientId: this._dispatcher.clientId
|
|
305
307
|
|
|
306
308
|
}, options, function(response) {
|
|
307
|
-
if (response.successful)
|
|
309
|
+
if (response.successful) {
|
|
308
310
|
publication.setDeferredStatus('succeeded');
|
|
309
|
-
else
|
|
311
|
+
} else {
|
|
310
312
|
publication.setDeferredStatus('failed', Error.parse(response.error));
|
|
313
|
+
}
|
|
311
314
|
}, this);
|
|
312
315
|
}, this);
|
|
313
316
|
|
|
@@ -323,7 +326,7 @@ var Client = Class({ className: 'Client',
|
|
|
323
326
|
|
|
324
327
|
this.pipeThroughExtensions('outgoing', message, null, function(message) {
|
|
325
328
|
if (!message) return;
|
|
326
|
-
if (callback) this._responseCallbacks
|
|
329
|
+
if (callback) this._responseCallbacks.set(message.id, [callback, context]);
|
|
327
330
|
this._dispatcher.sendMessage(message, timeout, options || {});
|
|
328
331
|
}, this);
|
|
329
332
|
},
|
|
@@ -338,8 +341,8 @@ var Client = Class({ className: 'Client',
|
|
|
338
341
|
var id = message.id, callback;
|
|
339
342
|
|
|
340
343
|
if (message.successful !== undefined) {
|
|
341
|
-
callback = this._responseCallbacks
|
|
342
|
-
|
|
344
|
+
callback = this._responseCallbacks.get(id);
|
|
345
|
+
this._responseCallbacks.delete(id);
|
|
343
346
|
}
|
|
344
347
|
|
|
345
348
|
this.pipeThroughExtensions('incoming', message, null, function(message) {
|
|
@@ -351,7 +354,7 @@ var Client = Class({ className: 'Client',
|
|
|
351
354
|
},
|
|
352
355
|
|
|
353
356
|
_handleAdvice: function(advice) {
|
|
354
|
-
assign(this._advice, advice);
|
|
357
|
+
Object.assign(this._advice, advice);
|
|
355
358
|
this._dispatcher.timeout = this._advice.timeout / 1000;
|
|
356
359
|
|
|
357
360
|
if (this._advice.reconnect === this.HANDSHAKE && this._state !== this.DISCONNECTED) {
|
|
@@ -377,9 +380,9 @@ var Client = Class({ className: 'Client',
|
|
|
377
380
|
}
|
|
378
381
|
});
|
|
379
382
|
|
|
380
|
-
assign(Client.prototype, Deferrable);
|
|
381
|
-
assign(Client.prototype, Publisher);
|
|
382
|
-
assign(Client.prototype, Logging);
|
|
383
|
-
assign(Client.prototype, Extensible);
|
|
383
|
+
Object.assign(Client.prototype, Deferrable);
|
|
384
|
+
Object.assign(Client.prototype, Publisher);
|
|
385
|
+
Object.assign(Client.prototype, Logging);
|
|
386
|
+
Object.assign(Client.prototype, Extensible);
|
|
384
387
|
|
|
385
388
|
module.exports = Client;
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
var Class = require('../util/class'),
|
|
4
4
|
URI = require('../util/uri'),
|
|
5
5
|
cookies = require('../util/cookies'),
|
|
6
|
-
assign = require('../util/assign'),
|
|
7
6
|
Logging = require('../mixins/logging'),
|
|
8
7
|
Publisher = require('../mixins/publisher'),
|
|
9
8
|
Transport = require('../transport'),
|
|
@@ -23,7 +22,7 @@ var Dispatcher = Class({ className: 'Dispatcher',
|
|
|
23
22
|
|
|
24
23
|
this.cookies = cookies.CookieJar && new cookies.CookieJar();
|
|
25
24
|
this._disabled = [];
|
|
26
|
-
this._envelopes =
|
|
25
|
+
this._envelopes = new Map();
|
|
27
26
|
this.headers = {};
|
|
28
27
|
this.retry = options.retry || this.DEFAULT_RETRY;
|
|
29
28
|
this._scheduler = options.scheduler || Scheduler;
|
|
@@ -37,15 +36,15 @@ var Dispatcher = Class({ className: 'Dispatcher',
|
|
|
37
36
|
var exts = options.websocketExtensions;
|
|
38
37
|
if (exts) {
|
|
39
38
|
exts = [].concat(exts);
|
|
40
|
-
for (
|
|
41
|
-
this.addWebsocketExtension(exts[i]);
|
|
39
|
+
for (let ext of exts) this.addWebsocketExtension(ext);
|
|
42
40
|
}
|
|
43
41
|
|
|
44
42
|
this.tls = options.tls || {};
|
|
45
43
|
this.tls.ca = this.tls.ca || options.ca;
|
|
46
44
|
|
|
47
|
-
for (
|
|
48
|
-
this._alternates[type] = URI.parse(
|
|
45
|
+
for (let [type, alt] of Object.entries(this._alternates)) {
|
|
46
|
+
this._alternates[type] = URI.parse(alt);
|
|
47
|
+
}
|
|
49
48
|
|
|
50
49
|
this.maxRequestSize = this.MAX_REQUEST_SIZE;
|
|
51
50
|
},
|
|
@@ -95,12 +94,13 @@ var Dispatcher = Class({ className: 'Dispatcher',
|
|
|
95
94
|
var id = message.id,
|
|
96
95
|
attempts = options.attempts,
|
|
97
96
|
deadline = options.deadline && new Date().getTime() + (options.deadline * 1000),
|
|
98
|
-
envelope = this._envelopes
|
|
97
|
+
envelope = this._envelopes.get(id),
|
|
99
98
|
scheduler;
|
|
100
99
|
|
|
101
100
|
if (!envelope) {
|
|
102
101
|
scheduler = new this._scheduler(message, { timeout: timeout, interval: this.retry, attempts: attempts, deadline: deadline });
|
|
103
|
-
envelope
|
|
102
|
+
envelope = { message: message, scheduler: scheduler };
|
|
103
|
+
this._envelopes.set(id, envelope);
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
this._sendEnvelope(envelope);
|
|
@@ -116,7 +116,7 @@ var Dispatcher = Class({ className: 'Dispatcher',
|
|
|
116
116
|
|
|
117
117
|
if (!scheduler.isDeliverable()) {
|
|
118
118
|
scheduler.abort();
|
|
119
|
-
|
|
119
|
+
this._envelopes.delete(message.id);
|
|
120
120
|
return;
|
|
121
121
|
}
|
|
122
122
|
|
|
@@ -129,11 +129,11 @@ var Dispatcher = Class({ className: 'Dispatcher',
|
|
|
129
129
|
},
|
|
130
130
|
|
|
131
131
|
handleResponse: function(reply) {
|
|
132
|
-
var envelope = this._envelopes
|
|
132
|
+
var envelope = this._envelopes.get(reply.id);
|
|
133
133
|
|
|
134
134
|
if (reply.successful !== undefined && envelope) {
|
|
135
135
|
envelope.scheduler.succeed();
|
|
136
|
-
|
|
136
|
+
this._envelopes.delete(reply.id);
|
|
137
137
|
global.clearTimeout(envelope.timer);
|
|
138
138
|
}
|
|
139
139
|
|
|
@@ -145,7 +145,7 @@ var Dispatcher = Class({ className: 'Dispatcher',
|
|
|
145
145
|
},
|
|
146
146
|
|
|
147
147
|
handleError: function(message, immediate) {
|
|
148
|
-
var envelope = this._envelopes
|
|
148
|
+
var envelope = this._envelopes.get(message.id),
|
|
149
149
|
request = envelope && envelope.request,
|
|
150
150
|
self = this;
|
|
151
151
|
|
|
@@ -180,7 +180,7 @@ Dispatcher.create = function(client, endpoint, options) {
|
|
|
180
180
|
return new Dispatcher(client, endpoint, options);
|
|
181
181
|
};
|
|
182
182
|
|
|
183
|
-
assign(Dispatcher.prototype, Publisher);
|
|
184
|
-
assign(Dispatcher.prototype, Logging);
|
|
183
|
+
Object.assign(Dispatcher.prototype, Publisher);
|
|
184
|
+
Object.assign(Dispatcher.prototype, Logging);
|
|
185
185
|
|
|
186
186
|
module.exports = Dispatcher;
|
package/src/protocol/error.js
CHANGED
|
@@ -45,11 +45,10 @@ var errors = {
|
|
|
45
45
|
serverError: [500, 'Internal server error']
|
|
46
46
|
};
|
|
47
47
|
|
|
48
|
-
for (
|
|
49
|
-
|
|
50
|
-
Error
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
})(name);
|
|
48
|
+
for (let [name, [status, msg]] of Object.entries(errors)) {
|
|
49
|
+
Error[name] = function() {
|
|
50
|
+
return new Error(status, arguments, msg).toString();
|
|
51
|
+
};
|
|
52
|
+
}
|
|
54
53
|
|
|
55
54
|
module.exports = Error;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
Logging = require('../mixins/logging');
|
|
3
|
+
var Logging = require('../mixins/logging');
|
|
5
4
|
|
|
6
5
|
var Extensible = {
|
|
7
6
|
addExtension: function(extension) {
|
|
@@ -42,6 +41,6 @@ var Extensible = {
|
|
|
42
41
|
}
|
|
43
42
|
};
|
|
44
43
|
|
|
45
|
-
assign(Extensible, Logging);
|
|
44
|
+
Object.assign(Extensible, Logging);
|
|
46
45
|
|
|
47
46
|
module.exports = Extensible;
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var assign = require('../util/assign');
|
|
4
|
-
|
|
5
3
|
var Scheduler = function(message, options) {
|
|
6
4
|
this.message = message;
|
|
7
5
|
this.options = options;
|
|
8
6
|
this.attempts = 0;
|
|
9
7
|
};
|
|
10
8
|
|
|
11
|
-
assign(Scheduler.prototype, {
|
|
9
|
+
Object.assign(Scheduler.prototype, {
|
|
12
10
|
getTimeout: function() {
|
|
13
11
|
return this.options.timeout;
|
|
14
12
|
},
|
|
@@ -23,11 +21,12 @@ assign(Scheduler.prototype, {
|
|
|
23
21
|
deadline = this.options.deadline,
|
|
24
22
|
now = new Date().getTime();
|
|
25
23
|
|
|
26
|
-
if (attempts !== undefined && made >= attempts)
|
|
24
|
+
if (attempts !== undefined && made >= attempts) {
|
|
27
25
|
return false;
|
|
28
|
-
|
|
29
|
-
if (deadline !== undefined && now > deadline)
|
|
26
|
+
}
|
|
27
|
+
if (deadline !== undefined && now > deadline) {
|
|
30
28
|
return false;
|
|
29
|
+
}
|
|
31
30
|
|
|
32
31
|
return true;
|
|
33
32
|
},
|
package/src/protocol/server.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
var Class = require('../util/class'),
|
|
4
4
|
array = require('../util/array'),
|
|
5
|
-
assign = require('../util/assign'),
|
|
6
5
|
constants = require('../util/constants'),
|
|
7
6
|
Logging = require('../mixins/logging'),
|
|
8
7
|
Engine = require('../engines/proxy'),
|
|
@@ -73,8 +72,8 @@ var Server = Class({ className: 'Server',
|
|
|
73
72
|
}
|
|
74
73
|
};
|
|
75
74
|
|
|
76
|
-
for (
|
|
77
|
-
this.pipeThroughExtensions('incoming',
|
|
75
|
+
for (let message of messages) {
|
|
76
|
+
this.pipeThroughExtensions('incoming', message, request, function(pipedMessage) {
|
|
78
77
|
this._handle(pipedMessage, local, handleReply, this);
|
|
79
78
|
}, this);
|
|
80
79
|
}
|
|
@@ -100,14 +99,15 @@ var Server = Class({ className: 'Server',
|
|
|
100
99
|
error = message.error,
|
|
101
100
|
response;
|
|
102
101
|
|
|
103
|
-
if (Channel.isMeta(channelName))
|
|
102
|
+
if (Channel.isMeta(channelName)) {
|
|
104
103
|
return this._handleMeta(message, local, callback, context);
|
|
105
|
-
|
|
106
|
-
if (!Grammar.CHANNEL_NAME.test(channelName))
|
|
104
|
+
}
|
|
105
|
+
if (!Grammar.CHANNEL_NAME.test(channelName)) {
|
|
107
106
|
error = Error.channelInvalid(channelName);
|
|
108
|
-
|
|
109
|
-
if (message.data === undefined)
|
|
107
|
+
}
|
|
108
|
+
if (message.data === undefined) {
|
|
110
109
|
error = Error.parameterMissing('data');
|
|
110
|
+
}
|
|
111
111
|
|
|
112
112
|
if (!error) this._engine.publish(message);
|
|
113
113
|
|
|
@@ -130,7 +130,7 @@ var Server = Class({ className: 'Server',
|
|
|
130
130
|
|
|
131
131
|
this[method](message, local, function(responses) {
|
|
132
132
|
responses = [].concat(responses);
|
|
133
|
-
for (
|
|
133
|
+
for (let response of responses) this._advize(response, message.connectionType);
|
|
134
134
|
callback.call(context, responses);
|
|
135
135
|
}, this);
|
|
136
136
|
},
|
|
@@ -148,8 +148,9 @@ var Server = Class({ className: 'Server',
|
|
|
148
148
|
},
|
|
149
149
|
|
|
150
150
|
_advize: function(response, connectionType) {
|
|
151
|
-
if (array.indexOf([Channel.HANDSHAKE, Channel.CONNECT], response.channel) < 0)
|
|
151
|
+
if (array.indexOf([Channel.HANDSHAKE, Channel.CONNECT], response.channel) < 0) {
|
|
152
152
|
return;
|
|
153
|
+
}
|
|
153
154
|
|
|
154
155
|
var interval, timeout;
|
|
155
156
|
if (connectionType === 'eventsource') {
|
|
@@ -162,9 +163,9 @@ var Server = Class({ className: 'Server',
|
|
|
162
163
|
|
|
163
164
|
response.advice = response.advice || {};
|
|
164
165
|
if (response.error) {
|
|
165
|
-
assign(response.advice, { reconnect: 'handshake' }, false);
|
|
166
|
+
Object.assign(response.advice, { reconnect: 'handshake' }, false);
|
|
166
167
|
} else {
|
|
167
|
-
assign(response.advice, {
|
|
168
|
+
Object.assign(response.advice, {
|
|
168
169
|
reconnect: 'retry',
|
|
169
170
|
interval: interval,
|
|
170
171
|
timeout: timeout
|
|
@@ -181,8 +182,9 @@ var Server = Class({ className: 'Server',
|
|
|
181
182
|
var response = this._makeResponse(message);
|
|
182
183
|
response.version = constants.BAYEUX_VERSION;
|
|
183
184
|
|
|
184
|
-
if (!message.version)
|
|
185
|
+
if (!message.version) {
|
|
185
186
|
response.error = Error.parameterMissing('version');
|
|
187
|
+
}
|
|
186
188
|
|
|
187
189
|
var clientConns = message.supportedConnectionTypes,
|
|
188
190
|
commonConns;
|
|
@@ -193,8 +195,9 @@ var Server = Class({ className: 'Server',
|
|
|
193
195
|
commonConns = array.filter(clientConns, function(conn) {
|
|
194
196
|
return array.indexOf(constants.CONNECTION_TYPES, conn) >= 0;
|
|
195
197
|
});
|
|
196
|
-
if (commonConns.length === 0)
|
|
198
|
+
if (commonConns.length === 0) {
|
|
197
199
|
response.error = Error.conntypeMismatch(clientConns);
|
|
200
|
+
}
|
|
198
201
|
} else {
|
|
199
202
|
response.error = Error.parameterMissing('supportedConnectionTypes');
|
|
200
203
|
}
|
|
@@ -221,8 +224,9 @@ var Server = Class({ className: 'Server',
|
|
|
221
224
|
if (!exists) response.error = Error.clientUnknown(clientId);
|
|
222
225
|
if (!clientId) response.error = Error.parameterMissing('clientId');
|
|
223
226
|
|
|
224
|
-
if (array.indexOf(constants.CONNECTION_TYPES, connectionType) < 0)
|
|
227
|
+
if (array.indexOf(constants.CONNECTION_TYPES, connectionType) < 0) {
|
|
225
228
|
response.error = Error.conntypeMismatch(connectionType);
|
|
229
|
+
}
|
|
226
230
|
|
|
227
231
|
if (!connectionType) response.error = Error.parameterMissing('connectionType');
|
|
228
232
|
|
|
@@ -269,8 +273,7 @@ var Server = Class({ className: 'Server',
|
|
|
269
273
|
subscribe: function(message, local, callback, context) {
|
|
270
274
|
var response = this._makeResponse(message),
|
|
271
275
|
clientId = message.clientId,
|
|
272
|
-
subscription = message.subscription
|
|
273
|
-
channel;
|
|
276
|
+
subscription = message.subscription;
|
|
274
277
|
|
|
275
278
|
subscription = subscription ? [].concat(subscription) : [];
|
|
276
279
|
|
|
@@ -281,9 +284,7 @@ var Server = Class({ className: 'Server',
|
|
|
281
284
|
|
|
282
285
|
response.subscription = message.subscription || [];
|
|
283
286
|
|
|
284
|
-
for (
|
|
285
|
-
channel = subscription[i];
|
|
286
|
-
|
|
287
|
+
for (let channel of subscription) {
|
|
287
288
|
if (response.error) break;
|
|
288
289
|
if (!local && !Channel.isSubscribable(channel)) response.error = Error.channelForbidden(channel);
|
|
289
290
|
if (!Channel.isValid(channel)) response.error = Error.channelInvalid(channel);
|
|
@@ -304,8 +305,7 @@ var Server = Class({ className: 'Server',
|
|
|
304
305
|
unsubscribe: function(message, local, callback, context) {
|
|
305
306
|
var response = this._makeResponse(message),
|
|
306
307
|
clientId = message.clientId,
|
|
307
|
-
subscription = message.subscription
|
|
308
|
-
channel;
|
|
308
|
+
subscription = message.subscription;
|
|
309
309
|
|
|
310
310
|
subscription = subscription ? [].concat(subscription) : [];
|
|
311
311
|
|
|
@@ -316,9 +316,7 @@ var Server = Class({ className: 'Server',
|
|
|
316
316
|
|
|
317
317
|
response.subscription = message.subscription || [];
|
|
318
318
|
|
|
319
|
-
for (
|
|
320
|
-
channel = subscription[i];
|
|
321
|
-
|
|
319
|
+
for (let channel of subscription) {
|
|
322
320
|
if (response.error) break;
|
|
323
321
|
if (!local && !Channel.isSubscribable(channel)) response.error = Error.channelForbidden(channel);
|
|
324
322
|
if (!Channel.isValid(channel)) response.error = Error.channelInvalid(channel);
|
|
@@ -337,7 +335,7 @@ Server.create = function(options) {
|
|
|
337
335
|
return new Server(options);
|
|
338
336
|
};
|
|
339
337
|
|
|
340
|
-
assign(Server.prototype, Logging);
|
|
341
|
-
assign(Server.prototype, Extensible);
|
|
338
|
+
Object.assign(Server.prototype, Logging);
|
|
339
|
+
Object.assign(Server.prototype, Extensible);
|
|
342
340
|
|
|
343
341
|
module.exports = Server;
|
package/src/protocol/socket.js
CHANGED
|
@@ -12,8 +12,9 @@ module.exports = Class({
|
|
|
12
12
|
|
|
13
13
|
send: function(message) {
|
|
14
14
|
this._server.pipeThroughExtensions('outgoing', message, this._request, function(pipedMessage) {
|
|
15
|
-
if (this._socket)
|
|
15
|
+
if (this._socket) {
|
|
16
16
|
this._socket.send(toJSON([pipedMessage]));
|
|
17
|
+
}
|
|
17
18
|
}, this);
|
|
18
19
|
},
|
|
19
20
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var Class = require('../util/class'),
|
|
4
|
-
assign = require('../util/assign'),
|
|
5
4
|
Deferrable = require('../mixins/deferrable');
|
|
6
5
|
|
|
7
6
|
var Subscription = Class({
|
|
@@ -21,11 +20,12 @@ var Subscription = Class({
|
|
|
21
20
|
apply: function(context, args) {
|
|
22
21
|
var message = args[0];
|
|
23
22
|
|
|
24
|
-
if (this._callback)
|
|
23
|
+
if (this._callback) {
|
|
25
24
|
this._callback.call(this._context, message.data);
|
|
26
|
-
|
|
27
|
-
if (this._withChannel)
|
|
25
|
+
}
|
|
26
|
+
if (this._withChannel) {
|
|
28
27
|
this._withChannel[0].call(this._withChannel[1], message.channel, message.data);
|
|
28
|
+
}
|
|
29
29
|
},
|
|
30
30
|
|
|
31
31
|
cancel: function() {
|
|
@@ -39,6 +39,6 @@ var Subscription = Class({
|
|
|
39
39
|
}
|
|
40
40
|
});
|
|
41
41
|
|
|
42
|
-
assign(Subscription.prototype, Deferrable);
|
|
42
|
+
Object.assign(Subscription.prototype, Deferrable);
|
|
43
43
|
|
|
44
44
|
module.exports = Subscription;
|
package/src/transport/cors.js
CHANGED
|
@@ -3,11 +3,10 @@
|
|
|
3
3
|
var Class = require('../util/class'),
|
|
4
4
|
Set = require('../util/set'),
|
|
5
5
|
URI = require('../util/uri'),
|
|
6
|
-
assign = require('../util/assign'),
|
|
7
6
|
toJSON = require('../util/to_json'),
|
|
8
7
|
Transport = require('./transport');
|
|
9
8
|
|
|
10
|
-
var CORS = assign(Class(Transport, {
|
|
9
|
+
var CORS = Object.assign(Class(Transport, {
|
|
11
10
|
encode: function(messages) {
|
|
12
11
|
return 'message=' + encodeURIComponent(toJSON(messages));
|
|
13
12
|
},
|
|
@@ -17,17 +16,15 @@ var CORS = assign(Class(Transport, {
|
|
|
17
16
|
xhr = new xhrClass(),
|
|
18
17
|
id = ++CORS._id,
|
|
19
18
|
headers = this._dispatcher.headers,
|
|
20
|
-
self = this
|
|
21
|
-
key;
|
|
19
|
+
self = this;
|
|
22
20
|
|
|
23
21
|
xhr.open('POST', this.endpoint.href, true);
|
|
24
22
|
xhr.withCredentials = true;
|
|
25
23
|
|
|
26
24
|
if (xhr.setRequestHeader) {
|
|
27
25
|
xhr.setRequestHeader('Pragma', 'no-cache');
|
|
28
|
-
for (key
|
|
29
|
-
|
|
30
|
-
xhr.setRequestHeader(key, headers[key]);
|
|
26
|
+
for (let [key, value] of Object.entries(headers)) {
|
|
27
|
+
xhr.setRequestHeader(key, value);
|
|
31
28
|
}
|
|
32
29
|
}
|
|
33
30
|
|
|
@@ -44,10 +41,11 @@ var CORS = assign(Class(Transport, {
|
|
|
44
41
|
|
|
45
42
|
cleanUp();
|
|
46
43
|
|
|
47
|
-
if (replies)
|
|
44
|
+
if (replies) {
|
|
48
45
|
self._receive(replies);
|
|
49
|
-
else
|
|
46
|
+
} else {
|
|
50
47
|
self._handleError(messages);
|
|
48
|
+
}
|
|
51
49
|
};
|
|
52
50
|
|
|
53
51
|
xhr.onerror = xhr.ontimeout = function() {
|
|
@@ -57,8 +55,9 @@ var CORS = assign(Class(Transport, {
|
|
|
57
55
|
|
|
58
56
|
xhr.onprogress = function() {};
|
|
59
57
|
|
|
60
|
-
if (xhrClass === global.XDomainRequest)
|
|
58
|
+
if (xhrClass === global.XDomainRequest) {
|
|
61
59
|
CORS._pending.add({ id: id, xhr: xhr });
|
|
60
|
+
}
|
|
62
61
|
|
|
63
62
|
xhr.send(this.encode(messages));
|
|
64
63
|
return xhr;
|
|
@@ -68,12 +67,12 @@ var CORS = assign(Class(Transport, {
|
|
|
68
67
|
_pending: new Set(),
|
|
69
68
|
|
|
70
69
|
isUsable: function(dispatcher, endpoint, callback, context) {
|
|
71
|
-
if (URI.isSameOrigin(endpoint))
|
|
70
|
+
if (URI.isSameOrigin(endpoint)) {
|
|
72
71
|
return callback.call(context, false);
|
|
73
|
-
|
|
74
|
-
if (global.XDomainRequest)
|
|
72
|
+
}
|
|
73
|
+
if (global.XDomainRequest) {
|
|
75
74
|
return callback.call(context, endpoint.protocol === location.protocol);
|
|
76
|
-
|
|
75
|
+
}
|
|
77
76
|
if (global.XMLHttpRequest) {
|
|
78
77
|
var xhr = new XMLHttpRequest();
|
|
79
78
|
return callback.call(context, xhr.withCredentials !== undefined);
|