media-encoder-host-worker
Advanced tools
Comparing version 9.2.0 to 10.0.0
import type { IExtendableMediaRecorderWavEncoderBrokerDefinition } from 'extendable-media-recorder-wav-encoder-broker'; | ||
export declare const createDeregisterEncoder: (encoderBrokerRegistry: Map<string, [RegExp, IExtendableMediaRecorderWavEncoderBrokerDefinition]>, ports: WeakMap<MessagePort, string>) => (port: MessagePort) => void; | ||
export declare const createDeregisterEncoder: (encoderBrokerRegistry: Map<string, [RegExp, IExtendableMediaRecorderWavEncoderBrokerDefinition]>, encoderIds: Map<number, string>) => (encoderId: number) => void; | ||
//# sourceMappingURL=deregister-encoder.d.ts.map |
@@ -1,9 +0,9 @@ | ||
export const createDeregisterEncoder = (encoderBrokerRegistry, ports) => (port) => { | ||
const regexAsString = ports.get(port); | ||
export const createDeregisterEncoder = (encoderBrokerRegistry, encoderIds) => (encoderId) => { | ||
const regexAsString = encoderIds.get(encoderId); | ||
if (regexAsString === undefined) { | ||
throw new Error('There is no encoder stored which wraps this port.'); | ||
throw new Error('There was no encoder stored with the given id.'); | ||
} | ||
encoderBrokerRegistry.delete(regexAsString); | ||
ports.delete(port); | ||
encoderIds.delete(encoderId); | ||
}; | ||
//# sourceMappingURL=deregister-encoder.js.map |
import type { closePort as closePortFunction } from '../functions/close-port'; | ||
import type { createRemoveEncoderInstance } from './remove-encoder-instance'; | ||
export declare const createFinishEncoding: (closePort: typeof closePortFunction, removeEncoderInstance: ReturnType<typeof createRemoveEncoderInstance>) => (encoderId: number) => Promise<ArrayBuffer[]>; | ||
export declare const createFinishEncoding: (closePort: typeof closePortFunction, removeEncoderInstance: ReturnType<typeof createRemoveEncoderInstance>) => (encoderInstanceId: number) => Promise<ArrayBuffer[]>; | ||
//# sourceMappingURL=finish-encoding.d.ts.map |
export const createFinishEncoding = (closePort, removeEncoderInstance) => { | ||
return (encoderId) => { | ||
const [encoderBroker, port, isRecording, sampleRate] = removeEncoderInstance(encoderId); | ||
return (encoderInstanceId) => { | ||
const [encoderBroker, port, isRecording, sampleRate] = removeEncoderInstance(encoderInstanceId); | ||
if (!isRecording) { | ||
return encoderBroker.encode(encoderId, null); | ||
return encoderBroker.encode(encoderInstanceId, null); | ||
} | ||
@@ -11,6 +11,6 @@ return new Promise((resolve) => { | ||
closePort(port); | ||
resolve(encoderBroker.encode(encoderId, null)); | ||
resolve(encoderBroker.encode(encoderInstanceId, null)); | ||
} | ||
else { | ||
encoderBroker.record(encoderId, sampleRate, data); | ||
encoderBroker.record(encoderInstanceId, sampleRate, data); | ||
} | ||
@@ -17,0 +17,0 @@ }; |
import type { TEncoderInstancesRegistryEntry } from '../types'; | ||
export declare const createGetEncoderInstance: (encoderInstancesRegistry: Map<number, TEncoderInstancesRegistryEntry>) => (encoderId: number) => TEncoderInstancesRegistryEntry; | ||
export declare const createGetEncoderInstance: (encoderInstancesRegistry: Map<number, TEncoderInstancesRegistryEntry>) => (encoderInstanceId: number) => TEncoderInstancesRegistryEntry; | ||
//# sourceMappingURL=get-encoder-instance.d.ts.map |
export const createGetEncoderInstance = (encoderInstancesRegistry) => { | ||
return (encoderId) => { | ||
const entry = encoderInstancesRegistry.get(encoderId); | ||
return (encoderInstanceId) => { | ||
const entry = encoderInstancesRegistry.get(encoderInstanceId); | ||
if (entry === undefined) { | ||
@@ -5,0 +5,0 @@ throw new Error('There was no instance of an encoder stored with the given id.'); |
import type { closePort as closePortFunction } from '../functions/close-port'; | ||
import type { TEncoderInstancesRegistryEntry } from '../types'; | ||
import type { createPickCapableEncoderBroker } from './pick-capable-encoder-broker'; | ||
export declare const createInstantiateEncoder: (closePort: typeof closePortFunction, encoderInstancesRegistry: Map<number, TEncoderInstancesRegistryEntry>, pickCapableEncoderBroker: ReturnType<typeof createPickCapableEncoderBroker>) => (encoderId: number, mimeType: string, sampleRate: number) => MessagePort; | ||
export declare const createInstantiateEncoder: (closePort: typeof closePortFunction, encoderInstancesRegistry: Map<number, TEncoderInstancesRegistryEntry>, pickCapableEncoderBroker: ReturnType<typeof createPickCapableEncoderBroker>) => (encoderInstanceId: number, mimeType: string, sampleRate: number) => MessagePort; | ||
//# sourceMappingURL=instantiate-encoder.d.ts.map |
export const createInstantiateEncoder = (closePort, encoderInstancesRegistry, pickCapableEncoderBroker) => { | ||
return (encoderId, mimeType, sampleRate) => { | ||
if (encoderInstancesRegistry.has(encoderId)) { | ||
throw new Error(`There is already an encoder registered with an id called "${encoderId}".`); | ||
return (encoderInstanceId, mimeType, sampleRate) => { | ||
if (encoderInstancesRegistry.has(encoderInstanceId)) { | ||
throw new Error(`There is already an encoder instance registered with an id called "${encoderInstanceId}".`); | ||
} | ||
@@ -9,3 +9,3 @@ const encoderBroker = pickCapableEncoderBroker(mimeType); | ||
const entry = [encoderBroker, port1, true, sampleRate]; | ||
encoderInstancesRegistry.set(encoderId, entry); | ||
encoderInstancesRegistry.set(encoderInstanceId, entry); | ||
port1.onmessage = ({ data }) => { | ||
@@ -17,3 +17,3 @@ if (data.length === 0) { | ||
else { | ||
encoderBroker.record(encoderId, sampleRate, data.map((channelDataOrNumberOfSamples) => typeof channelDataOrNumberOfSamples === 'number' | ||
encoderBroker.record(encoderInstanceId, sampleRate, data.map((channelDataOrNumberOfSamples) => typeof channelDataOrNumberOfSamples === 'number' | ||
? new Float32Array(channelDataOrNumberOfSamples) | ||
@@ -20,0 +20,0 @@ : channelDataOrNumberOfSamples)); |
import type { IExtendableMediaRecorderWavEncoderBrokerDefinition, wrap as wrapFunction } from 'extendable-media-recorder-wav-encoder-broker'; | ||
export declare const createRegisterEncoder: (encoderBrokerRegistry: Map<string, [RegExp, IExtendableMediaRecorderWavEncoderBrokerDefinition]>, ports: WeakMap<MessagePort, string>, wrap: typeof wrapFunction) => (port: MessagePort) => Promise<RegExp>; | ||
export declare const createRegisterEncoder: (encoderBrokerRegistry: Map<string, [RegExp, IExtendableMediaRecorderWavEncoderBrokerDefinition]>, encoderIds: Map<number, string>, wrap: typeof wrapFunction) => (encoderId: number, port: MessagePort) => Promise<RegExp>; | ||
//# sourceMappingURL=register-encoder.d.ts.map |
@@ -1,12 +0,15 @@ | ||
export const createRegisterEncoder = (encoderBrokerRegistry, ports, wrap) => async (port) => { | ||
export const createRegisterEncoder = (encoderBrokerRegistry, encoderIds, wrap) => async (encoderId, port) => { | ||
const encoderBroker = wrap(port); | ||
const regex = await encoderBroker.characterize(); | ||
const regexAsString = regex.toString(); | ||
if (encoderBrokerRegistry.has(regexAsString) || ports.has(port)) { | ||
if (encoderBrokerRegistry.has(regexAsString)) { | ||
throw new Error('There is already an encoder stored which handles exactly the same mime types.'); | ||
} | ||
if (encoderIds.has(encoderId)) { | ||
throw new Error(`There is already an encoder registered with an id called "${encoderId}".`); | ||
} | ||
encoderBrokerRegistry.set(regexAsString, [regex, encoderBroker]); | ||
ports.set(port, regexAsString); | ||
encoderIds.set(encoderId, regexAsString); | ||
return regex; | ||
}; | ||
//# sourceMappingURL=register-encoder.js.map |
import type { TEncoderInstancesRegistryEntry } from '../types'; | ||
import type { createGetEncoderInstance } from './get-encoder-instance'; | ||
export declare const createRemoveEncoderInstance: (encoderInstancesRegistry: Map<number, TEncoderInstancesRegistryEntry>, getEncoderInstance: ReturnType<typeof createGetEncoderInstance>) => (encoderId: number) => TEncoderInstancesRegistryEntry; | ||
export declare const createRemoveEncoderInstance: (encoderInstancesRegistry: Map<number, TEncoderInstancesRegistryEntry>, getEncoderInstance: ReturnType<typeof createGetEncoderInstance>) => (encoderInstanceId: number) => TEncoderInstancesRegistryEntry; | ||
//# sourceMappingURL=remove-encoder-instance.d.ts.map |
export const createRemoveEncoderInstance = (encoderInstancesRegistry, getEncoderInstance) => { | ||
return (encoderId) => { | ||
const entry = getEncoderInstance(encoderId); | ||
encoderInstancesRegistry.delete(encoderId); | ||
return (encoderInstanceId) => { | ||
const entry = getEncoderInstance(encoderInstanceId); | ||
encoderInstancesRegistry.delete(encoderInstanceId); | ||
return entry; | ||
@@ -6,0 +6,0 @@ }; |
import type { createGetEncoderInstance } from './get-encoder-instance'; | ||
export declare const createRequestPartialEncoding: (getEncoderInstance: ReturnType<typeof createGetEncoderInstance>) => (encoderId: number, timeslice: number) => Promise<ArrayBuffer[]>; | ||
export declare const createRequestPartialEncoding: (getEncoderInstance: ReturnType<typeof createGetEncoderInstance>) => (encoderInstanceId: number, timeslice: number) => Promise<ArrayBuffer[]>; | ||
//# sourceMappingURL=request-partial-encoding.d.ts.map |
export const createRequestPartialEncoding = (getEncoderInstance) => { | ||
return (encoderId, timeslice) => { | ||
const [encoderBroker] = getEncoderInstance(encoderId); | ||
return encoderBroker.encode(encoderId, timeslice); | ||
return (encoderInstanceId, timeslice) => { | ||
const [encoderBroker] = getEncoderInstance(encoderInstanceId); | ||
return encoderBroker.encode(encoderInstanceId, timeslice); | ||
}; | ||
}; | ||
//# sourceMappingURL=request-partial-encoding.js.map |
@@ -5,6 +5,6 @@ import { IWorkerDefinition } from 'worker-factory'; | ||
params: { | ||
port: MessagePort; | ||
encoderId: number; | ||
}; | ||
response: { | ||
result: undefined; | ||
result: null; | ||
}; | ||
@@ -14,3 +14,3 @@ }; | ||
params: { | ||
encoderId: number; | ||
encoderInstanceId: number; | ||
timeslice: null | number; | ||
@@ -26,3 +26,3 @@ }; | ||
params: { | ||
encoderId: number; | ||
encoderInstanceId: number; | ||
mimeType: string; | ||
@@ -38,2 +38,3 @@ sampleRate: number; | ||
params: { | ||
encoderId: number; | ||
port: MessagePort; | ||
@@ -40,0 +41,0 @@ }; |
@@ -19,4 +19,4 @@ import { wrap } from 'extendable-media-recorder-wav-encoder-broker'; | ||
const encoderBrokerRegistry = new Map(); | ||
const ports = new WeakMap(); | ||
const deregisterEncoder = createDeregisterEncoder(encoderBrokerRegistry, ports); | ||
const encoderIds = new Map(); | ||
const deregisterEncoder = createDeregisterEncoder(encoderBrokerRegistry, encoderIds); | ||
const encoderInstancesRegistry = new Map(); | ||
@@ -28,20 +28,21 @@ const getEncoderInstance = createGetEncoderInstance(encoderInstancesRegistry); | ||
const instantiateEncoder = createInstantiateEncoder(closePort, encoderInstancesRegistry, pickCapableEncoderBroker); | ||
const registerEncoder = createRegisterEncoder(encoderBrokerRegistry, ports, wrap); | ||
const registerEncoder = createRegisterEncoder(encoderBrokerRegistry, encoderIds, wrap); | ||
const requestPartialEncoding = createRequestPartialEncoding(getEncoderInstance); | ||
createWorker(self, { | ||
deregister: async ({ port }) => { | ||
return { result: deregisterEncoder(port) }; | ||
deregister: async ({ encoderId }) => { | ||
deregisterEncoder(encoderId); | ||
return { result: null }; | ||
}, | ||
encode: async ({ encoderId, timeslice }) => { | ||
const arrayBuffers = timeslice === null ? await finishEncoding(encoderId) : await requestPartialEncoding(encoderId, timeslice); | ||
encode: async ({ encoderInstanceId, timeslice }) => { | ||
const arrayBuffers = timeslice === null ? await finishEncoding(encoderInstanceId) : await requestPartialEncoding(encoderInstanceId, timeslice); | ||
return { result: arrayBuffers, transferables: arrayBuffers }; | ||
}, | ||
instantiate: ({ encoderId, mimeType, sampleRate }) => { | ||
const port = instantiateEncoder(encoderId, mimeType, sampleRate); | ||
instantiate: ({ encoderInstanceId, mimeType, sampleRate }) => { | ||
const port = instantiateEncoder(encoderInstanceId, mimeType, sampleRate); | ||
return { result: port, transferables: [port] }; | ||
}, | ||
register: async ({ port }) => { | ||
return { result: await registerEncoder(port) }; | ||
register: async ({ encoderId, port }) => { | ||
return { result: await registerEncoder(encoderId, port) }; | ||
} | ||
}); | ||
//# sourceMappingURL=module.js.map |
@@ -7,10 +7,10 @@ (function (global, factory) { | ||
var createDeregisterEncoder = function createDeregisterEncoder(encoderBrokerRegistry, ports) { | ||
return function (port) { | ||
var regexAsString = ports.get(port); | ||
var createDeregisterEncoder = function createDeregisterEncoder(encoderBrokerRegistry, encoderIds) { | ||
return function (encoderId) { | ||
var regexAsString = encoderIds.get(encoderId); | ||
if (regexAsString === undefined) { | ||
throw new Error('There is no encoder stored which wraps this port.'); | ||
throw new Error('There was no encoder stored with the given id.'); | ||
} | ||
encoderBrokerRegistry["delete"](regexAsString); | ||
ports["delete"](port); | ||
encoderIds["delete"](encoderId); | ||
}; | ||
@@ -20,4 +20,4 @@ }; | ||
var createFinishEncoding = function createFinishEncoding(closePort, removeEncoderInstance) { | ||
return function (encoderId) { | ||
var _removeEncoderInstanc = removeEncoderInstance(encoderId), | ||
return function (encoderInstanceId) { | ||
var _removeEncoderInstanc = removeEncoderInstance(encoderInstanceId), | ||
_removeEncoderInstanc2 = _slicedToArray(_removeEncoderInstanc, 4), | ||
@@ -29,3 +29,3 @@ encoderBroker = _removeEncoderInstanc2[0], | ||
if (!isRecording) { | ||
return encoderBroker.encode(encoderId, null); | ||
return encoderBroker.encode(encoderInstanceId, null); | ||
} | ||
@@ -37,5 +37,5 @@ return new Promise(function (resolve) { | ||
closePort(port); | ||
resolve(encoderBroker.encode(encoderId, null)); | ||
resolve(encoderBroker.encode(encoderInstanceId, null)); | ||
} else { | ||
encoderBroker.record(encoderId, sampleRate, data); | ||
encoderBroker.record(encoderInstanceId, sampleRate, data); | ||
} | ||
@@ -48,4 +48,4 @@ }; | ||
var createGetEncoderInstance = function createGetEncoderInstance(encoderInstancesRegistry) { | ||
return function (encoderId) { | ||
var entry = encoderInstancesRegistry.get(encoderId); | ||
return function (encoderInstanceId) { | ||
var entry = encoderInstancesRegistry.get(encoderInstanceId); | ||
if (entry === undefined) { | ||
@@ -59,5 +59,5 @@ throw new Error('There was no instance of an encoder stored with the given id.'); | ||
var createInstantiateEncoder = function createInstantiateEncoder(closePort, encoderInstancesRegistry, pickCapableEncoderBroker) { | ||
return function (encoderId, mimeType, sampleRate) { | ||
if (encoderInstancesRegistry.has(encoderId)) { | ||
throw new Error("There is already an encoder registered with an id called \"".concat(encoderId, "\".")); | ||
return function (encoderInstanceId, mimeType, sampleRate) { | ||
if (encoderInstancesRegistry.has(encoderInstanceId)) { | ||
throw new Error("There is already an encoder instance registered with an id called \"".concat(encoderInstanceId, "\".")); | ||
} | ||
@@ -69,3 +69,3 @@ var encoderBroker = pickCapableEncoderBroker(mimeType); | ||
var entry = [encoderBroker, port1, true, sampleRate]; | ||
encoderInstancesRegistry.set(encoderId, entry); | ||
encoderInstancesRegistry.set(encoderInstanceId, entry); | ||
port1.onmessage = function (_ref) { | ||
@@ -77,3 +77,3 @@ var data = _ref.data; | ||
} else { | ||
encoderBroker.record(encoderId, sampleRate, data.map(function (channelDataOrNumberOfSamples) { | ||
encoderBroker.record(encoderInstanceId, sampleRate, data.map(function (channelDataOrNumberOfSamples) { | ||
return typeof channelDataOrNumberOfSamples === 'number' ? new Float32Array(channelDataOrNumberOfSamples) : channelDataOrNumberOfSamples; | ||
@@ -101,5 +101,5 @@ })); | ||
var createRegisterEncoder = function createRegisterEncoder(encoderBrokerRegistry, ports, wrap) { | ||
var createRegisterEncoder = function createRegisterEncoder(encoderBrokerRegistry, encoderIds, wrap) { | ||
return /*#__PURE__*/function () { | ||
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(port) { | ||
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(encoderId, port) { | ||
var encoderBroker, regex, regexAsString; | ||
@@ -115,3 +115,3 @@ return _regeneratorRuntime.wrap(function _callee$(_context) { | ||
regexAsString = regex.toString(); | ||
if (!(encoderBrokerRegistry.has(regexAsString) || ports.has(port))) { | ||
if (!encoderBrokerRegistry.has(regexAsString)) { | ||
_context.next = 7; | ||
@@ -122,6 +122,12 @@ break; | ||
case 7: | ||
if (!encoderIds.has(encoderId)) { | ||
_context.next = 9; | ||
break; | ||
} | ||
throw new Error("There is already an encoder registered with an id called \"".concat(encoderId, "\".")); | ||
case 9: | ||
encoderBrokerRegistry.set(regexAsString, [regex, encoderBroker]); | ||
ports.set(port, regexAsString); | ||
encoderIds.set(encoderId, regexAsString); | ||
return _context.abrupt("return", regex); | ||
case 10: | ||
case 12: | ||
case "end": | ||
@@ -132,3 +138,3 @@ return _context.stop(); | ||
})); | ||
return function (_x) { | ||
return function (_x, _x2) { | ||
return _ref.apply(this, arguments); | ||
@@ -140,5 +146,5 @@ }; | ||
var createRemoveEncoderInstance = function createRemoveEncoderInstance(encoderInstancesRegistry, getEncoderInstance) { | ||
return function (encoderId) { | ||
var entry = getEncoderInstance(encoderId); | ||
encoderInstancesRegistry["delete"](encoderId); | ||
return function (encoderInstanceId) { | ||
var entry = getEncoderInstance(encoderInstanceId); | ||
encoderInstancesRegistry["delete"](encoderInstanceId); | ||
return entry; | ||
@@ -149,7 +155,7 @@ }; | ||
var createRequestPartialEncoding = function createRequestPartialEncoding(getEncoderInstance) { | ||
return function (encoderId, timeslice) { | ||
var _getEncoderInstance = getEncoderInstance(encoderId), | ||
return function (encoderInstanceId, timeslice) { | ||
var _getEncoderInstance = getEncoderInstance(encoderInstanceId), | ||
_getEncoderInstance2 = _slicedToArray(_getEncoderInstance, 1), | ||
encoderBroker = _getEncoderInstance2[0]; | ||
return encoderBroker.encode(encoderId, timeslice); | ||
return encoderBroker.encode(encoderInstanceId, timeslice); | ||
}; | ||
@@ -164,4 +170,4 @@ }; | ||
var encoderBrokerRegistry = new Map(); | ||
var ports = new WeakMap(); | ||
var deregisterEncoder = createDeregisterEncoder(encoderBrokerRegistry, ports); | ||
var encoderIds = new Map(); | ||
var deregisterEncoder = createDeregisterEncoder(encoderBrokerRegistry, encoderIds); | ||
var encoderInstancesRegistry = new Map(); | ||
@@ -173,3 +179,3 @@ var getEncoderInstance = createGetEncoderInstance(encoderInstancesRegistry); | ||
var instantiateEncoder = createInstantiateEncoder(closePort, encoderInstancesRegistry, pickCapableEncoderBroker); | ||
var registerEncoder = createRegisterEncoder(encoderBrokerRegistry, ports, extendableMediaRecorderWavEncoderBroker.wrap); | ||
var registerEncoder = createRegisterEncoder(encoderBrokerRegistry, encoderIds, extendableMediaRecorderWavEncoderBroker.wrap); | ||
var requestPartialEncoding = createRequestPartialEncoding(getEncoderInstance); | ||
@@ -179,11 +185,12 @@ workerFactory.createWorker(self, { | ||
var _deregister = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) { | ||
var port; | ||
var encoderId; | ||
return _regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) switch (_context.prev = _context.next) { | ||
case 0: | ||
port = _ref.port; | ||
encoderId = _ref.encoderId; | ||
deregisterEncoder(encoderId); | ||
return _context.abrupt("return", { | ||
result: deregisterEncoder(port) | ||
result: null | ||
}); | ||
case 2: | ||
case 3: | ||
case "end": | ||
@@ -201,7 +208,7 @@ return _context.stop(); | ||
var _encode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref2) { | ||
var encoderId, timeslice, arrayBuffers; | ||
var encoderInstanceId, timeslice, arrayBuffers; | ||
return _regeneratorRuntime.wrap(function _callee2$(_context2) { | ||
while (1) switch (_context2.prev = _context2.next) { | ||
case 0: | ||
encoderId = _ref2.encoderId, timeslice = _ref2.timeslice; | ||
encoderInstanceId = _ref2.encoderInstanceId, timeslice = _ref2.timeslice; | ||
if (!(timeslice === null)) { | ||
@@ -212,3 +219,3 @@ _context2.next = 7; | ||
_context2.next = 4; | ||
return finishEncoding(encoderId); | ||
return finishEncoding(encoderInstanceId); | ||
case 4: | ||
@@ -220,3 +227,3 @@ _context2.t0 = _context2.sent; | ||
_context2.next = 9; | ||
return requestPartialEncoding(encoderId, timeslice); | ||
return requestPartialEncoding(encoderInstanceId, timeslice); | ||
case 9: | ||
@@ -242,6 +249,6 @@ _context2.t0 = _context2.sent; | ||
instantiate: function instantiate(_ref3) { | ||
var encoderId = _ref3.encoderId, | ||
var encoderInstanceId = _ref3.encoderInstanceId, | ||
mimeType = _ref3.mimeType, | ||
sampleRate = _ref3.sampleRate; | ||
var port = instantiateEncoder(encoderId, mimeType, sampleRate); | ||
var port = instantiateEncoder(encoderInstanceId, mimeType, sampleRate); | ||
return { | ||
@@ -254,9 +261,9 @@ result: port, | ||
var _register = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(_ref4) { | ||
var port; | ||
var encoderId, port; | ||
return _regeneratorRuntime.wrap(function _callee3$(_context3) { | ||
while (1) switch (_context3.prev = _context3.next) { | ||
case 0: | ||
port = _ref4.port; | ||
encoderId = _ref4.encoderId, port = _ref4.port; | ||
_context3.next = 3; | ||
return registerEncoder(port); | ||
return registerEncoder(encoderId, port); | ||
case 3: | ||
@@ -263,0 +270,0 @@ _context3.t0 = _context3.sent; |
@@ -23,4 +23,4 @@ { | ||
"@babel/preset-env": "^7.24.4", | ||
"@commitlint/cli": "^18.6.1", | ||
"@commitlint/config-angular": "^18.6.1", | ||
"@commitlint/cli": "^19.3.0", | ||
"@commitlint/config-angular": "^19.3.0", | ||
"@rollup/plugin-babel": "^6.0.4", | ||
@@ -31,3 +31,3 @@ "chai": "^4.3.10", | ||
"eslint": "^8.57.0", | ||
"eslint-config-holy-grail": "^59.0.4", | ||
"eslint-config-holy-grail": "^59.0.7", | ||
"grunt": "^1.6.1", | ||
@@ -53,3 +53,3 @@ "grunt-cli": "^1.4.3", | ||
"rimraf": "^5.0.5", | ||
"rollup": "^4.14.2", | ||
"rollup": "^4.16.4", | ||
"sinon": "^17.0.1", | ||
@@ -89,3 +89,3 @@ "sinon-chai": "^3.7.0", | ||
"types": "build/es2019/module.d.ts", | ||
"version": "9.2.0" | ||
"version": "10.0.0" | ||
} |
import type { IExtendableMediaRecorderWavEncoderBrokerDefinition } from 'extendable-media-recorder-wav-encoder-broker'; | ||
export const createDeregisterEncoder = | ||
( | ||
encoderBrokerRegistry: Map<string, [RegExp, IExtendableMediaRecorderWavEncoderBrokerDefinition]>, | ||
ports: WeakMap<MessagePort, string> | ||
) => | ||
(port: MessagePort) => { | ||
const regexAsString = ports.get(port); | ||
(encoderBrokerRegistry: Map<string, [RegExp, IExtendableMediaRecorderWavEncoderBrokerDefinition]>, encoderIds: Map<number, string>) => | ||
(encoderId: number) => { | ||
const regexAsString = encoderIds.get(encoderId); | ||
if (regexAsString === undefined) { | ||
throw new Error('There is no encoder stored which wraps this port.'); | ||
throw new Error('There was no encoder stored with the given id.'); | ||
} | ||
encoderBrokerRegistry.delete(regexAsString); | ||
ports.delete(port); | ||
encoderIds.delete(encoderId); | ||
}; |
@@ -8,7 +8,7 @@ import type { closePort as closePortFunction } from '../functions/close-port'; | ||
) => { | ||
return (encoderId: number) => { | ||
const [encoderBroker, port, isRecording, sampleRate] = removeEncoderInstance(encoderId); | ||
return (encoderInstanceId: number) => { | ||
const [encoderBroker, port, isRecording, sampleRate] = removeEncoderInstance(encoderInstanceId); | ||
if (!isRecording) { | ||
return encoderBroker.encode(encoderId, null); | ||
return encoderBroker.encode(encoderInstanceId, null); | ||
} | ||
@@ -21,5 +21,5 @@ | ||
resolve(encoderBroker.encode(encoderId, null)); | ||
resolve(encoderBroker.encode(encoderInstanceId, null)); | ||
} else { | ||
encoderBroker.record(encoderId, sampleRate, data); | ||
encoderBroker.record(encoderInstanceId, sampleRate, data); | ||
} | ||
@@ -26,0 +26,0 @@ }; |
import type { TEncoderInstancesRegistryEntry } from '../types'; | ||
export const createGetEncoderInstance = (encoderInstancesRegistry: Map<number, TEncoderInstancesRegistryEntry>) => { | ||
return (encoderId: number) => { | ||
const entry = encoderInstancesRegistry.get(encoderId); | ||
return (encoderInstanceId: number) => { | ||
const entry = encoderInstancesRegistry.get(encoderInstanceId); | ||
@@ -7,0 +7,0 @@ if (entry === undefined) { |
@@ -11,5 +11,5 @@ import type { TTypedArray } from 'worker-factory'; | ||
) => { | ||
return (encoderId: number, mimeType: string, sampleRate: number) => { | ||
if (encoderInstancesRegistry.has(encoderId)) { | ||
throw new Error(`There is already an encoder registered with an id called "${encoderId}".`); | ||
return (encoderInstanceId: number, mimeType: string, sampleRate: number) => { | ||
if (encoderInstancesRegistry.has(encoderInstanceId)) { | ||
throw new Error(`There is already an encoder instance registered with an id called "${encoderInstanceId}".`); | ||
} | ||
@@ -21,3 +21,3 @@ | ||
encoderInstancesRegistry.set(encoderId, entry); | ||
encoderInstancesRegistry.set(encoderInstanceId, entry); | ||
@@ -31,3 +31,3 @@ port1.onmessage = ({ data }) => { | ||
encoderBroker.record( | ||
encoderId, | ||
encoderInstanceId, | ||
sampleRate, | ||
@@ -34,0 +34,0 @@ data.map((channelDataOrNumberOfSamples: number | TTypedArray) => |
@@ -9,6 +9,6 @@ import type { | ||
encoderBrokerRegistry: Map<string, [RegExp, IExtendableMediaRecorderWavEncoderBrokerDefinition]>, | ||
ports: WeakMap<MessagePort, string>, | ||
encoderIds: Map<number, string>, | ||
wrap: typeof wrapFunction | ||
) => | ||
async (port: MessagePort) => { | ||
async (encoderId: number, port: MessagePort) => { | ||
const encoderBroker = wrap(port); | ||
@@ -18,10 +18,14 @@ const regex = await encoderBroker.characterize(); | ||
if (encoderBrokerRegistry.has(regexAsString) || ports.has(port)) { | ||
if (encoderBrokerRegistry.has(regexAsString)) { | ||
throw new Error('There is already an encoder stored which handles exactly the same mime types.'); | ||
} | ||
if (encoderIds.has(encoderId)) { | ||
throw new Error(`There is already an encoder registered with an id called "${encoderId}".`); | ||
} | ||
encoderBrokerRegistry.set(regexAsString, [regex, encoderBroker]); | ||
ports.set(port, regexAsString); | ||
encoderIds.set(encoderId, regexAsString); | ||
return regex; | ||
}; |
@@ -8,6 +8,6 @@ import type { TEncoderInstancesRegistryEntry } from '../types'; | ||
) => { | ||
return (encoderId: number) => { | ||
const entry = getEncoderInstance(encoderId); | ||
return (encoderInstanceId: number) => { | ||
const entry = getEncoderInstance(encoderInstanceId); | ||
encoderInstancesRegistry.delete(encoderId); | ||
encoderInstancesRegistry.delete(encoderInstanceId); | ||
@@ -14,0 +14,0 @@ return entry; |
import type { createGetEncoderInstance } from './get-encoder-instance'; | ||
export const createRequestPartialEncoding = (getEncoderInstance: ReturnType<typeof createGetEncoderInstance>) => { | ||
return (encoderId: number, timeslice: number) => { | ||
const [encoderBroker] = getEncoderInstance(encoderId); | ||
return (encoderInstanceId: number, timeslice: number) => { | ||
const [encoderBroker] = getEncoderInstance(encoderInstanceId); | ||
return encoderBroker.encode(encoderId, timeslice); | ||
return encoderBroker.encode(encoderInstanceId, timeslice); | ||
}; | ||
}; |
@@ -6,7 +6,7 @@ import { IWorkerDefinition } from 'worker-factory'; | ||
params: { | ||
port: MessagePort; | ||
encoderId: number; | ||
}; | ||
response: { | ||
result: undefined; | ||
result: null; | ||
}; | ||
@@ -17,3 +17,3 @@ }; | ||
params: { | ||
encoderId: number; | ||
encoderInstanceId: number; | ||
@@ -34,3 +34,3 @@ timeslice: null | number; | ||
params: { | ||
encoderId: number; | ||
encoderInstanceId: number; | ||
@@ -51,2 +51,4 @@ mimeType: string; | ||
params: { | ||
encoderId: number; | ||
port: MessagePort; | ||
@@ -53,0 +55,0 @@ }; |
@@ -23,4 +23,4 @@ import { IExtendableMediaRecorderWavEncoderBrokerDefinition, wrap } from 'extendable-media-recorder-wav-encoder-broker'; | ||
const encoderBrokerRegistry: Map<string, [RegExp, IExtendableMediaRecorderWavEncoderBrokerDefinition]> = new Map(); | ||
const ports = new WeakMap<MessagePort, string>(); | ||
const deregisterEncoder = createDeregisterEncoder(encoderBrokerRegistry, ports); | ||
const encoderIds = new Map<number, string>(); | ||
const deregisterEncoder = createDeregisterEncoder(encoderBrokerRegistry, encoderIds); | ||
const encoderInstancesRegistry: Map<number, TEncoderInstancesRegistryEntry> = new Map(); | ||
@@ -32,22 +32,25 @@ const getEncoderInstance = createGetEncoderInstance(encoderInstancesRegistry); | ||
const instantiateEncoder = createInstantiateEncoder(closePort, encoderInstancesRegistry, pickCapableEncoderBroker); | ||
const registerEncoder = createRegisterEncoder(encoderBrokerRegistry, ports, wrap); | ||
const registerEncoder = createRegisterEncoder(encoderBrokerRegistry, encoderIds, wrap); | ||
const requestPartialEncoding = createRequestPartialEncoding(getEncoderInstance); | ||
createWorker<IMediaEncoderHostWorkerCustomDefinition>(self, <TWorkerImplementation<IMediaEncoderHostWorkerCustomDefinition>>{ | ||
deregister: async ({ port }) => { | ||
return { result: deregisterEncoder(port) }; | ||
deregister: async ({ encoderId }) => { | ||
deregisterEncoder(encoderId); | ||
return { result: null }; | ||
}, | ||
encode: async ({ encoderId, timeslice }) => { | ||
const arrayBuffers = timeslice === null ? await finishEncoding(encoderId) : await requestPartialEncoding(encoderId, timeslice); | ||
encode: async ({ encoderInstanceId, timeslice }) => { | ||
const arrayBuffers = | ||
timeslice === null ? await finishEncoding(encoderInstanceId) : await requestPartialEncoding(encoderInstanceId, timeslice); | ||
return { result: arrayBuffers, transferables: arrayBuffers }; | ||
}, | ||
instantiate: ({ encoderId, mimeType, sampleRate }) => { | ||
const port = instantiateEncoder(encoderId, mimeType, sampleRate); | ||
instantiate: ({ encoderInstanceId, mimeType, sampleRate }) => { | ||
const port = instantiateEncoder(encoderInstanceId, mimeType, sampleRate); | ||
return { result: port, transferables: [port] }; | ||
}, | ||
register: async ({ port }) => { | ||
return { result: await registerEncoder(port) }; | ||
register: async ({ encoderId, port }) => { | ||
return { result: await registerEncoder(encoderId, port) }; | ||
} | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
54055
724