@4players/odin-plugin-web 1.0.0-alpha.21 → 1.0.0-alpha.22

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.
Files changed (68) hide show
  1. package/lib/common/msgpack.d.ts +2 -0
  2. package/lib/common/msgpack.js +117 -0
  3. package/lib/plugin/config.d.ts +12 -0
  4. package/lib/plugin/config.js +22 -0
  5. package/lib/plugin/connectionPool.d.ts +17 -0
  6. package/lib/plugin/connectionPool.js +130 -0
  7. package/lib/plugin/deviceManager.d.ts +12 -0
  8. package/lib/plugin/deviceManager.js +120 -0
  9. package/lib/plugin/h3/mainConnection.d.ts +30 -0
  10. package/lib/plugin/h3/mainConnection.js +196 -0
  11. package/lib/plugin/index.d.ts +61 -18
  12. package/lib/plugin/index.js +405 -1
  13. package/lib/plugin/mainConnection.d.ts +30 -0
  14. package/lib/plugin/mainConnection.js +23 -0
  15. package/lib/plugin/mediaController.d.ts +66 -0
  16. package/lib/plugin/mediaController.js +215 -0
  17. package/lib/plugin/medias/audio-capture.d.ts +30 -0
  18. package/lib/plugin/medias/audio-capture.js +224 -0
  19. package/lib/plugin/medias/audio-playback.d.ts +13 -0
  20. package/lib/plugin/medias/audio-playback.js +40 -0
  21. package/lib/plugin/medias/video-capture.d.ts +15 -0
  22. package/lib/plugin/medias/video-capture.js +69 -0
  23. package/lib/plugin/medias/video-playback.d.ts +13 -0
  24. package/lib/plugin/medias/video-playback.js +20 -0
  25. package/lib/plugin/roomConnection.d.ts +40 -0
  26. package/lib/plugin/roomConnection.js +320 -0
  27. package/lib/plugin/rpcConnection.d.ts +57 -0
  28. package/lib/plugin/rpcConnection.js +281 -0
  29. package/lib/plugin/token.d.ts +13 -0
  30. package/lib/plugin/token.js +66 -0
  31. package/lib/plugin/webrtc/mainConnection.d.ts +52 -0
  32. package/lib/plugin/webrtc/mainConnection.js +455 -0
  33. package/lib/plugin/webrtc/websocket.d.ts +3 -0
  34. package/lib/plugin/webrtc/websocket.js +56 -0
  35. package/lib/wasm/index.d.ts +97 -0
  36. package/lib/worker/buffers.d.ts +42 -0
  37. package/lib/worker/buffers.js +79 -0
  38. package/lib/worker/common.d.ts +45 -0
  39. package/lib/worker/common.js +7 -0
  40. package/lib/worker/config.d.ts +8 -0
  41. package/lib/worker/config.js +11 -0
  42. package/lib/worker/index.d.ts +3 -0
  43. package/lib/worker/index.js +1 -0
  44. package/lib/worker/memory.d.ts +9 -0
  45. package/lib/worker/memory.js +29 -0
  46. package/lib/worker/messages.d.ts +14 -0
  47. package/lib/worker/messages.js +15 -0
  48. package/lib/worker/packet.d.ts +11 -0
  49. package/lib/worker/packet.js +59 -0
  50. package/lib/worker/shared/capture.d.ts +27 -0
  51. package/lib/worker/shared/capture.js +63 -0
  52. package/lib/worker/shared/index.d.ts +3 -0
  53. package/lib/worker/shared/index.js +147 -0
  54. package/lib/worker/shared/messages.d.ts +67 -0
  55. package/lib/worker/shared/messages.js +64 -0
  56. package/lib/worker/shared/playback.d.ts +20 -0
  57. package/lib/worker/shared/playback.js +78 -0
  58. package/lib/worker/unshared/capture.d.ts +27 -0
  59. package/lib/worker/unshared/capture.js +66 -0
  60. package/lib/worker/unshared/index.d.ts +3 -0
  61. package/lib/worker/unshared/index.js +170 -0
  62. package/lib/worker/unshared/messages.d.ts +81 -0
  63. package/lib/worker/unshared/messages.js +80 -0
  64. package/lib/worker/unshared/playback.d.ts +22 -0
  65. package/lib/worker/unshared/playback.js +83 -0
  66. package/package.json +9 -12
  67. package/lib/worker/shared.js +0 -1
  68. package/lib/worker/unshared.js +0 -1
@@ -0,0 +1,79 @@
1
+ import { free, malloc } from './memory';
2
+ export function createSampleBuffer(wasm, sampleRate, length, stereo) {
3
+ return {
4
+ headers: malloc(wasm, 'i32', length),
5
+ samples: malloc(wasm, 'f32', length * samplesPerEntry({ sampleRate, stereo })),
6
+ length,
7
+ sampleRate,
8
+ stereo,
9
+ };
10
+ }
11
+ export function freeSampleBuffer(wasm, buffer) {
12
+ free(wasm, buffer.headers);
13
+ free(wasm, buffer.samples);
14
+ }
15
+ export function samplesPerEntry(buffer) {
16
+ return buffer.sampleRate * 0.02 * (buffer.stereo ? 2 : 1);
17
+ }
18
+ export function getSamples(buffer, index) {
19
+ const size = samplesPerEntry(buffer);
20
+ const begin = size * index;
21
+ const end = begin + size;
22
+ return buffer.samples.subarray(begin, end);
23
+ }
24
+ export function getHeader(buffer, index) {
25
+ return { id: buffer.headers[index] };
26
+ }
27
+ export function setHeader(buffer, index, header) {
28
+ buffer.headers[index] = header.id;
29
+ }
30
+ export function createDecoderInformationBuffer(wasm, length) {
31
+ return {
32
+ values: malloc(wasm, 'f32', 1 + length * 2),
33
+ length,
34
+ };
35
+ }
36
+ export function freeDecoderInformationBuffer(wasm, buffer) {
37
+ free(wasm, buffer.values);
38
+ }
39
+ export function getGlobalDecoderVolume(buffer) {
40
+ return buffer.values[0];
41
+ }
42
+ export function setGlobalDecoderVolume(buffer, value) {
43
+ buffer.values[0] = value;
44
+ }
45
+ export function getDecoderRmsDBFS(buffer, index) {
46
+ return buffer.values[1 + index * 2];
47
+ }
48
+ export function setDecoderRmsDBFS(buffer, index, value) {
49
+ buffer.values[1 + index * 2] = value;
50
+ }
51
+ export function getDecoderVolume(buffer, index) {
52
+ return buffer.values[1 + index * 2 + 1];
53
+ }
54
+ export function setDecoderVolume(buffer, index, value) {
55
+ buffer.values[1 + index * 2 + 1] = value;
56
+ }
57
+ export function createEncoderInformationBuffer(wasm) {
58
+ return {
59
+ values: malloc(wasm, 'f32', 4),
60
+ };
61
+ }
62
+ export function freeEncoderInformationBuffer(wasm, buffer) {
63
+ free(wasm, buffer.values);
64
+ }
65
+ export function getEncoderActive(buffer) {
66
+ return buffer.values[0] !== 0;
67
+ }
68
+ export function getEncoderSpeechProbability(buffer) {
69
+ return buffer.values[1];
70
+ }
71
+ export function getEncoderRmsDBFS(buffer) {
72
+ return buffer.values[2];
73
+ }
74
+ export function getEncoderVolume(buffer) {
75
+ return buffer.values[3];
76
+ }
77
+ export function setEncoderVolume(buffer, value) {
78
+ return (buffer.values[3] = value);
79
+ }
@@ -0,0 +1,45 @@
1
+ export interface Activity {
2
+ isSilent: boolean;
3
+ rmsDBFS: number;
4
+ }
5
+ export declare const Silence: Activity;
6
+ export interface VadConfig {
7
+ volumeGate?: {
8
+ attackThreshold: number;
9
+ releaseThreshold: number;
10
+ };
11
+ voiceActivity?: {
12
+ attackThreshold: number;
13
+ releaseThreshold: number;
14
+ };
15
+ }
16
+ export type CaptureSink = (connectionId: number, packet: Uint8Array) => void;
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 interface PlaybackWorker {
32
+ readonly audioContext: AudioContext;
33
+ receivePacket(connectionId: number, packet: Uint8Array): void;
34
+ addMedias(connectionId: number, mediaIds: number[]): void;
35
+ removeMedias(connectionId: number, mediaIds: number[]): void;
36
+ getActivity(id: PlaybackId): Activity | undefined;
37
+ setGlobalVolume(value: number): void;
38
+ setVolume(id: PlaybackId, value: number): void;
39
+ close(): void;
40
+ }
41
+ export interface PlaybackId {
42
+ connectionId: number;
43
+ mediaId: number;
44
+ }
45
+ export declare function mergeIds(id: PlaybackId): number;
@@ -0,0 +1,7 @@
1
+ import { MinDBFs } from './config';
2
+ export const Silence = { isSilent: true, rmsDBFS: MinDBFs };
3
+ export function mergeIds(id) {
4
+ // connectionId is 21 Bits.
5
+ // mediaId is 32 Bits
6
+ return id.connectionId * 4294967296 + id.mediaId;
7
+ }
@@ -0,0 +1,8 @@
1
+ export declare const AdditionalPlaybackBlocks = 3;
2
+ export declare const AdditionalCaptureBlocks = 3;
3
+ export declare const PlaybackPreload = 3;
4
+ export declare const DefaultRefreshRate = 250;
5
+ export declare const VadPreload = 3;
6
+ export declare const MaxNumberOfDecoders = 512;
7
+ export declare const RenderQuantumSize = 128;
8
+ export declare const MinDBFs = -758.596;
@@ -0,0 +1,11 @@
1
+ // shared
2
+ export const AdditionalPlaybackBlocks = 3;
3
+ export const AdditionalCaptureBlocks = 3;
4
+ // unshared
5
+ export const PlaybackPreload = 3;
6
+ export const DefaultRefreshRate = 250;
7
+ // both
8
+ export const VadPreload = 3;
9
+ export const MaxNumberOfDecoders = 512;
10
+ export const RenderQuantumSize = 128;
11
+ export const MinDBFs = -758.596;
@@ -0,0 +1,3 @@
1
+ import { CaptureSink, CaptureWorker, PlaybackWorker } from './common';
2
+ export declare function createCaptureWorker(context: AudioContext, sink: CaptureSink, refreshRate?: number): Promise<CaptureWorker>;
3
+ export declare function createPlaybackWorker(audioContext: AudioContext, refreshRate?: number): Promise<PlaybackWorker>;