zmdms-utils 0.0.81 → 0.0.83
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/dist/es/validate.js +168 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/package.json +2 -6
- package/src/index.ts +0 -3
- package/src/validate.ts +198 -0
- package/dist/es/_virtual/FastBufferList.js +0 -7
- package/dist/es/_virtual/_commonjs-dynamic-modules.js +0 -5
- package/dist/es/_virtual/browser.js +0 -7
- package/dist/es/_virtual/browser2.js +0 -7
- package/dist/es/_virtual/debug.js +0 -7
- package/dist/es/_virtual/event.js +0 -7
- package/dist/es/_virtual/http-parser.js +0 -3
- package/dist/es/_virtual/iframe.js +0 -7
- package/dist/es/_virtual/index.js +0 -7
- package/dist/es/_virtual/index2.js +0 -7
- package/dist/es/_virtual/index3.js +0 -7
- package/dist/es/_virtual/index4.js +0 -7
- package/dist/es/_virtual/index5.js +0 -7
- package/dist/es/_virtual/index6.js +0 -7
- package/dist/es/_virtual/index7.js +0 -3
- package/dist/es/_virtual/index8.js +0 -7
- package/dist/es/_virtual/index9.js +0 -7
- package/dist/es/_virtual/inherits.js +0 -7
- package/dist/es/_virtual/inherits_browser.js +0 -7
- package/dist/es/_virtual/json3.js +0 -7
- package/dist/es/_virtual/node.js +0 -7
- package/dist/es/_virtual/node2.js +0 -7
- package/dist/es/_virtual/stomp-node.js +0 -3
- package/dist/es/_virtual/stomp.js +0 -3
- package/dist/es/_virtual/streams.js +0 -3
- package/dist/es/_virtual/utils.js +0 -3
- package/dist/es/node_modules/bufferutil/fallback.js +0 -43
- package/dist/es/node_modules/bufferutil/index.js +0 -21
- package/dist/es/node_modules/debug/src/browser.js +0 -192
- package/dist/es/node_modules/debug/src/common.js +0 -259
- package/dist/es/node_modules/debug/src/index.js +0 -25
- package/dist/es/node_modules/debug/src/node.js +0 -192
- package/dist/es/node_modules/eventsource/lib/eventsource.js +0 -493
- package/dist/es/node_modules/faye-websocket/lib/faye/eventsource.js +0 -150
- package/dist/es/node_modules/faye-websocket/lib/faye/websocket/api/event.js +0 -31
- package/dist/es/node_modules/faye-websocket/lib/faye/websocket/api/event_target.js +0 -41
- package/dist/es/node_modules/faye-websocket/lib/faye/websocket/api.js +0 -205
- package/dist/es/node_modules/faye-websocket/lib/faye/websocket/client.js +0 -107
- package/dist/es/node_modules/faye-websocket/lib/faye/websocket.js +0 -47
- package/dist/es/node_modules/has-flag/index.js +0 -17
- package/dist/es/node_modules/http-parser-js/http-parser.js +0 -471
- package/dist/es/node_modules/inherits/inherits.js +0 -14
- package/dist/es/node_modules/inherits/inherits_browser.js +0 -38
- package/dist/es/node_modules/is-typedarray/index.js +0 -51
- package/dist/es/node_modules/json3/lib/json3.js +0 -937
- package/dist/es/node_modules/ms/index.js +0 -172
- package/dist/es/node_modules/node-gyp-build/index.js +0 -21
- package/dist/es/node_modules/node-gyp-build/node-gyp-build.js +0 -222
- package/dist/es/node_modules/querystringify/index.js +0 -120
- package/dist/es/node_modules/requires-port/index.js +0 -38
- package/dist/es/node_modules/safe-buffer/index.js +0 -71
- package/dist/es/node_modules/supports-color/index.js +0 -143
- package/dist/es/node_modules/typedarray-to-buffer/index.js +0 -37
- package/dist/es/node_modules/url-parse/index.js +0 -594
- package/dist/es/node_modules/utf-8-validate/fallback.js +0 -71
- package/dist/es/node_modules/utf-8-validate/index.js +0 -21
- package/dist/es/node_modules/websocket/index.js +0 -15
- package/dist/es/node_modules/websocket/lib/Deprecation.js +0 -42
- package/dist/es/node_modules/websocket/lib/W3CWebSocket.js +0 -268
- package/dist/es/node_modules/websocket/lib/WebSocketClient.js +0 -380
- package/dist/es/node_modules/websocket/lib/WebSocketConnection.js +0 -914
- package/dist/es/node_modules/websocket/lib/WebSocketFrame.js +0 -293
- package/dist/es/node_modules/websocket/lib/WebSocketRequest.js +0 -543
- package/dist/es/node_modules/websocket/lib/WebSocketRouter.js +0 -172
- package/dist/es/node_modules/websocket/lib/WebSocketRouterRequest.js +0 -67
- package/dist/es/node_modules/websocket/lib/WebSocketServer.js +0 -272
- package/dist/es/node_modules/websocket/lib/utils.js +0 -80
- package/dist/es/node_modules/websocket/lib/version.js +0 -13
- package/dist/es/node_modules/websocket/lib/websocket.js +0 -31
- package/dist/es/node_modules/websocket/node_modules/debug/src/browser.js +0 -199
- package/dist/es/node_modules/websocket/node_modules/debug/src/debug.js +0 -215
- package/dist/es/node_modules/websocket/node_modules/debug/src/index.js +0 -25
- package/dist/es/node_modules/websocket/node_modules/debug/src/node.js +0 -266
- package/dist/es/node_modules/websocket/node_modules/ms/index.js +0 -162
- package/dist/es/node_modules/websocket/package.json.js +0 -77
- package/dist/es/node_modules/websocket/vendor/FastBufferList.js +0 -205
- package/dist/es/node_modules/websocket-driver/lib/websocket/driver/base.js +0 -202
- package/dist/es/node_modules/websocket-driver/lib/websocket/driver/client.js +0 -152
- package/dist/es/node_modules/websocket-driver/lib/websocket/driver/draft75.js +0 -128
- package/dist/es/node_modules/websocket-driver/lib/websocket/driver/draft76.js +0 -124
- package/dist/es/node_modules/websocket-driver/lib/websocket/driver/headers.js +0 -44
- package/dist/es/node_modules/websocket-driver/lib/websocket/driver/hybi/frame.js +0 -21
- package/dist/es/node_modules/websocket-driver/lib/websocket/driver/hybi/message.js +0 -37
- package/dist/es/node_modules/websocket-driver/lib/websocket/driver/hybi.js +0 -492
- package/dist/es/node_modules/websocket-driver/lib/websocket/driver/proxy.js +0 -108
- package/dist/es/node_modules/websocket-driver/lib/websocket/driver/server.js +0 -119
- package/dist/es/node_modules/websocket-driver/lib/websocket/driver/stream_reader.js +0 -72
- package/dist/es/node_modules/websocket-driver/lib/websocket/driver.js +0 -47
- package/dist/es/node_modules/websocket-driver/lib/websocket/http_parser.js +0 -140
- package/dist/es/node_modules/websocket-driver/lib/websocket/streams.js +0 -150
- package/dist/es/node_modules/websocket-extensions/lib/parser.js +0 -103
- package/dist/es/node_modules/websocket-extensions/lib/pipeline/cell.js +0 -56
- package/dist/es/node_modules/websocket-extensions/lib/pipeline/functor.js +0 -74
- package/dist/es/node_modules/websocket-extensions/lib/pipeline/index.js +0 -50
- package/dist/es/node_modules/websocket-extensions/lib/pipeline/pledge.js +0 -39
- package/dist/es/node_modules/websocket-extensions/lib/pipeline/ring_buffer.js +0 -66
- package/dist/es/node_modules/websocket-extensions/lib/websocket_extensions.js +0 -165
- package/dist/es/node_modules/yaeti/index.js +0 -17
- package/dist/es/node_modules/yaeti/lib/Event.js +0 -24
- package/dist/es/node_modules/yaeti/lib/EventTarget.js +0 -130
- package/dist/es/node_modules/zt-sockjs-client/lib/entry.js +0 -14
- package/dist/es/node_modules/zt-sockjs-client/lib/event/close.js +0 -21
- package/dist/es/node_modules/zt-sockjs-client/lib/event/event.js +0 -22
- package/dist/es/node_modules/zt-sockjs-client/lib/event/eventtarget.js +0 -62
- package/dist/es/node_modules/zt-sockjs-client/lib/event/trans-message.js +0 -19
- package/dist/es/node_modules/zt-sockjs-client/lib/facade.js +0 -40
- package/dist/es/node_modules/zt-sockjs-client/lib/iframe-bootstrap.js +0 -122
- package/dist/es/node_modules/zt-sockjs-client/lib/info-ajax.js +0 -57
- package/dist/es/node_modules/zt-sockjs-client/lib/info-iframe-receiver.js +0 -50
- package/dist/es/node_modules/zt-sockjs-client/lib/info-iframe.js +0 -81
- package/dist/es/node_modules/zt-sockjs-client/lib/info-receiver.js +0 -101
- package/dist/es/node_modules/zt-sockjs-client/lib/location.js +0 -12
- package/dist/es/node_modules/zt-sockjs-client/lib/main.js +0 -413
- package/dist/es/node_modules/zt-sockjs-client/lib/shims.js +0 -449
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/driver/websocket.js +0 -5
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/driver/xhr.js +0 -80
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/eventsource.js +0 -34
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/htmlfile.js +0 -31
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/iframe.js +0 -154
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/jsonp-polling.js +0 -41
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/lib/ajax-based.js +0 -55
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/lib/buffered-sender.js +0 -92
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/lib/iframe-wrap.js +0 -39
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/lib/polling.js +0 -65
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/lib/sender-receiver.js +0 -52
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/receiver/eventsource.js +0 -69
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/receiver/htmlfile.js +0 -96
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/receiver/jsonp.js +0 -193
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/receiver/xhr.js +0 -75
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/sender/jsonp.js +0 -104
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/sender/xdr.js +0 -113
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/sender/xhr-cors.js +0 -19
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/sender/xhr-fake.js +0 -28
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/sender/xhr-local.js +0 -21
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/websocket.js +0 -108
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/xdr-polling.js +0 -30
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/xdr-streaming.js +0 -38
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/xhr-polling.js +0 -40
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/xhr-streaming.js +0 -50
- package/dist/es/node_modules/zt-sockjs-client/lib/transport-list.js +0 -28
- package/dist/es/node_modules/zt-sockjs-client/lib/utils/browser.js +0 -29
- package/dist/es/node_modules/zt-sockjs-client/lib/utils/escape.js +0 -53
- package/dist/es/node_modules/zt-sockjs-client/lib/utils/event.js +0 -78
- package/dist/es/node_modules/zt-sockjs-client/lib/utils/iframe.js +0 -205
- package/dist/es/node_modules/zt-sockjs-client/lib/utils/log.js +0 -20
- package/dist/es/node_modules/zt-sockjs-client/lib/utils/object.js +0 -24
- package/dist/es/node_modules/zt-sockjs-client/lib/utils/random.js +0 -30
- package/dist/es/node_modules/zt-sockjs-client/lib/utils/transport.js +0 -52
- package/dist/es/node_modules/zt-sockjs-client/lib/utils/url.js +0 -54
- package/dist/es/node_modules/zt-sockjs-client/lib/version.js +0 -11
- package/dist/es/node_modules/zt-stompjs/index.js +0 -23
- package/dist/es/node_modules/zt-stompjs/lib/stomp-node.js +0 -117
- package/dist/es/node_modules/zt-stompjs/lib/stomp.js +0 -536
- package/dist/es/stompClient.d.ts +0 -55
- package/dist/es/stompClient.js +0 -379
- package/src/stompClient.ts +0 -449
|
@@ -1,413 +0,0 @@
|
|
|
1
|
-
import { commonjsGlobal } from '../../../_virtual/_commonjsHelpers.js';
|
|
2
|
-
import './shims.js';
|
|
3
|
-
import urlParse from '../../url-parse/index.js';
|
|
4
|
-
import '../../inherits/inherits.js';
|
|
5
|
-
import '../../json3/lib/json3.js';
|
|
6
|
-
import random$1 from './utils/random.js';
|
|
7
|
-
import _escape from './utils/escape.js';
|
|
8
|
-
import url from './utils/url.js';
|
|
9
|
-
import './utils/event.js';
|
|
10
|
-
import transport$1 from './utils/transport.js';
|
|
11
|
-
import object from './utils/object.js';
|
|
12
|
-
import browser$1 from './utils/browser.js';
|
|
13
|
-
import log$1 from './utils/log.js';
|
|
14
|
-
import event from './event/event.js';
|
|
15
|
-
import eventtarget from './event/eventtarget.js';
|
|
16
|
-
import location from './location.js';
|
|
17
|
-
import close from './event/close.js';
|
|
18
|
-
import transMessage from './event/trans-message.js';
|
|
19
|
-
import infoReceiver from './info-receiver.js';
|
|
20
|
-
import { __require as requireSrc } from '../../debug/src/index.js';
|
|
21
|
-
import { __require as requireVersion } from './version.js';
|
|
22
|
-
import { __require as requireIframeBootstrap } from './iframe-bootstrap.js';
|
|
23
|
-
import { exports as inheritsExports } from '../../../_virtual/inherits.js';
|
|
24
|
-
import { exports as json3Exports } from '../../../_virtual/json3.js';
|
|
25
|
-
import { exports as eventExports } from '../../../_virtual/event.js';
|
|
26
|
-
|
|
27
|
-
var URL = urlParse
|
|
28
|
-
, inherits = inheritsExports
|
|
29
|
-
, JSON3 = json3Exports
|
|
30
|
-
, random = random$1
|
|
31
|
-
, escape = _escape
|
|
32
|
-
, urlUtils = url
|
|
33
|
-
, eventUtils = eventExports
|
|
34
|
-
, transport = transport$1
|
|
35
|
-
, objectUtils = object
|
|
36
|
-
, browser = browser$1
|
|
37
|
-
, log = log$1
|
|
38
|
-
, Event = event
|
|
39
|
-
, EventTarget = eventtarget
|
|
40
|
-
, loc = location
|
|
41
|
-
, CloseEvent = close
|
|
42
|
-
, TransportMessageEvent = transMessage
|
|
43
|
-
, InfoReceiver = infoReceiver
|
|
44
|
-
;
|
|
45
|
-
|
|
46
|
-
var debug = function() {};
|
|
47
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
48
|
-
debug = requireSrc()('sockjs-client:main');
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
var transports;
|
|
52
|
-
|
|
53
|
-
// follow constructor steps defined at http://dev.w3.org/html5/websockets/#the-websocket-interface
|
|
54
|
-
function SockJS(url, protocols, options) {
|
|
55
|
-
if (!(this instanceof SockJS)) {
|
|
56
|
-
return new SockJS(url, protocols, options);
|
|
57
|
-
}
|
|
58
|
-
if (arguments.length < 1) {
|
|
59
|
-
throw new TypeError("Failed to construct 'SockJS: 1 argument required, but only 0 present");
|
|
60
|
-
}
|
|
61
|
-
EventTarget.call(this);
|
|
62
|
-
|
|
63
|
-
this.readyState = SockJS.CONNECTING;
|
|
64
|
-
this.extensions = '';
|
|
65
|
-
this.protocol = '';
|
|
66
|
-
|
|
67
|
-
// non-standard extension
|
|
68
|
-
options = options || {};
|
|
69
|
-
if (options.protocols_whitelist) {
|
|
70
|
-
log.warn("'protocols_whitelist' is DEPRECATED. Use 'transports' instead.");
|
|
71
|
-
}
|
|
72
|
-
this._transportsWhitelist = options.transports;
|
|
73
|
-
this._transportOptions = options.transportOptions || {};
|
|
74
|
-
this._timeout = options.timeout || 0;
|
|
75
|
-
|
|
76
|
-
var sessionId = options.sessionId || 8;
|
|
77
|
-
if (typeof sessionId === 'function') {
|
|
78
|
-
this._generateSessionId = sessionId;
|
|
79
|
-
} else if (typeof sessionId === 'number') {
|
|
80
|
-
this._generateSessionId = function() {
|
|
81
|
-
return random.string(sessionId);
|
|
82
|
-
};
|
|
83
|
-
} else {
|
|
84
|
-
throw new TypeError('If sessionId is used in the options, it needs to be a number or a function.');
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
this._server = options.server || random.numberString(1000);
|
|
88
|
-
|
|
89
|
-
// Step 1 of WS spec - parse and validate the url. Issue #8
|
|
90
|
-
var parsedUrl = new URL(url);
|
|
91
|
-
if (!parsedUrl.host || !parsedUrl.protocol) {
|
|
92
|
-
throw new SyntaxError("The URL '" + url + "' is invalid");
|
|
93
|
-
} else if (parsedUrl.hash) {
|
|
94
|
-
throw new SyntaxError('The URL must not contain a fragment');
|
|
95
|
-
} else if (parsedUrl.protocol !== 'http:' && parsedUrl.protocol !== 'https:') {
|
|
96
|
-
throw new SyntaxError("The URL's scheme must be either 'http:' or 'https:'. '" + parsedUrl.protocol + "' is not allowed.");
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
var secure = parsedUrl.protocol === 'https:';
|
|
100
|
-
// Step 2 - don't allow secure origin with an insecure protocol
|
|
101
|
-
if (loc.protocol === 'https:' && !secure) {
|
|
102
|
-
// exception is 127.0.0.0/8 and ::1 urls
|
|
103
|
-
if (!urlUtils.isLoopbackAddr(parsedUrl.hostname)) {
|
|
104
|
-
throw new Error('SecurityError: An insecure SockJS connection may not be initiated from a page loaded over HTTPS');
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// Step 3 - check port access - no need here
|
|
109
|
-
// Step 4 - parse protocols argument
|
|
110
|
-
if (!protocols) {
|
|
111
|
-
protocols = [];
|
|
112
|
-
} else if (!Array.isArray(protocols)) {
|
|
113
|
-
protocols = [protocols];
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// Step 5 - check protocols argument
|
|
117
|
-
var sortedProtocols = protocols.sort();
|
|
118
|
-
sortedProtocols.forEach(function(proto, i) {
|
|
119
|
-
if (!proto) {
|
|
120
|
-
throw new SyntaxError("The protocols entry '" + proto + "' is invalid.");
|
|
121
|
-
}
|
|
122
|
-
if (i < (sortedProtocols.length - 1) && proto === sortedProtocols[i + 1]) {
|
|
123
|
-
throw new SyntaxError("The protocols entry '" + proto + "' is duplicated.");
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
// Step 6 - convert origin
|
|
128
|
-
var o = urlUtils.getOrigin(loc.href);
|
|
129
|
-
this._origin = o ? o.toLowerCase() : null;
|
|
130
|
-
|
|
131
|
-
// remove the trailing slash
|
|
132
|
-
parsedUrl.set('pathname', parsedUrl.pathname.replace(/\/+$/, ''));
|
|
133
|
-
|
|
134
|
-
// store the sanitized url
|
|
135
|
-
this.url = parsedUrl.href;
|
|
136
|
-
debug('using url', this.url);
|
|
137
|
-
|
|
138
|
-
// Step 7 - start connection in background
|
|
139
|
-
// obtain server info
|
|
140
|
-
// http://sockjs.github.io/sockjs-protocol/sockjs-protocol-0.3.3.html#section-26
|
|
141
|
-
this._urlInfo = {
|
|
142
|
-
nullOrigin: !browser.hasDomain()
|
|
143
|
-
, sameOrigin: urlUtils.isOriginEqual(this.url, loc.href)
|
|
144
|
-
, sameScheme: urlUtils.isSchemeEqual(this.url, loc.href)
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
this._ir = new InfoReceiver(this.url, this._urlInfo);
|
|
148
|
-
this._ir.once('finish', this._receiveInfo.bind(this));
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
inherits(SockJS, EventTarget);
|
|
152
|
-
|
|
153
|
-
function userSetCode(code) {
|
|
154
|
-
return code === 1000 || (code >= 3000 && code <= 4999);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
SockJS.prototype.close = function(code, reason) {
|
|
158
|
-
// Step 1
|
|
159
|
-
if (code && !userSetCode(code)) {
|
|
160
|
-
throw new Error('InvalidAccessError: Invalid code');
|
|
161
|
-
}
|
|
162
|
-
// Step 2.4 states the max is 123 bytes, but we are just checking length
|
|
163
|
-
if (reason && reason.length > 123) {
|
|
164
|
-
throw new SyntaxError('reason argument has an invalid length');
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// Step 3.1
|
|
168
|
-
if (this.readyState === SockJS.CLOSING || this.readyState === SockJS.CLOSED) {
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// TODO look at docs to determine how to set this
|
|
173
|
-
var wasClean = true;
|
|
174
|
-
this._close(code || 1000, reason || 'Normal closure', wasClean);
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
SockJS.prototype.send = function(data) {
|
|
178
|
-
// #13 - convert anything non-string to string
|
|
179
|
-
// TODO this currently turns objects into [object Object]
|
|
180
|
-
if (typeof data !== 'string') {
|
|
181
|
-
data = '' + data;
|
|
182
|
-
}
|
|
183
|
-
if (this.readyState === SockJS.CONNECTING) {
|
|
184
|
-
throw new Error('InvalidStateError: The connection has not been established yet');
|
|
185
|
-
}
|
|
186
|
-
if (this.readyState !== SockJS.OPEN) {
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
189
|
-
this._transport.send(escape.quote(data));
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
SockJS.version = requireVersion();
|
|
193
|
-
|
|
194
|
-
SockJS.CONNECTING = 0;
|
|
195
|
-
SockJS.OPEN = 1;
|
|
196
|
-
SockJS.CLOSING = 2;
|
|
197
|
-
SockJS.CLOSED = 3;
|
|
198
|
-
|
|
199
|
-
SockJS.prototype._receiveInfo = function(info, rtt) {
|
|
200
|
-
debug('_receiveInfo', rtt);
|
|
201
|
-
this._ir = null;
|
|
202
|
-
if (!info) {
|
|
203
|
-
this._close(1002, 'Cannot connect to server');
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
// establish a round-trip timeout (RTO) based on the
|
|
208
|
-
// round-trip time (RTT)
|
|
209
|
-
this._rto = this.countRTO(rtt);
|
|
210
|
-
// allow server to override url used for the actual transport
|
|
211
|
-
this._transUrl = info.base_url ? info.base_url : this.url;
|
|
212
|
-
info = objectUtils.extend(info, this._urlInfo);
|
|
213
|
-
debug('info', info);
|
|
214
|
-
// determine list of desired and supported transports
|
|
215
|
-
var enabledTransports = transports.filterToEnabled(this._transportsWhitelist, info);
|
|
216
|
-
this._transports = enabledTransports.main;
|
|
217
|
-
debug(this._transports.length + ' enabled transports');
|
|
218
|
-
|
|
219
|
-
this._connect();
|
|
220
|
-
};
|
|
221
|
-
|
|
222
|
-
SockJS.prototype._connect = function() {
|
|
223
|
-
for (var Transport = this._transports.shift(); Transport; Transport = this._transports.shift()) {
|
|
224
|
-
debug('attempt', Transport.transportName);
|
|
225
|
-
if (Transport.needBody) {
|
|
226
|
-
if (!commonjsGlobal.document.body ||
|
|
227
|
-
(typeof commonjsGlobal.document.readyState !== 'undefined' &&
|
|
228
|
-
commonjsGlobal.document.readyState !== 'complete' &&
|
|
229
|
-
commonjsGlobal.document.readyState !== 'interactive')) {
|
|
230
|
-
debug('waiting for body');
|
|
231
|
-
this._transports.unshift(Transport);
|
|
232
|
-
eventUtils.attachEvent('load', this._connect.bind(this));
|
|
233
|
-
return;
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
// calculate timeout based on RTO and round trips. Default to 5s
|
|
238
|
-
var timeoutMs = Math.max(this._timeout, (this._rto * Transport.roundTrips) || 5000);
|
|
239
|
-
this._transportTimeoutId = setTimeout(this._transportTimeout.bind(this), timeoutMs);
|
|
240
|
-
debug('using timeout', timeoutMs);
|
|
241
|
-
|
|
242
|
-
var transportUrl = urlUtils.addPath(this._transUrl, '/' + this._server + '/' + this._generateSessionId());
|
|
243
|
-
var options = this._transportOptions[Transport.transportName];
|
|
244
|
-
debug('transport url', transportUrl);
|
|
245
|
-
var transportObj = new Transport(transportUrl, this._transUrl, options);
|
|
246
|
-
transportObj.on('message', this._transportMessage.bind(this));
|
|
247
|
-
transportObj.once('close', this._transportClose.bind(this));
|
|
248
|
-
transportObj.transportName = Transport.transportName;
|
|
249
|
-
this._transport = transportObj;
|
|
250
|
-
|
|
251
|
-
return;
|
|
252
|
-
}
|
|
253
|
-
this._close(2000, 'All transports failed', false);
|
|
254
|
-
};
|
|
255
|
-
|
|
256
|
-
SockJS.prototype._transportTimeout = function() {
|
|
257
|
-
debug('_transportTimeout');
|
|
258
|
-
if (this.readyState === SockJS.CONNECTING) {
|
|
259
|
-
if (this._transport) {
|
|
260
|
-
this._transport.close();
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
this._transportClose(2007, 'Transport timed out');
|
|
264
|
-
}
|
|
265
|
-
};
|
|
266
|
-
|
|
267
|
-
SockJS.prototype._transportMessage = function(msg) {
|
|
268
|
-
debug('_transportMessage', msg);
|
|
269
|
-
var self = this
|
|
270
|
-
, type = msg.slice(0, 1)
|
|
271
|
-
, content = msg.slice(1)
|
|
272
|
-
, payload
|
|
273
|
-
;
|
|
274
|
-
|
|
275
|
-
// first check for messages that don't need a payload
|
|
276
|
-
switch (type) {
|
|
277
|
-
case 'o':
|
|
278
|
-
this._open();
|
|
279
|
-
return;
|
|
280
|
-
case 'h':
|
|
281
|
-
this.dispatchEvent(new Event('heartbeat'));
|
|
282
|
-
debug('heartbeat', this.transport);
|
|
283
|
-
return;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
if (content) {
|
|
287
|
-
try {
|
|
288
|
-
payload = JSON3.parse(content);
|
|
289
|
-
} catch (e) {
|
|
290
|
-
debug('bad json', content);
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
if (typeof payload === 'undefined') {
|
|
295
|
-
debug('empty payload', content);
|
|
296
|
-
return;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
switch (type) {
|
|
300
|
-
case 'a':
|
|
301
|
-
if (Array.isArray(payload)) {
|
|
302
|
-
payload.forEach(function(p) {
|
|
303
|
-
debug('message', self.transport, p);
|
|
304
|
-
self.dispatchEvent(new TransportMessageEvent(p));
|
|
305
|
-
});
|
|
306
|
-
}
|
|
307
|
-
break;
|
|
308
|
-
case 'm':
|
|
309
|
-
debug('message', this.transport, payload);
|
|
310
|
-
this.dispatchEvent(new TransportMessageEvent(payload));
|
|
311
|
-
break;
|
|
312
|
-
case 'c':
|
|
313
|
-
if (Array.isArray(payload) && payload.length === 2) {
|
|
314
|
-
this._close(payload[0], payload[1], true);
|
|
315
|
-
}
|
|
316
|
-
break;
|
|
317
|
-
}
|
|
318
|
-
};
|
|
319
|
-
|
|
320
|
-
SockJS.prototype._transportClose = function(code, reason) {
|
|
321
|
-
debug('_transportClose', this.transport, code, reason);
|
|
322
|
-
if (this._transport) {
|
|
323
|
-
this._transport.removeAllListeners();
|
|
324
|
-
this._transport = null;
|
|
325
|
-
this.transport = null;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
if (!userSetCode(code) && code !== 2000 && this.readyState === SockJS.CONNECTING) {
|
|
329
|
-
this._connect();
|
|
330
|
-
return;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
this._close(code, reason);
|
|
334
|
-
};
|
|
335
|
-
|
|
336
|
-
SockJS.prototype._open = function() {
|
|
337
|
-
debug('_open', this._transport && this._transport.transportName, this.readyState);
|
|
338
|
-
if (this.readyState === SockJS.CONNECTING) {
|
|
339
|
-
if (this._transportTimeoutId) {
|
|
340
|
-
clearTimeout(this._transportTimeoutId);
|
|
341
|
-
this._transportTimeoutId = null;
|
|
342
|
-
}
|
|
343
|
-
this.readyState = SockJS.OPEN;
|
|
344
|
-
this.transport = this._transport.transportName;
|
|
345
|
-
this.dispatchEvent(new Event('open'));
|
|
346
|
-
debug('connected', this.transport);
|
|
347
|
-
} else {
|
|
348
|
-
// The server might have been restarted, and lost track of our
|
|
349
|
-
// connection.
|
|
350
|
-
this._close(1006, 'Server lost session');
|
|
351
|
-
}
|
|
352
|
-
};
|
|
353
|
-
|
|
354
|
-
SockJS.prototype._close = function(code, reason, wasClean) {
|
|
355
|
-
debug('_close', this.transport, code, reason, wasClean, this.readyState);
|
|
356
|
-
var forceFail = false;
|
|
357
|
-
|
|
358
|
-
if (this._ir) {
|
|
359
|
-
forceFail = true;
|
|
360
|
-
this._ir.close();
|
|
361
|
-
this._ir = null;
|
|
362
|
-
}
|
|
363
|
-
if (this._transport) {
|
|
364
|
-
this._transport.close();
|
|
365
|
-
this._transport = null;
|
|
366
|
-
this.transport = null;
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
if (this.readyState === SockJS.CLOSED) {
|
|
370
|
-
throw new Error('InvalidStateError: SockJS has already been closed');
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
this.readyState = SockJS.CLOSING;
|
|
374
|
-
setTimeout(function() {
|
|
375
|
-
this.readyState = SockJS.CLOSED;
|
|
376
|
-
|
|
377
|
-
if (forceFail) {
|
|
378
|
-
this.dispatchEvent(new Event('error'));
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
var e = new CloseEvent();
|
|
382
|
-
e.wasClean = wasClean || false;
|
|
383
|
-
e.code = code || 1000;
|
|
384
|
-
e.reason = reason;
|
|
385
|
-
|
|
386
|
-
this.dispatchEvent(e);
|
|
387
|
-
this.onmessage = this.onclose = this.onerror = null;
|
|
388
|
-
debug('disconnected');
|
|
389
|
-
}.bind(this), 0);
|
|
390
|
-
};
|
|
391
|
-
|
|
392
|
-
// See: http://www.erg.abdn.ac.uk/~gerrit/dccp/notes/ccid2/rto_estimator/
|
|
393
|
-
// and RFC 2988.
|
|
394
|
-
SockJS.prototype.countRTO = function(rtt) {
|
|
395
|
-
// In a local environment, when using IE8/9 and the `jsonp-polling`
|
|
396
|
-
// transport the time needed to establish a connection (the time that pass
|
|
397
|
-
// from the opening of the transport to the call of `_dispatchOpen`) is
|
|
398
|
-
// around 200msec (the lower bound used in the article above) and this
|
|
399
|
-
// causes spurious timeouts. For this reason we calculate a value slightly
|
|
400
|
-
// larger than that used in the article.
|
|
401
|
-
if (rtt > 100) {
|
|
402
|
-
return 4 * rtt; // rto > 400msec
|
|
403
|
-
}
|
|
404
|
-
return 300 + rtt; // 300msec < rto <= 400msec
|
|
405
|
-
};
|
|
406
|
-
|
|
407
|
-
var main = function(availableTransports) {
|
|
408
|
-
transports = transport(availableTransports);
|
|
409
|
-
requireIframeBootstrap()(SockJS, availableTransports);
|
|
410
|
-
return SockJS;
|
|
411
|
-
};
|
|
412
|
-
|
|
413
|
-
export { main as default };
|