videomail-client 16.2.0 → 16.4.1

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.
@@ -1648,7 +1648,7 @@ var __webpack_modules__ = {
1648
1648
  return 0 === comparison || comparison & DOCUMENT_POSITION_CONTAINED_BY;
1649
1649
  }
1650
1650
  },
1651
- TU (__unused_rspack_module, exports1, __webpack_require__) {
1651
+ T (__unused_rspack_module, exports1, __webpack_require__) {
1652
1652
  function isArray(arg) {
1653
1653
  if (Array.isArray) return Array.isArray(arg);
1654
1654
  return '[object Array]' === objectToString(arg);
@@ -2113,7 +2113,7 @@ var __webpack_modules__ = {
2113
2113
  return keys;
2114
2114
  };
2115
2115
  module.exports = Duplex;
2116
- var util = Object.create(__webpack_require__("TU"));
2116
+ var util = Object.create(__webpack_require__("T"));
2117
2117
  util.inherits = __webpack_require__("c5");
2118
2118
  var Readable = __webpack_require__("rp");
2119
2119
  var Writable = __webpack_require__("pv");
@@ -2167,7 +2167,7 @@ var __webpack_modules__ = {
2167
2167
  "use strict";
2168
2168
  module.exports = PassThrough;
2169
2169
  var Transform = __webpack_require__("It");
2170
- var util = Object.create(__webpack_require__("TU"));
2170
+ var util = Object.create(__webpack_require__("T"));
2171
2171
  util.inherits = __webpack_require__("c5");
2172
2172
  util.inherits(PassThrough, Transform);
2173
2173
  function PassThrough(options) {
@@ -2199,7 +2199,7 @@ var __webpack_modules__ = {
2199
2199
  function _isUint8Array(obj) {
2200
2200
  return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
2201
2201
  }
2202
- var util = Object.create(__webpack_require__("TU"));
2202
+ var util = Object.create(__webpack_require__("T"));
2203
2203
  util.inherits = __webpack_require__("c5");
2204
2204
  var debugUtil = __webpack_require__("AN");
2205
2205
  var debug = void 0;
@@ -2826,7 +2826,7 @@ var __webpack_modules__ = {
2826
2826
  "use strict";
2827
2827
  module.exports = Transform;
2828
2828
  var Duplex = __webpack_require__("OO");
2829
- var util = Object.create(__webpack_require__("TU"));
2829
+ var util = Object.create(__webpack_require__("T"));
2830
2830
  util.inherits = __webpack_require__("c5");
2831
2831
  util.inherits(Transform, Duplex);
2832
2832
  function afterTransform(er, data) {
@@ -2926,7 +2926,7 @@ var __webpack_modules__ = {
2926
2926
  ].indexOf(process.version.slice(0, 5)) > -1 ? setImmediate : pna.nextTick;
2927
2927
  var Duplex;
2928
2928
  Writable.WritableState = WritableState;
2929
- var util = Object.create(__webpack_require__("TU"));
2929
+ var util = Object.create(__webpack_require__("T"));
2930
2930
  util.inherits = __webpack_require__("c5");
2931
2931
  var internalUtil = {
2932
2932
  deprecate: __webpack_require__("NQ")
@@ -5948,7 +5948,8 @@ var __webpack_modules__ = {
5948
5948
  var percentTwenties = /%20/g;
5949
5949
  var Format = {
5950
5950
  RFC1738: 'RFC1738',
5951
- RFC3986: 'RFC3986'
5951
+ RFC3986: 'RFC3986',
5952
+ WHATWG: 'WHATWG'
5952
5953
  };
5953
5954
  module.exports = {
5954
5955
  default: Format.RFC3986,
@@ -5958,10 +5959,14 @@ var __webpack_modules__ = {
5958
5959
  },
5959
5960
  RFC3986: function(value) {
5960
5961
  return String(value);
5962
+ },
5963
+ WHATWG: function(value) {
5964
+ return replace.call(value, percentTwenties, '+');
5961
5965
  }
5962
5966
  },
5963
5967
  RFC1738: Format.RFC1738,
5964
- RFC3986: Format.RFC3986
5968
+ RFC3986: Format.RFC3986,
5969
+ WHATWG: Format.WHATWG
5965
5970
  };
5966
5971
  },
5967
5972
  b (module, __unused_rspack_exports, __webpack_require__) {
@@ -6022,8 +6027,8 @@ var __webpack_modules__ = {
6022
6027
  target: copy
6023
6028
  };
6024
6029
  }
6025
- target[keys[j]] = copies.get(value);
6026
- } else target[keys[j]] = value;
6030
+ utils.setProperty(target, keys[j], copies.get(value));
6031
+ } else utils.setProperty(target, keys[j], value);
6027
6032
  }
6028
6033
  }
6029
6034
  return result;
@@ -6070,7 +6075,7 @@ var __webpack_modules__ = {
6070
6075
  }
6071
6076
  return val.split(',');
6072
6077
  }
6073
- if (options.throwOnLimitExceeded && currentArrayLength >= options.arrayLimit) throw new RangeError('Array limit exceeded. Only ' + options.arrayLimit + ' element' + (1 === options.arrayLimit ? '' : 's') + ' allowed in an array.');
6078
+ if (options.throwOnLimitExceeded && currentArrayLength >= options.arrayLimit && currentArrayLength > 0) throw new RangeError('Array limit exceeded. Only ' + options.arrayLimit + ' element' + (1 === options.arrayLimit ? '' : 's') + ' allowed in an array.');
6074
6079
  return val;
6075
6080
  };
6076
6081
  var isoSentinel = 'utf8=%26%2310003%3B';
@@ -6107,11 +6112,13 @@ var __webpack_modules__ = {
6107
6112
  val = options.strictNullHandling ? null : '';
6108
6113
  } else {
6109
6114
  key = options.decoder(part.slice(0, pos), defaults.decoder, charset, 'key');
6110
- if (null !== key) val = utils.maybeMap(parseArrayValue(part.slice(pos + 1), options, isArray(obj[key]) ? obj[key].length : 0), function(encodedVal) {
6115
+ if (null !== key) val = utils.maybeMap(parseArrayValue(part.slice(pos + 1), options, isArray(obj[key]) && ('combine' === options.duplicates || isEmptyBracketKey) ? obj[key].length : 0), function(encodedVal) {
6111
6116
  return options.decoder(encodedVal, defaults.decoder, charset, 'value');
6112
6117
  });
6113
6118
  }
6114
- if (val && options.interpretNumericEntities && 'iso-8859-1' === charset) val = interpretNumericEntities(String(val));
6119
+ if (val && options.interpretNumericEntities && 'iso-8859-1' === charset) val = utils.maybeMap(val, function(value) {
6120
+ return value ? interpretNumericEntities(String(value)) : value;
6121
+ });
6115
6122
  if (isEmptyBracketKey) val = isArray(val) ? [
6116
6123
  val
6117
6124
  ] : val;
@@ -6140,7 +6147,7 @@ var __webpack_modules__ = {
6140
6147
  __proto__: null
6141
6148
  } : {};
6142
6149
  var cleanRoot = '[' === root.charAt(0) && ']' === root.charAt(root.length - 1) ? root.slice(1, -1) : root;
6143
- var decodedRoot = options.decodeDotInKeys ? cleanRoot.replace(/%2E/g, '.') : cleanRoot;
6150
+ var decodedRoot = options.decodeDotInKeys ? cleanRoot.replace(/%2E/gi, '.') : cleanRoot;
6144
6151
  var index = parseInt(decodedRoot, 10);
6145
6152
  var isValidArrayIndex = !isNaN(index) && root !== decodedRoot && String(index) === decodedRoot && index >= 0 && options.parseArrays;
6146
6153
  if (options.parseArrays || '' !== decodedRoot) {
@@ -6402,7 +6409,7 @@ var __webpack_modules__ = {
6402
6409
  }
6403
6410
  var encodedPrefix = String(prefix);
6404
6411
  var adjustedPrefix = commaRoundTrip && isArray(obj) && 1 === obj.length ? encodedPrefix + '[]' : encodedPrefix;
6405
- if (allowEmptyArrays && isArray(obj) && 0 === obj.length && 0 === Object.keys(obj).length) return adjustedPrefix + '[]';
6412
+ if (allowEmptyArrays && isArray(obj) && 0 === obj.length && 0 === Object.keys(obj).length) return formatter(encoder && !encodeValuesOnly ? encoder(adjustedPrefix, defaults.encoder, charset, 'key', format) : adjustedPrefix) + '[]';
6406
6413
  for(var j = 0; j < objKeys.length; ++j){
6407
6414
  var key = objKeys[j];
6408
6415
  var value = 'object' == typeof key && key && void 0 !== key.value ? key.value : obj[key];
@@ -6468,7 +6475,7 @@ var __webpack_modules__ = {
6468
6475
  filter = options.filter;
6469
6476
  obj = filter('', obj);
6470
6477
  } else if (isArray(options.filter)) {
6471
- filter = options.filter;
6478
+ filter = options.filter.slice();
6472
6479
  objKeys = filter;
6473
6480
  }
6474
6481
  var keys = [];
@@ -6484,7 +6491,7 @@ var __webpack_modules__ = {
6484
6491
  var value = obj[key];
6485
6492
  if (!options.skipNulls || null !== value) {
6486
6493
  var encodedKey = options.encodeDotInKeys ? String(key).replace(/\./g, '%2E') : String(key);
6487
- pushToArray(keys, stringify(value, encodedKey, generateArrayPrefix, commaRoundTrip, options.allowEmptyArrays, options.strictNullHandling, options.skipNulls, options.encodeDotInKeys, options.encode ? options.encoder : null, options.filter, options.sort, options.allowDots, options.serializeDate, options.format, options.formatter, options.encodeValuesOnly, options.charset, sideChannel, options.depth, 0));
6494
+ pushToArray(keys, stringify(value, encodedKey, generateArrayPrefix, commaRoundTrip, options.allowEmptyArrays, options.strictNullHandling, options.skipNulls, options.encodeDotInKeys, options.encode ? options.encoder : null, filter, options.sort, options.allowDots, options.serializeDate, options.format, options.formatter, options.encodeValuesOnly, options.charset, sideChannel, options.depth, 0));
6488
6495
  }
6489
6496
  }
6490
6497
  }
@@ -6733,7 +6740,7 @@ var __webpack_modules__ = {
6733
6740
  var arr = [];
6734
6741
  for(var i = 0; i < segment.length; ++i){
6735
6742
  var c = segment.charCodeAt(i);
6736
- if (0x2D === c || 0x2E === c || 0x5F === c || 0x7E === c || c >= 0x30 && c <= 0x39 || c >= 0x41 && c <= 0x5A || c >= 0x61 && c <= 0x7A || format === formats.RFC1738 && (0x28 === c || 0x29 === c)) {
6743
+ if (0x2D === c || 0x2E === c || 0x5F === c || 0x7E === c && format !== formats.WHATWG || c >= 0x30 && c <= 0x39 || c >= 0x41 && c <= 0x5A || c >= 0x61 && c <= 0x7A || format === formats.RFC1738 && (0x28 === c || 0x29 === c) || format === formats.WHATWG && 0x2A === c) {
6737
6744
  arr[arr.length] = segment.charAt(i);
6738
6745
  continue;
6739
6746
  }
@@ -6749,9 +6756,12 @@ var __webpack_modules__ = {
6749
6756
  arr[arr.length] = hexTable[0xE0 | c >> 12] + hexTable[0x80 | c >> 6 & 0x3F] + hexTable[0x80 | 0x3F & c];
6750
6757
  continue;
6751
6758
  }
6752
- i += 1;
6753
- c = 0x10000 + ((0x3FF & c) << 10 | 0x3FF & segment.charCodeAt(i));
6754
- arr[arr.length] = hexTable[0xF0 | c >> 18] + hexTable[0x80 | c >> 12 & 0x3F] + hexTable[0x80 | c >> 6 & 0x3F] + hexTable[0x80 | 0x3F & c];
6759
+ var next = segment.charCodeAt(i + 1);
6760
+ if (c <= 0xDBFF && next >= 0xDC00 && next <= 0xDFFF) {
6761
+ i += 1;
6762
+ c = 0x10000 + ((0x3FF & c) << 10 | 0x3FF & next);
6763
+ arr[arr.length] = hexTable[0xF0 | c >> 18] + hexTable[0x80 | c >> 12 & 0x3F] + hexTable[0x80 | c >> 6 & 0x3F] + hexTable[0x80 | 0x3F & c];
6764
+ } else arr[arr.length] = '%EF%BF%BD';
6755
6765
  }
6756
6766
  out += arr.join('');
6757
6767
  }
@@ -6837,6 +6847,7 @@ var __webpack_modules__ = {
6837
6847
  markOverflow: markOverflow,
6838
6848
  maybeMap: maybeMap,
6839
6849
  merge: merge,
6850
+ setProperty: setProperty,
6840
6851
  toCoercible: toCoercible
6841
6852
  };
6842
6853
  },
@@ -7189,7 +7200,7 @@ var __webpack_modules__ = {
7189
7200
  const qs = __webpack_require__("b");
7190
7201
  const RequestBase = __webpack_require__("d");
7191
7202
  const { isObject, mixin, hasOwn, isSafeKey } = __webpack_require__("Dp");
7192
- const ResponseBase = __webpack_require__("e");
7203
+ const ResponseBase = __webpack_require__("es");
7193
7204
  const Agent = __webpack_require__("pf");
7194
7205
  function noop() {}
7195
7206
  module.exports = function(method, url) {
@@ -7903,7 +7914,7 @@ var __webpack_modules__ = {
7903
7914
  }, this._responseTimeout);
7904
7915
  };
7905
7916
  },
7906
- e (module, __unused_rspack_exports, __webpack_require__) {
7917
+ es (module, __unused_rspack_exports, __webpack_require__) {
7907
7918
  "use strict";
7908
7919
  const utils = __webpack_require__("Dp");
7909
7920
  module.exports = ResponseBase;
@@ -8727,7 +8738,7 @@ var __webpack_modules__ = {
8727
8738
  return keys;
8728
8739
  };
8729
8740
  module.exports = Duplex;
8730
- var util = Object.create(__webpack_require__("TU"));
8741
+ var util = Object.create(__webpack_require__("T"));
8731
8742
  util.inherits = __webpack_require__("c5");
8732
8743
  var Readable = __webpack_require__("w");
8733
8744
  var Writable = __webpack_require__("S5");
@@ -8781,7 +8792,7 @@ var __webpack_modules__ = {
8781
8792
  "use strict";
8782
8793
  module.exports = PassThrough;
8783
8794
  var Transform = __webpack_require__("Ge");
8784
- var util = Object.create(__webpack_require__("TU"));
8795
+ var util = Object.create(__webpack_require__("T"));
8785
8796
  util.inherits = __webpack_require__("c5");
8786
8797
  util.inherits(PassThrough, Transform);
8787
8798
  function PassThrough(options) {
@@ -8813,7 +8824,7 @@ var __webpack_modules__ = {
8813
8824
  function _isUint8Array(obj) {
8814
8825
  return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
8815
8826
  }
8816
- var util = Object.create(__webpack_require__("TU"));
8827
+ var util = Object.create(__webpack_require__("T"));
8817
8828
  util.inherits = __webpack_require__("c5");
8818
8829
  var debugUtil = __webpack_require__("eD");
8819
8830
  var debug = void 0;
@@ -9440,7 +9451,7 @@ var __webpack_modules__ = {
9440
9451
  "use strict";
9441
9452
  module.exports = Transform;
9442
9453
  var Duplex = __webpack_require__("S7");
9443
- var util = Object.create(__webpack_require__("TU"));
9454
+ var util = Object.create(__webpack_require__("T"));
9444
9455
  util.inherits = __webpack_require__("c5");
9445
9456
  util.inherits(Transform, Duplex);
9446
9457
  function afterTransform(er, data) {
@@ -9540,7 +9551,7 @@ var __webpack_modules__ = {
9540
9551
  ].indexOf(process.version.slice(0, 5)) > -1 ? setImmediate : pna.nextTick;
9541
9552
  var Duplex;
9542
9553
  Writable.WritableState = WritableState;
9543
- var util = Object.create(__webpack_require__("TU"));
9554
+ var util = Object.create(__webpack_require__("T"));
9544
9555
  util.inherits = __webpack_require__("c5");
9545
9556
  var internalUtil = {
9546
9557
  deprecate: __webpack_require__("NQ")
@@ -11115,7 +11126,7 @@ var __webpack_exports__ = {};
11115
11126
  var client = __webpack_require__("Q");
11116
11127
  var client_default = /*#__PURE__*/ __webpack_require__.n(client);
11117
11128
  var package_namespaceObject = {
11118
- rE: "16.2.0"
11129
+ rE: "16.4.1"
11119
11130
  };
11120
11131
  function isAudioEnabled(options) {
11121
11132
  return Boolean(options.audio.enabled);
@@ -19959,11 +19970,11 @@ var __webpack_exports__ = {};
19959
19970
  const connection = RecorderConnection;
19960
19971
  function createUserMediaConstraints({ options, facingMode, limitedWidth, userMediaParams }) {
19961
19972
  const video = {
19973
+ facingMode: (null == userMediaParams ? void 0 : userMediaParams.switchingFacingMode) || facingMode,
19962
19974
  frameRate: {
19963
19975
  ideal: options.video.fps
19964
19976
  }
19965
19977
  };
19966
- if ((null == userMediaParams ? void 0 : userMediaParams.switchingFacingMode) || (null == userMediaParams ? void 0 : userMediaParams.recovering)) video.facingMode = userMediaParams.switchingFacingMode || facingMode;
19967
19978
  if (options.video.width) video.width = {
19968
19979
  ideal: options.video.width
19969
19980
  };
@@ -20970,6 +20981,50 @@ var __webpack_exports__ = {};
20970
20981
  const esm = esm_src;
20971
20982
  var is_power_of_two = __webpack_require__("dZ");
20972
20983
  var is_power_of_two_default = /*#__PURE__*/ __webpack_require__.n(is_power_of_two);
20984
+ const AUDIO_RECORDER_PROCESSOR_NAME = "videomail-pcm-recorder";
20985
+ function registerAudioRecorderProcessor(name, Processor, register) {
20986
+ class PcmRecorderProcessor extends Processor {
20987
+ process(inputs) {
20988
+ var _inputs_;
20989
+ if (this.recordingId < 0) return false;
20990
+ const channel = null == (_inputs_ = inputs[0]) ? void 0 : _inputs_[0];
20991
+ if (!channel || 0 === this.recordingId) return true;
20992
+ let inputOffset = 0;
20993
+ while(inputOffset < channel.length){
20994
+ const count = Math.min(this.samples.length - this.offset, channel.length - inputOffset);
20995
+ this.samples.set(channel.subarray(inputOffset, inputOffset + count), this.offset);
20996
+ this.offset += count;
20997
+ inputOffset += count;
20998
+ if (this.offset === this.samples.length) {
20999
+ const samples = this.samples;
21000
+ this.port.postMessage({
21001
+ recordingId: this.recordingId,
21002
+ samples
21003
+ }, [
21004
+ samples.buffer
21005
+ ]);
21006
+ this.samples = new Float32Array(this.offset);
21007
+ this.offset = 0;
21008
+ }
21009
+ }
21010
+ return true;
21011
+ }
21012
+ constructor(options){
21013
+ super();
21014
+ this.samples = new Float32Array(options.processorOptions.bufferSize);
21015
+ this.offset = 0;
21016
+ this.recordingId = 0;
21017
+ this.port.onmessage = (event)=>{
21018
+ const recordingId = event.data;
21019
+ if ("number" != typeof recordingId) return;
21020
+ if (!Number.isSafeInteger(recordingId) || recordingId < -1) return;
21021
+ this.recordingId = recordingId;
21022
+ this.offset = 0;
21023
+ };
21024
+ }
21025
+ }
21026
+ register(name, PcmRecorderProcessor);
21027
+ }
20973
21028
  function AudioRecorder_asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
20974
21029
  try {
20975
21030
  var info = gen[key](arg);
@@ -21007,82 +21062,191 @@ var __webpack_exports__ = {};
21007
21062
  return obj;
21008
21063
  }
21009
21064
  const CHANNELS = 1;
21010
- function getAudioContextClass() {
21011
- return window.AudioContext;
21012
- }
21013
- class AudioRecorder {
21014
- hasAudioContext() {
21015
- return Boolean(getAudioContextClass()) && Boolean(this.getAudioContext());
21016
- }
21065
+ const DEFAULT_BUFFER_SIZE = 2048;
21066
+ const MIN_BUFFER_SIZE = 256;
21067
+ const MAX_BUFFER_SIZE = 16384;
21068
+ class AudioRecorder extends util_Despot {
21017
21069
  getAudioContext() {
21018
- if (!this.vcAudioContext) {
21019
- const AudioContext = getAudioContextClass();
21020
- this.vcAudioContext = new AudioContext();
21021
- }
21070
+ if (!this.vcAudioContext) this.vcAudioContext = new window.AudioContext();
21022
21071
  return this.vcAudioContext;
21023
21072
  }
21024
- onAudioProcess(e, cb) {
21073
+ getBufferSize() {
21074
+ const configuredSize = this.options.audio.bufferSize;
21075
+ const bufferSize = "auto" === configuredSize ? DEFAULT_BUFFER_SIZE : configuredSize;
21076
+ if (void 0 === bufferSize) throw error_createError({
21077
+ message: "Audio buffer size is required.",
21078
+ options: this.options
21079
+ });
21080
+ const validBufferSize = Number.isInteger(bufferSize) && bufferSize >= MIN_BUFFER_SIZE && bufferSize <= MAX_BUFFER_SIZE && is_power_of_two_default()(bufferSize);
21081
+ if (!validBufferSize) throw error_createError({
21082
+ message: `Audio buffer size must be a power of two between ${MIN_BUFFER_SIZE} and ${MAX_BUFFER_SIZE}. The current buffer size is ${bufferSize}.`,
21083
+ options: this.options
21084
+ });
21085
+ return bufferSize;
21086
+ }
21087
+ validateVolume() {
21088
+ const { volume } = this.options.audio;
21089
+ const validVolume = Number.isFinite(volume) && volume >= 0 && volume <= 1;
21090
+ if (!validVolume) throw error_createError({
21091
+ message: `Audio volume must be between zero and one. The current volume is ${volume}.`,
21092
+ options: this.options
21093
+ });
21094
+ }
21095
+ revokeModuleUrl() {
21096
+ if (this.moduleUrl) {
21097
+ URL.revokeObjectURL(this.moduleUrl);
21098
+ this.moduleUrl = void 0;
21099
+ }
21100
+ }
21101
+ loadWorklet(context) {
21102
+ return AudioRecorder_async_to_generator(function*() {
21103
+ const source = `(${registerAudioRecorderProcessor.toString()})(${JSON.stringify(AUDIO_RECORDER_PROCESSOR_NAME)}, AudioWorkletProcessor, registerProcessor);`;
21104
+ const moduleUrl = URL.createObjectURL(new Blob([
21105
+ source
21106
+ ], {
21107
+ type: "text/javascript"
21108
+ }));
21109
+ this.moduleUrl = moduleUrl;
21110
+ try {
21111
+ yield context.audioWorklet.addModule(moduleUrl);
21112
+ } finally{
21113
+ if (this.moduleUrl === moduleUrl) this.revokeModuleUrl();
21114
+ }
21115
+ }).call(this);
21116
+ }
21117
+ onAudioProcess(event) {
21118
+ const callback = this.audioCallback;
21119
+ if (!callback) return;
21025
21120
  if (!this.userMedia.isRecording() || this.userMedia.isPaused()) return;
21026
- const float32Array = e.inputBuffer.getChannelData(0);
21027
- cb(new esm(float32Array));
21121
+ const message = event.data;
21122
+ if ("object" != typeof message || null === message) return;
21123
+ if (!("recordingId" in message) || message.recordingId !== this.recordingId) return;
21124
+ if (!("samples" in message) || !(message.samples instanceof Float32Array)) return;
21125
+ if (0 === message.samples.length) return;
21126
+ callback(new esm(message.samples));
21028
21127
  }
21029
21128
  disconnect() {
21030
21129
  var _this_audioInput, _this_volume;
21031
- if (this.scriptProcessor) {
21032
- this.scriptProcessor.onaudioprocess = null;
21033
- this.scriptProcessor.disconnect();
21130
+ if (this.worklet) {
21131
+ this.worklet.port.onmessage = null;
21132
+ this.worklet.onprocessorerror = null;
21133
+ this.worklet.port.postMessage(-1);
21134
+ this.worklet.port.close();
21135
+ this.worklet.disconnect();
21136
+ this.worklet = void 0;
21034
21137
  }
21035
21138
  null == (_this_audioInput = this.audioInput) || _this_audioInput.disconnect();
21036
21139
  null == (_this_volume = this.volume) || _this_volume.disconnect();
21140
+ this.audioInput = void 0;
21141
+ this.volume = void 0;
21142
+ this.audioCallback = void 0;
21143
+ this.recordingId = 0;
21037
21144
  }
21038
21145
  init(localMediaStream) {
21039
- this.options.logger.debug("AudioRecorder: init()");
21040
- this.disconnect();
21041
- const volume = this.getAudioContext().createGain();
21042
- this.volume = volume;
21043
- try {
21044
- this.audioInput = this.getAudioContext().createMediaStreamSource(localMediaStream);
21045
- } catch (exc) {
21046
- throw error_createError({
21047
- message: "Webcam has no audio",
21048
- exc,
21146
+ return AudioRecorder_async_to_generator(function*() {
21147
+ var _this_workletReady;
21148
+ this.options.logger.debug("AudioRecorder: init()");
21149
+ const initializationId = ++this.initializationId;
21150
+ this.disconnect();
21151
+ const bufferSize = this.getBufferSize();
21152
+ this.validateVolume();
21153
+ if ("function" != typeof window.AudioContext) throw error_createError({
21154
+ message: "Audio recording requires Web Audio support.",
21049
21155
  options: this.options
21050
21156
  });
21051
- }
21052
- let { bufferSize } = this.options.audio;
21053
- if ("auto" === bufferSize) bufferSize = util_getBrowser(this.options).isFirefox() ? 512 : 2048;
21054
- if (void 0 === bufferSize || !is_power_of_two_default()(bufferSize)) throw error_createError({
21055
- message: `Audio buffer size must be a power of two. The current buffer size is ${bufferSize}.`,
21056
- options: this.options
21057
- });
21058
- if (!Number.isFinite(this.options.audio.volume) || this.options.audio.volume < 0 || this.options.audio.volume > 1) throw error_createError({
21059
- message: `Audio volume must be between zero and one. The current volume is ${this.options.audio.volume}.`,
21060
- options: this.options
21061
- });
21062
- volume.gain.value = this.options.audio.volume;
21063
- this.scriptProcessor = this.getAudioContext().createScriptProcessor(bufferSize, CHANNELS, CHANNELS);
21064
- this.audioInput.connect(volume);
21065
- volume.connect(this.scriptProcessor);
21066
- this.scriptProcessor.connect(this.getAudioContext().destination);
21157
+ const context = this.getAudioContext();
21158
+ if (void 0 === context.audioWorklet || "function" != typeof window.AudioWorkletNode) throw error_createError({
21159
+ message: "Audio recording requires AudioWorklet support in a secure context.",
21160
+ options: this.options
21161
+ });
21162
+ const workletReady = null != (_this_workletReady = this.workletReady) ? _this_workletReady : this.workletReady = this.loadWorklet(context);
21163
+ try {
21164
+ yield workletReady;
21165
+ } catch (exc) {
21166
+ if (this.workletReady === workletReady) this.workletReady = void 0;
21167
+ if (initializationId !== this.initializationId) return;
21168
+ throw error_createError({
21169
+ message: "Unable to load the audio recorder worklet. Check AudioWorklet and Content Security Policy support for blob: scripts.",
21170
+ cause: exc,
21171
+ options: this.options
21172
+ });
21173
+ }
21174
+ if (initializationId !== this.initializationId) return;
21175
+ try {
21176
+ this.audioInput = context.createMediaStreamSource(localMediaStream);
21177
+ } catch (exc) {
21178
+ throw error_createError({
21179
+ message: "Webcam has no audio",
21180
+ exc,
21181
+ options: this.options
21182
+ });
21183
+ }
21184
+ try {
21185
+ this.volume = context.createGain();
21186
+ this.volume.gain.value = this.options.audio.volume;
21187
+ this.worklet = new window.AudioWorkletNode(context, AUDIO_RECORDER_PROCESSOR_NAME, {
21188
+ channelCount: CHANNELS,
21189
+ channelCountMode: "explicit",
21190
+ outputChannelCount: [
21191
+ CHANNELS
21192
+ ],
21193
+ processorOptions: {
21194
+ bufferSize
21195
+ }
21196
+ });
21197
+ this.worklet.port.onmessage = (event)=>{
21198
+ this.onAudioProcess(event);
21199
+ };
21200
+ this.worklet.onprocessorerror = ()=>{
21201
+ this.stop();
21202
+ this.emit("ERROR", {
21203
+ err: error_createError({
21204
+ message: "Audio recording processor failed.",
21205
+ options: this.options
21206
+ })
21207
+ });
21208
+ };
21209
+ this.audioInput.connect(this.volume);
21210
+ this.volume.connect(this.worklet);
21211
+ this.worklet.connect(context.destination);
21212
+ } catch (exc) {
21213
+ this.disconnect();
21214
+ throw error_createError({
21215
+ message: "Failed to connect the audio recorder.",
21216
+ exc,
21217
+ options: this.options
21218
+ });
21219
+ }
21220
+ }).call(this);
21067
21221
  }
21068
21222
  record(cb) {
21069
21223
  this.options.logger.debug("AudioRecorder: record()");
21070
- if (this.scriptProcessor) this.scriptProcessor.onaudioprocess = (e)=>{
21071
- this.onAudioProcess(e, cb);
21072
- };
21224
+ this.audioCallback = cb;
21225
+ this.updateRecordingState();
21226
+ }
21227
+ updateRecordingState() {
21228
+ if (!this.worklet) return;
21229
+ const shouldRecord = Boolean(this.audioCallback) && this.userMedia.isRecording() && !this.userMedia.isPaused();
21230
+ this.recordingId = shouldRecord ? ++this.recordingSequence : 0;
21231
+ this.worklet.port.postMessage(this.recordingId);
21073
21232
  }
21074
21233
  resume() {
21075
21234
  return AudioRecorder_async_to_generator(function*() {
21076
- const context = this.getAudioContext();
21235
+ const context = this.vcAudioContext;
21236
+ if (!context) return;
21077
21237
  if ("running" !== context.state) yield context.resume();
21078
21238
  }).call(this);
21079
21239
  }
21080
21240
  stop() {
21081
21241
  this.options.logger.debug("AudioRecorder: stop()");
21242
+ this.initializationId++;
21082
21243
  this.disconnect();
21083
- if (this.hasAudioContext()) this.getAudioContext().close().then(()=>{
21244
+ this.revokeModuleUrl();
21245
+ const context = this.vcAudioContext;
21246
+ this.vcAudioContext = void 0;
21247
+ this.workletReady = void 0;
21248
+ if (context && "closed" !== context.state) context.close().then(()=>{
21084
21249
  this.options.logger.debug("AudioRecorder: audio context is closed");
21085
- this.vcAudioContext = void 0;
21086
21250
  }).catch((err)=>{
21087
21251
  if (err instanceof Error) return void this.options.logger.error(error_createError({
21088
21252
  err,
@@ -21092,17 +21256,11 @@ var __webpack_exports__ = {};
21092
21256
  });
21093
21257
  }
21094
21258
  getSampleRate() {
21095
- if (this.hasAudioContext()) return this.getAudioContext().sampleRate;
21259
+ if ("function" == typeof window.AudioContext) return this.getAudioContext().sampleRate;
21096
21260
  return -1;
21097
21261
  }
21098
21262
  constructor(userMedia, options){
21099
- AudioRecorder_define_property(this, "scriptProcessor", void 0);
21100
- AudioRecorder_define_property(this, "audioInput", void 0);
21101
- AudioRecorder_define_property(this, "volume", void 0);
21102
- AudioRecorder_define_property(this, "vcAudioContext", void 0);
21103
- AudioRecorder_define_property(this, "userMedia", void 0);
21104
- AudioRecorder_define_property(this, "options", void 0);
21105
- this.options = options;
21263
+ super("AudioRecorder", options), AudioRecorder_define_property(this, "userMedia", void 0), AudioRecorder_define_property(this, "worklet", void 0), AudioRecorder_define_property(this, "audioInput", void 0), AudioRecorder_define_property(this, "volume", void 0), AudioRecorder_define_property(this, "vcAudioContext", void 0), AudioRecorder_define_property(this, "workletReady", void 0), AudioRecorder_define_property(this, "moduleUrl", void 0), AudioRecorder_define_property(this, "audioCallback", void 0), AudioRecorder_define_property(this, "initializationId", 0), AudioRecorder_define_property(this, "recordingSequence", 0), AudioRecorder_define_property(this, "recordingId", 0);
21106
21264
  this.userMedia = userMedia;
21107
21265
  }
21108
21266
  }
@@ -21287,28 +21445,34 @@ var __webpack_exports__ = {};
21287
21445
  var _this_rawVisualUserMedia;
21288
21446
  const readyState = null == (_this_rawVisualUserMedia = this.rawVisualUserMedia) ? void 0 : _this_rawVisualUserMedia.readyState;
21289
21447
  this.options.logger.debug(`UserMedia: fireCallbacks(readyState=${readyState}, onPlayReached=${this.onPlayReached}, onLoadedMetaDataReached=${this.onLoadedMetaDataReached})`);
21290
- if (this.onPlayReached && this.onLoadedMetaDataReached) if (this.audioRecorder) try {
21291
- this.audioRecorder.init(localMediaStream);
21292
- const onAudioReady = ()=>{
21293
- var _this_clearInitializationListeners, _this;
21294
- if (initializationId !== this.initializationId || this.currentVisualStream !== localMediaStream) return;
21295
- if (this.recording) this.audioRecord(audioCallback);
21296
- else this.on("SENDING_FIRST_FRAME", ()=>{
21297
- this.audioRecord(audioCallback);
21298
- });
21299
- null == (_this_clearInitializationListeners = (_this = this).clearInitializationListeners) || _this_clearInitializationListeners.call(_this);
21300
- videoCallback();
21301
- };
21302
- if (null == params ? void 0 : params.recovering) this.audioRecorder.resume().then(onAudioReady).catch(endedEarlyCallback);
21303
- else onAudioReady();
21304
- } catch (exc) {
21305
- unloadAllEventListeners();
21306
- this.stop(void 0, {
21307
- preserveRecordingState: Boolean(null == params ? void 0 : params.recovering)
21308
- });
21309
- endedEarlyCallback(exc);
21310
- }
21311
- else {
21448
+ if (this.onPlayReached && this.onLoadedMetaDataReached) if (this.audioRecorder) {
21449
+ const initializeAudio = (audioRecorder)=>userMedia_async_to_generator(function*() {
21450
+ try {
21451
+ yield audioRecorder.init(localMediaStream);
21452
+ if (initializationId !== this.initializationId || this.currentVisualStream !== localMediaStream) return;
21453
+ const onAudioReady = ()=>{
21454
+ var _this_clearInitializationListeners, _this;
21455
+ if (initializationId !== this.initializationId || this.currentVisualStream !== localMediaStream) return;
21456
+ if (this.recording) this.audioRecord(audioCallback);
21457
+ else this.on("SENDING_FIRST_FRAME", ()=>{
21458
+ this.audioRecord(audioCallback);
21459
+ });
21460
+ null == (_this_clearInitializationListeners = (_this = this).clearInitializationListeners) || _this_clearInitializationListeners.call(_this);
21461
+ videoCallback();
21462
+ };
21463
+ if (null == params ? void 0 : params.recovering) yield audioRecorder.resume();
21464
+ onAudioReady();
21465
+ } catch (exc) {
21466
+ if (initializationId !== this.initializationId) return;
21467
+ unloadAllEventListeners();
21468
+ this.stop(void 0, {
21469
+ preserveRecordingState: Boolean(null == params ? void 0 : params.recovering)
21470
+ });
21471
+ endedEarlyCallback(exc);
21472
+ }
21473
+ }).call(this);
21474
+ initializeAudio(this.audioRecorder);
21475
+ } else {
21312
21476
  var _this_clearInitializationListeners, _this;
21313
21477
  null == (_this_clearInitializationListeners = (_this = this).clearInitializationListeners) || _this_clearInitializationListeners.call(_this);
21314
21478
  videoCallback();
@@ -21470,16 +21634,22 @@ var __webpack_exports__ = {};
21470
21634
  return this.rawVisualUserMedia;
21471
21635
  }
21472
21636
  pause() {
21637
+ var _this_audioRecorder;
21473
21638
  this.paused = true;
21639
+ null == (_this_audioRecorder = this.audioRecorder) || _this_audioRecorder.updateRecordingState();
21474
21640
  }
21475
21641
  isPaused() {
21476
21642
  return this.paused;
21477
21643
  }
21478
21644
  resume() {
21645
+ var _this_audioRecorder;
21479
21646
  this.paused = false;
21647
+ null == (_this_audioRecorder = this.audioRecorder) || _this_audioRecorder.updateRecordingState();
21480
21648
  }
21481
21649
  record() {
21650
+ var _this_audioRecorder;
21482
21651
  this.recording = true;
21652
+ null == (_this_audioRecorder = this.audioRecorder) || _this_audioRecorder.updateRecordingState();
21483
21653
  }
21484
21654
  isRecording() {
21485
21655
  return this.recording;