I'm attempting to write a Ruby SDK for the Stream Deck, a product that is basically a fancy hardware AutoHotkey allowing the user to program buttons with customized icons that do whatever they please, including making directories to achieve an unlimited amount of buttons organized to their liking. It has a language-agnostic API wherein it runs your script or compiled app with the arguments -port
, -pluginUUID
, -registerEvent
, and -info
. It runs a websocket on localhost at the port specified in the args, and on opening a connection you are to send a JSON string with your event and UUID as specified in the args.
I've gotten Ruby 3.0.5 running within a plugin with console output, but I'm having trouble getting it to talk to the websocket. I'm using SDPL to load my script (intended only for testing):
#!/esr/bin/env ruby
require "json"
require "async/websocket/client"
require "async/http/endpoint"
include Async
include Async::HTTP
# Parse arguments
_, port, _, UUID, _, REGISTER_EVENT, _, *info = ARGV
PORT = port.to_i
INFO = JSON.parse info.join(" ")
# Debug output prints properly
p PORT
p UUID
p REGISTER_EVENT
p INFO
Async do |task|
WebSocket::Client.connect(Endpoint.parse "http://localhost:#{PORT}") do |ws|
ws.write({ event: REGISTER_EVENT, uuid: UUID }.to_json)
ws.flush
puts "Opened!"
while msg = ws.read
puts "Message:"
puts msg
end
end
end
The arguments output as expected, then it hangs. If this code is run in WSL (with modifications to hardcode the port and an open plugin UUID), it talks to the Stream Deck as expected. Possible issue with the module on Windows 10? On RubyInstaller 3.1.2, the situation is even worse- it crashes with the following error:
0.0s warn: Async::Task [oid=0x280] [ec=0x294] [pid=32436] [2022-12-13 00:36:46 -0500]
| Task may have ended with unhandled exception.
| Errno::EBADF: Bad file descriptor
| → <internal:io> 63
| C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/io-event-1.1.4/lib/io/event/selector/select.rb 206