1
0
mirror of https://github.com/lxsang/antd-web-apps synced 2024-11-19 18:08:21 +01:00

add remote building script support

This commit is contained in:
lxsang 2018-09-22 19:11:40 +02:00
parent 4709c5c3ed
commit 2b62fe27e9
17 changed files with 207 additions and 2264 deletions

View File

@ -5,7 +5,8 @@ coffees = assets/coffee/bootstrap.coffee \
assets/coffee/BaseObject.coffee \
assets/coffee/APIManager.coffee \
assets/coffee/MarkOn.coffee \
assets/coffee/WVNC.coffee
assets/coffee/WVNC.coffee \
assets/coffee/WebVNC.coffee
SED=sed
UNAME_S := $(shell uname -s)
@ -16,18 +17,13 @@ endif
main: js
- mkdir -p $(BUILDDIR)/assets
cp -rf $(copyfiles) $(BUILDDIR)
cp -r assets/css assets/scripts $(BUILDDIR)/assets
cp -r assets/css assets/scripts assets/shs $(BUILDDIR)/assets
- cd $(BUILDDIR) && ln -s ../grs ./rst
js:
- rm assets/scripts/main.*
for f in $(coffees); do (cat "$${f}"; echo) >> assets/scripts/main.coffee; done
coffee --compile assets/scripts/main.coffee
coffee --compile assets/coffee/decoder.coffee
$(SED) '2d' assets/coffee/decoder.js > assets/scripts/tmp.js
$(SED) '$$ d' assets/scripts/tmp.js > assets/scripts/decoder.js
-rm assets/coffee/decoder.js
-rm assets/scripts/tmp.js
-rm assets/scripts/main.coffee
clean:

View File

@ -1,257 +0,0 @@
class WVNC extends window.classes.BaseObject
constructor: (@args) ->
super "WVNC"
@socket = undefined
@uri = undefined
@uri = @args[0] if @args and @args.length > 0
@canvas = undefined
@canvas = ($ @args[1])[0] if @args and @args.length > 1
@scale = 0.8
@decoder = new Worker('/assets/scripts/decoder.js')
me = @
@mouseMask = 0
@decoder.onmessage = (e) ->
me.process e.data
init: () ->
me = @
@ready()
.then () ->
$("#stop").click (e) -> me.socket.close() if me.socket
$("#connect").click (e) ->
me.openSession()
me.initInputEvent()
.catch (m, s) ->
console.error(m, s)
initInputEvent: () ->
me = @
getMousePos = (e) ->
rect = me.canvas.getBoundingClientRect()
pos=
x: Math.floor((e.clientX - rect.left) / me.scale)
y: Math.floor((e.clientY - rect.top) / me.scale)
return pos
sendMouseLocation = (e) ->
p = getMousePos e
me.sendPointEvent p.x, p.y, me.mouseMask
return unless me.canvas
($ me.canvas).css "cursor", "none"
($ me.canvas).contextmenu (e) ->
e.preventDefault()
return false
($ me.canvas).mousemove (e) -> sendMouseLocation e
($ me.canvas).mousedown (e) ->
state = 1 << e.button
me.mouseMask = me.mouseMask | state
sendMouseLocation e
#e.preventDefault()
($ me.canvas).mouseup (e) ->
state = 1 << e.button
me.mouseMask = me.mouseMask & (~state)
sendMouseLocation e
#e.preventDefault()
me.canvas.onkeydown = me.canvas.onkeyup = (e) ->
# get the key code
keycode = e.keyCode
#console.log e
switch keycode
when 8 then code = 0xFF08 #back space
when 9 then code = 0xff89 #0xFF09 # tab ?
when 13 then code = 0xFF0D # return
when 27 then code = 0xFF1B # esc
when 46 then code = 0xFFFF # delete to verify
when 38 then code = 0xFF52 # up
when 40 then code = 0xFF54 # down
when 37 then code = 0xFF51 # left
when 39 then code = 0xFF53 # right
when 91 then code = 0xFFE7 # meta left
when 93 then code = 0xFFE8 # meta right
when 16 then code = 0xFFE1 # shift left
when 17 then code = 0xFFE3 # ctrl left
when 18 then code = 0xFFE9 # alt left
when 20 then code = 0xFFE5 # capslock
when 113 then code = 0xFFBF # f2
when 112 then code = 0xFFBE # f1
when 114 then code = 0xFFC0 # f3
when 115 then code = 0xFFC1 # f4
when 116 then code = 0xFFC2 # f5
when 117 then code = 0xFFC3 # f6
when 118 then code = 0xFFC4 # f7
when 119 then code = 0xFFC5 # f8
when 120 then code = 0xFFC6 # f9
when 121 then code = 0xFFC7 # f10
when 122 then code = 0xFFC8 # f11
when 123 then code = 0xFFC9 # f12
else
code = e.key.charCodeAt(0) #if not e.ctrlKey and not e.altKey
#if ((keycode > 47 and keycode < 58) or (keycode > 64 and keycode < 91) or (keycode > 95 and keycode < 112) or (keycode > 185 and keycode < 193) or (keycode > 218 && keycode < 223))
# code = e.key.charCodeAt(0)
#else
# code = keycode
e.preventDefault()
return unless code
if e.type is "keydown"
me.sendKeyEvent code, 1
else if e.type is "keyup"
me.sendKeyEvent code, 0
# mouse wheel event
hamster = Hamster @canvas
hamster.wheel (event, delta, deltaX, deltaY) ->
p = getMousePos event.originalEvent
if delta > 0
me.sendPointEvent p.x, p.y, 8
me.sendPointEvent p.x, p.y, 0
return
me.sendPointEvent p.x, p.y, 16
me.sendPointEvent p.x, p.y, 0
initCanvas: (w, h , d) ->
me = @
@depth = d
@canvas.width = w
@canvas.height = h
@engine =
w: w,
h: h,
depth: @depth,
wasm: true
@decoder.postMessage @engine
@setScale @scale
process: (msg) ->
if not @socket
return
data = new Uint8Array msg.pixels
#w = @buffer.width * @scale
#h = @buffer.height * @scale
ctx = @canvas.getContext "2d", { alpha: false }
imgData = ctx.createImageData msg.w, msg.h
imgData.data.set data
ctx.putImageData imgData, msg.x, msg.y
setScale: (n) ->
@scale = n
@canvas.style.transformOrigin = '0 0'
@canvas.style.transform = 'scale(' + n + ')'
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 = "192.168.1.20:5901"
data = new Uint8Array vncserver.length + 3
data[0] = 32 # bbp
###
flag:
0: raw data no compress
1: jpeg no compress
2: raw data compressed by zlib
3: jpeg data compressed by zlib
###
data[1] = 1
data[2] = 40 # jpeg quality
## rate in milisecond
data.set (new TextEncoder()).encode(vncserver), 3
@socket.send(@buildCommand 0x01, data)
sendPointEvent: (x, y, mask) ->
return unless @socket
data = new Uint8Array 5
data[0] = x & 0xFF
data[1] = x >> 8
data[2] = y & 0xFF
data[3] = y >> 8
data[4] = mask
@socket.send( @buildCommand 0x05, data )
sendKeyEvent: (code, v) ->
return unless @socket
data = new Uint8Array 3
data[0] = code & 0xFF
data[1] = code >> 8
data[2] = v
console.log code, v
@socket.send( @buildCommand 0x06, data )
buildCommand: (hex, o) ->
data = undefined
switch typeof o
when 'string'
data = (new TextEncoder()).encode(o)
when 'number'
data = new Uint8Array [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) ->
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 0x81
console.log "Request for password"
pass = "lxsan9"#"!x$@n9"
@socket.send (@buildCommand 0x02, pass)
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]
@initCanvas w, h, depth
# status command for ack
@socket.send(@buildCommand 0x04, 1)
when 0x84
# send data to web assembly for decoding
@decoder.postMessage data.buffer, [data.buffer]
else
console.log cmd
WVNC.dependencies = [
"/assets/scripts/hamster.js"
]
makeclass "WVNC", WVNC

View File

@ -0,0 +1,49 @@
class WebVNC extends window.classes.BaseObject
constructor: () ->
super "WebVNC"
init: () ->
me = @
@ready()
.then () ->
me.initVNCClient()
.catch (m, s) ->
console.error(m, s)
initVNCClient: () ->
args =
{
element: 'canvas',
ws: 'wss://localhost:9192/wvnc',
worker: '/assets/scripts/decoder.js'
}
@client = new WVNC args
me = @
@client.onpassword = () ->
return new Promise (r,e) ->
r('lxsan9')
@client.oncredential = () ->
return new Promise (r,e) ->
r('mrsang', '!x$@n9')
@client.oncopy = (text) ->
($ "#clipboard")[0].value = text
@client.init()
.then () ->
$("#connect").click (e) ->
me.client.connect "192.168.1.20:5901", {
bbp: 32,
flag: 3,
quality: 30
}
$("#stop").click (e) ->
me.client.disconnect()
$("#btclipboard").click (e) ->
me.client.sendTextAsClipboard ($ "#clipboard")[0].value
.catch (m,s) ->
console.error m, s
WebVNC.dependencies = [
"/assets/scripts/wvnc.js"
]
makeclass "WebVNC", WebVNC

View File

@ -1,133 +0,0 @@
#zlib library
importScripts('wvnc_asm.js')
#zlib library
importScripts('pako.min.js')
# jpeg library
importScripts('jpeg-decoder.js')
api = {}
engine = undefined
#frame_buffer = undefined
Module.onRuntimeInitialized = () ->
api =
{
createBuffer: Module.cwrap('create_buffer', 'number', ['number', 'number']),
destroyBuffer: Module.cwrap('destroy_buffer', '', ['number']),
updateBuffer: Module.cwrap("update", 'number', ['number', 'number', 'number', 'number', 'number', 'number']),
decodeBuffer: Module.cwrap("decode",'number', ['number', 'number', 'number','number'] )
}
pixelValue = (value, depth) ->
pixel =
r: 255
g: 255
b: 255
a: 255
#console.log("len is" + arr.length)
if depth is 24 or depth is 32
pixel.r = value & 0xFF
pixel.g = (value >> 8) & 0xFF
pixel.b = (value >> 16) & 0xFF
else if depth is 16
pixel.r = (value & 0x1F) * (255 / 31)
pixel.g = ((value >> 5) & 0x3F) * (255 / 63)
pixel.b = ((value >> 11) & 0x1F) * (255 / 31)
#console.log pixel
return pixel
getImageData = (d) ->
return d.pixels if engine.depth is 32
step = engine.depth / 8
npixels = d.pixels.length / step
data = new Uint8ClampedArray d.w * d.h * 4
for i in [0..npixels - 1]
value = 0
value = value | d.pixels[i * step + j] << (j * 8) for j in [0..step - 1]
pixel = pixelValue value, engine.depth
data[i * 4] = pixel.r
data[i * 4 + 1] = pixel.g
data[i * 4 + 2] = pixel.b
data[i * 4 + 3] = pixel.a
return data
decodeRaw = (d) ->
d.pixels = getImageData d
return d
decodeJPEG = (d) ->
raw = decode d.pixels, { useTArray: true, colorTransform: true }
d.pixels = raw.data
return d
###
blob = new Blob [d.pixels], { type: "image/jpeg" }
reader = new FileReader()
reader.onloadend = () ->
d.pixels = reader.result
postMessage d
reader.readAsDataURL blob
###
update = (msg) ->
d = {}
#ecconho "native"
data = new Uint8Array msg
d.x = data[1] | (data[2]<<8)
d.y = data[3] | (data[4]<<8)
d.w = data[5] | (data[6]<<8)
d.h = data[7] | (data[8]<<8)
d.flag = data[9]
d.pixels = data.subarray 10
# the zlib is slower than expected
switch d.flag
when 0x0 # raw data
raw = decodeRaw d
when 0x1 # jpeg data
raw = decodeJPEG(d)
when 0x2 # raw compress in zlib format
d.pixels = pako.inflate(d.pixels)
raw = decodeRaw d
when 0x3 # jpeg compress in zlib format
d.pixels = pako.inflate(d.pixels)
raw = decodeJPEG(d)
return unless raw
raw.pixels = raw.pixels.buffer
# fill the rectangle
postMessage raw, [raw.pixels]
wasm_update = (msg) ->
datain = new Uint8Array msg
x = datain[1] | (datain[2] << 8)
y = datain[3] | (datain[4] << 8)
w = datain[5] | (datain[6] << 8)
h = datain[7] | (datain[8] << 8)
flag = datain[9]
p = api.createBuffer datain.length
Module.HEAP8.set datain, p
size = w * h * 4
po = api.decodeBuffer p, datain.length, engine.depth, size
#api.updateBuffer frame_buffer, p, datain.length, engine.w, engine.h, engine.depth
# create buffer array and send back to main
dataout = new Uint8Array Module.HEAP8.buffer, po, size
# console.log dataout
msg = {}
tmp = new Uint8Array size
tmp.set dataout, 0
msg.pixels = tmp.buffer
msg.x = x
msg.y = y
msg.w = w
msg.h = h
postMessage msg, [msg.pixels]
api.destroyBuffer p
if flag isnt 0x0 or engine.depth isnt 32
api.destroyBuffer po
onmessage = (e) ->
if e.data.depth
engine = e.data
#api.destroyBuffer frame_buffer if frame_buffer
#frame_buffer = api.createBuffer engine.w * engine.h * 4
#else if e.data.cleanup
# api.destroyBuffer frame_buffer if frame_buffer
else
return wasm_update e.data if engine.wasm
update e.data

View File

@ -1,159 +1 @@
// Generated by CoffeeScript 1.12.7
var api, decodeJPEG, decodeRaw, engine, getImageData, onmessage, pixelValue, update, wasm_update;
importScripts('wvnc_asm.js');
importScripts('pako.min.js');
importScripts('jpeg-decoder.js');
api = {};
engine = void 0;
Module.onRuntimeInitialized = function() {
return api = {
createBuffer: Module.cwrap('create_buffer', 'number', ['number', 'number']),
destroyBuffer: Module.cwrap('destroy_buffer', '', ['number']),
updateBuffer: Module.cwrap("update", 'number', ['number', 'number', 'number', 'number', 'number', 'number']),
decodeBuffer: Module.cwrap("decode", 'number', ['number', 'number', 'number', 'number'])
};
};
pixelValue = function(value, depth) {
var pixel;
pixel = {
r: 255,
g: 255,
b: 255,
a: 255
};
if (depth === 24 || depth === 32) {
pixel.r = value & 0xFF;
pixel.g = (value >> 8) & 0xFF;
pixel.b = (value >> 16) & 0xFF;
} else if (depth === 16) {
pixel.r = (value & 0x1F) * (255 / 31);
pixel.g = ((value >> 5) & 0x3F) * (255 / 63);
pixel.b = ((value >> 11) & 0x1F) * (255 / 31);
}
return pixel;
};
getImageData = function(d) {
var data, i, j, k, l, npixels, pixel, ref, ref1, step, value;
if (engine.depth === 32) {
return d.pixels;
}
step = engine.depth / 8;
npixels = d.pixels.length / step;
data = new Uint8ClampedArray(d.w * d.h * 4);
for (i = k = 0, ref = npixels - 1; 0 <= ref ? k <= ref : k >= ref; i = 0 <= ref ? ++k : --k) {
value = 0;
for (j = l = 0, ref1 = step - 1; 0 <= ref1 ? l <= ref1 : l >= ref1; j = 0 <= ref1 ? ++l : --l) {
value = value | d.pixels[i * step + j] << (j * 8);
}
pixel = pixelValue(value, engine.depth);
data[i * 4] = pixel.r;
data[i * 4 + 1] = pixel.g;
data[i * 4 + 2] = pixel.b;
data[i * 4 + 3] = pixel.a;
}
return data;
};
decodeRaw = function(d) {
d.pixels = getImageData(d);
return d;
};
decodeJPEG = function(d) {
var raw;
raw = decode(d.pixels, {
useTArray: true,
colorTransform: true
});
d.pixels = raw.data;
return d;
/*
blob = new Blob [d.pixels], { type: "image/jpeg" }
reader = new FileReader()
reader.onloadend = () ->
d.pixels = reader.result
postMessage d
reader.readAsDataURL blob
*/
};
update = function(msg) {
var d, data, raw;
d = {};
data = new Uint8Array(msg);
d.x = data[1] | (data[2] << 8);
d.y = data[3] | (data[4] << 8);
d.w = data[5] | (data[6] << 8);
d.h = data[7] | (data[8] << 8);
d.flag = data[9];
d.pixels = data.subarray(10);
switch (d.flag) {
case 0x0:
raw = decodeRaw(d);
break;
case 0x1:
raw = decodeJPEG(d);
break;
case 0x2:
d.pixels = pako.inflate(d.pixels);
raw = decodeRaw(d);
break;
case 0x3:
d.pixels = pako.inflate(d.pixels);
raw = decodeJPEG(d);
}
if (!raw) {
return;
}
raw.pixels = raw.pixels.buffer;
return postMessage(raw, [raw.pixels]);
};
wasm_update = function(msg) {
var datain, dataout, flag, h, p, po, size, tmp, w, x, y;
datain = new Uint8Array(msg);
x = datain[1] | (datain[2] << 8);
y = datain[3] | (datain[4] << 8);
w = datain[5] | (datain[6] << 8);
h = datain[7] | (datain[8] << 8);
flag = datain[9];
p = api.createBuffer(datain.length);
Module.HEAP8.set(datain, p);
size = w * h * 4;
po = api.decodeBuffer(p, datain.length, engine.depth, size);
dataout = new Uint8Array(Module.HEAP8.buffer, po, size);
msg = {};
tmp = new Uint8Array(size);
tmp.set(dataout, 0);
msg.pixels = tmp.buffer;
msg.x = x;
msg.y = y;
msg.w = w;
msg.h = h;
postMessage(msg, [msg.pixels]);
api.destroyBuffer(p);
if (flag !== 0x0 || engine.depth !== 32) {
return api.destroyBuffer(po);
}
};
onmessage = function(e) {
if (e.data.depth) {
return engine = e.data;
} else {
if (engine.wasm) {
return wasm_update(e.data);
}
return update(e.data);
}
};
var api,onmessage,resolution,wasm_update;importScripts("wvnc_asm.js"),api={},resolution=void 0,Module.onRuntimeInitialized=function(){return api={createBuffer:Module.cwrap("create_buffer","number",["number","number"]),destroyBuffer:Module.cwrap("destroy_buffer","",["number"]),updateBuffer:Module.cwrap("update","number",["number","number","number","number","number","number"]),decodeBuffer:Module.cwrap("decode","number",["number","number","number","number"])}},wasm_update=function(e){var r,u,n,t,a,o,d,f,i,s,m;if(s=(r=new Uint8Array(e))[1]|r[2]<<8,m=r[3]|r[4]<<8,i=r[5]|r[6]<<8,t=r[7]|r[8]<<8,n=r[9],a=api.createBuffer(r.length),Module.HEAP8.set(r,a),d=i*t*4,o=api.decodeBuffer(a,r.length,resolution.depth,d),u=new Uint8Array(Module.HEAP8.buffer,o,d),e={},(f=new Uint8Array(d)).set(u,0),e.pixels=f.buffer,e.x=s,e.y=m,e.w=i,e.h=t,postMessage(e,[e.pixels]),api.destroyBuffer(a),0!==n||32!==resolution.depth)return api.destroyBuffer(o)},onmessage=function(e){return e.data.depth?resolution=e.data:wasm_update(e.data)};

View File

@ -1,327 +0,0 @@
/*
* Hamster.js v1.1.2
* (c) 2013 Monospaced http://monospaced.com
* License: MIT
*/
(function(window, document){
'use strict';
/**
* Hamster
* use this to create instances
* @returns {Hamster.Instance}
* @constructor
*/
var Hamster = function(element) {
return new Hamster.Instance(element);
};
// default event name
Hamster.SUPPORT = 'wheel';
// default DOM methods
Hamster.ADD_EVENT = 'addEventListener';
Hamster.REMOVE_EVENT = 'removeEventListener';
Hamster.PREFIX = '';
// until browser inconsistencies have been fixed...
Hamster.READY = false;
Hamster.Instance = function(element){
if (!Hamster.READY) {
// fix browser inconsistencies
Hamster.normalise.browser();
// Hamster is ready...!
Hamster.READY = true;
}
this.element = element;
// store attached event handlers
this.handlers = [];
// return instance
return this;
};
/**
* create new hamster instance
* all methods should return the instance itself, so it is chainable.
* @param {HTMLElement} element
* @returns {Hamster.Instance}
* @constructor
*/
Hamster.Instance.prototype = {
/**
* bind events to the instance
* @param {Function} handler
* @param {Boolean} useCapture
* @returns {Hamster.Instance}
*/
wheel: function onEvent(handler, useCapture){
Hamster.event.add(this, Hamster.SUPPORT, handler, useCapture);
// handle MozMousePixelScroll in older Firefox
if (Hamster.SUPPORT === 'DOMMouseScroll') {
Hamster.event.add(this, 'MozMousePixelScroll', handler, useCapture);
}
return this;
},
/**
* unbind events to the instance
* @param {Function} handler
* @param {Boolean} useCapture
* @returns {Hamster.Instance}
*/
unwheel: function offEvent(handler, useCapture){
// if no handler argument,
// unbind the last bound handler (if exists)
if (handler === undefined && (handler = this.handlers.slice(-1)[0])) {
handler = handler.original;
}
Hamster.event.remove(this, Hamster.SUPPORT, handler, useCapture);
// handle MozMousePixelScroll in older Firefox
if (Hamster.SUPPORT === 'DOMMouseScroll') {
Hamster.event.remove(this, 'MozMousePixelScroll', handler, useCapture);
}
return this;
}
};
Hamster.event = {
/**
* cross-browser 'addWheelListener'
* @param {Instance} hamster
* @param {String} eventName
* @param {Function} handler
* @param {Boolean} useCapture
*/
add: function add(hamster, eventName, handler, useCapture){
// store the original handler
var originalHandler = handler;
// redefine the handler
handler = function(originalEvent){
if (!originalEvent) {
originalEvent = window.event;
}
// create a normalised event object,
// and normalise "deltas" of the mouse wheel
var event = Hamster.normalise.event(originalEvent),
delta = Hamster.normalise.delta(originalEvent);
// fire the original handler with normalised arguments
return originalHandler(event, delta[0], delta[1], delta[2]);
};
// cross-browser addEventListener
hamster.element[Hamster.ADD_EVENT](Hamster.PREFIX + eventName, handler, useCapture || false);
// store original and normalised handlers on the instance
hamster.handlers.push({
original: originalHandler,
normalised: handler
});
},
/**
* removeWheelListener
* @param {Instance} hamster
* @param {String} eventName
* @param {Function} handler
* @param {Boolean} useCapture
*/
remove: function remove(hamster, eventName, handler, useCapture){
// find the normalised handler on the instance
var originalHandler = handler,
lookup = {},
handlers;
for (var i = 0, len = hamster.handlers.length; i < len; ++i) {
lookup[hamster.handlers[i].original] = hamster.handlers[i];
}
handlers = lookup[originalHandler];
handler = handlers.normalised;
// cross-browser removeEventListener
hamster.element[Hamster.REMOVE_EVENT](Hamster.PREFIX + eventName, handler, useCapture || false);
// remove original and normalised handlers from the instance
for (var h in hamster.handlers) {
if (hamster.handlers[h] == handlers) {
hamster.handlers.splice(h, 1);
break;
}
}
}
};
/**
* these hold the lowest deltas,
* used to normalise the delta values
* @type {Number}
*/
var lowestDelta,
lowestDeltaXY;
Hamster.normalise = {
/**
* fix browser inconsistencies
*/
browser: function normaliseBrowser(){
// detect deprecated wheel events
if (!('onwheel' in document || document.documentMode >= 9)) {
Hamster.SUPPORT = document.onmousewheel !== undefined ?
'mousewheel' : // webkit and IE < 9 support at least "mousewheel"
'DOMMouseScroll'; // assume remaining browsers are older Firefox
}
// detect deprecated event model
if (!window.addEventListener) {
// assume IE < 9
Hamster.ADD_EVENT = 'attachEvent';
Hamster.REMOVE_EVENT = 'detachEvent';
Hamster.PREFIX = 'on';
}
},
/**
* create a normalised event object
* @param {Function} originalEvent
* @returns {Object} event
*/
event: function normaliseEvent(originalEvent){
var event = {
// keep a reference to the original event object
originalEvent: originalEvent,
target: originalEvent.target || originalEvent.srcElement,
type: 'wheel',
deltaMode: originalEvent.type === 'MozMousePixelScroll' ? 0 : 1,
deltaX: 0,
deltaZ: 0,
preventDefault: function(){
if (originalEvent.preventDefault) {
originalEvent.preventDefault();
} else {
originalEvent.returnValue = false;
}
},
stopPropagation: function(){
if (originalEvent.stopPropagation) {
originalEvent.stopPropagation();
} else {
originalEvent.cancelBubble = false;
}
}
};
// calculate deltaY (and deltaX) according to the event
// 'mousewheel'
if (originalEvent.wheelDelta) {
event.deltaY = - 1/40 * originalEvent.wheelDelta;
}
// webkit
if (originalEvent.wheelDeltaX) {
event.deltaX = - 1/40 * originalEvent.wheelDeltaX;
}
// 'DomMouseScroll'
if (originalEvent.detail) {
event.deltaY = originalEvent.detail;
}
return event;
},
/**
* normalise 'deltas' of the mouse wheel
* @param {Function} originalEvent
* @returns {Array} deltas
*/
delta: function normaliseDelta(originalEvent){
var delta = 0,
deltaX = 0,
deltaY = 0,
absDelta = 0,
absDeltaXY = 0,
fn;
// normalise deltas according to the event
// 'wheel' event
if (originalEvent.deltaY) {
deltaY = originalEvent.deltaY * -1;
delta = deltaY;
}
if (originalEvent.deltaX) {
deltaX = originalEvent.deltaX;
delta = deltaX * -1;
}
// 'mousewheel' event
if (originalEvent.wheelDelta) {
delta = originalEvent.wheelDelta;
}
// webkit
if (originalEvent.wheelDeltaY) {
deltaY = originalEvent.wheelDeltaY;
}
if (originalEvent.wheelDeltaX) {
deltaX = originalEvent.wheelDeltaX * -1;
}
// 'DomMouseScroll' event
if (originalEvent.detail) {
delta = originalEvent.detail * -1;
}
// Don't return NaN
if (delta === 0) {
return [0, 0, 0];
}
// look for lowest delta to normalize the delta values
absDelta = Math.abs(delta);
if (!lowestDelta || absDelta < lowestDelta) {
lowestDelta = absDelta;
}
absDeltaXY = Math.max(Math.abs(deltaY), Math.abs(deltaX));
if (!lowestDeltaXY || absDeltaXY < lowestDeltaXY) {
lowestDeltaXY = absDeltaXY;
}
// convert deltas to whole numbers
fn = delta > 0 ? 'floor' : 'ceil';
delta = Math[fn](delta / lowestDelta);
deltaX = Math[fn](deltaX / lowestDeltaXY);
deltaY = Math[fn](deltaY / lowestDeltaXY);
return [delta, deltaX, deltaY];
}
};
if (typeof window.define === 'function' && window.define.amd) {
// AMD
window.define('hamster', [], function(){
return Hamster;
});
} else if (typeof exports === 'object') {
// CommonJS
module.exports = Hamster;
} else {
// Browser global
window.Hamster = Hamster;
}
})(window, window.document);

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
// Generated by CoffeeScript 1.12.7
(function() {
var APIManager, BaseObject, MarkOn, WVNC, require,
var APIManager, BaseObject, MarkOn, WebVNC, 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;
@ -97,8 +97,8 @@
APIManager = (function(superClass) {
extend(APIManager, superClass);
function APIManager(args) {
this.args = args;
function APIManager(args1) {
this.args = args1;
APIManager.__super__.constructor.call(this, "APIManager");
}
@ -160,370 +160,70 @@
makeclass("MarkOn", MarkOn);
WVNC = (function(superClass) {
extend(WVNC, superClass);
WebVNC = (function(superClass) {
extend(WebVNC, superClass);
function WVNC(args) {
var me;
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];
}
this.canvas = void 0;
if (this.args && this.args.length > 1) {
this.canvas = ($(this.args[1]))[0];
}
this.scale = 0.8;
this.decoder = new Worker('/assets/scripts/decoder.js');
me = this;
this.mouseMask = 0;
this.decoder.onmessage = function(e) {
return me.process(e.data);
};
function WebVNC() {
WebVNC.__super__.constructor.call(this, "WebVNC");
}
WVNC.prototype.init = function() {
WebVNC.prototype.init = function() {
var me;
me = this;
return this.ready().then(function() {
$("#stop").click(function(e) {
if (me.socket) {
return me.socket.close();
}
});
$("#connect").click(function(e) {
return me.openSession();
});
return me.initInputEvent();
return me.initVNCClient();
})["catch"](function(m, s) {
return console.error(m, s);
});
};
WVNC.prototype.initInputEvent = function() {
var getMousePos, hamster, me, sendMouseLocation;
WebVNC.prototype.initVNCClient = function() {
var args, me;
args = {
element: 'canvas',
ws: 'wss://localhost:9192/wvnc',
worker: '/assets/scripts/decoder.js'
};
this.client = new WVNC(args);
me = this;
getMousePos = function(e) {
var pos, rect;
rect = me.canvas.getBoundingClientRect();
pos = {
x: Math.floor((e.clientX - rect.left) / me.scale),
y: Math.floor((e.clientY - rect.top) / me.scale)
};
return pos;
this.client.onpassword = function() {
return new Promise(function(r, e) {
return r('lxsan9');
});
};
sendMouseLocation = function(e) {
var p;
p = getMousePos(e);
return me.sendPointEvent(p.x, p.y, me.mouseMask);
this.client.oncredential = function() {
return new Promise(function(r, e) {
return r('mrsang', '!x$@n9');
});
};
if (!me.canvas) {
return;
}
($(me.canvas)).css("cursor", "none");
($(me.canvas)).contextmenu(function(e) {
e.preventDefault();
return false;
});
($(me.canvas)).mousemove(function(e) {
return sendMouseLocation(e);
});
($(me.canvas)).mousedown(function(e) {
var state;
state = 1 << e.button;
me.mouseMask = me.mouseMask | state;
return sendMouseLocation(e);
});
($(me.canvas)).mouseup(function(e) {
var state;
state = 1 << e.button;
me.mouseMask = me.mouseMask & (~state);
return sendMouseLocation(e);
});
me.canvas.onkeydown = me.canvas.onkeyup = function(e) {
var code, keycode;
keycode = e.keyCode;
switch (keycode) {
case 8:
code = 0xFF08;
break;
case 9:
code = 0xff89;
break;
case 13:
code = 0xFF0D;
break;
case 27:
code = 0xFF1B;
break;
case 46:
code = 0xFFFF;
break;
case 38:
code = 0xFF52;
break;
case 40:
code = 0xFF54;
break;
case 37:
code = 0xFF51;
break;
case 39:
code = 0xFF53;
break;
case 91:
code = 0xFFE7;
break;
case 93:
code = 0xFFE8;
break;
case 16:
code = 0xFFE1;
break;
case 17:
code = 0xFFE3;
break;
case 18:
code = 0xFFE9;
break;
case 20:
code = 0xFFE5;
break;
case 113:
code = 0xFFBF;
break;
case 112:
code = 0xFFBE;
break;
case 114:
code = 0xFFC0;
break;
case 115:
code = 0xFFC1;
break;
case 116:
code = 0xFFC2;
break;
case 117:
code = 0xFFC3;
break;
case 118:
code = 0xFFC4;
break;
case 119:
code = 0xFFC5;
break;
case 120:
code = 0xFFC6;
break;
case 121:
code = 0xFFC7;
break;
case 122:
code = 0xFFC8;
break;
case 123:
code = 0xFFC9;
break;
default:
code = e.key.charCodeAt(0);
}
e.preventDefault();
if (!code) {
return;
}
if (e.type === "keydown") {
return me.sendKeyEvent(code, 1);
} else if (e.type === "keyup") {
return me.sendKeyEvent(code, 0);
}
this.client.oncopy = function(text) {
return ($("#clipboard"))[0].value = text;
};
hamster = Hamster(this.canvas);
return hamster.wheel(function(event, delta, deltaX, deltaY) {
var p;
p = getMousePos(event.originalEvent);
if (delta > 0) {
me.sendPointEvent(p.x, p.y, 8);
me.sendPointEvent(p.x, p.y, 0);
return;
}
me.sendPointEvent(p.x, p.y, 16);
return me.sendPointEvent(p.x, p.y, 0);
return this.client.init().then(function() {
$("#connect").click(function(e) {
return me.client.connect("192.168.1.20:5901", {
bbp: 32,
flag: 3,
quality: 30
});
});
$("#stop").click(function(e) {
return me.client.disconnect();
});
return $("#btclipboard").click(function(e) {
return me.client.sendTextAsClipboard(($("#clipboard"))[0].value);
});
})["catch"](function(m, s) {
return console.error(m, s);
});
};
WVNC.prototype.initCanvas = function(w, h, d) {
var me;
me = this;
this.depth = d;
this.canvas.width = w;
this.canvas.height = h;
this.engine = {
w: w,
h: h,
depth: this.depth,
wasm: true
};
this.decoder.postMessage(this.engine);
return this.setScale(this.scale);
};
WVNC.prototype.process = function(msg) {
var ctx, data, imgData;
if (!this.socket) {
return;
}
data = new Uint8Array(msg.pixels);
ctx = this.canvas.getContext("2d", {
alpha: false
});
imgData = ctx.createImageData(msg.w, msg.h);
imgData.data.set(data);
return ctx.putImageData(imgData, msg.x, msg.y);
};
WVNC.prototype.setScale = function(n) {
this.scale = n;
this.canvas.style.transformOrigin = '0 0';
return this.canvas.style.transform = 'scale(' + n + ')';
};
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 data, vncserver;
vncserver = "192.168.1.20:5901";
data = new Uint8Array(vncserver.length + 3);
data[0] = 32;
/*
flag:
0: raw data no compress
1: jpeg no compress
2: raw data compressed by zlib
3: jpeg data compressed by zlib
*/
data[1] = 1;
data[2] = 40;
data.set((new TextEncoder()).encode(vncserver), 3);
return this.socket.send(this.buildCommand(0x01, data));
};
WVNC.prototype.sendPointEvent = function(x, y, mask) {
var data;
if (!this.socket) {
return;
}
data = new Uint8Array(5);
data[0] = x & 0xFF;
data[1] = x >> 8;
data[2] = y & 0xFF;
data[3] = y >> 8;
data[4] = mask;
return this.socket.send(this.buildCommand(0x05, data));
};
WVNC.prototype.sendKeyEvent = function(code, v) {
var data;
if (!this.socket) {
return;
}
data = new Uint8Array(3);
data[0] = code & 0xFF;
data[1] = code >> 8;
data[2] = v;
console.log(code, v);
return this.socket.send(this.buildCommand(0x06, data));
};
WVNC.prototype.buildCommand = function(hex, o) {
var cmd, data;
data = void 0;
switch (typeof o) {
case 'string':
data = (new TextEncoder()).encode(o);
break;
case 'number':
data = new Uint8Array([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);
return cmd.buffer;
};
WVNC.prototype.consume = function(e) {
var arr, cmd, data, dec, depth, h, pass, user, w;
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 0x81:
console.log("Request for password");
pass = "lxsan9";
return this.socket.send(this.buildCommand(0x02, pass));
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];
this.initCanvas(w, h, depth);
return this.socket.send(this.buildCommand(0x04, 1));
case 0x84:
return this.decoder.postMessage(data.buffer, [data.buffer]);
default:
return console.log(cmd);
}
};
return WVNC;
return WebVNC;
})(window.classes.BaseObject);
WVNC.dependencies = ["/assets/scripts/hamster.js"];
WebVNC.dependencies = ["/assets/scripts/wvnc.js"];
makeclass("WVNC", WVNC);
makeclass("WebVNC", WebVNC);
}).call(this);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

57
apps/assets/shs/antd.sh Normal file
View File

@ -0,0 +1,57 @@
#! /bin/bash
echo "AND auto build script"
if [ -d "ant-http" ]; then
echo "Updating Antd source..."
cd "ant-http"
git stash
git pull
else
echo "Getting Antd..."
git clone https://github.com/lxsang/ant-http
cd "ant-http"
fi
[[ -d "plugins" ]] || mkdir "plugins"
echo "getting plugins..."
cd "plugins"
for plugin in $1; do
echo "Getting plugin: $plugin..."
if [ -d "antd-$plugin-plugin" ]; then
echo "Updating $plugin source..."
cd "antd-$plugin-plugin"
git pull
cd ../
else
echo "Getting $plugin..."
git clone "https://github.com/lxsang/antd-$plugin-plugin"
fi
done
cd ../
# ask user for some custom setting
read -p "Build to (absolute path):" build_dir </dev/tty
[[ -d "$build_dir" ]] || mkdir -p "$build_dir"
[[ -d "$build_dir/htdocs" ]] || mkdir -p "$build_dir/htdocs"
[[ -d "$build_dir/database" ]] || mkdir -p "$build_dir/database"
[[ -d "$build_dir/tmp" ]] || mkdir -p "$build_dir/tmp"
escape="${build_dir//\//\\/}"
escape="${escape//\./\\.}"
read -p "Default HTTP port : " http_port </dev/tty
cmd="sed -i -E 's/[^P]BUILDIRD=.*/BUILDIRD=$escape/' var.mk"
eval $cmd
echo
make && make antd_plugins
if [ $? -eq 0 ]; then
echo "[SERVER]" > "$build_dir/config.ini"
echo "port=$http_port" >> "$build_dir/config.ini"
echo "plugins=$build_dir/plugins" >> "$build_dir/config.ini"
echo "plugins_ext=.dylib" >> "$build_dir/config.ini"
echo "database=$build_dir/database" >> "$build_dir/config.ini"
echo "htdocs=$build_dir/htdocs" >> "$build_dir/config.ini"
echo "tmpdir=$build_dir/tmp" >> "$build_dir/config.ini"
echo "ssl.enable=0" >> "$build_dir/config.ini"
chmod u+x "$build_dir/antd"
echo "Build done, to run the server, execute the command:"
echo "$build_dir/antd"
else
echo "FAIL to build, please check dependencies"
fi

View File

@ -0,0 +1,19 @@
BaseController:subclass("ScriptController", {
registry = {}
})
function ScriptController:index( name )
local path = WWW_ROOT..DIR_SEP.."assets"..DIR_SEP.."shs"..DIR_SEP..name..".sh"
if ulib.exists(path) then
std.header("text/plain")
std.f(path)
else
self:error("No script found")
end
return false
end
function ScriptController:actionnotfound(...)
return self:index(table.unpack({...}))
end

View File

@ -0,0 +1,13 @@
BaseController:subclass("WebVNCController", {
registry = {}
})
function WebVNCController:index( ... )
self.template:set("args", "['WebVNC']")
return true
end
function WebVNCController:actionnotfound(...)
self.template:setView("index")
return self:index(table.unpack({...}))
end

View File

@ -1,13 +0,0 @@
BaseController:subclass("WvncController", {
registry = {}
})
function WvncController:index( ... )
self.template:set("args", "['WVNC', 'wss://localhost:9192/wvnc', '#canvas']")
return true
end
function WvncController:actionnotfound(...)
self.template:setView("index")
return self:index(table.unpack({...}))
end

View File

@ -0,0 +1,11 @@
<?lua
echo(JSON.encode(REQUEST))
?>
<form action="https://apps.localhost:9192/index/testrq" enctype="multipart/form-data" method="post">
<input type="file" name="fileToUpload" id="fileToUpload"><br>
First name:<br>
<input type="text" name="firstname" value="Mickey"><br>
Last name:<br>
<input type="text" name="lastname" value="Mouse"><br><br>
<input type="submit" value="Submit">
</form>

View File

@ -0,0 +1,7 @@
<h1>VNC screen here</h1>
<p><a id="connect" href="#">Connect</a><a id="stop" href="#">Disconnect</a></p>
<p>
<textarea id='clipboard'></textarea>
<button id="btclipboard">Send</button>
</p>
<canvas id = "canvas" tabindex="1"></canvas>

View File

@ -1,3 +0,0 @@
<h1>VNC screen here</h1>
<p><a id="connect" href="#">Connect</a><a id="stop" href="#">STOP</a></p>
<canvas id = "canvas" tabindex="1"></canvas>