From 3d8bc807ba73b8617a863545c7d2b9ef40ea4e6a Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Wed, 6 Jan 2021 18:51:49 +0100 Subject: [PATCH] Don't start video broadcasting if the modal has been closed without pressing "start" --- .../js/ui/modal/video-source/Controller.tsx | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/shared/js/ui/modal/video-source/Controller.tsx b/shared/js/ui/modal/video-source/Controller.tsx index a91fe365..2d1973ac 100644 --- a/shared/js/ui/modal/video-source/Controller.tsx +++ b/shared/js/ui/modal/video-source/Controller.tsx @@ -22,11 +22,13 @@ export type VideoSourceModalAction = { broadcastConstraints: VideoBroadcastConfig }; +export type VideoSourceSelectResult = { source: VideoSource | undefined, config: VideoBroadcastConfig | undefined }; + /** * @param type The video type which should be prompted * @param mode */ -export async function spawnVideoSourceSelectModal(type: VideoBroadcastType, mode: VideoSourceModalAction) : Promise<{ source: VideoSource | undefined, config: VideoBroadcastConfig | undefined }> { +export async function spawnVideoSourceSelectModal(type: VideoBroadcastType, mode: VideoSourceModalAction) : Promise { const controller = new VideoSourceController(type); let defaultSelectDevice: string | true; @@ -55,8 +57,23 @@ export async function spawnVideoSourceSelectModal(type: VideoBroadcastType, mode await controller.useSettings(mode.source, mode.broadcastConstraints); } + let result: VideoSourceSelectResult = { + config: undefined, + source: undefined + }; + const modal = spawnReactModal(ModalVideoSource, controller.events, type, mode.mode === "edit"); - controller.events.on(["action_start", "action_cancel"], () => modal.destroy()); + controller.events.on(["action_start", "action_cancel"], event => { + result.source?.deref(); + if(event.type === "action_start") { + result.source = controller.getCurrentSource()?.ref(); + result.config = controller.getBroadcastConstraints(); + } else { + result.source = undefined; + result.config = undefined; + } + modal.destroy(); + }); modal.show().then(() => { if(defaultSelectDevice) { @@ -86,13 +103,8 @@ export async function spawnVideoSourceSelectModal(type: VideoBroadcastType, mode modal.events.one(["destroy", "close"], resolve); }); - const resultSource = controller.getCurrentSource()?.ref(); - const resultConstraints = controller.getBroadcastConstraints(); controller.destroy(); - return { - source: resultSource, - config: resultConstraints - }; + return result; } function updateBroadcastConfigFromSource(source: VideoSource, constraints: VideoBroadcastConfig) {