Skip to content

Commit

Permalink
Final version
Browse files Browse the repository at this point in the history
  • Loading branch information
albertogcatalan committed Dec 18, 2020
1 parent 2a1bc7d commit 8ab809e
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 6 deletions.
Binary file modified Release/com.streamtools.webhooks.streamDeckPlugin
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 37 additions & 2 deletions Sources/com.streamtools.webhooks.sdPlugin/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,21 @@ const action = {
console.log(`[onSendToPlugin] ${JSON.stringify(jsonObj)}`);
if(jsonObj.payload) {
$SD.api.setSettings(jsonObj.context, jsonObj.payload);

let icon = "action@2x";
let url = "https://app.streamtools.com/Resources/App/Theme/STools/img/{icon}.png";
if (jsonObj.payload['widgettype'] == 'flipcoin') {
icon = "C11B_Coin_head";
url = "https://app.streamtools.com/Resources/App/Theme/STools/img/flipcoin/{icon}_a.png";
} else if (jsonObj.payload['widgettype'] == 'diceroller') {
icon = "C12B_Dice_1";
url = "https://app.streamtools.com/Resources/App/Theme/STools/img/diceroller/{icon}_a.png";
}
toDataURL(url.replace("{icon}", icon),
function (dataUrl) {
$SD.api.setImage(jsonObj.context, dataUrl);
}
);
}
},
onKeyUp: (jsonObj) => {
Expand All @@ -30,7 +45,7 @@ const action = {
$SD.api.showAlert(jsonObj.context);
return;
}
let url = 'http://streamtools.local.com/webhook/'+jsonObj.payload.settings.widgettype+'/'+jsonObj.payload.settings.widgetid+'/';
let url = 'https://app.streamtools.com/webhook/'+jsonObj.payload.settings.widgettype+'/'+jsonObj.payload.settings.widgetid+'/';
fetch(url, {
"method": 'POST',
"headers": {
Expand All @@ -40,4 +55,24 @@ const action = {
"body": JSON.stringify({"action": jsonObj.payload.settings.webhookpayload})
}).then(result => $SD.api.showOk(jsonObj.context), error => $SD.api.showAlert(jsonObj.context));
}
};
};

function toDataURL(src, callback, outputFormat) {
let img = new Image();
img.crossOrigin = 'Anonymous';
img.onload = function () {
let canvas = document.createElement('CANVAS');
let ctx = canvas.getContext('2d');
let dataURL;
canvas.height = this.naturalHeight;
canvas.width = this.naturalWidth;
ctx.drawImage(this, 0, 0);
dataURL = canvas.toDataURL(outputFormat);
callback(dataURL);
};
img.src = src;
if (img.complete || img.complete === undefined) {
img.src = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";
img.src = src;
}
}
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.13",
"Version": "1.0.28",
"OS": [
{
"Platform": "mac",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
settings = Utils.getProp(jsonObj, 'actionInfo.payload.settings', {});
document.getElementById("streamtoolsapikey").value = settings.streamtoolsapikey || "st...";
document.getElementById("widgettype").value = settings.widgettype;
document.getElementById("widgetid").value = settings.widgetid;
document.getElementById("widgetid").value = settings.widgetid || "...";
document.getElementById("webhookpayload").value = settings.webhookpayload;
// [].forEach.call(document.querySelectorAll(".inspector"), element => {
// element.addEventListener("change", () => {
Expand All @@ -74,7 +74,5 @@
}
</script>
<div class="sdpi-info-label hidden" style="top: -1000;" value=""></div>


</body>
</html>

0 comments on commit 8ab809e

Please sign in to comment.