diff --git a/apps/assets/coffee/WVNC.coffee b/apps/assets/coffee/WVNC.coffee index 935fe3c..9aeed00 100644 --- a/apps/assets/coffee/WVNC.coffee +++ b/apps/assets/coffee/WVNC.coffee @@ -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 = [ ] diff --git a/apps/assets/scripts/main.js b/apps/assets/scripts/main.js index c08870b..c768f8c 100644 --- a/apps/assets/scripts/main.js +++ b/apps/assets/scripts/main.js @@ -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; diff --git a/apps/controllers/WvncController.lua b/apps/controllers/WvncController.lua index 01c615f..2d100c7 100644 --- a/apps/controllers/WvncController.lua +++ b/apps/controllers/WvncController.lua @@ -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 diff --git a/apps/views/default/wvnc/index.ls b/apps/views/default/wvnc/index.ls index 7a2c8e9..9192b02 100644 --- a/apps/views/default/wvnc/index.ls +++ b/apps/views/default/wvnc/index.ls @@ -1 +1,2 @@ -

VNC screen here

\ No newline at end of file +

VNC screen here

+STOP \ No newline at end of file