Skip to content

Commit

Permalink
!redo your config, change in fileformat, also obs websocket-link is n…
Browse files Browse the repository at this point in the history
…ow optional. fixed edit song
  • Loading branch information
reaby committed Apr 16, 2020
1 parent 4e16f92 commit 0bdf544
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 17 deletions.
8 changes: 5 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ console.log("LoistoTxt starting...");
CheckDir("./data");
CheckDir("./data/songs");
CheckDir("./data/shows");
connectObs();
if (config.obs.enabled) {
connectObs();
}

// view engine setup
app.set('views', path.join(__dirname, 'views'));
Expand Down Expand Up @@ -85,8 +87,8 @@ async function connectObs() {
console.log("Connecting to local obs websocket!");

await obs.connect({
address: config.websocket.address || "127.0.0.1:4444",
password: config.websocket.password || ""
address: config.obs.websocket.address || "127.0.0.1:4444",
password: config.obs.websocket.password || ""
});
}
catch (e) {
Expand Down
15 changes: 9 additions & 6 deletions bin/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ class websocket {
}
}

this.obs = obs;
this.obs = obs || {};
this.io = io;
let self = this;


obs.on('SwitchScenes', data => {
self.serverOptions.obs.currentScene = data.sceneName;
self.serverOptions.obs.currentScene = data.sceneName;
io.emit("obs.update", self.serverOptions);
});

Expand All @@ -35,8 +35,10 @@ class websocket {
client => {
client.emit("update", self.serverOptions)
client.emit("callback.dataUpdate", self.getIndexFile());
self.getObsStatus(client);

if (config.obs.enabled) {
self.getObsStatus(client);
}

client.on("showTitles", data => {
self.serverOptions.showTitle = true;
self.serverOptions.currentText = "";
Expand All @@ -58,9 +60,9 @@ class websocket {

client.on("obs.setScene", async (scene) => {
try {
let data = await obs.send("SetCurrentScene", { 'scene-name': scene });
let data = await obs.send("SetCurrentScene", { 'scene-name': scene });
} catch (e) {
io.emit("obs.update", self.serverOptions);
io.emit("obs.update", self.serverOptions);
}
});

Expand Down Expand Up @@ -101,6 +103,7 @@ class websocket {
socket.emit("obs.scenelist", { currentScene: data.currentScene, scenes: outScenes });
} catch (e) {
console.log(e);
socket.emit("obs.scenelist", { currentScene: "", scenes: [] });
}
}

Expand Down
11 changes: 6 additions & 5 deletions config-default.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"websocket": {
"address": "127.0.0.1:4444",
"password": "admin"
},
"obs": {
"enabled": false,
"scenes": [
"Example1",
"Example2"
]
],
"websocket": {
"address": "127.0.0.1:4444",
"password": "admin"
}
}
}
4 changes: 2 additions & 2 deletions public/javascripts/editor.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
$(() => {
$.getJSON("/ajax/song/" + "{{ song }}", function (songData) {
$.getJSON("/ajax/song/" + song, function (songData) {
let output = "";
if (!Array.isArray(songData)) return;
for (var data of songData) {
output += `<div class="ui segment verse">
<div class="ui fluid labelled action input">
<label class="ui label">Osan otsikko</label>
<label class="ui label">Part title</label>
<input type="text" value="${data.title}" />
<button class="ui red inverted icon button" onclick="removeElem($(this).parent());"><i class="ui icon delete"></i>Delete part</button>
</div>
Expand Down
4 changes: 3 additions & 1 deletion routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ router.get('/ajax/song', function (req, res, next) {

router.get('/ajax/song/:uuid', function (req, res, next) {
let songData = {};
let file = './data/songs/' + req.params.uuid + ".json";
let file = './data/songs/' + req.params.uuid.toString() + ".json";
if (fs.existsSync(file)) {
songData = JSON.parse(fs.readFileSync(file).toString()) || {};
} else {
console.log("error, file not exists.");
}

res.json(songData);
Expand Down
1 change: 1 addition & 0 deletions views/editsong.twig
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io.connect();
var song = "{{ song }}";
</script>
<script src="/javascripts/editor.js"></script>
{% endblock %}

0 comments on commit 0bdf544

Please sign in to comment.