opus-codec 1.0.3 → 1.0.9

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.
@@ -1,7 +1,10 @@
1
1
  import { IWorkerRequest, RequestResponse, RequestResponseType } from './actions.js';
2
+ export interface IClientOptions {
3
+ timeout: number;
4
+ }
2
5
  export default class Client {
3
6
  #private;
4
- constructor(worker: Worker);
7
+ constructor(worker: Worker, clientOptions?: Partial<IClientOptions>);
5
8
  close(): void;
6
9
  sendMessage<T extends IWorkerRequest<unknown, unknown>>(data: T): Promise<RequestResponse<RequestResponseType<T>>>;
7
10
  private onMessageError;
@@ -1 +1 @@
1
- {"version":3,"file":"Client.d.ts","sourceRoot":"","sources":["../../actions/Client.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,cAAc,EACd,eAAe,EACf,mBAAmB,EACtB,MAAM,cAAc,CAAC;AAEtB,MAAM,CAAC,OAAO,OAAO,MAAM;;gBAMJ,MAAM,EAAE,MAAM;IAM1B,KAAK;IAUL,WAAW,CAAC,CAAC,SAAS,cAAc,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC;IAuBtE,OAAO,CAAC,cAAc,CAEpB;IACF,OAAO,CAAC,OAAO,CAEb;IACF,OAAO,CAAC,SAAS,CAQf;CACL"}
1
+ {"version":3,"file":"Client.d.ts","sourceRoot":"","sources":["../../actions/Client.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,cAAc,EACd,eAAe,EACf,mBAAmB,EACtB,MAAM,cAAc,CAAC;AAEtB,MAAM,WAAW,cAAc;IAC3B,OAAO,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,CAAC,OAAO,OAAO,MAAM;;gBAQnB,MAAM,EAAE,MAAM,EACd,aAAa,GAAE,OAAO,CAAC,cAAc,CAAM;IAWxC,KAAK;IAUL,WAAW,CAAC,CAAC,SAAS,cAAc,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC;IA0BtE,OAAO,CAAC,cAAc,CAEpB;IACF,OAAO,CAAC,OAAO,CAEb;IACF,OAAO,CAAC,SAAS,CAQf;CACL"}
@@ -1,8 +1,13 @@
1
1
  export default class Client {
2
2
  #worker;
3
3
  #pending = new Map();
4
- constructor(worker) {
4
+ #clientOptions;
5
+ constructor(worker, clientOptions = {}) {
5
6
  this.#worker = worker;
7
+ this.#clientOptions = {
8
+ timeout: 10000,
9
+ ...clientOptions
10
+ };
6
11
  worker.addEventListener('message', this.onMessage);
7
12
  worker.addEventListener('messageerror', this.onMessageError);
8
13
  worker.addEventListener('error', this.onError);
@@ -13,12 +18,11 @@ export default class Client {
13
18
  this.#pending.delete(p[0]);
14
19
  p[1]({
15
20
  requestId: p[0],
16
- failures: ['Worker destroyed'],
21
+ failures: ['Worker destroyed']
17
22
  });
18
23
  }
19
24
  }
20
25
  sendMessage(data) {
21
- const waitTimeBeforeResolvingAutomaticallyInMilliseconds = 10000;
22
26
  return new Promise((resolve, reject) => {
23
27
  if (this.#pending.has(data.requestId)) {
24
28
  reject(new Error(`Request already exists: ${data.requestId}`));
@@ -28,15 +32,20 @@ export default class Client {
28
32
  resolve({
29
33
  requestId: data.requestId,
30
34
  failures: [
31
- `Timeout expired. It took more than ${waitTimeBeforeResolvingAutomaticallyInMilliseconds} to resolve this request.`,
32
- ],
35
+ `Timeout expired. It took more than ${this.#clientOptions.timeout} ms to resolve this request.`
36
+ ]
33
37
  });
34
- }, waitTimeBeforeResolvingAutomaticallyInMilliseconds);
38
+ }, this.#clientOptions.timeout);
35
39
  this.#pending.set(data.requestId, (data) => {
36
40
  clearTimeout(timeoutId);
37
41
  resolve(data);
38
42
  });
39
- this.#worker.postMessage(data);
43
+ if (data.transfer) {
44
+ this.#worker.postMessage(data, data.transfer);
45
+ }
46
+ else {
47
+ this.#worker.postMessage(data);
48
+ }
40
49
  });
41
50
  }
42
51
  onMessageError = (e) => {
@@ -1 +1 @@
1
- {"version":3,"file":"Client.js","sourceRoot":"","sources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AC;YAChC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,EAAE;gBACvC,YAAY,CAAC,SAAS,CAAC,CAAC;gBACxB,OAAO,CAAC,IAAgB,CAAC,CAAC;YAC9B,CAAC,CAAC,CAAC;YACH,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;gBAChB,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;YAClD,CAAC;iBAAM,CAAC;gBACJ,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;YACnC,CAAC;QACL,CAAC,CAAC,CAAC;IACP,CAAC;IACO,cAAc,GAAG,CAAC,CAAe,EAAE,EAAE;QACzC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACrB,CAAC,CAAC;IACM,OAAO,GAAG,CAAC,CAAa,EAAE,EAAE;QAChC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACrB,CAAC,CAAC;IACM,SAAS,GAAG,CAAC,CAAe,EAAE,EAAE;QACpC,MAAM,IAAI,GAAG,CAAC,CAAC,IAAgC,CAAC;QAChD,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAClD,IAAI,CAAC,OAAO,EAAE,CAAC;YACX,OAAO,CAAC,KAAK,CAAC,mCAAmC,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;YACnE,OAAO;QACX,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,CAAC;IAClB,CAAC,CAAC;CACL"}
@@ -6,10 +6,11 @@ export interface IWorkerRequest<Data, Response> {
6
6
  requestId: RequestId;
7
7
  }
8
8
  export type CodecId = string;
9
- export type RequestResponse<T> = {
9
+ export interface IRequestResponseSuccess<T> {
10
10
  requestId: RequestId;
11
11
  value: T;
12
- } | {
12
+ }
13
+ export type RequestResponse<T> = IRequestResponseSuccess<T> | {
13
14
  requestId: RequestId;
14
15
  failures: string[];
15
16
  };
@@ -30,6 +31,7 @@ export interface IOpusSetRequest extends IWorkerRequest<OpusSetRequest, boolean>
30
31
  }
31
32
  export declare function setToEncoder(data: OpusSetRequest): IOpusSetRequest;
32
33
  export interface ICreateEncoder extends IWorkerRequest<ICreateEncoderOptions, CodecId> {
34
+ encoderId: CodecId;
33
35
  type: RequestType.CreateEncoder;
34
36
  }
35
37
  export interface ICreateDecoderOptions {
@@ -38,16 +40,17 @@ export interface ICreateDecoderOptions {
38
40
  frameSize: number;
39
41
  }
40
42
  export interface ICreateDecoder extends IWorkerRequest<ICreateDecoderOptions, CodecId> {
43
+ decoderId: CodecId;
41
44
  type: RequestType.CreateDecoder;
42
45
  }
43
- export declare function createDecoder(sampleRate: number, channels: number, frameSize: number): ICreateDecoder;
46
+ export declare function createDecoder({ sampleRate, channels, frameSize }: ICreateDecoderOptions): ICreateDecoder;
44
47
  export interface IDestroyEncoderOptions {
45
48
  encoderId: CodecId;
46
49
  }
47
- export interface IDestroyEncoder extends IWorkerRequest<CodecId, null> {
50
+ export interface IDestroyEncoder extends IWorkerRequest<IDestroyEncoderOptions, null> {
48
51
  type: RequestType.DestroyEncoder;
49
52
  }
50
- export declare function destroyEncoder(encoderId: CodecId): IDestroyEncoder;
53
+ export declare function destroyEncoder(data: IDestroyEncoderOptions): IDestroyEncoder;
51
54
  export interface IDrainRingBufferResult {
52
55
  }
53
56
  export declare enum RequestType {
@@ -68,12 +71,13 @@ export interface IInitializeWorkerOptions {
68
71
  wasmFileHref: string;
69
72
  }
70
73
  export declare function initializeWorker(data: IInitializeWorkerOptions): IInitializeWorker;
71
- export interface IDestroyDecoder extends IWorkerRequest<{
74
+ export interface IDestroyDecoderOptions {
72
75
  decoderId: CodecId;
73
- }, null> {
76
+ }
77
+ export interface IDestroyDecoder extends IWorkerRequest<IDestroyDecoderOptions, null> {
74
78
  type: RequestType.DestroyDecoder;
75
79
  }
76
- export declare function destroyDecoder(decoderId: CodecId): IDestroyDecoder;
80
+ export declare function destroyDecoder(data: IDestroyDecoderOptions): IDestroyDecoder;
77
81
  export interface IDecodeFloatOptions {
78
82
  decoderId: CodecId;
79
83
  decodeFec?: number;
@@ -1 +1 @@
1
- {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../actions/actions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAE3D,MAAM,WAAW,cAAc,CAAC,IAAI,EAAE,QAAQ;IAC1C,IAAI,EAAE,IAAI,CAAC;IACX,SAAS,CAAC,EAAE,eAAe,CAAC,QAAQ,CAAC,CAAC;IACtC,QAAQ,CAAC,EAAE,WAAW,EAAE,CAAC;IACzB,SAAS,EAAE,SAAS,CAAC;CACxB;AAED,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC;AAE7B,MAAM,MAAM,eAAe,CAAC,CAAC,IACvB;IACI,SAAS,EAAE,SAAS,CAAC;IACrB,KAAK,EAAE,CAAC,CAAC;CACZ,GACD;IACI,SAAS,EAAE,SAAS,CAAC;IACrB,QAAQ,EAAE,MAAM,EAAE,CAAC;CACtB,CAAC;AAER,MAAM,MAAM,SAAS,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC;AAExD,MAAM,WAAW,qBAAqB;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,eACb,SAAQ,cAAc,CAAC,cAAc,EAAE,MAAM,CAAC;IAC9C,IAAI,EAAE,WAAW,CAAC,cAAc,CAAC;CACpC;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,cAAc,GAAG,eAAe,CAMpE;AAED,MAAM,WAAW,eACb,SAAQ,cAAc,CAAC,cAAc,E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C,SAAS,EAAE,OAAO,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,KAAK,EAAE;QACH,GAAG,EAAE,YAAY,CAAC,WAAW,CAAC,CAAC;KAClC,GAAG,IAAI,CAAC;CACZ;AAED,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAC7B,CAAC,SAAS,cAAc,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAE3D,MAAM,MAAM,aAAa,GACnB,iBAAiB,GACjB,YAAY,GACZ,cAAc,GACd,cAAc,GACd,eAAe,GACf,YAAY,GACZ,eAAe,GACf,eAAe,GACf,eAAe,CAAC;AAMtB,iBAAS,YAAY,WAEpB;AAMD,wBAAgB,aAAa,CAAC,IAAI,EAAE,qBAAqB,GAAG,cAAc,CAOzE;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,mBAAmB,GAAG,YAAY,CAOnE"}
@@ -2,32 +2,33 @@ export function getFromEncoder(data) {
2
2
  return {
3
3
  type: RequestType.OpusGetRequest,
4
4
  data,
5
- requestId: getRequestId(),
5
+ requestId: getRequestId()
6
6
  };
7
7
  }
8
8
  export function setToEncoder(data) {
9
9
  return {
10
10
  type: RequestType.OpusSetRequest,
11
11
  data,
12
- requestId: getRequestId(),
12
+ requestId: getRequestId()
13
13
  };
14
14
  }
15
- export function createDecoder(sampleRate, channels, frameSize) {
15
+ export function createDecoder({ sampleRate, channels, frameSize }) {
16
16
  return {
17
17
  type: RequestType.CreateDecoder,
18
+ decoderId: generateCodecId(),
18
19
  data: {
19
20
  frameSize,
20
21
  sampleRate,
21
- channels,
22
+ channels
22
23
  },
23
- requestId: getRequestId(),
24
+ requestId: getRequestId()
24
25
  };
25
26
  }
26
- export function destroyEncoder(encoderId) {
27
+ export function destroyEncoder(data) {
27
28
  return {
28
29
  type: RequestType.DestroyEncoder,
29
- data: encoderId,
30
- requestId: getRequestId(),
30
+ data,
31
+ requestId: getRequestId()
31
32
  };
32
33
  }
33
34
  export var RequestType;
@@ -46,16 +47,14 @@ export function initializeWorker(data) {
46
47
  return {
47
48
  requestId: getRequestId(),
48
49
  data,
49
- type: RequestType.InitializeWorker,
50
+ type: RequestType.InitializeWorker
50
51
  };
51
52
  }
52
- export function destroyDecoder(decoderId) {
53
+ export function destroyDecoder(data) {
53
54
  return {
54
55
  type: RequestType.DestroyDecoder,
55
- data: {
56
- decoderId,
57
- },
58
- requestId: getRequestId(),
56
+ data,
57
+ requestId: getRequestId()
59
58
  };
60
59
  }
61
60
  export function decodeFloat(data) {
@@ -63,18 +62,24 @@ export function decodeFloat(data) {
63
62
  type: RequestType.DecodeFloat,
64
63
  data,
65
64
  requestId: getRequestId(),
66
- transfer: [data.encoded],
65
+ transfer: [data.encoded]
67
66
  };
68
67
  }
68
+ function generateRandomId() {
69
+ return crypto.getRandomValues(new Uint32Array(4)).join('-');
70
+ }
69
71
  function getRequestId() {
70
- const ids = crypto.getRandomValues(new Int32Array(4));
71
- return ids.join('-');
72
+ return generateRandomId();
73
+ }
74
+ function generateCodecId() {
75
+ return generateRandomId();
72
76
  }
73
77
  export function createEncoder(data) {
74
78
  return {
75
79
  data,
80
+ encoderId: generateCodecId(),
76
81
  requestId: getRequestId(),
77
- type: RequestType.CreateEncoder,
82
+ type: RequestType.CreateEncoder
78
83
  };
79
84
  }
80
85
  export function encodeFloat(data) {
@@ -82,7 +87,7 @@ export function encodeFloat(data) {
82
87
  data,
83
88
  requestId: getRequestId(),
84
89
  type: RequestType.EncodeFloat,
85
- transfer: data.input !== null ? [data.input.pcm.buffer] : [],
90
+ transfer: data.input !== null ? [data.input.pcm.buffer] : []
86
91
  };
87
92
  }
88
93
  //# sourceMappingURL=actions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"actions.js","sourceRoot":"","sources":["../../actions/actions.ts"],"names":[],"mappings":"AAoCA,MAAM,UAAU,cAAc,CAAC,IAAoB;IAC/C,OAAO;QACH,IAAI,EAAE,WAAW,CAAC,cAA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E,CAAC;AAED,SAAS,YAAY;IACjB,OAAO,gBAAgB,EAAE,CAAC;AAC9B,CAAC;AAED,SAAS,eAAe;IACpB,OAAO,gBAAgB,EAAE,CAAC;AAC9B,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,IAA2B;IACrD,OAAO;QACH,IAAI;QACJ,SAAS,EAAE,eAAe,EAAE;QAC5B,SAAS,EAAE,YAAY,EAAE;QACzB,IAAI,EAAE,WAAW,CAAC,aAAa;KAClC,CAAC;AACN,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,IAAyB;IACjD,OAAO;QACH,IAAI;QACJ,SAAS,EAAE,YAAY,EAAE;QACzB,IAAI,EAAE,WAAW,CAAC,WAAW;QAC7B,QAAQ,EAAE,IAAI,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE;KAC/D,CAAC;AACN,CAAC"}
@@ -1,2 +1,4 @@
1
+ import { type RequestResponse } from './actions.js';
1
2
  export * as default from './actions.js';
3
+ export declare function successOrFail<T>(pendingResponse: RequestResponse<T> | Promise<RequestResponse<T>>): Promise<import("./actions.js").IRequestResponseSuccess<T>>;
2
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../actions/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../actions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AAExC,wBAAsB,aAAa,CAAC,CAAC,EACjC,eAAe,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,8DASpE"}
@@ -1,2 +1,9 @@
1
1
  export * as default from './actions.js';
2
+ export async function successOrFail(pendingResponse) {
3
+ const response = await Promise.resolve(pendingResponse);
4
+ if ('failures' in response) {
5
+ throw new Error(`Request ${response.requestId} failed: ${response.failures?.join(', ')}`);
6
+ }
7
+ return response;
8
+ }
2
9
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../actions/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../actions/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AAExC,MAAM,CAAC,KAAK,UAAU,aAAa,CAC/B,eAAiE;IAEjE,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;IACxD,IAAI,UAAU,IAAI,QAAQ,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CACX,WAAW,QAAQ,CAAC,SAAS,YAAY,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE,CAC3E,CAAC;IACN,CAAC;IACD,OAAO,QAAQ,CAAC;AACpB,CAAC"}
@@ -16,7 +16,7 @@ export class OpusGettersAndSetters {
16
16
  getComplexity() {
17
17
  const result = this.#runtime.originalRuntime().opus_get_complexity(this.#opusEncoderOffset, this.#value.offset());
18
18
  if (result != constants.OPUS_OK)
19
- throw new Error('Failed to set OPUS_GET_COMPLEXITY');
19
+ throw new Error('Failed to get OPUS_GET_COMPLEXITY');
20
20
  return this.#value.value();
21
21
  }
22
22
  setBitrate(x) {
@@ -26,7 +26,7 @@ export class OpusGettersAndSetters {
26
26
  getBitrate() {
27
27
  const result = this.#runtime.originalRuntime().opus_get_bitrate(this.#opusEncoderOffset, this.#value.offset());
28
28
  if (result != constants.OPUS_OK)
29
- throw new Error('Failed to set OPUS_GET_BITRATE');
29
+ throw new Error('Failed to get OPUS_GET_BITRATE');
30
30
  return this.#value.value();
31
31
  }
32
32
  setVbr(x) {
@@ -36,7 +36,7 @@ export class OpusGettersAndSetters {
36
36
  getVbr() {
37
37
  const result = this.#runtime.originalRuntime().opus_get_vbr(this.#opusEncoderOffset, this.#value.offset());
38
38
  if (result != constants.OPUS_OK)
39
- throw new Error('Failed to set OPUS_GET_VBR');
39
+ throw new Error('Failed to get OPUS_GET_VBR');
40
40
  return this.#value.value();
41
41
  }
42
42
  setVbrConstraint(x) {
@@ -46,7 +46,7 @@ export class OpusGettersAndSetters {
46
46
  getVbrConstraint() {
47
47
  const result = this.#runtime.originalRuntime().opus_get_vbr_constraint(this.#opusEncoderOffset, this.#value.offset());
48
48
  if (result != constants.OPUS_OK)
49
- throw new Error('Failed to set OPUS_GET_VBR_CONSTRAINT');
49
+ throw new Error('Failed to get OPUS_GET_VBR_CONSTRAINT');
50
50
  return this.#value.value();
51
51
  }
52
52
  setForceChannels(x) {
@@ -56,7 +56,7 @@ export class OpusGettersAndSetters {
56
56
  getForceChannels() {
57
57
  const result = this.#runtime.originalRuntime().opus_get_force_channels(this.#opusEncoderOffset, this.#value.offset());
58
58
  if (result != constants.OPUS_OK)
59
- throw new Error('Failed to set OPUS_GET_FORCE_CHANNELS');
59
+ throw new Error('Failed to get OPUS_GET_FORCE_CHANNELS');
60
60
  return this.#value.value();
61
61
  }
62
62
  setMaxBandwidth(x) {
@@ -66,7 +66,7 @@ export class OpusGettersAndSetters {
66
66
  getMaxBandwidth() {
67
67
  const result = this.#runtime.originalRuntime().opus_get_max_bandwidth(this.#opusEncoderOffset, this.#value.offset());
68
68
  if (result != constants.OPUS_OK)
69
- throw new Error('Failed to set OPUS_GET_MAX_BANDWIDTH');
69
+ throw new Error('Failed to get OPUS_GET_MAX_BANDWIDTH');
70
70
  return this.#value.value();
71
71
  }
72
72
  setBandwidth(x) {
@@ -80,7 +80,7 @@ export class OpusGettersAndSetters {
80
80
  getSignal() {
81
81
  const result = this.#runtime.originalRuntime().opus_get_signal(this.#opusEncoderOffset, this.#value.offset());
82
82
  if (result != constants.OPUS_OK)
83
- throw new Error('Failed to set OPUS_GET_SIGNAL');
83
+ throw new Error('Failed to get OPUS_GET_SIGNAL');
84
84
  return this.#value.value();
85
85
  }
86
86
  setApplication(x) {
@@ -90,13 +90,13 @@ export class OpusGettersAndSetters {
90
90
  getApplication() {
91
91
  const result = this.#runtime.originalRuntime().opus_get_application(this.#opusEncoderOffset, this.#value.offset());
92
92
  if (result != constants.OPUS_OK)
93
- throw new Error('Failed to set OPUS_GET_APPLICATION');
93
+ throw new Error('Failed to get OPUS_GET_APPLICATION');
94
94
  return this.#value.value();
95
95
  }
96
96
  getLookahead() {
97
97
  const result = this.#runtime.originalRuntime().opus_get_lookahead(this.#opusEncoderOffset, this.#value.offset());
98
98
  if (result != constants.OPUS_OK)
99
- throw new Error('Failed to set OPUS_GET_LOOKAHEAD');
99
+ throw new Error('Failed to get OPUS_GET_LOOKAHEAD');
100
100
  return this.#value.value();
101
101
  }
102
102
  setInbandFec(x) {
@@ -106,7 +106,7 @@ export class OpusGettersAndSetters {
106
106
  getInbandFec() {
107
107
  const result = this.#runtime.originalRuntime().opus_get_inband_fec(this.#opusEncoderOffset, this.#value.offset());
108
108
  if (result != constants.OPUS_OK)
109
- throw new Error('Failed to set OPUS_GET_INBAND_FEC');
109
+ throw new Error('Failed to get OPUS_GET_INBAND_FEC');
110
110
  return this.#value.value();
111
111
  }
112
112
  setPacketLossperc(x) {
@@ -116,7 +116,7 @@ export class OpusGettersAndSetters {
116
116
  getPacketLossperc() {
117
117
  const result = this.#runtime.originalRuntime().opus_get_packet_loss_perc(this.#opusEncoderOffset, this.#value.offset());
118
118
  if (result != constants.OPUS_OK)
119
- throw new Error('Failed to set OPUS_GET_PACKET_LOSS_PERC');
119
+ throw new Error('Failed to get OPUS_GET_PACKET_LOSS_PERC');
120
120
  return this.#value.value();
121
121
  }
122
122
  setDtx(x) {
@@ -126,7 +126,7 @@ export class OpusGettersAndSetters {
126
126
  getDtx() {
127
127
  const result = this.#runtime.originalRuntime().opus_get_dtx(this.#opusEncoderOffset, this.#value.offset());
128
128
  if (result != constants.OPUS_OK)
129
- throw new Error('Failed to set OPUS_GET_DTX');
129
+ throw new Error('Failed to get OPUS_GET_DTX');
130
130
  return this.#value.value();
131
131
  }
132
132
  setLsbDepth(x) {
@@ -136,7 +136,7 @@ export class OpusGettersAndSetters {
136
136
  getLsbDepth() {
137
137
  const result = this.#runtime.originalRuntime().opus_get_lsb_depth(this.#opusEncoderOffset, this.#value.offset());
138
138
  if (result != constants.OPUS_OK)
139
- throw new Error('Failed to set OPUS_GET_LSB_DEPTH');
139
+ throw new Error('Failed to get OPUS_GET_LSB_DEPTH');
140
140
  return this.#value.value();
141
141
  }
142
142
  setExpertFrameduration(x) {
@@ -146,7 +146,7 @@ export class OpusGettersAndSetters {
146
146
  getExpertFrameduration() {
147
147
  const result = this.#runtime.originalRuntime().opus_get_expert_frame_duration(this.#opusEncoderOffset, this.#value.offset());
148
148
  if (result != constants.OPUS_OK)
149
- throw new Error('Failed to set OPUS_GET_EXPERT_FRAME_DURATION');
149
+ throw new Error('Failed to get OPUS_GET_EXPERT_FRAME_DURATION');
150
150
  return this.#value.value();
151
151
  }
152
152
  setPredictionDisabled(x) {
@@ -156,19 +156,19 @@ export class OpusGettersAndSetters {
156
156
  getPredictionDisabled() {
157
157
  const result = this.#runtime.originalRuntime().opus_get_prediction_disabled(this.#opusEncoderOffset, this.#value.offset());
158
158
  if (result != constants.OPUS_OK)
159
- throw new Error('Failed to set OPUS_GET_PREDICTION_DISABLED');
159
+ throw new Error('Failed to get OPUS_GET_PREDICTION_DISABLED');
160
160
  return this.#value.value();
161
161
  }
162
162
  getBandwidth() {
163
163
  const result = this.#runtime.originalRuntime().opus_get_bandwidth(this.#opusEncoderOffset, this.#value.offset());
164
164
  if (result != constants.OPUS_OK)
165
- throw new Error('Failed to set OPUS_GET_BANDWIDTH');
165
+ throw new Error('Failed to get OPUS_GET_BANDWIDTH');
166
166
  return this.#value.value();
167
167
  }
168
168
  getSampleRate() {
169
169
  const result = this.#runtime.originalRuntime().opus_get_sample_rate(this.#opusEncoderOffset, this.#value.offset());
170
170
  if (result != constants.OPUS_OK)
171
- throw new Error('Failed to set OPUS_GET_SAMPLE_RATE');
171
+ throw new Error('Failed to get OPUS_GET_SAMPLE_RATE');
172
172
  return this.#value.value();
173
173
  }
174
174
  setPhaseInversiondisabled(x) {
@@ -178,13 +178,13 @@ export class OpusGettersAndSetters {
178
178
  getPhaseInversiondisabled() {
179
179
  const result = this.#runtime.originalRuntime().opus_get_phase_inversion_disabled(this.#opusEncoderOffset, this.#value.offset());
180
180
  if (result != constants.OPUS_OK)
181
- throw new Error('Failed to set OPUS_GET_PHASE_INVERSION_DISABLED');
181
+ throw new Error('Failed to get OPUS_GET_PHASE_INVERSION_DISABLED');
182
182
  return this.#value.value();
183
183
  }
184
184
  getInDtx() {
185
185
  const result = this.#runtime.originalRuntime().opus_get_in_dtx(this.#opusEncoderOffset, this.#value.offset());
186
186
  if (result != constants.OPUS_OK)
187
- throw new Error('Failed to set OPUS_GET_IN_DTX');
187
+ throw new Error('Failed to get OPUS_GET_IN_DTX');
188
188
  return this.#value.value();
189
189
  }
190
190
  setGain(x) {
@@ -194,19 +194,19 @@ export class OpusGettersAndSetters {
194
194
  getGain() {
195
195
  const result = this.#runtime.originalRuntime().opus_get_gain(this.#opusEncoderOffset, this.#value.offset());
196
196
  if (result != constants.OPUS_OK)
197
- throw new Error('Failed to set OPUS_GET_GAIN');
197
+ throw new Error('Failed to get OPUS_GET_GAIN');
198
198
  return this.#value.value();
199
199
  }
200
200
  getLastPacketduration() {
201
201
  const result = this.#runtime.originalRuntime().opus_get_last_packet_duration(this.#opusEncoderOffset, this.#value.offset());
202
202
  if (result != constants.OPUS_OK)
203
- throw new Error('Failed to set OPUS_GET_LAST_PACKET_DURATION');
203
+ throw new Error('Failed to get OPUS_GET_LAST_PACKET_DURATION');
204
204
  return this.#value.value();
205
205
  }
206
206
  getPitch() {
207
207
  const result = this.#runtime.originalRuntime().opus_get_pitch(this.#opusEncoderOffset, this.#value.offset());
208
208
  if (result != constants.OPUS_OK)
209
- throw new Error('Failed to set OPUS_GET_PITCH');
209
+ throw new Error('Failed to get OPUS_GET_PITCH');
210
210
  return this.#value.value();
211
211
  }
212
212
  destroy() {
package/native/index.js CHANGED
@@ -5,40 +5,9 @@ async function wasmNoop(returnValue) {
5
5
  };
6
6
  }
7
7
 
8
- async function createModule({ wasmFileHref } = {}) {
9
- const wasi_snapshot_preview1 = {};
10
- for (const funcName of [
11
- 'args_get',
12
- 'args_sizes_get',
13
- 'fd_close',
14
- 'fd_seek',
15
- 'fd_write',
16
- 'proc_exit'
17
- ]) {
18
- wasi_snapshot_preview1[funcName] = function (args) {
19
- console.log('[%s] called with %o', funcName, args);
20
- return 0; // Success
21
- };
22
- }
23
-
24
- const importObject = {
25
- wasi_snapshot_preview1
26
- };
27
-
28
- let memory;
29
- const shouldImportMemory = process.env['WASI_IMPORT_MEMORY'];
30
-
31
- if (shouldImportMemory) {
32
- memory = new WebAssembly.Memory({ initial: 256, maximum: 32768 });
33
- importObject['env'] = {
34
- memory
35
- };
36
- } else {
37
- memory = null;
38
- }
39
-
8
+ async function getInstantiatedSource({ wasmFileHref, importObject }) {
40
9
  let pendingWebAssemblyInstantiateSource;
41
- if (process.env['NODE_ENV'] !== 'production') {
10
+ if ('process' in globalThis && process.env['RUNTIME'] === 'nodejs') {
42
11
  const fs = await import('fs');
43
12
  const path = await import('path');
44
13
  const wasmPath = path.resolve(import.meta.dirname, 'index.wasm');
@@ -48,11 +17,6 @@ async function createModule({ wasmFileHref } = {}) {
48
17
  importObject
49
18
  );
50
19
  } else {
51
- if (typeof wasmFileHref !== 'string') {
52
- const wasmBinaryUrl = await import('./index.wasm');
53
- wasmFileHref = wasmBinaryUrl.default;
54
- }
55
-
56
20
  if (typeof wasmFileHref !== 'string') {
57
21
  throw new Error('Invalid wasmFileHref');
58
22
  }
@@ -62,12 +26,35 @@ async function createModule({ wasmFileHref } = {}) {
62
26
  await WebAssembly.instantiateStreaming(response, importObject);
63
27
  }
64
28
 
65
- const webAssemblyInstantiatedSource =
66
- await pendingWebAssemblyInstantiateSource;
29
+ return pendingWebAssemblyInstantiateSource;
30
+ }
67
31
 
68
- if (!shouldImportMemory) {
69
- memory = webAssemblyInstantiatedSource.instance.exports.memory;
32
+ async function createModule({ wasmFileHref } = {}) {
33
+ const wasi_snapshot_preview1 = {};
34
+ for (const funcName of [
35
+ 'args_get',
36
+ 'args_sizes_get',
37
+ 'fd_close',
38
+ 'fd_seek',
39
+ 'fd_write',
40
+ 'proc_exit'
41
+ ]) {
42
+ wasi_snapshot_preview1[funcName] = function (args) {
43
+ console.log('[%s] called with %o', funcName, args);
44
+ return 0; // Success
45
+ };
70
46
  }
47
+
48
+ const importObject = {
49
+ wasi_snapshot_preview1
50
+ };
51
+
52
+ const webAssemblyInstantiatedSource = await getInstantiatedSource({
53
+ wasmFileHref,
54
+ importObject
55
+ });
56
+ const memory =
57
+ webAssemblyInstantiatedSource.instance.exports.memory ?? null;
71
58
  if (memory === null) {
72
59
  throw new Error('Memory was expected to be imported but is null');
73
60
  }
@@ -16,7 +16,7 @@ export class OpusGettersAndSetters {
16
16
  getComplexity() {
17
17
  const result = this.#runtime.originalRuntime().opus_get_complexity(this.#opusEncoderOffset, this.#value.offset());
18
18
  if (result != constants.OPUS_OK)
19
- throw new Error('Failed to set OPUS_GET_COMPLEXITY');
19
+ throw new Error('Failed to get OPUS_GET_COMPLEXITY');
20
20
  return this.#value.value();
21
21
  }
22
22
  setBitrate(x) {
@@ -26,7 +26,7 @@ export class OpusGettersAndSetters {
26
26
  getBitrate() {
27
27
  const result = this.#runtime.originalRuntime().opus_get_bitrate(this.#opusEncoderOffset, this.#value.offset());
28
28
  if (result != constants.OPUS_OK)
29
- throw new Error('Failed to set OPUS_GET_BITRATE');
29
+ throw new Error('Failed to get OPUS_GET_BITRATE');
30
30
  return this.#value.value();
31
31
  }
32
32
  setVbr(x) {
@@ -36,7 +36,7 @@ export class OpusGettersAndSetters {
36
36
  getVbr() {
37
37
  const result = this.#runtime.originalRuntime().opus_get_vbr(this.#opusEncoderOffset, this.#value.offset());
38
38
  if (result != constants.OPUS_OK)
39
- throw new Error('Failed to set OPUS_GET_VBR');
39
+ throw new Error('Failed to get OPUS_GET_VBR');
40
40
  return this.#value.value();
41
41
  }
42
42
  setVbrConstraint(x) {
@@ -46,7 +46,7 @@ export class OpusGettersAndSetters {
46
46
  getVbrConstraint() {
47
47
  const result = this.#runtime.originalRuntime().opus_get_vbr_constraint(this.#opusEncoderOffset, this.#value.offset());
48
48
  if (result != constants.OPUS_OK)
49
- throw new Error('Failed to set OPUS_GET_VBR_CONSTRAINT');
49
+ throw new Error('Failed to get OPUS_GET_VBR_CONSTRAINT');
50
50
  return this.#value.value();
51
51
  }
52
52
  setForceChannels(x) {
@@ -56,7 +56,7 @@ export class OpusGettersAndSetters {
56
56
  getForceChannels() {
57
57
  const result = this.#runtime.originalRuntime().opus_get_force_channels(this.#opusEncoderOffset, this.#value.offset());
58
58
  if (result != constants.OPUS_OK)
59
- throw new Error('Failed to set OPUS_GET_FORCE_CHANNELS');
59
+ throw new Error('Failed to get OPUS_GET_FORCE_CHANNELS');
60
60
  return this.#value.value();
61
61
  }
62
62
  setMaxBandwidth(x) {
@@ -66,7 +66,7 @@ export class OpusGettersAndSetters {
66
66
  getMaxBandwidth() {
67
67
  const result = this.#runtime.originalRuntime().opus_get_max_bandwidth(this.#opusEncoderOffset, this.#value.offset());
68
68
  if (result != constants.OPUS_OK)
69
- throw new Error('Failed to set OPUS_GET_MAX_BANDWIDTH');
69
+ throw new Error('Failed to get OPUS_GET_MAX_BANDWIDTH');
70
70
  return this.#value.value();
71
71
  }
72
72
  setBandwidth(x) {
@@ -80,7 +80,7 @@ export class OpusGettersAndSetters {
80
80
  getSignal() {
81
81
  const result = this.#runtime.originalRuntime().opus_get_signal(this.#opusEncoderOffset, this.#value.offset());
82
82
  if (result != constants.OPUS_OK)
83
- throw new Error('Failed to set OPUS_GET_SIGNAL');
83
+ throw new Error('Failed to get OPUS_GET_SIGNAL');
84
84
  return this.#value.value();
85
85
  }
86
86
  setApplication(x) {
@@ -90,13 +90,13 @@ export class OpusGettersAndSetters {
90
90
  getApplication() {
91
91
  const result = this.#runtime.originalRuntime().opus_get_application(this.#opusEncoderOffset, this.#value.offset());
92
92
  if (result != constants.OPUS_OK)
93
- throw new Error('Failed to set OPUS_GET_APPLICATION');
93
+ throw new Error('Failed to get OPUS_GET_APPLICATION');
94
94
  return this.#value.value();
95
95
  }
96
96
  getLookahead() {
97
97
  const result = this.#runtime.originalRuntime().opus_get_lookahead(this.#opusEncoderOffset, this.#value.offset());
98
98
  if (result != constants.OPUS_OK)
99
- throw new Error('Failed to set OPUS_GET_LOOKAHEAD');
99
+ throw new Error('Failed to get OPUS_GET_LOOKAHEAD');
100
100
  return this.#value.value();
101
101
  }
102
102
  setInbandFec(x) {
@@ -106,7 +106,7 @@ export class OpusGettersAndSetters {
106
106
  getInbandFec() {
107
107
  const result = this.#runtime.originalRuntime().opus_get_inband_fec(this.#opusEncoderOffset, this.#value.offset());
108
108
  if (result != constants.OPUS_OK)
109
- throw new Error('Failed to set OPUS_GET_INBAND_FEC');
109
+ throw new Error('Failed to get OPUS_GET_INBAND_FEC');
110
110
  return this.#value.value();
111
111
  }
112
112
  setPacketLossperc(x) {
@@ -116,7 +116,7 @@ export class OpusGettersAndSetters {
116
116
  getPacketLossperc() {
117
117
  const result = this.#runtime.originalRuntime().opus_get_packet_loss_perc(this.#opusEncoderOffset, this.#value.offset());
118
118
  if (result != constants.OPUS_OK)
119
- throw new Error('Failed to set OPUS_GET_PACKET_LOSS_PERC');
119
+ throw new Error('Failed to get OPUS_GET_PACKET_LOSS_PERC');
120
120
  return this.#value.value();
121
121
  }
122
122
  setDtx(x) {
@@ -126,7 +126,7 @@ export class OpusGettersAndSetters {
126
126
  getDtx() {
127
127
  const result = this.#runtime.originalRuntime().opus_get_dtx(this.#opusEncoderOffset, this.#value.offset());
128
128
  if (result != constants.OPUS_OK)
129
- throw new Error('Failed to set OPUS_GET_DTX');
129
+ throw new Error('Failed to get OPUS_GET_DTX');
130
130
  return this.#value.value();
131
131
  }
132
132
  setLsbDepth(x) {
@@ -136,7 +136,7 @@ export class OpusGettersAndSetters {
136
136
  getLsbDepth() {
137
137
  const result = this.#runtime.originalRuntime().opus_get_lsb_depth(this.#opusEncoderOffset, this.#value.offset());
138
138
  if (result != constants.OPUS_OK)
139
- throw new Error('Failed to set OPUS_GET_LSB_DEPTH');
139
+ throw new Error('Failed to get OPUS_GET_LSB_DEPTH');
140
140
  return this.#value.value();
141
141
  }
142
142
  setExpertFrameduration(x) {
@@ -146,7 +146,7 @@ export class OpusGettersAndSetters {
146
146
  getExpertFrameduration() {
147
147
  const result = this.#runtime.originalRuntime().opus_get_expert_frame_duration(this.#opusEncoderOffset, this.#value.offset());
148
148
  if (result != constants.OPUS_OK)
149
- throw new Error('Failed to set OPUS_GET_EXPERT_FRAME_DURATION');
149
+ throw new Error('Failed to get OPUS_GET_EXPERT_FRAME_DURATION');
150
150
  return this.#value.value();
151
151
  }
152
152
  setPredictionDisabled(x) {
@@ -156,19 +156,19 @@ export class OpusGettersAndSetters {
156
156
  getPredictionDisabled() {
157
157
  const result = this.#runtime.originalRuntime().opus_get_prediction_disabled(this.#opusEncoderOffset, this.#value.offset());
158
158
  if (result != constants.OPUS_OK)
159
- throw new Error('Failed to set OPUS_GET_PREDICTION_DISABLED');
159
+ throw new Error('Failed to get OPUS_GET_PREDICTION_DISABLED');
160
160
  return this.#value.value();
161
161
  }
162
162
  getBandwidth() {
163
163
  const result = this.#runtime.originalRuntime().opus_get_bandwidth(this.#opusEncoderOffset, this.#value.offset());
164
164
  if (result != constants.OPUS_OK)
165
- throw new Error('Failed to set OPUS_GET_BANDWIDTH');
165
+ throw new Error('Failed to get OPUS_GET_BANDWIDTH');
166
166
  return this.#value.value();
167
167
  }
168
168
  getSampleRate() {
169
169
  const result = this.#runtime.originalRuntime().opus_get_sample_rate(this.#opusEncoderOffset, this.#value.offset());
170
170
  if (result != constants.OPUS_OK)
171
- throw new Error('Failed to set OPUS_GET_SAMPLE_RATE');
171
+ throw new Error('Failed to get OPUS_GET_SAMPLE_RATE');
172
172
  return this.#value.value();
173
173
  }
174
174
  setPhaseInversiondisabled(x) {
@@ -178,13 +178,13 @@ export class OpusGettersAndSetters {
178
178
  getPhaseInversiondisabled() {
179
179
  const result = this.#runtime.originalRuntime().opus_get_phase_inversion_disabled(this.#opusEncoderOffset, this.#value.offset());
180
180
  if (result != constants.OPUS_OK)
181
- throw new Error('Failed to set OPUS_GET_PHASE_INVERSION_DISABLED');
181
+ throw new Error('Failed to get OPUS_GET_PHASE_INVERSION_DISABLED');
182
182
  return this.#value.value();
183
183
  }
184
184
  getInDtx() {
185
185
  const result = this.#runtime.originalRuntime().opus_get_in_dtx(this.#opusEncoderOffset, this.#value.offset());
186
186
  if (result != constants.OPUS_OK)
187
- throw new Error('Failed to set OPUS_GET_IN_DTX');
187
+ throw new Error('Failed to get OPUS_GET_IN_DTX');
188
188
  return this.#value.value();
189
189
  }
190
190
  setGain(x) {
@@ -194,19 +194,19 @@ export class OpusGettersAndSetters {
194
194
  getGain() {
195
195
  const result = this.#runtime.originalRuntime().opus_get_gain(this.#opusEncoderOffset, this.#value.offset());
196
196
  if (result != constants.OPUS_OK)
197
- throw new Error('Failed to set OPUS_GET_GAIN');
197
+ throw new Error('Failed to get OPUS_GET_GAIN');
198
198
  return this.#value.value();
199
199
  }
200
200
  getLastPacketduration() {
201
201
  const result = this.#runtime.originalRuntime().opus_get_last_packet_duration(this.#opusEncoderOffset, this.#value.offset());
202
202
  if (result != constants.OPUS_OK)
203
- throw new Error('Failed to set OPUS_GET_LAST_PACKET_DURATION');
203
+ throw new Error('Failed to get OPUS_GET_LAST_PACKET_DURATION');
204
204
  return this.#value.value();
205
205
  }
206
206
  getPitch() {
207
207
  const result = this.#runtime.originalRuntime().opus_get_pitch(this.#opusEncoderOffset, this.#value.offset());
208
208
  if (result != constants.OPUS_OK)
209
- throw new Error('Failed to set OPUS_GET_PITCH');
209
+ throw new Error('Failed to get OPUS_GET_PITCH');
210
210
  return this.#value.value();
211
211
  }
212
212
  destroy() {
package/package.json CHANGED
@@ -1,9 +1,14 @@
1
1
  {
2
2
  "devDependencies": {
3
+ "@babel/core": "^7.28.6",
4
+ "@babel/preset-env": "^7.28.6",
3
5
  "@high-nodejs/child_process": "^0.3.4",
4
6
  "@textstream/core": "^0.3.1",
5
7
  "@types/audioworklet": "^0.0.92",
6
8
  "@types/node": "^24.10.8",
9
+ "@vitest/browser-playwright": "^4.0.17",
10
+ "@vitest/coverage-v8": "^4.0.17",
11
+ "babel-loader": "^10.0.0",
7
12
  "c8": "^10.1.3",
8
13
  "cli-argument-helper": "^2.3.0",
9
14
  "eslint": "^8.57.1",
@@ -12,30 +17,27 @@
12
17
  "ringbud": "^1.0.23",
13
18
  "tsx": "^4.21.0",
14
19
  "typescript": "^5.9.3",
20
+ "vitest": "^4.0.17",
15
21
  "webpack": "^5.104.1",
16
- "webpack-cli": "^5.1.4"
22
+ "webpack-cli": "^5.1.4",
23
+ "webpack-merge": "^6.0.1"
17
24
  },
18
25
  "type": "module",
19
26
  "name": "opus-codec",
20
- "version": "1.0.3",
27
+ "version": "1.0.9",
21
28
  "license": "MIT",
22
29
  "files": [
23
30
  "{native,runtime,opus,es}/**/*.{d.ts,js,map,wasm}"
24
31
  ],
25
32
  "scripts": {
26
- "build": "npx tsc -b test --force",
27
- "build:es:opus": "npx tsc --project opus --module NodeNext --outDir es",
28
- "build:es:actions": "npx tsc --project actions --module NodeNext --outDir es",
29
- "build:es:runtime": "npx tsc --project runtime --module NodeNext --outDir es",
30
- "build:all": "npm run build && npm run build:es:opus && npm run build:es:runtime && npm run build:es:actions",
31
- "prepublishOnly": "npm run build:all && npm run set-es-paths",
32
- "set-es-paths": "npx package-utilities --set-es-paths --es-folder es --include \"{opus,runtime,actions}/**/*.js\"",
33
- "test": "npx tsx --test test",
34
- "test:coverage": "npx c8 --reporter=text --reporter=html npm run test"
33
+ "build": "npx tsc -b scripts test --force",
34
+ "prepublishOnly": "npm run build && npx tsx scripts --generate --compile && npm run test",
35
+ "test": "npx vitest test/worker.test.ts",
36
+ "test:coverage": "npx vitest --coverage test/worker.test.ts"
35
37
  },
36
38
  "repository": {
37
39
  "type": "git",
38
- "url": "git+https://github.com/VictorQueiroz/js-opus-codec"
40
+ "url": "git+https://github.com/VictorQueiroz/js-opus-codec.git"
39
41
  },
40
42
  "browser": {
41
43
  "./opus/index.js": "./es/opus/index.js",
@@ -1,3 +0,0 @@
1
- import type { RingBufferF32 } from 'ringbud';
2
- export default RingBufferF32;
3
- //# sourceMappingURL=RingBuffer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"RingBuffer.d.ts","sourceRoot":"","sources":["../../opus/RingBuffer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,eAAe,aAAa,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=RingBuffer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"RingBuffer.js","sourceRoot":"","sources":["../../opus/RingBuffer.ts"],"names":[],"mappings":""}