actioncable 5.1.0.beta1 → 5.1.0.rc1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e6a1923cc070932c10fd67f43091b790c221df82
4
- data.tar.gz: 4f8a716a47aeb4fcd7557e8fb9efd3f2629394a6
3
+ metadata.gz: ddd3032fd66feb385f3c135ce9677fa26b7d5e60
4
+ data.tar.gz: 8269dca8cc74d32cc8a7082679bd280520f30c9d
5
5
  SHA512:
6
- metadata.gz: f46c1ea1a1d68ce4b833fa58c287be8b658e0e599c2507e68c216a403f4e19a831a5e50a37dcb5c9f0125d5e545641ac9fa19feceeaeb4d3e3e53a459d8029d0
7
- data.tar.gz: 1495844434cdb511bec8e32976eced1a9c8c7657c6c6a6509ac9c6e8215294d1b850a08d00bca5c3ab83423ae0b34359bb137acea9c067c6d842b045c42ba59f
6
+ metadata.gz: afecb562901648e694975993307395f898fa10f52ec97a3158e0545b488095c58b0b4833e5b42cea311724da4dccd8f5a5c783ee2e11abef990ba308285c87f6
7
+ data.tar.gz: 683a014d35abd0a8e027ae7a97f8130df0e1a021a3c8b2c88a2fbf2256661381c096b0c6406335c2128dace4c3ee6cf83fb054574f06f021d13ba95874a0d307
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## Rails 5.1.0.rc1 (March 20, 2017) ##
2
+
3
+ * No changes.
4
+
5
+
1
6
  ## Rails 5.1.0.beta1 (February 23, 2017) ##
2
7
 
3
8
  * Redis subscription adapters now support `channel_prefix` option in `cable.yml`
@@ -8,7 +8,7 @@ module ActionCable
8
8
  MAJOR = 5
9
9
  MINOR = 1
10
10
  TINY = 0
11
- PRE = "beta1"
11
+ PRE = "rc1"
12
12
 
13
13
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
14
14
  end
@@ -1,584 +1,599 @@
1
1
  (function() {
2
- var slice = [].slice;
3
-
4
- this.ActionCable = {
5
- INTERNAL: {
6
- "message_types": {
7
- "welcome": "welcome",
8
- "ping": "ping",
9
- "confirmation": "confirm_subscription",
10
- "rejection": "reject_subscription"
11
- },
12
- "default_mount_path": "/cable",
13
- "protocols": ["actioncable-v1-json", "actioncable-unsupported"]
14
- },
15
- WebSocket: window.WebSocket,
16
- logger: window.console,
17
- createConsumer: function(url) {
18
- var ref;
19
- if (url == null) {
20
- url = (ref = this.getConfig("url")) != null ? ref : this.INTERNAL.default_mount_path;
21
- }
22
- return new ActionCable.Consumer(this.createWebSocketURL(url));
23
- },
24
- getConfig: function(name) {
25
- var element;
26
- element = document.head.querySelector("meta[name='action-cable-" + name + "']");
27
- return element != null ? element.getAttribute("content") : void 0;
28
- },
29
- createWebSocketURL: function(url) {
30
- var a;
31
- if (url && !/^wss?:/i.test(url)) {
32
- a = document.createElement("a");
33
- a.href = url;
34
- a.href = a.href;
35
- a.protocol = a.protocol.replace("http", "ws");
36
- return a.href;
37
- } else {
38
- return url;
39
- }
40
- },
41
- startDebugging: function() {
42
- return this.debugging = true;
43
- },
44
- stopDebugging: function() {
45
- return this.debugging = null;
46
- },
47
- log: function() {
48
- var messages, ref;
49
- messages = 1 <= arguments.length ? slice.call(arguments, 0) : [];
50
- if (this.debugging) {
51
- messages.push(Date.now());
52
- return (ref = this.logger).log.apply(ref, ["[ActionCable]"].concat(slice.call(messages)));
53
- }
54
- }
55
- };
2
+ (function() {
3
+ (function() {
4
+ var slice = [].slice;
5
+
6
+ this.ActionCable = {
7
+ INTERNAL: {
8
+ "message_types": {
9
+ "welcome": "welcome",
10
+ "ping": "ping",
11
+ "confirmation": "confirm_subscription",
12
+ "rejection": "reject_subscription"
13
+ },
14
+ "default_mount_path": "/cable",
15
+ "protocols": ["actioncable-v1-json", "actioncable-unsupported"]
16
+ },
17
+ WebSocket: window.WebSocket,
18
+ logger: window.console,
19
+ createConsumer: function(url) {
20
+ var ref;
21
+ if (url == null) {
22
+ url = (ref = this.getConfig("url")) != null ? ref : this.INTERNAL.default_mount_path;
23
+ }
24
+ return new ActionCable.Consumer(this.createWebSocketURL(url));
25
+ },
26
+ getConfig: function(name) {
27
+ var element;
28
+ element = document.head.querySelector("meta[name='action-cable-" + name + "']");
29
+ return element != null ? element.getAttribute("content") : void 0;
30
+ },
31
+ createWebSocketURL: function(url) {
32
+ var a;
33
+ if (url && !/^wss?:/i.test(url)) {
34
+ a = document.createElement("a");
35
+ a.href = url;
36
+ a.href = a.href;
37
+ a.protocol = a.protocol.replace("http", "ws");
38
+ return a.href;
39
+ } else {
40
+ return url;
41
+ }
42
+ },
43
+ startDebugging: function() {
44
+ return this.debugging = true;
45
+ },
46
+ stopDebugging: function() {
47
+ return this.debugging = null;
48
+ },
49
+ log: function() {
50
+ var messages, ref;
51
+ messages = 1 <= arguments.length ? slice.call(arguments, 0) : [];
52
+ if (this.debugging) {
53
+ messages.push(Date.now());
54
+ return (ref = this.logger).log.apply(ref, ["[ActionCable]"].concat(slice.call(messages)));
55
+ }
56
+ }
57
+ };
56
58
 
57
- }).call(this);
58
- (function() {
59
- var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
60
-
61
- ActionCable.ConnectionMonitor = (function() {
62
- var clamp, now, secondsSince;
63
-
64
- ConnectionMonitor.pollInterval = {
65
- min: 3,
66
- max: 30
67
- };
68
-
69
- ConnectionMonitor.staleThreshold = 6;
70
-
71
- function ConnectionMonitor(connection) {
72
- this.connection = connection;
73
- this.visibilityDidChange = bind(this.visibilityDidChange, this);
74
- this.reconnectAttempts = 0;
75
- }
76
-
77
- ConnectionMonitor.prototype.start = function() {
78
- if (!this.isRunning()) {
79
- this.startedAt = now();
80
- delete this.stoppedAt;
81
- this.startPolling();
82
- document.addEventListener("visibilitychange", this.visibilityDidChange);
83
- return ActionCable.log("ConnectionMonitor started. pollInterval = " + (this.getPollInterval()) + " ms");
84
- }
85
- };
86
-
87
- ConnectionMonitor.prototype.stop = function() {
88
- if (this.isRunning()) {
89
- this.stoppedAt = now();
90
- this.stopPolling();
91
- document.removeEventListener("visibilitychange", this.visibilityDidChange);
92
- return ActionCable.log("ConnectionMonitor stopped");
93
- }
94
- };
95
-
96
- ConnectionMonitor.prototype.isRunning = function() {
97
- return (this.startedAt != null) && (this.stoppedAt == null);
98
- };
99
-
100
- ConnectionMonitor.prototype.recordPing = function() {
101
- return this.pingedAt = now();
102
- };
103
-
104
- ConnectionMonitor.prototype.recordConnect = function() {
105
- this.reconnectAttempts = 0;
106
- this.recordPing();
107
- delete this.disconnectedAt;
108
- return ActionCable.log("ConnectionMonitor recorded connect");
109
- };
110
-
111
- ConnectionMonitor.prototype.recordDisconnect = function() {
112
- this.disconnectedAt = now();
113
- return ActionCable.log("ConnectionMonitor recorded disconnect");
114
- };
115
-
116
- ConnectionMonitor.prototype.startPolling = function() {
117
- this.stopPolling();
118
- return this.poll();
119
- };
120
-
121
- ConnectionMonitor.prototype.stopPolling = function() {
122
- return clearTimeout(this.pollTimeout);
123
- };
124
-
125
- ConnectionMonitor.prototype.poll = function() {
126
- return this.pollTimeout = setTimeout((function(_this) {
127
- return function() {
128
- _this.reconnectIfStale();
129
- return _this.poll();
130
- };
131
- })(this), this.getPollInterval());
132
- };
133
-
134
- ConnectionMonitor.prototype.getPollInterval = function() {
135
- var interval, max, min, ref;
136
- ref = this.constructor.pollInterval, min = ref.min, max = ref.max;
137
- interval = 5 * Math.log(this.reconnectAttempts + 1);
138
- return Math.round(clamp(interval, min, max) * 1000);
139
- };
140
-
141
- ConnectionMonitor.prototype.reconnectIfStale = function() {
142
- if (this.connectionIsStale()) {
143
- ActionCable.log("ConnectionMonitor detected stale connection. reconnectAttempts = " + this.reconnectAttempts + ", pollInterval = " + (this.getPollInterval()) + " ms, time disconnected = " + (secondsSince(this.disconnectedAt)) + " s, stale threshold = " + this.constructor.staleThreshold + " s");
144
- this.reconnectAttempts++;
145
- if (this.disconnectedRecently()) {
146
- return ActionCable.log("ConnectionMonitor skipping reopening recent disconnect");
147
- } else {
148
- ActionCable.log("ConnectionMonitor reopening");
149
- return this.connection.reopen();
59
+ }).call(this);
60
+ }).call(this);
61
+
62
+ var ActionCable = this.ActionCable;
63
+
64
+ (function() {
65
+ (function() {
66
+ var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
67
+
68
+ ActionCable.ConnectionMonitor = (function() {
69
+ var clamp, now, secondsSince;
70
+
71
+ ConnectionMonitor.pollInterval = {
72
+ min: 3,
73
+ max: 30
74
+ };
75
+
76
+ ConnectionMonitor.staleThreshold = 6;
77
+
78
+ function ConnectionMonitor(connection) {
79
+ this.connection = connection;
80
+ this.visibilityDidChange = bind(this.visibilityDidChange, this);
81
+ this.reconnectAttempts = 0;
150
82
  }
151
- }
152
- };
153
-
154
- ConnectionMonitor.prototype.connectionIsStale = function() {
155
- var ref;
156
- return secondsSince((ref = this.pingedAt) != null ? ref : this.startedAt) > this.constructor.staleThreshold;
157
- };
158
-
159
- ConnectionMonitor.prototype.disconnectedRecently = function() {
160
- return this.disconnectedAt && secondsSince(this.disconnectedAt) < this.constructor.staleThreshold;
161
- };
162
-
163
- ConnectionMonitor.prototype.visibilityDidChange = function() {
164
- if (document.visibilityState === "visible") {
165
- return setTimeout((function(_this) {
166
- return function() {
167
- if (_this.connectionIsStale() || !_this.connection.isOpen()) {
168
- ActionCable.log("ConnectionMonitor reopening stale connection on visibilitychange. visbilityState = " + document.visibilityState);
169
- return _this.connection.reopen();
83
+
84
+ ConnectionMonitor.prototype.start = function() {
85
+ if (!this.isRunning()) {
86
+ this.startedAt = now();
87
+ delete this.stoppedAt;
88
+ this.startPolling();
89
+ document.addEventListener("visibilitychange", this.visibilityDidChange);
90
+ return ActionCable.log("ConnectionMonitor started. pollInterval = " + (this.getPollInterval()) + " ms");
91
+ }
92
+ };
93
+
94
+ ConnectionMonitor.prototype.stop = function() {
95
+ if (this.isRunning()) {
96
+ this.stoppedAt = now();
97
+ this.stopPolling();
98
+ document.removeEventListener("visibilitychange", this.visibilityDidChange);
99
+ return ActionCable.log("ConnectionMonitor stopped");
100
+ }
101
+ };
102
+
103
+ ConnectionMonitor.prototype.isRunning = function() {
104
+ return (this.startedAt != null) && (this.stoppedAt == null);
105
+ };
106
+
107
+ ConnectionMonitor.prototype.recordPing = function() {
108
+ return this.pingedAt = now();
109
+ };
110
+
111
+ ConnectionMonitor.prototype.recordConnect = function() {
112
+ this.reconnectAttempts = 0;
113
+ this.recordPing();
114
+ delete this.disconnectedAt;
115
+ return ActionCable.log("ConnectionMonitor recorded connect");
116
+ };
117
+
118
+ ConnectionMonitor.prototype.recordDisconnect = function() {
119
+ this.disconnectedAt = now();
120
+ return ActionCable.log("ConnectionMonitor recorded disconnect");
121
+ };
122
+
123
+ ConnectionMonitor.prototype.startPolling = function() {
124
+ this.stopPolling();
125
+ return this.poll();
126
+ };
127
+
128
+ ConnectionMonitor.prototype.stopPolling = function() {
129
+ return clearTimeout(this.pollTimeout);
130
+ };
131
+
132
+ ConnectionMonitor.prototype.poll = function() {
133
+ return this.pollTimeout = setTimeout((function(_this) {
134
+ return function() {
135
+ _this.reconnectIfStale();
136
+ return _this.poll();
137
+ };
138
+ })(this), this.getPollInterval());
139
+ };
140
+
141
+ ConnectionMonitor.prototype.getPollInterval = function() {
142
+ var interval, max, min, ref;
143
+ ref = this.constructor.pollInterval, min = ref.min, max = ref.max;
144
+ interval = 5 * Math.log(this.reconnectAttempts + 1);
145
+ return Math.round(clamp(interval, min, max) * 1000);
146
+ };
147
+
148
+ ConnectionMonitor.prototype.reconnectIfStale = function() {
149
+ if (this.connectionIsStale()) {
150
+ ActionCable.log("ConnectionMonitor detected stale connection. reconnectAttempts = " + this.reconnectAttempts + ", pollInterval = " + (this.getPollInterval()) + " ms, time disconnected = " + (secondsSince(this.disconnectedAt)) + " s, stale threshold = " + this.constructor.staleThreshold + " s");
151
+ this.reconnectAttempts++;
152
+ if (this.disconnectedRecently()) {
153
+ return ActionCable.log("ConnectionMonitor skipping reopening recent disconnect");
154
+ } else {
155
+ ActionCable.log("ConnectionMonitor reopening");
156
+ return this.connection.reopen();
170
157
  }
171
- };
172
- })(this), 200);
173
- }
174
- };
158
+ }
159
+ };
160
+
161
+ ConnectionMonitor.prototype.connectionIsStale = function() {
162
+ var ref;
163
+ return secondsSince((ref = this.pingedAt) != null ? ref : this.startedAt) > this.constructor.staleThreshold;
164
+ };
175
165
 
176
- now = function() {
177
- return new Date().getTime();
178
- };
166
+ ConnectionMonitor.prototype.disconnectedRecently = function() {
167
+ return this.disconnectedAt && secondsSince(this.disconnectedAt) < this.constructor.staleThreshold;
168
+ };
179
169
 
180
- secondsSince = function(time) {
181
- return (now() - time) / 1000;
182
- };
170
+ ConnectionMonitor.prototype.visibilityDidChange = function() {
171
+ if (document.visibilityState === "visible") {
172
+ return setTimeout((function(_this) {
173
+ return function() {
174
+ if (_this.connectionIsStale() || !_this.connection.isOpen()) {
175
+ ActionCable.log("ConnectionMonitor reopening stale connection on visibilitychange. visbilityState = " + document.visibilityState);
176
+ return _this.connection.reopen();
177
+ }
178
+ };
179
+ })(this), 200);
180
+ }
181
+ };
183
182
 
184
- clamp = function(number, min, max) {
185
- return Math.max(min, Math.min(max, number));
186
- };
183
+ now = function() {
184
+ return new Date().getTime();
185
+ };
187
186
 
188
- return ConnectionMonitor;
187
+ secondsSince = function(time) {
188
+ return (now() - time) / 1000;
189
+ };
189
190
 
190
- })();
191
+ clamp = function(number, min, max) {
192
+ return Math.max(min, Math.min(max, number));
193
+ };
191
194
 
192
- }).call(this);
193
- (function() {
194
- var i, message_types, protocols, ref, supportedProtocols, unsupportedProtocol,
195
- slice = [].slice,
196
- bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
197
- indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
198
-
199
- ref = ActionCable.INTERNAL, message_types = ref.message_types, protocols = ref.protocols;
200
-
201
- supportedProtocols = 2 <= protocols.length ? slice.call(protocols, 0, i = protocols.length - 1) : (i = 0, []), unsupportedProtocol = protocols[i++];
202
-
203
- ActionCable.Connection = (function() {
204
- Connection.reopenDelay = 500;
205
-
206
- function Connection(consumer) {
207
- this.consumer = consumer;
208
- this.open = bind(this.open, this);
209
- this.subscriptions = this.consumer.subscriptions;
210
- this.monitor = new ActionCable.ConnectionMonitor(this);
211
- this.disconnected = true;
212
- }
213
-
214
- Connection.prototype.send = function(data) {
215
- if (this.isOpen()) {
216
- this.webSocket.send(JSON.stringify(data));
217
- return true;
218
- } else {
219
- return false;
220
- }
221
- };
222
-
223
- Connection.prototype.open = function() {
224
- if (this.isActive()) {
225
- ActionCable.log("Attempted to open WebSocket, but existing socket is " + (this.getState()));
226
- return false;
227
- } else {
228
- ActionCable.log("Opening WebSocket, current state is " + (this.getState()) + ", subprotocols: " + protocols);
229
- if (this.webSocket != null) {
230
- this.uninstallEventHandlers();
231
- }
232
- this.webSocket = new ActionCable.WebSocket(this.consumer.url, protocols);
233
- this.installEventHandlers();
234
- this.monitor.start();
235
- return true;
236
- }
237
- };
238
-
239
- Connection.prototype.close = function(arg) {
240
- var allowReconnect, ref1;
241
- allowReconnect = (arg != null ? arg : {
242
- allowReconnect: true
243
- }).allowReconnect;
244
- if (!allowReconnect) {
245
- this.monitor.stop();
246
- }
247
- if (this.isActive()) {
248
- return (ref1 = this.webSocket) != null ? ref1.close() : void 0;
249
- }
250
- };
251
-
252
- Connection.prototype.reopen = function() {
253
- var error;
254
- ActionCable.log("Reopening WebSocket, current state is " + (this.getState()));
255
- if (this.isActive()) {
256
- try {
257
- return this.close();
258
- } catch (error1) {
259
- error = error1;
260
- return ActionCable.log("Failed to reopen WebSocket", error);
261
- } finally {
262
- ActionCable.log("Reopening WebSocket in " + this.constructor.reopenDelay + "ms");
263
- setTimeout(this.open, this.constructor.reopenDelay);
264
- }
265
- } else {
266
- return this.open();
267
- }
268
- };
269
-
270
- Connection.prototype.getProtocol = function() {
271
- var ref1;
272
- return (ref1 = this.webSocket) != null ? ref1.protocol : void 0;
273
- };
274
-
275
- Connection.prototype.isOpen = function() {
276
- return this.isState("open");
277
- };
278
-
279
- Connection.prototype.isActive = function() {
280
- return this.isState("open", "connecting");
281
- };
282
-
283
- Connection.prototype.isProtocolSupported = function() {
284
- var ref1;
285
- return ref1 = this.getProtocol(), indexOf.call(supportedProtocols, ref1) >= 0;
286
- };
287
-
288
- Connection.prototype.isState = function() {
289
- var ref1, states;
290
- states = 1 <= arguments.length ? slice.call(arguments, 0) : [];
291
- return ref1 = this.getState(), indexOf.call(states, ref1) >= 0;
292
- };
293
-
294
- Connection.prototype.getState = function() {
295
- var ref1, state, value;
296
- for (state in WebSocket) {
297
- value = WebSocket[state];
298
- if (value === ((ref1 = this.webSocket) != null ? ref1.readyState : void 0)) {
299
- return state.toLowerCase();
300
- }
301
- }
302
- return null;
303
- };
304
-
305
- Connection.prototype.installEventHandlers = function() {
306
- var eventName, handler;
307
- for (eventName in this.events) {
308
- handler = this.events[eventName].bind(this);
309
- this.webSocket["on" + eventName] = handler;
310
- }
311
- };
312
-
313
- Connection.prototype.uninstallEventHandlers = function() {
314
- var eventName;
315
- for (eventName in this.events) {
316
- this.webSocket["on" + eventName] = function() {};
317
- }
318
- };
319
-
320
- Connection.prototype.events = {
321
- message: function(event) {
322
- var identifier, message, ref1, type;
323
- if (!this.isProtocolSupported()) {
324
- return;
195
+ return ConnectionMonitor;
196
+
197
+ })();
198
+
199
+ }).call(this);
200
+ (function() {
201
+ var i, message_types, protocols, ref, supportedProtocols, unsupportedProtocol,
202
+ slice = [].slice,
203
+ bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
204
+ indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
205
+
206
+ ref = ActionCable.INTERNAL, message_types = ref.message_types, protocols = ref.protocols;
207
+
208
+ supportedProtocols = 2 <= protocols.length ? slice.call(protocols, 0, i = protocols.length - 1) : (i = 0, []), unsupportedProtocol = protocols[i++];
209
+
210
+ ActionCable.Connection = (function() {
211
+ Connection.reopenDelay = 500;
212
+
213
+ function Connection(consumer) {
214
+ this.consumer = consumer;
215
+ this.open = bind(this.open, this);
216
+ this.subscriptions = this.consumer.subscriptions;
217
+ this.monitor = new ActionCable.ConnectionMonitor(this);
218
+ this.disconnected = true;
325
219
  }
326
- ref1 = JSON.parse(event.data), identifier = ref1.identifier, message = ref1.message, type = ref1.type;
327
- switch (type) {
328
- case message_types.welcome:
329
- this.monitor.recordConnect();
330
- return this.subscriptions.reload();
331
- case message_types.ping:
332
- return this.monitor.recordPing();
333
- case message_types.confirmation:
334
- return this.subscriptions.notify(identifier, "connected");
335
- case message_types.rejection:
336
- return this.subscriptions.reject(identifier);
337
- default:
338
- return this.subscriptions.notify(identifier, "received", message);
220
+
221
+ Connection.prototype.send = function(data) {
222
+ if (this.isOpen()) {
223
+ this.webSocket.send(JSON.stringify(data));
224
+ return true;
225
+ } else {
226
+ return false;
227
+ }
228
+ };
229
+
230
+ Connection.prototype.open = function() {
231
+ if (this.isActive()) {
232
+ ActionCable.log("Attempted to open WebSocket, but existing socket is " + (this.getState()));
233
+ return false;
234
+ } else {
235
+ ActionCable.log("Opening WebSocket, current state is " + (this.getState()) + ", subprotocols: " + protocols);
236
+ if (this.webSocket != null) {
237
+ this.uninstallEventHandlers();
238
+ }
239
+ this.webSocket = new ActionCable.WebSocket(this.consumer.url, protocols);
240
+ this.installEventHandlers();
241
+ this.monitor.start();
242
+ return true;
243
+ }
244
+ };
245
+
246
+ Connection.prototype.close = function(arg) {
247
+ var allowReconnect, ref1;
248
+ allowReconnect = (arg != null ? arg : {
249
+ allowReconnect: true
250
+ }).allowReconnect;
251
+ if (!allowReconnect) {
252
+ this.monitor.stop();
253
+ }
254
+ if (this.isActive()) {
255
+ return (ref1 = this.webSocket) != null ? ref1.close() : void 0;
256
+ }
257
+ };
258
+
259
+ Connection.prototype.reopen = function() {
260
+ var error;
261
+ ActionCable.log("Reopening WebSocket, current state is " + (this.getState()));
262
+ if (this.isActive()) {
263
+ try {
264
+ return this.close();
265
+ } catch (error1) {
266
+ error = error1;
267
+ return ActionCable.log("Failed to reopen WebSocket", error);
268
+ } finally {
269
+ ActionCable.log("Reopening WebSocket in " + this.constructor.reopenDelay + "ms");
270
+ setTimeout(this.open, this.constructor.reopenDelay);
271
+ }
272
+ } else {
273
+ return this.open();
274
+ }
275
+ };
276
+
277
+ Connection.prototype.getProtocol = function() {
278
+ var ref1;
279
+ return (ref1 = this.webSocket) != null ? ref1.protocol : void 0;
280
+ };
281
+
282
+ Connection.prototype.isOpen = function() {
283
+ return this.isState("open");
284
+ };
285
+
286
+ Connection.prototype.isActive = function() {
287
+ return this.isState("open", "connecting");
288
+ };
289
+
290
+ Connection.prototype.isProtocolSupported = function() {
291
+ var ref1;
292
+ return ref1 = this.getProtocol(), indexOf.call(supportedProtocols, ref1) >= 0;
293
+ };
294
+
295
+ Connection.prototype.isState = function() {
296
+ var ref1, states;
297
+ states = 1 <= arguments.length ? slice.call(arguments, 0) : [];
298
+ return ref1 = this.getState(), indexOf.call(states, ref1) >= 0;
299
+ };
300
+
301
+ Connection.prototype.getState = function() {
302
+ var ref1, state, value;
303
+ for (state in WebSocket) {
304
+ value = WebSocket[state];
305
+ if (value === ((ref1 = this.webSocket) != null ? ref1.readyState : void 0)) {
306
+ return state.toLowerCase();
307
+ }
308
+ }
309
+ return null;
310
+ };
311
+
312
+ Connection.prototype.installEventHandlers = function() {
313
+ var eventName, handler;
314
+ for (eventName in this.events) {
315
+ handler = this.events[eventName].bind(this);
316
+ this.webSocket["on" + eventName] = handler;
317
+ }
318
+ };
319
+
320
+ Connection.prototype.uninstallEventHandlers = function() {
321
+ var eventName;
322
+ for (eventName in this.events) {
323
+ this.webSocket["on" + eventName] = function() {};
324
+ }
325
+ };
326
+
327
+ Connection.prototype.events = {
328
+ message: function(event) {
329
+ var identifier, message, ref1, type;
330
+ if (!this.isProtocolSupported()) {
331
+ return;
332
+ }
333
+ ref1 = JSON.parse(event.data), identifier = ref1.identifier, message = ref1.message, type = ref1.type;
334
+ switch (type) {
335
+ case message_types.welcome:
336
+ this.monitor.recordConnect();
337
+ return this.subscriptions.reload();
338
+ case message_types.ping:
339
+ return this.monitor.recordPing();
340
+ case message_types.confirmation:
341
+ return this.subscriptions.notify(identifier, "connected");
342
+ case message_types.rejection:
343
+ return this.subscriptions.reject(identifier);
344
+ default:
345
+ return this.subscriptions.notify(identifier, "received", message);
346
+ }
347
+ },
348
+ open: function() {
349
+ ActionCable.log("WebSocket onopen event, using '" + (this.getProtocol()) + "' subprotocol");
350
+ this.disconnected = false;
351
+ if (!this.isProtocolSupported()) {
352
+ ActionCable.log("Protocol is unsupported. Stopping monitor and disconnecting.");
353
+ return this.close({
354
+ allowReconnect: false
355
+ });
356
+ }
357
+ },
358
+ close: function(event) {
359
+ ActionCable.log("WebSocket onclose event");
360
+ if (this.disconnected) {
361
+ return;
362
+ }
363
+ this.disconnected = true;
364
+ this.monitor.recordDisconnect();
365
+ return this.subscriptions.notifyAll("disconnected", {
366
+ willAttemptReconnect: this.monitor.isRunning()
367
+ });
368
+ },
369
+ error: function() {
370
+ return ActionCable.log("WebSocket onerror event");
371
+ }
372
+ };
373
+
374
+ return Connection;
375
+
376
+ })();
377
+
378
+ }).call(this);
379
+ (function() {
380
+ var slice = [].slice;
381
+
382
+ ActionCable.Subscriptions = (function() {
383
+ function Subscriptions(consumer) {
384
+ this.consumer = consumer;
385
+ this.subscriptions = [];
339
386
  }
340
- },
341
- open: function() {
342
- ActionCable.log("WebSocket onopen event, using '" + (this.getProtocol()) + "' subprotocol");
343
- this.disconnected = false;
344
- if (!this.isProtocolSupported()) {
345
- ActionCable.log("Protocol is unsupported. Stopping monitor and disconnecting.");
346
- return this.close({
347
- allowReconnect: false
387
+
388
+ Subscriptions.prototype.create = function(channelName, mixin) {
389
+ var channel, params, subscription;
390
+ channel = channelName;
391
+ params = typeof channel === "object" ? channel : {
392
+ channel: channel
393
+ };
394
+ subscription = new ActionCable.Subscription(this.consumer, params, mixin);
395
+ return this.add(subscription);
396
+ };
397
+
398
+ Subscriptions.prototype.add = function(subscription) {
399
+ this.subscriptions.push(subscription);
400
+ this.consumer.ensureActiveConnection();
401
+ this.notify(subscription, "initialized");
402
+ this.sendCommand(subscription, "subscribe");
403
+ return subscription;
404
+ };
405
+
406
+ Subscriptions.prototype.remove = function(subscription) {
407
+ this.forget(subscription);
408
+ if (!this.findAll(subscription.identifier).length) {
409
+ this.sendCommand(subscription, "unsubscribe");
410
+ }
411
+ return subscription;
412
+ };
413
+
414
+ Subscriptions.prototype.reject = function(identifier) {
415
+ var i, len, ref, results, subscription;
416
+ ref = this.findAll(identifier);
417
+ results = [];
418
+ for (i = 0, len = ref.length; i < len; i++) {
419
+ subscription = ref[i];
420
+ this.forget(subscription);
421
+ this.notify(subscription, "rejected");
422
+ results.push(subscription);
423
+ }
424
+ return results;
425
+ };
426
+
427
+ Subscriptions.prototype.forget = function(subscription) {
428
+ var s;
429
+ this.subscriptions = (function() {
430
+ var i, len, ref, results;
431
+ ref = this.subscriptions;
432
+ results = [];
433
+ for (i = 0, len = ref.length; i < len; i++) {
434
+ s = ref[i];
435
+ if (s !== subscription) {
436
+ results.push(s);
437
+ }
438
+ }
439
+ return results;
440
+ }).call(this);
441
+ return subscription;
442
+ };
443
+
444
+ Subscriptions.prototype.findAll = function(identifier) {
445
+ var i, len, ref, results, s;
446
+ ref = this.subscriptions;
447
+ results = [];
448
+ for (i = 0, len = ref.length; i < len; i++) {
449
+ s = ref[i];
450
+ if (s.identifier === identifier) {
451
+ results.push(s);
452
+ }
453
+ }
454
+ return results;
455
+ };
456
+
457
+ Subscriptions.prototype.reload = function() {
458
+ var i, len, ref, results, subscription;
459
+ ref = this.subscriptions;
460
+ results = [];
461
+ for (i = 0, len = ref.length; i < len; i++) {
462
+ subscription = ref[i];
463
+ results.push(this.sendCommand(subscription, "subscribe"));
464
+ }
465
+ return results;
466
+ };
467
+
468
+ Subscriptions.prototype.notifyAll = function() {
469
+ var args, callbackName, i, len, ref, results, subscription;
470
+ callbackName = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
471
+ ref = this.subscriptions;
472
+ results = [];
473
+ for (i = 0, len = ref.length; i < len; i++) {
474
+ subscription = ref[i];
475
+ results.push(this.notify.apply(this, [subscription, callbackName].concat(slice.call(args))));
476
+ }
477
+ return results;
478
+ };
479
+
480
+ Subscriptions.prototype.notify = function() {
481
+ var args, callbackName, i, len, results, subscription, subscriptions;
482
+ subscription = arguments[0], callbackName = arguments[1], args = 3 <= arguments.length ? slice.call(arguments, 2) : [];
483
+ if (typeof subscription === "string") {
484
+ subscriptions = this.findAll(subscription);
485
+ } else {
486
+ subscriptions = [subscription];
487
+ }
488
+ results = [];
489
+ for (i = 0, len = subscriptions.length; i < len; i++) {
490
+ subscription = subscriptions[i];
491
+ results.push(typeof subscription[callbackName] === "function" ? subscription[callbackName].apply(subscription, args) : void 0);
492
+ }
493
+ return results;
494
+ };
495
+
496
+ Subscriptions.prototype.sendCommand = function(subscription, command) {
497
+ var identifier;
498
+ identifier = subscription.identifier;
499
+ return this.consumer.send({
500
+ command: command,
501
+ identifier: identifier
348
502
  });
349
- }
350
- },
351
- close: function(event) {
352
- ActionCable.log("WebSocket onclose event");
353
- if (this.disconnected) {
354
- return;
355
- }
356
- this.disconnected = true;
357
- this.monitor.recordDisconnect();
358
- return this.subscriptions.notifyAll("disconnected", {
359
- willAttemptReconnect: this.monitor.isRunning()
360
- });
361
- },
362
- error: function() {
363
- return ActionCable.log("WebSocket onerror event");
364
- }
365
- };
503
+ };
366
504
 
367
- return Connection;
505
+ return Subscriptions;
368
506
 
369
- })();
507
+ })();
370
508
 
371
- }).call(this);
372
- (function() {
373
- var slice = [].slice;
374
-
375
- ActionCable.Subscriptions = (function() {
376
- function Subscriptions(consumer) {
377
- this.consumer = consumer;
378
- this.subscriptions = [];
379
- }
380
-
381
- Subscriptions.prototype.create = function(channelName, mixin) {
382
- var channel, params, subscription;
383
- channel = channelName;
384
- params = typeof channel === "object" ? channel : {
385
- channel: channel
386
- };
387
- subscription = new ActionCable.Subscription(this.consumer, params, mixin);
388
- return this.add(subscription);
389
- };
390
-
391
- Subscriptions.prototype.add = function(subscription) {
392
- this.subscriptions.push(subscription);
393
- this.consumer.ensureActiveConnection();
394
- this.notify(subscription, "initialized");
395
- this.sendCommand(subscription, "subscribe");
396
- return subscription;
397
- };
398
-
399
- Subscriptions.prototype.remove = function(subscription) {
400
- this.forget(subscription);
401
- if (!this.findAll(subscription.identifier).length) {
402
- this.sendCommand(subscription, "unsubscribe");
403
- }
404
- return subscription;
405
- };
406
-
407
- Subscriptions.prototype.reject = function(identifier) {
408
- var i, len, ref, results, subscription;
409
- ref = this.findAll(identifier);
410
- results = [];
411
- for (i = 0, len = ref.length; i < len; i++) {
412
- subscription = ref[i];
413
- this.forget(subscription);
414
- this.notify(subscription, "rejected");
415
- results.push(subscription);
416
- }
417
- return results;
418
- };
419
-
420
- Subscriptions.prototype.forget = function(subscription) {
421
- var s;
422
- this.subscriptions = (function() {
423
- var i, len, ref, results;
424
- ref = this.subscriptions;
425
- results = [];
426
- for (i = 0, len = ref.length; i < len; i++) {
427
- s = ref[i];
428
- if (s !== subscription) {
429
- results.push(s);
509
+ }).call(this);
510
+ (function() {
511
+ ActionCable.Subscription = (function() {
512
+ var extend;
513
+
514
+ function Subscription(consumer, params, mixin) {
515
+ this.consumer = consumer;
516
+ if (params == null) {
517
+ params = {};
430
518
  }
519
+ this.identifier = JSON.stringify(params);
520
+ extend(this, mixin);
431
521
  }
432
- return results;
433
- }).call(this);
434
- return subscription;
435
- };
436
-
437
- Subscriptions.prototype.findAll = function(identifier) {
438
- var i, len, ref, results, s;
439
- ref = this.subscriptions;
440
- results = [];
441
- for (i = 0, len = ref.length; i < len; i++) {
442
- s = ref[i];
443
- if (s.identifier === identifier) {
444
- results.push(s);
445
- }
446
- }
447
- return results;
448
- };
449
-
450
- Subscriptions.prototype.reload = function() {
451
- var i, len, ref, results, subscription;
452
- ref = this.subscriptions;
453
- results = [];
454
- for (i = 0, len = ref.length; i < len; i++) {
455
- subscription = ref[i];
456
- results.push(this.sendCommand(subscription, "subscribe"));
457
- }
458
- return results;
459
- };
460
-
461
- Subscriptions.prototype.notifyAll = function() {
462
- var args, callbackName, i, len, ref, results, subscription;
463
- callbackName = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
464
- ref = this.subscriptions;
465
- results = [];
466
- for (i = 0, len = ref.length; i < len; i++) {
467
- subscription = ref[i];
468
- results.push(this.notify.apply(this, [subscription, callbackName].concat(slice.call(args))));
469
- }
470
- return results;
471
- };
472
-
473
- Subscriptions.prototype.notify = function() {
474
- var args, callbackName, i, len, results, subscription, subscriptions;
475
- subscription = arguments[0], callbackName = arguments[1], args = 3 <= arguments.length ? slice.call(arguments, 2) : [];
476
- if (typeof subscription === "string") {
477
- subscriptions = this.findAll(subscription);
478
- } else {
479
- subscriptions = [subscription];
480
- }
481
- results = [];
482
- for (i = 0, len = subscriptions.length; i < len; i++) {
483
- subscription = subscriptions[i];
484
- results.push(typeof subscription[callbackName] === "function" ? subscription[callbackName].apply(subscription, args) : void 0);
485
- }
486
- return results;
487
- };
488
-
489
- Subscriptions.prototype.sendCommand = function(subscription, command) {
490
- var identifier;
491
- identifier = subscription.identifier;
492
- return this.consumer.send({
493
- command: command,
494
- identifier: identifier
495
- });
496
- };
497
-
498
- return Subscriptions;
499
-
500
- })();
501
522
 
502
- }).call(this);
503
- (function() {
504
- ActionCable.Subscription = (function() {
505
- var extend;
506
-
507
- function Subscription(consumer, params, mixin) {
508
- this.consumer = consumer;
509
- if (params == null) {
510
- params = {};
511
- }
512
- this.identifier = JSON.stringify(params);
513
- extend(this, mixin);
514
- }
515
-
516
- Subscription.prototype.perform = function(action, data) {
517
- if (data == null) {
518
- data = {};
519
- }
520
- data.action = action;
521
- return this.send(data);
522
- };
523
-
524
- Subscription.prototype.send = function(data) {
525
- return this.consumer.send({
526
- command: "message",
527
- identifier: this.identifier,
528
- data: JSON.stringify(data)
529
- });
530
- };
531
-
532
- Subscription.prototype.unsubscribe = function() {
533
- return this.consumer.subscriptions.remove(this);
534
- };
535
-
536
- extend = function(object, properties) {
537
- var key, value;
538
- if (properties != null) {
539
- for (key in properties) {
540
- value = properties[key];
541
- object[key] = value;
542
- }
543
- }
544
- return object;
545
- };
523
+ Subscription.prototype.perform = function(action, data) {
524
+ if (data == null) {
525
+ data = {};
526
+ }
527
+ data.action = action;
528
+ return this.send(data);
529
+ };
546
530
 
547
- return Subscription;
531
+ Subscription.prototype.send = function(data) {
532
+ return this.consumer.send({
533
+ command: "message",
534
+ identifier: this.identifier,
535
+ data: JSON.stringify(data)
536
+ });
537
+ };
548
538
 
549
- })();
539
+ Subscription.prototype.unsubscribe = function() {
540
+ return this.consumer.subscriptions.remove(this);
541
+ };
550
542
 
551
- }).call(this);
552
- (function() {
553
- ActionCable.Consumer = (function() {
554
- function Consumer(url) {
555
- this.url = url;
556
- this.subscriptions = new ActionCable.Subscriptions(this);
557
- this.connection = new ActionCable.Connection(this);
558
- }
543
+ extend = function(object, properties) {
544
+ var key, value;
545
+ if (properties != null) {
546
+ for (key in properties) {
547
+ value = properties[key];
548
+ object[key] = value;
549
+ }
550
+ }
551
+ return object;
552
+ };
559
553
 
560
- Consumer.prototype.send = function(data) {
561
- return this.connection.send(data);
562
- };
554
+ return Subscription;
563
555
 
564
- Consumer.prototype.connect = function() {
565
- return this.connection.open();
566
- };
556
+ })();
557
+
558
+ }).call(this);
559
+ (function() {
560
+ ActionCable.Consumer = (function() {
561
+ function Consumer(url) {
562
+ this.url = url;
563
+ this.subscriptions = new ActionCable.Subscriptions(this);
564
+ this.connection = new ActionCable.Connection(this);
565
+ }
567
566
 
568
- Consumer.prototype.disconnect = function() {
569
- return this.connection.close({
570
- allowReconnect: false
571
- });
572
- };
567
+ Consumer.prototype.send = function(data) {
568
+ return this.connection.send(data);
569
+ };
570
+
571
+ Consumer.prototype.connect = function() {
572
+ return this.connection.open();
573
+ };
574
+
575
+ Consumer.prototype.disconnect = function() {
576
+ return this.connection.close({
577
+ allowReconnect: false
578
+ });
579
+ };
580
+
581
+ Consumer.prototype.ensureActiveConnection = function() {
582
+ if (!this.connection.isActive()) {
583
+ return this.connection.open();
584
+ }
585
+ };
573
586
 
574
- Consumer.prototype.ensureActiveConnection = function() {
575
- if (!this.connection.isActive()) {
576
- return this.connection.open();
577
- }
578
- };
587
+ return Consumer;
579
588
 
580
- return Consumer;
589
+ })();
581
590
 
582
- })();
591
+ }).call(this);
592
+ }).call(this);
583
593
 
594
+ if (typeof module === "object" && module.exports) {
595
+ module.exports = ActionCable;
596
+ } else if (typeof define === "function" && define.amd) {
597
+ define(ActionCable);
598
+ }
584
599
  }).call(this);
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: actioncable
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.0.beta1
4
+ version: 5.1.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pratik Naik
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-02-23 00:00:00.000000000 Z
12
+ date: 2017-03-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionpack
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - '='
19
19
  - !ruby/object:Gem::Version
20
- version: 5.1.0.beta1
20
+ version: 5.1.0.rc1
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - '='
26
26
  - !ruby/object:Gem::Version
27
- version: 5.1.0.beta1
27
+ version: 5.1.0.rc1
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: nio4r
30
30
  requirement: !ruby/object:Gem::Requirement