mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-27 22:20:24 +00:00
broadway: Detect binary websockets support
This commit is contained in:
parent
7c87684629
commit
96e7ff73dd
@ -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() {
|
||||
|
@ -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");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user