Skip to content

Instantly share code, notes, and snippets.

@pcnoic
Created April 14, 2021 19:43
Show Gist options
  • Save pcnoic/222340cd8a4b151e53ff599bc5570055 to your computer and use it in GitHub Desktop.
Save pcnoic/222340cd8a4b151e53ff599bc5570055 to your computer and use it in GitHub Desktop.
refresh jsmpeg player after 60 seconds to minimize stream latency
<!DOCTYPE html>
<html>
<head>
<title>CAM1 - Peristera's Shipwreck - Alonissos Greece</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style type="text/css">
html, body {
background-color: #111;
text-align: center;
}
</style>
</head>
<body>
<script type="text/javascript" src="jsmpeg.min.js"></script>
<script type="text/javascript">
document.body.onload = addVideoCanvas;
function addVideoCanvas () {
// get the parent body element
const parentBody = document.getElementsByTagName("body")[0];
// create new video canvas element
const newCanvas = document.createElement("canvas");
newCanvas.setAttribute("id", "video-canvas");
// add the canvas element to body
parentBody.appendChild(newCanvas);
// get video-canvas element for jsmplayer
var canvas = document.getElementById("video-canvas");
var url = 'ws://'+document.location.hostname+':9081/';
var player = new JSMpeg.Player(url, {canvas: canvas});
setInterval( refreshVideo(player) , 60000);
}
function refreshVideo (p) {
arguments[0].updateForStreaming();
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment