Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Baptiewright authored Aug 12, 2020
0 parents commit 6284a26
Show file tree
Hide file tree
Showing 11 changed files with 1,941 additions and 0 deletions.
42 changes: 42 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"Actions": [

{
"Icon": "plugin/resources/pluginIcon",
"Name": "Effects",
"States": [
{
"Image": "plugin/resources/simhub_button",
"TitleAlignment": "bottom",
"FontSize": "10"
}
],
"SupportedInMultiActions": true,
"Tooltip": "Simhub Control Trigger",
"UUID": "com.baptiewright.simhub.control"
}
],
"Author": "Baptiewright Designs",
"CodePath": "plugin/main.html",
"Description": "Remotely Trigger Simhub Control Events",
"Name": "Simhub Controller",
"Icon": "plugin/resources/pluginIcon",
"URL": "http://www.baptiewright.com",
"PropertyInspectorPath": "propertyinspector/main_pi.html",
"Version": "0.1",
"OS": [
{
"MinimumVersion" : "10.12",
"Platform": "mac"
},
{
"Platform": "windows",
"MinimumVersion" : "10"
}
],
"SDKVersion": 2,
"Software": {
"MinimumVersion" : "4.1"
}

}
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>com.baptiewright.simhub</title>
<meta charset="utf-8" />
<script src="main.js"></script>
</head>

<body></body>

</html>

159 changes: 159 additions & 0 deletions plugin/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
//
// main.js
// Simhub Plugin
//
// Created by Grahame Wright, Baptiewright Designs
//

let websocket = null;
let pluginUUID = null;
//let settingsCache = {};
let globalSettingsCache = {};
let settingsCache = {};

const controlAction = {

type : "com.baptiewright.simhub.control",

onKeyUp : function(context, settings, coordinates, userDesiredState) {
triggerSimhub(settings['trigger'],context);
//console.log("Button Pressed");
},

onWillAppear : function(context, settings, coordinates) {
settingsCache[context] = settings;
//console.log("willAppear",settings);
},

SetTitle : function(context,jsonPayload) {
//console.log(jsonPayload['title']);
let payload = {};
payload.title = jsonPayload['title'];
payload.target = "DestinationEnum.HARDWARE_AND_SOFTWARE";
const json = {
"event": "setTitle",
"context": context,
"payload": payload,
};
websocket.send(JSON.stringify(json));
}

};

function triggerSimhub(trigger,context)
{
var simURL = "http://localhost:8888/api/triggerinput/"+trigger;
var method = "GET";
var request = new XMLHttpRequest();
request.open(method, simURL);
request.send();
//console.log(request);
request.onreadystatechange = function() {

if (request.readyState == 4){
if (request.status == 200) {
//var status = request.status;
var data = request.responseText;
if (data == "Ok") {
showAlert("showOk",context);
}
else {
//console.log("Shit went wrong");
showAlert("showAlert",context);
}

}
else {
//console.log("Shit went wrong");
showAlert("showAlert",context);
}
}
}
}

function showAlert(event,context) {
if (websocket) {
let payload = {};
const json = {
"event": event,
"context": context,
};
websocket.send(JSON.stringify(json));
}
}

function requestSettings(uuid,event,payload={}) {
if (websocket) {
const json = {
"event": event,
"context": uuid,
"payload" : payload,
};
//console.log("sending to plugin",json);
websocket.send(JSON.stringify(json));
}
}

function connectElgatoStreamDeckSocket(inPort, inPluginUUID, inRegisterEvent, inInfo)
{
pluginUUID = inPluginUUID;
console.log("pluginUUID ",pluginUUID);
// Open the web socket
websocket = new WebSocket("ws://localhost:" + inPort);

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

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

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

websocket.onmessage = function (evt)
{
// Received message from Stream Deck
const jsonObj = JSON.parse(evt.data);
const event = jsonObj['event'];
const action = jsonObj['action'];
const context = jsonObj['context'];
const jsonPayload = jsonObj['payload'];
console.log("main plugin onmessage",jsonObj)
if(event == "keyUp")
{
const settings = jsonPayload['settings'];
const coordinates = jsonPayload['coordinates'];
const userDesiredState = jsonPayload['userDesiredState'];
controlAction.onKeyUp(context, settings, coordinates, userDesiredState);
}
else if(event == "willAppear")
{
const settings = jsonPayload['settings'];
const coordinates = jsonPayload['coordinates'];
controlAction.onWillAppear(context, settings, coordinates);
}
else if (event == "propertyInspectorDidAppear") {

}
else if(event == "didReceiveSettings") {
settingsCache[context] = jsonPayload;
}

else if(event == "didReceiveGlobalSettings") {

}
else if(event == "sendToPlugin") {

}


}
};
Binary file added plugin/resources/pluginIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added plugin/resources/pluginIcon@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added plugin/resources/simhub_button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added plugin/resources/simhub_button@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.
41 changes: 41 additions & 0 deletions propertyinspector/main_pi.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8" />
<title>com.baptiewright.simhubPI</title>
<link rel="stylesheet" href="sdpi.css">
<script src="main_pi.js"></script>
</head>
<body>
<div class="sdpi-wrapper">

<div class="sdpi-item">
<div class="sdpi-item-label">Button Name</div>
<input class="sdpi-item-value" id="trigger" value="" placeholder="Enter Button Name">
</div>
</div>
</body>

<script language="javascript">
input = document.getElementById('trigger');
restrictChars(input, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_");

function restrictChars(input, chars) {
input.addEventListener("keypress", function (e) {
e.preventDefault();
if (e.keyCode !== 8 && e.keyCode !== 46)
{
var character = String.fromCharCode(e.keyCode);
var isValid = chars.indexOf(character) != -1;
if (isValid) {
input.value += character;
}
}
updateSettings();
});
}

</script>

</html>
78 changes: 78 additions & 0 deletions propertyinspector/main_pi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
//
// main_pi.js
// Simhub Plugin
//
// Created by Grahame Wright, Baptiewright Designs
//
//

let websocket = null,
uuid = null,
actionInfo = {};
settingsCache = {};

function connectElgatoStreamDeckSocket(inPort, inUUID, inRegisterEvent, inInfo, inActionInfo) {
uuid = inUUID;
actionInfo = JSON.parse(inActionInfo);
const action = actionInfo.action;
settingsCache[uuid] = actionInfo.payload.settings;
settings = settingsCache[uuid];
//console.log(settingsCache[uuid]);
websocket = new WebSocket('ws://127.0.0.1:' + inPort);

websocket.onopen = function () {
const json = {
event: inRegisterEvent,
uuid: uuid,
};
websocket.send(JSON.stringify(json));
//requestSettings(uuid,"getGlobalSettings");
};

websocket.onmessage = function (evt) {
// Received message from Stream Deck
console.log("event",evt);
const jsonObj = JSON.parse(evt.data);
settings = settingsCache[uuid];
const payload = jsonObj.payload;
if (jsonObj.event === 'didReceiveSettings')
{
settingsCache[uuid] = payload.settings;
settings = settingsCache[uuid];
}



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

if (settings.trigger)
{
var trigger = document.getElementById('trigger');
trigger.value = settings.trigger;
}

}

function updateSettings() {
//console.log("Updating Local Settings");
if (websocket) {
let payload = {};
const trigger = document.getElementById('trigger').value;
payload.trigger = trigger;

const json = {
"event": "setSettings",
"context": uuid,
"payload": payload,
};
//console.log("Updating Local Settings",json);
websocket.send(JSON.stringify(json));
settingsCache[uuid] = payload;
}
}




Loading

0 comments on commit 6284a26

Please sign in to comment.