@@ -138,6 +138,18 @@ function connect(remoteServer,position,message,backend_only=false) {
138
138
}
139
139
}
140
140
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
+
141
153
/*
142
154
Disconnects a websocket
143
155
@@ -195,10 +207,16 @@ function connectElgatoStreamDeckSocket(inPort, inPluginUUID, inRegisterEvent, in
195
207
var jsonObj = JSON . parse ( evt . data ) ;
196
208
197
209
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
+
199
218
if ( event == "didReceiveSettings" )
200
219
{
201
- var jsonPayload = jsonObj [ 'payload' ] ;
202
220
var settings = jsonPayload [ 'settings' ] ;
203
221
var coordinates = jsonPayload [ 'coordinates' ] ;
204
222
@@ -210,11 +228,18 @@ function connectElgatoStreamDeckSocket(inPort, inPluginUUID, inRegisterEvent, in
210
228
*/
211
229
else if ( event == "willAppear" )
212
230
{
213
- var jsonPayload = jsonObj [ 'payload' ] ;
214
231
var settings = jsonPayload [ 'settings' ] ;
215
232
var coordinates = jsonPayload [ 'coordinates' ] ;
233
+
216
234
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
+ }
218
243
}
219
244
}
220
245
/*
@@ -223,11 +248,14 @@ function connectElgatoStreamDeckSocket(inPort, inPluginUUID, inRegisterEvent, in
223
248
*/
224
249
else if ( event == "willDisappear" )
225
250
{
226
- var jsonPayload = jsonObj [ 'payload' ] ;
227
251
var settings = jsonPayload [ 'settings' ] ;
228
252
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
+ }
231
259
}
232
260
/*
233
261
Every other message is simply forwarded to node-red, the condition is
@@ -237,11 +265,16 @@ function connectElgatoStreamDeckSocket(inPort, inPluginUUID, inRegisterEvent, in
237
265
else if ( jsonObj . hasOwnProperty ( "payload" ) ) {
238
266
if ( jsonObj [ 'payload' ] . hasOwnProperty ( "settings" ) ) {
239
267
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
+ }
245
278
}
246
279
}
247
280
}
0 commit comments