So I'm writing streamdeck plugins and they are each combined into one library since I don't want to spawn a process for each one.
Everything works as expected but I am having issues when one plugin enters a cycle state e.g. runwait() or loop() etc.
This causes the other plugins to freeze. Any input is buffered and executed AFTER the script returns to the main function loop.
The issue here is that I am using a js websocket to connect to the streamdeck API. For this I am creating an object to execute functions from a class.
The received event data gets interpreted and then the corresponding functions are called to communicate with the streamdeck api (and other interfaces).
All function calls seem to be same-threaded if they are called from inside the OnMessage() function that resides in the Websocket object.
But this websocket object has to persist until streamdeck decides to close the websocket.
I can't use multiple websocket connections for one AHK instance unless I split up the library and create for each plugin a seperate streamdeck-Plugin environment (consists of its own folder structure with files and ressources). I'd rather have everything in one place.
To summerize with pseudocode:
Code: Select all
Parse A_Args
class websocket{
__New(A_Args){ connect to websocket and create neccessary objects }
function1(){}
function2(){}
...
OnMessage(event_data){
if event_data='bob'
streamdeck_plugin_one()
if event_data='alice'
streamdeck_plugin_one()
}
Send(data)
{
this.send_back_to_websocket(data)
}
}
streamdeck_plugin_one(){
do things which take a long time
obj.send(data:=whatever_is_needed)
}
streamdeck_plugin_two(){
do things
obj.send(data:=whatever_is_needed)
}
obj:=websocket(A_Args)
Is it possible to somehow pseudo-mutithread OnMessage() ?
Or do I have to split every plugin into its own folder structure and manage multiple websocket instances with one ahk process?
EDIT: I think it works if I use multiple script instances. Very complicated though. I need to break apart the plugin and websocket classes.
When a websocket.OnMessage event happens, I'd do a run() with parameters so the plugin part can do its job.
To coordinate the tasks I'd have to use OnMessage() on the main thread and Sendmessage() on the plugin-thread. I chose WM_COPYDATA to send messages back and forth. I'd need to pass at least strings.
With this I can also interrupt current threads which is quiet nice. But god is it complicated :/