Redirect sync watchers if video started

This commit is contained in:
WardPearce
2024-04-06 18:09:13 +13:00
parent d0c8c02a91
commit 4909dbea10
2 changed files with 23 additions and 1 deletions
+19 -1
View File
@@ -1,6 +1,6 @@
<script lang="ts">
import { goto } from '$app/navigation';
import { navigating } from '$app/stores';
import { navigating, page } from '$app/stores';
import { getFeed } from '$lib/Api/index';
import Logo from '$lib/Logo.svelte';
import PageLoading from '$lib/PageLoading.svelte';
@@ -136,6 +136,19 @@
if ($syncPartyPeer) {
$syncPartyPeer.on('connection', (conn) => {
conn.on('open', () => {
if ($page.url.pathname.startsWith('/watch')) {
const paths = $page.url.pathname.split('/');
if (paths.length > 2) {
conn.send({
events: [
{
type: 'change-video',
videoId: paths[2]
}
]
} as PlayerEvents);
}
}
changeVideoEvent(conn);
syncPartyConnections.set([...($syncPartyConnections || []), conn]);
});
@@ -241,6 +254,11 @@
changeVideoEvent(conn);
});
$syncPartyPeer.on('disconnected', () => {
syncPartyPeer.set(null);
syncPartyConnections.set(null);
});
}
});
@@ -41,6 +41,10 @@
let player: MediaPlayerElement;
function playerSyncEvents(conn: DataConnection) {
conn.send({
events: [{ type: 'seek', time: player.currentTime }]
} as PlayerEvents);
conn.on('data', (data) => {
const events = data as PlayerEvents;