extendable-media-recorder
Advanced tools
Comparing version 7.0.3 to 7.0.4
@@ -25,3 +25,2 @@ (function (global, factory) { | ||
} | ||
return new nativeBlobEventConstructor(type, blobEventInit); | ||
@@ -36,13 +35,10 @@ }; | ||
var offset = 0; | ||
while (offset < dataView.byteLength) { | ||
if (currentElementType === null) { | ||
var lengthAndType = readElementType(dataView, offset); | ||
if (lengthAndType === null) { | ||
break; | ||
} | ||
var length = lengthAndType.length, | ||
type = lengthAndType.type; | ||
type = lengthAndType.type; | ||
currentElementType = type; | ||
@@ -52,12 +48,9 @@ offset += length; | ||
var contentAndLength = readElementContent(dataView, offset, currentElementType, channelCount); | ||
if (contentAndLength === null) { | ||
break; | ||
} | ||
var content = contentAndLength.content, | ||
_length = contentAndLength.length; | ||
_length = contentAndLength.length; | ||
currentElementType = null; | ||
offset += _length; | ||
if (content !== null) { | ||
@@ -68,3 +61,2 @@ contents.push(content); | ||
} | ||
return { | ||
@@ -82,9 +74,6 @@ contents: contents, | ||
var nativeEventTarget = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; | ||
_classCallCheck__default["default"](this, EventTarget); | ||
this._listeners = new WeakMap(); | ||
this._nativeEventTarget = nativeEventTarget === null ? createEventTarget() : nativeEventTarget; | ||
} | ||
_createClass__default["default"](EventTarget, [{ | ||
@@ -95,6 +84,4 @@ key: "addEventListener", | ||
var wrappedEventListener = this._listeners.get(listener); | ||
if (wrappedEventListener === undefined) { | ||
wrappedEventListener = wrapEventListener(this, listener); | ||
if (typeof listener === 'function') { | ||
@@ -104,3 +91,2 @@ this._listeners.set(listener, wrappedEventListener); | ||
} | ||
this._nativeEventTarget.addEventListener(type, wrappedEventListener, options); | ||
@@ -118,7 +104,5 @@ } | ||
var wrappedEventListener = listener === null ? undefined : this._listeners.get(listener); | ||
this._nativeEventTarget.removeEventListener(type, wrappedEventListener === undefined ? null : wrappedEventListener, options); | ||
} | ||
}]); | ||
return EventTarget; | ||
@@ -133,3 +117,2 @@ }(); | ||
} | ||
return window.document.createElement('p'); | ||
@@ -141,3 +124,2 @@ }; | ||
var message = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; | ||
try { | ||
@@ -166,3 +148,4 @@ return new DOMException(message, 'InvalidModificationError'); | ||
var createIsSupportedPromise = function createIsSupportedPromise(window) { | ||
if (window !== null && // Bug #14: Before v14.1 Safari did not support the BlobEvent. | ||
if (window !== null && | ||
// Bug #14: Before v14.1 Safari did not support the BlobEvent. | ||
window.BlobEvent !== undefined && window.MediaStream !== undefined && ( | ||
@@ -182,14 +165,10 @@ /* | ||
} | ||
var canvasElement = window.document.createElement('canvas'); // @todo https://bugzilla.mozilla.org/show_bug.cgi?id=1388974 | ||
var canvasElement = window.document.createElement('canvas'); | ||
// @todo https://bugzilla.mozilla.org/show_bug.cgi?id=1388974 | ||
canvasElement.getContext('2d'); | ||
if (typeof canvasElement.captureStream !== 'function') { | ||
return resolve(false); | ||
} | ||
var mediaStream = canvasElement.captureStream(); | ||
var mimeType = 'audio/webm'; | ||
try { | ||
@@ -212,3 +191,2 @@ var mediaRecorder = new window.MediaRecorder(mediaStream, { | ||
} | ||
return Promise.resolve(false); | ||
@@ -218,21 +196,14 @@ }; | ||
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf__default["default"](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default["default"](this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default["default"](this, result); }; } | ||
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } | ||
var createMediaRecorderConstructor = function createMediaRecorderConstructor(createNativeMediaRecorder, createNotSupportedError, createWebAudioMediaRecorder, createWebmPcmMediaRecorder, encoderRegexes, eventTargetConstructor, nativeMediaRecorderConstructor) { | ||
return /*#__PURE__*/function (_eventTargetConstruct) { | ||
_inherits__default["default"](MediaRecorder, _eventTargetConstruct); | ||
var _super = _createSuper(MediaRecorder); | ||
function MediaRecorder(stream) { | ||
var _this; | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
_classCallCheck__default["default"](this, MediaRecorder); | ||
var mimeType = options.mimeType; | ||
if (nativeMediaRecorderConstructor !== null && ( // Bug #10: Safari does not yet implement the isTypeSupported() method. | ||
if (nativeMediaRecorderConstructor !== null && ( | ||
// Bug #10: Safari does not yet implement the isTypeSupported() method. | ||
mimeType === undefined || nativeMediaRecorderConstructor.isTypeSupported !== undefined && nativeMediaRecorderConstructor.isTypeSupported(mimeType))) { | ||
@@ -245,4 +216,4 @@ var internalMediaRecorder = createNativeMediaRecorder(nativeMediaRecorderConstructor, stream, options); | ||
})) { | ||
_this = _super.call(this); // Bug #10: Safari does not yet implement the isTypeSupported() method. | ||
_this = _super.call(this); | ||
// Bug #10: Safari does not yet implement the isTypeSupported() method. | ||
if (nativeMediaRecorderConstructor !== null && nativeMediaRecorderConstructor.isTypeSupported !== undefined && nativeMediaRecorderConstructor.isTypeSupported('audio/webm;codecs=pcm')) { | ||
@@ -258,6 +229,4 @@ _this._internalMediaRecorder = createWebmPcmMediaRecorder(_assertThisInitialized__default["default"](_this), nativeMediaRecorderConstructor, stream, mimeType); | ||
} | ||
throw createNotSupportedError(); | ||
} | ||
_this._ondataavailable = null; | ||
@@ -271,3 +240,2 @@ _this._onerror = null; | ||
} | ||
_createClass__default["default"](MediaRecorder, [{ | ||
@@ -287,3 +255,2 @@ key: "mimeType", | ||
} | ||
if (typeof value === 'function') { | ||
@@ -306,3 +273,2 @@ var boundListener = value.bind(this); | ||
} | ||
if (typeof value === 'function') { | ||
@@ -325,3 +291,2 @@ var boundListener = value.bind(this); | ||
} | ||
if (typeof value === 'function') { | ||
@@ -344,3 +309,2 @@ var boundListener = value.bind(this); | ||
} | ||
if (typeof value === 'function') { | ||
@@ -363,3 +327,2 @@ var boundListener = value.bind(this); | ||
} | ||
if (typeof value === 'function') { | ||
@@ -382,3 +345,2 @@ var boundListener = value.bind(this); | ||
} | ||
if (typeof value === 'function') { | ||
@@ -420,3 +382,4 @@ var boundListener = value.bind(this); | ||
value: function isTypeSupported(mimeType) { | ||
return nativeMediaRecorderConstructor !== null && // Bug #10: Safari does not yet implement the isTypeSupported() method. | ||
return nativeMediaRecorderConstructor !== null && | ||
// Bug #10: Safari does not yet implement the isTypeSupported() method. | ||
nativeMediaRecorderConstructor.isTypeSupported !== undefined && nativeMediaRecorderConstructor.isTypeSupported(mimeType) || encoderRegexes.some(function (regex) { | ||
@@ -427,3 +390,2 @@ return regex.test(mimeType); | ||
}]); | ||
return MediaRecorder; | ||
@@ -437,3 +399,2 @@ }(eventTargetConstructor); | ||
} | ||
return null; | ||
@@ -450,7 +411,5 @@ }; | ||
var isActive = true; | ||
nativeMediaRecorder.addEventListener = function (addEventListener) { | ||
return function (type, listener, options) { | ||
var patchedEventListener = listener; | ||
if (typeof listener === 'function') { | ||
@@ -473,3 +432,2 @@ if (type === 'dataavailable') { | ||
} | ||
listener.call(nativeMediaRecorder, event); | ||
@@ -479,3 +437,2 @@ } | ||
}; | ||
dataAvailableListeners.set(listener, patchedEventListener); | ||
@@ -489,3 +446,4 @@ } else if (type === 'error') { | ||
error: createInvalidModificationError() | ||
})); // Bug #1 & #2: Firefox throws an error event with an UnknownError. | ||
})); | ||
// Bug #1 & #2: Firefox throws an error event with an UnknownError. | ||
} else if (event.error.name === 'UnknownError') { | ||
@@ -504,3 +462,2 @@ var message = event.error.message; | ||
}; | ||
errorListeners.set(listener, patchedEventListener); | ||
@@ -515,11 +472,8 @@ } else if (type === 'stop') { | ||
}; | ||
stopListeners.set(listener, patchedEventListener); | ||
} | ||
} | ||
return addEventListener.call(nativeMediaRecorder, type, patchedEventListener, options); | ||
}; | ||
}(nativeMediaRecorder.addEventListener); | ||
nativeMediaRecorder.dispatchEvent = function (dispatchEvent) { | ||
@@ -540,11 +494,8 @@ // Bug #7 & #8: Chrome fires the dataavailable and stop events before it fires the error event. | ||
}(nativeMediaRecorder.dispatchEvent); | ||
nativeMediaRecorder.removeEventListener = function (removeEventListener) { | ||
return function (type, listener, options) { | ||
var patchedEventListener = listener; | ||
if (typeof listener === 'function') { | ||
if (type === 'dataavailable') { | ||
var dataAvailableListener = dataAvailableListeners.get(listener); | ||
if (dataAvailableListener !== undefined) { | ||
@@ -555,3 +506,2 @@ patchedEventListener = dataAvailableListener; | ||
var errorListener = errorListeners.get(listener); | ||
if (errorListener !== undefined) { | ||
@@ -562,3 +512,2 @@ patchedEventListener = errorListener; | ||
var stopListener = stopListeners.get(listener); | ||
if (stopListener !== undefined) { | ||
@@ -569,7 +518,5 @@ patchedEventListener = stopListener; | ||
} | ||
return removeEventListener.call(nativeMediaRecorder, type, patchedEventListener, options); | ||
}; | ||
}(nativeMediaRecorder.removeEventListener); | ||
nativeMediaRecorder.start = function (start) { | ||
@@ -584,3 +531,2 @@ return function (timeslice) { | ||
} | ||
isActive = timeslice !== undefined; | ||
@@ -590,3 +536,2 @@ return timeslice === undefined ? start.call(nativeMediaRecorder) : start.call(nativeMediaRecorder, timeslice); | ||
}(nativeMediaRecorder.start); | ||
return nativeMediaRecorder; | ||
@@ -600,3 +545,2 @@ }; | ||
} | ||
return window.MediaRecorder === undefined ? null : window.MediaRecorder; | ||
@@ -620,10 +564,7 @@ }; | ||
var lengthAndValue = readVariableSizeInteger(dataView, offset); | ||
if (lengthAndValue === null) { | ||
return lengthAndValue; | ||
} | ||
var length = lengthAndValue.length, | ||
value = lengthAndValue.value; | ||
value = lengthAndValue.value; | ||
if (type === 'master') { | ||
@@ -635,7 +576,5 @@ return { | ||
} | ||
if (offset + length + value > dataView.byteLength) { | ||
return null; | ||
} | ||
if (type === 'binary') { | ||
@@ -648,6 +587,4 @@ var numberOfSamples = (value / Float32Array.BYTES_PER_ELEMENT - 1) / channelCount; | ||
}); | ||
for (var i = 0; i < numberOfSamples; i += 1) { | ||
var elementOffset = i * channelCount + 1; | ||
for (var j = 0; j < channelCount; j += 1) { | ||
@@ -657,3 +594,2 @@ content[j][i] = dataView.getFloat32(offset + length + (elementOffset + j) * Float32Array.BYTES_PER_ELEMENT, true); | ||
} | ||
return { | ||
@@ -664,3 +600,2 @@ content: content, | ||
} | ||
return { | ||
@@ -676,10 +611,7 @@ content: null, | ||
var lengthAndValue = readVariableSizeInteger(dataView, offset); | ||
if (lengthAndValue === null) { | ||
return lengthAndValue; | ||
} | ||
var length = lengthAndValue.length, | ||
value = lengthAndValue.value; | ||
value = lengthAndValue.value; | ||
if (value === 35) { | ||
@@ -691,3 +623,2 @@ return { | ||
} | ||
if (value === 46 || value === 97 || value === 88713574 || value === 106212971 || value === 139690087 || value === 172351395 || value === 256095861) { | ||
@@ -699,3 +630,2 @@ return { | ||
} | ||
return { | ||
@@ -711,16 +641,11 @@ length: length, | ||
var length = readVariableSizeIntegerLength(dataView, offset); | ||
if (length === null) { | ||
return length; | ||
} | ||
var firstDataByteOffset = offset + Math.floor((length - 1) / 8); | ||
if (firstDataByteOffset + length > dataView.byteLength) { | ||
return null; | ||
} | ||
var firstDataByte = dataView.getUint8(firstDataByteOffset); | ||
var value = firstDataByte & (1 << 8 - length % 8) - 1; // tslint:disable-line:no-bitwise | ||
for (var i = 1; i < length; i += 1) { | ||
@@ -737,8 +662,7 @@ value = (value << 8) + dataView.getUint8(firstDataByteOffset + i); // tslint:disable-line:no-bitwise | ||
var ERROR_MESSAGE = 'Missing AudioWorklet support. Maybe this is not running in a secure context.'; // @todo This should live in a separate file. | ||
var ERROR_MESSAGE = 'Missing AudioWorklet support. Maybe this is not running in a secure context.'; | ||
// @todo This should live in a separate file. | ||
var createPromisedAudioNodesEncoderIdAndPort = /*#__PURE__*/function () { | ||
var _ref = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee(audioBuffer, audioContext, channelCount, mediaStream, mimeType) { | ||
var _yield$instantiate, encoderId, port, audioBufferSourceNode, mediaStreamAudioSourceNode, recorderAudioWorkletNode; | ||
return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) { | ||
@@ -750,3 +674,2 @@ while (1) { | ||
return mediaEncoderHost.instantiate(mimeType, audioContext.sampleRate); | ||
case 2: | ||
@@ -756,3 +679,2 @@ _yield$instantiate = _context.sent; | ||
port = _yield$instantiate.port; | ||
if (!(standardizedAudioContext.AudioWorkletNode === undefined)) { | ||
@@ -762,5 +684,3 @@ _context.next = 7; | ||
} | ||
throw new Error(ERROR_MESSAGE); | ||
case 7: | ||
@@ -783,3 +703,2 @@ audioBufferSourceNode = new standardizedAudioContext.AudioBufferSourceNode(audioContext, { | ||
}); | ||
case 11: | ||
@@ -792,3 +711,2 @@ case "end": | ||
})); | ||
return function createPromisedAudioNodesEncoderIdAndPort(_x, _x2, _x3, _x4, _x5) { | ||
@@ -798,7 +716,5 @@ return _ref.apply(this, arguments); | ||
}(); | ||
var createWebAudioMediaRecorderFactory = function createWebAudioMediaRecorderFactory(createBlobEvent, createInvalidModificationError, createInvalidStateError, createNotSupportedError) { | ||
return function (eventTarget, mediaStream, mimeType) { | ||
var _a; | ||
var sampleRate = (_a = mediaStream.getAudioTracks()[0]) === null || _a === void 0 ? void 0 : _a.getSettings().sampleRate; | ||
@@ -819,3 +735,2 @@ var audioContext = new standardizedAudioContext.MinimalAudioContext({ | ||
} | ||
return standardizedAudioContext.addAudioWorkletModule(audioContext, url); | ||
@@ -828,3 +743,2 @@ }); | ||
var isAudioContextRunning = true; | ||
var dispatchDataAvailableEvent = function dispatchDataAvailableEvent(arrayBuffers) { | ||
@@ -837,3 +751,2 @@ eventTarget.dispatchEvent(createBlobEvent('dataavailable', { | ||
}; | ||
var requestNextPartialRecording = /*#__PURE__*/function () { | ||
@@ -848,6 +761,4 @@ var _ref2 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee2(encoderId, timeslice) { | ||
return mediaEncoderHost.encode(encoderId, timeslice); | ||
case 2: | ||
arrayBuffers = _context2.sent; | ||
if (promisedAudioNodesAndEncoderId === null) { | ||
@@ -859,3 +770,2 @@ bufferedArrayBuffers.push.apply(bufferedArrayBuffers, _toConsumableArray__default["default"](arrayBuffers)); | ||
} | ||
case 4: | ||
@@ -868,3 +778,2 @@ case "end": | ||
})); | ||
return function requestNextPartialRecording(_x6, _x7) { | ||
@@ -874,3 +783,2 @@ return _ref2.apply(this, arguments); | ||
}(); | ||
var _resume = function resume() { | ||
@@ -880,3 +788,2 @@ isAudioContextRunning = true; | ||
}; | ||
var stop = function stop() { | ||
@@ -886,3 +793,2 @@ if (promisedAudioNodesAndEncoderId === null) { | ||
} | ||
if (abortRecording !== null) { | ||
@@ -892,7 +798,5 @@ mediaStream.removeEventListener('addtrack', abortRecording); | ||
} | ||
if (intervalId !== null) { | ||
clearTimeout(intervalId); | ||
} | ||
promisedAudioNodesAndEncoderId.then( /*#__PURE__*/function () { | ||
@@ -906,3 +810,2 @@ var _ref4 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee3(_ref3) { | ||
constantSourceNode = _ref3.constantSourceNode, encoderId = _ref3.encoderId, mediaStreamAudioSourceNode = _ref3.mediaStreamAudioSourceNode, recorderAudioWorkletNode = _ref3.recorderAudioWorkletNode; | ||
if (promisedPartialRecording !== null) { | ||
@@ -914,6 +817,4 @@ promisedPartialRecording["catch"](function () { | ||
} | ||
_context3.next = 4; | ||
return recorderAudioWorkletNode.stop(); | ||
case 4: | ||
@@ -924,6 +825,4 @@ mediaStreamAudioSourceNode.disconnect(recorderAudioWorkletNode); | ||
return mediaEncoderHost.encode(encoderId, null); | ||
case 8: | ||
arrayBuffers = _context3.sent; | ||
if (!(promisedAudioNodesAndEncoderId === null)) { | ||
@@ -933,6 +832,4 @@ _context3.next = 12; | ||
} | ||
_context3.next = 12; | ||
return suspend(); | ||
case 12: | ||
@@ -942,3 +839,2 @@ dispatchDataAvailableEvent([].concat(bufferedArrayBuffers, _toConsumableArray__default["default"](arrayBuffers))); | ||
eventTarget.dispatchEvent(new Event('stop')); | ||
case 15: | ||
@@ -951,3 +847,2 @@ case "end": | ||
})); | ||
return function (_x8) { | ||
@@ -959,3 +854,2 @@ return _ref4.apply(this, arguments); | ||
}; | ||
var suspend = function suspend() { | ||
@@ -965,3 +859,2 @@ isAudioContextRunning = false; | ||
}; | ||
suspend(); | ||
@@ -972,7 +865,5 @@ return { | ||
}, | ||
get state() { | ||
return promisedAudioNodesAndEncoderId === null ? 'inactive' : isAudioContextRunning ? 'recording' : 'paused'; | ||
}, | ||
pause: function pause() { | ||
@@ -982,3 +873,2 @@ if (promisedAudioNodesAndEncoderId === null) { | ||
} | ||
if (isAudioContextRunning) { | ||
@@ -993,6 +883,4 @@ suspend(); | ||
} | ||
if (!isAudioContextRunning) { | ||
_resume(); | ||
eventTarget.dispatchEvent(new Event('resume')); | ||
@@ -1003,14 +891,11 @@ } | ||
var _a; | ||
if (promisedAudioNodesAndEncoderId !== null) { | ||
throw createInvalidStateError(); | ||
} | ||
if (mediaStream.getVideoTracks().length > 0) { | ||
throw createNotSupportedError(); | ||
} | ||
eventTarget.dispatchEvent(new Event('start')); | ||
var audioTracks = mediaStream.getAudioTracks(); // @todo TypeScript v4.4.2 removed the channelCount property from the MediaTrackSettings interface. | ||
var audioTracks = mediaStream.getAudioTracks(); | ||
// @todo TypeScript v4.4.2 removed the channelCount property from the MediaTrackSettings interface. | ||
var channelCount = audioTracks.length === 0 ? 2 : (_a = audioTracks[0].getSettings().channelCount) !== null && _a !== void 0 ? _a : 2; | ||
@@ -1022,3 +907,2 @@ promisedAudioNodesAndEncoderId = Promise.all([_resume(), promisedAudioWorkletModule.then(function () { | ||
var _ref7, _ref7$, audioBufferSourceNode, encoderId, mediaStreamAudioSourceNode, port, recorderAudioWorkletNode, constantSourceNode; | ||
return _regeneratorRuntime__default["default"].wrap(function _callee4$(_context4) { | ||
@@ -1036,14 +920,11 @@ while (1) { | ||
}); | ||
case 4: | ||
audioBufferSourceNode.disconnect(recorderAudioWorkletNode); // Bug #17: Safari does throttle the processing on hidden tabs if there is no active audio output. | ||
audioBufferSourceNode.disconnect(recorderAudioWorkletNode); | ||
// Bug #17: Safari does throttle the processing on hidden tabs if there is no active audio output. | ||
constantSourceNode = new standardizedAudioContext.ConstantSourceNode(audioContext, { | ||
offset: 0 | ||
}); | ||
constantSourceNode.onended = function () { | ||
return constantSourceNode.disconnect(); | ||
}; | ||
constantSourceNode.connect(audioContext.destination); | ||
@@ -1053,3 +934,2 @@ constantSourceNode.start(); | ||
return recorderAudioWorkletNode.record(port); | ||
case 11: | ||
@@ -1059,3 +939,2 @@ if (timeslice !== undefined) { | ||
} | ||
return _context4.abrupt("return", { | ||
@@ -1067,3 +946,2 @@ constantSourceNode: constantSourceNode, | ||
}); | ||
case 13: | ||
@@ -1076,3 +954,2 @@ case "end": | ||
})); | ||
return function (_x9) { | ||
@@ -1083,3 +960,2 @@ return _ref6.apply(this, arguments); | ||
var tracks = mediaStream.getTracks(); | ||
abortRecording = function abortRecording() { | ||
@@ -1091,3 +967,2 @@ stop(); | ||
}; | ||
mediaStream.addEventListener('addtrack', abortRecording); | ||
@@ -1097,3 +972,2 @@ mediaStream.addEventListener('removetrack', abortRecording); | ||
var currentTracks = mediaStream.getTracks(); | ||
if ((currentTracks.length !== tracks.length || currentTracks.some(function (track, index) { | ||
@@ -1114,4 +988,4 @@ return track !== tracks[index]; | ||
var audioTracks = mediaStream.getAudioTracks(); | ||
var bufferedArrayBuffers = []; // @todo TypeScript v4.4.2 removed the channelCount property from the MediaTrackSettings interface. | ||
var bufferedArrayBuffers = []; | ||
// @todo TypeScript v4.4.2 removed the channelCount property from the MediaTrackSettings interface. | ||
var channelCount = audioTracks.length === 0 ? undefined : audioTracks[0].getSettings().channelCount; | ||
@@ -1123,6 +997,3 @@ var nativeMediaRecorder = new nativeMediaRecorderConstructor(mediaStream, { | ||
var promisedPartialRecording = null; | ||
var stopRecording = function stopRecording() {}; // tslint:disable-line:no-empty | ||
var dispatchDataAvailableEvent = function dispatchDataAvailableEvent(arrayBuffers) { | ||
@@ -1135,3 +1006,2 @@ eventTarget.dispatchEvent(createBlobEvent('dataavailable', { | ||
}; | ||
var requestNextPartialRecording = /*#__PURE__*/function () { | ||
@@ -1146,6 +1016,4 @@ var _ref = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee(encoderId, timeslice) { | ||
return mediaEncoderHost.encode(encoderId, timeslice); | ||
case 2: | ||
arrayBuffers = _context.sent; | ||
if (nativeMediaRecorder.state === 'inactive') { | ||
@@ -1157,3 +1025,2 @@ bufferedArrayBuffers.push.apply(bufferedArrayBuffers, _toConsumableArray__default["default"](arrayBuffers)); | ||
} | ||
case 4: | ||
@@ -1166,3 +1033,2 @@ case "end": | ||
})); | ||
return function requestNextPartialRecording(_x, _x2) { | ||
@@ -1172,3 +1038,2 @@ return _ref.apply(this, arguments); | ||
}(); | ||
var stop = function stop() { | ||
@@ -1178,3 +1043,2 @@ if (nativeMediaRecorder.state === 'inactive') { | ||
} | ||
if (promisedPartialRecording !== null) { | ||
@@ -1186,14 +1050,9 @@ promisedPartialRecording["catch"](function () { | ||
} | ||
stopRecording(); | ||
stopRecording = function stopRecording() {}; // tslint:disable-line:no-empty | ||
nativeMediaRecorder.stop(); | ||
}; | ||
nativeMediaRecorder.addEventListener('error', function () { | ||
stop(); // Bug #3 & #4: Chrome throws an error event without any error. | ||
stop(); | ||
// Bug #3 & #4: Chrome throws an error event without any error. | ||
eventTarget.dispatchEvent(new ErrorEvent('error', { | ||
@@ -1210,7 +1069,5 @@ error: createInvalidModificationError() | ||
}, | ||
get state() { | ||
return nativeMediaRecorder.state; | ||
}, | ||
pause: function pause() { | ||
@@ -1230,3 +1087,2 @@ return nativeMediaRecorder.pause(); | ||
} | ||
if (nativeMediaRecorder.state === 'inactive') { | ||
@@ -1236,13 +1092,10 @@ if (sampleRate === undefined) { | ||
} | ||
var isRecording = false; | ||
var isStopped = false; // Bug #9: Chrome sometimes fires more than one dataavailable event while being inactive. | ||
var isStopped = false; | ||
// Bug #9: Chrome sometimes fires more than one dataavailable event while being inactive. | ||
var pendingInvocations = 0; | ||
var promisedDataViewElementTypeEncoderIdAndPort = mediaEncoderHost.instantiate(mimeType, sampleRate); | ||
stopRecording = function stopRecording() { | ||
isStopped = true; | ||
}; | ||
var removeEventListener = subscribableThings.on(nativeMediaRecorder, 'dataavailable')(function (_ref2) { | ||
@@ -1254,3 +1107,2 @@ var data = _ref2.data; | ||
var _ref3$dataView, dataView, _ref3$elementType, elementType, encoderId, port, arrayBuffer, currentDataView, lengthAndValue, value, _decodeWebMChunk, currentElementType, offset, contents, remainingDataView; | ||
return _regeneratorRuntime__default["default"].wrap(function _callee2$(_context2) { | ||
@@ -1263,3 +1115,2 @@ while (1) { | ||
return data.arrayBuffer(); | ||
case 3: | ||
@@ -1269,3 +1120,2 @@ arrayBuffer = _context2.sent; | ||
currentDataView = dataView === null ? new multiBufferDataView.MultiBufferDataView([arrayBuffer]) : new multiBufferDataView.MultiBufferDataView([].concat(_toConsumableArray__default["default"](dataView.buffers), [arrayBuffer]), dataView.byteOffset); | ||
if (!(!isRecording && nativeMediaRecorder.state === 'recording' && !isStopped)) { | ||
@@ -1275,5 +1125,3 @@ _context2.next = 14; | ||
} | ||
lengthAndValue = readVariableSizeInteger(currentDataView, 0); | ||
if (!(lengthAndValue === null)) { | ||
@@ -1283,3 +1131,2 @@ _context2.next = 10; | ||
} | ||
return _context2.abrupt("return", { | ||
@@ -1291,6 +1138,4 @@ dataView: currentDataView, | ||
}); | ||
case 10: | ||
value = lengthAndValue.value; | ||
if (!(value !== 172351395)) { | ||
@@ -1300,3 +1145,2 @@ _context2.next = 13; | ||
} | ||
return _context2.abrupt("return", { | ||
@@ -1308,6 +1152,4 @@ dataView: dataView, | ||
}); | ||
case 13: | ||
isRecording = true; | ||
case 14: | ||
@@ -1322,3 +1164,2 @@ _decodeWebMChunk = decodeWebMChunk(currentDataView, elementType, channelCount), currentElementType = _decodeWebMChunk.currentElementType, offset = _decodeWebMChunk.offset, contents = _decodeWebMChunk.contents; | ||
}); | ||
if (pendingInvocations === 0 && (nativeMediaRecorder.state === 'inactive' || isStopped)) { | ||
@@ -1334,3 +1175,2 @@ mediaEncoderHost.encode(encoderId, null).then(function (arrayBuffers) { | ||
} | ||
return _context2.abrupt("return", { | ||
@@ -1342,3 +1182,2 @@ dataView: remainingDataView, | ||
}); | ||
case 19: | ||
@@ -1351,3 +1190,2 @@ case "end": | ||
})); | ||
return function (_x3) { | ||
@@ -1358,3 +1196,2 @@ return _ref4.apply(this, arguments); | ||
}); | ||
if (timeslice !== undefined) { | ||
@@ -1367,3 +1204,2 @@ promisedDataViewElementTypeEncoderIdAndPort.then(function (_ref6) { | ||
} | ||
nativeMediaRecorder.start(100); | ||
@@ -1384,37 +1220,27 @@ }, | ||
} | ||
var _byte = dataView.getUint8(offset); | ||
if (_byte > 127) { | ||
return 1; | ||
} | ||
if (_byte > 63) { | ||
return 2; | ||
} | ||
if (_byte > 31) { | ||
return 3; | ||
} | ||
if (_byte > 15) { | ||
return 4; | ||
} | ||
if (_byte > 7) { | ||
return 5; | ||
} | ||
if (_byte > 3) { | ||
return 6; | ||
} | ||
if (_byte > 1) { | ||
return 7; | ||
} | ||
if (_byte > 0) { | ||
return 8; | ||
} | ||
var length = readVariableSizeIntegerLength(dataView, offset + 1); | ||
@@ -1433,7 +1259,5 @@ return length === null ? null : length + 8; | ||
}); | ||
if (typeof eventListener === 'function') { | ||
return eventListener.call(target, event); | ||
} | ||
return eventListener.handleEvent.call(target, event); | ||
@@ -1469,8 +1293,5 @@ }; | ||
return mediaEncoderHost.register(port); | ||
case 3: | ||
_context.t1 = _context.sent; | ||
_context.t0.push.call(_context.t0, _context.t1); | ||
case 5: | ||
@@ -1483,3 +1304,2 @@ case "end": | ||
})); | ||
return function register(_x) { | ||
@@ -1486,0 +1306,0 @@ return _ref.apply(this, arguments); |
@@ -18,8 +18,8 @@ { | ||
"dependencies": { | ||
"@babel/runtime": "^7.19.0", | ||
"media-encoder-host": "^8.0.78", | ||
"multi-buffer-data-view": "^3.0.21", | ||
"recorder-audio-worklet": "^5.1.30", | ||
"standardized-audio-context": "^25.3.32", | ||
"subscribable-things": "^2.1.7", | ||
"@babel/runtime": "^7.19.4", | ||
"media-encoder-host": "^8.0.79", | ||
"multi-buffer-data-view": "^3.0.22", | ||
"recorder-audio-worklet": "^5.1.31", | ||
"standardized-audio-context": "^25.3.33", | ||
"subscribable-things": "^2.1.8", | ||
"tslib": "^2.4.0" | ||
@@ -29,6 +29,6 @@ }, | ||
"devDependencies": { | ||
"@babel/core": "^7.19.3", | ||
"@babel/core": "^7.19.6", | ||
"@babel/plugin-external-helpers": "^7.18.6", | ||
"@babel/plugin-transform-runtime": "^7.19.1", | ||
"@babel/preset-env": "^7.19.3", | ||
"@babel/plugin-transform-runtime": "^7.19.6", | ||
"@babel/preset-env": "^7.19.4", | ||
"@commitlint/cli": "^17.1.2", | ||
@@ -40,5 +40,5 @@ "@commitlint/config-angular": "^17.1.0", | ||
"cz-conventional-changelog": "^3.3.0", | ||
"eslint": "^8.24.0", | ||
"eslint": "^8.26.0", | ||
"eslint-config-holy-grail": "^52.0.33", | ||
"extendable-media-recorder-wav-encoder": "^7.0.76", | ||
"extendable-media-recorder-wav-encoder": "^7.0.77", | ||
"grunt": "^1.5.3", | ||
@@ -58,3 +58,3 @@ "grunt-cli": "^1.4.3", | ||
"load-grunt-config": "^4.0.1", | ||
"mocha": "^10.0.0", | ||
"mocha": "^10.1.0", | ||
"prettier": "^2.7.1", | ||
@@ -64,3 +64,3 @@ "pretty-quick": "^3.1.3", | ||
"rollup": "^2.79.1", | ||
"sinon": "^14.0.0", | ||
"sinon": "^14.0.1", | ||
"sinon-chai": "^3.7.0", | ||
@@ -99,3 +99,3 @@ "ts-loader": "^9.4.1", | ||
"types": "build/es2019/module.d.ts", | ||
"version": "7.0.3" | ||
"version": "7.0.4" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3813
274522