From 515661804a84aa9a0c3c855f9965e0e7f9348d77 Mon Sep 17 00:00:00 2001 From: Gabe Kangas Date: Wed, 22 Jul 2020 19:52:53 -0700 Subject: [PATCH] Force videojs to set cache-control header and add a random query param to each request. Closes #82 I hope. --- webroot/js/player.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/webroot/js/player.js b/webroot/js/player.js index df4d45584..35442aa83 100644 --- a/webroot/js/player.js +++ b/webroot/js/player.js @@ -17,7 +17,17 @@ class OwncastPlayer { this.handleEnded = this.handleEnded.bind(this); this.handleError = this.handleError.bind(this); } + init() { + videojs.Hls.xhr.beforeRequest = function (options) { + const cachebuster = Math.round(new Date().getTime() / 1000); + options.uri = options.uri + "?omgwtf=" + cachebuster; + options.headers = { + 'Cache-Control':'no-cache' + }; + return options; + }; + this.vjsPlayer = videojs(VIDEO_ID, VIDEO_OPTIONS); this.addAirplay(); this.vjsPlayer.ready(this.handleReady); @@ -35,9 +45,7 @@ class OwncastPlayer { // play startPlayer() { this.log('Start playing'); - const cachebuster = Math.round(new Date().getTime() / 1000); const source = { ...VIDEO_SRC } - source.src = source.src + "?okhi=" + cachebuster this.vjsPlayer.src(source); // this.vjsPlayer.play(); };