File tree Expand file tree Collapse file tree 1 file changed +17
-13
lines changed Expand file tree Collapse file tree 1 file changed +17
-13
lines changed Original file line number Diff line number Diff line change 1+ async function reportWebSocketError ( ) {
2+ try {
3+ await fetch ( '/nowebsocket' , {
4+ method : 'post' ,
5+ headers : {
6+ 'Content-Length' : '0' ,
7+ } ,
8+ } ) ;
9+ } catch ( e ) {
10+ console . log ( 'Error:' , e ) ;
11+ }
12+ }
13+
114export default function openWebSocket ( currentLocation : Location ) {
215 try {
316 const wsProtocol = currentLocation . protocol === 'https:' ? 'wss://' : 'ws://' ;
417 const wsUri = [ wsProtocol , currentLocation . host , '/websocket' ] . join ( '' ) ;
5- return new WebSocket ( wsUri ) ;
18+ const ws = new WebSocket ( wsUri ) ;
19+ ws . addEventListener ( 'error' , ( ) => reportWebSocketError ( ) ) ;
20+ return ws ;
621 } catch {
722 // WebSocket URL error or WebSocket is not supported by browser.
823 // Assume it's the second case since URL error is easy to notice.
9- ( async ( ) => {
10- try {
11- await fetch ( '/nowebsocket' , {
12- method : 'post' ,
13- headers : {
14- 'Content-Length' : '0' ,
15- } ,
16- } ) ;
17- } catch ( e ) {
18- console . log ( 'Error:' , e ) ;
19- }
20- } ) ( ) ;
24+ reportWebSocketError ( ) ;
2125 return null ;
2226 }
2327}
You can’t perform that action at this time.
0 commit comments