Don't start video broadcasting if the modal has been closed without pressing "start"

This commit is contained in:
WolverinDEV 2021-01-06 18:51:49 +01:00
parent 1a533b0101
commit 3d8bc807ba

View file

@ -22,11 +22,13 @@ export type VideoSourceModalAction = {
broadcastConstraints: VideoBroadcastConfig broadcastConstraints: VideoBroadcastConfig
}; };
export type VideoSourceSelectResult = { source: VideoSource | undefined, config: VideoBroadcastConfig | undefined };
/** /**
* @param type The video type which should be prompted * @param type The video type which should be prompted
* @param mode * @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<VideoSourceSelectResult> {
const controller = new VideoSourceController(type); const controller = new VideoSourceController(type);
let defaultSelectDevice: string | true; let defaultSelectDevice: string | true;
@ -55,8 +57,23 @@ export async function spawnVideoSourceSelectModal(type: VideoBroadcastType, mode
await controller.useSettings(mode.source, mode.broadcastConstraints); await controller.useSettings(mode.source, mode.broadcastConstraints);
} }
let result: VideoSourceSelectResult = {
config: undefined,
source: undefined
};
const modal = spawnReactModal(ModalVideoSource, controller.events, type, mode.mode === "edit"); 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(() => { modal.show().then(() => {
if(defaultSelectDevice) { if(defaultSelectDevice) {
@ -86,13 +103,8 @@ export async function spawnVideoSourceSelectModal(type: VideoBroadcastType, mode
modal.events.one(["destroy", "close"], resolve); modal.events.one(["destroy", "close"], resolve);
}); });
const resultSource = controller.getCurrentSource()?.ref();
const resultConstraints = controller.getBroadcastConstraints();
controller.destroy(); controller.destroy();
return { return result;
source: resultSource,
config: resultConstraints
};
} }
function updateBroadcastConfigFromSource(source: VideoSource, constraints: VideoBroadcastConfig) { function updateBroadcastConfigFromSource(source: VideoSource, constraints: VideoBroadcastConfig) {