diff --git a/examples/websocket.html b/examples/websocket.html new file mode 100644 index 0000000000000000000000000000000000000000..aed62c16959d3ac011c057a7d266f23277225e7f --- /dev/null +++ b/examples/websocket.html @@ -0,0 +1,43 @@ +<!DOCTYPE html> +<meta charset="utf-8" /> +<title>WebSocket Test</title> +<script language="javascript" type="text/javascript"> + + var out = function(message) { + var div = document.createElement('div'); + div.innerHTML = message; + document.getElementById('output').appendChild(div); + }; + + window.onload = function() { + var url = 'ws://' + location.host + '/ws'; + var num_messages = 0; + + websocket = new WebSocket(url); + websocket.onopen = function(ev) { + out('CONNECTED'); + var msg = 'Ðе вÑÑ‘ подчинÑетÑÑ Ñ€Ð°Ð·ÑƒÐ¼Ñƒ. Ðо вÑÑ‘ подчинÑетÑÑ ÑƒÐ¿Ð¾Ñ€Ñтву. '; + out('SENT: ' + msg); + websocket.send(msg); + }; + websocket.onclose = function(ev) { + out('DISCONNECTED'); + }; + websocket.onmessage = function(ev) { + if (!ev.data) return; // No data, this is a PING message, ignore it + out('<span style="color: blue;">RESPONSE: ' + ev.data + ' </span>'); + num_messages++; + if (num_messages > 100) { + websocket.send('exit'); + } + }; + websocket.onerror = function(ev) { + out('<span style="color: red; ">ERROR: </span> ' + ev.data); + }; + }; +</script> +<style> div {font: small Verdana; } </style> +<h2>Mongoose WebSocket Test</h2> + +<div id="output"></div> +</html>