File tree 1 file changed +12
-1
lines changed
1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change 21
21
< body >
22
22
< h2 > WebSocket demo</ h2 >
23
23
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 >
25
28
26
29
< fieldset id ="configuration ">
27
30
< p >
@@ -48,13 +51,21 @@ <h2>WebSocket demo</h2>
48
51
// elements
49
52
const configuration = document . getElementById ( 'configuration' ) ;
50
53
const location = document . getElementById ( 'location' ) ;
54
+ const codeblockWsLocation = document . getElementById ( 'codeblock-ws-location' ) ;
51
55
const connectBtn = document . getElementById ( 'connectBtn' ) ;
52
56
const disconnectBtn = document . getElementById ( 'disconnectBtn' ) ;
53
57
const messaging = document . getElementById ( 'messaging' ) ;
54
58
const message = document . getElementById ( 'message' ) ;
55
59
const sendBtn = document . getElementById ( 'sendBtn' ) ;
56
60
const logger = document . getElementById ( 'logger' ) ;
57
61
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
+
58
69
// ws
59
70
let socket ;
60
71
You can’t perform that action at this time.
0 commit comments