From b3c56c22d5cb578016f73f0e54df3cea1962c3fd Mon Sep 17 00:00:00 2001 From: Gagan Suie Date: Mon, 30 Oct 2023 02:04:37 -0500 Subject: [PATCH] Fix: restreaming issues --- .../Channel/Chat/DrawerRestream.svelte | 239 +++++++++--------- .../Channel/Stream/StreamControls.svelte | 19 +- src/lib/utils.ts | 23 +- 3 files changed, 141 insertions(+), 140 deletions(-) diff --git a/src/lib/components/Channel/Chat/DrawerRestream.svelte b/src/lib/components/Channel/Chat/DrawerRestream.svelte index 6b41e8f0..7c9ac054 100644 --- a/src/lib/components/Channel/Chat/DrawerRestream.svelte +++ b/src/lib/components/Channel/Chat/DrawerRestream.svelte @@ -37,16 +37,18 @@ const remove = async () => { loading = true - await del(`/output?outputId=${selected}`, auth) + await del(`output?outputId=${selected}`, auth) await getAll() loading = false confirm_modal = false } const getAll = async () => { - loading = true - urlList = await get('outputs', auth) - loading = false + if ($page.data.user?.userId) { + loading = true + urlList = await get('outputs', auth) + loading = false + } } const confirm = (id: string) => { @@ -66,16 +68,11 @@ onMount(() => { getAll() }) - - $: cloudFareUrl = payload.url.includes('cloudflare') - $: invalidUrl = !isValidURL(payload.url) - $: disbaled = loading || - !payload.url || - !payload.streamKey || - invalidUrl || - cloudFareUrl + $: cloudflareUrl = payload.url.includes('cloudflare') + $: invalidUrl = !isValidURL(payload.url) + $: disbaled = loading || !payload.url || !payload.streamKey || invalidUrl || cloudflareUrl
@@ -98,128 +95,118 @@
- diff --git a/src/lib/components/Channel/Stream/StreamControls.svelte b/src/lib/components/Channel/Stream/StreamControls.svelte index d8edbf52..88472d60 100644 --- a/src/lib/components/Channel/Stream/StreamControls.svelte +++ b/src/lib/components/Channel/Stream/StreamControls.svelte @@ -81,6 +81,19 @@ } } + const sendOutputs = async ({ liveInputUid }: { liveInputUid: string }) => { + if ($is_feature_restream_enabled) { + return await post( + `outputs/send`, + { liveInputUid }, + { + userId: $page.data.user?.userId, + token: $page.data.user?.token + } + ) + } + } + const startObsStream = async () => { const liveInput = await createLiveInput({ channelId: `${$page.params.channelId}`, @@ -91,7 +104,7 @@ meta: { name: `${$page.params.channelId}-${$page.data.user.userId}-obs` }, - recording: { mode: 'off' } + recording: { mode: 'automatic' } } }) channel.videoItems = updateVideoItems(channel.videoItems, [liveInput]) @@ -103,6 +116,7 @@ video: liveInput } }) + await sendOutputs({ liveInputUid: liveInput.uid }) await sendFcm({ channelId: $page.params.channelId, channelTitle: channel.title, @@ -155,6 +169,7 @@ video: liveInput } }) + await sendOutputs({ liveInputUid: liveInput.uid }) await sendFcm({ channelId: $page.params.channelId, channelTitle: channel.title, @@ -207,6 +222,7 @@ video: liveInput } }) + await sendOutputs({ liveInputUid: liveInput.uid }) await sendFcm({ channelId: $page.params.channelId, channelTitle: channel.title, @@ -259,6 +275,7 @@ video: liveInput } }) + await sendOutputs({ liveInputUid: liveInput.uid }) await sendFcm({ channelId: $page.params.channelId, channelTitle: channel.title, diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 47eeb511..7732ce8c 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -340,23 +340,20 @@ export const dataURLtoFile = (dataurl: string, filename: string) => { return new File([u8arr], filename, { type: mime }) } -export const objectMonitor = (object:any) => { - return (currentState:any) => { +export const objectMonitor = (object: any) => { + return (currentState: any) => { return JSON.stringify(object) !== JSON.stringify(currentState) } } export const isValidURL = (url: string) => { - // const urlPattern = /^https?:\/\/\S+$/i - // return urlPattern.test(url) const pattern = new RegExp( - '^(https?:\\/\\/)?' + // protocol - '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name - '((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address - '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path - '(\\?[;&a-z\\d%_.~+=-]*)?' + // query string - '(\\#[-a-z\\d_]*)?$', // fragment locator + '^rtmp:\\/\\/' + // protocol + '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name + '((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address + '(\\/[-a-z\\d%_.~+]*)+' + // app name + '$', 'i' - ); - return pattern.test(url); -} \ No newline at end of file + ) + return pattern.test(url) +}