UNPKG

matrix-react-sdk

Version:
51 lines (50 loc) 1.93 kB
import { Optional } from "matrix-events-sdk"; import { TypedEventEmitter } from "matrix-js-sdk/src/matrix"; import { VoiceRecording } from "../../audio/VoiceRecording"; import { IDestroyable } from "../../utils/IDestroyable"; export declare enum VoiceBroadcastRecorderEvent { ChunkRecorded = "chunk_recorded", CurrentChunkLengthUpdated = "current_chunk_length_updated" } interface EventMap { [VoiceBroadcastRecorderEvent.ChunkRecorded]: (chunk: ChunkRecordedPayload) => void; [VoiceBroadcastRecorderEvent.CurrentChunkLengthUpdated]: (length: number) => void; } export interface ChunkRecordedPayload { buffer: Uint8Array; length: number; } /** * This class provides the function to seamlessly record fixed length chunks. * Subscribe with on(VoiceBroadcastRecordingEvents.ChunkRecorded, (payload: ChunkRecordedPayload) => {}) * to retrieve chunks while recording. */ export declare class VoiceBroadcastRecorder extends TypedEventEmitter<VoiceBroadcastRecorderEvent, EventMap> implements IDestroyable { private voiceRecording; readonly targetChunkLength: number; private opusHead?; private opusTags?; private chunkBuffer; private previousChunkEndTimePosition; private currentChunkLength; constructor(voiceRecording: VoiceRecording, targetChunkLength: number); start(): Promise<void>; /** * Stops the recording and returns the remaining chunk (if any). */ stop(): Promise<Optional<ChunkRecordedPayload>>; get contentType(): string; private setCurrentChunkLength; getCurrentChunkLength(): number; private onDataAvailable; private handleData; private emitChunkIfTargetLengthReached; /** * Extracts the current chunk and resets the buffer. */ private extractChunk; private emitAndResetChunk; destroy(): void; } export declare const createVoiceBroadcastRecorder: () => VoiceBroadcastRecorder; export {};