Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
Update to support new events for when actions are updated/added/removed
Browse files Browse the repository at this point in the history
  • Loading branch information
nate1280 committed Aug 18, 2021
1 parent 6dc4b19 commit f8e8850
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 10 deletions.
34 changes: 29 additions & 5 deletions nate1280.streamerbot.sdPlugin/js/action-pi.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,25 @@ let currentAction

function connectElgatoStreamDeckSocket(port, uuid, registerEvent, info, action) {
data = JSON.parse(action)
currentAction = data.payload.settings.action

if (typeof data.payload.settings.action === 'string' || data.payload.settings.action instanceof String)
{
currentAction = { id: action, name: "Unknown"}
}
else if (data.payload.settings.action === undefined)
{
currentAction = { id: "", name: ""}
}
else
{
currentAction = { id: data.payload.settings.action.id, name: data.payload.settings.action.name}
}

_currentPlugin = {
action: data.action,
context: uuid
}

StreamDeck.debug = true
StreamDeck._ws = new WebSocket("ws://localhost:" + port)
StreamDeck._ws.onopen = () => {
Expand Down Expand Up @@ -53,11 +67,11 @@ function updateGlobalSettings() {

function updateActionsUI() {
document.getElementById('actions').innerText = ''
createAction('')
//createAction('')
sbActions.forEach((action) => {
createAction(action)
})
document.getElementById('actions').value = currentAction
document.getElementById('actions').value = currentAction.id
}

function createAction(action) {
Expand All @@ -68,10 +82,20 @@ function createAction(action) {
}

function updateSettings() {
let actionId = document.getElementById('actions').value;
let action = getAction(actionId);
StreamDeck.setSettings(_currentPlugin.context, {
action: document.getElementById('actions').value
action: { id: action.id, name: action.name }
})
currentAction = document.getElementById('actions').value
currentAction = { id: action.id, name: action.name }
}

function getAction(action){
for (var i = 0; i < sbActions.length; i++) {
if (sbActions[i].id == action) {
return sbActions[i];
}
}
}

document.getElementById('host').onchange = updateGlobalSettings
Expand Down
7 changes: 4 additions & 3 deletions nate1280.streamerbot.sdPlugin/js/buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ class Button {
}
}

hasAction(action){
hasAction(action) {
var id = (typeof action === 'string' || action instanceof String) ? action : action.id;
for (var i = 0; i < SB.actions.length; i++) {
if (SB.actions[i].id == action) {
if (SB.actions[i].id == id) {
return true;
}
}
Expand All @@ -41,7 +42,7 @@ class Button {
}

_updateTitle() {
StreamDeck.setTitle(this.context, this[this.type], StreamDeck.BOTH)
StreamDeck.setTitle(this.context, this[this.type].name, StreamDeck.BOTH)
}

setOnline() {
Expand Down
4 changes: 4 additions & 0 deletions nate1280.streamerbot.sdPlugin/js/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ sb.on('ConnectionClosed', () => {
setButtonsOffline()
})

sb.on('ActionAdded', sbUpdateActions)
sb.on('ActionUpdated', sbUpdateActions)
sb.on('ActionDeleted', sbUpdateActions)

sb.on('Exiting', () => {
sb.disconnect()
console.log('Streamer.bot Disconnecting')
Expand Down
21 changes: 20 additions & 1 deletion nate1280.streamerbot.sdPlugin/js/sb-websocket.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion nate1280.streamerbot.sdPlugin/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"Description": "Interface to run Streamer.bot actions from your StreamDeck!",
"Author": "nate1280",
"URL": "https://github.com/nate1280/streamdeck-Streamer.bot",
"Version": "0.1.0",
"Version": "0.2.0",
"Icon": "icons/icon",
"CodePath": "plugin.html",

Expand Down

0 comments on commit f8e8850

Please sign in to comment.