zmdms-utils 0.0.80 → 0.0.81

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.
Files changed (165) hide show
  1. package/declarations.d.ts +6 -0
  2. package/dist/es/_virtual/FastBufferList.js +7 -0
  3. package/dist/es/_virtual/_commonjs-dynamic-modules.js +5 -0
  4. package/dist/es/_virtual/browser.js +7 -0
  5. package/dist/es/_virtual/browser2.js +7 -0
  6. package/dist/es/_virtual/debug.js +7 -0
  7. package/dist/es/_virtual/event.js +7 -0
  8. package/dist/es/_virtual/http-parser.js +3 -0
  9. package/dist/es/_virtual/iframe.js +7 -0
  10. package/dist/es/_virtual/index.js +7 -0
  11. package/dist/es/_virtual/index2.js +7 -0
  12. package/dist/es/_virtual/index3.js +7 -0
  13. package/dist/es/_virtual/index4.js +7 -0
  14. package/dist/es/_virtual/index5.js +7 -0
  15. package/dist/es/_virtual/index6.js +7 -0
  16. package/dist/es/_virtual/index7.js +3 -0
  17. package/dist/es/_virtual/index8.js +7 -0
  18. package/dist/es/_virtual/index9.js +7 -0
  19. package/dist/es/_virtual/inherits.js +7 -0
  20. package/dist/es/_virtual/inherits_browser.js +7 -0
  21. package/dist/es/_virtual/json3.js +7 -0
  22. package/dist/es/_virtual/node.js +7 -0
  23. package/dist/es/_virtual/node2.js +7 -0
  24. package/dist/es/_virtual/stomp-node.js +3 -0
  25. package/dist/es/_virtual/stomp.js +3 -0
  26. package/dist/es/_virtual/streams.js +3 -0
  27. package/dist/es/_virtual/utils.js +3 -0
  28. package/dist/es/constants.d.ts +5 -1
  29. package/dist/es/constants.js +5 -1
  30. package/dist/es/node_modules/bufferutil/fallback.js +43 -0
  31. package/dist/es/node_modules/bufferutil/index.js +21 -0
  32. package/dist/es/node_modules/debug/src/browser.js +192 -0
  33. package/dist/es/node_modules/debug/src/common.js +259 -0
  34. package/dist/es/node_modules/debug/src/index.js +25 -0
  35. package/dist/es/node_modules/debug/src/node.js +192 -0
  36. package/dist/es/node_modules/eventsource/lib/eventsource.js +493 -0
  37. package/dist/es/node_modules/faye-websocket/lib/faye/eventsource.js +150 -0
  38. package/dist/es/node_modules/faye-websocket/lib/faye/websocket/api/event.js +31 -0
  39. package/dist/es/node_modules/faye-websocket/lib/faye/websocket/api/event_target.js +41 -0
  40. package/dist/es/node_modules/faye-websocket/lib/faye/websocket/api.js +205 -0
  41. package/dist/es/node_modules/faye-websocket/lib/faye/websocket/client.js +107 -0
  42. package/dist/es/node_modules/faye-websocket/lib/faye/websocket.js +47 -0
  43. package/dist/es/node_modules/has-flag/index.js +17 -0
  44. package/dist/es/node_modules/http-parser-js/http-parser.js +471 -0
  45. package/dist/es/node_modules/inherits/inherits.js +14 -0
  46. package/dist/es/node_modules/inherits/inherits_browser.js +38 -0
  47. package/dist/es/node_modules/is-typedarray/index.js +51 -0
  48. package/dist/es/node_modules/json3/lib/json3.js +937 -0
  49. package/dist/es/node_modules/ms/index.js +172 -0
  50. package/dist/es/node_modules/node-gyp-build/index.js +21 -0
  51. package/dist/es/node_modules/node-gyp-build/node-gyp-build.js +222 -0
  52. package/dist/es/node_modules/querystringify/index.js +120 -0
  53. package/dist/es/node_modules/requires-port/index.js +38 -0
  54. package/dist/es/node_modules/safe-buffer/index.js +71 -0
  55. package/dist/es/node_modules/supports-color/index.js +143 -0
  56. package/dist/es/node_modules/typedarray-to-buffer/index.js +37 -0
  57. package/dist/es/node_modules/url-parse/index.js +594 -0
  58. package/dist/es/node_modules/utf-8-validate/fallback.js +71 -0
  59. package/dist/es/node_modules/utf-8-validate/index.js +21 -0
  60. package/dist/es/node_modules/websocket/index.js +15 -0
  61. package/dist/es/node_modules/websocket/lib/Deprecation.js +42 -0
  62. package/dist/es/node_modules/websocket/lib/W3CWebSocket.js +268 -0
  63. package/dist/es/node_modules/websocket/lib/WebSocketClient.js +380 -0
  64. package/dist/es/node_modules/websocket/lib/WebSocketConnection.js +914 -0
  65. package/dist/es/node_modules/websocket/lib/WebSocketFrame.js +293 -0
  66. package/dist/es/node_modules/websocket/lib/WebSocketRequest.js +543 -0
  67. package/dist/es/node_modules/websocket/lib/WebSocketRouter.js +172 -0
  68. package/dist/es/node_modules/websocket/lib/WebSocketRouterRequest.js +67 -0
  69. package/dist/es/node_modules/websocket/lib/WebSocketServer.js +272 -0
  70. package/dist/es/node_modules/websocket/lib/utils.js +80 -0
  71. package/dist/es/node_modules/websocket/lib/version.js +13 -0
  72. package/dist/es/node_modules/websocket/lib/websocket.js +31 -0
  73. package/dist/es/node_modules/websocket/node_modules/debug/src/browser.js +199 -0
  74. package/dist/es/node_modules/websocket/node_modules/debug/src/debug.js +215 -0
  75. package/dist/es/node_modules/websocket/node_modules/debug/src/index.js +25 -0
  76. package/dist/es/node_modules/websocket/node_modules/debug/src/node.js +266 -0
  77. package/dist/es/node_modules/websocket/node_modules/ms/index.js +162 -0
  78. package/dist/es/node_modules/websocket/package.json.js +77 -0
  79. package/dist/es/node_modules/websocket/vendor/FastBufferList.js +205 -0
  80. package/dist/es/node_modules/websocket-driver/lib/websocket/driver/base.js +202 -0
  81. package/dist/es/node_modules/websocket-driver/lib/websocket/driver/client.js +152 -0
  82. package/dist/es/node_modules/websocket-driver/lib/websocket/driver/draft75.js +128 -0
  83. package/dist/es/node_modules/websocket-driver/lib/websocket/driver/draft76.js +124 -0
  84. package/dist/es/node_modules/websocket-driver/lib/websocket/driver/headers.js +44 -0
  85. package/dist/es/node_modules/websocket-driver/lib/websocket/driver/hybi/frame.js +21 -0
  86. package/dist/es/node_modules/websocket-driver/lib/websocket/driver/hybi/message.js +37 -0
  87. package/dist/es/node_modules/websocket-driver/lib/websocket/driver/hybi.js +492 -0
  88. package/dist/es/node_modules/websocket-driver/lib/websocket/driver/proxy.js +108 -0
  89. package/dist/es/node_modules/websocket-driver/lib/websocket/driver/server.js +119 -0
  90. package/dist/es/node_modules/websocket-driver/lib/websocket/driver/stream_reader.js +72 -0
  91. package/dist/es/node_modules/websocket-driver/lib/websocket/driver.js +47 -0
  92. package/dist/es/node_modules/websocket-driver/lib/websocket/http_parser.js +140 -0
  93. package/dist/es/node_modules/websocket-driver/lib/websocket/streams.js +150 -0
  94. package/dist/es/node_modules/websocket-extensions/lib/parser.js +103 -0
  95. package/dist/es/node_modules/websocket-extensions/lib/pipeline/cell.js +56 -0
  96. package/dist/es/node_modules/websocket-extensions/lib/pipeline/functor.js +74 -0
  97. package/dist/es/node_modules/websocket-extensions/lib/pipeline/index.js +50 -0
  98. package/dist/es/node_modules/websocket-extensions/lib/pipeline/pledge.js +39 -0
  99. package/dist/es/node_modules/websocket-extensions/lib/pipeline/ring_buffer.js +66 -0
  100. package/dist/es/node_modules/websocket-extensions/lib/websocket_extensions.js +165 -0
  101. package/dist/es/node_modules/yaeti/index.js +17 -0
  102. package/dist/es/node_modules/yaeti/lib/Event.js +24 -0
  103. package/dist/es/node_modules/yaeti/lib/EventTarget.js +130 -0
  104. package/dist/es/node_modules/zt-sockjs-client/lib/entry.js +14 -0
  105. package/dist/es/node_modules/zt-sockjs-client/lib/event/close.js +21 -0
  106. package/dist/es/node_modules/zt-sockjs-client/lib/event/event.js +22 -0
  107. package/dist/es/node_modules/zt-sockjs-client/lib/event/eventtarget.js +62 -0
  108. package/dist/es/node_modules/zt-sockjs-client/lib/event/trans-message.js +19 -0
  109. package/dist/es/node_modules/zt-sockjs-client/lib/facade.js +40 -0
  110. package/dist/es/node_modules/zt-sockjs-client/lib/iframe-bootstrap.js +122 -0
  111. package/dist/es/node_modules/zt-sockjs-client/lib/info-ajax.js +57 -0
  112. package/dist/es/node_modules/zt-sockjs-client/lib/info-iframe-receiver.js +50 -0
  113. package/dist/es/node_modules/zt-sockjs-client/lib/info-iframe.js +81 -0
  114. package/dist/es/node_modules/zt-sockjs-client/lib/info-receiver.js +101 -0
  115. package/dist/es/node_modules/zt-sockjs-client/lib/location.js +12 -0
  116. package/dist/es/node_modules/zt-sockjs-client/lib/main.js +413 -0
  117. package/dist/es/node_modules/zt-sockjs-client/lib/shims.js +449 -0
  118. package/dist/es/node_modules/zt-sockjs-client/lib/transport/driver/websocket.js +5 -0
  119. package/dist/es/node_modules/zt-sockjs-client/lib/transport/driver/xhr.js +80 -0
  120. package/dist/es/node_modules/zt-sockjs-client/lib/transport/eventsource.js +34 -0
  121. package/dist/es/node_modules/zt-sockjs-client/lib/transport/htmlfile.js +31 -0
  122. package/dist/es/node_modules/zt-sockjs-client/lib/transport/iframe.js +154 -0
  123. package/dist/es/node_modules/zt-sockjs-client/lib/transport/jsonp-polling.js +41 -0
  124. package/dist/es/node_modules/zt-sockjs-client/lib/transport/lib/ajax-based.js +55 -0
  125. package/dist/es/node_modules/zt-sockjs-client/lib/transport/lib/buffered-sender.js +92 -0
  126. package/dist/es/node_modules/zt-sockjs-client/lib/transport/lib/iframe-wrap.js +39 -0
  127. package/dist/es/node_modules/zt-sockjs-client/lib/transport/lib/polling.js +65 -0
  128. package/dist/es/node_modules/zt-sockjs-client/lib/transport/lib/sender-receiver.js +52 -0
  129. package/dist/es/node_modules/zt-sockjs-client/lib/transport/receiver/eventsource.js +69 -0
  130. package/dist/es/node_modules/zt-sockjs-client/lib/transport/receiver/htmlfile.js +96 -0
  131. package/dist/es/node_modules/zt-sockjs-client/lib/transport/receiver/jsonp.js +193 -0
  132. package/dist/es/node_modules/zt-sockjs-client/lib/transport/receiver/xhr.js +75 -0
  133. package/dist/es/node_modules/zt-sockjs-client/lib/transport/sender/jsonp.js +104 -0
  134. package/dist/es/node_modules/zt-sockjs-client/lib/transport/sender/xdr.js +113 -0
  135. package/dist/es/node_modules/zt-sockjs-client/lib/transport/sender/xhr-cors.js +19 -0
  136. package/dist/es/node_modules/zt-sockjs-client/lib/transport/sender/xhr-fake.js +28 -0
  137. package/dist/es/node_modules/zt-sockjs-client/lib/transport/sender/xhr-local.js +21 -0
  138. package/dist/es/node_modules/zt-sockjs-client/lib/transport/websocket.js +108 -0
  139. package/dist/es/node_modules/zt-sockjs-client/lib/transport/xdr-polling.js +30 -0
  140. package/dist/es/node_modules/zt-sockjs-client/lib/transport/xdr-streaming.js +38 -0
  141. package/dist/es/node_modules/zt-sockjs-client/lib/transport/xhr-polling.js +40 -0
  142. package/dist/es/node_modules/zt-sockjs-client/lib/transport/xhr-streaming.js +50 -0
  143. package/dist/es/node_modules/zt-sockjs-client/lib/transport-list.js +28 -0
  144. package/dist/es/node_modules/zt-sockjs-client/lib/utils/browser.js +29 -0
  145. package/dist/es/node_modules/zt-sockjs-client/lib/utils/escape.js +53 -0
  146. package/dist/es/node_modules/zt-sockjs-client/lib/utils/event.js +78 -0
  147. package/dist/es/node_modules/zt-sockjs-client/lib/utils/iframe.js +205 -0
  148. package/dist/es/node_modules/zt-sockjs-client/lib/utils/log.js +20 -0
  149. package/dist/es/node_modules/zt-sockjs-client/lib/utils/object.js +24 -0
  150. package/dist/es/node_modules/zt-sockjs-client/lib/utils/random.js +30 -0
  151. package/dist/es/node_modules/zt-sockjs-client/lib/utils/transport.js +52 -0
  152. package/dist/es/node_modules/zt-sockjs-client/lib/utils/url.js +54 -0
  153. package/dist/es/node_modules/zt-sockjs-client/lib/version.js +11 -0
  154. package/dist/es/node_modules/zt-stompjs/index.js +23 -0
  155. package/dist/es/node_modules/zt-stompjs/lib/stomp-node.js +117 -0
  156. package/dist/es/node_modules/zt-stompjs/lib/stomp.js +536 -0
  157. package/dist/es/stompClient.d.ts +55 -0
  158. package/dist/es/stompClient.js +379 -0
  159. package/dist/index.d.ts +2 -1
  160. package/dist/index.js +2 -1
  161. package/package.json +6 -2
  162. package/src/constants.ts +5 -0
  163. package/src/index.ts +4 -0
  164. package/src/stompClient.ts +449 -0
  165. package/tsconfig.json +1 -1
@@ -0,0 +1,119 @@
1
+ import require$$1 from 'util';
2
+ import http_parser from '../http_parser.js';
3
+ import base from './base.js';
4
+ import draft75 from './draft75.js';
5
+ import draft76 from './draft76.js';
6
+ import hybi from './hybi.js';
7
+
8
+ var util = require$$1,
9
+ HttpParser = http_parser,
10
+ Base = base,
11
+ Draft75 = draft75,
12
+ Draft76 = draft76,
13
+ Hybi = hybi;
14
+
15
+ var Server = function(options) {
16
+ Base.call(this, null, null, options);
17
+ this._http = new HttpParser('request');
18
+ };
19
+ util.inherits(Server, Base);
20
+
21
+ var instance = {
22
+ EVENTS: ['open', 'message', 'error', 'close', 'ping', 'pong'],
23
+
24
+ _bindEventListeners: function() {
25
+ this.messages.on('error', function() {});
26
+ this.on('error', function() {});
27
+ },
28
+
29
+ parse: function(chunk) {
30
+ if (this._delegate) return this._delegate.parse(chunk);
31
+
32
+ this._http.parse(chunk);
33
+ if (!this._http.isComplete()) return;
34
+
35
+ this.method = this._http.method;
36
+ this.url = this._http.url;
37
+ this.headers = this._http.headers;
38
+ this.body = this._http.body;
39
+
40
+ var self = this;
41
+ this._delegate = Server.http(this, this._options);
42
+ this._delegate.messages = this.messages;
43
+ this._delegate.io = this.io;
44
+ this._open();
45
+
46
+ this.EVENTS.forEach(function(event) {
47
+ this._delegate.on(event, function(e) { self.emit(event, e); });
48
+ }, this);
49
+
50
+ this.protocol = this._delegate.protocol;
51
+ this.version = this._delegate.version;
52
+
53
+ this.parse(this._http.body);
54
+ this.emit('connect', new Base.ConnectEvent());
55
+ },
56
+
57
+ _open: function() {
58
+ this.__queue.forEach(function(msg) {
59
+ this._delegate[msg[0]].apply(this._delegate, msg[1]);
60
+ }, this);
61
+ this.__queue = [];
62
+ }
63
+ };
64
+
65
+ ['addExtension', 'setHeader', 'start', 'frame', 'text', 'binary', 'ping', 'close'].forEach(function(method) {
66
+ instance[method] = function() {
67
+ if (this._delegate) {
68
+ return this._delegate[method].apply(this._delegate, arguments);
69
+ } else {
70
+ this.__queue.push([method, arguments]);
71
+ return true;
72
+ }
73
+ };
74
+ });
75
+
76
+ for (var key in instance)
77
+ Server.prototype[key] = instance[key];
78
+
79
+ Server.isSecureRequest = function(request) {
80
+ if (request.connection && request.connection.authorized !== undefined) return true;
81
+ if (request.socket && request.socket.secure) return true;
82
+
83
+ var headers = request.headers;
84
+ if (!headers) return false;
85
+ if (headers['https'] === 'on') return true;
86
+ if (headers['x-forwarded-ssl'] === 'on') return true;
87
+ if (headers['x-forwarded-scheme'] === 'https') return true;
88
+ if (headers['x-forwarded-proto'] === 'https') return true;
89
+
90
+ return false;
91
+ };
92
+
93
+ Server.determineUrl = function(request) {
94
+ var scheme = this.isSecureRequest(request) ? 'wss:' : 'ws:';
95
+ return scheme + '//' + request.headers.host + request.url;
96
+ };
97
+
98
+ Server.http = function(request, options) {
99
+ options = options || {};
100
+ if (options.requireMasking === undefined) options.requireMasking = true;
101
+
102
+ var headers = request.headers,
103
+ version = headers['sec-websocket-version'],
104
+ key = headers['sec-websocket-key'],
105
+ key1 = headers['sec-websocket-key1'],
106
+ key2 = headers['sec-websocket-key2'],
107
+ url = this.determineUrl(request);
108
+
109
+ if (version || key)
110
+ return new Hybi(request, url, options);
111
+ else if (key1 || key2)
112
+ return new Draft76(request, url, options);
113
+ else
114
+ return new Draft75(request, url, options);
115
+ };
116
+
117
+ var server = Server;
118
+
119
+ export { server as default };
@@ -0,0 +1,72 @@
1
+ import '../../../../safe-buffer/index.js';
2
+ import { exports as safeBufferExports } from '../../../../../_virtual/index9.js';
3
+
4
+ var Buffer = safeBufferExports.Buffer;
5
+
6
+ var StreamReader = function() {
7
+ this._queue = [];
8
+ this._queueSize = 0;
9
+ this._offset = 0;
10
+ };
11
+
12
+ StreamReader.prototype.put = function(buffer) {
13
+ if (!buffer || buffer.length === 0) return;
14
+ if (!Buffer.isBuffer(buffer)) buffer = Buffer.from(buffer);
15
+ this._queue.push(buffer);
16
+ this._queueSize += buffer.length;
17
+ };
18
+
19
+ StreamReader.prototype.read = function(length) {
20
+ if (length > this._queueSize) return null;
21
+ if (length === 0) return Buffer.alloc(0);
22
+
23
+ this._queueSize -= length;
24
+
25
+ var queue = this._queue,
26
+ remain = length,
27
+ first = queue[0],
28
+ buffers, buffer;
29
+
30
+ if (first.length >= length) {
31
+ if (first.length === length) {
32
+ return queue.shift();
33
+ } else {
34
+ buffer = first.slice(0, length);
35
+ queue[0] = first.slice(length);
36
+ return buffer;
37
+ }
38
+ }
39
+
40
+ for (var i = 0, n = queue.length; i < n; i++) {
41
+ if (remain < queue[i].length) break;
42
+ remain -= queue[i].length;
43
+ }
44
+ buffers = queue.splice(0, i);
45
+
46
+ if (remain > 0 && queue.length > 0) {
47
+ buffers.push(queue[0].slice(0, remain));
48
+ queue[0] = queue[0].slice(remain);
49
+ }
50
+ return Buffer.concat(buffers, length);
51
+ };
52
+
53
+ StreamReader.prototype.eachByte = function(callback, context) {
54
+ var buffer, n, index;
55
+
56
+ while (this._queue.length > 0) {
57
+ buffer = this._queue[0];
58
+ n = buffer.length;
59
+
60
+ while (this._offset < n) {
61
+ index = this._offset;
62
+ this._offset += 1;
63
+ callback.call(context, buffer[index]);
64
+ }
65
+ this._offset = 0;
66
+ this._queue.shift();
67
+ }
68
+ };
69
+
70
+ var stream_reader = StreamReader;
71
+
72
+ export { stream_reader as default };
@@ -0,0 +1,47 @@
1
+ import base from './driver/base.js';
2
+ import client from './driver/client.js';
3
+ import server from './driver/server.js';
4
+
5
+ // Protocol references:
6
+ //
7
+ // * http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-75
8
+ // * http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-76
9
+ // * http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-17
10
+
11
+ var Base = base,
12
+ Client = client,
13
+ Server = server;
14
+
15
+ var Driver = {
16
+ client: function(url, options) {
17
+ options = options || {};
18
+ if (options.masking === undefined) options.masking = true;
19
+ return new Client(url, options);
20
+ },
21
+
22
+ server: function(options) {
23
+ options = options || {};
24
+ if (options.requireMasking === undefined) options.requireMasking = true;
25
+ return new Server(options);
26
+ },
27
+
28
+ http: function() {
29
+ return Server.http.apply(Server, arguments);
30
+ },
31
+
32
+ isSecureRequest: function(request) {
33
+ return Server.isSecureRequest(request);
34
+ },
35
+
36
+ isWebSocket: function(request) {
37
+ return Base.isWebSocket(request);
38
+ },
39
+
40
+ validateOptions: function(options, validKeys) {
41
+ Base.validateOptions(options, validKeys);
42
+ }
43
+ };
44
+
45
+ var driver = Driver;
46
+
47
+ export { driver as default };
@@ -0,0 +1,140 @@
1
+ import '../../../http-parser-js/http-parser.js';
2
+ import '../../../safe-buffer/index.js';
3
+ import { exports as safeBufferExports } from '../../../../_virtual/index9.js';
4
+ import { __exports as httpParser } from '../../../../_virtual/http-parser.js';
5
+
6
+ var NodeHTTPParser = httpParser.HTTPParser,
7
+ Buffer = safeBufferExports.Buffer;
8
+
9
+ var TYPES = {
10
+ request: NodeHTTPParser.REQUEST || 'request',
11
+ response: NodeHTTPParser.RESPONSE || 'response'
12
+ };
13
+
14
+ var HttpParser = function(type) {
15
+ this._type = type;
16
+ this._parser = new NodeHTTPParser(TYPES[type]);
17
+ this._complete = false;
18
+ this.headers = {};
19
+
20
+ var current = null,
21
+ self = this;
22
+
23
+ this._parser.onHeaderField = function(b, start, length) {
24
+ current = b.toString('utf8', start, start + length).toLowerCase();
25
+ };
26
+
27
+ this._parser.onHeaderValue = function(b, start, length) {
28
+ var value = b.toString('utf8', start, start + length);
29
+
30
+ if (self.headers.hasOwnProperty(current))
31
+ self.headers[current] += ', ' + value;
32
+ else
33
+ self.headers[current] = value;
34
+ };
35
+
36
+ this._parser.onHeadersComplete = this._parser[NodeHTTPParser.kOnHeadersComplete] =
37
+ function(majorVersion, minorVersion, headers, method, pathname, statusCode) {
38
+ var info = arguments[0];
39
+
40
+ if (typeof info === 'object') {
41
+ method = info.method;
42
+ pathname = info.url;
43
+ statusCode = info.statusCode;
44
+ headers = info.headers;
45
+ }
46
+
47
+ self.method = (typeof method === 'number') ? HttpParser.METHODS[method] : method;
48
+ self.statusCode = statusCode;
49
+ self.url = pathname;
50
+
51
+ if (!headers) return;
52
+
53
+ for (var i = 0, n = headers.length, key, value; i < n; i += 2) {
54
+ key = headers[i].toLowerCase();
55
+ value = headers[i+1];
56
+ if (self.headers.hasOwnProperty(key))
57
+ self.headers[key] += ', ' + value;
58
+ else
59
+ self.headers[key] = value;
60
+ }
61
+
62
+ self._complete = true;
63
+ };
64
+ };
65
+
66
+ HttpParser.METHODS = {
67
+ 0: 'DELETE',
68
+ 1: 'GET',
69
+ 2: 'HEAD',
70
+ 3: 'POST',
71
+ 4: 'PUT',
72
+ 5: 'CONNECT',
73
+ 6: 'OPTIONS',
74
+ 7: 'TRACE',
75
+ 8: 'COPY',
76
+ 9: 'LOCK',
77
+ 10: 'MKCOL',
78
+ 11: 'MOVE',
79
+ 12: 'PROPFIND',
80
+ 13: 'PROPPATCH',
81
+ 14: 'SEARCH',
82
+ 15: 'UNLOCK',
83
+ 16: 'BIND',
84
+ 17: 'REBIND',
85
+ 18: 'UNBIND',
86
+ 19: 'ACL',
87
+ 20: 'REPORT',
88
+ 21: 'MKACTIVITY',
89
+ 22: 'CHECKOUT',
90
+ 23: 'MERGE',
91
+ 24: 'M-SEARCH',
92
+ 25: 'NOTIFY',
93
+ 26: 'SUBSCRIBE',
94
+ 27: 'UNSUBSCRIBE',
95
+ 28: 'PATCH',
96
+ 29: 'PURGE',
97
+ 30: 'MKCALENDAR',
98
+ 31: 'LINK',
99
+ 32: 'UNLINK'
100
+ };
101
+
102
+ var VERSION = process.version
103
+ ? process.version.match(/[0-9]+/g).map(function(n) { return parseInt(n, 10) })
104
+ : [];
105
+
106
+ if (VERSION[0] === 0 && VERSION[1] === 12) {
107
+ HttpParser.METHODS[16] = 'REPORT';
108
+ HttpParser.METHODS[17] = 'MKACTIVITY';
109
+ HttpParser.METHODS[18] = 'CHECKOUT';
110
+ HttpParser.METHODS[19] = 'MERGE';
111
+ HttpParser.METHODS[20] = 'M-SEARCH';
112
+ HttpParser.METHODS[21] = 'NOTIFY';
113
+ HttpParser.METHODS[22] = 'SUBSCRIBE';
114
+ HttpParser.METHODS[23] = 'UNSUBSCRIBE';
115
+ HttpParser.METHODS[24] = 'PATCH';
116
+ HttpParser.METHODS[25] = 'PURGE';
117
+ }
118
+
119
+ HttpParser.prototype.isComplete = function() {
120
+ return this._complete;
121
+ };
122
+
123
+ HttpParser.prototype.parse = function(chunk) {
124
+ var consumed = this._parser.execute(chunk, 0, chunk.length);
125
+
126
+ if (typeof consumed !== 'number') {
127
+ this.error = consumed;
128
+ this._complete = true;
129
+ return;
130
+ }
131
+
132
+ if (this._complete)
133
+ this.body = (consumed < chunk.length)
134
+ ? chunk.slice(consumed)
135
+ : Buffer.alloc(0);
136
+ };
137
+
138
+ var http_parser = HttpParser;
139
+
140
+ export { http_parser as default };
@@ -0,0 +1,150 @@
1
+ import { __exports as streams } from '../../../../_virtual/streams.js';
2
+ import require$$0 from 'stream';
3
+ import require$$1 from 'util';
4
+
5
+ /**
6
+
7
+ Streams in a WebSocket connection
8
+ ---------------------------------
9
+
10
+ We model a WebSocket as two duplex streams: one stream is for the wire protocol
11
+ over an I/O socket, and the other is for incoming/outgoing messages.
12
+
13
+
14
+ +----------+ +---------+ +----------+
15
+ [1] write(chunk) -->| ~~~~~~~~ +----->| parse() +----->| ~~~~~~~~ +--> emit('data') [2]
16
+ | | +----+----+ | |
17
+ | | | | |
18
+ | IO | | [5] | Messages |
19
+ | | V | |
20
+ | | +---------+ | |
21
+ [4] emit('data') <--+ ~~~~~~~~ |<-----+ frame() |<-----+ ~~~~~~~~ |<-- write(chunk) [3]
22
+ +----------+ +---------+ +----------+
23
+
24
+
25
+ Message transfer in each direction is simple: IO receives a byte stream [1] and
26
+ sends this stream for parsing. The parser will periodically emit a complete
27
+ message text on the Messages stream [2]. Similarly, when messages are written
28
+ to the Messages stream [3], they are framed using the WebSocket wire format and
29
+ emitted via IO [4].
30
+
31
+ There is a feedback loop via [5] since some input from [1] will be things like
32
+ ping, pong and close frames. In these cases the protocol responds by emitting
33
+ responses directly back to [4] rather than emitting messages via [2].
34
+
35
+ For the purposes of flow control, we consider the sources of each Readable
36
+ stream to be as follows:
37
+
38
+ * [2] receives input from [1]
39
+ * [4] receives input from [1] and [3]
40
+
41
+ The classes below express the relationships described above without prescribing
42
+ anything about how parse() and frame() work, other than assuming they emit
43
+ 'data' events to the IO and Messages streams. They will work with any protocol
44
+ driver having these two methods.
45
+ **/
46
+
47
+
48
+ var Stream = require$$0.Stream,
49
+ util = require$$1;
50
+
51
+
52
+ var IO = function(driver) {
53
+ this.readable = this.writable = true;
54
+ this._paused = false;
55
+ this._driver = driver;
56
+ };
57
+ util.inherits(IO, Stream);
58
+
59
+ // The IO pause() and resume() methods will be called when the socket we are
60
+ // piping to gets backed up and drains. Since IO output [4] comes from IO input
61
+ // [1] and Messages input [3], we need to tell both of those to return false
62
+ // from write() when this stream is paused.
63
+
64
+ IO.prototype.pause = function() {
65
+ this._paused = true;
66
+ this._driver.messages._paused = true;
67
+ };
68
+
69
+ IO.prototype.resume = function() {
70
+ this._paused = false;
71
+ this.emit('drain');
72
+
73
+ var messages = this._driver.messages;
74
+ messages._paused = false;
75
+ messages.emit('drain');
76
+ };
77
+
78
+ // When we receive input from a socket, send it to the parser and tell the
79
+ // source whether to back off.
80
+ IO.prototype.write = function(chunk) {
81
+ if (!this.writable) return false;
82
+ this._driver.parse(chunk);
83
+ return !this._paused;
84
+ };
85
+
86
+ // The IO end() method will be called when the socket piping into it emits
87
+ // 'close' or 'end', i.e. the socket is closed. In this situation the Messages
88
+ // stream will not emit any more data so we emit 'end'.
89
+ IO.prototype.end = function(chunk) {
90
+ if (!this.writable) return;
91
+ if (chunk !== undefined) this.write(chunk);
92
+ this.writable = false;
93
+
94
+ var messages = this._driver.messages;
95
+ if (messages.readable) {
96
+ messages.readable = messages.writable = false;
97
+ messages.emit('end');
98
+ }
99
+ };
100
+
101
+ IO.prototype.destroy = function() {
102
+ this.end();
103
+ };
104
+
105
+
106
+ var Messages = function(driver) {
107
+ this.readable = this.writable = true;
108
+ this._paused = false;
109
+ this._driver = driver;
110
+ };
111
+ util.inherits(Messages, Stream);
112
+
113
+ // The Messages pause() and resume() methods will be called when the app that's
114
+ // processing the messages gets backed up and drains. If we're emitting
115
+ // messages too fast we should tell the source to slow down. Message output [2]
116
+ // comes from IO input [1].
117
+
118
+ Messages.prototype.pause = function() {
119
+ this._driver.io._paused = true;
120
+ };
121
+
122
+ Messages.prototype.resume = function() {
123
+ this._driver.io._paused = false;
124
+ this._driver.io.emit('drain');
125
+ };
126
+
127
+ // When we receive messages from the user, send them to the formatter and tell
128
+ // the source whether to back off.
129
+ Messages.prototype.write = function(message) {
130
+ if (!this.writable) return false;
131
+ if (typeof message === 'string') this._driver.text(message);
132
+ else this._driver.binary(message);
133
+ return !this._paused;
134
+ };
135
+
136
+ // The Messages end() method will be called when a stream piping into it emits
137
+ // 'end'. Many streams may be piped into the WebSocket and one of them ending
138
+ // does not mean the whole socket is done, so just process the input and move
139
+ // on leaving the socket open.
140
+ Messages.prototype.end = function(message) {
141
+ if (message !== undefined) this.write(message);
142
+ };
143
+
144
+ Messages.prototype.destroy = function() {};
145
+
146
+
147
+ streams.IO = IO;
148
+ streams.Messages = Messages;
149
+
150
+ export { streams as default };
@@ -0,0 +1,103 @@
1
+ var TOKEN = /([!#\$%&'\*\+\-\.\^_`\|~0-9A-Za-z]+)/,
2
+ NOTOKEN = /([^!#\$%&'\*\+\-\.\^_`\|~0-9A-Za-z])/g,
3
+ QUOTED = /"((?:\\[\x00-\x7f]|[^\x00-\x08\x0a-\x1f\x7f"\\])*)"/,
4
+ PARAM = new RegExp(TOKEN.source + '(?:=(?:' + TOKEN.source + '|' + QUOTED.source + '))?'),
5
+ EXT = new RegExp(TOKEN.source + '(?: *; *' + PARAM.source + ')*', 'g'),
6
+ EXT_LIST = new RegExp('^' + EXT.source + '(?: *, *' + EXT.source + ')*$'),
7
+ NUMBER = /^-?(0|[1-9][0-9]*)(\.[0-9]+)?$/;
8
+
9
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
10
+
11
+ var Parser = {
12
+ parseHeader: function(header) {
13
+ var offers = new Offers();
14
+ if (header === '' || header === undefined) return offers;
15
+
16
+ if (!EXT_LIST.test(header))
17
+ throw new SyntaxError('Invalid Sec-WebSocket-Extensions header: ' + header);
18
+
19
+ var values = header.match(EXT);
20
+
21
+ values.forEach(function(value) {
22
+ var params = value.match(new RegExp(PARAM.source, 'g')),
23
+ name = params.shift(),
24
+ offer = {};
25
+
26
+ params.forEach(function(param) {
27
+ var args = param.match(PARAM), key = args[1], data;
28
+
29
+ if (args[2] !== undefined) {
30
+ data = args[2];
31
+ } else if (args[3] !== undefined) {
32
+ data = args[3].replace(/\\/g, '');
33
+ } else {
34
+ data = true;
35
+ }
36
+ if (NUMBER.test(data)) data = parseFloat(data);
37
+
38
+ if (hasOwnProperty.call(offer, key)) {
39
+ offer[key] = [].concat(offer[key]);
40
+ offer[key].push(data);
41
+ } else {
42
+ offer[key] = data;
43
+ }
44
+ }, this);
45
+ offers.push(name, offer);
46
+ }, this);
47
+
48
+ return offers;
49
+ },
50
+
51
+ serializeParams: function(name, params) {
52
+ var values = [];
53
+
54
+ var print = function(key, value) {
55
+ if (value instanceof Array) {
56
+ value.forEach(function(v) { print(key, v); });
57
+ } else if (value === true) {
58
+ values.push(key);
59
+ } else if (typeof value === 'number') {
60
+ values.push(key + '=' + value);
61
+ } else if (NOTOKEN.test(value)) {
62
+ values.push(key + '="' + value.replace(/"/g, '\\"') + '"');
63
+ } else {
64
+ values.push(key + '=' + value);
65
+ }
66
+ };
67
+
68
+ for (var key in params) print(key, params[key]);
69
+
70
+ return [name].concat(values).join('; ');
71
+ }
72
+ };
73
+
74
+ var Offers = function() {
75
+ this._byName = {};
76
+ this._inOrder = [];
77
+ };
78
+
79
+ Offers.prototype.push = function(name, params) {
80
+ if (!hasOwnProperty.call(this._byName, name))
81
+ this._byName[name] = [];
82
+
83
+ this._byName[name].push(params);
84
+ this._inOrder.push({ name: name, params: params });
85
+ };
86
+
87
+ Offers.prototype.eachOffer = function(callback, context) {
88
+ var list = this._inOrder;
89
+ for (var i = 0, n = list.length; i < n; i++)
90
+ callback.call(context, list[i].name, list[i].params);
91
+ };
92
+
93
+ Offers.prototype.byName = function(name) {
94
+ return this._byName[name] || [];
95
+ };
96
+
97
+ Offers.prototype.toArray = function() {
98
+ return this._inOrder.slice();
99
+ };
100
+
101
+ var parser = Parser;
102
+
103
+ export { parser as default };
@@ -0,0 +1,56 @@
1
+ import functor from './functor.js';
2
+ import pledge from './pledge.js';
3
+
4
+ var Functor = functor,
5
+ Pledge = pledge;
6
+
7
+ var Cell = function(tuple) {
8
+ this._ext = tuple[0];
9
+ this._session = tuple[1];
10
+
11
+ this._functors = {
12
+ incoming: new Functor(this._session, 'processIncomingMessage'),
13
+ outgoing: new Functor(this._session, 'processOutgoingMessage')
14
+ };
15
+ };
16
+
17
+ Cell.prototype.pending = function(direction) {
18
+ var functor = this._functors[direction];
19
+ if (!functor._stopped) functor.pending += 1;
20
+ };
21
+
22
+ Cell.prototype.incoming = function(error, message, callback, context) {
23
+ this._exec('incoming', error, message, callback, context);
24
+ };
25
+
26
+ Cell.prototype.outgoing = function(error, message, callback, context) {
27
+ this._exec('outgoing', error, message, callback, context);
28
+ };
29
+
30
+ Cell.prototype.close = function() {
31
+ this._closed = this._closed || new Pledge();
32
+ this._doClose();
33
+ return this._closed;
34
+ };
35
+
36
+ Cell.prototype._exec = function(direction, error, message, callback, context) {
37
+ this._functors[direction].call(error, message, function(err, msg) {
38
+ if (err) err.message = this._ext.name + ': ' + err.message;
39
+ callback.call(context, err, msg);
40
+ this._doClose();
41
+ }, this);
42
+ };
43
+
44
+ Cell.prototype._doClose = function() {
45
+ var fin = this._functors.incoming,
46
+ fout = this._functors.outgoing;
47
+
48
+ if (!this._closed || fin.pending + fout.pending !== 0) return;
49
+ if (this._session) this._session.close();
50
+ this._session = null;
51
+ this._closed.done();
52
+ };
53
+
54
+ var cell = Cell;
55
+
56
+ export { cell as default };