Apply prettier formatting
This commit is contained in:
parent
1cac306093
commit
526645c791
1576 changed files with 65385 additions and 62478 deletions
|
@ -60,14 +60,15 @@ interface EventMap {
|
|||
[VoiceBroadcastPlaybackEvent.LivenessChanged]: (liveness: VoiceBroadcastLiveness) => void;
|
||||
[VoiceBroadcastPlaybackEvent.StateChanged]: (
|
||||
state: VoiceBroadcastPlaybackState,
|
||||
playback: VoiceBroadcastPlayback
|
||||
playback: VoiceBroadcastPlayback,
|
||||
) => void;
|
||||
[VoiceBroadcastPlaybackEvent.InfoStateChanged]: (state: VoiceBroadcastInfoState) => void;
|
||||
}
|
||||
|
||||
export class VoiceBroadcastPlayback
|
||||
extends TypedEventEmitter<VoiceBroadcastPlaybackEvent, EventMap>
|
||||
implements IDestroyable, PlaybackInterface {
|
||||
implements IDestroyable, PlaybackInterface
|
||||
{
|
||||
private state = VoiceBroadcastPlaybackState.Stopped;
|
||||
private chunkEvents = new VoiceBroadcastChunkEvents();
|
||||
private playbacks = new Map<string, Playback>();
|
||||
|
@ -87,10 +88,7 @@ export class VoiceBroadcastPlayback
|
|||
private chunkRelationHelper!: RelationsHelper;
|
||||
private infoRelationHelper!: RelationsHelper;
|
||||
|
||||
public constructor(
|
||||
public readonly infoEvent: MatrixEvent,
|
||||
private client: MatrixClient,
|
||||
) {
|
||||
public constructor(public readonly infoEvent: MatrixEvent, private client: MatrixClient) {
|
||||
super();
|
||||
this.addInfoEvent(this.infoEvent);
|
||||
this.infoEvent.on(MatrixEventEvent.BeforeRedaction, this.onBeforeRedaction);
|
||||
|
@ -213,13 +211,10 @@ export class VoiceBroadcastPlayback
|
|||
this.playbacks.delete(event.getId()!);
|
||||
}
|
||||
|
||||
private onPlaybackPositionUpdate = (
|
||||
event: MatrixEvent,
|
||||
position: number,
|
||||
): void => {
|
||||
private onPlaybackPositionUpdate = (event: MatrixEvent, position: number): void => {
|
||||
if (event !== this.currentlyPlaying) return;
|
||||
|
||||
const newPosition = this.chunkEvents.getLengthTo(event) + (position * 1000); // observable sends seconds
|
||||
const newPosition = this.chunkEvents.getLengthTo(event) + position * 1000; // observable sends seconds
|
||||
|
||||
// do not jump backwards - this can happen when transiting from one to another chunk
|
||||
if (newPosition < this.position) return;
|
||||
|
@ -244,14 +239,11 @@ export class VoiceBroadcastPlayback
|
|||
}
|
||||
|
||||
private emitTimesChanged(): void {
|
||||
this.emit(
|
||||
VoiceBroadcastPlaybackEvent.TimesChanged,
|
||||
{
|
||||
duration: this.durationSeconds,
|
||||
position: this.timeSeconds,
|
||||
timeLeft: this.timeLeftSeconds,
|
||||
},
|
||||
);
|
||||
this.emit(VoiceBroadcastPlaybackEvent.TimesChanged, {
|
||||
duration: this.durationSeconds,
|
||||
position: this.timeSeconds,
|
||||
timeLeft: this.timeLeftSeconds,
|
||||
});
|
||||
}
|
||||
|
||||
private onPlaybackStateChange = async (event: MatrixEvent, newState: PlaybackState): Promise<void> => {
|
||||
|
@ -408,9 +400,10 @@ export class VoiceBroadcastPlayback
|
|||
public async start(): Promise<void> {
|
||||
const chunkEvents = this.chunkEvents.getEvents();
|
||||
|
||||
const toPlay = this.getInfoState() === VoiceBroadcastInfoState.Stopped
|
||||
? chunkEvents[0] // start at the beginning for an ended voice broadcast
|
||||
: chunkEvents[chunkEvents.length - 1]; // start at the current chunk for an ongoing voice broadcast
|
||||
const toPlay =
|
||||
this.getInfoState() === VoiceBroadcastInfoState.Stopped
|
||||
? chunkEvents[0] // start at the beginning for an ended voice broadcast
|
||||
: chunkEvents[chunkEvents.length - 1]; // start at the current chunk for an ongoing voice broadcast
|
||||
|
||||
if (toPlay) {
|
||||
return this.playEvent(toPlay);
|
||||
|
@ -499,7 +492,7 @@ export class VoiceBroadcastPlayback
|
|||
this.removeAllListeners();
|
||||
|
||||
this.chunkEvents = new VoiceBroadcastChunkEvents();
|
||||
this.playbacks.forEach(p => p.destroy());
|
||||
this.playbacks.forEach((p) => p.destroy());
|
||||
this.playbacks = new Map<string, Playback>();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,12 +25,13 @@ import { startNewVoiceBroadcastRecording } from "../utils/startNewVoiceBroadcast
|
|||
type VoiceBroadcastPreRecordingEvent = "dismiss";
|
||||
|
||||
interface EventMap {
|
||||
"dismiss": (voiceBroadcastPreRecording: VoiceBroadcastPreRecording) => void;
|
||||
dismiss: (voiceBroadcastPreRecording: VoiceBroadcastPreRecording) => void;
|
||||
}
|
||||
|
||||
export class VoiceBroadcastPreRecording
|
||||
extends TypedEventEmitter<VoiceBroadcastPreRecordingEvent, EventMap>
|
||||
implements IDestroyable {
|
||||
implements IDestroyable
|
||||
{
|
||||
public constructor(
|
||||
public room: Room,
|
||||
public sender: RoomMember,
|
||||
|
@ -42,12 +43,7 @@ export class VoiceBroadcastPreRecording
|
|||
}
|
||||
|
||||
public start = async (): Promise<void> => {
|
||||
await startNewVoiceBroadcastRecording(
|
||||
this.room,
|
||||
this.client,
|
||||
this.playbacksStore,
|
||||
this.recordingsStore,
|
||||
);
|
||||
await startNewVoiceBroadcastRecording(this.room, this.client, this.playbacksStore, this.recordingsStore);
|
||||
this.emit("dismiss", this);
|
||||
};
|
||||
|
||||
|
|
|
@ -56,7 +56,8 @@ interface EventMap {
|
|||
|
||||
export class VoiceBroadcastRecording
|
||||
extends TypedEventEmitter<VoiceBroadcastRecordingEvent, EventMap>
|
||||
implements IDestroyable {
|
||||
implements IDestroyable
|
||||
{
|
||||
private state: VoiceBroadcastInfoState;
|
||||
private recorder: VoiceBroadcastRecorder;
|
||||
private sequence = 1;
|
||||
|
@ -108,8 +109,8 @@ export class VoiceBroadcastRecording
|
|||
|
||||
private onChunkEvent = (event: MatrixEvent): void => {
|
||||
if (
|
||||
(!event.getId() && !event.getTxnId())
|
||||
|| event.getContent()?.msgtype !== MsgType.Audio // don't add non-audio event
|
||||
(!event.getId() && !event.getTxnId()) ||
|
||||
event.getContent()?.msgtype !== MsgType.Audio // don't add non-audio event
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
@ -119,15 +120,19 @@ export class VoiceBroadcastRecording
|
|||
|
||||
private setInitialStateFromInfoEvent(): void {
|
||||
const room = this.client.getRoom(this.infoEvent.getRoomId());
|
||||
const relations = room?.getUnfilteredTimelineSet()?.relations?.getChildEventsForEvent(
|
||||
this.infoEvent.getId(),
|
||||
RelationType.Reference,
|
||||
VoiceBroadcastInfoEventType,
|
||||
);
|
||||
const relations = room
|
||||
?.getUnfilteredTimelineSet()
|
||||
?.relations?.getChildEventsForEvent(
|
||||
this.infoEvent.getId(),
|
||||
RelationType.Reference,
|
||||
VoiceBroadcastInfoEventType,
|
||||
);
|
||||
const relatedEvents = relations?.getRelations();
|
||||
this.state = !relatedEvents?.find((event: MatrixEvent) => {
|
||||
return event.getContent()?.state === VoiceBroadcastInfoState.Stopped;
|
||||
}) ? VoiceBroadcastInfoState.Started : VoiceBroadcastInfoState.Stopped;
|
||||
})
|
||||
? VoiceBroadcastInfoState.Started
|
||||
: VoiceBroadcastInfoState.Stopped;
|
||||
}
|
||||
|
||||
public getTimeLeft(): number {
|
||||
|
@ -244,12 +249,9 @@ export class VoiceBroadcastRecording
|
|||
return uploadFile(
|
||||
this.client,
|
||||
this.infoEvent.getRoomId(),
|
||||
new Blob(
|
||||
[chunk.buffer],
|
||||
{
|
||||
type: this.getRecorder().contentType,
|
||||
},
|
||||
),
|
||||
new Blob([chunk.buffer], {
|
||||
type: this.getRecorder().contentType,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue