Commit 97362c39 authored by Dominic Luechinger's avatar Dominic Luechinger

Improved websocket binary support detection

A facke connection to 'wss://localhost:17523' (randomly chosen) to detect
the WebSocket binary support is not the best solution.
First of all, check of prototype has the property 'binaryType'. If not,
perform a dummy connection to 'wss://.' instead of 'wss://localhost:17523'.

This patch was inspired by the discussion and implementation of Modernizr:
https://github.com/Modernizr/Modernizr/issues/370
https://github.com/Modernizr/Modernizr/blob/master/feature-detects/websockets/binary.js
parent c70000ba
...@@ -296,17 +296,13 @@ function connect() { ...@@ -296,17 +296,13 @@ function connect() {
var uri; var uri;
if (typeof UsingSocketIO !== "undefined") { if (typeof UsingSocketIO !== "undefined") {
uri = "http://" + rfb_host + ":" + rfb_port + "/" + rfb_path; uri = "http";
} else { } else {
if (conf.encrypt) { uri = conf.encrypt ? "wss" : "ws";
uri = "wss://";
} else {
uri = "ws://";
}
uri += rfb_host + ":" + rfb_port + "/" + rfb_path;
} }
uri += "://" + rfb_host + ":" + rfb_port + "/" + rfb_path;
Util.Info("connecting to " + uri); Util.Info("connecting to " + uri);
// TODO: make protocols a configurable
ws.open(uri, conf.wsProtocols); ws.open(uri, conf.wsProtocols);
Util.Debug("<< RFB.connect"); Util.Debug("<< RFB.connect");
......
...@@ -262,7 +262,7 @@ function on(evt, handler) { ...@@ -262,7 +262,7 @@ function on(evt, handler) {
eventHandlers[evt] = handler; eventHandlers[evt] = handler;
} }
function init(protocols) { function init(protocols, ws_schema) {
rQ = []; rQ = [];
rQi = 0; rQi = 0;
sQ = []; sQ = [];
...@@ -278,11 +278,14 @@ function init(protocols) { ...@@ -278,11 +278,14 @@ function init(protocols) {
bt = true; bt = true;
} }
// Check for full binary type support in WebSockets // Check for full binary type support in WebSocket
// TODO: this sucks, the property should exist on the prototype // Inspired by:
// but it does not. // https://github.com/Modernizr/Modernizr/issues/370
// https://github.com/Modernizr/Modernizr/blob/master/feature-detects/websockets/binary.js
try { try {
if (bt && ('binaryType' in (new WebSocket("wss://localhost:17523")))) { if (bt &&
('binaryType' in WebSocket.prototype ||
!!(new WebSocket(ws_schema + '://.').binaryType))) {
Util.Info("Detected binaryType support in WebSockets"); Util.Info("Detected binaryType support in WebSockets");
wsbt = true; wsbt = true;
} }
...@@ -325,7 +328,8 @@ function init(protocols) { ...@@ -325,7 +328,8 @@ function init(protocols) {
} }
function open(uri, protocols) { function open(uri, protocols) {
protocols = init(protocols); var ws_schema = uri.match(/^([a-z]+):\/\//)[1];
protocols = init(protocols, ws_schema);
if (test_mode) { if (test_mode) {
websocket = {}; websocket = {};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment