herdr-remote 0.2.38 → 0.3.31

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 (203) hide show
  1. package/dist/chunks/353DMT35.js +3 -0
  2. package/dist/chunks/42KARAL4.js +31 -0
  3. package/dist/chunks/7AUQHB3O.js +10 -0
  4. package/dist/chunks/7SMZ43LI.js +9 -0
  5. package/dist/chunks/AM3OEMFK.js +16 -0
  6. package/dist/chunks/ANNJESOL.js +10 -0
  7. package/dist/chunks/AWB4A65P.js +63 -0
  8. package/dist/chunks/C2UUZY6J.js +2 -0
  9. package/dist/chunks/DGUZCGQN.js +3 -0
  10. package/dist/chunks/H24ZP5D5.js +16 -0
  11. package/dist/chunks/I6NRCYLI.js +3 -0
  12. package/dist/chunks/JJGEV4EZ.js +3 -0
  13. package/dist/chunks/KRSURB5L.js +5 -0
  14. package/dist/chunks/KRVF37OW.js +3 -0
  15. package/dist/chunks/KUDCC7ZO.js +6 -0
  16. package/dist/chunks/M3NRPJK2.js +77 -0
  17. package/dist/chunks/M4AFZHKH.js +3 -0
  18. package/dist/chunks/M52LJEES.js +6 -0
  19. package/dist/chunks/O2LNVFUT.js +3 -0
  20. package/dist/chunks/OJPBI7KB.js +3 -0
  21. package/dist/chunks/OMN6C7J6.js +3 -0
  22. package/dist/chunks/PBMBFWLQ.js +3 -0
  23. package/dist/chunks/PBRQ3HEG.js +3 -0
  24. package/dist/chunks/PFFVGFPL.js +45 -0
  25. package/dist/chunks/QRGNEKME.js +5 -0
  26. package/dist/chunks/TNLCNVA2.js +3 -0
  27. package/dist/chunks/U27JJKJ6.js +3 -0
  28. package/dist/chunks/U6QAYG3E.js +3 -0
  29. package/dist/chunks/UEOQE77N.js +4 -0
  30. package/dist/chunks/WSACSE45.js +4 -0
  31. package/dist/chunks/WY7WHEJ4.js +3 -0
  32. package/dist/chunks/XJKWLK43.js +4 -0
  33. package/dist/chunks/XN6D5S55.js +3 -0
  34. package/dist/chunks/YD3MIP7B.js +5 -0
  35. package/dist/chunks/YXDQ62BB.js +4 -0
  36. package/dist/cli.js +21 -294
  37. package/dist/connector/admin-broker.js +3 -302
  38. package/dist/connector/main.js +20 -18
  39. package/dist/harfbuzz-subset.wasm +0 -0
  40. package/dist/postinstall.js +17 -0
  41. package/herdr-plugin.toml +1 -1
  42. package/node_modules/herdr-remote-relay/bin/herdr-remote-relay.js +33 -92
  43. package/node_modules/herdr-remote-relay/package.json +3 -46
  44. package/package.json +8 -27
  45. package/dist/agent-status.js +0 -130
  46. package/dist/binary-plist.js +0 -157
  47. package/dist/config.js +0 -278
  48. package/dist/connector/admin-broker-setup.js +0 -40
  49. package/dist/connector/admin-shell.js +0 -67
  50. package/dist/connector/admin-tab.js +0 -90
  51. package/dist/connector/adminBrokerEndpoint.js +0 -68
  52. package/dist/connector/agent-watch.js +0 -123
  53. package/dist/connector/elevatedPty.js +0 -141
  54. package/dist/connector/font-server.js +0 -165
  55. package/dist/connector/herdr-prefix-keys.js +0 -28
  56. package/dist/connector/host-connector.js +0 -433
  57. package/dist/connector/host-hello.js +0 -32
  58. package/dist/connector/lock.js +0 -73
  59. package/dist/connector/sessions.js +0 -381
  60. package/dist/connector/update-report.js +0 -70
  61. package/dist/connector/wire.js +0 -42
  62. package/dist/exit-codes.js +0 -13
  63. package/dist/font-subset.js +0 -110
  64. package/dist/herdr-api.js +0 -254
  65. package/dist/herdr-command.js +0 -245
  66. package/dist/herdr-plugin.js +0 -120
  67. package/dist/herdr-server.js +0 -190
  68. package/dist/i18n/en.js +0 -257
  69. package/dist/i18n/index.js +0 -48
  70. package/dist/i18n/zh.js +0 -256
  71. package/dist/keepalive/detached.js +0 -97
  72. package/dist/keepalive/environment.js +0 -44
  73. package/dist/keepalive/index.js +0 -129
  74. package/dist/keepalive/launchd.js +0 -117
  75. package/dist/keepalive/systemd.js +0 -112
  76. package/dist/keepalive/types.js +0 -1
  77. package/dist/keepalive/windows-service-setup.js +0 -138
  78. package/dist/keepalive/windows-service.js +0 -272
  79. package/dist/keepalive/windows-task.js +0 -191
  80. package/dist/lib/process.js +0 -132
  81. package/dist/lifecycle.js +0 -79
  82. package/dist/net-interfaces.js +0 -82
  83. package/dist/node-pty-loader.js +0 -80
  84. package/dist/pasted-files.js +0 -115
  85. package/dist/paths.js +0 -74
  86. package/dist/pty-session.js +0 -133
  87. package/dist/relay-client.js +0 -106
  88. package/dist/relay-urls.js +0 -99
  89. package/dist/runtime.js +0 -107
  90. package/dist/service.js +0 -267
  91. package/dist/settings-model.js +0 -298
  92. package/dist/socket-discovery.js +0 -70
  93. package/dist/supervisor.js +0 -323
  94. package/dist/terminal-font/deps.js +0 -83
  95. package/dist/terminal-font/files.js +0 -357
  96. package/dist/terminal-font/formats.js +0 -355
  97. package/dist/terminal-font/index.js +0 -187
  98. package/dist/terminal-font/readers.js +0 -373
  99. package/dist/terminal-font/terminals.js +0 -147
  100. package/dist/terminal-palette.js +0 -399
  101. package/dist/tui/App.js +0 -199
  102. package/dist/tui/api.js +0 -91
  103. package/dist/tui/components/TextField.js +0 -50
  104. package/dist/tui/components/common.js +0 -80
  105. package/dist/tui/index.js +0 -36
  106. package/dist/tui/mouse/index.js +0 -164
  107. package/dist/tui/mouse/protocol.js +0 -96
  108. package/dist/tui/mouse/source.js +0 -79
  109. package/dist/tui/screens/About.js +0 -172
  110. package/dist/tui/screens/Herdr.js +0 -75
  111. package/dist/tui/screens/Keepalive.js +0 -141
  112. package/dist/tui/screens/Overview.js +0 -36
  113. package/dist/tui/screens/Pair.js +0 -74
  114. package/dist/tui/screens/Relay.js +0 -243
  115. package/dist/tui/screens/Services.js +0 -63
  116. package/dist/tui/screens/Wizard.js +0 -241
  117. package/dist/tui/terminal.js +0 -39
  118. package/dist/tui/theme.js +0 -33
  119. package/dist/update-command.js +0 -118
  120. package/dist/updater/in-place.js +0 -83
  121. package/dist/updater/npm.js +0 -62
  122. package/dist/updater.js +0 -401
  123. package/node_modules/herdr-remote-relay/README.md +0 -76
  124. package/node_modules/herdr-remote-relay/README.zh-CN.md +0 -76
  125. package/node_modules/herdr-remote-relay/config.example.json +0 -18
  126. package/node_modules/herdr-remote-relay/deploy/cloudflared/config.yml.example +0 -9
  127. package/node_modules/herdr-remote-relay/deploy/docker/compose.yaml +0 -23
  128. package/node_modules/herdr-remote-relay/deploy/nginx/herdr-remote-relay.conf.example +0 -49
  129. package/node_modules/herdr-remote-relay/deploy/systemd/herdr-remote-relay.service +0 -41
  130. package/node_modules/herdr-remote-relay/deploy/systemd/relay.env.example +0 -25
  131. package/node_modules/herdr-remote-relay/dist/auth-store.d.ts +0 -114
  132. package/node_modules/herdr-remote-relay/dist/auth-store.js +0 -289
  133. package/node_modules/herdr-remote-relay/dist/metrics.d.ts +0 -76
  134. package/node_modules/herdr-remote-relay/dist/metrics.js +0 -249
  135. package/node_modules/herdr-remote-relay/dist/protocol/frames.d.ts +0 -27
  136. package/node_modules/herdr-remote-relay/dist/protocol/frames.js +0 -110
  137. package/node_modules/herdr-remote-relay/dist/protocol/herdr-keys.d.ts +0 -8
  138. package/node_modules/herdr-remote-relay/dist/protocol/herdr-keys.js +0 -34
  139. package/node_modules/herdr-remote-relay/dist/protocol/http.d.ts +0 -165
  140. package/node_modules/herdr-remote-relay/dist/protocol/http.js +0 -3
  141. package/node_modules/herdr-remote-relay/dist/protocol/index.d.ts +0 -7
  142. package/node_modules/herdr-remote-relay/dist/protocol/index.js +0 -9
  143. package/node_modules/herdr-remote-relay/dist/protocol/messages.d.ts +0 -362
  144. package/node_modules/herdr-remote-relay/dist/protocol/messages.js +0 -20
  145. package/node_modules/herdr-remote-relay/dist/protocol/paste.d.ts +0 -14
  146. package/node_modules/herdr-remote-relay/dist/protocol/paste.js +0 -50
  147. package/node_modules/herdr-remote-relay/dist/protocol/release.d.ts +0 -8
  148. package/node_modules/herdr-remote-relay/dist/protocol/release.js +0 -17
  149. package/node_modules/herdr-remote-relay/dist/protocol/terminal.d.ts +0 -79
  150. package/node_modules/herdr-remote-relay/dist/protocol/terminal.js +0 -150
  151. package/node_modules/herdr-remote-relay/dist/relay-config.d.ts +0 -74
  152. package/node_modules/herdr-remote-relay/dist/relay-config.js +0 -316
  153. package/node_modules/herdr-remote-relay/dist/relay-server.d.ts +0 -67
  154. package/node_modules/herdr-remote-relay/dist/relay-server.js +0 -196
  155. package/node_modules/herdr-remote-relay/dist/scroll-input.d.ts +0 -17
  156. package/node_modules/herdr-remote-relay/dist/scroll-input.js +0 -124
  157. package/node_modules/herdr-remote-relay/dist/server/client-channel.d.ts +0 -3
  158. package/node_modules/herdr-remote-relay/dist/server/client-channel.js +0 -396
  159. package/node_modules/herdr-remote-relay/dist/server/font-proxy.d.ts +0 -19
  160. package/node_modules/herdr-remote-relay/dist/server/font-proxy.js +0 -155
  161. package/node_modules/herdr-remote-relay/dist/server/host-broadcasts.d.ts +0 -27
  162. package/node_modules/herdr-remote-relay/dist/server/host-broadcasts.js +0 -83
  163. package/node_modules/herdr-remote-relay/dist/server/host-channel.d.ts +0 -3
  164. package/node_modules/herdr-remote-relay/dist/server/host-channel.js +0 -271
  165. package/node_modules/herdr-remote-relay/dist/server/http-api.d.ts +0 -4
  166. package/node_modules/herdr-remote-relay/dist/server/http-api.js +0 -219
  167. package/node_modules/herdr-remote-relay/dist/server/maintenance.d.ts +0 -5
  168. package/node_modules/herdr-remote-relay/dist/server/maintenance.js +0 -64
  169. package/node_modules/herdr-remote-relay/dist/server/requests.d.ts +0 -34
  170. package/node_modules/herdr-remote-relay/dist/server/requests.js +0 -142
  171. package/node_modules/herdr-remote-relay/dist/server/sessions.d.ts +0 -36
  172. package/node_modules/herdr-remote-relay/dist/server/sessions.js +0 -230
  173. package/node_modules/herdr-remote-relay/dist/server/sockets.d.ts +0 -12
  174. package/node_modules/herdr-remote-relay/dist/server/sockets.js +0 -64
  175. package/node_modules/herdr-remote-relay/dist/server/status.d.ts +0 -11
  176. package/node_modules/herdr-remote-relay/dist/server/status.js +0 -99
  177. package/node_modules/herdr-remote-relay/dist/server/transport.d.ts +0 -16
  178. package/node_modules/herdr-remote-relay/dist/server/transport.js +0 -110
  179. package/node_modules/herdr-remote-relay/dist/server/types.d.ts +0 -133
  180. package/node_modules/herdr-remote-relay/dist/server/types.js +0 -3
  181. package/node_modules/herdr-remote-relay/dist/server/version.d.ts +0 -2
  182. package/node_modules/herdr-remote-relay/dist/server/version.js +0 -5
  183. package/node_modules/herdr-remote-relay/dist/state.d.ts +0 -6
  184. package/node_modules/herdr-remote-relay/dist/state.js +0 -47
  185. package/node_modules/ws/LICENSE +0 -20
  186. package/node_modules/ws/README.md +0 -548
  187. package/node_modules/ws/browser.js +0 -8
  188. package/node_modules/ws/index.js +0 -22
  189. package/node_modules/ws/lib/buffer-util.js +0 -131
  190. package/node_modules/ws/lib/constants.js +0 -19
  191. package/node_modules/ws/lib/event-target.js +0 -292
  192. package/node_modules/ws/lib/extension.js +0 -203
  193. package/node_modules/ws/lib/limiter.js +0 -55
  194. package/node_modules/ws/lib/permessage-deflate.js +0 -530
  195. package/node_modules/ws/lib/receiver.js +0 -743
  196. package/node_modules/ws/lib/sender.js +0 -607
  197. package/node_modules/ws/lib/stream.js +0 -161
  198. package/node_modules/ws/lib/subprotocol.js +0 -62
  199. package/node_modules/ws/lib/validation.js +0 -152
  200. package/node_modules/ws/lib/websocket-server.js +0 -562
  201. package/node_modules/ws/lib/websocket.js +0 -1407
  202. package/node_modules/ws/package.json +0 -74
  203. package/node_modules/ws/wrapper.mjs +0 -21
@@ -1,530 +0,0 @@
1
- 'use strict';
2
-
3
- const zlib = require('zlib');
4
-
5
- const bufferUtil = require('./buffer-util');
6
- const Limiter = require('./limiter');
7
- const { kStatusCode } = require('./constants');
8
-
9
- const FastBuffer = Buffer[Symbol.species];
10
- const TRAILER = Buffer.from([0x00, 0x00, 0xff, 0xff]);
11
- const kPerMessageDeflate = Symbol('permessage-deflate');
12
- const kTotalLength = Symbol('total-length');
13
- const kCallback = Symbol('callback');
14
- const kBuffers = Symbol('buffers');
15
- const kError = Symbol('error');
16
-
17
- //
18
- // We limit zlib concurrency, which prevents severe memory fragmentation
19
- // as documented in https://github.com/nodejs/node/issues/8871#issuecomment-250915913
20
- // and https://github.com/websockets/ws/issues/1202
21
- //
22
- // Intentionally global; it's the global thread pool that's an issue.
23
- //
24
- let zlibLimiter;
25
-
26
- /**
27
- * permessage-deflate implementation.
28
- */
29
- class PerMessageDeflate {
30
- /**
31
- * Creates a PerMessageDeflate instance.
32
- *
33
- * @param {Object} [options] Configuration options
34
- * @param {(Boolean|Number)} [options.clientMaxWindowBits] Advertise support
35
- * for, or request, a custom client window size
36
- * @param {Boolean} [options.clientNoContextTakeover=false] Advertise/
37
- * acknowledge disabling of client context takeover
38
- * @param {Number} [options.concurrencyLimit=10] The number of concurrent
39
- * calls to zlib
40
- * @param {Boolean} [options.isServer=false] Create the instance in either
41
- * server or client mode
42
- * @param {Number} [options.maxPayload=0] The maximum allowed message length
43
- * @param {(Boolean|Number)} [options.serverMaxWindowBits] Request/confirm the
44
- * use of a custom server window size
45
- * @param {Boolean} [options.serverNoContextTakeover=false] Request/accept
46
- * disabling of server context takeover
47
- * @param {Number} [options.threshold=1024] Size (in bytes) below which
48
- * messages should not be compressed if context takeover is disabled
49
- * @param {Object} [options.zlibDeflateOptions] Options to pass to zlib on
50
- * deflate
51
- * @param {Object} [options.zlibInflateOptions] Options to pass to zlib on
52
- * inflate
53
- */
54
- constructor(options) {
55
- this._options = options || {};
56
- this._threshold =
57
- this._options.threshold !== undefined ? this._options.threshold : 1024;
58
- this._maxPayload = this._options.maxPayload | 0;
59
- this._isServer = !!this._options.isServer;
60
- this._deflate = null;
61
- this._inflate = null;
62
-
63
- this.params = null;
64
-
65
- if (!zlibLimiter) {
66
- const concurrency =
67
- this._options.concurrencyLimit !== undefined
68
- ? this._options.concurrencyLimit
69
- : 10;
70
- zlibLimiter = new Limiter(concurrency);
71
- }
72
- }
73
-
74
- /**
75
- * @type {String}
76
- */
77
- static get extensionName() {
78
- return 'permessage-deflate';
79
- }
80
-
81
- /**
82
- * Create an extension negotiation offer.
83
- *
84
- * @return {Object} Extension parameters
85
- * @public
86
- */
87
- offer() {
88
- const params = {};
89
-
90
- if (this._options.serverNoContextTakeover) {
91
- params.server_no_context_takeover = true;
92
- }
93
- if (this._options.clientNoContextTakeover) {
94
- params.client_no_context_takeover = true;
95
- }
96
- if (this._options.serverMaxWindowBits) {
97
- params.server_max_window_bits = this._options.serverMaxWindowBits;
98
- }
99
- if (this._options.clientMaxWindowBits) {
100
- params.client_max_window_bits = this._options.clientMaxWindowBits;
101
- } else if (this._options.clientMaxWindowBits == null) {
102
- params.client_max_window_bits = true;
103
- }
104
-
105
- return params;
106
- }
107
-
108
- /**
109
- * Accept an extension negotiation offer/response.
110
- *
111
- * @param {Array} configurations The extension negotiation offers/reponse
112
- * @return {Object} Accepted configuration
113
- * @public
114
- */
115
- accept(configurations) {
116
- configurations = this.normalizeParams(configurations);
117
-
118
- this.params = this._isServer
119
- ? this.acceptAsServer(configurations)
120
- : this.acceptAsClient(configurations);
121
-
122
- return this.params;
123
- }
124
-
125
- /**
126
- * Releases all resources used by the extension.
127
- *
128
- * @public
129
- */
130
- cleanup() {
131
- if (this._inflate) {
132
- this._inflate.close();
133
- this._inflate = null;
134
- }
135
-
136
- if (this._deflate) {
137
- const callback = this._deflate[kCallback];
138
-
139
- this._deflate.close();
140
- this._deflate = null;
141
-
142
- if (callback) {
143
- callback(
144
- new Error(
145
- 'The deflate stream was closed while data was being processed'
146
- )
147
- );
148
- }
149
- }
150
- }
151
-
152
- /**
153
- * Accept an extension negotiation offer.
154
- *
155
- * @param {Array} offers The extension negotiation offers
156
- * @return {Object} Accepted configuration
157
- * @private
158
- */
159
- acceptAsServer(offers) {
160
- const opts = this._options;
161
- const accepted = offers.find((params) => {
162
- if (
163
- (opts.serverNoContextTakeover === false &&
164
- params.server_no_context_takeover) ||
165
- (params.server_max_window_bits &&
166
- (opts.serverMaxWindowBits === false ||
167
- (typeof opts.serverMaxWindowBits === 'number' &&
168
- opts.serverMaxWindowBits > params.server_max_window_bits))) ||
169
- (typeof opts.clientMaxWindowBits === 'number' &&
170
- (typeof params.client_max_window_bits === 'number'
171
- ? opts.clientMaxWindowBits > params.client_max_window_bits
172
- : !params.client_max_window_bits))
173
- ) {
174
- return false;
175
- }
176
-
177
- return true;
178
- });
179
-
180
- if (!accepted) {
181
- throw new Error('None of the extension offers can be accepted');
182
- }
183
-
184
- if (opts.serverNoContextTakeover) {
185
- accepted.server_no_context_takeover = true;
186
- }
187
- if (opts.clientNoContextTakeover) {
188
- accepted.client_no_context_takeover = true;
189
- }
190
- if (typeof opts.serverMaxWindowBits === 'number') {
191
- accepted.server_max_window_bits = opts.serverMaxWindowBits;
192
- }
193
- if (typeof opts.clientMaxWindowBits === 'number') {
194
- accepted.client_max_window_bits = opts.clientMaxWindowBits;
195
- } else if (
196
- accepted.client_max_window_bits === true ||
197
- opts.clientMaxWindowBits === false
198
- ) {
199
- delete accepted.client_max_window_bits;
200
- }
201
-
202
- return accepted;
203
- }
204
-
205
- /**
206
- * Accept the extension negotiation response.
207
- *
208
- * @param {Array} response The extension negotiation response
209
- * @return {Object} Accepted configuration
210
- * @private
211
- */
212
- acceptAsClient(response) {
213
- const params = response[0];
214
-
215
- if (
216
- this._options.clientNoContextTakeover === false &&
217
- params.client_no_context_takeover
218
- ) {
219
- throw new Error('Unexpected parameter "client_no_context_takeover"');
220
- }
221
-
222
- if (!params.client_max_window_bits) {
223
- if (typeof this._options.clientMaxWindowBits === 'number') {
224
- params.client_max_window_bits = this._options.clientMaxWindowBits;
225
- }
226
- } else if (
227
- this._options.clientMaxWindowBits === false ||
228
- (typeof this._options.clientMaxWindowBits === 'number' &&
229
- params.client_max_window_bits > this._options.clientMaxWindowBits)
230
- ) {
231
- throw new Error(
232
- 'Unexpected or invalid parameter "client_max_window_bits"'
233
- );
234
- }
235
-
236
- return params;
237
- }
238
-
239
- /**
240
- * Normalize parameters.
241
- *
242
- * @param {Array} configurations The extension negotiation offers/reponse
243
- * @return {Array} The offers/response with normalized parameters
244
- * @private
245
- */
246
- normalizeParams(configurations) {
247
- configurations.forEach((params) => {
248
- Object.keys(params).forEach((key) => {
249
- let value = params[key];
250
-
251
- if (value.length > 1) {
252
- throw new Error(`Parameter "${key}" must have only a single value`);
253
- }
254
-
255
- value = value[0];
256
-
257
- if (key === 'client_max_window_bits') {
258
- if (value !== true) {
259
- const num = +value;
260
- if (!Number.isInteger(num) || num < 8 || num > 15) {
261
- throw new TypeError(
262
- `Invalid value for parameter "${key}": ${value}`
263
- );
264
- }
265
- value = num;
266
- } else if (!this._isServer) {
267
- throw new TypeError(
268
- `Invalid value for parameter "${key}": ${value}`
269
- );
270
- }
271
- } else if (key === 'server_max_window_bits') {
272
- const num = +value;
273
- if (!Number.isInteger(num) || num < 8 || num > 15) {
274
- throw new TypeError(
275
- `Invalid value for parameter "${key}": ${value}`
276
- );
277
- }
278
- value = num;
279
- } else if (
280
- key === 'client_no_context_takeover' ||
281
- key === 'server_no_context_takeover'
282
- ) {
283
- if (value !== true) {
284
- throw new TypeError(
285
- `Invalid value for parameter "${key}": ${value}`
286
- );
287
- }
288
- } else {
289
- throw new Error(`Unknown parameter "${key}"`);
290
- }
291
-
292
- params[key] = value;
293
- });
294
- });
295
-
296
- return configurations;
297
- }
298
-
299
- /**
300
- * Decompress data. Concurrency limited.
301
- *
302
- * @param {Buffer} data Compressed data
303
- * @param {Boolean} fin Specifies whether or not this is the last fragment
304
- * @param {Function} callback Callback
305
- * @public
306
- */
307
- decompress(data, fin, callback) {
308
- zlibLimiter.add((done) => {
309
- this._decompress(data, fin, (err, result) => {
310
- done();
311
- callback(err, result);
312
- });
313
- });
314
- }
315
-
316
- /**
317
- * Compress data. Concurrency limited.
318
- *
319
- * @param {(Buffer|String)} data Data to compress
320
- * @param {Boolean} fin Specifies whether or not this is the last fragment
321
- * @param {Function} callback Callback
322
- * @public
323
- */
324
- compress(data, fin, callback) {
325
- zlibLimiter.add((done) => {
326
- this._compress(data, fin, (err, result) => {
327
- done();
328
- callback(err, result);
329
- });
330
- });
331
- }
332
-
333
- /**
334
- * Decompress data.
335
- *
336
- * @param {Buffer} data Compressed data
337
- * @param {Boolean} fin Specifies whether or not this is the last fragment
338
- * @param {Function} callback Callback
339
- * @private
340
- */
341
- _decompress(data, fin, callback) {
342
- const endpoint = this._isServer ? 'client' : 'server';
343
-
344
- if (!this._inflate) {
345
- const key = `${endpoint}_max_window_bits`;
346
- const windowBits =
347
- typeof this.params[key] !== 'number'
348
- ? zlib.Z_DEFAULT_WINDOWBITS
349
- : this.params[key];
350
-
351
- this._inflate = zlib.createInflateRaw({
352
- ...this._options.zlibInflateOptions,
353
- windowBits
354
- });
355
- this._inflate[kPerMessageDeflate] = this;
356
- this._inflate[kTotalLength] = 0;
357
- this._inflate[kBuffers] = [];
358
- this._inflate.on('error', inflateOnError);
359
- this._inflate.on('data', inflateOnData);
360
- }
361
-
362
- this._inflate[kCallback] = callback;
363
-
364
- this._inflate.write(data);
365
- if (fin) this._inflate.write(TRAILER);
366
-
367
- this._inflate.flush(() => {
368
- const err = this._inflate[kError];
369
-
370
- if (err) {
371
- this._inflate.close();
372
- this._inflate = null;
373
- callback(err);
374
- return;
375
- }
376
-
377
- const data = bufferUtil.concat(
378
- this._inflate[kBuffers],
379
- this._inflate[kTotalLength]
380
- );
381
-
382
- if (this._inflate._readableState.endEmitted) {
383
- this._inflate.close();
384
- this._inflate = null;
385
- } else {
386
- this._inflate[kTotalLength] = 0;
387
- this._inflate[kBuffers] = [];
388
-
389
- if (fin && this.params[`${endpoint}_no_context_takeover`]) {
390
- this._inflate.reset();
391
- }
392
- }
393
-
394
- callback(null, data);
395
- });
396
- }
397
-
398
- /**
399
- * Compress data.
400
- *
401
- * @param {(Buffer|String)} data Data to compress
402
- * @param {Boolean} fin Specifies whether or not this is the last fragment
403
- * @param {Function} callback Callback
404
- * @private
405
- */
406
- _compress(data, fin, callback) {
407
- const endpoint = this._isServer ? 'server' : 'client';
408
-
409
- if (!this._deflate) {
410
- const key = `${endpoint}_max_window_bits`;
411
- const windowBits =
412
- typeof this.params[key] !== 'number'
413
- ? zlib.Z_DEFAULT_WINDOWBITS
414
- : this.params[key];
415
-
416
- this._deflate = zlib.createDeflateRaw({
417
- ...this._options.zlibDeflateOptions,
418
- windowBits
419
- });
420
-
421
- this._deflate[kTotalLength] = 0;
422
- this._deflate[kBuffers] = [];
423
-
424
- this._deflate.on('data', deflateOnData);
425
- }
426
-
427
- this._deflate[kCallback] = callback;
428
-
429
- this._deflate.write(data);
430
- this._deflate.flush(zlib.Z_SYNC_FLUSH, () => {
431
- if (!this._deflate) {
432
- //
433
- // The deflate stream was closed while data was being processed.
434
- //
435
- return;
436
- }
437
-
438
- let data = bufferUtil.concat(
439
- this._deflate[kBuffers],
440
- this._deflate[kTotalLength]
441
- );
442
-
443
- if (fin) {
444
- data = new FastBuffer(data.buffer, data.byteOffset, data.length - 4);
445
- }
446
-
447
- //
448
- // Ensure that the callback will not be called again in
449
- // `PerMessageDeflate#cleanup()`.
450
- //
451
- this._deflate[kCallback] = null;
452
-
453
- this._deflate[kTotalLength] = 0;
454
- this._deflate[kBuffers] = [];
455
-
456
- if (fin && this.params[`${endpoint}_no_context_takeover`]) {
457
- this._deflate.reset();
458
- }
459
-
460
- callback(null, data);
461
- });
462
- }
463
- }
464
-
465
- module.exports = PerMessageDeflate;
466
-
467
- /**
468
- * The listener of the `zlib.DeflateRaw` stream `'data'` event.
469
- *
470
- * @param {Buffer} chunk A chunk of data
471
- * @private
472
- */
473
- function deflateOnData(chunk) {
474
- this[kBuffers].push(chunk);
475
- this[kTotalLength] += chunk.length;
476
- }
477
-
478
- /**
479
- * The listener of the `zlib.InflateRaw` stream `'data'` event.
480
- *
481
- * @param {Buffer} chunk A chunk of data
482
- * @private
483
- */
484
- function inflateOnData(chunk) {
485
- this[kTotalLength] += chunk.length;
486
-
487
- if (
488
- this[kPerMessageDeflate]._maxPayload < 1 ||
489
- this[kTotalLength] <= this[kPerMessageDeflate]._maxPayload
490
- ) {
491
- this[kBuffers].push(chunk);
492
- return;
493
- }
494
-
495
- this[kError] = new RangeError('Max payload size exceeded');
496
- this[kError].code = 'WS_ERR_UNSUPPORTED_MESSAGE_LENGTH';
497
- this[kError][kStatusCode] = 1009;
498
- this.removeListener('data', inflateOnData);
499
-
500
- //
501
- // The choice to employ `zlib.reset()` over `zlib.close()` is dictated by the
502
- // fact that in Node.js versions prior to 13.10.0, the callback for
503
- // `zlib.flush()` is not called if `zlib.close()` is used. Utilizing
504
- // `zlib.reset()` ensures that either the callback is invoked or an error is
505
- // emitted.
506
- //
507
- this.reset();
508
- }
509
-
510
- /**
511
- * The listener of the `zlib.InflateRaw` stream `'error'` event.
512
- *
513
- * @param {Error} err The emitted error
514
- * @private
515
- */
516
- function inflateOnError(err) {
517
- //
518
- // There is no need to call `Zlib#close()` as the handle is automatically
519
- // closed when an error is emitted.
520
- //
521
- this[kPerMessageDeflate]._inflate = null;
522
-
523
- if (this[kError]) {
524
- this[kCallback](this[kError]);
525
- return;
526
- }
527
-
528
- err[kStatusCode] = 1007;
529
- this[kCallback](err);
530
- }