Skip to content

Commit 471349f

Browse files
authored
docs(websocket): improve example for online IDE (#990)
1 parent e644a22 commit 471349f

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

examples/websocket/index.html

+12-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@
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

0 commit comments

Comments
 (0)