pusher-js 7.0.2 → 7.0.6
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/.github/stale.yml +2 -2
- package/.github/workflows/release.yml +112 -0
- package/.github/workflows/release_pr.yml +42 -0
- package/.github/workflows/run-tests.yml +38 -0
- package/CHANGELOG.md +26 -0
- package/Makefile +17 -12
- package/README.md +28 -0
- package/dist/node/pusher.js +85 -44
- package/dist/node/pusher.js.map +1 -0
- package/dist/react-native/pusher.js +3 -2
- package/dist/react-native/pusher.js.map +1 -0
- package/dist/web/pusher-with-encryption.js +7 -5
- package/dist/web/pusher-with-encryption.js.map +1 -0
- package/dist/web/pusher-with-encryption.min.js +3 -2
- package/dist/web/pusher-with-encryption.min.js.map +1 -0
- package/dist/web/pusher.js +7 -5
- package/dist/web/pusher.js.map +1 -0
- package/dist/web/pusher.min.js +3 -2
- package/dist/web/pusher.min.js.map +1 -0
- package/dist/worker/pusher-with-encryption.worker.js +19 -7
- package/dist/worker/pusher-with-encryption.worker.js.map +1 -0
- package/dist/worker/pusher-with-encryption.worker.min.js +3 -2
- package/dist/worker/pusher-with-encryption.worker.min.js.map +1 -0
- package/dist/worker/pusher.worker.js +19 -7
- package/dist/worker/pusher.worker.js.map +1 -0
- package/dist/worker/pusher.worker.min.js +3 -2
- package/dist/worker/pusher.worker.min.js.map +1 -0
- package/package.json +17 -15
- package/spec/config/jasmine/helpers/reporter.js +14 -0
- package/spec/config/jasmine/integration.json +13 -0
- package/spec/config/jasmine/unit.json +13 -0
- package/spec/config/{jasmine-node → jasmine}/webpack.integration.js +4 -4
- package/spec/config/{jasmine-node → jasmine}/webpack.unit.js +4 -6
- package/spec/config/karma/config.common.js +10 -4
- package/spec/config/karma/config.integration.js +4 -4
- package/spec/config/karma/config.unit.js +5 -7
- package/spec/config/karma/integration.js +3 -3
- package/spec/config/karma/unit.js +2 -2
- package/spec/javascripts/helpers/mocks.js +18 -18
- package/spec/javascripts/helpers/waitsFor.js +37 -0
- package/spec/javascripts/integration/core/cluster_config_spec.js +45 -34
- package/spec/javascripts/integration/core/falling_back_spec.js +124 -127
- package/spec/javascripts/integration/core/pusher_spec/test_builder.js +264 -284
- package/spec/javascripts/integration/core/timeout_configuration_spec.js +24 -22
- package/spec/javascripts/integration/core/transport_lists_spec.js +8 -8
- package/spec/javascripts/integration/web/dom/jsonp_spec.js +67 -69
- package/spec/javascripts/integration/web/dom/script_request_spec.js +44 -52
- package/spec/javascripts/unit/core/channels/channel_spec.js +11 -21
- package/spec/javascripts/unit/core/channels/encrypted_channel_spec.js +9 -17
- package/spec/javascripts/unit/core/channels/presence_channel_spec.js +8 -19
- package/spec/javascripts/unit/core/channels/private_channel_spec.js +9 -19
- package/spec/javascripts/unit/core/config_spec.js +2 -2
- package/spec/javascripts/unit/core/connection/connection_manager_spec.js +69 -63
- package/spec/javascripts/unit/core/connection/connection_spec.js +14 -13
- package/spec/javascripts/unit/core/connection/handshake_spec.js +14 -12
- package/spec/javascripts/unit/core/connection/protocol_spec.js +9 -4
- package/spec/javascripts/unit/core/defaults_spec.js +1 -1
- package/spec/javascripts/unit/core/events_dispatcher_spec.js +20 -20
- package/spec/javascripts/unit/core/http/http_polling_socket_spec.js +4 -4
- package/spec/javascripts/unit/core/http/http_request_spec.js +20 -17
- package/spec/javascripts/unit/core/http/http_socket_spec.js +35 -32
- package/spec/javascripts/unit/core/http/http_streaming_socket_spec.js +4 -4
- package/spec/javascripts/unit/core/http/http_xhr_request_spec.js +13 -13
- package/spec/javascripts/unit/core/pusher_authorizer_spec.js +11 -11
- package/spec/javascripts/unit/core/pusher_spec.js +31 -27
- package/spec/javascripts/unit/core/strategies/best_connected_ever_strategy_spec.js +5 -5
- package/spec/javascripts/unit/core/strategies/cached_strategy_spec.js +17 -13
- package/spec/javascripts/unit/core/strategies/delayed_strategy_spec.js +12 -8
- package/spec/javascripts/unit/core/strategies/sequential_strategy_spec.js +23 -19
- package/spec/javascripts/unit/core/strategies/transport_strategy_spec.js +22 -24
- package/spec/javascripts/unit/core/timeline/timeline_spec.js +16 -9
- package/spec/javascripts/unit/core/transports/assistant_to_the_transport_manager_spec.js +36 -22
- package/spec/javascripts/unit/core/transports/hosts_and_ports_spec.js +10 -10
- package/spec/javascripts/unit/core/transports/transport_connection_spec.js +81 -86
- package/spec/javascripts/unit/core/transports/transport_manager_spec.js +1 -1
- package/spec/javascripts/unit/core/utils/periodic_timer_spec.js +17 -16
- package/spec/javascripts/unit/core/utils/timers_spec.js +32 -26
- package/spec/javascripts/unit/isomorphic/transports/hosts_and_ports_spec.js +12 -8
- package/spec/javascripts/unit/isomorphic/transports/transports_spec.js +7 -7
- package/spec/javascripts/unit/node/timeline_sender_spec.js +5 -5
- package/spec/javascripts/unit/web/dom/dependency_loader_spec.js +30 -30
- package/spec/javascripts/unit/web/dom/jsonp_request_spec.js +7 -7
- package/spec/javascripts/unit/web/http/http_xdomain_request_spec.js +22 -22
- package/spec/javascripts/unit/web/pusher_authorizer_spec.js +3 -3
- package/spec/javascripts/unit/web/timeline/timeline_sender_spec.js +12 -12
- package/spec/javascripts/unit/web/transports/hosts_and_ports_spec.js +15 -12
- package/spec/javascripts/unit/web/transports/transports_spec.js +24 -26
- package/spec/javascripts/unit/worker/pusher_authorizer_spec.js +2 -2
- package/spec/javascripts/unit/worker/timeline_sender_spec.js +2 -2
- package/src/core/auth/options.ts +1 -0
- package/types/src/core/auth/options.d.ts +1 -0
- package/webpack/config.node.js +2 -2
- package/webpack/config.react-native.js +2 -2
- package/webpack/config.shared.js +9 -1
- package/webpack/config.web.js +2 -2
- package/webpack/config.worker.js +5 -3
- package/worker/index.d.ts +15 -0
- package/worker/index.js +1 -0
- package/worker/with-encryption/index.d.ts +15 -0
- package/worker/with-encryption/index.js +1 -0
- package/.travis.build +0 -22
- package/.travis.yml +0 -7
- package/spec/config/jasmine-node/config.js +0 -10
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
const Pusher = require('pusher_integration');
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
const Integration = require('integration');
|
|
4
|
+
const OneOffTimer = require('core/utils/timers').OneOffTimer;
|
|
5
|
+
const Collections = require('core/utils/collections');
|
|
6
|
+
const Runtime = require('runtime').default;
|
|
7
|
+
const TRANSPORTS = Runtime.Transports;
|
|
8
|
+
const waitsFor = require('../../../helpers/waitsFor');
|
|
8
9
|
|
|
9
10
|
// this is a slightly horrible function that allows easy placement of arbitrary
|
|
10
11
|
// delays in jasmine async tests. e.g:
|
|
@@ -47,16 +48,25 @@ function build(testConfig) {
|
|
|
47
48
|
|
|
48
49
|
describe("with " + (transport ? transport + ", " : "") + "forceTLS=" + forceTLS, function() {
|
|
49
50
|
var pusher1, pusher2;
|
|
51
|
+
var jasmineDefaultTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
|
|
52
|
+
|
|
53
|
+
beforeAll(() => {
|
|
54
|
+
jasmine.DEFAULT_TIMEOUT_INTERVAL = 41000;
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
afterAll(() => {
|
|
58
|
+
jasmine.DEFAULT_TIMEOUT_INTERVAL = jasmineDefaultTimeout;
|
|
59
|
+
});
|
|
50
60
|
|
|
51
61
|
beforeEach(function() {
|
|
52
62
|
Collections.objectApply(TRANSPORTS, function(t, name) {
|
|
53
|
-
spyOn(t, "isSupported").
|
|
63
|
+
spyOn(t, "isSupported").and.returnValue(false);
|
|
54
64
|
});
|
|
55
|
-
TRANSPORTS[transport].isSupported.
|
|
65
|
+
TRANSPORTS[transport].isSupported.and.returnValue(true);
|
|
56
66
|
});
|
|
57
67
|
|
|
58
68
|
describe("setup", function() {
|
|
59
|
-
it("should open connections", function() {
|
|
69
|
+
it("should open connections", async function() {
|
|
60
70
|
pusher1 = new Pusher("7324d55a5eeb8f554761", {
|
|
61
71
|
forceTLS: forceTLS,
|
|
62
72
|
});
|
|
@@ -64,11 +74,11 @@ function build(testConfig) {
|
|
|
64
74
|
pusher2 = new Pusher("7324d55a5eeb8f554761", {
|
|
65
75
|
forceTLS: forceTLS,
|
|
66
76
|
});
|
|
67
|
-
waitsFor(function() {
|
|
77
|
+
await waitsFor(function() {
|
|
68
78
|
return pusher2.connection.state === "connected";
|
|
69
79
|
}, "second connection to be established", 20000);
|
|
70
80
|
}
|
|
71
|
-
waitsFor(function() {
|
|
81
|
+
await waitsFor(function() {
|
|
72
82
|
return pusher1.connection.state === "connected";
|
|
73
83
|
}, "first connection to be established", 20000);
|
|
74
84
|
});
|
|
@@ -132,7 +142,7 @@ function build(testConfig) {
|
|
|
132
142
|
});
|
|
133
143
|
}
|
|
134
144
|
function buildPresenceChannelTests(getPusher1, getPusher2) {
|
|
135
|
-
it("should get connection's member data", function() {
|
|
145
|
+
it("should get connection's member data", async function() {
|
|
136
146
|
var pusher = getPusher1();
|
|
137
147
|
var channelName = Integration.getRandomName("presence-integration_me");
|
|
138
148
|
|
|
@@ -141,21 +151,20 @@ function buildPresenceChannelTests(getPusher1, getPusher2) {
|
|
|
141
151
|
members = ms;
|
|
142
152
|
});
|
|
143
153
|
|
|
144
|
-
waitsFor(function() {
|
|
154
|
+
await waitsFor(function() {
|
|
145
155
|
return members !== null;
|
|
146
156
|
}, "channel to subscribe", 10000);
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
});
|
|
157
|
+
|
|
158
|
+
expect(members.me).toEqual({
|
|
159
|
+
id: pusher.connection.socket_id,
|
|
160
|
+
info: {
|
|
161
|
+
name: "Integration " + pusher.connection.socket_id,
|
|
162
|
+
email: "integration-" + pusher.connection.socket_id + "@example.com"
|
|
163
|
+
}
|
|
155
164
|
});
|
|
156
165
|
});
|
|
157
166
|
|
|
158
|
-
it("should receive a member added event", function() {
|
|
167
|
+
it("should receive a member added event", async function() {
|
|
159
168
|
var pusher1 = getPusher1();
|
|
160
169
|
var pusher2 = getPusher2();
|
|
161
170
|
var channelName = Integration.getRandomName("presence-integration_member_added");
|
|
@@ -169,25 +178,24 @@ function buildPresenceChannelTests(getPusher1, getPusher2) {
|
|
|
169
178
|
subscribe(pusher2, channelName, function() {});
|
|
170
179
|
});
|
|
171
180
|
|
|
172
|
-
waitsFor(function() {
|
|
181
|
+
await waitsFor(function() {
|
|
173
182
|
return member !== null;
|
|
174
183
|
}, "the member added event", 10000);
|
|
175
|
-
runs(function() {
|
|
176
|
-
expect(member.id).toEqual(pusher2.connection.socket_id);
|
|
177
|
-
expect(member).toEqual({
|
|
178
|
-
id: pusher2.connection.socket_id,
|
|
179
|
-
info: {
|
|
180
|
-
name: "Integration " + pusher2.connection.socket_id,
|
|
181
|
-
email: "integration-" + pusher2.connection.socket_id + "@example.com"
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
184
|
|
|
185
|
-
|
|
186
|
-
|
|
185
|
+
expect(member.id).toEqual(pusher2.connection.socket_id);
|
|
186
|
+
expect(member).toEqual({
|
|
187
|
+
id: pusher2.connection.socket_id,
|
|
188
|
+
info: {
|
|
189
|
+
name: "Integration " + pusher2.connection.socket_id,
|
|
190
|
+
email: "integration-" + pusher2.connection.socket_id + "@example.com"
|
|
191
|
+
}
|
|
187
192
|
});
|
|
193
|
+
|
|
194
|
+
pusher1.unsubscribe(channelName);
|
|
195
|
+
pusher2.unsubscribe(channelName);
|
|
188
196
|
});
|
|
189
197
|
|
|
190
|
-
it("should receive a member removed event", function() {
|
|
198
|
+
it("should receive a member removed event", async function() {
|
|
191
199
|
var pusher1 = getPusher1();
|
|
192
200
|
var pusher2 = getPusher2();
|
|
193
201
|
var channelName = Integration.getRandomName("presence-integration_member_removed");
|
|
@@ -204,24 +212,23 @@ function buildPresenceChannelTests(getPusher1, getPusher2) {
|
|
|
204
212
|
subscribe(pusher1, channelName, function() {});
|
|
205
213
|
});
|
|
206
214
|
|
|
207
|
-
waitsFor(function() {
|
|
215
|
+
await waitsFor(function() {
|
|
208
216
|
return member !== null;
|
|
209
217
|
}, "the member removed event", 10000);
|
|
210
|
-
runs(function() {
|
|
211
|
-
expect(member.id).toEqual(pusher1.connection.socket_id);
|
|
212
|
-
expect(member).toEqual({
|
|
213
|
-
id: pusher1.connection.socket_id,
|
|
214
|
-
info: {
|
|
215
|
-
name: "Integration " + pusher1.connection.socket_id,
|
|
216
|
-
email: "integration-" + pusher1.connection.socket_id + "@example.com"
|
|
217
|
-
}
|
|
218
|
-
});
|
|
219
218
|
|
|
220
|
-
|
|
219
|
+
expect(member.id).toEqual(pusher1.connection.socket_id);
|
|
220
|
+
expect(member).toEqual({
|
|
221
|
+
id: pusher1.connection.socket_id,
|
|
222
|
+
info: {
|
|
223
|
+
name: "Integration " + pusher1.connection.socket_id,
|
|
224
|
+
email: "integration-" + pusher1.connection.socket_id + "@example.com"
|
|
225
|
+
}
|
|
221
226
|
});
|
|
227
|
+
|
|
228
|
+
pusher2.unsubscribe(channelName);
|
|
222
229
|
});
|
|
223
230
|
|
|
224
|
-
it("should maintain correct members count", function() {
|
|
231
|
+
it("should maintain correct members count", async function() {
|
|
225
232
|
var pusher1 = getPusher1();
|
|
226
233
|
var pusher2 = getPusher2();
|
|
227
234
|
var channelName = Integration.getRandomName("presence-integration_member_count");
|
|
@@ -233,41 +240,39 @@ function buildPresenceChannelTests(getPusher1, getPusher2) {
|
|
|
233
240
|
var onMemberAdded = jasmine.createSpy("onMemberAdded");
|
|
234
241
|
var onMemberRemoved = jasmine.createSpy("onMemberRemoved");
|
|
235
242
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
return onSubscribed1.calls.length > 0;
|
|
243
|
+
channel1 = subscribe(pusher1, channelName, onSubscribed1);
|
|
244
|
+
expect(channel1.members.count).toEqual(0);
|
|
245
|
+
|
|
246
|
+
await waitsFor(function() {
|
|
247
|
+
return onSubscribed1.calls.count() > 0;
|
|
242
248
|
}, "first connection to subscribe", 10000);
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
waitsFor(function() {
|
|
249
|
-
return onSubscribed2.calls.
|
|
249
|
+
|
|
250
|
+
expect(channel1.members.count).toEqual(1);
|
|
251
|
+
channel1.bind("pusher:member_added", onMemberAdded);
|
|
252
|
+
channel2 = subscribe(pusher2, channelName, onSubscribed2);
|
|
253
|
+
|
|
254
|
+
await waitsFor(function() {
|
|
255
|
+
return onSubscribed2.calls.count() > 0;
|
|
250
256
|
}, "second connection to subscribe", 10000);
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
waitsFor(function() {
|
|
255
|
-
return onMemberAdded.calls.
|
|
257
|
+
|
|
258
|
+
expect(channel2.members.count).toEqual(2);
|
|
259
|
+
|
|
260
|
+
await waitsFor(function() {
|
|
261
|
+
return onMemberAdded.calls.count() > 0;
|
|
256
262
|
}, "member added event", 10000);
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
waitsFor(function() {
|
|
263
|
-
return onMemberRemoved.calls.
|
|
263
|
+
|
|
264
|
+
expect(channel1.members.count).toEqual(2);
|
|
265
|
+
channel2.bind("pusher:member_removed", onMemberRemoved);
|
|
266
|
+
pusher1.unsubscribe(channelName);
|
|
267
|
+
|
|
268
|
+
await waitsFor(function() {
|
|
269
|
+
return onMemberRemoved.calls.count() > 0;
|
|
264
270
|
}, "member removed event", 10000);
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
});
|
|
271
|
+
|
|
272
|
+
expect(channel2.members.count).toEqual(1);
|
|
268
273
|
});
|
|
269
274
|
|
|
270
|
-
it("should maintain correct members data", function() {
|
|
275
|
+
it("should maintain correct members data", async function() {
|
|
271
276
|
var pusher1 = getPusher1();
|
|
272
277
|
var pusher2 = getPusher2();
|
|
273
278
|
var channelName = Integration.getRandomName("presence-integration_member_count");
|
|
@@ -294,59 +299,57 @@ function buildPresenceChannelTests(getPusher1, getPusher2) {
|
|
|
294
299
|
}
|
|
295
300
|
};
|
|
296
301
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
return onSubscribed1.calls.length > 0;
|
|
302
|
+
channel1 = subscribe(pusher1, channelName, onSubscribed1);
|
|
303
|
+
|
|
304
|
+
await waitsFor(function() {
|
|
305
|
+
return onSubscribed1.calls.count() > 0;
|
|
302
306
|
}, "first connection to subscribe", 10000);
|
|
303
|
-
runs(function() {
|
|
304
|
-
expect(channel1.members.get(pusher1.connection.socket_id))
|
|
305
|
-
.toEqual(member1);
|
|
306
|
-
expect(channel1.members.get(pusher2.connection.socket_id))
|
|
307
|
-
.toBe(null);
|
|
308
307
|
|
|
309
|
-
|
|
308
|
+
expect(channel1.members.get(pusher1.connection.socket_id))
|
|
309
|
+
.toEqual(member1);
|
|
310
|
+
expect(channel1.members.get(pusher2.connection.socket_id))
|
|
311
|
+
.toBe(null);
|
|
310
312
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
313
|
+
expect(channel1.members.me).toEqual(member1);
|
|
314
|
+
|
|
315
|
+
channel1.bind("pusher:member_added", onMemberAdded);
|
|
316
|
+
channel2 = subscribe(pusher2, channelName, onSubscribed2);
|
|
317
|
+
|
|
318
|
+
await waitsFor(function() {
|
|
319
|
+
return onSubscribed2.calls.count() > 0;
|
|
316
320
|
}, "second connection to subscribe", 10000);
|
|
317
|
-
runs(function() {
|
|
318
|
-
expect(channel2.members.get(pusher1.connection.socket_id))
|
|
319
|
-
.toEqual(member1);
|
|
320
|
-
expect(channel2.members.get(pusher2.connection.socket_id))
|
|
321
|
-
.toEqual(member2);
|
|
322
321
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
322
|
+
expect(channel2.members.get(pusher1.connection.socket_id))
|
|
323
|
+
.toEqual(member1);
|
|
324
|
+
expect(channel2.members.get(pusher2.connection.socket_id))
|
|
325
|
+
.toEqual(member2);
|
|
326
|
+
|
|
327
|
+
expect(channel2.members.me).toEqual(member2);
|
|
328
|
+
|
|
329
|
+
await waitsFor(function() {
|
|
330
|
+
return onMemberAdded.calls.count() > 0;
|
|
327
331
|
}, "member added event", 10000);
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
waitsFor(function() {
|
|
338
|
-
return onMemberRemoved.calls.
|
|
332
|
+
|
|
333
|
+
expect(channel1.members.get(pusher1.connection.socket_id))
|
|
334
|
+
.toEqual(member1);
|
|
335
|
+
expect(channel1.members.get(pusher2.connection.socket_id))
|
|
336
|
+
.toEqual(member2);
|
|
337
|
+
|
|
338
|
+
channel2.bind("pusher:member_removed", onMemberRemoved);
|
|
339
|
+
pusher1.unsubscribe(channelName);
|
|
340
|
+
|
|
341
|
+
await waitsFor(function() {
|
|
342
|
+
return onMemberRemoved.calls.count() > 0;
|
|
339
343
|
}, "member removed event", 10000);
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
});
|
|
344
|
+
|
|
345
|
+
expect(channel2.members.get(pusher1.connection.socket_id))
|
|
346
|
+
.toBe(null);
|
|
347
|
+
expect(channel2.members.get(pusher2.connection.socket_id))
|
|
348
|
+
.toEqual(member2);
|
|
346
349
|
});
|
|
347
350
|
}
|
|
348
351
|
function buildClientEventsTests(getPusher1, getPusher2, prefix) {
|
|
349
|
-
it("should receive a client event sent by another connection", function() {
|
|
352
|
+
it("should receive a client event sent by another connection", async function() {
|
|
350
353
|
var pusher1 = getPusher1();
|
|
351
354
|
var pusher2 = getPusher2();
|
|
352
355
|
|
|
@@ -361,28 +364,27 @@ function buildClientEventsTests(getPusher1, getPusher2, prefix) {
|
|
|
361
364
|
var onEvent1 = jasmine.createSpy("onEvent1");
|
|
362
365
|
var onEvent2 = jasmine.createSpy("onEvent2");
|
|
363
366
|
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
waitsFor(function() {
|
|
369
|
-
return onSubscribed1.calls.
|
|
367
|
+
|
|
368
|
+
channel1 = subscribe(pusher1, channelName, onSubscribed1);
|
|
369
|
+
channel2 = subscribe(pusher2, channelName, onSubscribed2);
|
|
370
|
+
|
|
371
|
+
await waitsFor(function() {
|
|
372
|
+
return onSubscribed1.calls.count() > 0 && onSubscribed2.calls.count() > 0;
|
|
370
373
|
}, "both connections to subscribe", 10000);
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
waitsFor(function() {
|
|
377
|
-
return onEvent2.calls.
|
|
374
|
+
|
|
375
|
+
channel1.bind(eventName, onEvent1);
|
|
376
|
+
channel2.bind(eventName, onEvent2);
|
|
377
|
+
pusher1.send_event(eventName, data, channelName);
|
|
378
|
+
|
|
379
|
+
await waitsFor(function() {
|
|
380
|
+
return onEvent2.calls.count();
|
|
378
381
|
}, "second connection to receive a message", 10000);
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
});
|
|
382
|
+
|
|
383
|
+
pusher1.unsubscribe(channelName);
|
|
384
|
+
pusher2.unsubscribe(channelName);
|
|
383
385
|
});
|
|
384
386
|
|
|
385
|
-
it("should not receive a client event sent by itself", function() {
|
|
387
|
+
it("should not receive a client event sent by itself", async function() {
|
|
386
388
|
var pusher = getPusher1();
|
|
387
389
|
|
|
388
390
|
var channelName = Integration.getRandomName((prefix || "") + "integration_client_events");
|
|
@@ -393,25 +395,24 @@ function buildClientEventsTests(getPusher1, getPusher2, prefix) {
|
|
|
393
395
|
var timer = null;
|
|
394
396
|
|
|
395
397
|
var channel = subscribe(pusher, channelName, onSubscribed);
|
|
396
|
-
waitsFor(function() {
|
|
397
|
-
return onSubscribed.calls.
|
|
398
|
+
await waitsFor(function() {
|
|
399
|
+
return onSubscribed.calls.count() > 0;
|
|
398
400
|
}, "connection to subscribe", 10000);
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
waitsFor(function() {
|
|
401
|
+
|
|
402
|
+
channel.bind(eventName, onEvent);
|
|
403
|
+
pusher.send_event(eventName, {}, channelName);
|
|
404
|
+
timer = new OneOffTimer(3000, function() {});
|
|
405
|
+
|
|
406
|
+
await waitsFor(function() {
|
|
405
407
|
return !timer.isRunning();
|
|
406
408
|
}, "timer to finish", 3210);
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
});
|
|
409
|
+
|
|
410
|
+
expect(onEvent).not.toHaveBeenCalled();
|
|
411
|
+
pusher.unsubscribe(channelName);
|
|
411
412
|
});
|
|
412
413
|
}
|
|
413
414
|
function buildPublicChannelTests(getPusher, prefix) {
|
|
414
|
-
it("should subscribe and receive a message sent via REST API", function() {
|
|
415
|
+
it("should subscribe and receive a message sent via REST API", async function() {
|
|
415
416
|
var pusher = getPusher();
|
|
416
417
|
var channelName = Integration.getRandomName((prefix || "") + "integration");
|
|
417
418
|
|
|
@@ -422,30 +423,29 @@ function buildPublicChannelTests(getPusher, prefix) {
|
|
|
422
423
|
var data = { x: 1, y: "z" };
|
|
423
424
|
var received = null;
|
|
424
425
|
|
|
425
|
-
waitsFor(function() {
|
|
426
|
-
return onSubscribed.calls.
|
|
426
|
+
await waitsFor(function() {
|
|
427
|
+
return onSubscribed.calls.count();
|
|
427
428
|
}, "subscription to succeed", 10000);
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
});
|
|
432
|
-
Integration.sendAPIMessage({
|
|
433
|
-
url: Integration.API_URL + "/v2/send",
|
|
434
|
-
channel: channelName,
|
|
435
|
-
event: eventName,
|
|
436
|
-
data: data
|
|
437
|
-
});
|
|
429
|
+
|
|
430
|
+
channel.bind(eventName, function(message) {
|
|
431
|
+
received = message;
|
|
438
432
|
});
|
|
439
|
-
|
|
433
|
+
Integration.sendAPIMessage({
|
|
434
|
+
url: Integration.API_URL + "/v2/send",
|
|
435
|
+
channel: channelName,
|
|
436
|
+
event: eventName,
|
|
437
|
+
data: data
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
await waitsFor(function() {
|
|
440
441
|
return received !== null;
|
|
441
442
|
}, "message to get delivered", 10000);
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
});
|
|
443
|
+
|
|
444
|
+
expect(received).toEqual(data);
|
|
445
|
+
pusher.unsubscribe(channelName);
|
|
446
446
|
});
|
|
447
447
|
|
|
448
|
-
it("should not receive messages after unsubscribing", function() {
|
|
448
|
+
it("should not receive messages after unsubscribing", async function() {
|
|
449
449
|
var pusher = getPusher();
|
|
450
450
|
var channelName = Integration.getRandomName((prefix || "") + "integration");
|
|
451
451
|
|
|
@@ -456,48 +456,46 @@ function buildPublicChannelTests(getPusher, prefix) {
|
|
|
456
456
|
var received = null;
|
|
457
457
|
var timer = null;
|
|
458
458
|
|
|
459
|
-
waitsFor(function() {
|
|
460
|
-
return onSubscribed.calls.
|
|
459
|
+
await waitsFor(function() {
|
|
460
|
+
return onSubscribed.calls.count();
|
|
461
461
|
}, "subscription to succeed", 10000);
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
});
|
|
466
|
-
pusher.unsubscribe(channelName);
|
|
467
|
-
Integration.sendAPIMessage({
|
|
468
|
-
url: Integration.API_URL + "/v2/send",
|
|
469
|
-
channel: channelName,
|
|
470
|
-
event: eventName,
|
|
471
|
-
data: {}
|
|
472
|
-
});
|
|
473
|
-
timer = new Timer(3000, function() {});
|
|
462
|
+
|
|
463
|
+
channel.bind(eventName, function(message) {
|
|
464
|
+
received = message;
|
|
474
465
|
});
|
|
475
|
-
|
|
466
|
+
pusher.unsubscribe(channelName);
|
|
467
|
+
Integration.sendAPIMessage({
|
|
468
|
+
url: Integration.API_URL + "/v2/send",
|
|
469
|
+
channel: channelName,
|
|
470
|
+
event: eventName,
|
|
471
|
+
data: {}
|
|
472
|
+
});
|
|
473
|
+
timer = new OneOffTimer(3000, function() {});
|
|
474
|
+
|
|
475
|
+
await waitsFor(function() {
|
|
476
476
|
return !timer.isRunning();
|
|
477
477
|
}, "timer to finish", 3210);
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
});
|
|
478
|
+
|
|
479
|
+
expect(received).toBe(null);
|
|
481
480
|
});
|
|
482
481
|
|
|
483
|
-
it("should handle unsubscribing as an idempotent operation", function() {
|
|
482
|
+
it("should handle unsubscribing as an idempotent operation", async function() {
|
|
484
483
|
var pusher = getPusher();
|
|
485
484
|
var channelName = Integration.getRandomName((prefix || "") + "integration");
|
|
486
485
|
|
|
487
486
|
var onSubscribed = jasmine.createSpy("onSubscribed");
|
|
488
487
|
subscribe(pusher, channelName, onSubscribed);
|
|
489
488
|
|
|
490
|
-
waitsFor(function() {
|
|
491
|
-
return onSubscribed.calls.
|
|
489
|
+
await waitsFor(function() {
|
|
490
|
+
return onSubscribed.calls.count();
|
|
492
491
|
}, "subscription to succeed", 10000);
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
});
|
|
492
|
+
|
|
493
|
+
pusher.unsubscribe(channelName);
|
|
494
|
+
pusher.unsubscribe(channelName);
|
|
495
|
+
pusher.unsubscribe(channelName);
|
|
498
496
|
});
|
|
499
497
|
|
|
500
|
-
it("should handle cancelling pending subscription", function() {
|
|
498
|
+
it("should handle cancelling pending subscription", async function() {
|
|
501
499
|
var pusher = getPusher();
|
|
502
500
|
var channelName = Integration.getRandomName((prefix || "") + "integration");
|
|
503
501
|
|
|
@@ -511,28 +509,27 @@ function buildPublicChannelTests(getPusher, prefix) {
|
|
|
511
509
|
});
|
|
512
510
|
|
|
513
511
|
pusher.unsubscribe(channelName);
|
|
514
|
-
waitsFor(function() {
|
|
512
|
+
await waitsFor(function() {
|
|
515
513
|
return !channel.subscriptionPending;
|
|
516
514
|
}, "subscription to succeed", 10000);
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
});
|
|
524
|
-
timer = new Timer(3000, function() {});
|
|
515
|
+
|
|
516
|
+
Integration.sendAPIMessage({
|
|
517
|
+
url: Integration.API_URL + "/v2/send",
|
|
518
|
+
channel: channelName,
|
|
519
|
+
event: eventName,
|
|
520
|
+
data: {}
|
|
525
521
|
});
|
|
526
|
-
|
|
522
|
+
timer = new OneOffTimer(3000, function() {});
|
|
523
|
+
|
|
524
|
+
await waitsFor(function() {
|
|
527
525
|
return !timer.isRunning();
|
|
528
526
|
}, "timer to finish", 10000);
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
});
|
|
527
|
+
|
|
528
|
+
expect(channel.subscribed).toEqual(false);
|
|
529
|
+
expect(received).toBe(null);
|
|
533
530
|
});
|
|
534
531
|
|
|
535
|
-
it("should handle reinstating cancelled pending subscription", function() {
|
|
532
|
+
it("should handle reinstating cancelled pending subscription", async function() {
|
|
536
533
|
var pusher = getPusher();
|
|
537
534
|
var channelName = Integration.getRandomName((prefix || "") + "integration");
|
|
538
535
|
|
|
@@ -547,30 +544,29 @@ function buildPublicChannelTests(getPusher, prefix) {
|
|
|
547
544
|
|
|
548
545
|
pusher.unsubscribe(channelName);
|
|
549
546
|
pusher.subscribe(channelName);
|
|
550
|
-
waitsFor(function() {
|
|
547
|
+
await waitsFor(function() {
|
|
551
548
|
return !channel.subscriptionPending;
|
|
552
549
|
}, "subscription to succeed", 10000);
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
});
|
|
560
|
-
timer = new Timer(3000, function() {});
|
|
550
|
+
|
|
551
|
+
Integration.sendAPIMessage({
|
|
552
|
+
url: Integration.API_URL + "/v2/send",
|
|
553
|
+
channel: channelName,
|
|
554
|
+
event: eventName,
|
|
555
|
+
data: {}
|
|
561
556
|
});
|
|
562
|
-
|
|
557
|
+
timer = new OneOffTimer(3000, function() {});
|
|
558
|
+
|
|
559
|
+
await waitsFor(function() {
|
|
563
560
|
return !timer.isRunning();
|
|
564
561
|
}, "timer to finish", 10000);
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
});
|
|
562
|
+
|
|
563
|
+
expect(channel.subscribed).toEqual(true);
|
|
564
|
+
expect(received).not.toBe(null);
|
|
569
565
|
});
|
|
570
566
|
}
|
|
571
567
|
|
|
572
568
|
function buildSubscriptionStateTests(getPusher, prefix) {
|
|
573
|
-
it("sub-sub = sub", function() {
|
|
569
|
+
it("sub-sub = sub", async function() {
|
|
574
570
|
var pusher = getPusher();
|
|
575
571
|
var channelName = Integration.getRandomName((prefix || "") + "integration");
|
|
576
572
|
|
|
@@ -583,18 +579,16 @@ function buildSubscriptionStateTests(getPusher, prefix) {
|
|
|
583
579
|
expect(pusher.channel(channelName).subscriptionPending).toEqual(true);
|
|
584
580
|
expect(pusher.channel(channelName).subscriptionCancelled).toEqual(false);
|
|
585
581
|
|
|
586
|
-
waitsFor(function() {
|
|
582
|
+
await waitsFor(function() {
|
|
587
583
|
return pusher.channel(channelName).subscribed;
|
|
588
584
|
}, "subscription to finish", 10000);
|
|
589
585
|
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
expect(pusher.channel(channelName).subscriptionCancelled).toEqual(false);
|
|
594
|
-
});
|
|
586
|
+
expect(pusher.channel(channelName).subscribed).toEqual(true);
|
|
587
|
+
expect(pusher.channel(channelName).subscriptionPending).toEqual(false);
|
|
588
|
+
expect(pusher.channel(channelName).subscriptionCancelled).toEqual(false);
|
|
595
589
|
});
|
|
596
590
|
|
|
597
|
-
it("sub-wait-sub = sub", function() {
|
|
591
|
+
it("sub-wait-sub = sub", async function() {
|
|
598
592
|
var pusher = getPusher();
|
|
599
593
|
var channelName = Integration.getRandomName((prefix || "") + "integration");
|
|
600
594
|
|
|
@@ -603,23 +597,21 @@ function buildSubscriptionStateTests(getPusher, prefix) {
|
|
|
603
597
|
expect(pusher.channel(channelName).subscriptionPending).toEqual(true);
|
|
604
598
|
expect(pusher.channel(channelName).subscriptionCancelled).toEqual(false);
|
|
605
599
|
|
|
606
|
-
waitsFor(function() {
|
|
600
|
+
await waitsFor(function() {
|
|
607
601
|
return pusher.channel(channelName).subscribed;
|
|
608
602
|
}, "subscription to finish", 10000);
|
|
609
603
|
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
expect(pusher.channel(channelName).subscriptionCancelled).toEqual(false);
|
|
604
|
+
expect(pusher.channel(channelName).subscribed).toEqual(true);
|
|
605
|
+
expect(pusher.channel(channelName).subscriptionPending).toEqual(false);
|
|
606
|
+
expect(pusher.channel(channelName).subscriptionCancelled).toEqual(false);
|
|
614
607
|
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
});
|
|
608
|
+
pusher.subscribe(channelName)
|
|
609
|
+
expect(pusher.channel(channelName).subscribed).toEqual(true);
|
|
610
|
+
expect(pusher.channel(channelName).subscriptionPending).toEqual(false);
|
|
611
|
+
expect(pusher.channel(channelName).subscriptionCancelled).toEqual(false);
|
|
620
612
|
});
|
|
621
613
|
|
|
622
|
-
it("sub-unsub = NOP", function() {
|
|
614
|
+
it("sub-unsub = NOP", async function() {
|
|
623
615
|
var pusher = getPusher();
|
|
624
616
|
var channelName = Integration.getRandomName((prefix || "") + "integration");
|
|
625
617
|
|
|
@@ -635,14 +627,12 @@ function buildSubscriptionStateTests(getPusher, prefix) {
|
|
|
635
627
|
|
|
636
628
|
// there is no easy way to know when an unsubscribe request has been
|
|
637
629
|
// actioned by the server, so we just wait a while
|
|
638
|
-
waitsFor(sleep(3000), "unsubscription to finish", 3500)
|
|
630
|
+
await waitsFor(sleep(3000), "unsubscription to finish", 3500)
|
|
639
631
|
|
|
640
|
-
|
|
641
|
-
expect(pusher.channel(channelName)).toBe(undefined);
|
|
642
|
-
});
|
|
632
|
+
expect(pusher.channel(channelName)).toBe(undefined);
|
|
643
633
|
});
|
|
644
634
|
|
|
645
|
-
it("sub-wait-unsub = NOP", function() {
|
|
635
|
+
it("sub-wait-unsub = NOP", async function() {
|
|
646
636
|
var pusher = getPusher();
|
|
647
637
|
var channelName = Integration.getRandomName((prefix || "") + "integration");
|
|
648
638
|
|
|
@@ -651,21 +641,19 @@ function buildSubscriptionStateTests(getPusher, prefix) {
|
|
|
651
641
|
expect(pusher.channel(channelName).subscriptionPending).toEqual(true);
|
|
652
642
|
expect(pusher.channel(channelName).subscriptionCancelled).toEqual(false);
|
|
653
643
|
|
|
654
|
-
waitsFor(function() {
|
|
644
|
+
await waitsFor(function() {
|
|
655
645
|
return pusher.channel(channelName).subscribed;
|
|
656
646
|
}, "subscription to finish", 10000);
|
|
657
647
|
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
expect(pusher.channel(channelName).subscriptionCancelled).toEqual(false);
|
|
648
|
+
expect(pusher.channel(channelName).subscribed).toEqual(true);
|
|
649
|
+
expect(pusher.channel(channelName).subscriptionPending).toEqual(false);
|
|
650
|
+
expect(pusher.channel(channelName).subscriptionCancelled).toEqual(false);
|
|
662
651
|
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
});
|
|
652
|
+
pusher.unsubscribe(channelName)
|
|
653
|
+
expect(pusher.channel(channelName)).toBe(undefined);
|
|
666
654
|
});
|
|
667
655
|
|
|
668
|
-
it("sub-unsub-sub = sub", function() {
|
|
656
|
+
it("sub-unsub-sub = sub", async function() {
|
|
669
657
|
var pusher = getPusher();
|
|
670
658
|
var channelName = Integration.getRandomName((prefix || "") + "integration");
|
|
671
659
|
|
|
@@ -684,18 +672,16 @@ function buildSubscriptionStateTests(getPusher, prefix) {
|
|
|
684
672
|
expect(pusher.channel(channelName).subscriptionPending).toEqual(true);
|
|
685
673
|
expect(pusher.channel(channelName).subscriptionCancelled).toEqual(false);
|
|
686
674
|
|
|
687
|
-
waitsFor(function() {
|
|
675
|
+
await waitsFor(function() {
|
|
688
676
|
return pusher.channel(channelName).subscribed;
|
|
689
677
|
}, "subscription to finish", 10000);
|
|
690
678
|
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
expect(pusher.channel(channelName).subscriptionCancelled).toEqual(false);
|
|
695
|
-
});
|
|
679
|
+
expect(pusher.channel(channelName).subscribed).toEqual(true);
|
|
680
|
+
expect(pusher.channel(channelName).subscriptionPending).toEqual(false);
|
|
681
|
+
expect(pusher.channel(channelName).subscriptionCancelled).toEqual(false);
|
|
696
682
|
});
|
|
697
683
|
|
|
698
|
-
it("sub-unsub-wait-sub = sub", function() {
|
|
684
|
+
it("sub-unsub-wait-sub = sub", async function() {
|
|
699
685
|
var pusher = getPusher();
|
|
700
686
|
var channelName = Integration.getRandomName((prefix || "") + "integration");
|
|
701
687
|
|
|
@@ -711,28 +697,24 @@ function buildSubscriptionStateTests(getPusher, prefix) {
|
|
|
711
697
|
|
|
712
698
|
// there is no easy way to know when an unsubscribe request has been
|
|
713
699
|
// actioned by the server, so we just wait a while
|
|
714
|
-
waitsFor(sleep(3000), "unsubscription to finish", 3500)
|
|
715
|
-
|
|
716
|
-
expect(pusher.channel(channelName)).toBe(undefined);
|
|
717
|
-
|
|
718
|
-
pusher.subscribe(channelName)
|
|
719
|
-
expect(pusher.channel(channelName).subscribed).toEqual(false);
|
|
720
|
-
expect(pusher.channel(channelName).subscriptionPending).toEqual(true);
|
|
721
|
-
expect(pusher.channel(channelName).subscriptionCancelled).toEqual(false);
|
|
722
|
-
});
|
|
700
|
+
await waitsFor(sleep(3000), "unsubscription to finish", 3500)
|
|
701
|
+
expect(pusher.channel(channelName)).toBe(undefined);
|
|
723
702
|
|
|
724
|
-
|
|
703
|
+
pusher.subscribe(channelName)
|
|
704
|
+
expect(pusher.channel(channelName).subscribed).toEqual(false);
|
|
705
|
+
expect(pusher.channel(channelName).subscriptionPending).toEqual(true);
|
|
706
|
+
expect(pusher.channel(channelName).subscriptionCancelled).toEqual(false);
|
|
707
|
+
|
|
708
|
+
await waitsFor(function() {
|
|
725
709
|
return pusher.channel(channelName).subscribed;
|
|
726
710
|
}, "subscription to finish", 10000);
|
|
727
711
|
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
expect(pusher.channel(channelName).subscriptionCancelled).toEqual(false);
|
|
732
|
-
});
|
|
712
|
+
expect(pusher.channel(channelName).subscribed).toEqual(true);
|
|
713
|
+
expect(pusher.channel(channelName).subscriptionPending).toEqual(false);
|
|
714
|
+
expect(pusher.channel(channelName).subscriptionCancelled).toEqual(false);
|
|
733
715
|
});
|
|
734
716
|
|
|
735
|
-
it("sub-unsub-unsub = NOP", function() {
|
|
717
|
+
it("sub-unsub-unsub = NOP", async function() {
|
|
736
718
|
var pusher = getPusher();
|
|
737
719
|
var channelName = Integration.getRandomName((prefix || "") + "integration");
|
|
738
720
|
|
|
@@ -753,11 +735,9 @@ function buildSubscriptionStateTests(getPusher, prefix) {
|
|
|
753
735
|
|
|
754
736
|
// there is no easy way to know when an unsubscribe request has been
|
|
755
737
|
// actioned by the server, so we just wait a while
|
|
756
|
-
waitsFor(sleep(3000), "unsubscription to finish", 3500)
|
|
738
|
+
await waitsFor(sleep(3000), "unsubscription to finish", 3500)
|
|
757
739
|
|
|
758
|
-
|
|
759
|
-
expect(pusher.channel(channelName)).toBe(undefined);
|
|
760
|
-
});
|
|
740
|
+
expect(pusher.channel(channelName)).toBe(undefined);
|
|
761
741
|
});
|
|
762
742
|
}
|
|
763
743
|
module.exports = {build}
|