Skip to content
This repository has been archived by the owner on May 8, 2020. It is now read-only.

Commit

Permalink
🎉 Welcome Zapier!
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Möritz committed Jan 13, 2019
0 parents commit 6169458
Show file tree
Hide file tree
Showing 17 changed files with 1,937 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Zapier Integration for Elgato Stream Deck
> Integrate the Elgato Stream Deck in your Zapier setup and automate your workflow more easier.
8 changes: 8 additions & 0 deletions de.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Description": "Integriere das Elgato Stream Deck in dein Zapier-Setup und automatisiere deine Arbeitsabläufe leichter als zuvor.",
"Name": "Zapier-Integration",
"de.tobimori.streamdeck.zapier.action": {
"Name": "Zapier-Button",
"Tooltip": "Sobald Stream Deck-Button gedrückt, mache..."
}
}
38 changes: 38 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"Actions": [
{
"Icon": "resources/actionIcon",
"Name": "Zapier Button",
"States": [
{
"Image": "resources/actionDefaultImage",
"TitleAlignment": "bottom",
"FontSize": "10"
}
],
"SupportedInMultiActions": false,
"Tooltip": "If Stream Deck button pressed, then...",
"UUID": "de.tobimori.streamdeck.zapier.action"
}
],
"Author": "tobimori",
"CodePath": "plugin/main.html",
"Description": "Integrate the Elgato Stream Deck in your Zapier setup and automate your workflow more easier.",
"Name": "Zapier Integration",
"Icon": "resources/pluginIcon",
"URL": "https://streamdeck.tobimori.de",
"PropertyInspectorPath": "propertyinspector/main_pi.html",
"Version": "1.0",
"Category": "tobimori",
"CategoryIcon": "resources/categoryIcon",
"OS": [
{
"MinimumVersion" : "10.11",
"Platform": "mac"
},
{
"Platform": "windows",
"MinimumVersion" : "10"
}
]
}
13 changes: 13 additions & 0 deletions plugin/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE HTML>
<html>

<head>
<title>de.tobimori.streamdeck.ifttt</title>
<meta charset="utf-8" />
<script src="main.js"></script>
</head>

<body></body>

</html>

154 changes: 154 additions & 0 deletions plugin/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
var websocket = null;
var pluginUUID = null;
var settingsCache = {};

var DestinationEnum = Object.freeze({"HARDWARE_AND_SOFTWARE":0, "HARDWARE_ONLY":1, "SOFTWARE_ONLY":2})

var webhookAction = {

type : "de.tobimori.streamdeck.zapier.action",

onKeyDown : function(context, settings, coordinates, userDesiredState) {
},

onKeyUp : function(context, settings, coordinates, userDesiredState) {
settingsCache[context] = settings;
var zapid = "";
if(settings != null && settings.hasOwnProperty('zapid')){
zapid = settings["zapid"];
}
var userid = "";
if(settings != null && settings.hasOwnProperty('userid')){
userid = settings["userid"];
}
if(zapid == "") {
this.ShowReaction(context, "Alert");
} else if(userid == "") {
this.ShowReaction(context, "Alert");
} else {
const request = new XMLHttpRequest();
request.open("GET", 'https://hooks.zapier.com/hooks/catch/' + userid + '/' + zapid);
request.send();
}

},

onWillAppear : function(context, settings, coordinates) {
settingsCache[context] = settings;
var zapid = "";
if(settings != null && settings.hasOwnProperty('zapid')){
zapid = settings["zapid"];
}
var userid = "";
if(settings != null && settings.hasOwnProperty('userid')){
userid = settings["userid"];
}
if(zapid == "") {
this.ShowReaction(context, "Alert");
} else if(userid == "") {
this.ShowReaction(context, "Alert");
}
},

ShowReaction : function(context, type) {
var json = {
"event": "show" + type,
"context": context,
};
websocket.send(JSON.stringify(json));
},

SetSettings : function(context, settings) {
var json = {
"event": "setSettings",
"context": context,
"payload": settings
};

websocket.send(JSON.stringify(json));
},

SendSettings : function(action, context) {
var json = {
"action": action,
"event": "sendToPropertyInspector",
"context": context,
"payload": settingsCache[context]
};

websocket.send(JSON.stringify(json));
}
};

function connectSocket(inPort, inPluginUUID, inRegisterEvent, inInfo)
{
pluginUUID = inPluginUUID;

// Open the web socket
websocket = new WebSocket("ws://localhost:" + inPort);

function registerPlugin(inPluginUUID)
{
var json = {
"event": inRegisterEvent,
"uuid": inPluginUUID
};

websocket.send(JSON.stringify(json));
};

websocket.onopen = function()
{
// WebSocket is connected, send message
registerPlugin(pluginUUID);
};

websocket.onmessage = function (evt)
{
// Received message from Stream Deck
var jsonObj = JSON.parse(evt.data);
var event = jsonObj['event'];
var action = jsonObj['action'];
var context = jsonObj['context'];
var jsonPayload = jsonObj['payload'];

if(event == "keyDown")
{
var settings = jsonPayload['settings'];
var coordinates = jsonPayload['coordinates'];
var userDesiredState = jsonPayload['userDesiredState'];
console.log(settings);
webhookAction.onKeyDown(context, settings, coordinates, userDesiredState);
}
else if(event == "keyUp")
{
var settings = jsonPayload['settings'];
var coordinates = jsonPayload['coordinates'];
var userDesiredState = jsonPayload['userDesiredState'];
webhookAction.onKeyUp(context, settings, coordinates, userDesiredState);
}
else if(event == "willAppear")
{
var settings = jsonPayload['settings'];
var coordinates = jsonPayload['coordinates'];
webhookAction.onWillAppear(context, settings, coordinates);
}
else if(event == "sendToPlugin") {

if(jsonPayload['type'] == "updateSettings") {

webhookAction.SetSettings(context, jsonPayload);
settingsCache[context] = jsonPayload;

} else if(jsonPayload['type'] == "requestSettings") {

webhookAction.SendSettings(action, context);
}
}
};

websocket.onclose = function()
{
// Websocket is closed
};
};
3 changes: 3 additions & 0 deletions propertyinspector/caret.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions propertyinspector/main_pi.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8" />
<title>de.tobimori.streamdeck.zapier.pi</title>
<link rel="stylesheet" href="sdpi.css">
<script src="main_pi.js"></script>
</head>

<body>
<div class="sdpi-wrapper hidden">

<div class="sdpi-heading">SETTINGS</div>

<div class="sdpi-item">
<div class="sdpi-item-label">User ID</div>
<input class="sdpi-item-value" id="userid" value="" onchange="updateSettings()" placeholder="Enter your User ID">
</div>
<div class="sdpi-item">
<div class="sdpi-item-label">Zap ID</div>
<input class="sdpi-item-value" id="zapid" value="" onchange="updateSettings()" placeholder="Enter the ID of your Zap">
</div>

</div>
</body>

</html>
86 changes: 86 additions & 0 deletions propertyinspector/main_pi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
var websocket = null,
uuid = null,
actionInfo = {};

function connectSocket(inPort, inUUID, inRegisterEvent, inInfo, inActionInfo) {
uuid = inUUID;

actionInfo = JSON.parse(inActionInfo);
websocket = new WebSocket('ws://localhost:' + inPort);

websocket.onopen = function () {
var json = {
event: inRegisterEvent,
uuid: inUUID
};

websocket.send(JSON.stringify(json));
requestSettings();


}

websocket.onmessage = function (evt) {
// Received message from Stream Deck
var jsonObj = JSON.parse(evt.data);
if (jsonObj.event === 'sendToPropertyInspector') {
var payload = jsonObj.payload;
if (payload.error) {
return;
}

var zapid = document.getElementById('zapid');
zapid.value = payload.zapid;

var userid = document.getElementById('userid');
userid.value = payload.userid;

if(userid.value == "undefined" && zapid.value == "undefined") {
userid.value = "";
zapid.value = "";
}

revealPropertyInspector()
}
};

}

function revealPropertyInspector() {
const el = document.querySelector('.sdpi-wrapper');
el && el.classList.remove('hidden');
}

function requestSettings() {
if (websocket) {
var payload = {};
payload.type = "requestSettings";
const json = {
"action": actionInfo['action'],
"event": "sendToPlugin",
"context": uuid,
"payload": payload,
};
websocket.send(JSON.stringify(json));
}
}

function updateSettings() {
if (websocket) {
var userid = document.getElementById('userid');
var zapid = document.getElementById('zapid');

var payload = {};
payload.type = "updateSettings";
payload.userid = userid.value;
payload.zapid = zapid.value;
console.log(payload);
const json = {
"action": actionInfo['action'],
"event": "sendToPlugin",
"context": uuid,
"payload": payload,
};
websocket.send(JSON.stringify(json));
}
}
Loading

0 comments on commit 6169458

Please sign in to comment.