@4players/odin-plugin-web 1.0.0-alpha.8 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/cmake/dependencies.cmake +31 -0
- package/cmake/options.cmake +53 -0
- package/esbuild.config.ts +49 -0
- package/lib/plugin/index.d.ts +42 -50
- package/lib/plugin/index.js +1 -293
- package/lib/worker/shared.js +1 -0
- package/lib/worker/unshared.js +1 -0
- package/package.json +38 -29
- package/lib/plugin/audioController.d.ts +0 -102
- package/lib/plugin/audioController.js +0 -442
- package/lib/plugin/config.d.ts +0 -11
- package/lib/plugin/config.js +0 -11
- package/lib/plugin/connectionPool.d.ts +0 -17
- package/lib/plugin/connectionPool.js +0 -111
- package/lib/plugin/mainConnection.d.ts +0 -40
- package/lib/plugin/mainConnection.js +0 -294
- package/lib/plugin/roomConnection.d.ts +0 -37
- package/lib/plugin/roomConnection.js +0 -299
- package/lib/plugin/rpcConnection.d.ts +0 -49
- package/lib/plugin/rpcConnection.js +0 -235
- package/lib/plugin/token.d.ts +0 -16
- package/lib/plugin/token.js +0 -67
- package/lib/wasm/index.d.ts +0 -97
- package/lib/wasm/index.js +0 -19
- package/lib/worker/common.d.ts +0 -28
- package/lib/worker/common.js +0 -100
- package/lib/worker/index.d.ts +0 -47
- package/lib/worker/index.js +0 -2
- package/lib/worker/messages.d.ts +0 -94
- package/lib/worker/messages.js +0 -16
package/lib/worker/common.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { Result } from '@4players/odin-common';
|
|
2
|
-
import type { OdinWasm } from '../../lib/wasm';
|
|
3
|
-
import type { PlaybackId } from './index';
|
|
4
|
-
export declare const PlaybackPreload = 3;
|
|
5
|
-
export declare const DefaultRefreshRate = 250;
|
|
6
|
-
export declare const VadPreload = 3;
|
|
7
|
-
export declare const MaxNumberOfDecoders = 512;
|
|
8
|
-
export declare const MinDBFs = -758.596;
|
|
9
|
-
export declare function malloc(wasm: typeof OdinWasm, element: 'f32', length: number): Float32Array;
|
|
10
|
-
export declare function malloc(wasm: typeof OdinWasm, element: 'u32', length: number): Uint32Array;
|
|
11
|
-
export declare function malloc(wasm: typeof OdinWasm, element: 'i32', length: number): Int32Array;
|
|
12
|
-
export declare function malloc(wasm: typeof OdinWasm, element: 'u8', length: number): Uint8Array;
|
|
13
|
-
export declare function free(wasm: typeof OdinWasm, array: Float32Array): void;
|
|
14
|
-
export declare function free(wasm: typeof OdinWasm, array: Uint32Array): void;
|
|
15
|
-
export declare function free(wasm: typeof OdinWasm, array: Int32Array): void;
|
|
16
|
-
export declare function free(wasm: typeof OdinWasm, array: Uint8Array): void;
|
|
17
|
-
export declare function mergeIds(id: PlaybackId): number;
|
|
18
|
-
export declare class Packet {
|
|
19
|
-
readonly mediaIds: number[];
|
|
20
|
-
readonly sequenceNumber: number;
|
|
21
|
-
readonly timeStamp: number;
|
|
22
|
-
readonly isEndOfSpurt: boolean;
|
|
23
|
-
readonly payload: Uint8Array;
|
|
24
|
-
static parse(bytes: Uint8Array): Result<Packet>;
|
|
25
|
-
constructor(mediaIds: number[], sequenceNumber: number, timeStamp: number, isEndOfSpurt: boolean, payload: Uint8Array);
|
|
26
|
-
toBytes(): Uint8Array;
|
|
27
|
-
}
|
|
28
|
-
//# sourceMappingURL=common.d.ts.map
|
package/lib/worker/common.js
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-redeclare */
|
|
2
|
-
import { failure, success } from '@4players/odin-common';
|
|
3
|
-
import * as msgpack from '@msgpack/msgpack';
|
|
4
|
-
export const PlaybackPreload = 3;
|
|
5
|
-
export const DefaultRefreshRate = 250;
|
|
6
|
-
export const VadPreload = 3;
|
|
7
|
-
export const MaxNumberOfDecoders = 512;
|
|
8
|
-
export const MinDBFs = -758.596;
|
|
9
|
-
export function malloc(wasm, element, length) {
|
|
10
|
-
let heap;
|
|
11
|
-
switch (element) {
|
|
12
|
-
case 'f32':
|
|
13
|
-
heap = wasm.HEAPF32;
|
|
14
|
-
break;
|
|
15
|
-
case 'u32':
|
|
16
|
-
heap = wasm.HEAPU32;
|
|
17
|
-
break;
|
|
18
|
-
case 'i32':
|
|
19
|
-
heap = wasm.HEAP32;
|
|
20
|
-
break;
|
|
21
|
-
case 'u8':
|
|
22
|
-
heap = wasm.HEAPU8;
|
|
23
|
-
break;
|
|
24
|
-
default:
|
|
25
|
-
throw new Error(`allocating ${element} is not supported`);
|
|
26
|
-
}
|
|
27
|
-
const pointer = wasm._malloc(length * heap.BYTES_PER_ELEMENT);
|
|
28
|
-
if (pointer === 0 || pointer % heap.BYTES_PER_ELEMENT !== 0) {
|
|
29
|
-
throw new Error(`failed allocating a ${length} ${element} array`);
|
|
30
|
-
}
|
|
31
|
-
const start = pointer / heap.BYTES_PER_ELEMENT;
|
|
32
|
-
return heap.subarray(start, start + length);
|
|
33
|
-
}
|
|
34
|
-
export function free(wasm, array) {
|
|
35
|
-
wasm._free(array.byteOffset);
|
|
36
|
-
}
|
|
37
|
-
export function mergeIds(id) {
|
|
38
|
-
// connectionId is 21 Bits.
|
|
39
|
-
// mediaId is 32 Bits
|
|
40
|
-
return id.connectionId * 4294967296 + id.mediaId;
|
|
41
|
-
}
|
|
42
|
-
export class Packet {
|
|
43
|
-
static parse(bytes) {
|
|
44
|
-
let parsed;
|
|
45
|
-
try {
|
|
46
|
-
parsed = msgpack.decode(bytes);
|
|
47
|
-
}
|
|
48
|
-
catch (error) {
|
|
49
|
-
return failure('not valid msgpack');
|
|
50
|
-
}
|
|
51
|
-
if (!Array.isArray(parsed))
|
|
52
|
-
return failure('container must be an array');
|
|
53
|
-
if (parsed.length < 6)
|
|
54
|
-
return failure('missing fields');
|
|
55
|
-
if (parsed[0] !== 1)
|
|
56
|
-
return failure('unknown type');
|
|
57
|
-
if (!Array.isArray(parsed[1]))
|
|
58
|
-
return failure('media ids must be an array');
|
|
59
|
-
if (!parsed[1].every((entry) => typeof entry === 'number')) {
|
|
60
|
-
return failure('media ids must be numbers');
|
|
61
|
-
}
|
|
62
|
-
if (typeof parsed[2] !== 'number') {
|
|
63
|
-
return failure('sequence number must be a number');
|
|
64
|
-
}
|
|
65
|
-
if (typeof parsed[3] !== 'number') {
|
|
66
|
-
return failure('timestamp must be a number');
|
|
67
|
-
}
|
|
68
|
-
if (typeof parsed[4] !== 'number')
|
|
69
|
-
return failure('flags must be a number');
|
|
70
|
-
const mediaIds = parsed[1];
|
|
71
|
-
const sequenceNumber = parsed[2] >>> 0;
|
|
72
|
-
const timeStamp = parsed[3] >>> 0;
|
|
73
|
-
const flags = parsed[4];
|
|
74
|
-
const isEndOfSpurt = (flags & 0x01) !== 0;
|
|
75
|
-
const payload = parsed[parsed.length - 1];
|
|
76
|
-
if (!(payload instanceof Uint8Array)) {
|
|
77
|
-
return failure('payload must be bytes');
|
|
78
|
-
}
|
|
79
|
-
return success(new Packet(mediaIds, sequenceNumber, timeStamp, isEndOfSpurt, payload));
|
|
80
|
-
}
|
|
81
|
-
constructor(mediaIds, sequenceNumber, timeStamp, isEndOfSpurt, payload) {
|
|
82
|
-
this.mediaIds = mediaIds;
|
|
83
|
-
this.sequenceNumber = sequenceNumber;
|
|
84
|
-
this.timeStamp = timeStamp;
|
|
85
|
-
this.isEndOfSpurt = isEndOfSpurt;
|
|
86
|
-
this.payload = payload;
|
|
87
|
-
}
|
|
88
|
-
toBytes() {
|
|
89
|
-
const flags = Number(this.isEndOfSpurt);
|
|
90
|
-
return msgpack.encode([
|
|
91
|
-
1,
|
|
92
|
-
this.mediaIds,
|
|
93
|
-
this.sequenceNumber >>> 0,
|
|
94
|
-
this.timeStamp >>> 0,
|
|
95
|
-
flags,
|
|
96
|
-
this.payload,
|
|
97
|
-
]);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
//# sourceMappingURL=common.js.map
|
package/lib/worker/index.d.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
export type CaptureSink = (connectionId: number, packet: Uint8Array) => void;
|
|
2
|
-
export interface Activity {
|
|
3
|
-
isSilent: boolean;
|
|
4
|
-
rmsDBFS: number;
|
|
5
|
-
}
|
|
6
|
-
export declare const silence: Activity;
|
|
7
|
-
export interface VadConfig {
|
|
8
|
-
volumeGate?: {
|
|
9
|
-
attackThreshold: number;
|
|
10
|
-
releaseThreshold: number;
|
|
11
|
-
};
|
|
12
|
-
voiceActivity?: {
|
|
13
|
-
attackThreshold: number;
|
|
14
|
-
releaseThreshold: number;
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
export interface CaptureWorker {
|
|
18
|
-
readonly worklet: AudioWorkletNode;
|
|
19
|
-
readonly worker: Worker;
|
|
20
|
-
get context(): BaseAudioContext;
|
|
21
|
-
get activity(): Activity;
|
|
22
|
-
get speechProbability(): number;
|
|
23
|
-
setMedias(connections: Array<{
|
|
24
|
-
id: number;
|
|
25
|
-
mediaIds: number[];
|
|
26
|
-
}>): void;
|
|
27
|
-
setVolume(value: number): void;
|
|
28
|
-
setVad(config: VadConfig): void;
|
|
29
|
-
close(): void;
|
|
30
|
-
}
|
|
31
|
-
export declare function createCaptureWorker(context: AudioContext, sink: CaptureSink, refreshRate?: number): Promise<CaptureWorker>;
|
|
32
|
-
export interface PlaybackId {
|
|
33
|
-
connectionId: number;
|
|
34
|
-
mediaId: number;
|
|
35
|
-
}
|
|
36
|
-
export interface PlaybackWorker {
|
|
37
|
-
readonly audioContext: AudioContext;
|
|
38
|
-
receivePacket(connectionId: number, packet: Uint8Array): void;
|
|
39
|
-
addMedias(connectionId: number, mediaIds: number[]): void;
|
|
40
|
-
removeMedias(connectionId: number, mediaIds: number[]): void;
|
|
41
|
-
getActivity(id: PlaybackId): Activity | undefined;
|
|
42
|
-
setGlobalVolume(value: number): void;
|
|
43
|
-
setVolume(id: PlaybackId, value: number): void;
|
|
44
|
-
close(): void;
|
|
45
|
-
}
|
|
46
|
-
export declare function createPlaybackWorker(audioContext: AudioContext, refreshRate?: number): Promise<PlaybackWorker>;
|
|
47
|
-
//# sourceMappingURL=index.d.ts.map
|