Skip to content

Commit

Permalink
docs(websocket): improve example for online IDE
Browse files Browse the repository at this point in the history
  • Loading branch information
chimurai committed Apr 20, 2024
1 parent e644a22 commit df88d56
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion examples/websocket/index.html
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 df88d56

Please sign in to comment.