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,42 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const TestEnv = require('testenv');
|
|
2
|
+
const Pusher = require('pusher_integration');
|
|
3
3
|
|
|
4
4
|
if (TestEnv === "web") window.Pusher = Pusher;
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
var Timer = require('core/utils/timers').OneOffTimer;
|
|
6
|
+
const Integration = require('integration');
|
|
7
|
+
const Mocks = require("mocks");
|
|
8
|
+
const Network = require('net_info').Network;
|
|
9
|
+
const OneOffTimer = require('core/utils/timers').OneOffTimer;
|
|
10
|
+
const Runtime = require('runtime').default;
|
|
11
|
+
const transports = Runtime.Transports;
|
|
12
|
+
const waitsFor = require('../../helpers/waitsFor')
|
|
14
13
|
|
|
15
14
|
module.exports = function() {
|
|
16
15
|
Integration.describe("Falling back", function() {
|
|
17
16
|
var pusher;
|
|
18
17
|
|
|
19
18
|
beforeEach(function() {
|
|
20
|
-
spyOn(Network, "isOnline").
|
|
19
|
+
spyOn(Network, "isOnline").and.returnValue(true);
|
|
21
20
|
|
|
22
|
-
spyOn(transports.ws, "isSupported").
|
|
23
|
-
spyOn(transports.xhr_streaming, "isSupported").
|
|
24
|
-
spyOn(transports.xhr_polling, "isSupported").
|
|
21
|
+
spyOn(transports.ws, "isSupported").and.returnValue(false);
|
|
22
|
+
spyOn(transports.xhr_streaming, "isSupported").and.returnValue(false);
|
|
23
|
+
spyOn(transports.xhr_polling, "isSupported").and.returnValue(false);
|
|
25
24
|
|
|
26
25
|
if (TestEnv === "web") {
|
|
27
|
-
spyOn(transports.sockjs, "isSupported").
|
|
28
|
-
spyOn(transports.xdr_streaming, "isSupported").
|
|
29
|
-
spyOn(transports.xdr_polling, "isSupported").
|
|
26
|
+
spyOn(transports.sockjs, "isSupported").and.returnValue(false);
|
|
27
|
+
spyOn(transports.xdr_streaming, "isSupported").and.returnValue(false);
|
|
28
|
+
spyOn(transports.xdr_polling, "isSupported").and.returnValue(false);
|
|
30
29
|
}
|
|
31
30
|
|
|
32
|
-
spyOn(Runtime, "getLocalStorage").
|
|
31
|
+
spyOn(Runtime, "getLocalStorage").and.returnValue({});
|
|
33
32
|
});
|
|
34
33
|
|
|
35
34
|
afterEach(function() {
|
|
36
35
|
pusher.disconnect();
|
|
37
36
|
});
|
|
38
37
|
|
|
39
|
-
it("should disable WebSockets after two broken connections", function() {
|
|
38
|
+
it("should disable WebSockets after two broken connections", async function() {
|
|
40
39
|
var transport;
|
|
41
40
|
|
|
42
41
|
function createConnection() {
|
|
@@ -44,75 +43,75 @@ module.exports = function() {
|
|
|
44
43
|
return transport;
|
|
45
44
|
}
|
|
46
45
|
|
|
47
|
-
transports.ws.isSupported.
|
|
48
|
-
spyOn(transports.ws, "createConnection").
|
|
46
|
+
transports.ws.isSupported.and.returnValue(true);
|
|
47
|
+
spyOn(transports.ws, "createConnection").and.callFake(createConnection);
|
|
49
48
|
|
|
50
49
|
var timer;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
waitsFor(function() {
|
|
56
|
-
return transports.ws.createConnection.calls.
|
|
50
|
+
|
|
51
|
+
pusher = new Pusher("foobar");
|
|
52
|
+
pusher.connect();
|
|
53
|
+
|
|
54
|
+
await waitsFor(function() {
|
|
55
|
+
return transports.ws.createConnection.calls.count() === 1;
|
|
57
56
|
}, "WS connection to be created", 500);
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
waitsFor(function() {
|
|
63
|
-
return transport.connect.calls.
|
|
57
|
+
|
|
58
|
+
transport.state = "initialized";
|
|
59
|
+
transport.emit("initialized");
|
|
60
|
+
|
|
61
|
+
await waitsFor(function() {
|
|
62
|
+
return transport.connect.calls.count() === 1;
|
|
64
63
|
}, "connect to be called", 500);
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
});
|
|
64
|
+
|
|
65
|
+
transport.state = "open";
|
|
66
|
+
transport.emit("open");
|
|
67
|
+
|
|
68
|
+
var timer = new OneOffTimer(100, function() {
|
|
69
|
+
transport.emit("closed", {
|
|
70
|
+
code: 1006,
|
|
71
|
+
reason: "KABOOM!",
|
|
72
|
+
wasClean: false
|
|
75
73
|
});
|
|
76
74
|
});
|
|
77
|
-
|
|
78
|
-
|
|
75
|
+
|
|
76
|
+
await waitsFor(function() {
|
|
77
|
+
return transports.ws.createConnection.calls.count() === 2;
|
|
79
78
|
}, "WS connection to be created", 1500);
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
waitsFor(function() {
|
|
85
|
-
return transport.connect.calls.
|
|
79
|
+
|
|
80
|
+
transport.state = "initialized";
|
|
81
|
+
transport.emit("initialized");
|
|
82
|
+
|
|
83
|
+
await waitsFor(function() {
|
|
84
|
+
return transport.connect.calls.count() === 1;
|
|
86
85
|
}, "connect to be called", 500);
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
});
|
|
86
|
+
|
|
87
|
+
transport.state = "open";
|
|
88
|
+
transport.emit("open");
|
|
89
|
+
|
|
90
|
+
timer = new OneOffTimer(100, function() {
|
|
91
|
+
transport.emit("closed", {
|
|
92
|
+
code: 1006,
|
|
93
|
+
reason: "KABOOM! AGAIN!",
|
|
94
|
+
wasClean: false
|
|
97
95
|
});
|
|
98
96
|
});
|
|
99
|
-
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
await waitsFor(function() {
|
|
100
100
|
return !timer.isRunning();
|
|
101
101
|
}, "the transport to close", 200);
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
waitsFor(function() {
|
|
102
|
+
|
|
103
|
+
timer = new OneOffTimer(500, function() {});
|
|
104
|
+
|
|
105
|
+
await waitsFor(function() {
|
|
106
106
|
return !timer.isRunning();
|
|
107
107
|
}, "a while", 600);
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
});
|
|
108
|
+
|
|
109
|
+
expect(transports.ws.createConnection.calls.count()).toEqual(2);
|
|
110
|
+
pusher.disconnect();
|
|
112
111
|
});
|
|
113
112
|
|
|
114
113
|
if (TestEnv === "web") {
|
|
115
|
-
it("should not close established SockJS connection when WebSocket is stuck in handshake", function() {
|
|
114
|
+
it("should not close established SockJS connection when WebSocket is stuck in handshake", async function() {
|
|
116
115
|
var wsTransport, sockjsTransport;
|
|
117
116
|
|
|
118
117
|
function createWSConnection() {
|
|
@@ -124,74 +123,72 @@ module.exports = function() {
|
|
|
124
123
|
return sockjsTransport;
|
|
125
124
|
}
|
|
126
125
|
|
|
127
|
-
transports.ws.isSupported.
|
|
128
|
-
transports.sockjs.isSupported.
|
|
129
|
-
spyOn(transports.ws, "createConnection").
|
|
130
|
-
spyOn(transports.sockjs, "createConnection").
|
|
126
|
+
transports.ws.isSupported.and.returnValue(true);
|
|
127
|
+
transports.sockjs.isSupported.and.returnValue(true);
|
|
128
|
+
spyOn(transports.ws, "createConnection").and.callFake(createWSConnection);
|
|
129
|
+
spyOn(transports.sockjs, "createConnection").and.callFake(createSockJSConnection);
|
|
131
130
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
waitsFor(function() {
|
|
138
|
-
return transports.ws.createConnection.calls.
|
|
131
|
+
|
|
132
|
+
// use TLS connection, to force sockjs to be the primary fallback
|
|
133
|
+
pusher = new Pusher("foobar", { forceTLS: true });
|
|
134
|
+
pusher.connect();
|
|
135
|
+
|
|
136
|
+
await waitsFor(function() {
|
|
137
|
+
return transports.ws.createConnection.calls.count() === 1;
|
|
139
138
|
}, "WS connection to be created", 500);
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
waitsFor(function() {
|
|
145
|
-
return wsTransport.connect.calls.
|
|
139
|
+
|
|
140
|
+
wsTransport.state = "initialized";
|
|
141
|
+
wsTransport.emit("initialized");
|
|
142
|
+
|
|
143
|
+
await waitsFor(function() {
|
|
144
|
+
return wsTransport.connect.calls.count() === 1;
|
|
146
145
|
}, "connect on WS to be called", 500);
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
waitsFor(function() {
|
|
153
|
-
return transports.sockjs.createConnection.calls.
|
|
146
|
+
|
|
147
|
+
wsTransport.state = "open";
|
|
148
|
+
wsTransport.emit("open");
|
|
149
|
+
// start handshake, but don't do anything
|
|
150
|
+
|
|
151
|
+
await waitsFor(function() {
|
|
152
|
+
return transports.sockjs.createConnection.calls.count() === 1;
|
|
154
153
|
}, "SockJS connection to be created", 3000);
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
waitsFor(function() {
|
|
160
|
-
return sockjsTransport.connect.calls.
|
|
154
|
+
|
|
155
|
+
sockjsTransport.state = "initialized";
|
|
156
|
+
sockjsTransport.emit("initialized");
|
|
157
|
+
|
|
158
|
+
await waitsFor(function() {
|
|
159
|
+
return sockjsTransport.connect.calls.count() === 1;
|
|
161
160
|
}, "connect on SockJS to be called", 500);
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
});
|
|
161
|
+
|
|
162
|
+
sockjsTransport.state = "open";
|
|
163
|
+
sockjsTransport.emit("open");
|
|
164
|
+
sockjsTransport.emit("message", {
|
|
165
|
+
data: JSON.stringify({
|
|
166
|
+
event: "pusher:connection_established",
|
|
167
|
+
data: {
|
|
168
|
+
socket_id: "123.456",
|
|
169
|
+
activity_timeout: 120
|
|
170
|
+
}
|
|
171
|
+
})
|
|
174
172
|
});
|
|
175
|
-
|
|
176
|
-
|
|
173
|
+
|
|
174
|
+
await waitsFor(function() {
|
|
175
|
+
return wsTransport.close.calls.count() === 1;
|
|
177
176
|
}, "close on WS to be called", 500);
|
|
178
177
|
|
|
179
178
|
var timer;
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
reason: "clean"
|
|
186
|
-
});
|
|
187
|
-
timer = new Timer(2000, function() {});
|
|
179
|
+
// this caused a connection to be retried after 1s
|
|
180
|
+
wsTransport.emit("closed", {
|
|
181
|
+
code: 1000,
|
|
182
|
+
wasClean: true,
|
|
183
|
+
reason: "clean"
|
|
188
184
|
});
|
|
189
|
-
|
|
185
|
+
timer = new OneOffTimer(2000, function() {});
|
|
186
|
+
|
|
187
|
+
await waitsFor(function() {
|
|
190
188
|
return !timer.isRunning();
|
|
191
189
|
}, "timer to be called", 2500);
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
});
|
|
190
|
+
|
|
191
|
+
expect(sockjsTransport.close).not.toHaveBeenCalled();
|
|
195
192
|
});
|
|
196
193
|
}
|
|
197
194
|
});
|