From df88d56678b6ee8fbd6f7f22c60d65f8b09f9cdb Mon Sep 17 00:00:00 2001 From: chimurai <655241+chimurai@users.noreply.github.com> Date: Sat, 20 Apr 2024 12:19:41 +0000 Subject: [PATCH] docs(websocket): improve example for online IDE --- 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;