open-access-control-api/index.html

47 lines
1.6 KiB
HTML

<html>
<head>
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io();
// console.log("loaded socketio");
// connect to socketio
socket.on('connect', function(){
// send connect message
socket.send('hi '+window.location);
});
window.onload = function(){
cons = document.getElementById("console");
// handle user input
cons.onsubmit = function(){
inp = document.getElementById("input")
scr = document.getElementById("screen")
// send input to socketio
socket.emit('data',inp.value);
// console.log(inp.value);
scr.value += "> "+inp.value+"\r";
scr.scrollTop = scr.scrollHeight;
inp.value = "";
return false;
};
scr = document.getElementById("screen")
scr.value = ""; // reset input onload
// log data from socket
socket.on('data', function(data){
// console.log(data);
scr.value += "< "+data+"\r";
scr.scrollTop = scr.scrollHeight;
});
// log connect messages
socket.on('message', function(data){
console.log('message',window.location,data);
});
};
</script>
</head>
<form id="console">
<textarea cols=80 rows=20 id="screen"></textarea><br/>
<input id="input" type="text" />
<input id="submit" type="button" value="Submit" />
</form>
</html>