2020-08-10 12:41:34 +00:00
|
|
|
import {
|
2020-09-07 10:42:00 +00:00
|
|
|
AbstractVoiceConnection,
|
2020-09-01 12:16:43 +00:00
|
|
|
VoiceConnectionStatus, WhisperSessionInitializer
|
2020-09-12 13:49:20 +00:00
|
|
|
} from "../connection/VoiceConnection";
|
|
|
|
import {RecorderProfile} from "../voice/RecorderProfile";
|
2020-11-17 10:26:52 +00:00
|
|
|
import {AbstractServerConnection, ConnectionStatistics} from "../connection/ConnectionBase";
|
2020-09-12 13:49:20 +00:00
|
|
|
import {VoiceClient} from "../voice/VoiceClient";
|
|
|
|
import {VoicePlayerEvents, VoicePlayerLatencySettings, VoicePlayerState} from "../voice/VoicePlayer";
|
|
|
|
import {WhisperSession, WhisperTarget} from "../voice/VoiceWhisper";
|
|
|
|
import {Registry} from "../events";
|
2020-08-10 12:41:34 +00:00
|
|
|
|
|
|
|
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;
|
2020-08-10 12:41:34 +00:00
|
|
|
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;
|
2020-08-10 12:41:34 +00:00
|
|
|
this.volume = 1;
|
|
|
|
}
|
|
|
|
|
2020-09-07 10:42:00 +00:00
|
|
|
getClientId(): number {
|
|
|
|
return this.clientId;
|
2020-08-10 12:41:34 +00:00
|
|
|
}
|
|
|
|
|
2020-09-07 10:42:00 +00:00
|
|
|
getVolume(): number {
|
|
|
|
return this.volume;
|
2020-08-10 12:41:34 +00:00
|
|
|
}
|
|
|
|
|
2020-09-07 10:42:00 +00:00
|
|
|
setVolume(volume: number) {
|
2020-08-10 12:41:34 +00:00
|
|
|
this.volume = volume;
|
|
|
|
}
|
|
|
|
|
2020-09-07 10:42:00 +00:00
|
|
|
getState(): VoicePlayerState {
|
|
|
|
return VoicePlayerState.STOPPED;
|
2020-08-10 12:41:34 +00:00
|
|
|
}
|
|
|
|
|
2020-09-07 10:42:00 +00:00
|
|
|
getLatencySettings(): Readonly<VoicePlayerLatencySettings> {
|
|
|
|
return { maxBufferTime: 0, minBufferTime: 0 };
|
2020-08-10 12:41:34 +00:00
|
|
|
}
|
|
|
|
|
2020-09-07 10:42:00 +00:00
|
|
|
setLatencySettings(settings) { }
|
|
|
|
|
|
|
|
flushBuffer() { }
|
|
|
|
abortReplay() { }
|
2020-09-07 17:07:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
resetLatencySettings() {
|
|
|
|
}
|
2020-08-10 12:41:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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-09-07 10:42:00 +00:00
|
|
|
availableVoiceClients(): 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-09-07 10:42:00 +00:00
|
|
|
async registerVoiceClient(clientId: number): Promise<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
|
|
|
|
2020-09-07 10:42:00 +00:00
|
|
|
async unregisterVoiceClient(client: VoiceClient): Promise<void> {
|
2020-08-10 12:41:34 +00:00
|
|
|
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-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
|
|
|
|
}
|
|
|
|
}
|
2020-08-10 12:41:34 +00:00
|
|
|
}
|