From 96e7ff73ddf2580e52d1b1fd61bb1ca04335b0b7 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Mon, 1 Oct 2012 11:50:16 +0200 Subject: [PATCH] broadway: Detect binary websockets support --- gdk/broadway/broadway.js | 24 +++++++++++++++++------- gdk/broadway/gdkdisplay-broadway.c | 8 ++++++-- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/gdk/broadway/broadway.js b/gdk/broadway/broadway.js index 86b605a50c..a5e30c1bfd 100644 --- a/gdk/broadway/broadway.js +++ b/gdk/broadway/broadway.js @@ -2755,6 +2755,18 @@ function setupDocument(document) } } +function newWS(loc) { + var ws = null; + if ("WebSocket" in window) { + ws = new WebSocket(loc, "broadway"); + } else if ("MozWebSocket" in window) { // Firefox 6 + ws = new MozWebSocket(loc); + } else { + alert("WebSocket not supported, broadway will not work!"); + } + return ws; +} + function connect() { var url = window.location.toString(); @@ -2767,15 +2779,13 @@ function connect() var loc = window.location.toString().replace("http:", "ws:"); loc = loc.substr(0, loc.lastIndexOf('/')) + "/socket"; - var ws = null; - if ("WebSocket" in window) { - ws = new WebSocket(loc, "broadway"); - } else if ("MozWebSocket" in window) { // Firefox 6 - ws = new MozWebSocket(loc); + var supports_binary = newWS (loc + "-test").binaryType == "blob"; + if (supports_binary) { + ws = newWS (loc + "-bin"); + ws.binaryType = "arraybuffer"; } else { - alert("WebSocket not supported, input will not work!"); - return; + ws = newWS (loc); } ws.onopen = function() { diff --git a/gdk/broadway/gdkdisplay-broadway.c b/gdk/broadway/gdkdisplay-broadway.c index 49d95a2740..a6fadd604b 100644 --- a/gdk/broadway/gdkdisplay-broadway.c +++ b/gdk/broadway/gdkdisplay-broadway.c @@ -149,6 +149,7 @@ struct BroadwayInput { gboolean seen_time; gint64 time_base; gboolean proto_v7_plus; + gboolean binary; }; static void @@ -691,7 +692,7 @@ generate_handshake_response_wsietf_v7 (const gchar *key) } static void -start_input (HttpRequest *request) +start_input (HttpRequest *request, gboolean binary) { char **lines; char *p; @@ -867,6 +868,7 @@ start_input (HttpRequest *request) input->display = request->display; input->connection = g_object_ref (request->connection); input->proto_v7_plus = proto_v7_plus; + input->binary = binary; data_buffer = g_buffered_input_stream_peek_buffer (G_BUFFERED_INPUT_STREAM (request->data), &data_buffer_size); input->buffer = g_byte_array_sized_new (data_buffer_size); @@ -985,7 +987,9 @@ got_request (HttpRequest *request) else if (strcmp (escaped, "/broadway.js") == 0) send_data (request, "text/javascript", broadway_js, G_N_ELEMENTS(broadway_js) - 1); else if (strcmp (escaped, "/socket") == 0) - start_input (request); + start_input (request, FALSE); + else if (strcmp (escaped, "/socket-bin") == 0) + start_input (request, TRUE); else send_error (request, 404, "File not found");