UNPKG

matrix-react-sdk

Version:
88 lines (87 loc) 3.19 kB
import { MatrixClient, MatrixEvent, TypedEventEmitter } from "matrix-js-sdk/src/matrix"; import { VoiceBroadcastInfoState } from ".."; import { IDestroyable } from "../../utils/IDestroyable"; export declare enum VoiceBroadcastRecordingEvent { StateChanged = "liveness_changed", TimeLeftChanged = "time_left_changed" } export type VoiceBroadcastRecordingState = VoiceBroadcastInfoState | "connection_error"; interface EventMap { [VoiceBroadcastRecordingEvent.StateChanged]: (state: VoiceBroadcastRecordingState) => void; [VoiceBroadcastRecordingEvent.TimeLeftChanged]: (timeLeft: number) => void; } export declare class VoiceBroadcastRecording extends TypedEventEmitter<VoiceBroadcastRecordingEvent, EventMap> implements IDestroyable { readonly infoEvent: MatrixEvent; private client; private state; private recorder; private dispatcherRef; private chunkEvents; private chunkRelationHelper; private maxLength; private timeLeft; private toRetry; private reconnectedListener; private roomId; private infoEventId; private backgroundAudio; /** * Broadcast chunks have a sequence number to bring them in the correct order and to know if a message is missing. * This variable holds the last sequence number. * Starts with 0 because there is no chunk at the beginning of a broadcast. * Will be incremented when a chunk message is created. */ private sequence; constructor(infoEvent: MatrixEvent, client: MatrixClient, initialState?: VoiceBroadcastInfoState); private initialiseChunkEventRelation; private onChunkEvent; private determineEventIdFromInfoEvent; private determineRoomIdFromInfoEvent; /** * Determines the initial broadcast state. * Checks all related events. If one has the "stopped" state → stopped, else started. */ private determineInitialStateFromInfoEvent; getTimeLeft(): number; /** * Retries failed actions on reconnect. */ private onReconnect; private setTimeLeft; start(): Promise<void>; stop(): Promise<void>; pause(): Promise<void>; resume(): Promise<void>; toggle: () => Promise<void>; getState(): VoiceBroadcastRecordingState; private getRecorder; destroy(): Promise<void>; private onBeforeRedaction; private onAction; private setState; private onCurrentChunkLengthUpdated; private onChunkRecorded; /** * This function is called on connection errors. * It sets the connection error state and stops the recorder. */ private onConnectionError; private playConnectionErrorAudioNotification; private uploadFile; private sendVoiceMessage; /** * Sends an info state event with given state. * On error stores a resend function and setState(state) in {@link toRetry} and * sets the broadcast state to connection_error. */ private sendInfoStateEvent; /** * Calls the function. * On failure adds it to the retry list and triggers connection error. * {@link toRetry} * {@link onConnectionError} */ private callWithRetry; private stopRecorder; } export {};