Skip to content

Commit

Permalink
Sync default backgound video across roommates
Browse files Browse the repository at this point in the history
  • Loading branch information
ed-asriyan committed Feb 4, 2025
1 parent 613e3bb commit f23ce84
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
19 changes: 14 additions & 5 deletions src/components/video-player/index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@
clearInterval(watchMinuteAnalyticsTimeInterval);
});
const getRandomDefaultVideo = function (): string {
return defaultVideos[Math.floor(Math.random() * defaultVideos.length)];
};
let urlUpdatedAt = $derived(room?.url?.updatedAt);
let defaultVideo = $derived(defaultVideos[Math.round($urlUpdatedAt % defaultVideos.length)]);
let currentVideoTime = 0;
let saveCurrentTime = true;
Expand Down Expand Up @@ -141,8 +140,18 @@
{/if}
{/await}
{:else}
{#if defaultVideos}
<VideoPlayerVidstack source={normalizeSource(getRandomDefaultVideo())} muted={true}/>
{#if defaultVideo}
<VideoPlayerVidstack
source={normalizeSource(defaultVideo)}
bind:paused={$paused}
bind:currentTime={$currentTime}
bind:muted={muted}
on:seeked={onSeeked}
on:seeking={onSeeking}
on:pause={onPause}
on:play={onPlay}
on:timeupdate={onTimeUpdate}
/>
{/if}
{/if}
{/if}
Expand Down
2 changes: 1 addition & 1 deletion src/stores/room/bound-timed-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class BoundTimedStore<T> implements Writable<T> {
readonly updatedAt: Readable<number>;

constructor (ref: DatabaseReference, defaultValue: T, tolerance: number = 0) {
const defauleRaw = { value: defaultValue, updatedAt: 0 };
const defauleRaw = { value: defaultValue, updatedAt: now() };
this.remote = new BoundStore(ref, defauleRaw);
this.store = writable<TimedValue<T>>(defauleRaw, set => {
return this.remote.subscribe(newValue => {
Expand Down

0 comments on commit f23ce84

Please sign in to comment.