Skip to content

Commit

Permalink
docs(websocket): improve example for online IDE (#990)
Browse files Browse the repository at this point in the history
  • Loading branch information
chimurai authored Apr 20, 2024
1 parent e644a22 commit 471349f
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion examples/websocket/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
<body>
<h2>WebSocket demo</h2>

<p>Proxy <code>ws://localhost:3000</code> to <code>ws://ws.ifelse.io</code></p>
<p>
Proxy <code id="codeblock-ws-location">ws://localhost:3000</code>
<code>ws://ws.ifelse.io</code>
</p>

<fieldset id="configuration">
<p>
Expand All @@ -48,13 +51,21 @@ <h2>WebSocket demo</h2>
// elements
const configuration = document.getElementById('configuration');
const location = document.getElementById('location');
const codeblockWsLocation = document.getElementById('codeblock-ws-location');
const connectBtn = document.getElementById('connectBtn');
const disconnectBtn = document.getElementById('disconnectBtn');
const messaging = document.getElementById('messaging');
const message = document.getElementById('message');
const sendBtn = document.getElementById('sendBtn');
const logger = document.getElementById('logger');

const documentUrl = new URL(document.location);
const wsProtocol = documentUrl.protocol.includes('https') ? 'wss:' : 'ws:';
const wsPort = documentUrl.port ? `:${documentUrl.port}` : '';
const locationValue = `${wsProtocol}//${documentUrl.host}${wsPort}`;
location.value = locationValue;
codeblockWsLocation.innerText = locationValue;

// ws
let socket;

Expand Down

0 comments on commit 471349f

Please sign in to comment.