mirror of
https://github.com/lxsang/antd-web-apps
synced 2024-12-27 09:58:20 +01:00
new wvnc app
This commit is contained in:
parent
c9c50df4f4
commit
467a36b531
@ -5,7 +5,7 @@ coffees = assets/coffee/bootstrap.coffee \
|
||||
assets/coffee/BaseObject.coffee \
|
||||
assets/coffee/APIManager.coffee \
|
||||
assets/coffee/MarkOn.coffee \
|
||||
|
||||
assets/coffee/WVNC.coffee
|
||||
|
||||
main: js
|
||||
- mkdir -p $(BUILDDIR)/assets
|
||||
@ -17,7 +17,7 @@ js:
|
||||
- rm assets/scripts/main.js
|
||||
for f in $(coffees); do (cat "$${f}"; echo) >> assets/scripts/main.coffee; done
|
||||
coffee --compile assets/scripts/main.coffee
|
||||
- rm assets/scripts/main.coffee
|
||||
-rm assets/scripts/main.coffee
|
||||
|
||||
clean:
|
||||
rm -rf $(BUILDDIR)/*
|
@ -1,9 +1,11 @@
|
||||
class APIManager extends window.classes.BaseObject
|
||||
constructor: () ->
|
||||
constructor: (@args) ->
|
||||
super "APIManager"
|
||||
|
||||
init: (cname) ->
|
||||
console.log(cname)
|
||||
init: () ->
|
||||
me = @
|
||||
return console.error "No class found" unless @args and @args.length > 0
|
||||
cname = (@args.splice 0,1)[0].trim()
|
||||
@ready()
|
||||
.then () ->
|
||||
if mobilecheck()
|
||||
@ -11,7 +13,7 @@ class APIManager extends window.classes.BaseObject
|
||||
# load the class
|
||||
return if not cname or cname is ""
|
||||
return console.error("Cannot find class ", cname) unless window.classes[cname]
|
||||
(new window.classes[cname]).init()
|
||||
(new window.classes[cname](me.args)).init()
|
||||
.catch ( m, s ) ->
|
||||
console.error(m, s)
|
||||
|
||||
|
@ -1,3 +1,14 @@
|
||||
# private function
|
||||
require = (lib) ->
|
||||
return new Promise (r, e) ->
|
||||
return r() if window.libraries[lib]
|
||||
$.getScript window.myuri + lib
|
||||
.done (d) ->
|
||||
window.libraries[lib] = true
|
||||
r()
|
||||
.fail (m, s) ->
|
||||
e(m, s)
|
||||
|
||||
class BaseObject
|
||||
constructor: (@name) ->
|
||||
|
||||
|
57
apps/assets/coffee/WVNC.coffee
Normal file
57
apps/assets/coffee/WVNC.coffee
Normal file
@ -0,0 +1,57 @@
|
||||
class WVNC extends window.classes.BaseObject
|
||||
constructor: (@args) ->
|
||||
super "WVNC"
|
||||
@socket = undefined
|
||||
@uri = undefined
|
||||
@uri = @args[0] if @args and @args.length > 0
|
||||
|
||||
init: () ->
|
||||
me = @
|
||||
@ready()
|
||||
.then () ->
|
||||
me.openSession()
|
||||
.catch (m, s) ->
|
||||
console.error(m, s)
|
||||
|
||||
openSession: () ->
|
||||
me = @
|
||||
@socket.close() if @socket
|
||||
return unless @uri
|
||||
@socket = new WebSocket @uri
|
||||
@socket.binaryType = "arraybuffer"
|
||||
@socket.onopen = () ->
|
||||
console.log "socket opened"
|
||||
me.initConnection()
|
||||
|
||||
@socket.onmessage = (e) ->
|
||||
me.consume e
|
||||
@socket.onclose = () ->
|
||||
me.socket = null
|
||||
console.log "socket closed"
|
||||
|
||||
initConnection: () ->
|
||||
vncserver = "localhost:5901"
|
||||
@socket.send(@buildCommand 0x01, vncserver)
|
||||
|
||||
buildCommand: (hex, o) ->
|
||||
data = undefined
|
||||
switch typeof o
|
||||
when 'string'
|
||||
data = (new TextEncoder()).encode(o)
|
||||
else
|
||||
data = o
|
||||
cmd = new Uint8Array data.length + 3
|
||||
cmd[0] = hex
|
||||
cmd[2] = data.length >> 8
|
||||
cmd[1] = data.length & 0x0F
|
||||
cmd.set data, 3
|
||||
console.log "the command is", cmd.buffer
|
||||
return cmd.buffer
|
||||
|
||||
|
||||
consume: (e) ->
|
||||
console.log e
|
||||
WVNC.dependencies = [
|
||||
]
|
||||
|
||||
makeclass "WVNC", WVNC
|
@ -8,6 +8,7 @@ window.mobilecheck = () ->
|
||||
|
||||
window.makeclass = (n, o) -> window.classes[n] = o
|
||||
|
||||
###
|
||||
window.require = (lib) ->
|
||||
return new Promise (r, e) ->
|
||||
return r() if window.libraries[lib]
|
||||
@ -16,4 +17,4 @@ window.require = (lib) ->
|
||||
window.libraries[lib] = true
|
||||
r()
|
||||
.fail (m, s) ->
|
||||
e(m, s)
|
||||
e(m, s) ###
|
||||
|
@ -1,6 +1,6 @@
|
||||
// Generated by CoffeeScript 1.12.7
|
||||
// Generated by CoffeeScript 1.9.3
|
||||
(function() {
|
||||
var APIManager, BaseObject, MarkOn,
|
||||
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; },
|
||||
hasProp = {}.hasOwnProperty;
|
||||
|
||||
@ -21,7 +21,20 @@
|
||||
return window.classes[n] = o;
|
||||
};
|
||||
|
||||
window.require = function(lib) {
|
||||
|
||||
/*
|
||||
window.require = (lib) ->
|
||||
return new Promise (r, e) ->
|
||||
return r() if window.libraries[lib]
|
||||
$.getScript window.myuri + lib
|
||||
.done (d) ->
|
||||
window.libraries[lib] = true
|
||||
r()
|
||||
.fail (m, s) ->
|
||||
e(m, s)
|
||||
*/
|
||||
|
||||
require = function(lib) {
|
||||
return new Promise(function(r, e) {
|
||||
if (window.libraries[lib]) {
|
||||
return r();
|
||||
@ -84,12 +97,18 @@
|
||||
APIManager = (function(superClass) {
|
||||
extend(APIManager, superClass);
|
||||
|
||||
function APIManager() {
|
||||
function APIManager(args) {
|
||||
this.args = args;
|
||||
APIManager.__super__.constructor.call(this, "APIManager");
|
||||
}
|
||||
|
||||
APIManager.prototype.init = function(cname) {
|
||||
console.log(cname);
|
||||
APIManager.prototype.init = function() {
|
||||
var cname, me;
|
||||
me = this;
|
||||
if (!(this.args && this.args.length > 0)) {
|
||||
return console.error("No class found");
|
||||
}
|
||||
cname = (this.args.splice(0, 1))[0].trim();
|
||||
return this.ready().then(function() {
|
||||
if (mobilecheck()) {
|
||||
mobileConsole.init();
|
||||
@ -100,7 +119,7 @@
|
||||
if (!window.classes[cname]) {
|
||||
return console.error("Cannot find class ", cname);
|
||||
}
|
||||
return (new window.classes[cname]).init();
|
||||
return (new window.classes[cname](me.args)).init();
|
||||
})["catch"](function(m, s) {
|
||||
return console.error(m, s);
|
||||
});
|
||||
@ -141,4 +160,88 @@
|
||||
|
||||
makeclass("MarkOn", MarkOn);
|
||||
|
||||
WVNC = (function(superClass) {
|
||||
extend(WVNC, superClass);
|
||||
|
||||
function WVNC(args) {
|
||||
this.args = args;
|
||||
WVNC.__super__.constructor.call(this, "WVNC");
|
||||
this.socket = void 0;
|
||||
this.uri = void 0;
|
||||
if (this.args && this.args.length > 0) {
|
||||
this.uri = this.args[0];
|
||||
}
|
||||
}
|
||||
|
||||
WVNC.prototype.init = function() {
|
||||
var me;
|
||||
me = this;
|
||||
return this.ready().then(function() {
|
||||
return me.openSession();
|
||||
})["catch"](function(m, s) {
|
||||
return console.error(m, s);
|
||||
});
|
||||
};
|
||||
|
||||
WVNC.prototype.openSession = function() {
|
||||
var me;
|
||||
me = this;
|
||||
if (this.socket) {
|
||||
this.socket.close();
|
||||
}
|
||||
if (!this.uri) {
|
||||
return;
|
||||
}
|
||||
this.socket = new WebSocket(this.uri);
|
||||
this.socket.binaryType = "arraybuffer";
|
||||
this.socket.onopen = function() {
|
||||
console.log("socket opened");
|
||||
return me.initConnection();
|
||||
};
|
||||
this.socket.onmessage = function(e) {
|
||||
return me.consume(e);
|
||||
};
|
||||
return this.socket.onclose = function() {
|
||||
me.socket = null;
|
||||
return console.log("socket closed");
|
||||
};
|
||||
};
|
||||
|
||||
WVNC.prototype.initConnection = function() {
|
||||
var vncserver;
|
||||
vncserver = "localhost:5901";
|
||||
return this.socket.send(this.buildCommand(0x01, vncserver));
|
||||
};
|
||||
|
||||
WVNC.prototype.buildCommand = function(hex, o) {
|
||||
var cmd, data;
|
||||
data = void 0;
|
||||
switch (typeof o) {
|
||||
case 'string':
|
||||
data = (new TextEncoder()).encode(o);
|
||||
break;
|
||||
default:
|
||||
data = o;
|
||||
}
|
||||
cmd = new Uint8Array(data.length + 3);
|
||||
cmd[0] = hex;
|
||||
cmd[2] = data.length >> 8;
|
||||
cmd[1] = data.length & 0x0F;
|
||||
cmd.set(data, 3);
|
||||
console.log("the command is", cmd.buffer);
|
||||
return cmd.buffer;
|
||||
};
|
||||
|
||||
WVNC.prototype.consume = function(e) {
|
||||
return console.log(e);
|
||||
};
|
||||
|
||||
return WVNC;
|
||||
|
||||
})(window.classes.BaseObject);
|
||||
|
||||
WVNC.dependencies = [];
|
||||
|
||||
makeclass("WVNC", WVNC);
|
||||
|
||||
}).call(this);
|
||||
|
@ -3,7 +3,7 @@ BaseController:subclass("MarkOnController", {
|
||||
})
|
||||
|
||||
function MarkOnController:index( ... )
|
||||
self.template:set("jsclass", "MarkOn")
|
||||
self.template:set("args", "['MarkOn']")
|
||||
return true
|
||||
end
|
||||
|
||||
|
13
apps/controllers/WvncController.lua
Normal file
13
apps/controllers/WvncController.lua
Normal file
@ -0,0 +1,13 @@
|
||||
BaseController:subclass("WvncController", {
|
||||
registry = {}
|
||||
})
|
||||
|
||||
function WvncController:index( ... )
|
||||
self.template:set("args", "['WVNC', 'wss://localhost:9195/wvnc']")
|
||||
return true
|
||||
end
|
||||
|
||||
function WvncController:actionnotfound(...)
|
||||
self.template:setView("index")
|
||||
return self:index(table.unpack({...}))
|
||||
end
|
@ -24,6 +24,7 @@ local REGISTRY = {}
|
||||
REGISTRY.logger = Logger:new{ levels = {INFO = true, ERROR = true, DEBUG = true}}
|
||||
REGISTRY.db = DBHelper:new{db="iosapps"}
|
||||
REGISTRY.layout = 'default'
|
||||
REGISTRY.fileaccess = true
|
||||
|
||||
REGISTRY.db:open()
|
||||
local router = Router:new{registry = REGISTRY}
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?lua
|
||||
local jsclass = __main__:get("jsclass")
|
||||
if jsclass == nil then jsclass = "" end
|
||||
local args = __main__:get("args")
|
||||
if args == nil then args = "[]" end
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
@ -16,8 +16,8 @@ if jsclass == nil then jsclass = "" end
|
||||
<script>
|
||||
$(window).on('load', function(){
|
||||
window.myuri = '<?=HTTP_ROOT?>';
|
||||
var manager = new window.classes.APIManager();
|
||||
manager.init('<?=jsclass?>');
|
||||
var manager = new window.classes.APIManager(<?=args?>);
|
||||
manager.init();
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
|
1
apps/views/default/wvnc/index.ls
Normal file
1
apps/views/default/wvnc/index.ls
Normal file
@ -0,0 +1 @@
|
||||
<h1>VNC screen here</h1>
|
Loading…
Reference in New Issue
Block a user