TeaWeb/shared/js/connection/DummyVoiceConnection.ts

157 lines
3.9 KiB
TypeScript
Raw Normal View History

import {
2020-09-07 10:42:00 +00:00
AbstractVoiceConnection,
2020-09-01 12:16:43 +00:00
VoiceConnectionStatus, WhisperSessionInitializer
} from "../connection/VoiceConnection";
import {RecorderProfile} from "../voice/RecorderProfile";
2020-11-17 10:26:52 +00:00
import {AbstractServerConnection, ConnectionStatistics} from "../connection/ConnectionBase";
import {VoiceClient} from "../voice/VoiceClient";
import {VoicePlayerEvents, VoicePlayerLatencySettings, VoicePlayerState} from "../voice/VoicePlayer";
import {WhisperSession, WhisperTarget} from "../voice/VoiceWhisper";
import {Registry} from "../events";
class DummyVoiceClient implements VoiceClient {
2020-09-07 17:07:14 +00:00
readonly events: Registry<VoicePlayerEvents>;
2020-09-07 10:42:00 +00:00
private readonly clientId: number;
private volume: number;
constructor(clientId: number) {
2020-09-07 17:07:14 +00:00
this.events = new Registry<VoicePlayerEvents>();
2020-09-07 10:42:00 +00:00
this.clientId = clientId;
this.volume = 1;
}
2020-09-07 10:42:00 +00:00
getClientId(): number {
return this.clientId;
}
2020-09-07 10:42:00 +00:00
getVolume(): number {
return this.volume;
}
2020-09-07 10:42:00 +00:00
setVolume(volume: number) {
this.volume = volume;
}
2020-09-07 10:42:00 +00:00
getState(): VoicePlayerState {
return VoicePlayerState.STOPPED;
}
2020-09-07 10:42:00 +00:00
getLatencySettings(): Readonly<VoicePlayerLatencySettings> {
return { maxBufferTime: 0, minBufferTime: 0 };
}
2020-09-07 10:42:00 +00:00
setLatencySettings(settings) { }
flushBuffer() { }
abortReplay() { }
2020-09-07 17:07:14 +00:00
resetLatencySettings() {
}
}
export class DummyVoiceConnection extends AbstractVoiceConnection {
private recorder: RecorderProfile;
private voiceClients: DummyVoiceClient[] = [];
constructor(connection: AbstractServerConnection) {
super(connection);
}
2020-08-26 10:33:53 +00: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 10:42:00 +00:00
availableVoiceClients(): VoiceClient[] {
return this.voiceClients;
}
2020-08-26 10:33:53 +00:00
decodingSupported(codec: number): boolean {
return false;
}
2020-08-26 10:33:53 +00:00
encodingSupported(codec: number): boolean {
return false;
}
getConnectionState(): VoiceConnectionStatus {
return VoiceConnectionStatus.ClientUnsupported;
}
2020-08-26 10:33:53 +00:00
getEncoderCodec(): number {
return 0;
}
2020-09-07 10:42:00 +00:00
async registerVoiceClient(clientId: number): Promise<VoiceClient> {
const client = new DummyVoiceClient(clientId);
this.voiceClients.push(client);
return client;
}
2020-08-26 10:33:53 +00:00
setEncoderCodec(codec: number) {}
2020-09-07 10:42:00 +00:00
async unregisterVoiceClient(client: VoiceClient): Promise<void> {
this.voiceClients.remove(client as any);
}
2020-08-26 10:33:53 +00:00
voiceRecorder(): RecorderProfile {
return this.recorder;
}
2020-09-01 12:16:43 +00:00
dropWhisperSession(session: WhisperSession) { }
getWhisperSessionInitializer(): WhisperSessionInitializer | undefined {
return undefined;
}
getWhisperSessions(): WhisperSession[] {
return [];
}
setWhisperSessionInitializer(initializer: WhisperSessionInitializer | undefined) { }
2020-09-07 17:07:14 +00:00
getWhisperTarget(): WhisperTarget | undefined {
return undefined;
}
startWhisper(target: WhisperTarget): Promise<void> {
return Promise.reject(tr("not supported"));
}
stopWhisper() { }
2020-09-16 19:50:21 +00:00
getFailedMessage(): string {
return "";
}
2020-09-24 13:51:22 +00:00
isReplayingVoice(): boolean {
return false;
}
stopAllVoiceReplays() { }
2020-11-17 10:26:52 +00:00
async getConnectionStats(): Promise<ConnectionStatistics> {
return {
bytesReceived: 0,
bytesSend: 0
}
}
}