2020-08-10 12:41:34 +00:00
|
|
|
import {
|
|
|
|
AbstractVoiceConnection, LatencySettings,
|
|
|
|
PlayerState,
|
|
|
|
VoiceClient,
|
2020-09-01 12:16:43 +00:00
|
|
|
VoiceConnectionStatus, WhisperSessionInitializer
|
2020-08-10 12:41:34 +00:00
|
|
|
} from "tc-shared/connection/VoiceConnection";
|
|
|
|
import {RecorderProfile} from "tc-shared/voice/RecorderProfile";
|
|
|
|
import {AbstractServerConnection} from "tc-shared/connection/ConnectionBase";
|
2020-09-01 12:16:43 +00:00
|
|
|
import {WhisperSession} from "tc-shared/voice/Whisper";
|
2020-08-10 12:41:34 +00:00
|
|
|
|
|
|
|
class DummyVoiceClient implements VoiceClient {
|
|
|
|
client_id: number;
|
|
|
|
|
|
|
|
callback_playback: () => any;
|
|
|
|
callback_stopped: () => any;
|
|
|
|
|
|
|
|
callback_state_changed: (new_state: PlayerState) => any;
|
|
|
|
|
|
|
|
private volume: number;
|
|
|
|
|
|
|
|
constructor(clientId: number) {
|
|
|
|
this.client_id = clientId;
|
|
|
|
|
|
|
|
this.volume = 1;
|
|
|
|
this.reset_latency_settings();
|
|
|
|
}
|
|
|
|
|
|
|
|
abort_replay() { }
|
|
|
|
|
|
|
|
flush() {
|
|
|
|
throw "flush isn't supported";}
|
|
|
|
|
|
|
|
get_state(): PlayerState {
|
|
|
|
return PlayerState.STOPPED;
|
|
|
|
}
|
|
|
|
|
|
|
|
latency_settings(settings?: LatencySettings): LatencySettings {
|
|
|
|
throw "latency settings are not supported";
|
|
|
|
}
|
|
|
|
|
|
|
|
reset_latency_settings() {
|
|
|
|
throw "latency settings are not supported";
|
|
|
|
}
|
|
|
|
|
|
|
|
set_volume(volume: number): void {
|
|
|
|
this.volume = volume;
|
|
|
|
}
|
|
|
|
|
|
|
|
get_volume(): number {
|
|
|
|
return this.volume;
|
|
|
|
}
|
|
|
|
|
|
|
|
support_flush(): boolean {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
support_latency_settings(): boolean {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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> {
|
2020-08-10 12:41:34 +00:00
|
|
|
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-08-26 10:33:53 +00:00
|
|
|
availableClients(): VoiceClient[] {
|
2020-08-10 12:41:34 +00:00
|
|
|
return this.voiceClients;
|
|
|
|
}
|
|
|
|
|
2020-08-26 10:33:53 +00:00
|
|
|
decodingSupported(codec: number): boolean {
|
2020-08-10 12:41:34 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-08-26 10:33:53 +00:00
|
|
|
encodingSupported(codec: number): boolean {
|
2020-08-10 12:41:34 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
getConnectionState(): VoiceConnectionStatus {
|
|
|
|
return VoiceConnectionStatus.ClientUnsupported;
|
|
|
|
}
|
|
|
|
|
2020-08-26 10:33:53 +00:00
|
|
|
getEncoderCodec(): number {
|
2020-08-10 12:41:34 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-08-26 10:33:53 +00:00
|
|
|
registerClient(clientId: number): VoiceClient {
|
2020-08-10 12:41:34 +00:00
|
|
|
const client = new DummyVoiceClient(clientId);
|
|
|
|
this.voiceClients.push(client);
|
|
|
|
return client;
|
|
|
|
}
|
|
|
|
|
2020-08-26 10:33:53 +00:00
|
|
|
setEncoderCodec(codec: number) {}
|
2020-08-10 12:41:34 +00:00
|
|
|
|
|
|
|
async unregister_client(client: VoiceClient): Promise<void> {
|
|
|
|
this.voiceClients.remove(client as any);
|
|
|
|
}
|
|
|
|
|
2020-08-26 10:33:53 +00:00
|
|
|
voiceRecorder(): RecorderProfile {
|
2020-08-10 12:41:34 +00:00
|
|
|
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-08-10 12:41:34 +00:00
|
|
|
}
|