Generalise VoiceRecording (#9304)

This commit is contained in:
Michael Weimann
2022-09-21 18:46:28 +02:00
committed by GitHub
parent 71cf9bf932
commit c182c1c706
11 changed files with 422 additions and 103 deletions
+5 -5
View File
@@ -22,12 +22,12 @@ import { IEventRelation } from "matrix-js-sdk/src/models/event";
import { AsyncStoreWithClient } from "./AsyncStoreWithClient";
import defaultDispatcher from "../dispatcher/dispatcher";
import { ActionPayload } from "../dispatcher/payloads";
import { VoiceRecording } from "../audio/VoiceRecording";
import { createVoiceMessageRecording, VoiceMessageRecording } from "../audio/VoiceMessageRecording";
const SEPARATOR = "|";
interface IState {
[voiceRecordingId: string]: Optional<VoiceRecording>;
[voiceRecordingId: string]: Optional<VoiceMessageRecording>;
}
export class VoiceRecordingStore extends AsyncStoreWithClient<IState> {
@@ -63,7 +63,7 @@ export class VoiceRecordingStore extends AsyncStoreWithClient<IState> {
* @param {string} voiceRecordingId The room ID (with optionally the thread ID if in one) to get the recording in.
* @returns {Optional<VoiceRecording>} The recording, if any.
*/
public getActiveRecording(voiceRecordingId: string): Optional<VoiceRecording> {
public getActiveRecording(voiceRecordingId: string): Optional<VoiceMessageRecording> {
return this.state[voiceRecordingId];
}
@@ -74,12 +74,12 @@ export class VoiceRecordingStore extends AsyncStoreWithClient<IState> {
* @param {string} voiceRecordingId The room ID (with optionally the thread ID if in one) to start recording in.
* @returns {VoiceRecording} The recording.
*/
public startRecording(voiceRecordingId: string): VoiceRecording {
public startRecording(voiceRecordingId: string): VoiceMessageRecording {
if (!this.matrixClient) throw new Error("Cannot start a recording without a MatrixClient");
if (!voiceRecordingId) throw new Error("Recording must be associated with a room");
if (this.state[voiceRecordingId]) throw new Error("A recording is already in progress");
const recording = new VoiceRecording(this.matrixClient);
const recording = createVoiceMessageRecording(this.matrixClient);
// noinspection JSIgnoredPromiseFromCall - we can safely run this async
this.updateState({ ...this.state, [voiceRecordingId]: recording });