Skip to content

Commit

Permalink
More changes
Browse files Browse the repository at this point in the history
  • Loading branch information
albertogcatalan committed Dec 16, 2020
1 parent b5225c2 commit bc72005
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 107 deletions.
Binary file added .DS_Store
Binary file not shown.
9 changes: 9 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
The MIT License

Copyright 2018 Corsair Memory, Inc

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

# Streamtools Webhook

The `Stream Deck Plugin Template` is a boilerplate template to let you get started quickly when writing a Javascript plugin for [Stream Deck](https://developer.elgato.com/documentation/stream-deck/).

`Stream Deck Plugin Template` requires Stream Deck 4.1 or later.

./DistributionTool -b -i com.streamtools.webhooks.sdPlugin -o ../Release/
Binary file added Release/.DS_Store
Binary file not shown.
Binary file not shown.
95 changes: 23 additions & 72 deletions Sources/com.streamtools.webhooks.sdPlugin/app.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,32 @@
/* global $CC, Utils, $SD */

/**
* Here are a couple of wrappers we created to help ypu quickly setup
* your plugin and subscribe to events sent by Stream Deck to your plugin.
*/

/**
* The 'connected' event is sent to your plugin, after the plugin's instance
* is registered with Stream Deck software. It carries the current websocket
* and other information about the current environmet in a JSON object
* You can use it to subscribe to events you want to use in your plugin.
*/

$SD.on('connected', (jsonObj) => connected(jsonObj));

function connected(jsn) {
/** subscribe to the willAppear and other events */
function connected(jsonObj) {
console.log(`[connected] ${JSON.stringify(jsonObj)}`);
$SD.on('com.streamtools.webhooks.action.willAppear', (jsonObj) => action.onWillAppear(jsonObj));
$SD.on('com.streamtools.webhooks.action.keyUp', (jsonObj) => action.onKeyUp(jsonObj));
$SD.on('com.streamtools.webhooks.action.sendToPlugin', (jsonObj) => action.onSendToPlugin(jsonObj));
$SD.on('com.streamtools.webhooks.action.didReceiveSettings', (jsonObj) => action.onDidReceiveSettings(jsonObj));
$SD.on('com.streamtools.webhooks.action.propertyInspectorDidAppear', (jsonObj) => {
console.log('%c%s', 'color: white; background: black; font-size: 13px;', '[app.js]propertyInspectorDidAppear:');
});
$SD.on('com.streamtools.webhooks.action.propertyInspectorDidDisappear', (jsonObj) => {
console.log('%c%s', 'color: white; background: red; font-size: 13px;', '[app.js]propertyInspectorDidDisappear:');
});
$SD.on('com.streamtools.webhooks.action.propertyInspectorDidAppear', (jsonObj) => {});
$SD.on('com.streamtools.webhooks.action.propertyInspectorDidDisappear', (jsonObj) => {});
$SD.on('com.streamtools.webhooks.action.sendToPlugin', (jsonObj) => action.onSendToPlugin(jsonObj));
};

/** ACTIONS */

const action = {
settings:{},
onDidReceiveSettings: function(jsonObj) {
onDidReceiveSettings: (jsonObj) => {
console.log(`[onDidReceiveMessage] ${JSON.stringify(jsonObj)}`);
},

/**
* The 'willAppear' event is the first event a key will receive, right before it gets
* showed on your Stream Deck and/or in Stream Deck software.
* This event is a good place to setup your plugin and look at current settings (if any),
* which are embedded in the events payload.
*/

onWillAppear: function (jsonObj) {
onWillAppear: (jsonObj) => {
console.log(`[onWillAppear] ${JSON.stringify(jsonObj)}`);
$SD.api.sendToPropertyInspector(jsonObj.context, Utils.getProp(jsonObj, "payload.settings", {}), jsonObj.action);
},

onKeyUp: function (jsonObj) {
if (!jsonObj.payload.settings || !jsonObj.payload.settings.streamtoolsapikey || !jsonObj.payload.settings.widgetid) {
onSendToPlugin: (jsonObj) => {
console.log(`[onSendToPlugin] ${JSON.stringify(jsonObj)}`);
if(jsonObj.payload) {
$SD.api.setSettings(jsonObj.context, jsonObj.payload);
}
},
onKeyUp: (jsonObj) => {
console.log(`[onKeyUp] ${JSON.stringify(jsonObj)}`);
if (!jsonObj.payload.settings || !jsonObj.payload.settings.streamtoolsapikey) {
$SD.api.showAlert(jsonObj.context);
return;
}
Expand All @@ -57,38 +35,11 @@ const action = {
"method": 'POST',
"headers": {
"content-type": "application/json",
'X-API-KEY': jsonObj.payload.settings.streamtoolsapikey
"X-API-KEY": jsonObj.payload.settings.streamtoolsapikey
},
"body": {'action': jsonObj.payload.settings.webhookpayload}
}).then(result => $SD.api.showOk(jsonObj.context), error => $SD.api.showAlert(jsonObj.context));
},

onSendToPlugin: function (jsonObj) {
/**
* this is a message sent directly from the Property Inspector
* (e.g. some value, which is not saved to settings)
* You can send this event from Property Inspector (see there for an example)
*/

if(jsonObj.payload) {
$SD.api.setSettings(jsonObj.context, jsonObj.payload);
}
},

/**
* This snippet shows, how you could save settings persistantly to Stream Deck software
* It is not used in this example plugin.
*/

saveSettings: function (jsn, sdpi_collection) {
console.log('saveSettings:', jsn);
if (sdpi_collection.hasOwnProperty('key') && sdpi_collection.key != '') {
if (sdpi_collection.value && sdpi_collection.value !== undefined) {
this.settings[sdpi_collection.key] = sdpi_collection.value;
console.log('setSettings....', this.settings);
$SD.api.setSettings(jsn.context, this.settings);
"body": {
"action": jsonObj.payload.settings.webhookpayload
}
}
},
};

}).then(result => $SD.api.showOk(jsonObj.context), error => $SD.api.showAlert(jsonObj.context));
}
};
8 changes: 3 additions & 5 deletions Sources/com.streamtools.webhooks.sdPlugin/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
"Name": "Streamtools Webhook",
"Category": "Templates",
"com.streamtools.webhooks.action": {
"Name": "Send action",
"Name": "Streamtools - Send action",
"Tooltip": "Send an action request to a Streamtools widget with remote webhook API"
},
"Localization": {
"More info": "More info",
"Message": "Message",
"Click Me": "Click Me",
"Button": "Button"
"Save": "Save",
"Action": "Action"
}
}
8 changes: 3 additions & 5 deletions Sources/com.streamtools.webhooks.sdPlugin/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
"Name": "Streamtools Webhook",
"Category": "Templates",
"com.streamtools.webhooks.action": {
"Name": "Enviar acción",
"Name": "Streamtools - Enviar acción",
"Tooltip": "Envia una solicitud de acción a un widget de Streamtools con la API"
},
"Localization": {
"More info": "Más info",
"Message": "Mensaje",
"Click Me": "Haz click",
"Button": "Botón"
"Save": "Guardar",
"Action": "Acción"
}
}
2 changes: 1 addition & 1 deletion Sources/com.streamtools.webhooks.sdPlugin/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"Name": "Streamtools Webhook",
"Icon": "action/images/action",
"URL": "https://streamtools.com",
"Version": "1.0.0",
"Version": "1.0.4",
"OS": [
{
"Platform": "mac",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
<meta name=apple-mobile-web-app-status-bar-style content=black>
<title>Streamtools Webhook</title>
<link rel="stylesheet" href="css/sdpi.css">
<script src="js/common.js"></script>
</head>
<body>
<div class="sdpi-wrapper">
<div class="sdpi-item">
<div class="sdpi-item-label">Streamtools API Key</div>
<input class="inspector sdpi-item-value" id="streamtoolsapikey" value="">
</div>
<div class="sdpi-item" id="select_single">
<div class="sdpi-item">
<div class="sdpi-item-label">Widget</div>
<select class="sdpi-item-value select inspector" id="widgettype">
<option value="timer">Timers</option>
Expand All @@ -28,14 +29,14 @@
<div class="sdpi-item-label">Widget ID</div>
<input class="inspector sdpi-item-value" id="widgetid" value="">
</div>
<div type="textarea" class="sdpi-item" id="message_only">
<div class="sdpi-item-label">Action</div>
<div type="textarea" class="sdpi-item">
<div class="sdpi-item-label" data-localize="Action">Action</div>
<select class="sdpi-item-value select inspector" id="webhookpayload">
<option value="start">Start</option>
</select>
</div>
<div class="sdpi-item">
<button class="sdpi-item-value" id="save" onclick="save()">Save</button>
<button class="sdpi-item-value" id="save" onclick="save()" data-localize="Save">Save</button>
</div>
</div>
<script>
Expand Down Expand Up @@ -71,9 +72,7 @@
}
</script>

<div class="sdpi-info-label hidden" style="top: -1000;" value=""></div>
<script src="js/common.js"></script>
<script src="js/common_pi.js"></script>
<script src="js/index_pi.js"></script>


</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -1059,27 +1059,16 @@ const SDApi = {
getGlobalSettings: function (context, payload) {
SDApi.send(context, 'getGlobalSettings', {});
},

setGlobalSettings: function (context, payload) {
SDApi.send(context, 'setGlobalSettings', {
payload: payload
});
},

logMessage: function () {
/**
* for logMessage we don't need a context, so we allow both
* logMessage(unneededContext, 'message')
* and
* logMessage('message')
*/

let payload = (arguments.length > 1) ? arguments[1] : arguments[0];

SDApi.send(null, 'logMessage', {
payload: {
message: payload
}
logMessage: function (context, payload) {
SDApi.send(context, 'logMessage', {
payload: payload
});
},

Expand Down Expand Up @@ -1197,4 +1186,4 @@ const SOCKETERRORS = {
'1': 'The connection is established and communication is possible',
'2': 'The connection is going through the closing handshake',
'3': 'The connection has been closed or could not be opened'
};
};

0 comments on commit bc72005

Please sign in to comment.