1
0
mirror of https://github.com/lxsang/antd-web-apps synced 2025-07-27 02:59:47 +02:00

new wvnc app

This commit is contained in:
Xuan Sang LE
2018-09-17 19:43:24 +02:00
parent c9c50df4f4
commit 467a36b531
11 changed files with 208 additions and 19 deletions

View File

@ -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)

View File

@ -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) ->

View 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

View File

@ -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) ###