UNPKG

matrix-react-sdk

Version:
109 lines (108 loc) 3.91 kB
import { MatrixClient, MatrixEvent, TypedEventEmitter } from "matrix-js-sdk/src/matrix"; import { SimpleObservable } from "matrix-widget-api"; import { PlaybackInterface, PlaybackState } from "../../audio/Playback"; import { IDestroyable } from "../../utils/IDestroyable"; import { VoiceBroadcastLiveness, VoiceBroadcastInfoState, VoiceBroadcastRecordingsStore } from ".."; export declare enum VoiceBroadcastPlaybackState { Paused = "pause", Playing = "playing", Stopped = "stopped", Buffering = "buffering", Error = "error" } export declare enum VoiceBroadcastPlaybackEvent { TimesChanged = "times_changed", LivenessChanged = "liveness_changed", StateChanged = "state_changed", InfoStateChanged = "info_state_changed" } export type VoiceBroadcastPlaybackTimes = { duration: number; position: number; timeLeft: number; }; interface EventMap { [VoiceBroadcastPlaybackEvent.TimesChanged]: (times: VoiceBroadcastPlaybackTimes) => void; [VoiceBroadcastPlaybackEvent.LivenessChanged]: (liveness: VoiceBroadcastLiveness) => void; [VoiceBroadcastPlaybackEvent.StateChanged]: (state: VoiceBroadcastPlaybackState, playback: VoiceBroadcastPlayback) => void; [VoiceBroadcastPlaybackEvent.InfoStateChanged]: (state: VoiceBroadcastInfoState) => void; } export declare class VoiceBroadcastPlayback extends TypedEventEmitter<VoiceBroadcastPlaybackEvent, EventMap> implements IDestroyable, PlaybackInterface { readonly infoEvent: MatrixEvent; private client; private recordings; private state; private chunkEvents; /** @var Map: event Id → undecryptable event */ private utdChunkEvents; private playbacks; private currentlyPlaying; /** @var total duration of all chunks in milliseconds */ private duration; /** @var current playback position in milliseconds */ private position; readonly liveData: SimpleObservable<number[]>; private liveness; private infoState; private lastInfoEvent; private chunkRelationHelper; private infoRelationHelper; private skipToNext?; private skipToDeferred?; constructor(infoEvent: MatrixEvent, client: MatrixClient, recordings: VoiceBroadcastRecordingsStore); private setUpRelationsHelper; private addChunkEvent; private onChunkEventDecryptionFailure; private onChunkEventDecrypted; private startOrPlayNext; private addInfoEvent; private onBeforeRedaction; private tryLoadPlayback; private loadPlayback; private unloadPlayback; private onPlaybackPositionUpdate; private setDuration; private setPosition; private emitTimesChanged; private onPlaybackStateChange; private playNext; /** * @returns {number} The last chunk sequence from the latest info event. * Falls back to the length of received chunks if the info event does not provide the number. */ private get lastChunkSequence(); private playEvent; private tryGetOrLoadPlaybackForEvent; private getOrLoadPlaybackForEvent; private getCurrentPlayback; getLiveness(): VoiceBroadcastLiveness; private setLiveness; get currentState(): PlaybackState; get timeSeconds(): number; get durationSeconds(): number; get timeLeftSeconds(): number; skipTo(timeSeconds: number): Promise<void>; private doSkipTo; start(): Promise<void>; stop(): void; pause(): void; resume(): void; /** * Toggles the playback: * stopped → playing * playing → paused * paused → playing */ toggle(): Promise<void>; getState(): VoiceBroadcastPlaybackState; private setState; /** * Set error state. Stop current playback, if any. */ private setError; getInfoState(): VoiceBroadcastInfoState; private setInfoState; get errorMessage(): string; destroy(): void; } export {};