add castjs
This commit is contained in:
parent
8464733984
commit
af8f273e66
@ -2,6 +2,7 @@
|
||||
<head>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/video.js/{{ videojs_version }}/video-js.css">
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/video.js/{{ videojs_version }}/video.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/castjs/{{ castjs_version }}/cast.min.js"></script>
|
||||
<script src="{{ script }}"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
11
script.js
11
script.js
@ -1,9 +1,18 @@
|
||||
let url = new URL("{{ stream }}", window.location.origin);
|
||||
let upstream = url.href;
|
||||
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
let bodies = document.getElementsByTagName("body");
|
||||
if(bodies.length === 1) {
|
||||
let body = bodies[0];
|
||||
let cast = document.createElement("button");
|
||||
let cjs = new Castjs();
|
||||
cast.addEventListener("click", () => {
|
||||
if(cjs.available) {
|
||||
cjs.cast(upstream);
|
||||
}
|
||||
}
|
||||
let xhr = new XMLHttpRequest();
|
||||
let upstream = "{{ stream }}";
|
||||
xhr.addEventListener("load", () => {
|
||||
let video = document.createElement("video");
|
||||
video.className = "video-js";
|
||||
|
11
sources.py
11
sources.py
@ -32,8 +32,15 @@ if playlist is not None:
|
||||
|
||||
with open("/app/sources.json", "w+") as f:
|
||||
f.write(json.dumps(playlist))
|
||||
|
||||
videojs_version = None
|
||||
try:
|
||||
resp = requests.get("https://api.cdnjs.com/libraries/castjs?fields=version")
|
||||
data = json.loads(resp.text)
|
||||
castjs_version = data["version"]
|
||||
except Exception as e:
|
||||
print(e)
|
||||
else:
|
||||
with open("/app/castjs-version.txt", "w") as f:
|
||||
f.write(castjs_version)
|
||||
try:
|
||||
resp = requests.get("https://api.cdnjs.com/libraries/video.js?fields=version")
|
||||
data = json.loads(resp.text)
|
||||
|
@ -66,6 +66,7 @@ if icecast_server is not None and stream_server is not None:
|
||||
template_html = None
|
||||
template_js = None
|
||||
videojs_version = None
|
||||
castjs_version = None
|
||||
try:
|
||||
with open("/app/index.html", "r") as f:
|
||||
template_html = tornado.template.Template(f.read().strip())
|
||||
@ -73,6 +74,8 @@ try:
|
||||
template_js = tornado.template.Template(f.read().strip())
|
||||
with open("/app/videojs-version.txt", "r") as f:
|
||||
videojs_version = f.read().strip()
|
||||
with open("/app/castjs-version.txt", "r") as f:
|
||||
castjs_version = f.read().strip()
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
@ -160,7 +163,7 @@ class MainHandler(tornado.web.RequestHandler):
|
||||
rendered_js = template_js.generate(stream=stream_path);
|
||||
b64 = str(base64.b64encode(rendered_js), "ascii")
|
||||
script = f'data:text/javascript;charset=utf8;base64,{b64}'
|
||||
rendered_html = template_html.generate(script=script, videojs_version=videojs_version)
|
||||
rendered_html = template_html.generate(script=script, videojs_version=videojs_version, castjs_version=castjs_version)
|
||||
self.write(rendered_html)
|
||||
else:
|
||||
self.set_status(404)
|
||||
|
Loading…
x
Reference in New Issue
Block a user