From a3de8076f42b6adde512982e5396380446a8b340 Mon Sep 17 00:00:00 2001 From: Ed Asriyan Date: Wed, 10 Apr 2024 16:49:36 +0400 Subject: [PATCH] Add streaming support --- .env | 6 + Dockerfile | 4 +- src/App.svelte | 3 +- src/analytics.svelte | 2 - src/components/1-video-selector.svelte | 163 ++++++++---------- src/components/index.svelte | 2 + src/components/room.svelte | 5 +- src/components/video-player/index.svelte | 66 +++---- .../video-player/player-magnet.svelte | 32 ++++ .../video-player/video-player-native.svelte | 4 +- src/components/video-selector-btn.svelte | 32 +++- src/destructable.ts | 4 +- src/i18n/_.ts | 16 +- src/i18n/fr.ts | 16 +- src/i18n/ru.ts | 16 +- src/main.ts | 25 ++- src/normalize-link.ts | 21 ++- src/settings.ts | 16 +- src/stores/blob.ts | 3 + src/stores/bound-minutes-watched.ts | 13 +- src/stores/bound-timed-store.ts | 8 +- src/stores/room.ts | 30 +--- src/web-torrent.ts | 95 ++++++++++ static/sw.min.js | 1 + vite.config.ts | 1 + 25 files changed, 364 insertions(+), 220 deletions(-) create mode 100644 src/components/video-player/player-magnet.svelte create mode 100644 src/stores/blob.ts create mode 100644 src/web-torrent.ts create mode 100644 static/sw.min.js diff --git a/.env b/.env index 75f3615..16f316d 100644 --- a/.env +++ b/.env @@ -10,6 +10,9 @@ VITE_FIREBASE_MEASUREMENT_ID= # base URL where the website is hosted (e.g. https://watchtogether.online) VITE_URL= +# list of ICE servers for webrtc +VITE_ICE_SERVERS= + # usernames separated by comma to be randomly picked for users VITE_USERNAMES=🐵,🐒,🦍,🦧,🐶,🐕,🦮,🐕‍🦺,🐩,🐺,🦊,🦝,🐱,🐈,🐈‍⬛,🦁,🐯,🐅,🐆,🐴,🫎,🫏,🐎,🦄,🦓,🦌,🦬,🐮,🐂,🐃,🐄,🐷,🐖,🐗,🐽,🐏,🐑,🐐,🐪,🐫,🦙,🦒,🐘,🦣,🦏,🦛,🐭,🐁,🐀,🐹,🐰,🐇,🐿️,🦫,🦔,🦇,🐻,🐻‍❄️,🐨,🐼,🦥,🦦,🦨,🦘,🦡,🦃,🐔,🐓,🐣,🐤,🐥,🐦,🐧,🕊️,🦅,🦆,🦢,🦉,🦤,🪶,🦩,🦚,🦜,🪽,🐦‍⬛,🪿,🐸,🐊,🐢,🦎,🐍,🐲,🐉,🦕,🦖,🐳,🐋,🐬,🦭,🐟,🐠,🐡,🦈,🐙,🪼,🦀,🦞,🦐,🦑,🐌,🦋,🐛,🐜,🐝,🪲,🐞,🦗,🪳,🕷️,🦂,🦟,🪰,🪱,💐,🌸,🪷,🏵️,🌹,🌺,🌻,🌼,🌷,⛄,🧸,🎃,🍇,🍈,🍉,🍊,🍋,🍌,🍍,🥭,🍎,🍏,🍐,🍑,🍒,🍓,🫐,🥝,🍅,🫒 @@ -25,5 +28,8 @@ VITE_PROXIES_HLS_URL= # URL of running http proxy that proxies request to URL which provided in ?url= query parameter. better to have on dedicated server VITE_PROXIES_REGULAR_URL= +# list of urls of custom web-torrent trackers separated by comma +VITE_WEB_TORRENT_TRACKERS= + # video URL examples (URL-encoded) separated by comma VITE_URL_EXAMPLES= diff --git a/Dockerfile b/Dockerfile index 4449c2f..576ef78 100644 --- a/Dockerfile +++ b/Dockerfile @@ -31,6 +31,8 @@ ARG VITE_VITE_FIREBASE_APP_ID ARG VITE_FIREBASE_MEASUREMENT_ID ARG VITE_USERNAMES ARG VITE_URL +ARG VITE_ICE_SERVERS +ARG VITE_WEB_TORRENT_TRACKERS ARG VITE_SENTRY_DSN ARG VITE_ANALYTICS_MEASHUREMENT_ID ARG VITE_PROXIES_HLS_URL @@ -38,7 +40,7 @@ ARG VITE_PROXIES_REGULAR_URL ARG VITE_URL_EXAMPLES ARG NODE_ENV -RUN npm run build -- --mode $NODE_ENV && npm run copy-static +RUN npm run build -- --mode $NODE_ENV FROM scratch as bundle COPY --from=builder /app/dist /dist diff --git a/src/App.svelte b/src/App.svelte index 8de9dd8..5461ac0 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -4,10 +4,10 @@ import { _ } from 'svelte-i18n'; import { randomStr } from './utils'; import Analytics from './analytics.svelte'; + import LanguageSelector from './components/language-selector.svelte'; import Page from './components/index.svelte'; import { environment, isProduction } from './settings'; import './app.scss'; - import LanguageSelector from './components/language-selector.svelte'; let header; let roomId: string; @@ -59,6 +59,7 @@ · Svelte · Firebase · Vidstack + · WebTorrent · UIkit
diff --git a/src/analytics.svelte b/src/analytics.svelte index fb398c5..a079181 100644 --- a/src/analytics.svelte +++ b/src/analytics.svelte @@ -1,5 +1,4 @@ +🔗 { $_('selectVideo.link.title') }
- - { $_('or') } - + + {#if data.name === 'type'} + { data.text } + {/if} +
-{#if $isLocalMode} -
- { $_('selectVideo.file.description') } -
- -{:else} -
- - {#if data.name === 'type'} - { data.text } +
+ + {#if !$url && haveExamples} + + { $_('selectVideo.link.insertExample') } + + {/if} +
+ +{#if !($url && $link && $link.SourceType === SourceType.direct) } +
+ {#if $url} + {#if $link} + {#if $link.type == SourceType.direct} + + {#if data.name === 'u'} + { data.text } + {/if} + + + {#if data.name === 'link'} + { data.text } + {/if} + + {/if} + {:else} + { $_('selectVideo.link.hintInvalid') } {/if} - -
-
- - {#if !$url && haveExamples} - - { $_('selectVideo.link.insertExample') } - + {:else} + { $_('selectVideo.link.hintEmpty') } + + {#if data.name === 'link'} + { data.text } + {/if} + {/if}
{/if} +
+ +📂 { $_('selectVideo.file.title') } +
+ { $_('selectVideo.file.description') } +
+
- - {#if $isLocalMode} - { $_('selectVideo.file.hint') } - - {#if data.name === 'link'} - { data.text } - {/if} - - {:else} - {#if $url} - {#if $play} - {#if $play.type == SourceType.direct} - - {#if data.name === 'u'} - { data.text } - {/if} - - - {#if data.name === 'link'} - { data.text } - {/if} - - {/if} - {:else} - { $_('selectVideo.link.hintInvalid') } - {/if} - {:else} - { $_('selectVideo.link.hintEmpty') } - - {#if data.name === 'link'} - { data.text } - {/if} - - {/if} + { $_('selectVideo.file.hint') } + + {#if data.name === 'link'} + { data.text } {/if} - +