make domains configurable & extend webserver
Some checks reported errors
continuous-integration/drone/pr Build was killed
Some checks reported errors
continuous-integration/drone/pr Build was killed
Signed-off-by: Christian Richter <crichter@owncloud.com>
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
**/*.json
|
**/*.json
|
||||||
node_modules
|
node_modules
|
||||||
.drone.yml
|
.drone.yml
|
||||||
|
assets/baseurl.js
|
||||||
@@ -4,6 +4,10 @@
|
|||||||
type="text/javascript"
|
type="text/javascript"
|
||||||
src="http://www.youtube.com/player_api"
|
src="http://www.youtube.com/player_api"
|
||||||
></script>
|
></script>
|
||||||
|
<script
|
||||||
|
type="text/javascript"
|
||||||
|
src="baseurl.js"
|
||||||
|
></script>
|
||||||
<title>Weirdradio</title>
|
<title>Weirdradio</title>
|
||||||
</head>
|
</head>
|
||||||
<style>
|
<style>
|
||||||
@@ -108,8 +112,7 @@
|
|||||||
}
|
}
|
||||||
console.log("Connecting to socket");
|
console.log("Connecting to socket");
|
||||||
socketSemaphore = true;
|
socketSemaphore = true;
|
||||||
baseUrl = window.location.host.replace("8080", "8090");
|
let socket = new WebSocket("ws://" + wsBaseUrl);
|
||||||
let socket = new WebSocket("ws://" + baseUrl);
|
|
||||||
socket.onopen = function (e) {
|
socket.onopen = function (e) {
|
||||||
clearInterval(socketConnector);
|
clearInterval(socketConnector);
|
||||||
socketConnector = null;
|
socketConnector = null;
|
||||||
@@ -167,8 +170,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function playNext() {
|
function playNext() {
|
||||||
console.log(playlist)
|
|
||||||
console.log(playlist[0].videoId)
|
|
||||||
if (playlist[0] != null && playlist[0] != "") {
|
if (playlist[0] != null && playlist[0] != "") {
|
||||||
player.loadVideoById(playlist[0].videoId);
|
player.loadVideoById(playlist[0].videoId);
|
||||||
player.playVideo();
|
player.playVideo();
|
||||||
@@ -190,12 +191,5 @@
|
|||||||
console.log(`item ${data.videoId} already exists in playlist skipping`);
|
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>
|
</script>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
{
|
{
|
||||||
"homeServerUrl": "https://matrix.your-homeserver.org",
|
"homeServerUrl": "https://matrix.your-homeserver.org",
|
||||||
"accessToken": "youraccesstokencanbeobtainedthroughriot",
|
"accessToken": "youraccesstokencanbeobtainedthroughriot",
|
||||||
|
"domain": "yourdomain.tld",
|
||||||
|
"webSocketDomain": "ws.yourdomain.tld",
|
||||||
"storage": "config/bot.json",
|
"storage": "config/bot.json",
|
||||||
"assetDir": "assets/",
|
"assetDir": "assets/",
|
||||||
"webServerPort": "8080",
|
"webServerPort": "8080",
|
||||||
|
|||||||
@@ -20,14 +20,22 @@ const client = new MatrixClient(
|
|||||||
new SimpleFsStorageProvider(config.storage)
|
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
|
// load assets
|
||||||
console.log("Reading assets...")
|
console.log("Reading assets...");
|
||||||
let assets = [];
|
let assets = [];
|
||||||
var files = fs.readdirSync(config.assetDir);
|
var files = fs.readdirSync(config.assetDir);
|
||||||
files.forEach((name) => {
|
files.forEach((name) => {
|
||||||
assets[name] = fs.readFileSync("assets/" + name);
|
assets[name] = fs.readFileSync("assets/" + name);
|
||||||
});
|
});
|
||||||
console.log("[DONE]")
|
console.log("[DONE]");
|
||||||
// create server, this is for delivering the iframe page
|
// create server, this is for delivering the iframe page
|
||||||
const webServer = http
|
const webServer = http
|
||||||
.createServer((req, res) => {
|
.createServer((req, res) => {
|
||||||
@@ -36,7 +44,14 @@ const webServer = http
|
|||||||
reqFileName = "index.html";
|
reqFileName = "index.html";
|
||||||
}
|
}
|
||||||
if (assets[reqFileName] != undefined && assets[reqFileName] != null) {
|
if (assets[reqFileName] != undefined && assets[reqFileName] != null) {
|
||||||
|
extension = reqFileName.split(".").pop();
|
||||||
|
if (extension == "html" || extension == "html") {
|
||||||
res.writeHead(200, { "Content-Type": "text/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]);
|
res.end(assets[reqFileName]);
|
||||||
} else {
|
} else {
|
||||||
res.writeHead(404, { "Content-Type": "text/plain" });
|
res.writeHead(404, { "Content-Type": "text/plain" });
|
||||||
@@ -85,7 +100,7 @@ client.on("room.message", (roomId, event) => {
|
|||||||
//link_matches = body.match(/https?:\/\/[^\ ]*youtu[^\ ]*/g);
|
//link_matches = body.match(/https?:\/\/[^\ ]*youtu[^\ ]*/g);
|
||||||
var r = new RegExp(/https?:\/\/[^\ ]*youtube.com\/watch\?v=([^\ ]*)/g);
|
var r = new RegExp(/https?:\/\/[^\ ]*youtube.com\/watch\?v=([^\ ]*)/g);
|
||||||
link_matches = r.exec(body);
|
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
|
// get title
|
||||||
request(link_matches[0], function (err, _res, body) {
|
request(link_matches[0], function (err, _res, body) {
|
||||||
if (err) return console.error(err);
|
if (err) return console.error(err);
|
||||||
|
|||||||
Reference in New Issue
Block a user