@4players/odin-plugin-web 1.0.0-alpha.23 → 1.0.0-alpha.25

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 (70) hide show
  1. package/lib/plugin/index.d.ts +127 -61
  2. package/lib/plugin/index.js +2 -405
  3. package/lib/worker/shared.js +1 -0
  4. package/lib/worker/unshared.js +1 -0
  5. package/package.json +22 -21
  6. package/lib/common/msgpack.d.ts +0 -2
  7. package/lib/common/msgpack.js +0 -117
  8. package/lib/plugin/config.d.ts +0 -12
  9. package/lib/plugin/config.js +0 -22
  10. package/lib/plugin/connectionPool.d.ts +0 -17
  11. package/lib/plugin/connectionPool.js +0 -130
  12. package/lib/plugin/deviceManager.d.ts +0 -12
  13. package/lib/plugin/deviceManager.js +0 -120
  14. package/lib/plugin/h3/mainConnection.d.ts +0 -30
  15. package/lib/plugin/h3/mainConnection.js +0 -196
  16. package/lib/plugin/mainConnection.d.ts +0 -30
  17. package/lib/plugin/mainConnection.js +0 -23
  18. package/lib/plugin/mediaController.d.ts +0 -66
  19. package/lib/plugin/mediaController.js +0 -215
  20. package/lib/plugin/medias/audio-capture.d.ts +0 -30
  21. package/lib/plugin/medias/audio-capture.js +0 -224
  22. package/lib/plugin/medias/audio-playback.d.ts +0 -13
  23. package/lib/plugin/medias/audio-playback.js +0 -40
  24. package/lib/plugin/medias/video-capture.d.ts +0 -15
  25. package/lib/plugin/medias/video-capture.js +0 -69
  26. package/lib/plugin/medias/video-playback.d.ts +0 -13
  27. package/lib/plugin/medias/video-playback.js +0 -20
  28. package/lib/plugin/roomConnection.d.ts +0 -40
  29. package/lib/plugin/roomConnection.js +0 -320
  30. package/lib/plugin/rpcConnection.d.ts +0 -57
  31. package/lib/plugin/rpcConnection.js +0 -281
  32. package/lib/plugin/token.d.ts +0 -13
  33. package/lib/plugin/token.js +0 -66
  34. package/lib/plugin/webrtc/mainConnection.d.ts +0 -52
  35. package/lib/plugin/webrtc/mainConnection.js +0 -455
  36. package/lib/plugin/webrtc/websocket.d.ts +0 -3
  37. package/lib/plugin/webrtc/websocket.js +0 -56
  38. package/lib/version.d.ts +0 -1
  39. package/lib/version.js +0 -2
  40. package/lib/wasm/index.d.ts +0 -97
  41. package/lib/worker/buffers.d.ts +0 -42
  42. package/lib/worker/buffers.js +0 -79
  43. package/lib/worker/common.d.ts +0 -45
  44. package/lib/worker/common.js +0 -7
  45. package/lib/worker/config.d.ts +0 -8
  46. package/lib/worker/config.js +0 -11
  47. package/lib/worker/index.d.ts +0 -3
  48. package/lib/worker/index.js +0 -1
  49. package/lib/worker/memory.d.ts +0 -9
  50. package/lib/worker/memory.js +0 -29
  51. package/lib/worker/messages.d.ts +0 -14
  52. package/lib/worker/messages.js +0 -15
  53. package/lib/worker/packet.d.ts +0 -11
  54. package/lib/worker/packet.js +0 -59
  55. package/lib/worker/shared/capture.d.ts +0 -27
  56. package/lib/worker/shared/capture.js +0 -63
  57. package/lib/worker/shared/index.d.ts +0 -3
  58. package/lib/worker/shared/index.js +0 -147
  59. package/lib/worker/shared/messages.d.ts +0 -67
  60. package/lib/worker/shared/messages.js +0 -64
  61. package/lib/worker/shared/playback.d.ts +0 -20
  62. package/lib/worker/shared/playback.js +0 -78
  63. package/lib/worker/unshared/capture.d.ts +0 -27
  64. package/lib/worker/unshared/capture.js +0 -66
  65. package/lib/worker/unshared/index.d.ts +0 -3
  66. package/lib/worker/unshared/index.js +0 -170
  67. package/lib/worker/unshared/messages.d.ts +0 -81
  68. package/lib/worker/unshared/messages.js +0 -80
  69. package/lib/worker/unshared/playback.d.ts +0 -22
  70. package/lib/worker/unshared/playback.js +0 -83
@@ -1,224 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { Silence } from '../../worker/common';
11
- import { logger } from '../index';
12
- import { createCaptureWorker } from '../../worker';
13
- import { openCaptureDevice, stopMediaStream, enumerateDevices, } from '../deviceManager';
14
- const defaultVad = {
15
- voiceActivity: {
16
- attackThreshold: 0.9,
17
- releaseThreshold: 0.8,
18
- },
19
- volumeGate: {
20
- attackThreshold: -30,
21
- releaseThreshold: -40,
22
- },
23
- };
24
- const defaultApm = {
25
- echoCanceller: false,
26
- highPassFilter: false,
27
- preAmplifier: false,
28
- captureLevelAdjustment: false,
29
- noiseSuppression: 'None',
30
- transientSuppressor: false,
31
- gainController: false,
32
- };
33
- export class AudioCapture {
34
- get vad() {
35
- return this._Vad;
36
- }
37
- get apm() {
38
- return this._Apm;
39
- }
40
- get volume() {
41
- return this._Volume;
42
- }
43
- get activity() {
44
- var _a, _b;
45
- return (_b = (_a = this._Capture) === null || _a === void 0 ? void 0 : _a.worker.activity) !== null && _b !== void 0 ? _b : Silence;
46
- }
47
- get speechProbability() {
48
- var _a, _b;
49
- return (_b = (_a = this._Capture) === null || _a === void 0 ? void 0 : _a.worker.speechProbability) !== null && _b !== void 0 ? _b : 0;
50
- }
51
- get deviceId() {
52
- var _a, _b;
53
- return (_b = (_a = this._DeviceParameters) === null || _a === void 0 ? void 0 : _a.device) === null || _b === void 0 ? void 0 : _b.device.deviceId;
54
- }
55
- constructor(controller, parameters) {
56
- this.controller = controller;
57
- this._Medias = new Map();
58
- this._Vad = defaultVad;
59
- this._Apm = defaultApm;
60
- this._Volume = 1;
61
- this._ProcessingSetDevice = false;
62
- this._DeviceCb = () => __awaiter(this, void 0, void 0, function* () {
63
- var _a, _b;
64
- logger.debug(['Audio'], 'AudioCapture._DeviceCb()');
65
- const devices = yield enumerateDevices();
66
- const isListed = devices.some((device) => {
67
- var _a, _b;
68
- return (device.device.deviceId ===
69
- ((_b = (_a = this._DeviceParameters) === null || _a === void 0 ? void 0 : _a.device) === null || _b === void 0 ? void 0 : _b.device.deviceId));
70
- });
71
- if (!isListed) {
72
- (_b = (_a = this._DeviceParameters) === null || _a === void 0 ? void 0 : _a.onStatusChanged) === null || _b === void 0 ? void 0 : _b.call(_a, 'stopped');
73
- navigator.mediaDevices.removeEventListener('devicechange', this._DeviceCb);
74
- }
75
- });
76
- if (parameters.apm) {
77
- this.setApm(parameters.apm);
78
- }
79
- if (parameters.vad) {
80
- this.setVad(parameters.vad);
81
- }
82
- if (parameters.volume) {
83
- this.setVolume(parameters.volume);
84
- }
85
- }
86
- start(room, media, uid) {
87
- var _a;
88
- logger.debug(['Audio'], 'AudioCapture.start()', media);
89
- let entry = this._Medias.get(media.connectionId);
90
- if (entry === undefined) {
91
- this._Medias.set(media.connectionId, (entry = new Set()));
92
- }
93
- if (entry.has(media.mediaId))
94
- return;
95
- entry.add(media.mediaId);
96
- if (((_a = room.mainConnection) === null || _a === void 0 ? void 0 : _a.id) === media.connectionId) {
97
- room
98
- .typedRequest('StartMedia', {
99
- media_id: media.mediaId,
100
- properties: { kind: 'audio', uid },
101
- })
102
- .catch((reason) => console.error(`StartMedia got rejected; ${reason}`));
103
- }
104
- this._UpdateMedias();
105
- }
106
- stop(room, media) {
107
- var _a;
108
- logger.debug(['Audio'], 'AudioCapture.stop()', media);
109
- const entry = this._Medias.get(media.connectionId);
110
- if (!(entry === null || entry === void 0 ? void 0 : entry.delete(media.mediaId)))
111
- return;
112
- if (((_a = room.mainConnection) === null || _a === void 0 ? void 0 : _a.id) === media.connectionId) {
113
- room
114
- .typedRequest('StopMedia', { media_id: media.mediaId })
115
- .catch((reason) => console.error(`StopMedia got rejected; ${reason}`));
116
- }
117
- this._UpdateMedias();
118
- }
119
- setVad(value) {
120
- logger.debug(['Audio'], 'AudioCapture.setVad() config', value);
121
- this._Vad = value;
122
- if (this._Capture) {
123
- this._Capture.worker.setVad(value);
124
- }
125
- }
126
- setApm(config) {
127
- return __awaiter(this, void 0, void 0, function* () {
128
- logger.debug(['Audio'], 'AudioCapture.setApm() config', config);
129
- this._Apm = config;
130
- if (this._DeviceParameters) {
131
- yield this.setDevice(this._DeviceParameters);
132
- }
133
- });
134
- }
135
- setDevice(parameters) {
136
- return __awaiter(this, void 0, void 0, function* () {
137
- var _a;
138
- logger.debug(['Device'], 'AudioCapture.setDevice() parameters: ', parameters);
139
- const rollbackParams = this._DeviceParameters;
140
- this._DeviceParameters = parameters;
141
- if (this._Volume === 'muted') {
142
- return;
143
- }
144
- const device = yield openCaptureDevice(this.controller, parameters, this._Apm);
145
- if (device.type !== 'Success') {
146
- logger.error([
147
- 'Device',
148
- `AudioCapture.setDevice() Unable to open capture device; ${device.reason}`,
149
- ]);
150
- this._DeviceParameters = rollbackParams;
151
- return;
152
- }
153
- if (this._DeviceParameters.onStatusChanged) {
154
- navigator.mediaDevices.addEventListener('devicechange', this._DeviceCb);
155
- }
156
- if (this._Capture !== undefined) {
157
- stopMediaStream(this._Capture.source.mediaStream);
158
- this._Capture.source.disconnect(this._Capture.worker.worklet);
159
- }
160
- if (this._Capture === undefined ||
161
- this._Capture.worker.worklet.context !== device.value.context) {
162
- (_a = this._Capture) === null || _a === void 0 ? void 0 : _a.worker.close();
163
- this._Capture = {
164
- worker: yield createCaptureWorker(device.value.context, this.controller.sink),
165
- source: device.value,
166
- };
167
- yield this._UpdateMedias();
168
- yield this.setVolume(this._Volume);
169
- this.setVad(this.vad);
170
- }
171
- else {
172
- this._Capture.source = device.value;
173
- }
174
- this._Capture.source.connect(this._Capture.worker.worklet);
175
- });
176
- }
177
- setVolume(value) {
178
- return __awaiter(this, void 0, void 0, function* () {
179
- var _a;
180
- logger.debug(['Audio'], 'AudioCapture.setVolume()', value);
181
- this._Volume = value;
182
- if (this._ProcessingSetDevice)
183
- return;
184
- this._ProcessingSetDevice = true;
185
- if (value === 'muted') {
186
- yield this.close();
187
- }
188
- else {
189
- if (!this._Capture && this._DeviceParameters) {
190
- yield this.setDevice(this._DeviceParameters);
191
- }
192
- (_a = this._Capture) === null || _a === void 0 ? void 0 : _a.worker.setVolume(value);
193
- }
194
- this._ProcessingSetDevice = false;
195
- if (value !== this._Volume) {
196
- yield this.setVolume(this._Volume);
197
- }
198
- });
199
- }
200
- close() {
201
- return __awaiter(this, void 0, void 0, function* () {
202
- logger.debug(['Audio'], 'AudioCapture.close()');
203
- if (this._Capture !== undefined) {
204
- this._Capture.worker.close();
205
- stopMediaStream(this._Capture.source.mediaStream);
206
- this._Capture.source.disconnect(this._Capture.worker.worklet);
207
- yield this.controller.audioContexts.release(this._Capture.source.context);
208
- }
209
- navigator.mediaDevices.removeEventListener('devicechange', this._DeviceCb);
210
- this._Capture = undefined;
211
- });
212
- }
213
- _UpdateMedias() {
214
- return __awaiter(this, void 0, void 0, function* () {
215
- logger.debug(['Audio'], 'AudioCapture._UpdateMedias()');
216
- if (this._Capture !== undefined) {
217
- const connections = Array.from(this._Medias).map(([key, value]) => {
218
- return { id: key, mediaIds: Array.from(value) };
219
- });
220
- this._Capture.worker.setMedias(connections);
221
- }
222
- });
223
- }
224
- }
@@ -1,13 +0,0 @@
1
- import { Backend } from '@4players/odin-common';
2
- import { GlobalMediaId, MediaController } from '../mediaController';
3
- export declare class AudioPlayback implements Backend.AudioPlayback {
4
- readonly controller: MediaController;
5
- readonly uid: Backend.UID;
6
- get volume(): Backend.Volume;
7
- get activity(): Backend.Activity;
8
- constructor(controller: MediaController, uid: Backend.UID);
9
- start(id: GlobalMediaId): void;
10
- stop(id: GlobalMediaId): void;
11
- setVolume(value: Backend.Volume): Promise<void>;
12
- close(): void;
13
- }
@@ -1,40 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { logger } from '../config';
11
- export class AudioPlayback {
12
- get volume() {
13
- return this.controller.playbackGetVolume(this.uid);
14
- }
15
- get activity() {
16
- return this.controller.playbackGetActivity(this.uid);
17
- }
18
- constructor(controller, uid) {
19
- this.controller = controller;
20
- this.uid = uid;
21
- }
22
- start(id) {
23
- logger.debug(['Audio'], 'AudioPlayback.start()', id);
24
- this.controller.playbackStart(this.uid, id);
25
- }
26
- stop(id) {
27
- logger.debug(['Audio'], 'AudioPlayback.stop()', id);
28
- this.controller.playbackStop(this.uid, id);
29
- }
30
- setVolume(value) {
31
- return __awaiter(this, void 0, void 0, function* () {
32
- logger.debug(['Audio'], 'AudioPlayback.setVolume()', value);
33
- this.controller.playbackSetVolume(this.uid, value);
34
- });
35
- }
36
- close() {
37
- logger.debug(['Audio'], 'AudioPlayback.close()');
38
- this.controller.closePlayback(this.uid);
39
- }
40
- }
@@ -1,15 +0,0 @@
1
- import { GlobalMediaId, MediaController } from '../mediaController';
2
- import { Backend } from '@4players/odin-common';
3
- import { RoomConnection } from '../roomConnection';
4
- export declare class VideoCapture implements Backend.VideoCapture {
5
- readonly controller: MediaController;
6
- readonly customType?: string | undefined;
7
- private _mediaStream?;
8
- private readonly _Medias;
9
- constructor(controller: MediaController, customType?: string | undefined);
10
- get mediaStream(): MediaStream | undefined;
11
- setDevice(ms: MediaStream): Promise<void>;
12
- start(room: RoomConnection, media: GlobalMediaId, uid: Backend.UID): void;
13
- stop(room: RoomConnection, media: GlobalMediaId): void;
14
- close(): void;
15
- }
@@ -1,69 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { stopMediaStream } from '../deviceManager';
11
- export class VideoCapture {
12
- constructor(controller, customType) {
13
- this.controller = controller;
14
- this.customType = customType;
15
- this._Medias = new Map();
16
- }
17
- get mediaStream() {
18
- return this._mediaStream;
19
- }
20
- setDevice(ms) {
21
- return __awaiter(this, void 0, void 0, function* () {
22
- // @TODO: Stop old ms before
23
- this._mediaStream = ms;
24
- });
25
- }
26
- start(room, media, uid) {
27
- var _a;
28
- let entry = this._Medias.get(media.connectionId);
29
- if (entry === undefined) {
30
- this._Medias.set(media.connectionId, (entry = new Set()));
31
- }
32
- if (entry.has(media.mediaId))
33
- return;
34
- entry.add(media.mediaId);
35
- if (((_a = room.mainConnection) === null || _a === void 0 ? void 0 : _a.id) === media.connectionId) {
36
- const properties = {
37
- kind: 'video',
38
- codec: 'VP8',
39
- uid,
40
- };
41
- if (this.customType) {
42
- properties.customType = this.customType;
43
- }
44
- room
45
- .typedRequest('StartMedia', {
46
- media_id: media.mediaId,
47
- properties,
48
- })
49
- .catch((reason) => console.error(`StartMedia got rejected; ${reason}`));
50
- }
51
- }
52
- stop(room, media) {
53
- var _a;
54
- if (this._mediaStream) {
55
- stopMediaStream(this._mediaStream);
56
- }
57
- const entry = this._Medias.get(media.connectionId);
58
- if (!(entry === null || entry === void 0 ? void 0 : entry.delete(media.mediaId)))
59
- return;
60
- if (((_a = room.mainConnection) === null || _a === void 0 ? void 0 : _a.id) === media.connectionId) {
61
- room
62
- .typedRequest('StopMedia', { media_id: media.mediaId })
63
- .catch((reason) => console.error(`StopMedia got rejected; ${reason}`));
64
- }
65
- }
66
- close() {
67
- throw new Error('Method not implemented.');
68
- }
69
- }
@@ -1,13 +0,0 @@
1
- import { Backend } from '@4players/odin-common';
2
- export declare class VideoPlayback implements Backend.VideoPlayback {
3
- readonly uid: Backend.UID;
4
- readonly customType?: string | undefined;
5
- private _mediaStream?;
6
- constructor(uid: Backend.UID, customType?: string | undefined);
7
- /**
8
- * Sets the MediaStream once.
9
- */
10
- setMediaStream(ms?: MediaStream): void;
11
- get mediaStream(): MediaStream | undefined;
12
- close(): void;
13
- }
@@ -1,20 +0,0 @@
1
- export class VideoPlayback {
2
- constructor(uid, customType) {
3
- this.uid = uid;
4
- this.customType = customType;
5
- }
6
- /**
7
- * Sets the MediaStream once.
8
- */
9
- setMediaStream(ms) {
10
- if (this._mediaStream)
11
- return;
12
- this._mediaStream = ms;
13
- }
14
- get mediaStream() {
15
- return this._mediaStream;
16
- }
17
- close() {
18
- throw new Error('Method not implemented.');
19
- }
20
- }
@@ -1,40 +0,0 @@
1
- import { Backend, RoomCommands, Result, Infer } from '@4players/odin-common';
2
- import { ConnectionPool } from './connectionPool';
3
- import { MainConnection } from './mainConnection';
4
- import { Token } from './token';
5
- import Transport = Backend.Transport;
6
- export declare class RoomConnection implements RoomConnection {
7
- readonly connectionPool: ConnectionPool;
8
- readonly transport: Transport;
9
- readonly onEvent: Backend.OnEvent;
10
- readonly gateway: URL | undefined;
11
- readonly roomId: string;
12
- private _RoomConnection;
13
- private _MainConnection;
14
- private _OwnPeerId;
15
- private readonly _Close;
16
- private _Token;
17
- private _UserData;
18
- private _Position;
19
- private _ConnectionFailures;
20
- private _FailureLimit;
21
- private _LastTokenRenew;
22
- private readonly _Closed;
23
- get token(): Token;
24
- get userData(): Uint8Array;
25
- get position(): [number, number, number];
26
- get closed(): boolean;
27
- get mainConnection(): MainConnection | undefined;
28
- constructor(connectionPool: ConnectionPool, transport: Transport, onEvent: Backend.OnEvent, gateway: URL | undefined, token: Token, roomId: string, userData: Uint8Array, position: [number, number, number]);
29
- request(name: string, properties: unknown): Promise<Result<unknown> | 'closed'>;
30
- typedRequest<Name extends Extract<keyof RoomCommands, string>>(name: Name, properties: Infer<RoomCommands[Name]['request']>): Promise<Result<Infer<RoomCommands[Name]['response']>> | 'closed'>;
31
- close(): void;
32
- get renewTokenIn(): number;
33
- private _Main;
34
- private _ConnectToServer;
35
- private _ChangeStatus;
36
- private _HandleConnection;
37
- private _HandleEvent;
38
- private _HandleRequests;
39
- private _RenewToken;
40
- }