Skip to content

Commit a7532b5

Browse files
committedDec 23, 2013
Disable ripple-lib in Safari iOS < 5 and Safari Mac < 6.
Actively disabling support for these browsers allows us to catch and report the problem rather than trying to connect and failing for unknown reasons.
1 parent 9596787 commit a7532b5

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed
 

‎web_modules/ws.js

+37-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,40 @@
11
// If there is no WebSocket, try MozWebSocket (support for some old browsers)
22
try {
3-
module.exports = WebSocket
3+
module.exports = WebSocket;
44
} catch(err) {
5-
module.exports = MozWebSocket
6-
}
5+
module.exports = MozWebSocket;
6+
}
7+
8+
// Some versions of Safari Mac 5 and Safari iOS 4 seem to support websockets,
9+
// but can't communicate with websocketpp, which is what rippled uses.
10+
//
11+
// Note that we check for both the WebSocket protocol version the browser seems
12+
// to implement as well as the user agent etc. The reason is that we want to err
13+
// on the side of trying to connect since we don't want to accidentally disable
14+
// a browser that would normally work fine.
15+
var match, versionRegexp = /Version\/(\d+)\.(\d+)(?:\.(\d+))?.*Safari\//;
16+
if (
17+
// Is browser
18+
"object" === typeof navigator &&
19+
"string" === typeof navigator.userAgent &&
20+
// Is Safari
21+
(match = versionRegexp.exec(navigator.userAgent)) &&
22+
// And uses the old websocket protocol
23+
2 === window.WebSocket.CLOSED
24+
) {
25+
// Is iOS
26+
if (/iP(hone|od|ad)/.test(navigator.platform)) {
27+
// Below version 5 is broken
28+
if (+match[1] < 5) {
29+
module.exports = void(0);
30+
}
31+
// Is any other Mac OS
32+
// If you want to refactor this code, be careful, iOS user agents contain the
33+
// string "like Mac OS X".
34+
} else if (navigator.appVersion.indexOf("Mac") !== -1) {
35+
// Below version 6 is broken
36+
if (+match[1] < 6) {
37+
module.exports = void(0);
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)
Please sign in to comment.