Make controls opt-in when joining a running session #6

Merged
char merged 3 commits from patch/opt-in-controls into main 2021-12-03 20:30:26 +00:00
8 changed files with 29 additions and 21 deletions

View File

@ -3,7 +3,7 @@
<head>
<meta charset="utf-8" />
<title>watch party :D</title>
<link rel="stylesheet" href="/styles.css?v=4" />
<link rel="stylesheet" href="/styles.css?v=5" />
</head>
<body>
@ -47,6 +47,6 @@
</p>
</div>
<script type="module" src="/create.mjs?v=1"></script>
<script type="module" src="/create.mjs?v=5"></script>
</body>
</html>

View File

@ -1,4 +1,4 @@
import { setupCreateSessionForm } from "./lib/create-session.mjs?v=2";
import { setupCreateSessionForm } from "./lib/create-session.mjs?v=5";
const main = () => {
setupCreateSessionForm();

View File

@ -3,7 +3,7 @@
<head>
<meta charset="utf-8" />
<title>watch party :D</title>
<link rel="stylesheet" href="/styles.css?v=4" />
<link rel="stylesheet" href="/styles.css?v=5" />
</head>
<body>
@ -52,6 +52,6 @@
</form>
</div>
<script type="module" src="/main.mjs?v=4"></script>
<script type="module" src="/main.mjs?v=5"></script>
</body>
</html>

View File

@ -1,4 +1,4 @@
import { createSession } from "./watch-session.mjs?v=4";
import { createSession } from "./watch-session.mjs?v=5";
export const setupCreateSessionForm = () => {
const form = document.querySelector("#create-session-form");

View File

@ -1,4 +1,4 @@
import { joinSession } from "./watch-session.mjs?v=4";
import { joinSession } from "./watch-session.mjs?v=5";
/**
* @param {HTMLInputElement} field

View File

@ -6,6 +6,7 @@ const createVideoElement = (videoUrl, subtitles) => {
const video = document.createElement("video");
video.controls = true;
video.autoplay = false;
video.volume = 0.5;
video.crossOrigin = "anonymous";
const source = document.createElement("source");
@ -46,15 +47,15 @@ const createVideoElement = (videoUrl, subtitles) => {
navigator.mediaSession.setActionHandler("skipad", null);
} else {
// disable media button support by ignoring the events
navigator.mediaSession.setActionHandler("play", () => {});
navigator.mediaSession.setActionHandler("pause", () => {});
navigator.mediaSession.setActionHandler("stop", () => {});
navigator.mediaSession.setActionHandler("seekbackward", () => {});
navigator.mediaSession.setActionHandler("seekforward", () => {});
navigator.mediaSession.setActionHandler("seekto", () => {});
navigator.mediaSession.setActionHandler("previoustrack", () => {});
navigator.mediaSession.setActionHandler("nexttrack", () => {});
navigator.mediaSession.setActionHandler("skipad", () => {});
navigator.mediaSession.setActionHandler("play", () => { });
navigator.mediaSession.setActionHandler("pause", () => { });
navigator.mediaSession.setActionHandler("stop", () => { });
navigator.mediaSession.setActionHandler("seekbackward", () => { });
navigator.mediaSession.setActionHandler("seekforward", () => { });
navigator.mediaSession.setActionHandler("seekto", () => { });
navigator.mediaSession.setActionHandler("previoustrack", () => { });
navigator.mediaSession.setActionHandler("nexttrack", () => { });
navigator.mediaSession.setActionHandler("skipad", () => { });
}
return;
}

View File

@ -1,5 +1,5 @@
import { setupVideo } from "./video.mjs?v=e";
import { setupChat, logEventToChat } from "./chat.mjs?v=2";
import { setupVideo } from "./video.mjs?v=5";
import { setupChat, logEventToChat } from "./chat.mjs?v=5";
/**
* @param {string} sessionId
@ -9,7 +9,7 @@ import { setupChat, logEventToChat } from "./chat.mjs?v=2";
const createWebSocket = (sessionId, nickname) => {
const wsUrl = new URL(
`/sess/${sessionId}/subscribe` +
`?nickname=${encodeURIComponent(nickname)}`,
`?nickname=${encodeURIComponent(nickname)}`,
window.location.href
);
wsUrl.protocol = { "http:": "ws:", "https:": "wss:" }[wsUrl.protocol];
@ -73,7 +73,7 @@ const setupIncomingEvents = (video, socket) => {
}
logEventToChat(event);
} catch (_err) {}
} catch (_err) { }
});
};
@ -162,6 +162,13 @@ export const joinSession = async (nickname, sessionId) => {
is_playing
);
// By default, we should disable video controls if the video is already playing.
// This solves an issue where Safari users join and seek to 00:00:00 because of
// outgoing events.
if (current_time_ms != 0) {
video.controls = false;
}
setupOutgoingEvents(video, socket);
setupIncomingEvents(video, socket);
setupChat(socket);

View File

@ -1,4 +1,4 @@
import { setupJoinSessionForm } from "./lib/join-session.mjs?v=4";
import { setupJoinSessionForm } from "./lib/join-session.mjs?v=5";
const main = () => {
setupJoinSessionForm();