Extract useVoiceBroadcastRecording hook (#9406)
* Extract useVoiceBroadcastRecording hook * Trigger CI
This commit is contained in:
parent
1800cb8c71
commit
7a1c47a23e
9 changed files with 192 additions and 185 deletions
|
@ -14,42 +14,20 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import React, { useState } from "react";
|
||||
import React from "react";
|
||||
|
||||
import {
|
||||
VoiceBroadcastInfoState,
|
||||
VoiceBroadcastRecordingBody,
|
||||
VoiceBroadcastRecordingsStore,
|
||||
VoiceBroadcastRecording,
|
||||
VoiceBroadcastRecordingEvent,
|
||||
} from "..";
|
||||
import { IBodyProps } from "../../components/views/messages/IBodyProps";
|
||||
import { MatrixClientPeg } from "../../MatrixClientPeg";
|
||||
import { useTypedEventEmitter } from "../../hooks/useEventEmitter";
|
||||
|
||||
export const VoiceBroadcastBody: React.FC<IBodyProps> = ({ mxEvent }) => {
|
||||
const client = MatrixClientPeg.get();
|
||||
const room = client.getRoom(mxEvent.getRoomId());
|
||||
const recording = VoiceBroadcastRecordingsStore.instance().getByInfoEvent(mxEvent, client);
|
||||
const [recordingState, setRecordingState] = useState(recording.getState());
|
||||
|
||||
useTypedEventEmitter(
|
||||
recording,
|
||||
VoiceBroadcastRecordingEvent.StateChanged,
|
||||
(state: VoiceBroadcastInfoState, _recording: VoiceBroadcastRecording) => {
|
||||
setRecordingState(state);
|
||||
},
|
||||
);
|
||||
|
||||
const stopVoiceBroadcast = () => {
|
||||
if (recordingState !== VoiceBroadcastInfoState.Started) return;
|
||||
recording.stop();
|
||||
};
|
||||
|
||||
return <VoiceBroadcastRecordingBody
|
||||
onClick={stopVoiceBroadcast}
|
||||
live={recordingState === VoiceBroadcastInfoState.Started}
|
||||
sender={mxEvent.sender}
|
||||
roomName={room.name}
|
||||
recording={recording}
|
||||
/>;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue