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,42 +0,0 @@
|
|
|
1
|
-
/************************************************************************
|
|
2
|
-
* Copyright 2010-2015 Brian McKelvey.
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
***********************************************************************/
|
|
16
|
-
|
|
17
|
-
var Deprecation_1;
|
|
18
|
-
var hasRequiredDeprecation;
|
|
19
|
-
|
|
20
|
-
function requireDeprecation () {
|
|
21
|
-
if (hasRequiredDeprecation) return Deprecation_1;
|
|
22
|
-
hasRequiredDeprecation = 1;
|
|
23
|
-
var Deprecation = {
|
|
24
|
-
disableWarnings: false,
|
|
25
|
-
|
|
26
|
-
deprecationWarningMap: {
|
|
27
|
-
|
|
28
|
-
},
|
|
29
|
-
|
|
30
|
-
warn: function(deprecationName) {
|
|
31
|
-
if (!this.disableWarnings && this.deprecationWarningMap[deprecationName]) {
|
|
32
|
-
console.warn('DEPRECATION WARNING: ' + this.deprecationWarningMap[deprecationName]);
|
|
33
|
-
this.deprecationWarningMap[deprecationName] = false;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
Deprecation_1 = Deprecation;
|
|
39
|
-
return Deprecation_1;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export { requireDeprecation as __require };
|
|
@@ -1,268 +0,0 @@
|
|
|
1
|
-
import { __require as requireWebSocketClient } from './WebSocketClient.js';
|
|
2
|
-
import { __require as requireTypedarrayToBuffer } from '../../typedarray-to-buffer/index.js';
|
|
3
|
-
import { __require as requireYaeti } from '../../yaeti/index.js';
|
|
4
|
-
|
|
5
|
-
/************************************************************************
|
|
6
|
-
* Copyright 2010-2015 Brian McKelvey.
|
|
7
|
-
*
|
|
8
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
|
-
* you may not use this file except in compliance with the License.
|
|
10
|
-
* You may obtain a copy of the License at
|
|
11
|
-
*
|
|
12
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
13
|
-
*
|
|
14
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
15
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
16
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17
|
-
* See the License for the specific language governing permissions and
|
|
18
|
-
* limitations under the License.
|
|
19
|
-
***********************************************************************/
|
|
20
|
-
|
|
21
|
-
var W3CWebSocket_1;
|
|
22
|
-
var hasRequiredW3CWebSocket;
|
|
23
|
-
|
|
24
|
-
function requireW3CWebSocket () {
|
|
25
|
-
if (hasRequiredW3CWebSocket) return W3CWebSocket_1;
|
|
26
|
-
hasRequiredW3CWebSocket = 1;
|
|
27
|
-
var WebSocketClient = requireWebSocketClient();
|
|
28
|
-
var toBuffer = requireTypedarrayToBuffer();
|
|
29
|
-
var yaeti = requireYaeti();
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const CONNECTING = 0;
|
|
33
|
-
const OPEN = 1;
|
|
34
|
-
const CLOSING = 2;
|
|
35
|
-
const CLOSED = 3;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
W3CWebSocket_1 = W3CWebSocket;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
function W3CWebSocket(url, protocols, origin, headers, requestOptions, clientConfig) {
|
|
42
|
-
// Make this an EventTarget.
|
|
43
|
-
yaeti.EventTarget.call(this);
|
|
44
|
-
|
|
45
|
-
// Sanitize clientConfig.
|
|
46
|
-
clientConfig = clientConfig || {};
|
|
47
|
-
clientConfig.assembleFragments = true; // Required in the W3C API.
|
|
48
|
-
|
|
49
|
-
var self = this;
|
|
50
|
-
|
|
51
|
-
this._url = url;
|
|
52
|
-
this._readyState = CONNECTING;
|
|
53
|
-
this._protocol = undefined;
|
|
54
|
-
this._extensions = '';
|
|
55
|
-
this._bufferedAmount = 0; // Hack, always 0.
|
|
56
|
-
this._binaryType = 'arraybuffer'; // TODO: Should be 'blob' by default, but Node has no Blob.
|
|
57
|
-
|
|
58
|
-
// The WebSocketConnection instance.
|
|
59
|
-
this._connection = undefined;
|
|
60
|
-
|
|
61
|
-
// WebSocketClient instance.
|
|
62
|
-
this._client = new WebSocketClient(clientConfig);
|
|
63
|
-
|
|
64
|
-
this._client.on('connect', function(connection) {
|
|
65
|
-
onConnect.call(self, connection);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
this._client.on('connectFailed', function() {
|
|
69
|
-
onConnectFailed.call(self);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
this._client.connect(url, protocols, origin, headers, requestOptions);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
// Expose W3C read only attributes.
|
|
77
|
-
Object.defineProperties(W3CWebSocket.prototype, {
|
|
78
|
-
url: { get: function() { return this._url; } },
|
|
79
|
-
readyState: { get: function() { return this._readyState; } },
|
|
80
|
-
protocol: { get: function() { return this._protocol; } },
|
|
81
|
-
extensions: { get: function() { return this._extensions; } },
|
|
82
|
-
bufferedAmount: { get: function() { return this._bufferedAmount; } }
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
// Expose W3C write/read attributes.
|
|
87
|
-
Object.defineProperties(W3CWebSocket.prototype, {
|
|
88
|
-
binaryType: {
|
|
89
|
-
get: function() {
|
|
90
|
-
return this._binaryType;
|
|
91
|
-
},
|
|
92
|
-
set: function(type) {
|
|
93
|
-
// TODO: Just 'arraybuffer' supported.
|
|
94
|
-
if (type !== 'arraybuffer') {
|
|
95
|
-
throw new SyntaxError('just "arraybuffer" type allowed for "binaryType" attribute');
|
|
96
|
-
}
|
|
97
|
-
this._binaryType = type;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
// Expose W3C readyState constants into the WebSocket instance as W3C states.
|
|
104
|
-
[['CONNECTING',CONNECTING], ['OPEN',OPEN], ['CLOSING',CLOSING], ['CLOSED',CLOSED]].forEach(function(property) {
|
|
105
|
-
Object.defineProperty(W3CWebSocket.prototype, property[0], {
|
|
106
|
-
get: function() { return property[1]; }
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
// Also expose W3C readyState constants into the WebSocket class (not defined by the W3C,
|
|
111
|
-
// but there are so many libs relying on them).
|
|
112
|
-
[['CONNECTING',CONNECTING], ['OPEN',OPEN], ['CLOSING',CLOSING], ['CLOSED',CLOSED]].forEach(function(property) {
|
|
113
|
-
Object.defineProperty(W3CWebSocket, property[0], {
|
|
114
|
-
get: function() { return property[1]; }
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
W3CWebSocket.prototype.send = function(data) {
|
|
120
|
-
if (this._readyState !== OPEN) {
|
|
121
|
-
throw new Error('cannot call send() while not connected');
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// Text.
|
|
125
|
-
if (typeof data === 'string' || data instanceof String) {
|
|
126
|
-
this._connection.sendUTF(data);
|
|
127
|
-
}
|
|
128
|
-
// Binary.
|
|
129
|
-
else {
|
|
130
|
-
// Node Buffer.
|
|
131
|
-
if (data instanceof Buffer) {
|
|
132
|
-
this._connection.sendBytes(data);
|
|
133
|
-
}
|
|
134
|
-
// If ArrayBuffer or ArrayBufferView convert it to Node Buffer.
|
|
135
|
-
else if (data.byteLength || data.byteLength === 0) {
|
|
136
|
-
data = toBuffer(data);
|
|
137
|
-
this._connection.sendBytes(data);
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
throw new Error('unknown binary data:', data);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
W3CWebSocket.prototype.close = function(code, reason) {
|
|
147
|
-
switch(this._readyState) {
|
|
148
|
-
case CONNECTING:
|
|
149
|
-
// NOTE: We don't have the WebSocketConnection instance yet so no
|
|
150
|
-
// way to close the TCP connection.
|
|
151
|
-
// Artificially invoke the onConnectFailed event.
|
|
152
|
-
onConnectFailed.call(this);
|
|
153
|
-
// And close if it connects after a while.
|
|
154
|
-
this._client.on('connect', function(connection) {
|
|
155
|
-
if (code) {
|
|
156
|
-
connection.close(code, reason);
|
|
157
|
-
} else {
|
|
158
|
-
connection.close();
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
break;
|
|
162
|
-
case OPEN:
|
|
163
|
-
this._readyState = CLOSING;
|
|
164
|
-
if (code) {
|
|
165
|
-
this._connection.close(code, reason);
|
|
166
|
-
} else {
|
|
167
|
-
this._connection.close();
|
|
168
|
-
}
|
|
169
|
-
break;
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* Private API.
|
|
176
|
-
*/
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
function createCloseEvent(code, reason) {
|
|
180
|
-
var event = new yaeti.Event('close');
|
|
181
|
-
|
|
182
|
-
event.code = code;
|
|
183
|
-
event.reason = reason;
|
|
184
|
-
event.wasClean = (typeof code === 'undefined' || code === 1000);
|
|
185
|
-
|
|
186
|
-
return event;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
function createMessageEvent(data) {
|
|
191
|
-
var event = new yaeti.Event('message');
|
|
192
|
-
|
|
193
|
-
event.data = data;
|
|
194
|
-
|
|
195
|
-
return event;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
function onConnect(connection) {
|
|
200
|
-
var self = this;
|
|
201
|
-
|
|
202
|
-
this._readyState = OPEN;
|
|
203
|
-
this._connection = connection;
|
|
204
|
-
this._protocol = connection.protocol;
|
|
205
|
-
this._extensions = connection.extensions;
|
|
206
|
-
|
|
207
|
-
this._connection.on('close', function(code, reason) {
|
|
208
|
-
onClose.call(self, code, reason);
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
this._connection.on('message', function(msg) {
|
|
212
|
-
onMessage.call(self, msg);
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
this.dispatchEvent(new yaeti.Event('open'));
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
function onConnectFailed() {
|
|
220
|
-
destroy.call(this);
|
|
221
|
-
this._readyState = CLOSED;
|
|
222
|
-
|
|
223
|
-
try {
|
|
224
|
-
this.dispatchEvent(new yaeti.Event('error'));
|
|
225
|
-
} finally {
|
|
226
|
-
this.dispatchEvent(createCloseEvent(1006, 'connection failed'));
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
function onClose(code, reason) {
|
|
232
|
-
destroy.call(this);
|
|
233
|
-
this._readyState = CLOSED;
|
|
234
|
-
|
|
235
|
-
this.dispatchEvent(createCloseEvent(code, reason || ''));
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
function onMessage(message) {
|
|
240
|
-
if (message.utf8Data) {
|
|
241
|
-
this.dispatchEvent(createMessageEvent(message.utf8Data));
|
|
242
|
-
}
|
|
243
|
-
else if (message.binaryData) {
|
|
244
|
-
// Must convert from Node Buffer to ArrayBuffer.
|
|
245
|
-
// TODO: or to a Blob (which does not exist in Node!).
|
|
246
|
-
if (this.binaryType === 'arraybuffer') {
|
|
247
|
-
var buffer = message.binaryData;
|
|
248
|
-
var arraybuffer = new ArrayBuffer(buffer.length);
|
|
249
|
-
var view = new Uint8Array(arraybuffer);
|
|
250
|
-
for (var i=0, len=buffer.length; i<len; ++i) {
|
|
251
|
-
view[i] = buffer[i];
|
|
252
|
-
}
|
|
253
|
-
this.dispatchEvent(createMessageEvent(arraybuffer));
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
function destroy() {
|
|
260
|
-
this._client.removeAllListeners();
|
|
261
|
-
if (this._connection) {
|
|
262
|
-
this._connection.removeAllListeners();
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
return W3CWebSocket_1;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
export { requireW3CWebSocket as __require };
|
|
@@ -1,380 +0,0 @@
|
|
|
1
|
-
import { __require as requireUtils } from './utils.js';
|
|
2
|
-
import require$$1$1 from 'util';
|
|
3
|
-
import require$$1 from 'events';
|
|
4
|
-
import require$$3 from 'http';
|
|
5
|
-
import require$$4 from 'https';
|
|
6
|
-
import require$$2 from 'url';
|
|
7
|
-
import require$$0 from 'crypto';
|
|
8
|
-
import { __require as requireWebSocketConnection } from './WebSocketConnection.js';
|
|
9
|
-
|
|
10
|
-
/************************************************************************
|
|
11
|
-
* Copyright 2010-2015 Brian McKelvey.
|
|
12
|
-
*
|
|
13
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
14
|
-
* you may not use this file except in compliance with the License.
|
|
15
|
-
* You may obtain a copy of the License at
|
|
16
|
-
*
|
|
17
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
18
|
-
*
|
|
19
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
20
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
21
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
22
|
-
* See the License for the specific language governing permissions and
|
|
23
|
-
* limitations under the License.
|
|
24
|
-
***********************************************************************/
|
|
25
|
-
|
|
26
|
-
var WebSocketClient_1;
|
|
27
|
-
var hasRequiredWebSocketClient;
|
|
28
|
-
|
|
29
|
-
function requireWebSocketClient () {
|
|
30
|
-
if (hasRequiredWebSocketClient) return WebSocketClient_1;
|
|
31
|
-
hasRequiredWebSocketClient = 1;
|
|
32
|
-
var utils = requireUtils();
|
|
33
|
-
var extend = utils.extend;
|
|
34
|
-
var util = require$$1$1;
|
|
35
|
-
var EventEmitter = require$$1.EventEmitter;
|
|
36
|
-
var http = require$$3;
|
|
37
|
-
var https = require$$4;
|
|
38
|
-
var url = require$$2;
|
|
39
|
-
var crypto = require$$0;
|
|
40
|
-
var WebSocketConnection = requireWebSocketConnection();
|
|
41
|
-
var bufferAllocUnsafe = utils.bufferAllocUnsafe;
|
|
42
|
-
|
|
43
|
-
var protocolSeparators = [
|
|
44
|
-
'(', ')', '<', '>', '@',
|
|
45
|
-
',', ';', ':', '\\', '\"',
|
|
46
|
-
'/', '[', ']', '?', '=',
|
|
47
|
-
'{', '}', ' ', String.fromCharCode(9)
|
|
48
|
-
];
|
|
49
|
-
|
|
50
|
-
var excludedTlsOptions = ['hostname','port','method','path','headers'];
|
|
51
|
-
|
|
52
|
-
function WebSocketClient(config) {
|
|
53
|
-
// Superclass Constructor
|
|
54
|
-
EventEmitter.call(this);
|
|
55
|
-
|
|
56
|
-
// TODO: Implement extensions
|
|
57
|
-
|
|
58
|
-
this.config = {
|
|
59
|
-
// 1MiB max frame size.
|
|
60
|
-
maxReceivedFrameSize: 0x100000,
|
|
61
|
-
|
|
62
|
-
// 8MiB max message size, only applicable if
|
|
63
|
-
// assembleFragments is true
|
|
64
|
-
maxReceivedMessageSize: 0x800000,
|
|
65
|
-
|
|
66
|
-
// Outgoing messages larger than fragmentationThreshold will be
|
|
67
|
-
// split into multiple fragments.
|
|
68
|
-
fragmentOutgoingMessages: true,
|
|
69
|
-
|
|
70
|
-
// Outgoing frames are fragmented if they exceed this threshold.
|
|
71
|
-
// Default is 16KiB
|
|
72
|
-
fragmentationThreshold: 0x4000,
|
|
73
|
-
|
|
74
|
-
// Which version of the protocol to use for this session. This
|
|
75
|
-
// option will be removed once the protocol is finalized by the IETF
|
|
76
|
-
// It is only available to ease the transition through the
|
|
77
|
-
// intermediate draft protocol versions.
|
|
78
|
-
// At present, it only affects the name of the Origin header.
|
|
79
|
-
webSocketVersion: 13,
|
|
80
|
-
|
|
81
|
-
// If true, fragmented messages will be automatically assembled
|
|
82
|
-
// and the full message will be emitted via a 'message' event.
|
|
83
|
-
// If false, each frame will be emitted via a 'frame' event and
|
|
84
|
-
// the application will be responsible for aggregating multiple
|
|
85
|
-
// fragmented frames. Single-frame messages will emit a 'message'
|
|
86
|
-
// event in addition to the 'frame' event.
|
|
87
|
-
// Most users will want to leave this set to 'true'
|
|
88
|
-
assembleFragments: true,
|
|
89
|
-
|
|
90
|
-
// The Nagle Algorithm makes more efficient use of network resources
|
|
91
|
-
// by introducing a small delay before sending small packets so that
|
|
92
|
-
// multiple messages can be batched together before going onto the
|
|
93
|
-
// wire. This however comes at the cost of latency, so the default
|
|
94
|
-
// is to disable it. If you don't need low latency and are streaming
|
|
95
|
-
// lots of small messages, you can change this to 'false'
|
|
96
|
-
disableNagleAlgorithm: true,
|
|
97
|
-
|
|
98
|
-
// The number of milliseconds to wait after sending a close frame
|
|
99
|
-
// for an acknowledgement to come back before giving up and just
|
|
100
|
-
// closing the socket.
|
|
101
|
-
closeTimeout: 5000,
|
|
102
|
-
|
|
103
|
-
// Options to pass to https.connect if connecting via TLS
|
|
104
|
-
tlsOptions: {}
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
if (config) {
|
|
108
|
-
var tlsOptions;
|
|
109
|
-
if (config.tlsOptions) {
|
|
110
|
-
tlsOptions = config.tlsOptions;
|
|
111
|
-
delete config.tlsOptions;
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
tlsOptions = {};
|
|
115
|
-
}
|
|
116
|
-
extend(this.config, config);
|
|
117
|
-
extend(this.config.tlsOptions, tlsOptions);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
this._req = null;
|
|
121
|
-
|
|
122
|
-
switch (this.config.webSocketVersion) {
|
|
123
|
-
case 8:
|
|
124
|
-
case 13:
|
|
125
|
-
break;
|
|
126
|
-
default:
|
|
127
|
-
throw new Error('Requested webSocketVersion is not supported. Allowed values are 8 and 13.');
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
util.inherits(WebSocketClient, EventEmitter);
|
|
132
|
-
|
|
133
|
-
WebSocketClient.prototype.connect = function(requestUrl, protocols, origin, headers, extraRequestOptions) {
|
|
134
|
-
var self = this;
|
|
135
|
-
|
|
136
|
-
if (typeof(protocols) === 'string') {
|
|
137
|
-
if (protocols.length > 0) {
|
|
138
|
-
protocols = [protocols];
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
protocols = [];
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
if (!(protocols instanceof Array)) {
|
|
145
|
-
protocols = [];
|
|
146
|
-
}
|
|
147
|
-
this.protocols = protocols;
|
|
148
|
-
this.origin = origin;
|
|
149
|
-
|
|
150
|
-
if (typeof(requestUrl) === 'string') {
|
|
151
|
-
this.url = url.parse(requestUrl);
|
|
152
|
-
}
|
|
153
|
-
else {
|
|
154
|
-
this.url = requestUrl; // in case an already parsed url is passed in.
|
|
155
|
-
}
|
|
156
|
-
if (!this.url.protocol) {
|
|
157
|
-
throw new Error('You must specify a full WebSocket URL, including protocol.');
|
|
158
|
-
}
|
|
159
|
-
if (!this.url.host) {
|
|
160
|
-
throw new Error('You must specify a full WebSocket URL, including hostname. Relative URLs are not supported.');
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
this.secure = (this.url.protocol === 'wss:');
|
|
164
|
-
|
|
165
|
-
// validate protocol characters:
|
|
166
|
-
this.protocols.forEach(function(protocol) {
|
|
167
|
-
for (var i=0; i < protocol.length; i ++) {
|
|
168
|
-
var charCode = protocol.charCodeAt(i);
|
|
169
|
-
var character = protocol.charAt(i);
|
|
170
|
-
if (charCode < 0x0021 || charCode > 0x007E || protocolSeparators.indexOf(character) !== -1) {
|
|
171
|
-
throw new Error('Protocol list contains invalid character "' + String.fromCharCode(charCode) + '"');
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
var defaultPorts = {
|
|
177
|
-
'ws:': '80',
|
|
178
|
-
'wss:': '443'
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
if (!this.url.port) {
|
|
182
|
-
this.url.port = defaultPorts[this.url.protocol];
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
var nonce = bufferAllocUnsafe(16);
|
|
186
|
-
for (var i=0; i < 16; i++) {
|
|
187
|
-
nonce[i] = Math.round(Math.random()*0xFF);
|
|
188
|
-
}
|
|
189
|
-
this.base64nonce = nonce.toString('base64');
|
|
190
|
-
|
|
191
|
-
var hostHeaderValue = this.url.hostname;
|
|
192
|
-
if ((this.url.protocol === 'ws:' && this.url.port !== '80') ||
|
|
193
|
-
(this.url.protocol === 'wss:' && this.url.port !== '443')) {
|
|
194
|
-
hostHeaderValue += (':' + this.url.port);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
var reqHeaders = {};
|
|
198
|
-
if (this.secure && this.config.tlsOptions.hasOwnProperty('headers')) {
|
|
199
|
-
// Allow for additional headers to be provided when connecting via HTTPS
|
|
200
|
-
extend(reqHeaders, this.config.tlsOptions.headers);
|
|
201
|
-
}
|
|
202
|
-
if (headers) {
|
|
203
|
-
// Explicitly provided headers take priority over any from tlsOptions
|
|
204
|
-
extend(reqHeaders, headers);
|
|
205
|
-
}
|
|
206
|
-
extend(reqHeaders, {
|
|
207
|
-
'Upgrade': 'websocket',
|
|
208
|
-
'Connection': 'Upgrade',
|
|
209
|
-
'Sec-WebSocket-Version': this.config.webSocketVersion.toString(10),
|
|
210
|
-
'Sec-WebSocket-Key': this.base64nonce,
|
|
211
|
-
'Host': reqHeaders.Host || hostHeaderValue
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
if (this.protocols.length > 0) {
|
|
215
|
-
reqHeaders['Sec-WebSocket-Protocol'] = this.protocols.join(', ');
|
|
216
|
-
}
|
|
217
|
-
if (this.origin) {
|
|
218
|
-
if (this.config.webSocketVersion === 13) {
|
|
219
|
-
reqHeaders['Origin'] = this.origin;
|
|
220
|
-
}
|
|
221
|
-
else if (this.config.webSocketVersion === 8) {
|
|
222
|
-
reqHeaders['Sec-WebSocket-Origin'] = this.origin;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
// TODO: Implement extensions
|
|
227
|
-
|
|
228
|
-
var pathAndQuery;
|
|
229
|
-
// Ensure it begins with '/'.
|
|
230
|
-
if (this.url.pathname) {
|
|
231
|
-
pathAndQuery = this.url.path;
|
|
232
|
-
}
|
|
233
|
-
else if (this.url.path) {
|
|
234
|
-
pathAndQuery = '/' + this.url.path;
|
|
235
|
-
}
|
|
236
|
-
else {
|
|
237
|
-
pathAndQuery = '/';
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
function handleRequestError(error) {
|
|
241
|
-
self._req = null;
|
|
242
|
-
self.emit('connectFailed', error);
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
var requestOptions = {
|
|
246
|
-
agent: false
|
|
247
|
-
};
|
|
248
|
-
if (extraRequestOptions) {
|
|
249
|
-
extend(requestOptions, extraRequestOptions);
|
|
250
|
-
}
|
|
251
|
-
// These options are always overridden by the library. The user is not
|
|
252
|
-
// allowed to specify these directly.
|
|
253
|
-
extend(requestOptions, {
|
|
254
|
-
hostname: this.url.hostname,
|
|
255
|
-
port: this.url.port,
|
|
256
|
-
method: 'GET',
|
|
257
|
-
path: pathAndQuery,
|
|
258
|
-
headers: reqHeaders
|
|
259
|
-
});
|
|
260
|
-
if (this.secure) {
|
|
261
|
-
var tlsOptions = this.config.tlsOptions;
|
|
262
|
-
for (var key in tlsOptions) {
|
|
263
|
-
if (tlsOptions.hasOwnProperty(key) && excludedTlsOptions.indexOf(key) === -1) {
|
|
264
|
-
requestOptions[key] = tlsOptions[key];
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
var req = this._req = (this.secure ? https : http).request(requestOptions);
|
|
270
|
-
req.on('upgrade', function handleRequestUpgrade(response, socket, head) {
|
|
271
|
-
self._req = null;
|
|
272
|
-
req.removeListener('error', handleRequestError);
|
|
273
|
-
self.socket = socket;
|
|
274
|
-
self.response = response;
|
|
275
|
-
self.firstDataChunk = head;
|
|
276
|
-
self.validateHandshake();
|
|
277
|
-
});
|
|
278
|
-
req.on('error', handleRequestError);
|
|
279
|
-
|
|
280
|
-
req.on('response', function(response) {
|
|
281
|
-
self._req = null;
|
|
282
|
-
if (utils.eventEmitterListenerCount(self, 'httpResponse') > 0) {
|
|
283
|
-
self.emit('httpResponse', response, self);
|
|
284
|
-
if (response.socket) {
|
|
285
|
-
response.socket.end();
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
else {
|
|
289
|
-
var headerDumpParts = [];
|
|
290
|
-
for (var headerName in response.headers) {
|
|
291
|
-
headerDumpParts.push(headerName + ': ' + response.headers[headerName]);
|
|
292
|
-
}
|
|
293
|
-
self.failHandshake(
|
|
294
|
-
'Server responded with a non-101 status: ' +
|
|
295
|
-
response.statusCode + ' ' + response.statusMessage +
|
|
296
|
-
'\nResponse Headers Follow:\n' +
|
|
297
|
-
headerDumpParts.join('\n') + '\n'
|
|
298
|
-
);
|
|
299
|
-
}
|
|
300
|
-
});
|
|
301
|
-
req.end();
|
|
302
|
-
};
|
|
303
|
-
|
|
304
|
-
WebSocketClient.prototype.validateHandshake = function() {
|
|
305
|
-
var headers = this.response.headers;
|
|
306
|
-
|
|
307
|
-
if (this.protocols.length > 0) {
|
|
308
|
-
this.protocol = headers['sec-websocket-protocol'];
|
|
309
|
-
if (this.protocol) {
|
|
310
|
-
if (this.protocols.indexOf(this.protocol) === -1) {
|
|
311
|
-
this.failHandshake('Server did not respond with a requested protocol.');
|
|
312
|
-
return;
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
else {
|
|
316
|
-
this.failHandshake('Expected a Sec-WebSocket-Protocol header.');
|
|
317
|
-
return;
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
if (!(headers['connection'] && headers['connection'].toLocaleLowerCase() === 'upgrade')) {
|
|
322
|
-
this.failHandshake('Expected a Connection: Upgrade header from the server');
|
|
323
|
-
return;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
if (!(headers['upgrade'] && headers['upgrade'].toLocaleLowerCase() === 'websocket')) {
|
|
327
|
-
this.failHandshake('Expected an Upgrade: websocket header from the server');
|
|
328
|
-
return;
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
var sha1 = crypto.createHash('sha1');
|
|
332
|
-
sha1.update(this.base64nonce + '258EAFA5-E914-47DA-95CA-C5AB0DC85B11');
|
|
333
|
-
var expectedKey = sha1.digest('base64');
|
|
334
|
-
|
|
335
|
-
if (!headers['sec-websocket-accept']) {
|
|
336
|
-
this.failHandshake('Expected Sec-WebSocket-Accept header from server');
|
|
337
|
-
return;
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
if (headers['sec-websocket-accept'] !== expectedKey) {
|
|
341
|
-
this.failHandshake('Sec-WebSocket-Accept header from server didn\'t match expected value of ' + expectedKey);
|
|
342
|
-
return;
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
// TODO: Support extensions
|
|
346
|
-
|
|
347
|
-
this.succeedHandshake();
|
|
348
|
-
};
|
|
349
|
-
|
|
350
|
-
WebSocketClient.prototype.failHandshake = function(errorDescription) {
|
|
351
|
-
if (this.socket && this.socket.writable) {
|
|
352
|
-
this.socket.end();
|
|
353
|
-
}
|
|
354
|
-
this.emit('connectFailed', new Error(errorDescription));
|
|
355
|
-
};
|
|
356
|
-
|
|
357
|
-
WebSocketClient.prototype.succeedHandshake = function() {
|
|
358
|
-
var connection = new WebSocketConnection(this.socket, [], this.protocol, true, this.config);
|
|
359
|
-
|
|
360
|
-
connection.webSocketVersion = this.config.webSocketVersion;
|
|
361
|
-
connection._addSocketEventListeners();
|
|
362
|
-
|
|
363
|
-
this.emit('connect', connection);
|
|
364
|
-
if (this.firstDataChunk.length > 0) {
|
|
365
|
-
connection.handleSocketData(this.firstDataChunk);
|
|
366
|
-
}
|
|
367
|
-
this.firstDataChunk = null;
|
|
368
|
-
};
|
|
369
|
-
|
|
370
|
-
WebSocketClient.prototype.abort = function() {
|
|
371
|
-
if (this._req) {
|
|
372
|
-
this._req.abort();
|
|
373
|
-
}
|
|
374
|
-
};
|
|
375
|
-
|
|
376
|
-
WebSocketClient_1 = WebSocketClient;
|
|
377
|
-
return WebSocketClient_1;
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
export { requireWebSocketClient as __require };
|