Convert wstelnet to use Websock.
This commit is contained in:
parent
124f28c63a
commit
bc96026fbf
|
@ -189,7 +189,7 @@ function send(arr) {
|
|||
|
||||
function send_string(str) {
|
||||
//Util.Debug(">> send_string: " + str);
|
||||
api.send_array(str.split('').map(
|
||||
api.send(str.split('').map(
|
||||
function (chr) { return chr.charCodeAt(0); } ) );
|
||||
}
|
||||
|
||||
|
@ -296,7 +296,7 @@ function constructor() {
|
|||
api.rQwait = rQwait;
|
||||
|
||||
api.flush = flush;
|
||||
api.send_array = send_array;
|
||||
api.send = send;
|
||||
api.send_string = send_string;
|
||||
|
||||
api.recv_message = recv_message;
|
||||
|
|
|
@ -46,14 +46,14 @@ Array.prototype.pushStr = function (str) {
|
|||
function do_send() {
|
||||
if (sQ.length > 0) {
|
||||
Util.Debug("Sending " + sQ);
|
||||
ws.send(Base64.encode(sQ));
|
||||
ws.send(sQ);
|
||||
sQ = [];
|
||||
}
|
||||
}
|
||||
|
||||
function do_recv(e) {
|
||||
function do_recv() {
|
||||
//console.log(">> do_recv");
|
||||
var arr = Base64.decode(e.data), str = "",
|
||||
var arr = ws.rQshiftBytes(ws.rQlen()), str = "",
|
||||
chr, cmd, code, value;
|
||||
|
||||
Util.Debug("Received array '" + arr + "'");
|
||||
|
@ -162,26 +162,8 @@ that.connect = function(host, port, encrypt) {
|
|||
}
|
||||
uri = scheme + host + ":" + port;
|
||||
Util.Info("connecting to " + uri);
|
||||
ws = new WebSocket(uri);
|
||||
|
||||
ws.onmessage = do_recv;
|
||||
|
||||
ws.onopen = function(e) {
|
||||
Util.Info(">> WebSockets.onopen");
|
||||
vt100.curs_set(true, true);
|
||||
connect_callback();
|
||||
Util.Info("<< WebSockets.onopen");
|
||||
};
|
||||
ws.onclose = function(e) {
|
||||
Util.Info(">> WebSockets.onclose");
|
||||
that.disconnect();
|
||||
Util.Info("<< WebSockets.onclose");
|
||||
};
|
||||
ws.onerror = function(e) {
|
||||
Util.Info(">> WebSockets.onerror");
|
||||
that.disconnect();
|
||||
Util.Info("<< WebSockets.onerror");
|
||||
};
|
||||
ws.open(uri);
|
||||
|
||||
Util.Debug("<< connect");
|
||||
}
|
||||
|
@ -199,6 +181,27 @@ that.disconnect = function() {
|
|||
|
||||
|
||||
function constructor() {
|
||||
/* Initialize Websock object */
|
||||
ws = new Websock();
|
||||
|
||||
ws.on('message', do_recv);
|
||||
ws.on('open', function(e) {
|
||||
Util.Info(">> WebSockets.onopen");
|
||||
vt100.curs_set(true, true);
|
||||
connect_callback();
|
||||
Util.Info("<< WebSockets.onopen");
|
||||
});
|
||||
ws.on('close', function(e) {
|
||||
Util.Info(">> WebSockets.onclose");
|
||||
that.disconnect();
|
||||
Util.Info("<< WebSockets.onclose");
|
||||
});
|
||||
ws.on('error', function(e) {
|
||||
Util.Info(">> WebSockets.onerror");
|
||||
that.disconnect();
|
||||
Util.Info("<< WebSockets.onerror");
|
||||
});
|
||||
|
||||
/* Initialize the terminal emulator/renderer */
|
||||
|
||||
vt100 = new VT100(80, 24, target);
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
<head>
|
||||
<title>WebSockets Telnet</title>
|
||||
<script src="include/base64.js"></script>
|
||||
<script src="include/websock.js"></script>
|
||||
<script src="include/util.js"></script>
|
||||
<script src="include/webutil.js"></script>
|
||||
<script src="include/keysym.js"></script>
|
||||
|
@ -58,25 +59,8 @@
|
|||
$D('connectButton').onclick = connect;
|
||||
}
|
||||
|
||||
/* If no builtin websockets then load web_socket.js */
|
||||
if (window.WebSocket) {
|
||||
VNC_native_ws = true;
|
||||
} else {
|
||||
VNC_native_ws = false;
|
||||
console.log("Loading web-socket-js flash bridge");
|
||||
var extra = "<script src='include/web-socket-js/swfobject.js'><\/script>";
|
||||
extra += "<script src='include/web-socket-js/FABridge.js'><\/script>";
|
||||
extra += "<script src='include/web-socket-js/web_socket.js'><\/script>";
|
||||
document.write(extra);
|
||||
}
|
||||
|
||||
window.onload = function() {
|
||||
console.log("onload");
|
||||
if (!VNC_native_ws) {
|
||||
console.log("initializing web-socket-js flash bridge");
|
||||
WebSocket.__swfLocation = "include/web-socket-js/WebSocketMain.swf";
|
||||
WebSocket.__initialize();
|
||||
}
|
||||
var url = document.location.href;
|
||||
$D('host').value = (url.match(/host=([^&#]*)/) || ['',''])[1];
|
||||
$D('port').value = (url.match(/port=([^&#]*)/) || ['',''])[1];
|
||||
|
|
Loading…
Reference in New Issue