Skip to content

Commit ad858cc

Browse files
committed
Implemented multi-action
1 parent 577661c commit ad858cc

File tree

3 files changed

+49
-13
lines changed

3 files changed

+49
-13
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# v1.1.8
2+
- You can now use SD WebSocket in multi-actions
3+
14
# v1.1.7
25
- Properly release unused connections
36

Sources/org.tynsoe.streamdeck.wsproxy.sdPlugin/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"Name": "WebSocket Proxy",
3232
"Icon": "images/websocket",
3333
"SDKVersion": 2,
34-
"Version": "1.1.7",
34+
"Version": "1.1.8",
3535
"PropertyInspectorPath": "plugin/inspector.html",
3636
"OS": [
3737
{

Sources/org.tynsoe.streamdeck.wsproxy.sdPlugin/plugin/index.js

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,18 @@ function connect(remoteServer,position,message,backend_only=false) {
138138
}
139139
}
140140

141+
var oneEventConnections = []
142+
function sendOneEvent(remoteServer,message) {
143+
var c = new WebSocket(remoteServer)
144+
oneEventConnections.push(c)
145+
c.onopen = function(evt) {
146+
console.log("Remote multi-action socket opened")
147+
c.send(JSON.stringify(message))
148+
c.close()
149+
delete oneEventConnections[c]
150+
}
151+
}
152+
141153
/*
142154
Disconnects a websocket
143155
@@ -195,10 +207,16 @@ function connectElgatoStreamDeckSocket(inPort, inPluginUUID, inRegisterEvent, in
195207
var jsonObj = JSON.parse(evt.data);
196208

197209
var event = jsonObj['event'];
198-
210+
211+
var jsonPayload = jsonObj['payload'];
212+
var isInMultiAction = null
213+
214+
if (jsonPayload && jsonPayload.hasOwnProperty("isInMultiAction") && jsonPayload['isInMultiAction']) {
215+
isInMultiAction = jsonPayload['isInMultiAction']
216+
}
217+
199218
if(event == "didReceiveSettings")
200219
{
201-
var jsonPayload = jsonObj['payload'];
202220
var settings = jsonPayload['settings'];
203221
var coordinates = jsonPayload['coordinates'];
204222

@@ -210,11 +228,18 @@ function connectElgatoStreamDeckSocket(inPort, inPluginUUID, inRegisterEvent, in
210228
*/
211229
else if(event == "willAppear")
212230
{
213-
var jsonPayload = jsonObj['payload'];
214231
var settings = jsonPayload['settings'];
215232
var coordinates = jsonPayload['coordinates'];
233+
216234
if (settings.hasOwnProperty("remoteServer")) {
217-
connect(settings.remoteServer,positionFromCoordinates(coordinates),jsonObj)
235+
// Multiactions are treated as one-offs and have short lived dedicated
236+
// connections
237+
if (isInMultiAction) {
238+
sendOneEvent(settings.remoteServer,jsonObj)
239+
}
240+
else {
241+
connect(settings.remoteServer,positionFromCoordinates(coordinates),jsonObj)
242+
}
218243
}
219244
}
220245
/*
@@ -223,11 +248,14 @@ function connectElgatoStreamDeckSocket(inPort, inPluginUUID, inRegisterEvent, in
223248
*/
224249
else if(event == "willDisappear")
225250
{
226-
var jsonPayload = jsonObj['payload'];
227251
var settings = jsonPayload['settings'];
228252
var coordinates = jsonPayload['coordinates'];
229-
230-
disconnect(settings.remoteServer,positionFromCoordinates(coordinates),jsonObj)
253+
if (isInMultiAction) {
254+
sendOneEvent(settings.remoteServer,jsonObj)
255+
}
256+
else {
257+
disconnect(settings.remoteServer,positionFromCoordinates(coordinates),jsonObj)
258+
}
231259
}
232260
/*
233261
Every other message is simply forwarded to node-red, the condition is
@@ -237,11 +265,16 @@ function connectElgatoStreamDeckSocket(inPort, inPluginUUID, inRegisterEvent, in
237265
else if (jsonObj.hasOwnProperty("payload")) {
238266
if (jsonObj['payload'].hasOwnProperty("settings")) {
239267
key = jsonObj['payload']['settings']['remoteServer']
240-
if (connections.hasOwnProperty(key)) {
241-
c=connections[key].websocket
242-
if (c && c.readyState == 1) {
243-
console.log(jsonObj)
244-
c.send(JSON.stringify(jsonObj))
268+
if (isInMultiAction) {
269+
sendOneEvent(key,jsonObj)
270+
}
271+
else {
272+
if (connections.hasOwnProperty(key)) {
273+
c=connections[key].websocket
274+
if (c && c.readyState == 1) {
275+
console.log(jsonObj)
276+
c.send(JSON.stringify(jsonObj))
277+
}
245278
}
246279
}
247280
}

0 commit comments

Comments
 (0)