TeaWeb/shared/js/connection/DummyVoiceConnection.ts

123 lines
3.2 KiB
TypeScript
Raw Normal View History

import {
2020-09-07 12:42:00 +02:00
AbstractVoiceConnection,
2020-09-01 14:16:43 +02:00
VoiceConnectionStatus, WhisperSessionInitializer
} from "tc-shared/connection/VoiceConnection";
import {RecorderProfile} from "tc-shared/voice/RecorderProfile";
import {AbstractServerConnection} from "tc-shared/connection/ConnectionBase";
2020-09-07 12:42:00 +02:00
import {VoiceClient} from "tc-shared/voice/VoiceClient";
import {VoicePlayerLatencySettings, VoicePlayerState} from "tc-shared/voice/VoicePlayer";
import {WhisperSession} from "tc-shared/voice/VoiceWhisper";
class DummyVoiceClient implements VoiceClient {
2020-09-07 12:42:00 +02:00
private readonly clientId: number;
private volume: number;
constructor(clientId: number) {
2020-09-07 12:42:00 +02:00
this.clientId = clientId;
this.volume = 1;
}
2020-09-07 12:42:00 +02:00
getClientId(): number {
return this.clientId;
}
2020-09-07 12:42:00 +02:00
getVolume(): number {
return this.volume;
}
2020-09-07 12:42:00 +02:00
setVolume(volume: number) {
this.volume = volume;
}
2020-09-07 12:42:00 +02:00
getState(): VoicePlayerState {
return VoicePlayerState.STOPPED;
}
2020-09-07 12:42:00 +02:00
getLatencySettings(): Readonly<VoicePlayerLatencySettings> {
return { maxBufferTime: 0, minBufferTime: 0 };
}
2020-09-07 12:42:00 +02:00
setLatencySettings(settings) { }
flushBuffer() { }
abortReplay() { }
}
export class DummyVoiceConnection extends AbstractVoiceConnection {
private recorder: RecorderProfile;
private voiceClients: DummyVoiceClient[] = [];
constructor(connection: AbstractServerConnection) {
super(connection);
}
2020-08-26 12:33:53 +02:00
async acquireVoiceRecorder(recorder: RecorderProfile | undefined): Promise<void> {
if(this.recorder === recorder)
return;
if(this.recorder) {
this.recorder.callback_unmount = undefined;
await this.recorder.unmount();
}
await recorder?.unmount();
this.recorder = recorder;
if(this.recorder) {
this.recorder.callback_unmount = () => {
this.recorder = undefined;
this.events.fire("notify_recorder_changed");
}
}
this.events.fire("notify_recorder_changed", {});
}
2020-09-07 12:42:00 +02:00
availableVoiceClients(): VoiceClient[] {
return this.voiceClients;
}
2020-08-26 12:33:53 +02:00
decodingSupported(codec: number): boolean {
return false;
}
2020-08-26 12:33:53 +02:00
encodingSupported(codec: number): boolean {
return false;
}
getConnectionState(): VoiceConnectionStatus {
return VoiceConnectionStatus.ClientUnsupported;
}
2020-08-26 12:33:53 +02:00
getEncoderCodec(): number {
return 0;
}
2020-09-07 12:42:00 +02:00
async registerVoiceClient(clientId: number): Promise<VoiceClient> {
const client = new DummyVoiceClient(clientId);
this.voiceClients.push(client);
return client;
}
2020-08-26 12:33:53 +02:00
setEncoderCodec(codec: number) {}
2020-09-07 12:42:00 +02:00
async unregisterVoiceClient(client: VoiceClient): Promise<void> {
this.voiceClients.remove(client as any);
}
2020-08-26 12:33:53 +02:00
voiceRecorder(): RecorderProfile {
return this.recorder;
}
2020-09-01 14:16:43 +02:00
dropWhisperSession(session: WhisperSession) { }
getWhisperSessionInitializer(): WhisperSessionInitializer | undefined {
return undefined;
}
getWhisperSessions(): WhisperSession[] {
return [];
}
setWhisperSessionInitializer(initializer: WhisperSessionInitializer | undefined) { }
}