···1-/*!
2- * Personal website of Sefa Eyeoglu
3- * Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
4- *
5- * This program is free software: you can redistribute it and/or modify
6- * it under the terms of the GNU Affero General Public License as published by
7- * the Free Software Foundation, either version 3 of the License, or
8- * (at your option) any later version.
9- *
10- * This program is distributed in the hope that it will be useful,
11- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13- * GNU Affero General Public License for more details.
14- *
15- * You should have received a copy of the GNU Affero General Public License
16- * along with this program. If not, see <https://www.gnu.org/licenses/>.
17- */
18-19-import Hls from "hls.js";
20-21-window.Hls = Hls;
22-23-import OvenPlayer from "ovenplayer";
24-import ready from "./_utils";
25-import base64url from "base64url";
26-27-const streamUrlElem = document.getElementById("stream-url");
28-const maximizeButtonElem = document.getElementById("maximizeButton");
29-30-let refreshTimeout;
31-let player;
32-33-function isWebSocketURL(string) {
34- let url;
35- try {
36- url = new URL(string);
37- } catch {
38- return false;
39- }
40-41- return url.protocol === "ws:" || url.protocol === "wss:";
42-}
43-44-function playStream(streamId) {
45- const webrtcUrl = new URL(streamId, "wss://live.scrumplex.net");
46- webrtcUrl.protocol = "wss";
47-48- const hlsUrl = new URL(
49- streamId + "/llhls.m3u8",
50- "https://live.scrumplex.net",
51- );
52- hlsUrl.protocol = "https";
53-54- const thumbUrl = new URL(
55- streamId + "/thumb.png",
56- "https://live.scrumplex.net",
57- );
58- thumbUrl.protocol = "https";
59-60- location.replace(`#${base64url.encode(streamId)}`);
61- streamUrlElem.value = streamId;
62- let options = {
63- image: thumbUrl,
64- autoFallback: false,
65- sources: [
66- {
67- label: "Low Latency WebRTC",
68- type: "webrtc",
69- file: webrtcUrl,
70- },
71- {
72- label: '"Low Latency" HLS',
73- type: "hls",
74- file: hlsUrl,
75- },
76- ],
77- };
78-79- if (!player) {
80- player = OvenPlayer.create("ovenplayer", options);
81- } else {
82- player.load(options);
83- }
84-}
85-86-streamUrlElem.addEventListener("keyup", () => {
87- clearTimeout(refreshTimeout);
88- refreshTimeout = setTimeout(() => {
89- playStream(streamUrlElem.value);
90- }, 1000);
91-});
92-93-maximizeButtonElem.addEventListener("click", () => {
94- document.body.classList.toggle("theater");
95-});
96-97-ready().then(() => {
98- OvenPlayer.debug(true);
99- const hash = document.location.hash.substring(1);
100- const decoded = base64url.decode(hash);
101- if (isWebSocketURL(decoded)) streamUrlElem.value = decoded;
102- playStream(decoded);
103-});
···1-include include/link
2-doctype html
3-html(lang="en")
4- head
5- meta(charset="utf-8")
6- title Scrumplex · Livestream
7- link(rel="stylesheet", href="scss/application.scss")
8- include include/head
9- meta(name="page-topic" content="Scrumplex")
10- meta(name="robots" content="noindex")
11- body.scroll
12- include include/noscript
13-14- div.container.wrapper#wrapper
15- div.sheet.sheet-splash.wavy#main
16- div.row: div.col
17- h1 WebRTC Live Stream Player
18- p.
19- Paste a WebSocket URL below, to watch a livestream.
20- If you want to setup your own live stream, then take a look at #[+link(true, false)(href="https://airensoft.gitbook.io/ovenmediaengine/") OvenMediaEngine].
21- #[br]
22- If you want to share your stream with others, then just share the URL of this page.
23-24- div.row: div.col.flex.flex-align-center
25- label(for="stream-url") Stream URL
26- input.flex-grow(type="url", id="stream-url", name="stream-url")
27- div.row: div.col
28- div#ovenplayer
29- button.btn.btn-primary#maximizeButton Toggle Theater Mode
30-31- script(type="module", src="js/stream.js")