Compare commits

...

1 Commits

Author SHA1 Message Date
Christian Richter
27916b6356 make domains configurable & extend webserver
Some checks reported errors
continuous-integration/drone/pr Build was killed
Signed-off-by: Christian Richter <crichter@owncloud.com>
2022-07-19 09:01:41 +02:00
4 changed files with 28 additions and 16 deletions

3
.gitignore vendored
View File

@@ -1,3 +1,4 @@
**/*.json
node_modules
.drone.yml
.drone.yml
assets/baseurl.js

View File

@@ -4,6 +4,10 @@
type="text/javascript"
src="http://www.youtube.com/player_api"
></script>
<script
type="text/javascript"
src="baseurl.js"
></script>
<title>Weirdradio</title>
</head>
<style>
@@ -108,8 +112,7 @@
}
console.log("Connecting to socket");
socketSemaphore = true;
baseUrl = window.location.host.replace("8080", "8090");
let socket = new WebSocket("ws://" + baseUrl);
let socket = new WebSocket("ws://" + wsBaseUrl);
socket.onopen = function (e) {
clearInterval(socketConnector);
socketConnector = null;
@@ -167,8 +170,6 @@
}
function playNext() {
console.log(playlist)
console.log(playlist[0].videoId)
if (playlist[0] != null && playlist[0] != "") {
player.loadVideoById(playlist[0].videoId);
player.playVideo();
@@ -190,12 +191,5 @@
console.log(`item ${data.videoId} already exists in playlist skipping`);
}
}
//function myDebugger() {
// console.log(socketSemaphore);
// console.log(socketConnector);
// console.log("=================");
//}
//myDebugger = setInterval(myDebugger, 2000);
</script>
</html>

View File

@@ -1,6 +1,8 @@
{
"homeServerUrl": "https://matrix.your-homeserver.org",
"accessToken": "youraccesstokencanbeobtainedthroughriot",
"domain": "yourdomain.tld",
"webSocketDomain": "ws.yourdomain.tld",
"storage": "config/bot.json",
"assetDir": "assets/",
"webServerPort": "8080",

View File

@@ -20,14 +20,22 @@ const client = new MatrixClient(
new SimpleFsStorageProvider(config.storage)
);
// write javascript for baseurl
fs.writeFileSync(
config.assetDir + "/baseurl.js",
`var baseUrl = "${config.domain}";\nvar wsBaseUrl = "${config.webSocketDomain}";\n`,
function (err) {
if (err) return console.log(err);
}
);
// load assets
console.log("Reading assets...")
console.log("Reading assets...");
let assets = [];
var files = fs.readdirSync(config.assetDir);
files.forEach((name) => {
assets[name] = fs.readFileSync("assets/" + name);
});
console.log("[DONE]")
console.log("[DONE]");
// create server, this is for delivering the iframe page
const webServer = http
.createServer((req, res) => {
@@ -36,7 +44,14 @@ const webServer = http
reqFileName = "index.html";
}
if (assets[reqFileName] != undefined && assets[reqFileName] != null) {
res.writeHead(200, { "Content-Type": "text/html" });
extension = reqFileName.split(".").pop();
if (extension == "html" || extension == "html") {
res.writeHead(200, { "Content-Type": "text/html" });
} else if (extension == "js") {
res.writeHead(200, { "Content-Type": "text/javascript" });
} else {
res.writeHead(200, { "Content-TYpe": "text/plain" });
}
res.end(assets[reqFileName]);
} else {
res.writeHead(404, { "Content-Type": "text/plain" });
@@ -85,7 +100,7 @@ client.on("room.message", (roomId, event) => {
//link_matches = body.match(/https?:\/\/[^\ ]*youtu[^\ ]*/g);
var r = new RegExp(/https?:\/\/[^\ ]*youtube.com\/watch\?v=([^\ ]*)/g);
link_matches = r.exec(body);
if (link_matches && link_matches.length > 1) {
if (link_matches && link_matches.length > 1 && link_matches[0] != null) {
// get title
request(link_matches[0], function (err, _res, body) {
if (err) return console.error(err);