elm-video/index.html

126 lines
4.5 KiB
HTML
Raw Normal View History

2021-06-09 11:00:36 +02:00
<!doctype HTML>
<html>
<head>
<title>twitch.tforgione.fr</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
2021-06-09 16:30:21 +02:00
<style>
.filled {
fill: currentColor;
}
</style>
2021-06-09 11:00:36 +02:00
</head>
<body>
<div id="container"></div>
<script src="https://cdn.rawgit.com/video-dev/hls.js/18bb552/dist/hls.min.js"></script>
<script src="js/main.js"></script>
<script>
Object.defineProperty(TimeRanges.prototype, "asArray", {
get: function() {
var ret = [];
for (var i = 0; i < this.length; i++) {
ret.push({start: this.start(i), end: this.end(i)});
}
return ret;
}
});
2021-06-09 17:19:42 +02:00
Object.defineProperty(HTMLElement.prototype, "document", {
get: function() {
return document;
}
});
2021-06-09 18:59:20 +02:00
const app = Elm.Main.init({
2021-06-09 11:00:36 +02:00
node: document.getElementById('container'),
2021-06-10 15:06:58 +02:00
flags: {
url: "video/manifest.m3u8",
width: window.innerWidth,
height: window.innerHeight
}
2021-06-09 11:00:36 +02:00
});
2021-06-11 11:39:12 +02:00
let hls;
2021-06-14 12:02:55 +02:00
app.ports.polymnyVideoInit.subscribe(function(arg) {
2021-06-09 11:00:36 +02:00
const video = document.getElementById('video');
2021-06-10 09:57:09 +02:00
if (Hls.isSupported()) {
2021-06-11 11:39:12 +02:00
hls = new Hls();
2021-06-10 09:57:09 +02:00
hls.loadSource(arg);
2021-06-09 11:00:36 +02:00
2021-06-10 09:57:09 +02:00
hls.on(Hls.Events.MANIFEST_PARSED, function (event, data) {
// Transform available levels into an array of integers (height values).
const availableQualities = hls.levels.map((l) => l.height);
availableQualities.unshift(0);
2021-06-14 12:02:55 +02:00
app.ports.polymnyVideoNowHasQualities.send(availableQualities);
2021-06-10 09:57:09 +02:00
});
2021-06-09 11:00:36 +02:00
2021-06-10 09:57:09 +02:00
hls.on(Hls.Events.LEVEL_SWITCHED, function (event, data) {
2021-06-14 12:02:55 +02:00
app.ports.polymnyVideoNowHasQuality.send({
2021-06-11 11:39:12 +02:00
auto: hls.autoLevelEnabled,
height: hls.levels[data.level].height
});
2021-06-10 09:57:09 +02:00
})
2021-06-09 11:00:36 +02:00
2021-06-10 09:57:09 +02:00
hls.attachMedia(video);
} else if (video.canPlayType('application/vnd.apple.mpegurl')) {
video.src = arg;
2021-06-09 11:00:36 +02:00
}
});
2021-06-14 12:02:55 +02:00
app.ports.polymnyVideoPlayPause.subscribe(function() {
2021-06-09 11:00:36 +02:00
const video = document.getElementById('video');
if (video.paused) {
video.play();
} else {
video.pause();
}
});
2021-06-14 12:02:55 +02:00
app.ports.polymnyVideoSeek.subscribe(function(arg) {
2021-06-09 11:00:36 +02:00
const video = document.getElementById('video');
console.log(arg);
2021-06-09 11:00:36 +02:00
video.currentTime = arg;
});
2021-06-09 17:19:42 +02:00
2021-06-14 12:02:55 +02:00
app.ports.polymnyVideoRequestFullscreen.subscribe(function() {
2021-06-09 17:19:42 +02:00
document.getElementById('full').requestFullscreen();
});
2021-06-14 12:02:55 +02:00
app.ports.polymnyVideoExitFullscreen.subscribe(function() {
2021-06-09 17:19:42 +02:00
document.exitFullscreen();
});
2021-06-11 11:39:12 +02:00
2021-06-14 12:02:55 +02:00
app.ports.polymnyVideoSetPlaybackRate.subscribe(function(arg) {
2021-06-11 11:39:12 +02:00
const video = document.getElementById('video');
video.playbackRate = arg;
});
2021-06-14 12:02:55 +02:00
app.ports.polymnyVideoSetQuality.subscribe(function(arg) {
2021-06-11 11:39:12 +02:00
var old = hls.currentLevel;
if (arg.auto) {
hls.currentLevel = -1;
} else {
hls.levels.forEach((level, levelIndex) => {
if (level.height === arg.height) {
hls.currentLevel = levelIndex;
}
});
}
if (old === hls.currentLevel) {
2021-06-14 12:02:55 +02:00
app.ports.polymnyVideoNowHasQuality.send({
2021-06-11 11:39:12 +02:00
auto: hls.autoLevelEnabled,
height: hls.currentLevel === -1 ? 0 : hls.levels[hls.currentLevel].height
});
}
});
2021-06-14 12:02:55 +02:00
app.ports.polymnyVideoSetVolume.subscribe(function(arg) {
const video = document.getElementById('video');
video.volume = arg.volume;
video.muted = arg.muted;
});
2021-06-09 11:00:36 +02:00
</script>
</body>
</html>