Add confirm end voice broadcast dialog (#9442)
This commit is contained in:
parent
57eec824d9
commit
a61076b4fb
3 changed files with 58 additions and 5 deletions
76
src/voice-broadcast/hooks/useVoiceBroadcastRecording.tsx
Normal file
76
src/voice-broadcast/hooks/useVoiceBroadcastRecording.tsx
Normal file
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
Copyright 2022 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import React, { useState } from "react";
|
||||
|
||||
import {
|
||||
VoiceBroadcastInfoState,
|
||||
VoiceBroadcastRecording,
|
||||
VoiceBroadcastRecordingEvent,
|
||||
VoiceBroadcastRecordingsStore,
|
||||
} from "..";
|
||||
import QuestionDialog from "../../components/views/dialogs/QuestionDialog";
|
||||
import { useTypedEventEmitter } from "../../hooks/useEventEmitter";
|
||||
import { _t } from "../../languageHandler";
|
||||
import { MatrixClientPeg } from "../../MatrixClientPeg";
|
||||
import Modal from "../../Modal";
|
||||
|
||||
const showStopBroadcastingDialog = async (): Promise<boolean> => {
|
||||
const { finished } = Modal.createDialog(
|
||||
QuestionDialog,
|
||||
{
|
||||
title: _t("Stop live broadcasting?"),
|
||||
description: (
|
||||
<p>
|
||||
{ _t("Are you sure you want to stop your live broadcast?"
|
||||
+ "This will end the broadcast and the full recording will be available in the room.") }
|
||||
</p>
|
||||
),
|
||||
button: _t("Yes, stop broadcast"),
|
||||
},
|
||||
);
|
||||
const [confirmed] = await finished;
|
||||
return confirmed;
|
||||
};
|
||||
|
||||
export const useVoiceBroadcastRecording = (recording: VoiceBroadcastRecording) => {
|
||||
const client = MatrixClientPeg.get();
|
||||
const room = client.getRoom(recording.infoEvent.getRoomId());
|
||||
const stopRecording = async () => {
|
||||
const confirmed = await showStopBroadcastingDialog();
|
||||
|
||||
if (confirmed) {
|
||||
recording.stop();
|
||||
VoiceBroadcastRecordingsStore.instance().clearCurrent();
|
||||
}
|
||||
};
|
||||
|
||||
const [live, setLive] = useState(recording.getState() === VoiceBroadcastInfoState.Started);
|
||||
useTypedEventEmitter(
|
||||
recording,
|
||||
VoiceBroadcastRecordingEvent.StateChanged,
|
||||
(state: VoiceBroadcastInfoState, _recording: VoiceBroadcastRecording) => {
|
||||
setLive(state === VoiceBroadcastInfoState.Started);
|
||||
},
|
||||
);
|
||||
|
||||
return {
|
||||
live,
|
||||
room,
|
||||
sender: recording.infoEvent.sender,
|
||||
stopRecording,
|
||||
};
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue