1
1
// If there is no WebSocket, try MozWebSocket (support for some old browsers)
2
2
try {
3
- module . exports = WebSocket
3
+ module . exports = WebSocket ;
4
4
} 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 = / V e r s i o n \/ ( \d + ) \. ( \d + ) (?: \. ( \d + ) ) ? .* S a f a r i \/ / ;
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 ( / i P ( h o n e | o d | a d ) / . 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