TeaWeb/shared/js/connection/VoiceConnection.ts

95 lines
2.8 KiB
TypeScript
Raw Normal View History

import {RecorderProfile} from "../voice/RecorderProfile";
import {AbstractServerConnection, ConnectionStatistics} from "../connection/ConnectionBase";
import {Registry} from "../events";
import {VoiceClient} from "../voice/VoiceClient";
import {WhisperSession, WhisperTarget} from "../voice/VoiceWhisper";
export enum VoiceConnectionStatus {
ClientUnsupported,
ServerUnsupported,
Connecting,
Connected,
Disconnecting,
Disconnected,
Failed
}
export interface VoiceConnectionEvents {
"notify_connection_status_changed": {
oldStatus: VoiceConnectionStatus,
newStatus: VoiceConnectionStatus
},
2020-08-26 10:33:53 +00:00
"notify_recorder_changed": {},
"notify_whisper_created": {
session: WhisperSession
},
"notify_whisper_initialized": {
session: WhisperSession
},
"notify_whisper_destroyed": {
session: WhisperSession
2020-09-24 13:51:22 +00:00
},
"notify_voice_replay_state_change": {
replaying: boolean
2020-08-26 10:33:53 +00:00
}
}
2020-08-26 10:33:53 +00:00
export type WhisperSessionInitializeData = {
clientName: string,
clientUniqueId: string,
sessionTimeout: number,
blocked: boolean,
volume: number
};
export type WhisperSessionInitializer = (session: WhisperSession) => Promise<WhisperSessionInitializeData>;
export abstract class AbstractVoiceConnection {
readonly events: Registry<VoiceConnectionEvents>;
readonly connection: AbstractServerConnection;
protected constructor(connection: AbstractServerConnection) {
this.events = new Registry<VoiceConnectionEvents>();
this.connection = connection;
}
abstract getConnectionState() : VoiceConnectionStatus;
abstract getFailedMessage() : string;
abstract getRetryTimestamp() : number | 0;
abstract getConnectionStats() : Promise<ConnectionStatistics>;
2020-08-26 10:33:53 +00:00
abstract encodingSupported(codec: number) : boolean;
abstract decodingSupported(codec: number) : boolean;
abstract registerVoiceClient(clientId: number) : VoiceClient;
2020-09-07 10:42:00 +00:00
abstract availableVoiceClients() : VoiceClient[];
abstract unregisterVoiceClient(client: VoiceClient);
2020-08-26 10:33:53 +00:00
abstract voiceRecorder() : RecorderProfile;
abstract acquireVoiceRecorder(recorder: RecorderProfile | undefined) : Promise<void>;
abstract getEncoderCodec() : number;
abstract setEncoderCodec(codec: number);
2020-09-24 13:51:22 +00:00
abstract stopAllVoiceReplays();
abstract isReplayingVoice() : boolean;
2020-08-26 10:33:53 +00:00
/* the whisper API */
abstract getWhisperSessions() : WhisperSession[];
abstract dropWhisperSession(session: WhisperSession);
2020-08-26 10:33:53 +00:00
abstract setWhisperSessionInitializer(initializer: WhisperSessionInitializer | undefined);
abstract getWhisperSessionInitializer() : WhisperSessionInitializer | undefined;
2020-09-07 10:42:00 +00:00
abstract startWhisper(target: WhisperTarget) : Promise<void>;
abstract getWhisperTarget() : WhisperTarget | undefined;
abstract stopWhisper();
}