mirror of
https://github.com/novnc/noVNC.git
synced 2026-06-03 02:49:40 +00:00
Import web-socket-js: a0fb3933ce5c824bcb882f5a1cf87e46de773ea8
web-socket-js is a flash based WebSockets emulator. From: http://github.com/gimite/web-socket-js
This commit is contained in:
70
include/web-socket-js/sample.html
Normal file
70
include/web-socket-js/sample.html
Normal file
@@ -0,0 +1,70 @@
|
||||
<!--
|
||||
Copyright: Hiroshi Ichikawa <http://gimite.net/en/>
|
||||
Lincense: New BSD Lincense
|
||||
-->
|
||||
|
||||
<html><head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<title>Sample of web_socket.js</title>
|
||||
|
||||
<!-- Include these three JS files: -->
|
||||
<script type="text/javascript" src="swfobject.js"></script>
|
||||
<script type="text/javascript" src="FABridge.js"></script>
|
||||
<script type="text/javascript" src="web_socket.js"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
// Set URL of your WebSocketMain.swf here:
|
||||
WebSocket.__swfLocation = "WebSocketMain.swf";
|
||||
|
||||
var ws;
|
||||
|
||||
function init() {
|
||||
|
||||
// Connect to Web Socket.
|
||||
// Change host/port here to your own Web Socket server.
|
||||
ws = new WebSocket("ws://localhost:10081/");
|
||||
|
||||
// Set event handlers.
|
||||
ws.onopen = function() {
|
||||
output("onopen");
|
||||
};
|
||||
ws.onmessage = function(e) {
|
||||
// e.data contains received string.
|
||||
output("onmessage: " + e.data);
|
||||
};
|
||||
ws.onclose = function() {
|
||||
output("onclose");
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
function onSubmit() {
|
||||
var input = document.getElementById("input");
|
||||
// You can send message to the Web Socket using ws.send.
|
||||
ws.send(input.value);
|
||||
output("send: " + input.value);
|
||||
input.value = "";
|
||||
input.focus();
|
||||
}
|
||||
|
||||
function onCloseClick() {
|
||||
ws.close();
|
||||
}
|
||||
|
||||
function output(str) {
|
||||
var log = document.getElementById("log");
|
||||
var escaped = str.replace(/&/, "&").replace(/</, "<").
|
||||
replace(/>/, ">").replace(/"/, """); // "
|
||||
log.innerHTML = escaped + "<br>" + log.innerHTML;
|
||||
}
|
||||
|
||||
</script>
|
||||
</head><body onload="init();">
|
||||
<form onsubmit="onSubmit(); return false;">
|
||||
<input type="text" id="input">
|
||||
<input type="submit" value="Send">
|
||||
<button onclick="onCloseClick(); return false;">close</button>
|
||||
</form>
|
||||
<div id="log"></div>
|
||||
</body></html>
|
||||
Reference in New Issue
Block a user