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

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/plugin/index.d.ts +17 -66
  2. package/lib/plugin/index.js +1 -404
  3. package/lib/worker/shared.js +1 -0
  4. package/lib/worker/unshared.js +1 -0
  5. package/package.json +12 -9
  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 -31
  15. package/lib/plugin/h3/mainConnection.js +0 -195
  16. package/lib/plugin/mainConnection.d.ts +0 -30
  17. package/lib/plugin/mainConnection.js +0 -21
  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 -53
  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/wasm/index.d.ts +0 -97
  39. package/lib/worker/buffers.d.ts +0 -42
  40. package/lib/worker/buffers.js +0 -79
  41. package/lib/worker/common.d.ts +0 -45
  42. package/lib/worker/common.js +0 -7
  43. package/lib/worker/config.d.ts +0 -8
  44. package/lib/worker/config.js +0 -11
  45. package/lib/worker/index.d.ts +0 -3
  46. package/lib/worker/index.js +0 -1
  47. package/lib/worker/memory.d.ts +0 -9
  48. package/lib/worker/memory.js +0 -29
  49. package/lib/worker/messages.d.ts +0 -14
  50. package/lib/worker/messages.js +0 -15
  51. package/lib/worker/packet.d.ts +0 -11
  52. package/lib/worker/packet.js +0 -59
  53. package/lib/worker/shared/capture.d.ts +0 -27
  54. package/lib/worker/shared/capture.js +0 -63
  55. package/lib/worker/shared/index.d.ts +0 -3
  56. package/lib/worker/shared/index.js +0 -147
  57. package/lib/worker/shared/messages.d.ts +0 -67
  58. package/lib/worker/shared/messages.js +0 -64
  59. package/lib/worker/shared/playback.d.ts +0 -20
  60. package/lib/worker/shared/playback.js +0 -78
  61. package/lib/worker/unshared/capture.d.ts +0 -27
  62. package/lib/worker/unshared/capture.js +0 -66
  63. package/lib/worker/unshared/index.d.ts +0 -3
  64. package/lib/worker/unshared/index.js +0 -170
  65. package/lib/worker/unshared/messages.d.ts +0 -81
  66. package/lib/worker/unshared/messages.js +0 -80
  67. package/lib/worker/unshared/playback.d.ts +0 -22
  68. package/lib/worker/unshared/playback.js +0 -83
@@ -1,195 +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 { ConnectionStatus, } from '../mainConnection';
11
- import { MainCommandsRpc, MainNotificationsRpc, RoomCommandsRpc, RoomNotificationsRpc, failure, success, } from '@4players/odin-common';
12
- import { logger, Transport } from '..';
13
- import { Token } from '../token';
14
- import { RpcConnection, TypedRpcConnection } from '../rpcConnection';
15
- import { HealthCheckTimeout } from '../config';
16
- import * as pkg from '../../../package.json';
17
- export class H3MainConnection {
18
- get closeSignal() {
19
- return this.closeController.signal;
20
- }
21
- get transport() {
22
- return Transport.H3;
23
- }
24
- get closed() {
25
- return this.closeSignal.aborted;
26
- }
27
- static create(id, address, onDatagram, signal) {
28
- return __awaiter(this, void 0, void 0, function* () {
29
- try {
30
- const url = new URL(`https://${address}?version=${pkg.version}`);
31
- const closeController = new AbortController();
32
- signal.addEventListener('abort', () => closeController.abort(), {
33
- once: true,
34
- });
35
- const connection = new WebTransport(url);
36
- closeController.signal.addEventListener('abort', () => __awaiter(this, void 0, void 0, function* () {
37
- try {
38
- yield connection.close();
39
- }
40
- catch (_a) {
41
- /* drop silently */
42
- }
43
- }), { once: true });
44
- yield connection.ready;
45
- const stream = yield connection.createBidirectionalStream();
46
- const rpc = new TypedRpcConnection(new RpcConnection(stream), MainCommandsRpc, MainNotificationsRpc);
47
- closeController.signal.addEventListener('abort', () => rpc.close(), {
48
- once: true,
49
- });
50
- rpc.notify('Hello', { stream: 'main' });
51
- return success(new H3MainConnection(id, address, onDatagram, connection, rpc, closeController));
52
- }
53
- catch (error) {
54
- return failure(`connecting to ${address} failed with ${error}`);
55
- }
56
- });
57
- }
58
- constructor(id, address, onDatagram, connection, rpc, closeController) {
59
- this.id = id;
60
- this.address = address;
61
- this.connection = connection;
62
- this.rpc = rpc;
63
- this.closeController = closeController;
64
- this.status = ConnectionStatus.Connecting;
65
- logger.info(['Connection', 'H3'], 'H3MainConnection.constructor()');
66
- this.closePromise = (() => __awaiter(this, void 0, void 0, function* () {
67
- try {
68
- yield this.connection.closed;
69
- }
70
- catch (_a) {
71
- /* drop silently */
72
- }
73
- return 'closed';
74
- }))();
75
- this.datagramWriter = connection.datagrams.writable.getWriter();
76
- this.connection.closed
77
- .then(() => {
78
- this.status = ConnectionStatus.Closed;
79
- })
80
- .catch(() => {
81
- /* drop silently */
82
- });
83
- this.connection.ready
84
- .then(() => {
85
- this.status = ConnectionStatus.Connected;
86
- })
87
- .catch(() => {
88
- /* drop silently */
89
- });
90
- readDatagrams(this.connection, this.id, onDatagram);
91
- }
92
- waitForConnected() {
93
- return Promise.race([
94
- this.connection.ready,
95
- this.connection.closed.then(() => {
96
- throw new Error('connection closed');
97
- }),
98
- ]);
99
- }
100
- close() {
101
- this.closeController.abort('request');
102
- }
103
- joinRoom(token, roomId, userData, position) {
104
- return __awaiter(this, void 0, void 0, function* () {
105
- try {
106
- if (this.closed)
107
- return 'closed';
108
- const stream = yield this.connection
109
- .createBidirectionalStream()
110
- .catch(() => 'closed');
111
- if (stream === 'closed')
112
- return 'closed';
113
- const rpc = new TypedRpcConnection(new RpcConnection(stream), RoomCommandsRpc, RoomNotificationsRpc);
114
- const response = yield rpc.request('Hello', {
115
- stream: 'room',
116
- token: String(token),
117
- room_id: roomId,
118
- user_data: userData,
119
- position,
120
- });
121
- if (response === 'closed' || response.type === 'Failure')
122
- return response;
123
- return success(rpc.rpcConnection);
124
- }
125
- catch (error) {
126
- return failure(`JoinRoom failed; ${error}`);
127
- }
128
- });
129
- }
130
- getReconnectToken(peerId) {
131
- return __awaiter(this, void 0, void 0, function* () {
132
- const response = yield this._Request('RequestReconnectToken', {
133
- peer_id: peerId,
134
- });
135
- if (response.type === 'Failure')
136
- return response;
137
- return Token.parse(response.value);
138
- });
139
- }
140
- healthCheck() {
141
- return __awaiter(this, void 0, void 0, function* () {
142
- const response = yield this._Request('Ping', {}, HealthCheckTimeout);
143
- const success = response !== 'timeout' && response.type === 'Success';
144
- if (!success)
145
- this.close();
146
- return success;
147
- });
148
- }
149
- sendDatagram(datagram) {
150
- try {
151
- this.datagramWriter.write(datagram);
152
- }
153
- catch (_a) {
154
- /* drop silently */
155
- }
156
- }
157
- startLocalVideo(mediaId, track) {
158
- throw new Error('not supported.');
159
- }
160
- stopLocalVideo(mediaId) {
161
- throw new Error('not supported.');
162
- }
163
- startRemoteVideo(mediaId) {
164
- throw new Error('not supported.');
165
- }
166
- stopRemoteVideo(mediaId) {
167
- throw new Error('not supported.');
168
- }
169
- _Request(name, properties, timeout) {
170
- return __awaiter(this, void 0, void 0, function* () {
171
- const result = yield (timeout === undefined
172
- ? this.rpc.request(name, properties)
173
- : this.rpc.request(name, properties, timeout));
174
- if (result === 'closed')
175
- return failure('connection lost');
176
- return result;
177
- });
178
- }
179
- }
180
- function readDatagrams(connection, connectionId, onDatagram) {
181
- return __awaiter(this, void 0, void 0, function* () {
182
- try {
183
- const reader = connection.datagrams.readable.getReader();
184
- for (;;) {
185
- const read = yield reader.read();
186
- if (read.done)
187
- break;
188
- onDatagram(connectionId, read.value);
189
- }
190
- }
191
- catch (_a) {
192
- /* drop silently */
193
- }
194
- });
195
- }
@@ -1,30 +0,0 @@
1
- import { Result } from '@4players/odin-common';
2
- import { Token } from './token';
3
- import { Transport } from './index';
4
- import { RpcConnection } from './rpcConnection';
5
- export type DatagramHandler = (connectionId: number, datagram: Uint8Array) => void;
6
- export declare function createMainConnection(id: number, transport: Transport, address: string, onDatagram: DatagramHandler, signal: AbortSignal): Promise<Result<MainConnection>>;
7
- export declare enum ConnectionStatus {
8
- Connecting = 0,
9
- Connected = 1,
10
- Closed = 2
11
- }
12
- export interface MainConnection {
13
- get id(): number;
14
- get transport(): Transport;
15
- get address(): string;
16
- get status(): ConnectionStatus;
17
- get closePromise(): Promise<'closed'>;
18
- get closeSignal(): AbortSignal;
19
- get closed(): boolean;
20
- waitForConnected(): Promise<void>;
21
- close(): void;
22
- joinRoom(token: Token, roomId: string, userData: Uint8Array, position: [number, number, number]): Promise<Result<RpcConnection> | 'closed'>;
23
- getReconnectToken(peerId: number): Promise<Result<Token>>;
24
- healthCheck(): Promise<boolean>;
25
- sendDatagram(datagram: Uint8Array): void;
26
- startLocalVideo(mediaId: number, track: MediaStreamTrack): void;
27
- stopLocalVideo(mediaId: number): void;
28
- startRemoteVideo(mediaId: number): Promise<MediaStreamTrack>;
29
- stopRemoteVideo(mediaId: number): void;
30
- }
@@ -1,21 +0,0 @@
1
- /* eslint-disable no-dupe-class-members */
2
- import { logger, Transport } from './index';
3
- import { WebRtcMainConnection } from './webrtc/mainConnection';
4
- import { H3MainConnection } from './h3/mainConnection';
5
- export function createMainConnection(id, transport, address, onDatagram, signal) {
6
- logger.log(['Connection'], 'createMainConnection() ', transport, address);
7
- switch (transport) {
8
- case Transport.H3:
9
- return H3MainConnection.create(id, address, onDatagram, signal);
10
- case Transport.WebRTC:
11
- return WebRtcMainConnection.create(id, address, onDatagram, signal);
12
- default:
13
- throw new Error(`transport ${transport} is not supported`);
14
- }
15
- }
16
- export var ConnectionStatus;
17
- (function (ConnectionStatus) {
18
- ConnectionStatus[ConnectionStatus["Connecting"] = 0] = "Connecting";
19
- ConnectionStatus[ConnectionStatus["Connected"] = 1] = "Connected";
20
- ConnectionStatus[ConnectionStatus["Closed"] = 2] = "Closed";
21
- })(ConnectionStatus || (ConnectionStatus = {}));
@@ -1,66 +0,0 @@
1
- import { Backend, Strand } from '@4players/odin-common';
2
- import { CaptureSink, PlaybackId, PlaybackWorker } from '../worker/common';
3
- import { AudioCapture } from './medias/audio-capture';
4
- import { VideoCapture } from './medias/video-capture';
5
- import { AudioPlayback } from './medias/audio-playback';
6
- export type CreateAudioPlaybackParameters = Backend.CreateAudioPlaybackParameters;
7
- export type CreateAudioCaptureParameters = Backend.CreateAudioCaptureParameters & {
8
- readonly device?: Device;
9
- };
10
- export type AudioContextFactory = (sampleRate: number | undefined) => Promise<AudioContext>;
11
- export interface GlobalMediaId extends PlaybackId {
12
- }
13
- declare global {
14
- interface AudioSinkOptions {
15
- type: 'none';
16
- }
17
- interface AudioContext {
18
- setSinkId?: (sinkId: string | undefined | AudioSinkOptions) => Promise<undefined>;
19
- }
20
- }
21
- export declare class AudioContextCollection {
22
- readonly audioContextFactory: AudioContextFactory;
23
- readonly entries: Array<{
24
- sampleRate: undefined | number;
25
- audioContext: AudioContext;
26
- references: number;
27
- }>;
28
- constructor(audioContextFactory: AudioContextFactory);
29
- acquire(sampleRate: number | undefined): Promise<AudioContext>;
30
- release(audioContext: BaseAudioContext): Promise<void>;
31
- close(): void;
32
- }
33
- export declare class MediaController {
34
- readonly audioContexts: AudioContextCollection;
35
- readonly sink: CaptureSink;
36
- playbackWorker: PlaybackWorker | undefined;
37
- globalVolume: number;
38
- playbacks: Map<string, {
39
- id: GlobalMediaId | undefined;
40
- volume: Backend.Volume;
41
- playback: AudioPlayback;
42
- }>;
43
- setPlaybackStrand: Strand;
44
- create(audioContexts: AudioContextCollection, sink: CaptureSink): Promise<MediaController>;
45
- constructor(audioContexts: AudioContextCollection, sink: CaptureSink);
46
- receivePacket(connectionId: number, packet: Uint8Array): void;
47
- createAudioPlayback(parameters: CreateAudioPlaybackParameters): Promise<AudioPlayback>;
48
- createAudioCapture(parameters: CreateAudioCaptureParameters): Promise<AudioCapture>;
49
- createVideoCapture(ms: MediaStream, customType?: string): Promise<VideoCapture>;
50
- playbackSetDevice(device?: Device): Promise<void>;
51
- playbackSetGlobalVolume(value: Backend.Volume): void;
52
- playbackStart(uid: string, id: GlobalMediaId): void;
53
- playbackStop(uid: string, id: GlobalMediaId): void;
54
- playbackGetActivity(uid: string): Backend.Activity;
55
- playbackSetVolume(uid: string, volume: Backend.Volume): void;
56
- playbackGetVolume(uid: string): Backend.Volume;
57
- closePlayback(uid: string): void;
58
- close(): void;
59
- }
60
- export declare class Device implements Backend.Device {
61
- readonly device: MediaDeviceInfo;
62
- readonly isDefault: boolean;
63
- constructor(device: MediaDeviceInfo, isDefault?: boolean);
64
- get type(): "AudioPlayback" | "AudioCapture";
65
- get name(): string;
66
- }
@@ -1,215 +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 { Strand, assert } from '@4players/odin-common';
11
- import { createPlaybackWorker } from '../worker';
12
- import { Silence, } from '../worker/common';
13
- import { AudioCapture } from './medias/audio-capture';
14
- import { VideoCapture } from './medias/video-capture';
15
- import { AudioPlayback } from './medias/audio-playback';
16
- export class AudioContextCollection {
17
- constructor(audioContextFactory) {
18
- this.audioContextFactory = audioContextFactory;
19
- this.entries = [];
20
- }
21
- acquire(sampleRate) {
22
- return __awaiter(this, void 0, void 0, function* () {
23
- for (const entry of this.entries) {
24
- if (entry.sampleRate === sampleRate) {
25
- entry.references += 1;
26
- return entry.audioContext;
27
- }
28
- else if (entry.sampleRate === undefined) {
29
- const audioContext = entry.audioContext;
30
- if (audioContext.sampleRate === sampleRate) {
31
- entry.references += 1;
32
- return entry.audioContext;
33
- }
34
- }
35
- }
36
- const entry = {
37
- sampleRate,
38
- audioContext: yield this.audioContextFactory(sampleRate),
39
- references: 1,
40
- };
41
- this.entries.push(entry);
42
- return entry.audioContext;
43
- });
44
- }
45
- release(audioContext) {
46
- return __awaiter(this, void 0, void 0, function* () {
47
- const index = this.entries.findIndex((entry) => entry.audioContext === audioContext);
48
- if (index < 0)
49
- return;
50
- this.entries[index].references -= 1;
51
- if (this.entries[index].references <= 0) {
52
- const context = this.entries[index].audioContext;
53
- this.entries.splice(index, 1);
54
- yield context.close();
55
- }
56
- });
57
- }
58
- close() {
59
- for (const entry of this.entries) {
60
- entry.audioContext.close();
61
- }
62
- }
63
- }
64
- export class MediaController {
65
- create(audioContexts, sink) {
66
- return __awaiter(this, void 0, void 0, function* () {
67
- return new MediaController(audioContexts, sink);
68
- });
69
- }
70
- constructor(audioContexts, sink) {
71
- this.audioContexts = audioContexts;
72
- this.sink = sink;
73
- this.globalVolume = 1;
74
- this.playbacks = new Map();
75
- this.setPlaybackStrand = new Strand();
76
- }
77
- receivePacket(connectionId, packet) {
78
- var _a;
79
- (_a = this.playbackWorker) === null || _a === void 0 ? void 0 : _a.receivePacket(connectionId, packet);
80
- }
81
- createAudioPlayback(parameters) {
82
- return __awaiter(this, void 0, void 0, function* () {
83
- let entry = this.playbacks.get(parameters.uid);
84
- let volume = parameters.volume;
85
- if (entry === undefined) {
86
- volume = volume !== null && volume !== void 0 ? volume : 1;
87
- const playback = new AudioPlayback(this, parameters.uid);
88
- entry = { id: undefined, volume, playback };
89
- this.playbacks.set(parameters.uid, entry);
90
- }
91
- if (volume !== undefined) {
92
- entry.playback.setVolume(volume);
93
- }
94
- return entry.playback;
95
- });
96
- }
97
- createAudioCapture(parameters) {
98
- return __awaiter(this, void 0, void 0, function* () {
99
- const capture = new AudioCapture(this, parameters);
100
- yield capture.setDevice(parameters);
101
- return capture;
102
- });
103
- }
104
- createVideoCapture(ms, customType) {
105
- return __awaiter(this, void 0, void 0, function* () {
106
- const videoCapture = new VideoCapture(this, customType);
107
- yield videoCapture.setDevice(ms);
108
- return videoCapture;
109
- });
110
- }
111
- playbackSetDevice(device) {
112
- return this.setPlaybackStrand.enqueue(() => __awaiter(this, void 0, void 0, function* () {
113
- var _a;
114
- let deviceId = (_a = device === null || device === void 0 ? void 0 : device.device.deviceId) !== null && _a !== void 0 ? _a : '';
115
- if (deviceId === 'default') {
116
- deviceId = '';
117
- }
118
- let audioContext;
119
- if (this.playbackWorker === undefined) {
120
- audioContext = yield this.audioContexts.acquire(48000);
121
- this.playbackWorker = yield createPlaybackWorker(audioContext);
122
- this.playbackWorker.setGlobalVolume(this.globalVolume);
123
- }
124
- else {
125
- audioContext = this.playbackWorker.audioContext;
126
- }
127
- if ((audioContext === null || audioContext === void 0 ? void 0 : audioContext.setSinkId) !== undefined &&
128
- device &&
129
- (audioContext === null || audioContext === void 0 ? void 0 : audioContext.state) === 'running') {
130
- yield audioContext.setSinkId(deviceId);
131
- }
132
- }));
133
- }
134
- playbackSetGlobalVolume(value) {
135
- var _a;
136
- this.globalVolume = value === 'muted' ? 0 : value;
137
- (_a = this.playbackWorker) === null || _a === void 0 ? void 0 : _a.setGlobalVolume(this.globalVolume);
138
- }
139
- playbackStart(uid, id) {
140
- var _a;
141
- const entry = this.playbacks.get(uid);
142
- if (entry === undefined)
143
- return;
144
- if (entry.id !== undefined) {
145
- this.playbackStop(uid, entry.id);
146
- }
147
- entry.id = id;
148
- (_a = this.playbackWorker) === null || _a === void 0 ? void 0 : _a.addMedias(id.connectionId, [id.mediaId]);
149
- this.playbackSetVolume(uid, entry.volume);
150
- }
151
- playbackStop(uid, id) {
152
- var _a;
153
- const entry = this.playbacks.get(uid);
154
- if (entry === undefined)
155
- return;
156
- if (entry.id !== id)
157
- console.error('playback mediaId out of sync!');
158
- entry.id = undefined;
159
- (_a = this.playbackWorker) === null || _a === void 0 ? void 0 : _a.removeMedias(id.connectionId, [id.mediaId]);
160
- }
161
- playbackGetActivity(uid) {
162
- var _a, _b;
163
- const entry = this.playbacks.get(uid);
164
- if ((entry === null || entry === void 0 ? void 0 : entry.id) === undefined)
165
- return Silence;
166
- return (_b = (_a = this.playbackWorker) === null || _a === void 0 ? void 0 : _a.getActivity(entry.id)) !== null && _b !== void 0 ? _b : Silence;
167
- }
168
- playbackSetVolume(uid, volume) {
169
- var _a;
170
- const entry = this.playbacks.get(uid);
171
- if (entry === undefined)
172
- return;
173
- entry.volume = volume === 'muted' ? 0 : volume;
174
- if (entry.id !== undefined) {
175
- (_a = this.playbackWorker) === null || _a === void 0 ? void 0 : _a.setVolume(entry.id, entry.volume);
176
- }
177
- }
178
- playbackGetVolume(uid) {
179
- var _a;
180
- const entry = this.playbacks.get(uid);
181
- return (_a = entry === null || entry === void 0 ? void 0 : entry.volume) !== null && _a !== void 0 ? _a : 1;
182
- }
183
- closePlayback(uid) {
184
- const entry = this.playbacks.get(uid);
185
- if (entry === undefined)
186
- return;
187
- if (entry.id !== undefined)
188
- this.playbackStop(uid, entry.id);
189
- this.playbacks.delete(uid);
190
- }
191
- close() {
192
- var _a;
193
- (_a = this.playbackWorker) === null || _a === void 0 ? void 0 : _a.close();
194
- this.audioContexts.close();
195
- }
196
- }
197
- export class Device {
198
- constructor(device, isDefault = false) {
199
- this.device = device;
200
- this.isDefault = isDefault;
201
- }
202
- get type() {
203
- switch (this.device.kind) {
204
- case 'audioinput':
205
- return 'AudioCapture';
206
- case 'audiooutput':
207
- return 'AudioPlayback';
208
- default:
209
- assert(false, 'not supported device');
210
- }
211
- }
212
- get name() {
213
- return this.device.label;
214
- }
215
- }
@@ -1,30 +0,0 @@
1
- import { Backend } from '@4players/odin-common';
2
- import { DeviceParameters } from '../index';
3
- import { RoomConnection } from '../roomConnection';
4
- import { MediaController, CreateAudioCaptureParameters, GlobalMediaId } from '../mediaController';
5
- export declare class AudioCapture implements Backend.AudioCapture {
6
- readonly controller: MediaController;
7
- private _Capture;
8
- private readonly _Medias;
9
- private _Vad;
10
- private _Apm;
11
- private _Volume;
12
- private _DeviceParameters?;
13
- private _ProcessingSetDevice;
14
- private _DeviceCb;
15
- get vad(): Backend.VadConfig;
16
- get apm(): Backend.ApmConfig;
17
- get volume(): Backend.Volume;
18
- get activity(): import("../../worker/common").Activity;
19
- get speechProbability(): number;
20
- get deviceId(): string | undefined;
21
- constructor(controller: MediaController, parameters: CreateAudioCaptureParameters);
22
- start(room: RoomConnection, media: GlobalMediaId, uid: Backend.UID): void;
23
- stop(room: RoomConnection, media: GlobalMediaId): void;
24
- setVad(value: Backend.VadConfig): void;
25
- setApm(config: Backend.ApmConfig): Promise<void>;
26
- setDevice(parameters: DeviceParameters): Promise<void>;
27
- setVolume(value: Backend.Volume): Promise<void>;
28
- close(): Promise<void>;
29
- _UpdateMedias(): Promise<void>;
30
- }