Changes
2 changed files (+37/-28)
-
-
@@ -20,6 +20,33 @@ NETWORK_ERROR,UNEXPECTED_RESPONSE, } /** * Roon forces application-layer ping/pong instead of WebSocket's ping/pong frame. */ private static void handle_ping(Soup.WebsocketConnection conn, int _type, GLib.Bytes bytes) { var message = (string) bytes.get_data(); Moo.Metadata req_meta; Moo.Headers req_headers; try { req_meta = new Moo.Metadata.from_string(message); req_headers = new Moo.Headers.from_string(message, req_meta); } catch (GLib.Error error) { GLib.log("Plac", LEVEL_WARNING, "Got invalid MOO message: %s", error.message); return; } if (req_meta.service != "com.roonlabs.ping:1/ping") { return; } var res_meta = new Moo.Metadata("COMPLETE", "Success"); var res_headers = new Moo.Headers(); res_headers.write("Request-Id", @"$(req_headers.request_id)"); conn.send_binary(@"$res_meta$res_headers".data); } // TODO: Handle connection close and reconnect public class Connection : Object { private size_t request_id = 1;
-
@@ -30,34 +57,6 @@ public string token { get; construct; }public Connection(Soup.WebsocketConnection conn, Server server, string token) { Object(conn: conn, server: server, token: token); } construct { // Roon forces application-layer ping/pong instead of WebSocket's // ping/pong frame. conn.message.connect((c, type, bytes) => { var message = (string) bytes.get_data(); Moo.Metadata req_meta; Moo.Headers req_headers; try { req_meta = new Moo.Metadata.from_string(message); req_headers = new Moo.Headers.from_string(message, req_meta); } catch (GLib.Error error) { GLib.log("Plac", LEVEL_WARNING, "Got invalid MOO message: %s", error.message); return; } if (req_meta.service != "com.roonlabs.ping:1/ping") { return; } var res_meta = new Moo.Metadata("COMPLETE", "Success"); var res_headers = new Moo.Headers(); res_headers.write("Request-Id", @"$(req_headers.request_id)"); conn.send_binary(@"$res_meta$res_headers".data); }); } public async Response json_request(string service, string body) throws RequestError {
-
-
-
@@ -81,6 +81,9 @@return new Server(address, id, info.display_version, info.display_name, http_port); } /** * TODO: Move connection-related code to `Connection` class */ private static async Soup.WebsocketConnection ws_connect( GLib.InetSocketAddress address, uint16 port,
-
@@ -99,6 +102,8 @@ // Roon API does not specify WebSocket subprotocols.Soup.WebsocketConnection conn = yield session.websocket_connect_async( msg, null, null, GLib.Priority.DEFAULT, cancellable ); conn.message.connect(handle_ping); return conn; }
-
@@ -122,6 +127,11 @@ res_meta = new Moo.Metadata.from_string(message);res_headers = new Moo.Headers.from_string(message, res_meta); } catch (GLib.Error error) { GLib.log("Plac", LEVEL_WARNING, "Got invalid MOO message: %s", error.message); return; } if (res_meta.verb == "REQUEST") { // Application ping message, skip. return; }
-