@remotion/renderer 3.0.31 → 3.1.0

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 (93) hide show
  1. package/dist/browser/NetworkManager.js +1 -5
  2. package/dist/combine-videos.d.ts +2 -1
  3. package/dist/combine-videos.js +8 -2
  4. package/dist/convert-number-of-gif-loops-to-ffmpeg.d.ts +1 -0
  5. package/dist/convert-number-of-gif-loops-to-ffmpeg.js +17 -0
  6. package/dist/ensure-frames-in-order.d.ts +1 -1
  7. package/dist/ensure-frames-in-order.js +3 -2
  8. package/dist/ensure-presentation-timestamp.d.ts +1 -1
  9. package/dist/ensure-presentation-timestamp.js +9 -10
  10. package/dist/extract-frame-from-video.js +4 -2
  11. package/dist/get-codec-name.js +3 -0
  12. package/dist/get-duration-from-frame-range.d.ts +1 -2
  13. package/dist/get-duration-from-frame-range.js +13 -9
  14. package/dist/get-extension-from-codec.d.ts +1 -1
  15. package/dist/get-extension-from-codec.js +5 -0
  16. package/dist/index.d.ts +4 -3
  17. package/dist/index.js +3 -1
  18. package/dist/mime-types.d.ts +1 -1
  19. package/dist/mime-types.js +2 -2
  20. package/dist/prespawn-ffmpeg.js +2 -2
  21. package/dist/render-frames.d.ts +1 -0
  22. package/dist/render-frames.js +12 -16
  23. package/dist/render-media.d.ts +2 -0
  24. package/dist/render-media.js +11 -4
  25. package/dist/render-still.js +1 -1
  26. package/dist/stitch-frames-to-video.d.ts +1 -0
  27. package/dist/stitch-frames-to-video.js +32 -22
  28. package/dist/validate-output-filename.js +5 -0
  29. package/package.json +8 -10
  30. package/tsconfig.json +2 -1
  31. package/vitest.config.ts +8 -0
  32. package/dist/abort.d.ts +0 -7
  33. package/dist/abort.js +0 -20
  34. package/dist/assets/cleanup-assets.d.ts +0 -2
  35. package/dist/assets/cleanup-assets.js +0 -2
  36. package/dist/browser/ConnectionTransport.d.ts +0 -21
  37. package/dist/browser/ConnectionTransport.js +0 -17
  38. package/dist/browser/EmulationManager.d.ts +0 -7
  39. package/dist/browser/EmulationManager.js +0 -40
  40. package/dist/browser/Page.d.ts +0 -74
  41. package/dist/browser/Page.js +0 -283
  42. package/dist/browser/compat.d.ts +0 -2
  43. package/dist/browser/compat.js +0 -17
  44. package/dist/browser/environment.d.ts +0 -16
  45. package/dist/browser/environment.js +0 -19
  46. package/dist/browser/ws.d.ts +0 -287
  47. package/dist/browser/ws.js +0 -21
  48. package/dist/cancel.d.ts +0 -7
  49. package/dist/cancel.js +0 -25
  50. package/dist/ensure-faststart.d.ts +0 -1
  51. package/dist/ensure-faststart.js +0 -14
  52. package/dist/faststart/atom.d.ts +0 -35
  53. package/dist/faststart/atom.js +0 -138
  54. package/dist/faststart/index.d.ts +0 -0
  55. package/dist/faststart/index.js +0 -1
  56. package/dist/faststart/options.d.ts +0 -6
  57. package/dist/faststart/options.js +0 -2
  58. package/dist/faststart/qt-faststart.d.ts +0 -18
  59. package/dist/faststart/qt-faststart.js +0 -66
  60. package/dist/faststart/update-chunk-offsets.d.ts +0 -10
  61. package/dist/faststart/update-chunk-offsets.js +0 -114
  62. package/dist/faststart/util.d.ts +0 -9
  63. package/dist/faststart/util.js +0 -34
  64. package/dist/get-duration-of-asset.d.ts +0 -7
  65. package/dist/get-duration-of-asset.js +0 -36
  66. package/dist/is-vp9-video.d.ts +0 -3
  67. package/dist/is-vp9-video.js +0 -24
  68. package/dist/offthread/index.d.ts +0 -0
  69. package/dist/offthread/index.js +0 -1
  70. package/dist/render-gif.d.ts +0 -2
  71. package/dist/render-gif.js +0 -242
  72. package/dist/serve-handler/glob-slash.d.ts +0 -1
  73. package/dist/serve-handler/glob-slash.js +0 -12
  74. package/dist/should-use-vp9-decoder.d.ts +0 -0
  75. package/dist/should-use-vp9-decoder.js +0 -1
  76. package/dist/stitch-frames-to-gif.d.ts +0 -8
  77. package/dist/stitch-frames-to-gif.js +0 -128
  78. package/dist/validate-fps-for-gif.d.ts +0 -2
  79. package/dist/validate-fps-for-gif.js +0 -9
  80. package/dist/validate-offthreadvideo-image-format.d.ts +0 -1
  81. package/dist/validate-offthreadvideo-image-format.js +0 -15
  82. package/dist/ws/buffer-util.d.ts +0 -10
  83. package/dist/ws/buffer-util.js +0 -123
  84. package/dist/ws/constants.d.ts +0 -10
  85. package/dist/ws/constants.js +0 -13
  86. package/dist/ws/event-target.d.ts +0 -155
  87. package/dist/ws/event-target.js +0 -203
  88. package/dist/ws/extension.d.ts +0 -16
  89. package/dist/ws/extension.js +0 -232
  90. package/dist/ws/limiter.d.ts +0 -34
  91. package/dist/ws/limiter.js +0 -41
  92. package/dist/ws/permessage_deflate.d.ts +0 -152
  93. package/dist/ws/permessage_deflate.js +0 -409
@@ -1,152 +0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- import zlib from 'zlib';
4
- declare type Options = {
5
- clientMaxWindowBits: number | boolean;
6
- clientNoContextTakeover: boolean;
7
- concurrencyLimit: number;
8
- serverMaxWindowBits: boolean | number;
9
- serverNoContextTakeover: boolean;
10
- threshold: number;
11
- zlibDeflateOptions: object;
12
- zlibInflateOptions: object;
13
- };
14
- declare type OfferParams = {
15
- server_no_context_takeover?: true;
16
- client_no_context_takeover?: true;
17
- server_max_window_bits?: number | boolean;
18
- client_max_window_bits?: number | boolean;
19
- };
20
- declare type Callback = (err: Error | null, result: unknown) => void;
21
- /**
22
- * permessage-deflate implementation.
23
- */
24
- export declare class PerMessageDeflate {
25
- /**
26
- * Creates a PerMessageDeflate instance.
27
- *
28
- * @param {Object} [options] Configuration options
29
- * @param {(Boolean|Number)} [options.clientMaxWindowBits] Advertise support
30
- * for, or request, a custom client window size
31
- * @param {Boolean} [options.clientNoContextTakeover=false] Advertise/
32
- * acknowledge disabling of client context takeover
33
- * @param {Number} [options.concurrencyLimit=10] The number of concurrent
34
- * calls to zlib
35
- * @param {(Boolean|Number)} [options.serverMaxWindowBits] Request/confirm the
36
- * use of a custom server window size
37
- * @param {Boolean} [options.serverNoContextTakeover=false] Request/accept
38
- * disabling of server context takeover
39
- * @param {Number} [options.threshold=1024] Size (in bytes) below which
40
- * messages should not be compressed if context takeover is disabled
41
- * @param {Object} [options.zlibDeflateOptions] Options to pass to zlib on
42
- * deflate
43
- * @param {Object} [options.zlibInflateOptions] Options to pass to zlib on
44
- * inflate
45
- * @param {Boolean} [isServer=false] Create the instance in either server or
46
- * client mode
47
- * @param {Number} [maxPayload=0] The maximum allowed message length
48
- */
49
- _maxPayload: number;
50
- _options: Options;
51
- _threshold: number;
52
- _isServer: boolean;
53
- _deflate: zlib.DeflateRaw | null;
54
- _inflate: null;
55
- params: null;
56
- constructor(options: {
57
- clientMaxWindowBits: number | boolean;
58
- clientNoContextTakeover: boolean;
59
- concurrencyLimit: number;
60
- serverMaxWindowBits: boolean | number;
61
- serverNoContextTakeover: boolean;
62
- threshold: number;
63
- zlibDeflateOptions: object;
64
- zlibInflateOptions: object;
65
- }, isServer: boolean, maxPayload: number);
66
- /**
67
- * @type {String}
68
- */
69
- static get extensionName(): string;
70
- /**
71
- * Create an extension negotiation offer.
72
- *
73
- * @return {Object} Extension parameters
74
- * @public
75
- */
76
- offer(): OfferParams;
77
- /**
78
- * Accept an extension negotiation offer/response.
79
- *
80
- * @param {Array} configurations The extension negotiation offers/reponse
81
- * @return {Object} Accepted configuration
82
- * @public
83
- */
84
- accept(configurations: unknown[]): null;
85
- /**
86
- * Releases all resources used by the extension.
87
- *
88
- * @public
89
- */
90
- cleanup(): void;
91
- /**
92
- * Accept an extension negotiation offer.
93
- *
94
- * @param {Array} offers The extension negotiation offers
95
- * @return {Object} Accepted configuration
96
- * @private
97
- */
98
- acceptAsServer(offers: any): any;
99
- /**
100
- * Accept the extension negotiation response.
101
- *
102
- * @param {Array} response The extension negotiation response
103
- * @return {Object} Accepted configuration
104
- * @private
105
- */
106
- acceptAsClient(response: any): any;
107
- /**
108
- * Normalize parameters.
109
- *
110
- * @param {Array} configurations The extension negotiation offers/reponse
111
- * @return {Array} The offers/response with normalized parameters
112
- * @private
113
- */
114
- normalizeParams(configurations: any): any;
115
- /**
116
- * Decompress data. Concurrency limited.
117
- *
118
- * @param {Buffer} data Compressed data
119
- * @param {Boolean} fin Specifies whether or not this is the last fragment
120
- * @param {Function} callback Callback
121
- * @public
122
- */
123
- decompress(data: Buffer, fin: boolean, callback: Callback): void;
124
- /**
125
- * Compress data. Concurrency limited.
126
- *
127
- * @param {(Buffer|String)} data Data to compress
128
- * @param {Boolean} fin Specifies whether or not this is the last fragment
129
- * @param {Function} callback Callback
130
- * @public
131
- */
132
- compress(data: Buffer | string, fin: boolean, callback: Callback): void;
133
- /**
134
- * Decompress data.
135
- *
136
- * @param {Buffer} data Compressed data
137
- * @param {Boolean} fin Specifies whether or not this is the last fragment
138
- * @param {Function} callback Callback
139
- * @private
140
- */
141
- _decompress(data: Buffer, fin: boolean, callback: Callback): void;
142
- /**
143
- * Compress data.
144
- *
145
- * @param {(Buffer|String)} data Data to compress
146
- * @param {Boolean} fin Specifies whether or not this is the last fragment
147
- * @param {Function} callback Callback
148
- * @private
149
- */
150
- _compress(data: Buffer | string, fin: boolean, callback: Callback): void;
151
- }
152
- export {};
@@ -1,409 +0,0 @@
1
- 'use strict';
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.PerMessageDeflate = void 0;
7
- const zlib_1 = __importDefault(require("zlib"));
8
- const constants_1 = require("./constants");
9
- const limiter_1 = require("./limiter");
10
- const buffer_util_1 = require("./buffer-util");
11
- const TRAILER = Buffer.from([0x00, 0x00, 0xff, 0xff]);
12
- const kPerMessageDeflate = Symbol('permessage-deflate');
13
- const kTotalLength = Symbol('total-length');
14
- const kCallback = Symbol('callback');
15
- const kBuffers = Symbol('buffers');
16
- const kError = Symbol('error');
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
- * permessage-deflate implementation.
27
- */
28
- class PerMessageDeflate {
29
- constructor(options, isServer, maxPayload) {
30
- // eslint-disable-next-line no-bitwise
31
- this._maxPayload = maxPayload | 0;
32
- this._options = options || {};
33
- this._threshold =
34
- // eslint-disable-next-line no-negated-condition
35
- this._options.threshold !== undefined ? this._options.threshold : 1024;
36
- this._isServer = Boolean(isServer);
37
- this._deflate = null;
38
- this._inflate = null;
39
- this.params = null;
40
- if (!zlibLimiter) {
41
- const concurrency =
42
- // eslint-disable-next-line no-negated-condition
43
- this._options.concurrencyLimit !== undefined
44
- ? this._options.concurrencyLimit
45
- : 10;
46
- zlibLimiter = new limiter_1.Limiter(concurrency);
47
- }
48
- }
49
- /**
50
- * @type {String}
51
- */
52
- static get extensionName() {
53
- return 'permessage-deflate';
54
- }
55
- /**
56
- * Create an extension negotiation offer.
57
- *
58
- * @return {Object} Extension parameters
59
- * @public
60
- */
61
- offer() {
62
- const params = {};
63
- if (this._options.serverNoContextTakeover) {
64
- params.server_no_context_takeover = true;
65
- }
66
- if (this._options.clientNoContextTakeover) {
67
- params.client_no_context_takeover = true;
68
- }
69
- if (this._options.serverMaxWindowBits) {
70
- params.server_max_window_bits = this._options.serverMaxWindowBits;
71
- }
72
- if (this._options.clientMaxWindowBits) {
73
- params.client_max_window_bits = this._options.clientMaxWindowBits;
74
- // eslint-disable-next-line no-eq-null, eqeqeq
75
- }
76
- else if (this._options.clientMaxWindowBits == null) {
77
- params.client_max_window_bits = true;
78
- }
79
- return params;
80
- }
81
- /**
82
- * Accept an extension negotiation offer/response.
83
- *
84
- * @param {Array} configurations The extension negotiation offers/reponse
85
- * @return {Object} Accepted configuration
86
- * @public
87
- */
88
- accept(configurations) {
89
- configurations = this.normalizeParams(configurations);
90
- this.params = this._isServer
91
- ? this.acceptAsServer(configurations)
92
- : this.acceptAsClient(configurations);
93
- return this.params;
94
- }
95
- /**
96
- * Releases all resources used by the extension.
97
- *
98
- * @public
99
- */
100
- cleanup() {
101
- if (this._inflate) {
102
- this._inflate.close();
103
- this._inflate = null;
104
- }
105
- if (this._deflate) {
106
- const callback = this._deflate[kCallback];
107
- this._deflate.close();
108
- this._deflate = null;
109
- if (callback) {
110
- callback(new Error('The deflate stream was closed while data was being processed'));
111
- }
112
- }
113
- }
114
- /**
115
- * Accept an extension negotiation offer.
116
- *
117
- * @param {Array} offers The extension negotiation offers
118
- * @return {Object} Accepted configuration
119
- * @private
120
- */
121
- acceptAsServer(offers) {
122
- const opts = this._options;
123
- const accepted = offers.find((params) => {
124
- if ((opts.serverNoContextTakeover === false &&
125
- params.server_no_context_takeover) ||
126
- (params.server_max_window_bits &&
127
- (opts.serverMaxWindowBits === false ||
128
- (typeof opts.serverMaxWindowBits === 'number' &&
129
- opts.serverMaxWindowBits > params.server_max_window_bits))) ||
130
- (typeof opts.clientMaxWindowBits === 'number' &&
131
- !params.client_max_window_bits)) {
132
- return false;
133
- }
134
- return true;
135
- });
136
- if (!accepted) {
137
- throw new Error('None of the extension offers can be accepted');
138
- }
139
- if (opts.serverNoContextTakeover) {
140
- accepted.server_no_context_takeover = true;
141
- }
142
- if (opts.clientNoContextTakeover) {
143
- accepted.client_no_context_takeover = true;
144
- }
145
- if (typeof opts.serverMaxWindowBits === 'number') {
146
- accepted.server_max_window_bits = opts.serverMaxWindowBits;
147
- }
148
- if (typeof opts.clientMaxWindowBits === 'number') {
149
- accepted.client_max_window_bits = opts.clientMaxWindowBits;
150
- }
151
- else if (accepted.client_max_window_bits === true ||
152
- opts.clientMaxWindowBits === false) {
153
- delete accepted.client_max_window_bits;
154
- }
155
- return accepted;
156
- }
157
- /**
158
- * Accept the extension negotiation response.
159
- *
160
- * @param {Array} response The extension negotiation response
161
- * @return {Object} Accepted configuration
162
- * @private
163
- */
164
- acceptAsClient(response) {
165
- const params = response[0];
166
- if (this._options.clientNoContextTakeover === false &&
167
- params.client_no_context_takeover) {
168
- throw new Error('Unexpected parameter "client_no_context_takeover"');
169
- }
170
- if (!params.client_max_window_bits) {
171
- if (typeof this._options.clientMaxWindowBits === 'number') {
172
- params.client_max_window_bits = this._options.clientMaxWindowBits;
173
- }
174
- }
175
- else if (this._options.clientMaxWindowBits === false ||
176
- (typeof this._options.clientMaxWindowBits === 'number' &&
177
- params.client_max_window_bits > this._options.clientMaxWindowBits)) {
178
- throw new Error('Unexpected or invalid parameter "client_max_window_bits"');
179
- }
180
- return params;
181
- }
182
- /**
183
- * Normalize parameters.
184
- *
185
- * @param {Array} configurations The extension negotiation offers/reponse
186
- * @return {Array} The offers/response with normalized parameters
187
- * @private
188
- */
189
- normalizeParams(configurations) {
190
- configurations.forEach((params) => {
191
- Object.keys(params).forEach((key) => {
192
- let value = params[key];
193
- if (value.length > 1) {
194
- throw new Error(`Parameter "${key}" must have only a single value`);
195
- }
196
- value = value[0];
197
- if (key === 'client_max_window_bits') {
198
- if (value !== true) {
199
- const num = Number(value);
200
- if (!Number.isInteger(num) || num < 8 || num > 15) {
201
- throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
202
- }
203
- value = num;
204
- }
205
- else if (!this._isServer) {
206
- throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
207
- }
208
- }
209
- else if (key === 'server_max_window_bits') {
210
- const num = Number(value);
211
- if (!Number.isInteger(num) || num < 8 || num > 15) {
212
- throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
213
- }
214
- value = num;
215
- }
216
- else if (key === 'client_no_context_takeover' ||
217
- key === 'server_no_context_takeover') {
218
- if (value !== true) {
219
- throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
220
- }
221
- }
222
- else {
223
- throw new Error(`Unknown parameter "${key}"`);
224
- }
225
- params[key] = value;
226
- });
227
- });
228
- return configurations;
229
- }
230
- /**
231
- * Decompress data. Concurrency limited.
232
- *
233
- * @param {Buffer} data Compressed data
234
- * @param {Boolean} fin Specifies whether or not this is the last fragment
235
- * @param {Function} callback Callback
236
- * @public
237
- */
238
- decompress(data, fin, callback) {
239
- zlibLimiter.add((done) => {
240
- this._decompress(data, fin, (err, result) => {
241
- done();
242
- callback(err, result);
243
- });
244
- });
245
- }
246
- /**
247
- * Compress data. Concurrency limited.
248
- *
249
- * @param {(Buffer|String)} data Data to compress
250
- * @param {Boolean} fin Specifies whether or not this is the last fragment
251
- * @param {Function} callback Callback
252
- * @public
253
- */
254
- compress(data, fin, callback) {
255
- zlibLimiter.add((done) => {
256
- this._compress(data, fin, (err, result) => {
257
- done();
258
- callback(err, result);
259
- });
260
- });
261
- }
262
- /**
263
- * Decompress data.
264
- *
265
- * @param {Buffer} data Compressed data
266
- * @param {Boolean} fin Specifies whether or not this is the last fragment
267
- * @param {Function} callback Callback
268
- * @private
269
- */
270
- _decompress(data, fin, callback) {
271
- const endpoint = this._isServer ? 'client' : 'server';
272
- if (!this._inflate) {
273
- const key = `${endpoint}_max_window_bits`;
274
- const windowBits =
275
- // eslint-disable-next-line no-negated-condition
276
- typeof this.params[key] !== 'number'
277
- ? zlib_1.default.Z_DEFAULT_WINDOWBITS
278
- : this.params[key];
279
- this._inflate = zlib_1.default.createInflateRaw({
280
- ...this._options.zlibInflateOptions,
281
- windowBits,
282
- });
283
- this._inflate[kPerMessageDeflate] = this;
284
- this._inflate[kTotalLength] = 0;
285
- this._inflate[kBuffers] = [];
286
- this._inflate.on('error', inflateOnError);
287
- this._inflate.on('data', inflateOnData);
288
- }
289
- this._inflate[kCallback] = callback;
290
- this._inflate.write(data);
291
- if (fin)
292
- this._inflate.write(TRAILER);
293
- this._inflate.flush(() => {
294
- const err = this._inflate[kError];
295
- if (err) {
296
- this._inflate.close();
297
- this._inflate = null;
298
- callback(err);
299
- return;
300
- }
301
- const data = (0, buffer_util_1.concat)(this._inflate[kBuffers], this._inflate[kTotalLength]);
302
- if (this._inflate._readableState.endEmitted) {
303
- this._inflate.close();
304
- this._inflate = null;
305
- }
306
- else {
307
- this._inflate[kTotalLength] = 0;
308
- this._inflate[kBuffers] = [];
309
- if (fin && this.params[`${endpoint}_no_context_takeover`]) {
310
- this._inflate.reset();
311
- }
312
- }
313
- callback(null, data);
314
- });
315
- }
316
- /**
317
- * Compress data.
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
- * @private
323
- */
324
- _compress(data, fin, callback) {
325
- const endpoint = this._isServer ? 'server' : 'client';
326
- if (!this._deflate) {
327
- const key = `${endpoint}_max_window_bits`;
328
- const windowBits = typeof this.params[key] !== 'number'
329
- ? zlib_1.default.Z_DEFAULT_WINDOWBITS
330
- : this.params[key];
331
- this._deflate = zlib_1.default.createDeflateRaw({
332
- ...this._options.zlibDeflateOptions,
333
- windowBits,
334
- });
335
- this._deflate[kTotalLength] = 0;
336
- this._deflate[kBuffers] = [];
337
- this._deflate.on('data', deflateOnData);
338
- }
339
- this._deflate[kCallback] = callback;
340
- this._deflate.write(data);
341
- this._deflate.flush(zlib_1.default.Z_SYNC_FLUSH, () => {
342
- if (!this._deflate) {
343
- //
344
- // The deflate stream was closed while data was being processed.
345
- //
346
- return;
347
- }
348
- let _data = (0, buffer_util_1.concat)(this._deflate[kBuffers], this._deflate[kTotalLength]);
349
- if (fin)
350
- _data = _data.slice(0, _data.length - 4);
351
- //
352
- // Ensure that the callback will not be called again in
353
- // `PerMessageDeflate#cleanup()`.
354
- //
355
- this._deflate[kCallback] = null;
356
- this._deflate[kTotalLength] = 0;
357
- this._deflate[kBuffers] = [];
358
- if (fin && this.params[`${endpoint}_no_context_takeover`]) {
359
- this._deflate.reset();
360
- }
361
- callback(null, _data);
362
- });
363
- }
364
- }
365
- exports.PerMessageDeflate = PerMessageDeflate;
366
- /**
367
- * The listener of the `zlib.DeflateRaw` stream `'data'` event.
368
- *
369
- * @param {Buffer} chunk A chunk of data
370
- * @private
371
- */
372
- function deflateOnData(chunk) {
373
- this[kBuffers].push(chunk);
374
- this[kTotalLength] += chunk.length;
375
- }
376
- /**
377
- * The listener of the `zlib.InflateRaw` stream `'data'` event.
378
- *
379
- * @param {Buffer} chunk A chunk of data
380
- * @private
381
- */
382
- function inflateOnData(chunk) {
383
- this[kTotalLength] += chunk.length;
384
- if (this[kPerMessageDeflate]._maxPayload < 1 ||
385
- this[kTotalLength] <= this[kPerMessageDeflate]._maxPayload) {
386
- this[kBuffers].push(chunk);
387
- return;
388
- }
389
- this[kError] = new RangeError('Max payload size exceeded');
390
- this[kError].code = 'WS_ERR_UNSUPPORTED_MESSAGE_LENGTH';
391
- this[kError][constants_1.constants.kStatusCode] = 1009;
392
- this.removeListener('data', inflateOnData);
393
- this.reset();
394
- }
395
- /**
396
- * The listener of the `zlib.InflateRaw` stream `'error'` event.
397
- *
398
- * @param {Error} err The emitted error
399
- * @private
400
- */
401
- function inflateOnError(err) {
402
- //
403
- // There is no need to call `Zlib#close()` as the handle is automatically
404
- // closed when an error is emitted.
405
- //
406
- this[kPerMessageDeflate]._inflate = null;
407
- err[constants_1.constants.kStatusCode] = 1007;
408
- this[kCallback](err);
409
- }