Merge branch 'develop' of https://github.com/ripple/ripple-lib into develop

This commit is contained in:
wltsmrz
2013-12-23 11:49:30 -08:00
2 changed files with 42 additions and 3 deletions

View File

@@ -163,6 +163,11 @@ Server.prototype.connect = function() {
if (this._ws) this._ws.close();
var WebSocket = Server.websocketConstructor();
if (!WebSocket) {
throw new Error("No websocket support detected!");
}
var ws = this._ws = new WebSocket(this._opts.url);
this._shouldConnect = true;

View File

@@ -1,6 +1,40 @@
// If there is no WebSocket, try MozWebSocket (support for some old browsers)
try {
module.exports = WebSocket
module.exports = WebSocket;
} catch(err) {
module.exports = MozWebSocket
module.exports = MozWebSocket;
}
// Some versions of Safari Mac 5 and Safari iOS 4 seem to support websockets,
// but can't communicate with websocketpp, which is what rippled uses.
//
// Note that we check for both the WebSocket protocol version the browser seems
// to implement as well as the user agent etc. The reason is that we want to err
// on the side of trying to connect since we don't want to accidentally disable
// a browser that would normally work fine.
var match, versionRegexp = /Version\/(\d+)\.(\d+)(?:\.(\d+))?.*Safari\//;
if (
// Is browser
"object" === typeof navigator &&
"string" === typeof navigator.userAgent &&
// Is Safari
(match = versionRegexp.exec(navigator.userAgent)) &&
// And uses the old websocket protocol
2 === window.WebSocket.CLOSED
) {
// Is iOS
if (/iP(hone|od|ad)/.test(navigator.platform)) {
// Below version 5 is broken
if (+match[1] < 5) {
module.exports = void(0);
}
// Is any other Mac OS
// If you want to refactor this code, be careful, iOS user agents contain the
// string "like Mac OS X".
} else if (navigator.appVersion.indexOf("Mac") !== -1) {
// Below version 6 is broken
if (+match[1] < 6) {
module.exports = void(0);
}
}
}