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
|
@@ -13,11 +13,11 @@ describe("HTTP.getXDR", function() {
|
|
|
13
13
|
HTTPFactory = require('runtime').default.HTTPFactory;
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
window.XDomainRequest = jasmine.createSpy().
|
|
16
|
+
window.XDomainRequest = jasmine.createSpy().and.callFake(
|
|
17
17
|
Mocks.getXHR
|
|
18
18
|
);;
|
|
19
19
|
|
|
20
|
-
spyOn(HTTPFactory, "createRequest").
|
|
20
|
+
spyOn(HTTPFactory, "createRequest").and.callFake(function(h, m, u) {
|
|
21
21
|
hooks = h;
|
|
22
22
|
method = m;
|
|
23
23
|
url = u;
|
|
@@ -52,15 +52,15 @@ describe("HTTP.getXDR", function() {
|
|
|
52
52
|
describe("on XDR timeout", function() {
|
|
53
53
|
it("should close the socket", function() {
|
|
54
54
|
xdr.ontimeout();
|
|
55
|
-
expect(socket.close.calls.
|
|
55
|
+
expect(socket.close.calls.count()).toEqual(1);
|
|
56
56
|
});
|
|
57
57
|
|
|
58
58
|
it("should emit an RequestTimedOut error before closing the socket", function() {
|
|
59
59
|
var onError = jasmine.createSpy();
|
|
60
60
|
socket.bind("error", onError);
|
|
61
61
|
|
|
62
|
-
socket.close.
|
|
63
|
-
expect(onError.calls.
|
|
62
|
+
socket.close.and.callFake(function() {
|
|
63
|
+
expect(onError.calls.count()).toEqual(1);
|
|
64
64
|
expect(onError).toHaveBeenCalledWith(
|
|
65
65
|
jasmine.any(Errors.RequestTimedOut)
|
|
66
66
|
);
|
|
@@ -73,15 +73,15 @@ describe("HTTP.getXDR", function() {
|
|
|
73
73
|
describe("on XDR error", function() {
|
|
74
74
|
it("should close the socket", function() {
|
|
75
75
|
xdr.onerror("test error");
|
|
76
|
-
expect(socket.close.calls.
|
|
76
|
+
expect(socket.close.calls.count()).toEqual(1);
|
|
77
77
|
});
|
|
78
78
|
|
|
79
79
|
it("should emit the error before closing the socket", function() {
|
|
80
80
|
var onError = jasmine.createSpy();
|
|
81
81
|
socket.bind("error", onError);
|
|
82
82
|
|
|
83
|
-
socket.close.
|
|
84
|
-
expect(onError.calls.
|
|
83
|
+
socket.close.and.callFake(function() {
|
|
84
|
+
expect(onError.calls.count()).toEqual(1);
|
|
85
85
|
expect(onError).toHaveBeenCalledWith("test error");
|
|
86
86
|
});
|
|
87
87
|
|
|
@@ -108,7 +108,7 @@ describe("HTTP.getXDR", function() {
|
|
|
108
108
|
xdr.responseText = "asdf";
|
|
109
109
|
|
|
110
110
|
xdr.onprogress();
|
|
111
|
-
expect(socket.onChunk.calls.
|
|
111
|
+
expect(socket.onChunk.calls.count()).toEqual(1);
|
|
112
112
|
expect(socket.onChunk).toHaveBeenCalledWith(200, "asdf");
|
|
113
113
|
});
|
|
114
114
|
|
|
@@ -116,12 +116,12 @@ describe("HTTP.getXDR", function() {
|
|
|
116
116
|
xdr.responseText = "asdf";
|
|
117
117
|
|
|
118
118
|
xdr.onprogress();
|
|
119
|
-
expect(socket.onChunk.calls.
|
|
119
|
+
expect(socket.onChunk.calls.count()).toEqual(1);
|
|
120
120
|
expect(socket.onChunk).toHaveBeenCalledWith(200, "asdf");
|
|
121
121
|
|
|
122
122
|
xdr.responseText = "asdfghjkl";
|
|
123
123
|
xdr.onprogress();
|
|
124
|
-
expect(socket.onChunk.calls.
|
|
124
|
+
expect(socket.onChunk.calls.count()).toEqual(2);
|
|
125
125
|
expect(socket.onChunk).toHaveBeenCalledWith(200, "asdfghjkl");
|
|
126
126
|
});
|
|
127
127
|
});
|
|
@@ -131,7 +131,7 @@ describe("HTTP.getXDR", function() {
|
|
|
131
131
|
xdr.responseText = "";
|
|
132
132
|
|
|
133
133
|
xdr.onload();
|
|
134
|
-
expect(socket.close.calls.
|
|
134
|
+
expect(socket.close.calls.count()).toEqual(1);
|
|
135
135
|
});
|
|
136
136
|
|
|
137
137
|
it("should not call socket.onChunk if there is no responseText", function() {
|
|
@@ -151,8 +151,8 @@ describe("HTTP.getXDR", function() {
|
|
|
151
151
|
it("should call socket.onChunk before closing if responseText is not empty", function() {
|
|
152
152
|
xdr.responseText = "12356890";
|
|
153
153
|
|
|
154
|
-
socket.close.
|
|
155
|
-
expect(socket.onChunk.calls.
|
|
154
|
+
socket.close.and.callFake(function() {
|
|
155
|
+
expect(socket.onChunk.calls.count()).toEqual(1);
|
|
156
156
|
expect(socket.onChunk).toHaveBeenCalledWith(200, "12356890");
|
|
157
157
|
});
|
|
158
158
|
|
|
@@ -165,8 +165,8 @@ describe("HTTP.getXDR", function() {
|
|
|
165
165
|
var onFinished = jasmine.createSpy();
|
|
166
166
|
socket.bind("finished", onFinished);
|
|
167
167
|
|
|
168
|
-
socket.close.
|
|
169
|
-
expect(onFinished.calls.
|
|
168
|
+
socket.close.and.callFake(function() {
|
|
169
|
+
expect(onFinished.calls.count()).toEqual(1);
|
|
170
170
|
expect(onFinished).toHaveBeenCalledWith(200);
|
|
171
171
|
});
|
|
172
172
|
|
|
@@ -177,14 +177,14 @@ describe("HTTP.getXDR", function() {
|
|
|
177
177
|
|
|
178
178
|
describe("#abortRequest", function() {
|
|
179
179
|
it("should abort the passed request", function() {
|
|
180
|
-
expect(xdr.abort.calls.
|
|
180
|
+
expect(xdr.abort.calls.count()).toEqual(0);
|
|
181
181
|
hooks.abortRequest(xdr);
|
|
182
|
-
expect(xdr.abort.calls.
|
|
182
|
+
expect(xdr.abort.calls.count()).toEqual(1);
|
|
183
183
|
});
|
|
184
184
|
|
|
185
185
|
it("should set the ontimeout listener to null before calling abort", function() {
|
|
186
186
|
xdr.ontimeout = function() {};
|
|
187
|
-
xdr.abort.
|
|
187
|
+
xdr.abort.and.callFake(function() {
|
|
188
188
|
expect(xdr.ontimeout).toBe(null);
|
|
189
189
|
});
|
|
190
190
|
|
|
@@ -193,7 +193,7 @@ describe("HTTP.getXDR", function() {
|
|
|
193
193
|
|
|
194
194
|
it("should set the onerror listener to null before calling abort", function() {
|
|
195
195
|
xdr.onerror = function() {};
|
|
196
|
-
xdr.abort.
|
|
196
|
+
xdr.abort.and.callFake(function() {
|
|
197
197
|
expect(xdr.onerror).toBe(null);
|
|
198
198
|
});
|
|
199
199
|
|
|
@@ -202,7 +202,7 @@ describe("HTTP.getXDR", function() {
|
|
|
202
202
|
|
|
203
203
|
it("should set the onprogress listener to null before calling abort", function() {
|
|
204
204
|
xdr.onprogress = function() {};
|
|
205
|
-
xdr.abort.
|
|
205
|
+
xdr.abort.and.callFake(function() {
|
|
206
206
|
expect(xdr.onprogress).toBe(null);
|
|
207
207
|
});
|
|
208
208
|
|
|
@@ -211,7 +211,7 @@ describe("HTTP.getXDR", function() {
|
|
|
211
211
|
|
|
212
212
|
it("should set the onload listener to null before calling abort", function() {
|
|
213
213
|
xdr.onload = function() {};
|
|
214
|
-
xdr.abort.
|
|
214
|
+
xdr.abort.and.callFake(function() {
|
|
215
215
|
expect(xdr.onload).toBe(null);
|
|
216
216
|
});
|
|
217
217
|
|
|
@@ -22,10 +22,10 @@ describe("JSONP Authorizer", function() {
|
|
|
22
22
|
var script = Mocks.getDocumentElement();
|
|
23
23
|
var documentElement = Mocks.getDocumentElement();
|
|
24
24
|
|
|
25
|
-
document.createElement.
|
|
26
|
-
document.getElementsByTagName.
|
|
25
|
+
document.createElement.and.returnValue(script);
|
|
26
|
+
document.getElementsByTagName.and.returnValue([]);
|
|
27
27
|
document.documentElement = documentElement;
|
|
28
|
-
spyOn(Runtime, "getDocument").
|
|
28
|
+
spyOn(Runtime, "getDocument").and.returnValue(document);
|
|
29
29
|
|
|
30
30
|
spyOn(Logger, "warn");
|
|
31
31
|
authorizer.authorize("1.23", function() {});
|
|
@@ -9,13 +9,13 @@ describe("TimelineSender", function() {
|
|
|
9
9
|
|
|
10
10
|
beforeEach(function() {
|
|
11
11
|
timeline = Mocks.getTimeline();
|
|
12
|
-
timeline.isEmpty.
|
|
13
|
-
timeline.send.
|
|
12
|
+
timeline.isEmpty.and.returnValue(false);
|
|
13
|
+
timeline.send.and.callFake(function(sendJSONP, callback) {
|
|
14
14
|
sendJSONP({ events: [1, 2, 3]}, callback);
|
|
15
15
|
});
|
|
16
16
|
|
|
17
17
|
onSend = jasmine.createSpy("onSend");
|
|
18
|
-
spyOn(Runtime, "createJSONPRequest").
|
|
18
|
+
spyOn(Runtime, "createJSONPRequest").and.callFake(function() {
|
|
19
19
|
// JSONPRequest and ScriptRequest have compatible interfaces
|
|
20
20
|
jsonpRequest = Mocks.getScriptRequest();
|
|
21
21
|
return jsonpRequest;
|
|
@@ -44,7 +44,7 @@ describe("TimelineSender", function() {
|
|
|
44
44
|
it("should send a non-empty timeline", function() {
|
|
45
45
|
sender.send(false, onSend);
|
|
46
46
|
|
|
47
|
-
expect(Runtime.createJSONPRequest.calls.
|
|
47
|
+
expect(Runtime.createJSONPRequest.calls.count()).toEqual(1);
|
|
48
48
|
expect(Runtime.createJSONPRequest).toHaveBeenCalledWith(
|
|
49
49
|
"http://example.com/timeline",
|
|
50
50
|
{ "events": [1, 2, 3] }
|
|
@@ -60,7 +60,7 @@ describe("TimelineSender", function() {
|
|
|
60
60
|
});
|
|
61
61
|
sender.send(true, onSend);
|
|
62
62
|
|
|
63
|
-
expect(Runtime.createJSONPRequest.calls.
|
|
63
|
+
expect(Runtime.createJSONPRequest.calls.count()).toEqual(1);
|
|
64
64
|
expect(Runtime.createJSONPRequest).toHaveBeenCalledWith(
|
|
65
65
|
"https://example.com/timeline",
|
|
66
66
|
{ "events": [1, 2, 3] }
|
|
@@ -70,7 +70,7 @@ describe("TimelineSender", function() {
|
|
|
70
70
|
it("should register a receiver using ScriptReceivers", function() {
|
|
71
71
|
sender.send(false, onSend);
|
|
72
72
|
|
|
73
|
-
var jsonpReceiver = jsonpRequest.send.calls
|
|
73
|
+
var jsonpReceiver = jsonpRequest.send.calls.first().args[0];
|
|
74
74
|
expect(ScriptReceivers[jsonpReceiver.number]).toBe(jsonpReceiver.callback);
|
|
75
75
|
});
|
|
76
76
|
|
|
@@ -78,7 +78,7 @@ describe("TimelineSender", function() {
|
|
|
78
78
|
sender.send(false, onSend);
|
|
79
79
|
|
|
80
80
|
expect(onSend).not.toHaveBeenCalled();
|
|
81
|
-
var jsonpReceiver = jsonpRequest.send.calls
|
|
81
|
+
var jsonpReceiver = jsonpRequest.send.calls.first().args[0];
|
|
82
82
|
jsonpReceiver.callback(null, { result: "ok" });
|
|
83
83
|
expect(onSend).toHaveBeenCalledWith(null, { result: "ok" });
|
|
84
84
|
});
|
|
@@ -87,7 +87,7 @@ describe("TimelineSender", function() {
|
|
|
87
87
|
sender.send(false, onSend);
|
|
88
88
|
|
|
89
89
|
expect(onSend).not.toHaveBeenCalled();
|
|
90
|
-
var jsonpReceiver = jsonpRequest.send.calls
|
|
90
|
+
var jsonpReceiver = jsonpRequest.send.calls.first().args[0];
|
|
91
91
|
jsonpReceiver.callback("ERROR!", undefined);
|
|
92
92
|
expect(onSend).toHaveBeenCalledWith("ERROR!", undefined);
|
|
93
93
|
});
|
|
@@ -95,7 +95,7 @@ describe("TimelineSender", function() {
|
|
|
95
95
|
it("should remove the receiver from ScriptReceivers", function() {
|
|
96
96
|
sender.send(false, onSend);
|
|
97
97
|
|
|
98
|
-
var jsonpReceiver = jsonpRequest.send.calls
|
|
98
|
+
var jsonpReceiver = jsonpRequest.send.calls.first().args[0];
|
|
99
99
|
jsonpReceiver.callback(null, {});
|
|
100
100
|
expect(ScriptReceivers[jsonpReceiver.number]).toBe(undefined);
|
|
101
101
|
});
|
|
@@ -104,13 +104,13 @@ describe("TimelineSender", function() {
|
|
|
104
104
|
sender.send(false, onSend);
|
|
105
105
|
|
|
106
106
|
expect(jsonpRequest.cleanup).not.toHaveBeenCalled();
|
|
107
|
-
var jsonpReceiver = jsonpRequest.send.calls
|
|
107
|
+
var jsonpReceiver = jsonpRequest.send.calls.first().args[0];
|
|
108
108
|
jsonpReceiver.callback(null, {});
|
|
109
109
|
expect(jsonpRequest.cleanup).toHaveBeenCalled();
|
|
110
110
|
});
|
|
111
111
|
|
|
112
112
|
it("should not send an empty timeline", function() {
|
|
113
|
-
timeline.isEmpty.
|
|
113
|
+
timeline.isEmpty.and.returnValue(true);
|
|
114
114
|
sender.send(false, onSend);
|
|
115
115
|
expect(Runtime.createJSONPRequest).not.toHaveBeenCalled();
|
|
116
116
|
});
|
|
@@ -118,7 +118,7 @@ describe("TimelineSender", function() {
|
|
|
118
118
|
it("should use returned hostname for subsequent requests", function() {
|
|
119
119
|
sender.send(false);
|
|
120
120
|
|
|
121
|
-
var jsonpReceiver = jsonpRequest.send.calls
|
|
121
|
+
var jsonpReceiver = jsonpRequest.send.calls.first().args[0];
|
|
122
122
|
jsonpReceiver.callback(null, { host: "returned.example.com" });
|
|
123
123
|
|
|
124
124
|
sender.send(false);
|
|
@@ -16,13 +16,16 @@ describe("Host/Port Configuration", function() {
|
|
|
16
16
|
var Transports;
|
|
17
17
|
|
|
18
18
|
beforeEach(function() {
|
|
19
|
-
|
|
19
|
+
jasmine.clock().uninstall();
|
|
20
|
+
jasmine.clock().install();
|
|
21
|
+
|
|
22
|
+
spyOn(Runtime, 'getNetwork').and.callFake(function(){
|
|
20
23
|
var network = new NetInfo();
|
|
21
24
|
network.isOnline = jasmine.createSpy("isOnline")
|
|
22
|
-
.
|
|
25
|
+
.and.returnValue(true);
|
|
23
26
|
return network;
|
|
24
27
|
});
|
|
25
|
-
spyOn(Runtime, "getLocalStorage").
|
|
28
|
+
spyOn(Runtime, "getLocalStorage").and.returnValue({});
|
|
26
29
|
Transports = Runtime.Transports;
|
|
27
30
|
});
|
|
28
31
|
|
|
@@ -34,19 +37,19 @@ describe("Host/Port Configuration", function() {
|
|
|
34
37
|
var _SockJS;
|
|
35
38
|
|
|
36
39
|
beforeEach(function() {
|
|
37
|
-
spyOn(Transports.ws, "isSupported").
|
|
38
|
-
spyOn(Transports.xdr_streaming, "isSupported").
|
|
39
|
-
spyOn(Transports.xhr_streaming, "isSupported").
|
|
40
|
-
spyOn(Transports.xdr_polling, "isSupported").
|
|
41
|
-
spyOn(Transports.xhr_polling, "isSupported").
|
|
42
|
-
spyOn(Transports.sockjs, "isSupported").
|
|
43
|
-
|
|
44
|
-
spyOn(Dependencies, "load").
|
|
40
|
+
spyOn(Transports.ws, "isSupported").and.returnValue(false);
|
|
41
|
+
spyOn(Transports.xdr_streaming, "isSupported").and.returnValue(false);
|
|
42
|
+
spyOn(Transports.xhr_streaming, "isSupported").and.returnValue(false);
|
|
43
|
+
spyOn(Transports.xdr_polling, "isSupported").and.returnValue(false);
|
|
44
|
+
spyOn(Transports.xhr_polling, "isSupported").and.returnValue(false);
|
|
45
|
+
spyOn(Transports.sockjs, "isSupported").and.returnValue(true);
|
|
46
|
+
|
|
47
|
+
spyOn(Dependencies, "load").and.callFake(function(file, callback) {
|
|
45
48
|
callback();
|
|
46
49
|
});
|
|
47
50
|
|
|
48
51
|
_SockJS = window.WebSocket;
|
|
49
|
-
window.SockJS = jasmine.createSpy("WebSocket").
|
|
52
|
+
window.SockJS = jasmine.createSpy("WebSocket").and.callFake(function() {
|
|
50
53
|
return Mocks.getTransport();
|
|
51
54
|
});
|
|
52
55
|
});
|
|
@@ -55,7 +55,7 @@ describe("Transports", function() {
|
|
|
55
55
|
"ws://example.com:123/path/app/foobar?protocol=7&client=js&version=" + VERSION + "&flash=false"
|
|
56
56
|
);
|
|
57
57
|
});
|
|
58
|
-
|
|
58
|
+
|
|
59
59
|
it("should generate correct TLS URLs with custom path prefix", function() {
|
|
60
60
|
var url = Transports.ws.hooks.urls.getInitial("foobar", {
|
|
61
61
|
useTLS: true,
|
|
@@ -114,15 +114,14 @@ describe("Transports", function() {
|
|
|
114
114
|
describe("getSocket hook", function() {
|
|
115
115
|
it("should return a new WebSocket object, if the class is present", function() {
|
|
116
116
|
if(!isSafari()) {
|
|
117
|
-
window.WebSocket = jasmine.createSpy().
|
|
117
|
+
window.WebSocket = jasmine.createSpy().and.callFake(function(url) {
|
|
118
118
|
this.url = url;
|
|
119
119
|
});
|
|
120
120
|
window.MozWebSocket = undefined;
|
|
121
121
|
|
|
122
122
|
var socket = Transports.ws.hooks.getSocket("testurl");
|
|
123
|
-
expect(window.WebSocket.calls.
|
|
123
|
+
expect(window.WebSocket.calls.count()).toEqual(1);
|
|
124
124
|
expect(window.WebSocket).toHaveBeenCalledWith("testurl");
|
|
125
|
-
expect(socket).toEqual(jasmine.any(window.WebSocket));
|
|
126
125
|
expect(socket.url).toEqual("testurl");
|
|
127
126
|
}
|
|
128
127
|
});
|
|
@@ -131,15 +130,14 @@ describe("Transports", function() {
|
|
|
131
130
|
if(!isSafari()) {
|
|
132
131
|
window.WebSocket = undefined;
|
|
133
132
|
|
|
134
|
-
window.MozWebSocket = jasmine.createSpy().
|
|
133
|
+
window.MozWebSocket = jasmine.createSpy().and.callFake(function(url) {
|
|
135
134
|
this.url = url;
|
|
136
135
|
});
|
|
137
136
|
|
|
138
137
|
var socket = Transports.ws.hooks.getSocket("moztesturl");
|
|
139
138
|
|
|
140
|
-
expect(window.MozWebSocket.calls.
|
|
139
|
+
expect(window.MozWebSocket.calls.count()).toEqual(1);
|
|
141
140
|
expect(window.MozWebSocket).toHaveBeenCalledWith("moztesturl");
|
|
142
|
-
expect(socket).toEqual(jasmine.any(window.MozWebSocket));
|
|
143
141
|
expect(socket.url).toEqual("moztesturl");
|
|
144
142
|
}
|
|
145
143
|
});
|
|
@@ -192,8 +190,8 @@ describe("Transports", function() {
|
|
|
192
190
|
var socket = Mocks.getWebSocket();
|
|
193
191
|
Transports.sockjs.hooks.beforeOpen(socket, "test/path");
|
|
194
192
|
|
|
195
|
-
expect(socket.send.calls.
|
|
196
|
-
var pathMessage = JSON.parse(socket.send.calls
|
|
193
|
+
expect(socket.send.calls.count()).toEqual(1);
|
|
194
|
+
var pathMessage = JSON.parse(socket.send.calls.first().args[0]);
|
|
197
195
|
expect(pathMessage).toEqual({ path: "test/path" });
|
|
198
196
|
});
|
|
199
197
|
});
|
|
@@ -209,7 +207,7 @@ describe("Transports", function() {
|
|
|
209
207
|
Dependencies.load = jasmine.createSpy("load");
|
|
210
208
|
Dependencies.getRoot = jasmine.createSpy("getRoot");
|
|
211
209
|
Dependencies.getPath = jasmine.createSpy("getPath");
|
|
212
|
-
Dependencies.getPath.
|
|
210
|
+
Dependencies.getPath.and.callFake(function(file, options) {
|
|
213
211
|
return (options.useTLS ? "https" : "http") + "://host/" + file;
|
|
214
212
|
});
|
|
215
213
|
});
|
|
@@ -233,21 +231,21 @@ describe("Transports", function() {
|
|
|
233
231
|
var socket = Transports.sockjs.hooks.getSocket(
|
|
234
232
|
"url", { useTLS: true }
|
|
235
233
|
);
|
|
236
|
-
expect(window.SockJS).toHaveBeenCalledWith(
|
|
237
|
-
|
|
238
|
-
|
|
234
|
+
expect(window.SockJS).toHaveBeenCalledWith('url', null, {
|
|
235
|
+
js_path: 'https://host/sockjs',
|
|
236
|
+
ignore_null_origin: undefined
|
|
237
|
+
});
|
|
239
238
|
});
|
|
240
239
|
|
|
241
240
|
it("should return a new SockJS object", function() {
|
|
242
|
-
window.SockJS = jasmine.createSpy().
|
|
241
|
+
window.SockJS = jasmine.createSpy().and.callFake(function(url) {
|
|
243
242
|
this.url = url;
|
|
244
243
|
});
|
|
245
244
|
|
|
246
245
|
var socket = Transports.sockjs.hooks.getSocket(
|
|
247
246
|
"sock_test", { useTLS: false }
|
|
248
247
|
);
|
|
249
|
-
expect(window.SockJS.calls.
|
|
250
|
-
expect(socket).toEqual(jasmine.any(window.SockJS));
|
|
248
|
+
expect(window.SockJS.calls.count()).toEqual(1);
|
|
251
249
|
expect(socket.url).toEqual("sock_test");
|
|
252
250
|
});
|
|
253
251
|
});
|
|
@@ -331,14 +329,14 @@ describe("Transports", function() {
|
|
|
331
329
|
|
|
332
330
|
describe("isSupported hook", function() {
|
|
333
331
|
it("should return true if window.XMLHttpRequest exists and its instances have a withCredentials property", function() {
|
|
334
|
-
window.XMLHttpRequest = jasmine.createSpy().
|
|
332
|
+
window.XMLHttpRequest = jasmine.createSpy().and.callFake(function() {
|
|
335
333
|
this.withCredentials = false;
|
|
336
334
|
});
|
|
337
335
|
expect(Transports[transport].hooks.isSupported({})).toBe(true);
|
|
338
336
|
});
|
|
339
337
|
|
|
340
338
|
it("should return false if window.XMLHttpRequest exists, but its instances don't have a withCredentials property", function() {
|
|
341
|
-
window.XMLHttpRequest = jasmine.createSpy().
|
|
339
|
+
window.XMLHttpRequest = jasmine.createSpy().and.callFake(function() {
|
|
342
340
|
this.withCredentials = undefined;
|
|
343
341
|
});
|
|
344
342
|
expect(Transports[transport].hooks.isSupported({})).toBe(false);
|
|
@@ -363,7 +361,7 @@ describe("Transports", function() {
|
|
|
363
361
|
describe("isSupported hook", function() {
|
|
364
362
|
it("should return true if window.XDomainRequest exists, document protocol is http: and connection is not using TLS", function() {
|
|
365
363
|
window.XDomainRequest = function() {};
|
|
366
|
-
spyOn(Runtime, "getDocument").
|
|
364
|
+
spyOn(Runtime, "getDocument").and.returnValue({
|
|
367
365
|
location: {
|
|
368
366
|
protocol: "http:"
|
|
369
367
|
}
|
|
@@ -373,7 +371,7 @@ describe("Transports", function() {
|
|
|
373
371
|
|
|
374
372
|
it("should return true if window.XDomainRequest exists, document protocol is https: and connection is using TLS", function() {
|
|
375
373
|
window.XDomainRequest = function() {};
|
|
376
|
-
spyOn(Runtime, "getDocument").
|
|
374
|
+
spyOn(Runtime, "getDocument").and.returnValue({
|
|
377
375
|
location: {
|
|
378
376
|
protocol: "https:"
|
|
379
377
|
}
|
|
@@ -383,7 +381,7 @@ describe("Transports", function() {
|
|
|
383
381
|
|
|
384
382
|
it("should return false if window.XDomainRequest exists, document protocol is http: and connection is using TLS", function() {
|
|
385
383
|
window.XDomainRequest = function() {};
|
|
386
|
-
spyOn(Runtime, "getDocument").
|
|
384
|
+
spyOn(Runtime, "getDocument").and.returnValue({
|
|
387
385
|
location: {
|
|
388
386
|
protocol: "http:"
|
|
389
387
|
}
|
|
@@ -393,7 +391,7 @@ describe("Transports", function() {
|
|
|
393
391
|
|
|
394
392
|
it("should return false if window.XDomainRequest exists, document protocol is https: and connection is not using TLS", function() {
|
|
395
393
|
window.XDomainRequest = function() {};
|
|
396
|
-
spyOn(Runtime, "getDocument").
|
|
394
|
+
spyOn(Runtime, "getDocument").and.returnValue({
|
|
397
395
|
location: {
|
|
398
396
|
protocol: "https:"
|
|
399
397
|
}
|
|
@@ -414,12 +412,12 @@ describe("Transports", function() {
|
|
|
414
412
|
describe(transport, function() {
|
|
415
413
|
describe("getSocket hook", function() {
|
|
416
414
|
it("should return a new streaming HTTPSocket object", function() {
|
|
417
|
-
spyOn(HTTP, "createStreamingSocket").
|
|
415
|
+
spyOn(HTTP, "createStreamingSocket").and.callFake(function(url) {
|
|
418
416
|
return "streaming socket mock";
|
|
419
417
|
});
|
|
420
418
|
|
|
421
419
|
var socket = Transports[transport].hooks.getSocket("streamurl");
|
|
422
|
-
expect(HTTP.createStreamingSocket.calls.
|
|
420
|
+
expect(HTTP.createStreamingSocket.calls.count()).toEqual(1);
|
|
423
421
|
expect(HTTP.createStreamingSocket).toHaveBeenCalledWith("streamurl");
|
|
424
422
|
expect(socket).toEqual("streaming socket mock");
|
|
425
423
|
});
|
|
@@ -431,12 +429,12 @@ describe("Transports", function() {
|
|
|
431
429
|
describe(transport, function() {
|
|
432
430
|
describe("getSocket hook", function() {
|
|
433
431
|
it("should return a new polling HTTPSocket object", function() {
|
|
434
|
-
spyOn(HTTP, "createPollingSocket").
|
|
432
|
+
spyOn(HTTP, "createPollingSocket").and.callFake(function(url) {
|
|
435
433
|
return "polling socket mock";
|
|
436
434
|
});
|
|
437
435
|
|
|
438
436
|
var socket = Transports[transport].hooks.getSocket("streamurl");
|
|
439
|
-
expect(HTTP.createPollingSocket.calls.
|
|
437
|
+
expect(HTTP.createPollingSocket.calls.count()).toEqual(1);
|
|
440
438
|
expect(HTTP.createPollingSocket).toHaveBeenCalledWith("streamurl");
|
|
441
439
|
expect(socket).toEqual("polling socket mock");
|
|
442
440
|
});
|
|
@@ -77,7 +77,7 @@ describe("Fetch Authorizer", function(){
|
|
|
77
77
|
);
|
|
78
78
|
var callback = jasmine.createSpy("callback");
|
|
79
79
|
authorizer.authorize("1.23", callback).then(function(){
|
|
80
|
-
expect(callback.calls.
|
|
80
|
+
expect(callback.calls.count()).toEqual(1);
|
|
81
81
|
expect(callback).toHaveBeenCalledWith(false, data);
|
|
82
82
|
});
|
|
83
83
|
});
|
|
@@ -99,7 +99,7 @@ describe("Fetch Authorizer", function(){
|
|
|
99
99
|
var callback = jasmine.createSpy("callback");
|
|
100
100
|
|
|
101
101
|
authorizer.authorize("1.23", callback).then(function(){
|
|
102
|
-
expect(callback.calls.
|
|
102
|
+
expect(callback.calls.count()).toEqual(1);
|
|
103
103
|
expect(callback).toHaveBeenCalledWith(
|
|
104
104
|
true,
|
|
105
105
|
"JSON returned from auth endpoint was invalid, yet status code was 200. " +
|
|
@@ -9,8 +9,8 @@ describe("fetch", function(){
|
|
|
9
9
|
|
|
10
10
|
beforeEach(function(){
|
|
11
11
|
timeline = Mocks.getTimeline();
|
|
12
|
-
timeline.isEmpty.
|
|
13
|
-
timeline.send.
|
|
12
|
+
timeline.isEmpty.and.returnValue(false);
|
|
13
|
+
timeline.send.and.callFake(function(sendXHR, callback) {
|
|
14
14
|
sendXHR({ events: [1, 2, 3]}, callback);
|
|
15
15
|
});
|
|
16
16
|
|
package/src/core/auth/options.ts
CHANGED
package/webpack/config.node.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
var path = require('path');
|
|
2
|
-
|
|
2
|
+
const { merge } = require('webpack-merge');
|
|
3
3
|
var configShared = require('./config.shared');
|
|
4
4
|
var webpack = require('webpack');
|
|
5
5
|
|
|
6
|
-
module.exports =
|
|
6
|
+
module.exports = merge({}, configShared, {
|
|
7
7
|
entry: {
|
|
8
8
|
pusher: './src/core/pusher-with-encryption.js'
|
|
9
9
|
},
|
|
@@ -2,12 +2,12 @@ var path = require('path');
|
|
|
2
2
|
var NormalModuleReplacementPlugin = require('webpack')
|
|
3
3
|
.NormalModuleReplacementPlugin;
|
|
4
4
|
var version = require('../package').version;
|
|
5
|
-
|
|
5
|
+
const { merge } = require('webpack-merge');
|
|
6
6
|
var configShared = require('./config.shared');
|
|
7
7
|
var webpack = require('webpack');
|
|
8
8
|
var buffer = require('buffer');
|
|
9
9
|
|
|
10
|
-
module.exports =
|
|
10
|
+
module.exports = merge({}, configShared, {
|
|
11
11
|
entry: {
|
|
12
12
|
pusher: './src/core/pusher-with-encryption.js'
|
|
13
13
|
},
|
package/webpack/config.shared.js
CHANGED
|
@@ -16,13 +16,21 @@ module.exports = {
|
|
|
16
16
|
entry: {
|
|
17
17
|
pusher: './src/core/pusher.js'
|
|
18
18
|
},
|
|
19
|
+
devtool: 'source-map',
|
|
19
20
|
resolve: {
|
|
20
21
|
extensions: ['.webpack.js', '.web.js', '.ts', '.js'],
|
|
21
22
|
// add runtimes for easier importing of isomorphic runtime modules
|
|
22
23
|
modules: ['src', 'src/runtimes', 'node_modules']
|
|
23
24
|
},
|
|
24
25
|
module: {
|
|
25
|
-
rules: [
|
|
26
|
+
rules: [
|
|
27
|
+
{ test: /\.ts$/, loader: 'ts-loader' },
|
|
28
|
+
{
|
|
29
|
+
test: /\.js$/,
|
|
30
|
+
enforce: 'pre',
|
|
31
|
+
use: ['source-map-loader']
|
|
32
|
+
}
|
|
33
|
+
]
|
|
26
34
|
},
|
|
27
35
|
node: {
|
|
28
36
|
// nacl uses Buffer on node.js but has a different code path for the browser.
|
package/webpack/config.web.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var path = require('path');
|
|
2
2
|
var webpack = require('webpack');
|
|
3
3
|
var NormalModuleReplacementPlugin = webpack.NormalModuleReplacementPlugin;
|
|
4
|
-
|
|
4
|
+
const { merge } = require('webpack-merge');
|
|
5
5
|
var configShared = require('./config.shared');
|
|
6
6
|
|
|
7
7
|
var filename = configShared.optimization.minimize
|
|
@@ -14,7 +14,7 @@ if (process.env.INCLUDE_TWEETNACL === 'true') {
|
|
|
14
14
|
filename = filename.replace('pusher', 'pusher-with-encryption');
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
module.exports =
|
|
17
|
+
module.exports = merge({}, configShared, {
|
|
18
18
|
entry: {
|
|
19
19
|
pusher: entry
|
|
20
20
|
},
|
package/webpack/config.worker.js
CHANGED
|
@@ -2,7 +2,7 @@ var path = require('path');
|
|
|
2
2
|
var NormalModuleReplacementPlugin = require('webpack')
|
|
3
3
|
.NormalModuleReplacementPlugin;
|
|
4
4
|
var version = require('../package').version;
|
|
5
|
-
|
|
5
|
+
const { merge } = require('webpack-merge');
|
|
6
6
|
var webpack = require('webpack');
|
|
7
7
|
var configShared = require('./config.shared');
|
|
8
8
|
|
|
@@ -16,14 +16,16 @@ if (process.env.INCLUDE_TWEETNACL === 'true') {
|
|
|
16
16
|
filename = filename.replace('pusher', 'pusher-with-encryption');
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
var config =
|
|
19
|
+
var config = merge(configShared, {
|
|
20
20
|
entry: {
|
|
21
21
|
pusher: entry
|
|
22
22
|
},
|
|
23
23
|
output: {
|
|
24
24
|
library: 'Pusher',
|
|
25
25
|
path: path.join(__dirname, '../dist/worker'),
|
|
26
|
-
filename: filename
|
|
26
|
+
filename: filename,
|
|
27
|
+
libraryTarget: 'umd',
|
|
28
|
+
globalObject: 'this'
|
|
27
29
|
},
|
|
28
30
|
resolve: {
|
|
29
31
|
// in order to import the appropriate runtime.ts
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export {
|
|
2
|
+
Authorizer,
|
|
3
|
+
AuthOptions,
|
|
4
|
+
AuthorizerGenerator,
|
|
5
|
+
AuthorizerCallback,
|
|
6
|
+
} from '../types/src/core/auth/options';
|
|
7
|
+
export { Options } from '../types/src/core/options';
|
|
8
|
+
|
|
9
|
+
export { default as Channel } from '../types/src/core/channels/channel';
|
|
10
|
+
export { default as PresenceChannel } from '../types/src/core/channels/presence_channel';
|
|
11
|
+
export { default as Members } from '../types/src/core/channels/members';
|
|
12
|
+
export { default as Runtime } from '../types/src/runtimes/interface';
|
|
13
|
+
export { default as ConnectionManager } from '../types/src/core/connection/connection_manager';
|
|
14
|
+
|
|
15
|
+
export { default } from '../types/src/core/pusher';
|
package/worker/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../dist/worker/pusher.worker.js');
|