mirror of
https://github.com/lxsang/antd-web-apps
synced 2024-11-19 18:08:21 +01:00
first communication
This commit is contained in:
parent
467a36b531
commit
1b09ab53fc
@ -15,6 +15,7 @@ class WVNC extends window.classes.BaseObject
|
||||
|
||||
openSession: () ->
|
||||
me = @
|
||||
$("#stop").click (e) -> me.socket.close() if me.socket
|
||||
@socket.close() if @socket
|
||||
return unless @uri
|
||||
@socket = new WebSocket @uri
|
||||
@ -30,7 +31,7 @@ class WVNC extends window.classes.BaseObject
|
||||
console.log "socket closed"
|
||||
|
||||
initConnection: () ->
|
||||
vncserver = "localhost:5901"
|
||||
vncserver = "mrsang.local"
|
||||
@socket.send(@buildCommand 0x01, vncserver)
|
||||
|
||||
buildCommand: (hex, o) ->
|
||||
@ -50,7 +51,41 @@ class WVNC extends window.classes.BaseObject
|
||||
|
||||
|
||||
consume: (e) ->
|
||||
console.log e
|
||||
data = new Uint8Array e.data
|
||||
cmd = data[0]
|
||||
switch cmd
|
||||
when 0xFE #error
|
||||
data = data.subarray 1, data.length - 1
|
||||
dec = new TextDecoder("utf-8")
|
||||
console.log "Error",dec.decode(data)
|
||||
when 0x82
|
||||
console.log "Request for login"
|
||||
user = "mrsang"
|
||||
pass = "!x$@n9"
|
||||
arr = new Uint8Array user.length + pass.length + 1
|
||||
arr.set (new TextEncoder()).encode(user), 0
|
||||
arr.set ['\0'], user.length
|
||||
arr.set (new TextEncoder()).encode(pass), user.length + 1
|
||||
@socket.send(@buildCommand 0x03, arr)
|
||||
when 0x83
|
||||
console.log "resize"
|
||||
w = data[1] | (data[2]<<8)
|
||||
h = data[3] | (data[4]<<8)
|
||||
depth = data[5]
|
||||
console.log w,h,depth
|
||||
when 0x84
|
||||
console.log "update"
|
||||
x = data[1] | (data[2]<<8)
|
||||
y = data[3] | (data[4]<<8)
|
||||
w = data[5] | (data[6]<<8)
|
||||
h = data[7] | (data[8]<<8)
|
||||
pixels = data.subarray 9, data.length - 1
|
||||
console.log x,y,w,h, pixels.length
|
||||
else
|
||||
console.log cmd
|
||||
#@socket.close()
|
||||
|
||||
|
||||
WVNC.dependencies = [
|
||||
]
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 1.9.3
|
||||
// Generated by CoffeeScript 1.12.7
|
||||
(function() {
|
||||
var APIManager, BaseObject, MarkOn, WVNC, require,
|
||||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
||||
@ -186,6 +186,11 @@
|
||||
WVNC.prototype.openSession = function() {
|
||||
var me;
|
||||
me = this;
|
||||
$("#stop").click(function(e) {
|
||||
if (me.socket) {
|
||||
return me.socket.close();
|
||||
}
|
||||
});
|
||||
if (this.socket) {
|
||||
this.socket.close();
|
||||
}
|
||||
@ -209,7 +214,7 @@
|
||||
|
||||
WVNC.prototype.initConnection = function() {
|
||||
var vncserver;
|
||||
vncserver = "localhost:5901";
|
||||
vncserver = "mrsang.local";
|
||||
return this.socket.send(this.buildCommand(0x01, vncserver));
|
||||
};
|
||||
|
||||
@ -233,7 +238,40 @@
|
||||
};
|
||||
|
||||
WVNC.prototype.consume = function(e) {
|
||||
return console.log(e);
|
||||
var arr, cmd, data, dec, depth, h, pass, pixels, user, w, x, y;
|
||||
data = new Uint8Array(e.data);
|
||||
cmd = data[0];
|
||||
switch (cmd) {
|
||||
case 0xFE:
|
||||
data = data.subarray(1, data.length - 1);
|
||||
dec = new TextDecoder("utf-8");
|
||||
return console.log("Error", dec.decode(data));
|
||||
case 0x82:
|
||||
console.log("Request for login");
|
||||
user = "mrsang";
|
||||
pass = "!x$@n9";
|
||||
arr = new Uint8Array(user.length + pass.length + 1);
|
||||
arr.set((new TextEncoder()).encode(user), 0);
|
||||
arr.set(['\0'], user.length);
|
||||
arr.set((new TextEncoder()).encode(pass), user.length + 1);
|
||||
return this.socket.send(this.buildCommand(0x03, arr));
|
||||
case 0x83:
|
||||
console.log("resize");
|
||||
w = data[1] | (data[2] << 8);
|
||||
h = data[3] | (data[4] << 8);
|
||||
depth = data[5];
|
||||
return console.log(w, h, depth);
|
||||
case 0x84:
|
||||
console.log("update");
|
||||
x = data[1] | (data[2] << 8);
|
||||
y = data[3] | (data[4] << 8);
|
||||
w = data[5] | (data[6] << 8);
|
||||
h = data[7] | (data[8] << 8);
|
||||
pixels = data.subarray(9, data.length - 1);
|
||||
return console.log(x, y, w, h, pixels.length);
|
||||
default:
|
||||
return console.log(cmd);
|
||||
}
|
||||
};
|
||||
|
||||
return WVNC;
|
||||
|
@ -3,7 +3,7 @@ BaseController:subclass("WvncController", {
|
||||
})
|
||||
|
||||
function WvncController:index( ... )
|
||||
self.template:set("args", "['WVNC', 'wss://localhost:9195/wvnc']")
|
||||
self.template:set("args", "['WVNC', 'wss://localhost:9192/wvnc']")
|
||||
return true
|
||||
end
|
||||
|
||||
|
@ -1 +1,2 @@
|
||||
<h1>VNC screen here</h1>
|
||||
<h1>VNC screen here</h1>
|
||||
<a id="stop" href="#">STOP</a>
|
Loading…
Reference in New Issue
Block a user