mirror of
https://github.com/cyberarm/w3d_hub_linux_launcher.git
synced 2026-03-22 04:06:18 +00:00
Migrated away from Excon and to async-http, fixes issues with ipv6 dns resolving but not reachable- and is the start towards more migration to async libs, websocket based server list updater is temporarily broken
This commit is contained in:
@@ -23,20 +23,24 @@ class W3DHub
|
||||
end
|
||||
|
||||
def run
|
||||
return
|
||||
|
||||
Thread.new do
|
||||
begin
|
||||
connect
|
||||
Sync do |task|
|
||||
begin
|
||||
async_connect(task)
|
||||
|
||||
while W3DHub::BackgroundWorker.alive?
|
||||
connect if @auto_reconnect
|
||||
sleep 1
|
||||
while W3DHub::BackgroundWorker.alive?
|
||||
async_connect(task) if @auto_reconnect
|
||||
sleep 1
|
||||
end
|
||||
rescue => e
|
||||
puts e
|
||||
puts e.backtrace
|
||||
|
||||
sleep 30
|
||||
retry
|
||||
end
|
||||
rescue => e
|
||||
puts e
|
||||
puts e.backtrace
|
||||
|
||||
sleep 30
|
||||
retry
|
||||
end
|
||||
end
|
||||
|
||||
@@ -44,6 +48,39 @@ class W3DHub
|
||||
@@instance = nil
|
||||
end
|
||||
|
||||
def async_connect(task)
|
||||
@auto_reconnect = false
|
||||
|
||||
logger.debug(LOG_TAG) { "Requesting connection token..." }
|
||||
response = Api.post("/listings/push/v2/negotiate?negotiateVersion=1", Api::DEFAULT_HEADERS, "", :gsh)
|
||||
|
||||
if response.status != 200
|
||||
@auto_reconnect = true
|
||||
return
|
||||
end
|
||||
|
||||
data = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
@invocation_id = 0 if @invocation_id > 9095
|
||||
id = data[:connectionToken]
|
||||
endpoint = "#{Api::SERVER_LIST_ENDPOINT}/listings/push/v2?id=#{id}"
|
||||
|
||||
logger.debug(LOG_TAG) { "Connecting to websocket..." }
|
||||
|
||||
Async::WebSocket::Client.connect(Async::HTTP::Endpoint.parse(endpoint)) do |connection|
|
||||
logger.debug(LOG_TAG) { "Requesting json protocol, v1..." }
|
||||
async_websocket_send(connection, { protocol: "json", version: 1 }.to_json)
|
||||
end
|
||||
end
|
||||
|
||||
def async_websocket_send(connection, payload)
|
||||
connection.write("#{payload}\x1e")
|
||||
connection.flush
|
||||
end
|
||||
|
||||
def async_websocket_read(connection, payload)
|
||||
end
|
||||
|
||||
def connect
|
||||
@auto_reconnect = false
|
||||
|
||||
|
||||
Reference in New Issue
Block a user