From 471349f7335e364277bd8ca1b14ce62f722f2f34 Mon Sep 17 00:00:00 2001 From: Steven Chim <655241+chimurai@users.noreply.github.com> Date: Sat, 20 Apr 2024 14:23:05 +0200 Subject: [PATCH] docs(websocket): improve example for online IDE (#990) --- examples/websocket/index.html | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/examples/websocket/index.html b/examples/websocket/index.html index 74818a88..1a95aa80 100644 --- a/examples/websocket/index.html +++ b/examples/websocket/index.html @@ -21,7 +21,10 @@

WebSocket demo

-

Proxy ws://localhost:3000 to ws://ws.ifelse.io

+

+ Proxy ws://localhost:3000 ➡ + ws://ws.ifelse.io +

@@ -48,6 +51,7 @@

WebSocket demo

// 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'); @@ -55,6 +59,13 @@

WebSocket demo

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;