File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change 2121 < body >
2222 < h2 > WebSocket demo</ h2 >
2323
24- < p > Proxy < code > ws://localhost:3000</ code > to < code > ws://ws.ifelse.io</ code > </ p >
24+ < p >
25+ Proxy < code id ="codeblock-ws-location "> ws://localhost:3000</ code > ➡
26+ < code > ws://ws.ifelse.io</ code >
27+ </ p >
2528
2629 < fieldset id ="configuration ">
2730 < p >
@@ -48,13 +51,21 @@ <h2>WebSocket demo</h2>
4851 // elements
4952 const configuration = document . getElementById ( 'configuration' ) ;
5053 const location = document . getElementById ( 'location' ) ;
54+ const codeblockWsLocation = document . getElementById ( 'codeblock-ws-location' ) ;
5155 const connectBtn = document . getElementById ( 'connectBtn' ) ;
5256 const disconnectBtn = document . getElementById ( 'disconnectBtn' ) ;
5357 const messaging = document . getElementById ( 'messaging' ) ;
5458 const message = document . getElementById ( 'message' ) ;
5559 const sendBtn = document . getElementById ( 'sendBtn' ) ;
5660 const logger = document . getElementById ( 'logger' ) ;
5761
62+ const documentUrl = new URL ( document . location ) ;
63+ const wsProtocol = documentUrl . protocol . includes ( 'https' ) ? 'wss:' : 'ws:' ;
64+ const wsPort = documentUrl . port ? `:${ documentUrl . port } ` : '' ;
65+ const locationValue = `${ wsProtocol } //${ documentUrl . host } ${ wsPort } ` ;
66+ location . value = locationValue ;
67+ codeblockWsLocation . innerText = locationValue ;
68+
5869 // ws
5970 let socket ;
6071
You can’t perform that action at this time.
0 commit comments