Added some comments

This commit is contained in:
2021-12-27 17:08:46 -06:00
parent 93cc161f4c
commit 822a9a8971

View File

@@ -13,7 +13,7 @@ class W3DHub
end end
def write(object) def write(object)
super(dump(object) + "\x1e") super("#{dump(object)}\x1e")
end end
end end
@@ -37,9 +37,12 @@ class W3DHub
Async::WebSocket::Client.connect(endpoint, headers: headers, handler: WSS::Connection) do |connection| Async::WebSocket::Client.connect(endpoint, headers: headers, handler: WSS::Connection) do |connection|
connection.write({ protocol: "json", version: 1 }) connection.write({ protocol: "json", version: 1 })
connection.flush connection.flush
pp connection.read # Should be an empty hash for protocol agreement
connection.read
# Write keep alive?
connection.write({ "type": 6 }) connection.write({ "type": 6 })
# Subscribe to server changes
servers.each_with_index do |server, i| servers.each_with_index do |server, i|
i += 1 i += 1
out = { "type": 1, "invocationId": "#{i}", "target": "SubscribeToServerStatusUpdates", "arguments": [server[:id], 2] } out = { "type": 1, "invocationId": "#{i}", "target": "SubscribeToServerStatusUpdates", "arguments": [server[:id], 2] }
@@ -47,6 +50,7 @@ class W3DHub
end end
while (message = connection.read) while (message = connection.read)
# Keep alive?
connection.write({ type: 6 }) if message.first[:type] == 6 connection.write({ type: 6 }) if message.first[:type] == 6
# TODO: process messages (of type 3?) # TODO: process messages (of type 3?)