sercrod

WebSocket talkie

This playground connects to a WebSocket endpoint and sends simple text messages. Open this page in another browser or device that reaches the same server to see how a shared channel can be used.

Sample: WebSocket talkie

Code

<serc-rod
	data='{"name":"", "text":""}'
	*websocket="'wss://na-bla.com:8443/ws'"
	*into="ws_data"
>
	<h2>Sercrod WebSocket talkie</h2>

	<p *if="$ws_ready">WS: connected (same IP room)</p>
	<p *else>WS: not connected</p>

	<p>
		<label>
			Your name:
			<input type="text" *input="name">
		</label>
	</p>

	<p>
		<label>
			Message:
			<input type="text" *input="text">
		</label>
	</p>

	<p>
		<button
			*if="$ws_ready"
			*ws-send="(name || 'anonymous') + ': ' + text"
			@click="text = ''"
		>Send</button>
		<span *else>Waiting for connection...</span>
	</p>

	<h3>Last message from server</h3>
	<pre>%$ws_last%</pre>
</serc-rod>

Sample

Sercrod WebSocket talkie

WS: connected (same IP room)

WS: not connected

Waiting for connection...

Last message from server

%$ws_last%

Notes