create stream url in js
This commit is contained in:
parent
f201d8e803
commit
dd9be53140
@ -220,9 +220,7 @@ if icecast_server is not None and stream_server is not None:
|
||||
logger.info(e)
|
||||
|
||||
template_html = None
|
||||
template_js = None
|
||||
template_embed = tornado.template.Template('<iframe src="{{ origin }}?provider={{ provider }}&render=true" width="{{ width }}" height="{{ height }}" allow="fullscreen"></iframe>')
|
||||
|
||||
script_file = None
|
||||
videojs_version = None
|
||||
font_awesome_version = None
|
||||
custom_style = None
|
||||
@ -230,7 +228,9 @@ try:
|
||||
with open("/app/index.html", "r") as f:
|
||||
template_html = tornado.template.Template(f.read().strip())
|
||||
with open("/app/script.js", "r") as f:
|
||||
template_js = tornado.template.Template(f.read().strip())
|
||||
script_raw = bytes(f.read().strip(), "utf-8")
|
||||
b64 = str(base64.b64encode(script_raw), "ascii")
|
||||
script_file = f'data:text/javascript;charset=utf-8;base64,{b64}'
|
||||
with open("/app/version/video.js.txt", "r") as f:
|
||||
videojs_version = f.read().strip()
|
||||
with open("/app/version/chromecast.txt", "r") as f:
|
||||
@ -311,7 +311,7 @@ class MainHandler(tornado.web.RequestHandler):
|
||||
self.write("Stream not found. (provider missing)")
|
||||
|
||||
async def handle_render(self, handler):
|
||||
if template_js is not None and template_html is not None:
|
||||
if script_file is not None and template_html is not None:
|
||||
meta = await handler.meta()
|
||||
title = handler.render_url
|
||||
video_creator = None
|
||||
@ -329,17 +329,11 @@ class MainHandler(tornado.web.RequestHandler):
|
||||
title = video_creator
|
||||
elif isinstance(video_title, str):
|
||||
title = video_title
|
||||
|
||||
rendered_js = template_js.generate(stream=handler.stream_url, title=title);
|
||||
b64_js = str(base64.b64encode(rendered_js), "ascii")
|
||||
script = f'data:text/javascript;charset=utf-8;base64,{b64_js}'
|
||||
data["script"] = script
|
||||
data["script"] = script_file
|
||||
data["videojs_version"] = videojs_version
|
||||
data["chromecast_version"] = chromecast_version
|
||||
data["font_awesome_version"] = font_awesome_version
|
||||
data["custom_style"] = custom_style
|
||||
data["stream_url"] = handler.stream_url
|
||||
data["render_url"] = handler.render_url
|
||||
rendered_html = template_html.generate(data=data, meta=meta)
|
||||
self.write(rendered_html)
|
||||
else:
|
||||
|
@ -1,15 +1,14 @@
|
||||
(() => {
|
||||
const setRemotePlayer = () => {
|
||||
class NewRemotePlayer extends cast.framework.RemotePlayer {
|
||||
constructor() {
|
||||
super();
|
||||
this.canControlVolume = false;
|
||||
}
|
||||
}
|
||||
cast.framework.RemotePlayer = NewRemotePlayer;
|
||||
const findUpstream = () => {
|
||||
const search = new URLSearchParams(location.search);
|
||||
search.set("render", "false");
|
||||
const url = new URL(location.origin);
|
||||
url.pathname = location.pathname;
|
||||
url.search = search.toString();
|
||||
return url.href;
|
||||
}
|
||||
|
||||
const upstream = "{{ stream }}";
|
||||
const upstream = findUpstream();
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open("HEAD", upstream, true);
|
||||
xhr.send();
|
||||
@ -21,11 +20,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
const handleLoaded = () => {
|
||||
setRemotePlayer();
|
||||
handleCount();
|
||||
}
|
||||
|
||||
const handle = () => {
|
||||
const [body] = document.getElementsByTagName("body");
|
||||
const video = document.createElement("video");
|
||||
@ -41,10 +35,6 @@
|
||||
options.techOrder = ["chromecast", "html5"];
|
||||
options.plugins = {};
|
||||
options.plugins.chromecast = {};
|
||||
options.plugins.chromecast.requestTitleFn = (src) => {
|
||||
return "{% raw title %}";
|
||||
}
|
||||
|
||||
const player = videojs(video, options);
|
||||
const source = {};
|
||||
source.type = ctype;
|
||||
@ -66,7 +56,10 @@
|
||||
player.one("play", () => {
|
||||
player.removeChild(button);
|
||||
});
|
||||
player.on("chromecastConnected", () => {
|
||||
player.volume(0.1);
|
||||
});
|
||||
}
|
||||
document.addEventListener("DOMContentLoaded", handleLoaded);
|
||||
document.addEventListener("DOMContentLoaded", handleCount);
|
||||
xhr.addEventListener("load", handleCount);
|
||||
})();
|
||||
|
Loading…
Reference in New Issue
Block a user