···11-/*!
22- * Personal website of Sefa Eyeoglu
33- * Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
44- *
55- * This program is free software: you can redistribute it and/or modify
66- * it under the terms of the GNU Affero General Public License as published by
77- * the Free Software Foundation, either version 3 of the License, or
88- * (at your option) any later version.
99- *
1010- * This program is distributed in the hope that it will be useful,
1111- * but WITHOUT ANY WARRANTY; without even the implied warranty of
1212- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1313- * GNU Affero General Public License for more details.
1414- *
1515- * You should have received a copy of the GNU Affero General Public License
1616- * along with this program. If not, see <https://www.gnu.org/licenses/>.
1717- */
1818-1919-import Hls from "hls.js";
2020-2121-window.Hls = Hls;
2222-2323-import OvenPlayer from "ovenplayer";
2424-import ready from "./_utils";
2525-import base64url from "base64url";
2626-2727-const streamUrlElem = document.getElementById("stream-url");
2828-const maximizeButtonElem = document.getElementById("maximizeButton");
2929-3030-let refreshTimeout;
3131-let player;
3232-3333-function isWebSocketURL(string) {
3434- let url;
3535- try {
3636- url = new URL(string);
3737- } catch {
3838- return false;
3939- }
4040-4141- return url.protocol === "ws:" || url.protocol === "wss:";
4242-}
4343-4444-function playStream(streamId) {
4545- const webrtcUrl = new URL(streamId, "wss://live.scrumplex.net");
4646- webrtcUrl.protocol = "wss";
4747-4848- const hlsUrl = new URL(
4949- streamId + "/llhls.m3u8",
5050- "https://live.scrumplex.net",
5151- );
5252- hlsUrl.protocol = "https";
5353-5454- const thumbUrl = new URL(
5555- streamId + "/thumb.png",
5656- "https://live.scrumplex.net",
5757- );
5858- thumbUrl.protocol = "https";
5959-6060- location.replace(`#${base64url.encode(streamId)}`);
6161- streamUrlElem.value = streamId;
6262- let options = {
6363- image: thumbUrl,
6464- autoFallback: false,
6565- sources: [
6666- {
6767- label: "Low Latency WebRTC",
6868- type: "webrtc",
6969- file: webrtcUrl,
7070- },
7171- {
7272- label: '"Low Latency" HLS',
7373- type: "hls",
7474- file: hlsUrl,
7575- },
7676- ],
7777- };
7878-7979- if (!player) {
8080- player = OvenPlayer.create("ovenplayer", options);
8181- } else {
8282- player.load(options);
8383- }
8484-}
8585-8686-streamUrlElem.addEventListener("keyup", () => {
8787- clearTimeout(refreshTimeout);
8888- refreshTimeout = setTimeout(() => {
8989- playStream(streamUrlElem.value);
9090- }, 1000);
9191-});
9292-9393-maximizeButtonElem.addEventListener("click", () => {
9494- document.body.classList.toggle("theater");
9595-});
9696-9797-ready().then(() => {
9898- OvenPlayer.debug(true);
9999- const hash = document.location.hash.substring(1);
100100- const decoded = base64url.decode(hash);
101101- if (isWebSocketURL(decoded)) streamUrlElem.value = decoded;
102102- playStream(decoded);
103103-});
-31
src/stream.pug
···11-include include/link
22-doctype html
33-html(lang="en")
44- head
55- meta(charset="utf-8")
66- title Scrumplex · Livestream
77- link(rel="stylesheet", href="scss/application.scss")
88- include include/head
99- meta(name="page-topic" content="Scrumplex")
1010- meta(name="robots" content="noindex")
1111- body.scroll
1212- include include/noscript
1313-1414- div.container.wrapper#wrapper
1515- div.sheet.sheet-splash.wavy#main
1616- div.row: div.col
1717- h1 WebRTC Live Stream Player
1818- p.
1919- Paste a WebSocket URL below, to watch a livestream.
2020- If you want to setup your own live stream, then take a look at #[+link(true, false)(href="https://airensoft.gitbook.io/ovenmediaengine/") OvenMediaEngine].
2121- #[br]
2222- If you want to share your stream with others, then just share the URL of this page.
2323-2424- div.row: div.col.flex.flex-align-center
2525- label(for="stream-url") Stream URL
2626- input.flex-grow(type="url", id="stream-url", name="stream-url")
2727- div.row: div.col
2828- div#ovenplayer
2929- button.btn.btn-primary#maximizeButton Toggle Theater Mode
3030-3131- script(type="module", src="js/stream.js")