diff --git a/apps/Makefile b/apps/Makefile index ee7259e..01cb653 100644 --- a/apps/Makefile +++ b/apps/Makefile @@ -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: diff --git a/apps/assets/coffee/WVNC.coffee b/apps/assets/coffee/WVNC.coffee deleted file mode 100644 index 3180d99..0000000 --- a/apps/assets/coffee/WVNC.coffee +++ /dev/null @@ -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 \ No newline at end of file diff --git a/apps/assets/coffee/WebVNC.coffee b/apps/assets/coffee/WebVNC.coffee new file mode 100644 index 0000000..d0322f7 --- /dev/null +++ b/apps/assets/coffee/WebVNC.coffee @@ -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 \ No newline at end of file diff --git a/apps/assets/coffee/decoder.coffee b/apps/assets/coffee/decoder.coffee deleted file mode 100644 index 9a72795..0000000 --- a/apps/assets/coffee/decoder.coffee +++ /dev/null @@ -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 \ No newline at end of file diff --git a/apps/assets/scripts/decoder.js b/apps/assets/scripts/decoder.js index bbc9d1e..4cdf372 100644 --- a/apps/assets/scripts/decoder.js +++ b/apps/assets/scripts/decoder.js @@ -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)}; \ No newline at end of file diff --git a/apps/assets/scripts/hamster.js b/apps/assets/scripts/hamster.js deleted file mode 100644 index ac99dc8..0000000 --- a/apps/assets/scripts/hamster.js +++ /dev/null @@ -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); diff --git a/apps/assets/scripts/jpeg-decoder.js b/apps/assets/scripts/jpeg-decoder.js deleted file mode 100644 index 98c259c..0000000 --- a/apps/assets/scripts/jpeg-decoder.js +++ /dev/null @@ -1,1018 +0,0 @@ -/* -*- tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- / -/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */ -/* - Copyright 2011 notmasteryet - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// - The JPEG specification can be found in the ITU CCITT Recommendation T.81 -// (www.w3.org/Graphics/JPEG/itu-t81.pdf) -// - The JFIF specification can be found in the JPEG File Interchange Format -// (www.w3.org/Graphics/JPEG/jfif3.pdf) -// - The Adobe Application-Specific JPEG markers in the Supporting the DCT Filters -// in PostScript Level 2, Technical Note #5116 -// (partners.adobe.com/public/developer/en/ps/sdk/5116.DCT_Filter.pdf) - -var JpegImage = (function jpegImage() { - "use strict"; - var dctZigZag = new Int32Array([ - 0, - 1, 8, - 16, 9, 2, - 3, 10, 17, 24, - 32, 25, 18, 11, 4, - 5, 12, 19, 26, 33, 40, - 48, 41, 34, 27, 20, 13, 6, - 7, 14, 21, 28, 35, 42, 49, 56, - 57, 50, 43, 36, 29, 22, 15, - 23, 30, 37, 44, 51, 58, - 59, 52, 45, 38, 31, - 39, 46, 53, 60, - 61, 54, 47, - 55, 62, - 63 - ]); - - var dctCos1 = 4017 // cos(pi/16) - var dctSin1 = 799 // sin(pi/16) - var dctCos3 = 3406 // cos(3*pi/16) - var dctSin3 = 2276 // sin(3*pi/16) - var dctCos6 = 1567 // cos(6*pi/16) - var dctSin6 = 3784 // sin(6*pi/16) - var dctSqrt2 = 5793 // sqrt(2) - var dctSqrt1d2 = 2896 // sqrt(2) / 2 - - function constructor() { - } - - function buildHuffmanTable(codeLengths, values) { - var k = 0, code = [], i, j, length = 16; - while (length > 0 && !codeLengths[length - 1]) - length--; - code.push({children: [], index: 0}); - var p = code[0], q; - for (i = 0; i < length; i++) { - for (j = 0; j < codeLengths[i]; j++) { - p = code.pop(); - p.children[p.index] = values[k]; - while (p.index > 0) { - p = code.pop(); - } - p.index++; - code.push(p); - while (code.length <= i) { - code.push(q = {children: [], index: 0}); - p.children[p.index] = q.children; - p = q; - } - k++; - } - if (i + 1 < length) { - // p here points to last code - code.push(q = {children: [], index: 0}); - p.children[p.index] = q.children; - p = q; - } - } - return code[0].children; - } - - function decodeScan(data, offset, - frame, components, resetInterval, - spectralStart, spectralEnd, - successivePrev, successive) { - var precision = frame.precision; - var samplesPerLine = frame.samplesPerLine; - var scanLines = frame.scanLines; - var mcusPerLine = frame.mcusPerLine; - var progressive = frame.progressive; - var maxH = frame.maxH, maxV = frame.maxV; - - var startOffset = offset, bitsData = 0, bitsCount = 0; - function readBit() { - if (bitsCount > 0) { - bitsCount--; - return (bitsData >> bitsCount) & 1; - } - bitsData = data[offset++]; - if (bitsData == 0xFF) { - var nextByte = data[offset++]; - if (nextByte) { - throw new Error("unexpected marker: " + ((bitsData << 8) | nextByte).toString(16)); - } - // unstuff 0 - } - bitsCount = 7; - return bitsData >>> 7; - } - function decodeHuffman(tree) { - var node = tree, bit; - while ((bit = readBit()) !== null) { - node = node[bit]; - if (typeof node === 'number') - return node; - if (typeof node !== 'object') - throw new Error("invalid huffman sequence"); - } - return null; - } - function receive(length) { - var n = 0; - while (length > 0) { - var bit = readBit(); - if (bit === null) return; - n = (n << 1) | bit; - length--; - } - return n; - } - function receiveAndExtend(length) { - var n = receive(length); - if (n >= 1 << (length - 1)) - return n; - return n + (-1 << length) + 1; - } - function decodeBaseline(component, zz) { - var t = decodeHuffman(component.huffmanTableDC); - var diff = t === 0 ? 0 : receiveAndExtend(t); - zz[0]= (component.pred += diff); - var k = 1; - while (k < 64) { - var rs = decodeHuffman(component.huffmanTableAC); - var s = rs & 15, r = rs >> 4; - if (s === 0) { - if (r < 15) - break; - k += 16; - continue; - } - k += r; - var z = dctZigZag[k]; - zz[z] = receiveAndExtend(s); - k++; - } - } - function decodeDCFirst(component, zz) { - var t = decodeHuffman(component.huffmanTableDC); - var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive); - zz[0] = (component.pred += diff); - } - function decodeDCSuccessive(component, zz) { - zz[0] |= readBit() << successive; - } - var eobrun = 0; - function decodeACFirst(component, zz) { - if (eobrun > 0) { - eobrun--; - return; - } - var k = spectralStart, e = spectralEnd; - while (k <= e) { - var rs = decodeHuffman(component.huffmanTableAC); - var s = rs & 15, r = rs >> 4; - if (s === 0) { - if (r < 15) { - eobrun = receive(r) + (1 << r) - 1; - break; - } - k += 16; - continue; - } - k += r; - var z = dctZigZag[k]; - zz[z] = receiveAndExtend(s) * (1 << successive); - k++; - } - } - var successiveACState = 0, successiveACNextValue; - function decodeACSuccessive(component, zz) { - var k = spectralStart, e = spectralEnd, r = 0; - while (k <= e) { - var z = dctZigZag[k]; - var direction = zz[z] < 0 ? -1 : 1; - switch (successiveACState) { - case 0: // initial state - var rs = decodeHuffman(component.huffmanTableAC); - var s = rs & 15, r = rs >> 4; - if (s === 0) { - if (r < 15) { - eobrun = receive(r) + (1 << r); - successiveACState = 4; - } else { - r = 16; - successiveACState = 1; - } - } else { - if (s !== 1) - throw new Error("invalid ACn encoding"); - successiveACNextValue = receiveAndExtend(s); - successiveACState = r ? 2 : 3; - } - continue; - case 1: // skipping r zero items - case 2: - if (zz[z]) - zz[z] += (readBit() << successive) * direction; - else { - r--; - if (r === 0) - successiveACState = successiveACState == 2 ? 3 : 0; - } - break; - case 3: // set value for a zero item - if (zz[z]) - zz[z] += (readBit() << successive) * direction; - else { - zz[z] = successiveACNextValue << successive; - successiveACState = 0; - } - break; - case 4: // eob - if (zz[z]) - zz[z] += (readBit() << successive) * direction; - break; - } - k++; - } - if (successiveACState === 4) { - eobrun--; - if (eobrun === 0) - successiveACState = 0; - } - } - function decodeMcu(component, decode, mcu, row, col) { - var mcuRow = (mcu / mcusPerLine) | 0; - var mcuCol = mcu % mcusPerLine; - var blockRow = mcuRow * component.v + row; - var blockCol = mcuCol * component.h + col; - decode(component, component.blocks[blockRow][blockCol]); - } - function decodeBlock(component, decode, mcu) { - var blockRow = (mcu / component.blocksPerLine) | 0; - var blockCol = mcu % component.blocksPerLine; - decode(component, component.blocks[blockRow][blockCol]); - } - - var componentsLength = components.length; - var component, i, j, k, n; - var decodeFn; - if (progressive) { - if (spectralStart === 0) - decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive; - else - decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive; - } else { - decodeFn = decodeBaseline; - } - - var mcu = 0, marker; - var mcuExpected; - if (componentsLength == 1) { - mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn; - } else { - mcuExpected = mcusPerLine * frame.mcusPerColumn; - } - if (!resetInterval) resetInterval = mcuExpected; - - var h, v; - while (mcu < mcuExpected) { - // reset interval stuff - for (i = 0; i < componentsLength; i++) - components[i].pred = 0; - eobrun = 0; - - if (componentsLength == 1) { - component = components[0]; - for (n = 0; n < resetInterval; n++) { - decodeBlock(component, decodeFn, mcu); - mcu++; - } - } else { - for (n = 0; n < resetInterval; n++) { - for (i = 0; i < componentsLength; i++) { - component = components[i]; - h = component.h; - v = component.v; - for (j = 0; j < v; j++) { - for (k = 0; k < h; k++) { - decodeMcu(component, decodeFn, mcu, j, k); - } - } - } - mcu++; - - // If we've reached our expected MCU's, stop decoding - if (mcu === mcuExpected) break; - } - } - - // find marker - bitsCount = 0; - marker = (data[offset] << 8) | data[offset + 1]; - if (marker < 0xFF00) { - throw new Error("marker was not found"); - } - - if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx - offset += 2; - } - else - break; - } - - return offset - startOffset; - } - - function buildComponentData(frame, component) { - var lines = []; - var blocksPerLine = component.blocksPerLine; - var blocksPerColumn = component.blocksPerColumn; - var samplesPerLine = blocksPerLine << 3; - var R = new Int32Array(64), r = new Uint8Array(64); - - // A port of poppler's IDCT method which in turn is taken from: - // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz, - // "Practical Fast 1-D DCT Algorithms with 11 Multiplications", - // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989, - // 988-991. - function quantizeAndInverse(zz, dataOut, dataIn) { - var qt = component.quantizationTable; - var v0, v1, v2, v3, v4, v5, v6, v7, t; - var p = dataIn; - var i; - - // dequant - for (i = 0; i < 64; i++) - p[i] = zz[i] * qt[i]; - - // inverse DCT on rows - for (i = 0; i < 8; ++i) { - var row = 8 * i; - - // check for all-zero AC coefficients - if (p[1 + row] == 0 && p[2 + row] == 0 && p[3 + row] == 0 && - p[4 + row] == 0 && p[5 + row] == 0 && p[6 + row] == 0 && - p[7 + row] == 0) { - t = (dctSqrt2 * p[0 + row] + 512) >> 10; - p[0 + row] = t; - p[1 + row] = t; - p[2 + row] = t; - p[3 + row] = t; - p[4 + row] = t; - p[5 + row] = t; - p[6 + row] = t; - p[7 + row] = t; - continue; - } - - // stage 4 - v0 = (dctSqrt2 * p[0 + row] + 128) >> 8; - v1 = (dctSqrt2 * p[4 + row] + 128) >> 8; - v2 = p[2 + row]; - v3 = p[6 + row]; - v4 = (dctSqrt1d2 * (p[1 + row] - p[7 + row]) + 128) >> 8; - v7 = (dctSqrt1d2 * (p[1 + row] + p[7 + row]) + 128) >> 8; - v5 = p[3 + row] << 4; - v6 = p[5 + row] << 4; - - // stage 3 - t = (v0 - v1+ 1) >> 1; - v0 = (v0 + v1 + 1) >> 1; - v1 = t; - t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8; - v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8; - v3 = t; - t = (v4 - v6 + 1) >> 1; - v4 = (v4 + v6 + 1) >> 1; - v6 = t; - t = (v7 + v5 + 1) >> 1; - v5 = (v7 - v5 + 1) >> 1; - v7 = t; - - // stage 2 - t = (v0 - v3 + 1) >> 1; - v0 = (v0 + v3 + 1) >> 1; - v3 = t; - t = (v1 - v2 + 1) >> 1; - v1 = (v1 + v2 + 1) >> 1; - v2 = t; - t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12; - v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12; - v7 = t; - t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12; - v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12; - v6 = t; - - // stage 1 - p[0 + row] = v0 + v7; - p[7 + row] = v0 - v7; - p[1 + row] = v1 + v6; - p[6 + row] = v1 - v6; - p[2 + row] = v2 + v5; - p[5 + row] = v2 - v5; - p[3 + row] = v3 + v4; - p[4 + row] = v3 - v4; - } - - // inverse DCT on columns - for (i = 0; i < 8; ++i) { - var col = i; - - // check for all-zero AC coefficients - if (p[1*8 + col] == 0 && p[2*8 + col] == 0 && p[3*8 + col] == 0 && - p[4*8 + col] == 0 && p[5*8 + col] == 0 && p[6*8 + col] == 0 && - p[7*8 + col] == 0) { - t = (dctSqrt2 * dataIn[i+0] + 8192) >> 14; - p[0*8 + col] = t; - p[1*8 + col] = t; - p[2*8 + col] = t; - p[3*8 + col] = t; - p[4*8 + col] = t; - p[5*8 + col] = t; - p[6*8 + col] = t; - p[7*8 + col] = t; - continue; - } - - // stage 4 - v0 = (dctSqrt2 * p[0*8 + col] + 2048) >> 12; - v1 = (dctSqrt2 * p[4*8 + col] + 2048) >> 12; - v2 = p[2*8 + col]; - v3 = p[6*8 + col]; - v4 = (dctSqrt1d2 * (p[1*8 + col] - p[7*8 + col]) + 2048) >> 12; - v7 = (dctSqrt1d2 * (p[1*8 + col] + p[7*8 + col]) + 2048) >> 12; - v5 = p[3*8 + col]; - v6 = p[5*8 + col]; - - // stage 3 - t = (v0 - v1 + 1) >> 1; - v0 = (v0 + v1 + 1) >> 1; - v1 = t; - t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12; - v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12; - v3 = t; - t = (v4 - v6 + 1) >> 1; - v4 = (v4 + v6 + 1) >> 1; - v6 = t; - t = (v7 + v5 + 1) >> 1; - v5 = (v7 - v5 + 1) >> 1; - v7 = t; - - // stage 2 - t = (v0 - v3 + 1) >> 1; - v0 = (v0 + v3 + 1) >> 1; - v3 = t; - t = (v1 - v2 + 1) >> 1; - v1 = (v1 + v2 + 1) >> 1; - v2 = t; - t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12; - v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12; - v7 = t; - t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12; - v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12; - v6 = t; - - // stage 1 - p[0*8 + col] = v0 + v7; - p[7*8 + col] = v0 - v7; - p[1*8 + col] = v1 + v6; - p[6*8 + col] = v1 - v6; - p[2*8 + col] = v2 + v5; - p[5*8 + col] = v2 - v5; - p[3*8 + col] = v3 + v4; - p[4*8 + col] = v3 - v4; - } - - // convert to 8-bit integers - for (i = 0; i < 64; ++i) { - var sample = 128 + ((p[i] + 8) >> 4); - dataOut[i] = sample < 0 ? 0 : sample > 0xFF ? 0xFF : sample; - } - } - - var i, j; - for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) { - var scanLine = blockRow << 3; - for (i = 0; i < 8; i++) - lines.push(new Uint8Array(samplesPerLine)); - for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) { - quantizeAndInverse(component.blocks[blockRow][blockCol], r, R); - - var offset = 0, sample = blockCol << 3; - for (j = 0; j < 8; j++) { - var line = lines[scanLine + j]; - for (i = 0; i < 8; i++) - line[sample + i] = r[offset++]; - } - } - } - return lines; - } - - function clampTo8bit(a) { - return a < 0 ? 0 : a > 255 ? 255 : a; - } - - constructor.prototype = { - load: function load(path) { - var xhr = new XMLHttpRequest(); - xhr.open("GET", path, true); - xhr.responseType = "arraybuffer"; - xhr.onload = (function() { - // TODO catch parse error - var data = new Uint8Array(xhr.response || xhr.mozResponseArrayBuffer); - this.parse(data); - if (this.onload) - this.onload(); - }).bind(this); - xhr.send(null); - }, - parse: function parse(data) { - var offset = 0, length = data.length; - function readUint16() { - var value = (data[offset] << 8) | data[offset + 1]; - offset += 2; - return value; - } - function readDataBlock() { - var length = readUint16(); - var array = data.subarray(offset, offset + length - 2); - offset += array.length; - return array; - } - function prepareComponents(frame) { - var maxH = 0, maxV = 0; - var component, componentId; - for (componentId in frame.components) { - if (frame.components.hasOwnProperty(componentId)) { - component = frame.components[componentId]; - if (maxH < component.h) maxH = component.h; - if (maxV < component.v) maxV = component.v; - } - } - var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / maxH); - var mcusPerColumn = Math.ceil(frame.scanLines / 8 / maxV); - for (componentId in frame.components) { - if (frame.components.hasOwnProperty(componentId)) { - component = frame.components[componentId]; - var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) * component.h / maxH); - var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) * component.v / maxV); - var blocksPerLineForMcu = mcusPerLine * component.h; - var blocksPerColumnForMcu = mcusPerColumn * component.v; - var blocks = []; - for (var i = 0; i < blocksPerColumnForMcu; i++) { - var row = []; - for (var j = 0; j < blocksPerLineForMcu; j++) - row.push(new Int32Array(64)); - blocks.push(row); - } - component.blocksPerLine = blocksPerLine; - component.blocksPerColumn = blocksPerColumn; - component.blocks = blocks; - } - } - frame.maxH = maxH; - frame.maxV = maxV; - frame.mcusPerLine = mcusPerLine; - frame.mcusPerColumn = mcusPerColumn; - } - var jfif = null; - var adobe = null; - var pixels = null; - var frame, resetInterval; - var quantizationTables = [], frames = []; - var huffmanTablesAC = [], huffmanTablesDC = []; - var fileMarker = readUint16(); - if (fileMarker != 0xFFD8) { // SOI (Start of Image) - throw new Error("SOI not found"); - } - - fileMarker = readUint16(); - while (fileMarker != 0xFFD9) { // EOI (End of image) - var i, j, l; - switch(fileMarker) { - case 0xFF00: break; - case 0xFFE0: // APP0 (Application Specific) - case 0xFFE1: // APP1 - case 0xFFE2: // APP2 - case 0xFFE3: // APP3 - case 0xFFE4: // APP4 - case 0xFFE5: // APP5 - case 0xFFE6: // APP6 - case 0xFFE7: // APP7 - case 0xFFE8: // APP8 - case 0xFFE9: // APP9 - case 0xFFEA: // APP10 - case 0xFFEB: // APP11 - case 0xFFEC: // APP12 - case 0xFFED: // APP13 - case 0xFFEE: // APP14 - case 0xFFEF: // APP15 - case 0xFFFE: // COM (Comment) - var appData = readDataBlock(); - - if (fileMarker === 0xFFE0) { - if (appData[0] === 0x4A && appData[1] === 0x46 && appData[2] === 0x49 && - appData[3] === 0x46 && appData[4] === 0) { // 'JFIF\x00' - jfif = { - version: { major: appData[5], minor: appData[6] }, - densityUnits: appData[7], - xDensity: (appData[8] << 8) | appData[9], - yDensity: (appData[10] << 8) | appData[11], - thumbWidth: appData[12], - thumbHeight: appData[13], - thumbData: appData.subarray(14, 14 + 3 * appData[12] * appData[13]) - }; - } - } - // TODO APP1 - Exif - if (fileMarker === 0xFFEE) { - if (appData[0] === 0x41 && appData[1] === 0x64 && appData[2] === 0x6F && - appData[3] === 0x62 && appData[4] === 0x65 && appData[5] === 0) { // 'Adobe\x00' - adobe = { - version: appData[6], - flags0: (appData[7] << 8) | appData[8], - flags1: (appData[9] << 8) | appData[10], - transformCode: appData[11] - }; - } - } - break; - - case 0xFFDB: // DQT (Define Quantization Tables) - var quantizationTablesLength = readUint16(); - var quantizationTablesEnd = quantizationTablesLength + offset - 2; - while (offset < quantizationTablesEnd) { - var quantizationTableSpec = data[offset++]; - var tableData = new Int32Array(64); - if ((quantizationTableSpec >> 4) === 0) { // 8 bit values - for (j = 0; j < 64; j++) { - var z = dctZigZag[j]; - tableData[z] = data[offset++]; - } - } else if ((quantizationTableSpec >> 4) === 1) { //16 bit - for (j = 0; j < 64; j++) { - var z = dctZigZag[j]; - tableData[z] = readUint16(); - } - } else - throw new Error("DQT: invalid table spec"); - quantizationTables[quantizationTableSpec & 15] = tableData; - } - break; - - case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT) - case 0xFFC1: // SOF1 (Start of Frame, Extended DCT) - case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT) - readUint16(); // skip data length - frame = {}; - frame.extended = (fileMarker === 0xFFC1); - frame.progressive = (fileMarker === 0xFFC2); - frame.precision = data[offset++]; - frame.scanLines = readUint16(); - frame.samplesPerLine = readUint16(); - frame.components = {}; - frame.componentsOrder = []; - var componentsCount = data[offset++], componentId; - var maxH = 0, maxV = 0; - for (i = 0; i < componentsCount; i++) { - componentId = data[offset]; - var h = data[offset + 1] >> 4; - var v = data[offset + 1] & 15; - var qId = data[offset + 2]; - frame.componentsOrder.push(componentId); - frame.components[componentId] = { - h: h, - v: v, - quantizationIdx: qId - }; - offset += 3; - } - prepareComponents(frame); - frames.push(frame); - break; - - case 0xFFC4: // DHT (Define Huffman Tables) - var huffmanLength = readUint16(); - for (i = 2; i < huffmanLength;) { - var huffmanTableSpec = data[offset++]; - var codeLengths = new Uint8Array(16); - var codeLengthSum = 0; - for (j = 0; j < 16; j++, offset++) - codeLengthSum += (codeLengths[j] = data[offset]); - var huffmanValues = new Uint8Array(codeLengthSum); - for (j = 0; j < codeLengthSum; j++, offset++) - huffmanValues[j] = data[offset]; - i += 17 + codeLengthSum; - - ((huffmanTableSpec >> 4) === 0 ? - huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] = - buildHuffmanTable(codeLengths, huffmanValues); - } - break; - - case 0xFFDD: // DRI (Define Restart Interval) - readUint16(); // skip data length - resetInterval = readUint16(); - break; - - case 0xFFDA: // SOS (Start of Scan) - var scanLength = readUint16(); - var selectorsCount = data[offset++]; - var components = [], component; - for (i = 0; i < selectorsCount; i++) { - component = frame.components[data[offset++]]; - var tableSpec = data[offset++]; - component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4]; - component.huffmanTableAC = huffmanTablesAC[tableSpec & 15]; - components.push(component); - } - var spectralStart = data[offset++]; - var spectralEnd = data[offset++]; - var successiveApproximation = data[offset++]; - var processed = decodeScan(data, offset, - frame, components, resetInterval, - spectralStart, spectralEnd, - successiveApproximation >> 4, successiveApproximation & 15); - offset += processed; - break; - - case 0xFFFF: // Fill bytes - if (data[offset] !== 0xFF) { // Avoid skipping a valid marker. - offset--; - } - break; - - default: - if (data[offset - 3] == 0xFF && - data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) { - // could be incorrect encoding -- last 0xFF byte of the previous - // block was eaten by the encoder - offset -= 3; - break; - } - throw new Error("unknown JPEG marker " + fileMarker.toString(16)); - } - fileMarker = readUint16(); - } - if (frames.length != 1) - throw new Error("only single frame JPEGs supported"); - - // set each frame's components quantization table - for (var i = 0; i < frames.length; i++) { - var cp = frames[i].components; - for (var j in cp) { - cp[j].quantizationTable = quantizationTables[cp[j].quantizationIdx]; - delete cp[j].quantizationIdx; - } - } - - this.width = frame.samplesPerLine; - this.height = frame.scanLines; - this.jfif = jfif; - this.adobe = adobe; - this.components = []; - for (var i = 0; i < frame.componentsOrder.length; i++) { - var component = frame.components[frame.componentsOrder[i]]; - this.components.push({ - lines: buildComponentData(frame, component), - scaleX: component.h / frame.maxH, - scaleY: component.v / frame.maxV - }); - } - }, - getData: function getData(width, height) { - var scaleX = this.width / width, scaleY = this.height / height; - - var component1, component2, component3, component4; - var component1Line, component2Line, component3Line, component4Line; - var x, y; - var offset = 0; - var Y, Cb, Cr, K, C, M, Ye, R, G, B; - var colorTransform; - var dataLength = width * height * this.components.length; - var data = new Uint8Array(dataLength); - switch (this.components.length) { - case 1: - component1 = this.components[0]; - for (y = 0; y < height; y++) { - component1Line = component1.lines[0 | (y * component1.scaleY * scaleY)]; - for (x = 0; x < width; x++) { - Y = component1Line[0 | (x * component1.scaleX * scaleX)]; - - data[offset++] = Y; - } - } - break; - case 2: - // PDF might compress two component data in custom colorspace - component1 = this.components[0]; - component2 = this.components[1]; - for (y = 0; y < height; y++) { - component1Line = component1.lines[0 | (y * component1.scaleY * scaleY)]; - component2Line = component2.lines[0 | (y * component2.scaleY * scaleY)]; - for (x = 0; x < width; x++) { - Y = component1Line[0 | (x * component1.scaleX * scaleX)]; - data[offset++] = Y; - Y = component2Line[0 | (x * component2.scaleX * scaleX)]; - data[offset++] = Y; - } - } - break; - case 3: - // The default transform for three components is true - colorTransform = true; - // The adobe transform marker overrides any previous setting - if (this.adobe && this.adobe.transformCode) - colorTransform = true; - else if (typeof this.colorTransform !== 'undefined') - colorTransform = !!this.colorTransform; - - component1 = this.components[0]; - component2 = this.components[1]; - component3 = this.components[2]; - for (y = 0; y < height; y++) { - component1Line = component1.lines[0 | (y * component1.scaleY * scaleY)]; - component2Line = component2.lines[0 | (y * component2.scaleY * scaleY)]; - component3Line = component3.lines[0 | (y * component3.scaleY * scaleY)]; - for (x = 0; x < width; x++) { - if (!colorTransform) { - R = component1Line[0 | (x * component1.scaleX * scaleX)]; - G = component2Line[0 | (x * component2.scaleX * scaleX)]; - B = component3Line[0 | (x * component3.scaleX * scaleX)]; - } else { - Y = component1Line[0 | (x * component1.scaleX * scaleX)]; - Cb = component2Line[0 | (x * component2.scaleX * scaleX)]; - Cr = component3Line[0 | (x * component3.scaleX * scaleX)]; - - R = clampTo8bit(Y + 1.402 * (Cr - 128)); - G = clampTo8bit(Y - 0.3441363 * (Cb - 128) - 0.71413636 * (Cr - 128)); - B = clampTo8bit(Y + 1.772 * (Cb - 128)); - } - - data[offset++] = R; - data[offset++] = G; - data[offset++] = B; - } - } - break; - case 4: - if (!this.adobe) - throw 'Unsupported color mode (4 components)'; - // The default transform for four components is false - colorTransform = false; - // The adobe transform marker overrides any previous setting - if (this.adobe && this.adobe.transformCode) - colorTransform = true; - else if (typeof this.colorTransform !== 'undefined') - colorTransform = !!this.colorTransform; - - component1 = this.components[0]; - component2 = this.components[1]; - component3 = this.components[2]; - component4 = this.components[3]; - for (y = 0; y < height; y++) { - component1Line = component1.lines[0 | (y * component1.scaleY * scaleY)]; - component2Line = component2.lines[0 | (y * component2.scaleY * scaleY)]; - component3Line = component3.lines[0 | (y * component3.scaleY * scaleY)]; - component4Line = component4.lines[0 | (y * component4.scaleY * scaleY)]; - for (x = 0; x < width; x++) { - if (!colorTransform) { - C = component1Line[0 | (x * component1.scaleX * scaleX)]; - M = component2Line[0 | (x * component2.scaleX * scaleX)]; - Ye = component3Line[0 | (x * component3.scaleX * scaleX)]; - K = component4Line[0 | (x * component4.scaleX * scaleX)]; - } else { - Y = component1Line[0 | (x * component1.scaleX * scaleX)]; - Cb = component2Line[0 | (x * component2.scaleX * scaleX)]; - Cr = component3Line[0 | (x * component3.scaleX * scaleX)]; - K = component4Line[0 | (x * component4.scaleX * scaleX)]; - - C = 255 - clampTo8bit(Y + 1.402 * (Cr - 128)); - M = 255 - clampTo8bit(Y - 0.3441363 * (Cb - 128) - 0.71413636 * (Cr - 128)); - Ye = 255 - clampTo8bit(Y + 1.772 * (Cb - 128)); - } - data[offset++] = 255-C; - data[offset++] = 255-M; - data[offset++] = 255-Ye; - data[offset++] = 255-K; - } - } - break; - default: - throw 'Unsupported color mode'; - } - return data; - }, - copyToImageData: function copyToImageData(imageData) { - var width = imageData.width, height = imageData.height; - var imageDataArray = imageData.data; - var data = this.getData(width, height); - var i = 0, j = 0, x, y; - var Y, K, C, M, R, G, B; - switch (this.components.length) { - case 1: - for (y = 0; y < height; y++) { - for (x = 0; x < width; x++) { - Y = data[i++]; - - imageDataArray[j++] = Y; - imageDataArray[j++] = Y; - imageDataArray[j++] = Y; - imageDataArray[j++] = 255; - } - } - break; - case 3: - for (y = 0; y < height; y++) { - for (x = 0; x < width; x++) { - R = data[i++]; - G = data[i++]; - B = data[i++]; - - imageDataArray[j++] = R; - imageDataArray[j++] = G; - imageDataArray[j++] = B; - imageDataArray[j++] = 255; - } - } - break; - case 4: - for (y = 0; y < height; y++) { - for (x = 0; x < width; x++) { - C = data[i++]; - M = data[i++]; - Y = data[i++]; - K = data[i++]; - - R = 255 - clampTo8bit(C * (1 - K / 255) + K); - G = 255 - clampTo8bit(M * (1 - K / 255) + K); - B = 255 - clampTo8bit(Y * (1 - K / 255) + K); - - imageDataArray[j++] = R; - imageDataArray[j++] = G; - imageDataArray[j++] = B; - imageDataArray[j++] = 255; - } - } - break; - default: - throw 'Unsupported color mode'; - } - } - }; - - return constructor; -})(); -//module.exports = decode; - -function decode(jpegData, opts) { - var defaultOpts = { - useTArray: false, - colorTransform: true - }; - if (opts) { - if (typeof opts === 'object') { - opts = { - useTArray: (typeof opts.useTArray === 'undefined' ? - defaultOpts.useTArray : opts.useTArray), - colorTransform: (typeof opts.colorTransform === 'undefined' ? - defaultOpts.colorTransform : opts.colorTransform) - }; - } else { - // backwards compatiblity, before 0.3.5, we only had the useTArray param - opts = defaultOpts; - opts.useTArray = true; - } - } else { - opts = defaultOpts; - } - - var arr = new Uint8Array(jpegData); - var decoder = new JpegImage(); - decoder.parse(arr); - decoder.colorTransform = opts.colorTransform; - - var image = { - width: decoder.width, - height: decoder.height, - data: opts.useTArray ? - new Uint8Array(decoder.width * decoder.height * 4) : - new Buffer(decoder.width * decoder.height * 4) - }; - - decoder.copyToImageData(image); - - return image; -} diff --git a/apps/assets/scripts/main.js b/apps/assets/scripts/main.js index 217ffc9..479f3da 100644 --- a/apps/assets/scripts/main.js +++ b/apps/assets/scripts/main.js @@ -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); diff --git a/apps/assets/scripts/pako.min.js b/apps/assets/scripts/pako.min.js deleted file mode 100644 index 73024f7..0000000 --- a/apps/assets/scripts/pako.min.js +++ /dev/null @@ -1 +0,0 @@ -!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).pako=t()}}(function(){return function t(e,a,i){function n(s,o){if(!a[s]){if(!e[s]){var l="function"==typeof require&&require;if(!o&&l)return l(s,!0);if(r)return r(s,!0);var h=new Error("Cannot find module '"+s+"'");throw h.code="MODULE_NOT_FOUND",h}var d=a[s]={exports:{}};e[s][0].call(d.exports,function(t){var a=e[s][1][t];return n(a||t)},d,d.exports,t,e,a,i)}return a[s].exports}for(var r="function"==typeof require&&require,s=0;s0?e.windowBits=-e.windowBits:e.gzip&&e.windowBits>0&&e.windowBits<16&&(e.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new h,this.strm.avail_out=0;var a=r.deflateInit2(this.strm,e.level,e.method,e.windowBits,e.memLevel,e.strategy);if(a!==f)throw new Error(l[a]);if(e.header&&r.deflateSetHeader(this.strm,e.header),e.dictionary){var n;if(n="string"==typeof e.dictionary?o.string2buf(e.dictionary):"[object ArrayBuffer]"===d.call(e.dictionary)?new Uint8Array(e.dictionary):e.dictionary,(a=r.deflateSetDictionary(this.strm,n))!==f)throw new Error(l[a]);this._dict_set=!0}}function n(t,e){var a=new i(e);if(a.push(t,!0),a.err)throw a.msg||l[a.err];return a.result}var r=t("./zlib/deflate"),s=t("./utils/common"),o=t("./utils/strings"),l=t("./zlib/messages"),h=t("./zlib/zstream"),d=Object.prototype.toString,f=0,_=-1,u=0,c=8;i.prototype.push=function(t,e){var a,i,n=this.strm,l=this.options.chunkSize;if(this.ended)return!1;i=e===~~e?e:!0===e?4:0,"string"==typeof t?n.input=o.string2buf(t):"[object ArrayBuffer]"===d.call(t)?n.input=new Uint8Array(t):n.input=t,n.next_in=0,n.avail_in=n.input.length;do{if(0===n.avail_out&&(n.output=new s.Buf8(l),n.next_out=0,n.avail_out=l),1!==(a=r.deflate(n,i))&&a!==f)return this.onEnd(a),this.ended=!0,!1;0!==n.avail_out&&(0!==n.avail_in||4!==i&&2!==i)||("string"===this.options.to?this.onData(o.buf2binstring(s.shrinkBuf(n.output,n.next_out))):this.onData(s.shrinkBuf(n.output,n.next_out)))}while((n.avail_in>0||0===n.avail_out)&&1!==a);return 4===i?(a=r.deflateEnd(this.strm),this.onEnd(a),this.ended=!0,a===f):2!==i||(this.onEnd(f),n.avail_out=0,!0)},i.prototype.onData=function(t){this.chunks.push(t)},i.prototype.onEnd=function(t){t===f&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=s.flattenChunks(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg},a.Deflate=i,a.deflate=n,a.deflateRaw=function(t,e){return e=e||{},e.raw=!0,n(t,e)},a.gzip=function(t,e){return e=e||{},e.gzip=!0,n(t,e)}},{"./utils/common":3,"./utils/strings":4,"./zlib/deflate":8,"./zlib/messages":13,"./zlib/zstream":15}],2:[function(t,e,a){"use strict";function i(t){if(!(this instanceof i))return new i(t);this.options=s.assign({chunkSize:16384,windowBits:0,to:""},t||{});var e=this.options;e.raw&&e.windowBits>=0&&e.windowBits<16&&(e.windowBits=-e.windowBits,0===e.windowBits&&(e.windowBits=-15)),!(e.windowBits>=0&&e.windowBits<16)||t&&t.windowBits||(e.windowBits+=32),e.windowBits>15&&e.windowBits<48&&0==(15&e.windowBits)&&(e.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new d,this.strm.avail_out=0;var a=r.inflateInit2(this.strm,e.windowBits);if(a!==l.Z_OK)throw new Error(h[a]);this.header=new f,r.inflateGetHeader(this.strm,this.header)}function n(t,e){var a=new i(e);if(a.push(t,!0),a.err)throw a.msg||h[a.err];return a.result}var r=t("./zlib/inflate"),s=t("./utils/common"),o=t("./utils/strings"),l=t("./zlib/constants"),h=t("./zlib/messages"),d=t("./zlib/zstream"),f=t("./zlib/gzheader"),_=Object.prototype.toString;i.prototype.push=function(t,e){var a,i,n,h,d,f,u=this.strm,c=this.options.chunkSize,b=this.options.dictionary,g=!1;if(this.ended)return!1;i=e===~~e?e:!0===e?l.Z_FINISH:l.Z_NO_FLUSH,"string"==typeof t?u.input=o.binstring2buf(t):"[object ArrayBuffer]"===_.call(t)?u.input=new Uint8Array(t):u.input=t,u.next_in=0,u.avail_in=u.input.length;do{if(0===u.avail_out&&(u.output=new s.Buf8(c),u.next_out=0,u.avail_out=c),(a=r.inflate(u,l.Z_NO_FLUSH))===l.Z_NEED_DICT&&b&&(f="string"==typeof b?o.string2buf(b):"[object ArrayBuffer]"===_.call(b)?new Uint8Array(b):b,a=r.inflateSetDictionary(this.strm,f)),a===l.Z_BUF_ERROR&&!0===g&&(a=l.Z_OK,g=!1),a!==l.Z_STREAM_END&&a!==l.Z_OK)return this.onEnd(a),this.ended=!0,!1;u.next_out&&(0!==u.avail_out&&a!==l.Z_STREAM_END&&(0!==u.avail_in||i!==l.Z_FINISH&&i!==l.Z_SYNC_FLUSH)||("string"===this.options.to?(n=o.utf8border(u.output,u.next_out),h=u.next_out-n,d=o.buf2string(u.output,n),u.next_out=h,u.avail_out=c-h,h&&s.arraySet(u.output,u.output,n,h,0),this.onData(d)):this.onData(s.shrinkBuf(u.output,u.next_out)))),0===u.avail_in&&0===u.avail_out&&(g=!0)}while((u.avail_in>0||0===u.avail_out)&&a!==l.Z_STREAM_END);return a===l.Z_STREAM_END&&(i=l.Z_FINISH),i===l.Z_FINISH?(a=r.inflateEnd(this.strm),this.onEnd(a),this.ended=!0,a===l.Z_OK):i!==l.Z_SYNC_FLUSH||(this.onEnd(l.Z_OK),u.avail_out=0,!0)},i.prototype.onData=function(t){this.chunks.push(t)},i.prototype.onEnd=function(t){t===l.Z_OK&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=s.flattenChunks(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg},a.Inflate=i,a.inflate=n,a.inflateRaw=function(t,e){return e=e||{},e.raw=!0,n(t,e)},a.ungzip=n},{"./utils/common":3,"./utils/strings":4,"./zlib/constants":6,"./zlib/gzheader":9,"./zlib/inflate":11,"./zlib/messages":13,"./zlib/zstream":15}],3:[function(t,e,a){"use strict";function i(t,e){return Object.prototype.hasOwnProperty.call(t,e)}var n="undefined"!=typeof Uint8Array&&"undefined"!=typeof Uint16Array&&"undefined"!=typeof Int32Array;a.assign=function(t){for(var e=Array.prototype.slice.call(arguments,1);e.length;){var a=e.shift();if(a){if("object"!=typeof a)throw new TypeError(a+"must be non-object");for(var n in a)i(a,n)&&(t[n]=a[n])}}return t},a.shrinkBuf=function(t,e){return t.length===e?t:t.subarray?t.subarray(0,e):(t.length=e,t)};var r={arraySet:function(t,e,a,i,n){if(e.subarray&&t.subarray)t.set(e.subarray(a,a+i),n);else for(var r=0;r=252?6:l>=248?5:l>=240?4:l>=224?3:l>=192?2:1;o[254]=o[254]=1,a.string2buf=function(t){var e,a,i,r,s,o=t.length,l=0;for(r=0;r>>6,e[s++]=128|63&a):a<65536?(e[s++]=224|a>>>12,e[s++]=128|a>>>6&63,e[s++]=128|63&a):(e[s++]=240|a>>>18,e[s++]=128|a>>>12&63,e[s++]=128|a>>>6&63,e[s++]=128|63&a);return e},a.buf2binstring=function(t){return i(t,t.length)},a.binstring2buf=function(t){for(var e=new n.Buf8(t.length),a=0,i=e.length;a4)h[n++]=65533,a+=s-1;else{for(r&=2===s?31:3===s?15:7;s>1&&a1?h[n++]=65533:r<65536?h[n++]=r:(r-=65536,h[n++]=55296|r>>10&1023,h[n++]=56320|1023&r)}return i(h,n)},a.utf8border=function(t,e){var a;for((e=e||t.length)>t.length&&(e=t.length),a=e-1;a>=0&&128==(192&t[a]);)a--;return a<0?e:0===a?e:a+o[t[a]]>e?a:e}},{"./common":3}],5:[function(t,e,a){"use strict";e.exports=function(t,e,a,i){for(var n=65535&t|0,r=t>>>16&65535|0,s=0;0!==a;){a-=s=a>2e3?2e3:a;do{r=r+(n=n+e[i++]|0)|0}while(--s);n%=65521,r%=65521}return n|r<<16|0}},{}],6:[function(t,e,a){"use strict";e.exports={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8}},{}],7:[function(t,e,a){"use strict";var i=function(){for(var t,e=[],a=0;a<256;a++){t=a;for(var i=0;i<8;i++)t=1&t?3988292384^t>>>1:t>>>1;e[a]=t}return e}();e.exports=function(t,e,a,n){var r=i,s=n+a;t^=-1;for(var o=n;o>>8^r[255&(t^e[o])];return-1^t}},{}],8:[function(t,e,a){"use strict";function i(t,e){return t.msg=A[e],e}function n(t){return(t<<1)-(t>4?9:0)}function r(t){for(var e=t.length;--e>=0;)t[e]=0}function s(t){var e=t.state,a=e.pending;a>t.avail_out&&(a=t.avail_out),0!==a&&(z.arraySet(t.output,e.pending_buf,e.pending_out,a,t.next_out),t.next_out+=a,e.pending_out+=a,t.total_out+=a,t.avail_out-=a,e.pending-=a,0===e.pending&&(e.pending_out=0))}function o(t,e){B._tr_flush_block(t,t.block_start>=0?t.block_start:-1,t.strstart-t.block_start,e),t.block_start=t.strstart,s(t.strm)}function l(t,e){t.pending_buf[t.pending++]=e}function h(t,e){t.pending_buf[t.pending++]=e>>>8&255,t.pending_buf[t.pending++]=255&e}function d(t,e,a,i){var n=t.avail_in;return n>i&&(n=i),0===n?0:(t.avail_in-=n,z.arraySet(e,t.input,t.next_in,n,a),1===t.state.wrap?t.adler=S(t.adler,e,n,a):2===t.state.wrap&&(t.adler=E(t.adler,e,n,a)),t.next_in+=n,t.total_in+=n,n)}function f(t,e){var a,i,n=t.max_chain_length,r=t.strstart,s=t.prev_length,o=t.nice_match,l=t.strstart>t.w_size-it?t.strstart-(t.w_size-it):0,h=t.window,d=t.w_mask,f=t.prev,_=t.strstart+at,u=h[r+s-1],c=h[r+s];t.prev_length>=t.good_match&&(n>>=2),o>t.lookahead&&(o=t.lookahead);do{if(a=e,h[a+s]===c&&h[a+s-1]===u&&h[a]===h[r]&&h[++a]===h[r+1]){r+=2,a++;do{}while(h[++r]===h[++a]&&h[++r]===h[++a]&&h[++r]===h[++a]&&h[++r]===h[++a]&&h[++r]===h[++a]&&h[++r]===h[++a]&&h[++r]===h[++a]&&h[++r]===h[++a]&&r<_);if(i=at-(_-r),r=_-at,i>s){if(t.match_start=e,s=i,i>=o)break;u=h[r+s-1],c=h[r+s]}}}while((e=f[e&d])>l&&0!=--n);return s<=t.lookahead?s:t.lookahead}function _(t){var e,a,i,n,r,s=t.w_size;do{if(n=t.window_size-t.lookahead-t.strstart,t.strstart>=s+(s-it)){z.arraySet(t.window,t.window,s,s,0),t.match_start-=s,t.strstart-=s,t.block_start-=s,e=a=t.hash_size;do{i=t.head[--e],t.head[e]=i>=s?i-s:0}while(--a);e=a=s;do{i=t.prev[--e],t.prev[e]=i>=s?i-s:0}while(--a);n+=s}if(0===t.strm.avail_in)break;if(a=d(t.strm,t.window,t.strstart+t.lookahead,n),t.lookahead+=a,t.lookahead+t.insert>=et)for(r=t.strstart-t.insert,t.ins_h=t.window[r],t.ins_h=(t.ins_h<=et&&(t.ins_h=(t.ins_h<=et)if(i=B._tr_tally(t,t.strstart-t.match_start,t.match_length-et),t.lookahead-=t.match_length,t.match_length<=t.max_lazy_match&&t.lookahead>=et){t.match_length--;do{t.strstart++,t.ins_h=(t.ins_h<=et&&(t.ins_h=(t.ins_h<4096)&&(t.match_length=et-1)),t.prev_length>=et&&t.match_length<=t.prev_length){n=t.strstart+t.lookahead-et,i=B._tr_tally(t,t.strstart-1-t.prev_match,t.prev_length-et),t.lookahead-=t.prev_length-1,t.prev_length-=2;do{++t.strstart<=n&&(t.ins_h=(t.ins_h<=et&&t.strstart>0&&(n=t.strstart-1,(i=s[n])===s[++n]&&i===s[++n]&&i===s[++n])){r=t.strstart+at;do{}while(i===s[++n]&&i===s[++n]&&i===s[++n]&&i===s[++n]&&i===s[++n]&&i===s[++n]&&i===s[++n]&&i===s[++n]&&nt.lookahead&&(t.match_length=t.lookahead)}if(t.match_length>=et?(a=B._tr_tally(t,1,t.match_length-et),t.lookahead-=t.match_length,t.strstart+=t.match_length,t.match_length=0):(a=B._tr_tally(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++),a&&(o(t,!1),0===t.strm.avail_out))return _t}return t.insert=0,e===N?(o(t,!0),0===t.strm.avail_out?ct:bt):t.last_lit&&(o(t,!1),0===t.strm.avail_out)?_t:ut}function g(t,e){for(var a;;){if(0===t.lookahead&&(_(t),0===t.lookahead)){if(e===Z)return _t;break}if(t.match_length=0,a=B._tr_tally(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++,a&&(o(t,!1),0===t.strm.avail_out))return _t}return t.insert=0,e===N?(o(t,!0),0===t.strm.avail_out?ct:bt):t.last_lit&&(o(t,!1),0===t.strm.avail_out)?_t:ut}function m(t,e,a,i,n){this.good_length=t,this.max_lazy=e,this.nice_length=a,this.max_chain=i,this.func=n}function w(t){t.window_size=2*t.w_size,r(t.head),t.max_lazy_match=x[t.level].max_lazy,t.good_match=x[t.level].good_length,t.nice_match=x[t.level].nice_length,t.max_chain_length=x[t.level].max_chain,t.strstart=0,t.block_start=0,t.lookahead=0,t.insert=0,t.match_length=t.prev_length=et-1,t.match_available=0,t.ins_h=0}function p(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=q,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new z.Buf16(2*$),this.dyn_dtree=new z.Buf16(2*(2*Q+1)),this.bl_tree=new z.Buf16(2*(2*V+1)),r(this.dyn_ltree),r(this.dyn_dtree),r(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new z.Buf16(tt+1),this.heap=new z.Buf16(2*J+1),r(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new z.Buf16(2*J+1),r(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}function v(t){var e;return t&&t.state?(t.total_in=t.total_out=0,t.data_type=Y,e=t.state,e.pending=0,e.pending_out=0,e.wrap<0&&(e.wrap=-e.wrap),e.status=e.wrap?rt:dt,t.adler=2===e.wrap?0:1,e.last_flush=Z,B._tr_init(e),D):i(t,U)}function k(t){var e=v(t);return e===D&&w(t.state),e}function y(t,e,a,n,r,s){if(!t)return U;var o=1;if(e===L&&(e=6),n<0?(o=0,n=-n):n>15&&(o=2,n-=16),r<1||r>G||a!==q||n<8||n>15||e<0||e>9||s<0||s>M)return i(t,U);8===n&&(n=9);var l=new p;return t.state=l,l.strm=t,l.wrap=o,l.gzhead=null,l.w_bits=n,l.w_size=1<t.pending_buf_size-5&&(a=t.pending_buf_size-5);;){if(t.lookahead<=1){if(_(t),0===t.lookahead&&e===Z)return _t;if(0===t.lookahead)break}t.strstart+=t.lookahead,t.lookahead=0;var i=t.block_start+a;if((0===t.strstart||t.strstart>=i)&&(t.lookahead=t.strstart-i,t.strstart=i,o(t,!1),0===t.strm.avail_out))return _t;if(t.strstart-t.block_start>=t.w_size-it&&(o(t,!1),0===t.strm.avail_out))return _t}return t.insert=0,e===N?(o(t,!0),0===t.strm.avail_out?ct:bt):(t.strstart>t.block_start&&(o(t,!1),t.strm.avail_out),_t)}),new m(4,4,8,4,u),new m(4,5,16,8,u),new m(4,6,32,32,u),new m(4,4,16,16,c),new m(8,16,32,32,c),new m(8,16,128,128,c),new m(8,32,128,256,c),new m(32,128,258,1024,c),new m(32,258,258,4096,c)],a.deflateInit=function(t,e){return y(t,e,q,X,W,P)},a.deflateInit2=y,a.deflateReset=k,a.deflateResetKeep=v,a.deflateSetHeader=function(t,e){return t&&t.state?2!==t.state.wrap?U:(t.state.gzhead=e,D):U},a.deflate=function(t,e){var a,o,d,f;if(!t||!t.state||e>O||e<0)return t?i(t,U):U;if(o=t.state,!t.output||!t.input&&0!==t.avail_in||o.status===ft&&e!==N)return i(t,0===t.avail_out?F:U);if(o.strm=t,a=o.last_flush,o.last_flush=e,o.status===rt)if(2===o.wrap)t.adler=0,l(o,31),l(o,139),l(o,8),o.gzhead?(l(o,(o.gzhead.text?1:0)+(o.gzhead.hcrc?2:0)+(o.gzhead.extra?4:0)+(o.gzhead.name?8:0)+(o.gzhead.comment?16:0)),l(o,255&o.gzhead.time),l(o,o.gzhead.time>>8&255),l(o,o.gzhead.time>>16&255),l(o,o.gzhead.time>>24&255),l(o,9===o.level?2:o.strategy>=j||o.level<2?4:0),l(o,255&o.gzhead.os),o.gzhead.extra&&o.gzhead.extra.length&&(l(o,255&o.gzhead.extra.length),l(o,o.gzhead.extra.length>>8&255)),o.gzhead.hcrc&&(t.adler=E(t.adler,o.pending_buf,o.pending,0)),o.gzindex=0,o.status=st):(l(o,0),l(o,0),l(o,0),l(o,0),l(o,0),l(o,9===o.level?2:o.strategy>=j||o.level<2?4:0),l(o,gt),o.status=dt);else{var _=q+(o.w_bits-8<<4)<<8;_|=(o.strategy>=j||o.level<2?0:o.level<6?1:6===o.level?2:3)<<6,0!==o.strstart&&(_|=nt),_+=31-_%31,o.status=dt,h(o,_),0!==o.strstart&&(h(o,t.adler>>>16),h(o,65535&t.adler)),t.adler=1}if(o.status===st)if(o.gzhead.extra){for(d=o.pending;o.gzindex<(65535&o.gzhead.extra.length)&&(o.pending!==o.pending_buf_size||(o.gzhead.hcrc&&o.pending>d&&(t.adler=E(t.adler,o.pending_buf,o.pending-d,d)),s(t),d=o.pending,o.pending!==o.pending_buf_size));)l(o,255&o.gzhead.extra[o.gzindex]),o.gzindex++;o.gzhead.hcrc&&o.pending>d&&(t.adler=E(t.adler,o.pending_buf,o.pending-d,d)),o.gzindex===o.gzhead.extra.length&&(o.gzindex=0,o.status=ot)}else o.status=ot;if(o.status===ot)if(o.gzhead.name){d=o.pending;do{if(o.pending===o.pending_buf_size&&(o.gzhead.hcrc&&o.pending>d&&(t.adler=E(t.adler,o.pending_buf,o.pending-d,d)),s(t),d=o.pending,o.pending===o.pending_buf_size)){f=1;break}f=o.gzindexd&&(t.adler=E(t.adler,o.pending_buf,o.pending-d,d)),0===f&&(o.gzindex=0,o.status=lt)}else o.status=lt;if(o.status===lt)if(o.gzhead.comment){d=o.pending;do{if(o.pending===o.pending_buf_size&&(o.gzhead.hcrc&&o.pending>d&&(t.adler=E(t.adler,o.pending_buf,o.pending-d,d)),s(t),d=o.pending,o.pending===o.pending_buf_size)){f=1;break}f=o.gzindexd&&(t.adler=E(t.adler,o.pending_buf,o.pending-d,d)),0===f&&(o.status=ht)}else o.status=ht;if(o.status===ht&&(o.gzhead.hcrc?(o.pending+2>o.pending_buf_size&&s(t),o.pending+2<=o.pending_buf_size&&(l(o,255&t.adler),l(o,t.adler>>8&255),t.adler=0,o.status=dt)):o.status=dt),0!==o.pending){if(s(t),0===t.avail_out)return o.last_flush=-1,D}else if(0===t.avail_in&&n(e)<=n(a)&&e!==N)return i(t,F);if(o.status===ft&&0!==t.avail_in)return i(t,F);if(0!==t.avail_in||0!==o.lookahead||e!==Z&&o.status!==ft){var u=o.strategy===j?g(o,e):o.strategy===K?b(o,e):x[o.level].func(o,e);if(u!==ct&&u!==bt||(o.status=ft),u===_t||u===ct)return 0===t.avail_out&&(o.last_flush=-1),D;if(u===ut&&(e===R?B._tr_align(o):e!==O&&(B._tr_stored_block(o,0,0,!1),e===C&&(r(o.head),0===o.lookahead&&(o.strstart=0,o.block_start=0,o.insert=0))),s(t),0===t.avail_out))return o.last_flush=-1,D}return e!==N?D:o.wrap<=0?I:(2===o.wrap?(l(o,255&t.adler),l(o,t.adler>>8&255),l(o,t.adler>>16&255),l(o,t.adler>>24&255),l(o,255&t.total_in),l(o,t.total_in>>8&255),l(o,t.total_in>>16&255),l(o,t.total_in>>24&255)):(h(o,t.adler>>>16),h(o,65535&t.adler)),s(t),o.wrap>0&&(o.wrap=-o.wrap),0!==o.pending?D:I)},a.deflateEnd=function(t){var e;return t&&t.state?(e=t.state.status)!==rt&&e!==st&&e!==ot&&e!==lt&&e!==ht&&e!==dt&&e!==ft?i(t,U):(t.state=null,e===dt?i(t,T):D):U},a.deflateSetDictionary=function(t,e){var a,i,n,s,o,l,h,d,f=e.length;if(!t||!t.state)return U;if(a=t.state,2===(s=a.wrap)||1===s&&a.status!==rt||a.lookahead)return U;for(1===s&&(t.adler=S(t.adler,e,f,0)),a.wrap=0,f>=a.w_size&&(0===s&&(r(a.head),a.strstart=0,a.block_start=0,a.insert=0),d=new z.Buf8(a.w_size),z.arraySet(d,e,f-a.w_size,a.w_size,0),e=d,f=a.w_size),o=t.avail_in,l=t.next_in,h=t.input,t.avail_in=f,t.next_in=0,t.input=e,_(a);a.lookahead>=et;){i=a.strstart,n=a.lookahead-(et-1);do{a.ins_h=(a.ins_h<>>24,u>>>=v,c-=v,0===(v=p>>>16&255))S[r++]=65535&p;else{if(!(16&v)){if(0==(64&v)){p=b[(65535&p)+(u&(1<>>=v,c-=v),c<15&&(u+=B[i++]<>>24,u>>>=v,c-=v,!(16&(v=p>>>16&255))){if(0==(64&v)){p=g[(65535&p)+(u&(1<l){t.msg="invalid distance too far back",a.mode=30;break t}if(u>>>=v,c-=v,v=r-s,y>v){if((v=y-v)>d&&a.sane){t.msg="invalid distance too far back",a.mode=30;break t}if(x=0,z=_,0===f){if(x+=h-v,v2;)S[r++]=z[x++],S[r++]=z[x++],S[r++]=z[x++],k-=3;k&&(S[r++]=z[x++],k>1&&(S[r++]=z[x++]))}else{x=r-y;do{S[r++]=S[x++],S[r++]=S[x++],S[r++]=S[x++],k-=3}while(k>2);k&&(S[r++]=S[x++],k>1&&(S[r++]=S[x++]))}break}}break}}while(i>3,u&=(1<<(c-=k<<3))-1,t.next_in=i,t.next_out=r,t.avail_in=i>>24&255)+(t>>>8&65280)+((65280&t)<<8)+((255&t)<<24)}function n(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new u.Buf16(320),this.work=new u.Buf16(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function r(t){var e;return t&&t.state?(e=t.state,t.total_in=t.total_out=e.total=0,t.msg="",e.wrap&&(t.adler=1&e.wrap),e.mode=N,e.last=0,e.havedict=0,e.dmax=32768,e.head=null,e.hold=0,e.bits=0,e.lencode=e.lendyn=new u.Buf32(dt),e.distcode=e.distdyn=new u.Buf32(ft),e.sane=1,e.back=-1,z):E}function s(t){var e;return t&&t.state?(e=t.state,e.wsize=0,e.whave=0,e.wnext=0,r(t)):E}function o(t,e){var a,i;return t&&t.state?(i=t.state,e<0?(a=0,e=-e):(a=1+(e>>4),e<48&&(e&=15)),e&&(e<8||e>15)?E:(null!==i.window&&i.wbits!==e&&(i.window=null),i.wrap=a,i.wbits=e,s(t))):E}function l(t,e){var a,i;return t?(i=new n,t.state=i,i.window=null,(a=o(t,e))!==z&&(t.state=null),a):E}function h(t){if(ut){var e;for(f=new u.Buf32(512),_=new u.Buf32(32),e=0;e<144;)t.lens[e++]=8;for(;e<256;)t.lens[e++]=9;for(;e<280;)t.lens[e++]=7;for(;e<288;)t.lens[e++]=8;for(m(p,t.lens,0,288,f,0,t.work,{bits:9}),e=0;e<32;)t.lens[e++]=5;m(v,t.lens,0,32,_,0,t.work,{bits:5}),ut=!1}t.lencode=f,t.lenbits=9,t.distcode=_,t.distbits=5}function d(t,e,a,i){var n,r=t.state;return null===r.window&&(r.wsize=1<=r.wsize?(u.arraySet(r.window,e,a-r.wsize,r.wsize,0),r.wnext=0,r.whave=r.wsize):((n=r.wsize-r.wnext)>i&&(n=i),u.arraySet(r.window,e,a-i,n,r.wnext),(i-=n)?(u.arraySet(r.window,e,a-i,i,0),r.wnext=i,r.whave=r.wsize):(r.wnext+=n,r.wnext===r.wsize&&(r.wnext=0),r.whave>>8&255,a.check=b(a.check,Et,2,0),_=0,dt=0,a.mode=O;break}if(a.flags=0,a.head&&(a.head.done=!1),!(1&a.wrap)||(((255&_)<<8)+(_>>8))%31){t.msg="incorrect header check",a.mode=ot;break}if((15&_)!==C){t.msg="unknown compression method",a.mode=ot;break}if(_>>>=4,dt-=4,yt=8+(15&_),0===a.wbits)a.wbits=yt;else if(yt>a.wbits){t.msg="invalid window size",a.mode=ot;break}a.dmax=1<>8&1),512&a.flags&&(Et[0]=255&_,Et[1]=_>>>8&255,a.check=b(a.check,Et,2,0)),_=0,dt=0,a.mode=D;case D:for(;dt<32;){if(0===l)break t;l--,_+=n[s++]<>>8&255,Et[2]=_>>>16&255,Et[3]=_>>>24&255,a.check=b(a.check,Et,4,0)),_=0,dt=0,a.mode=I;case I:for(;dt<16;){if(0===l)break t;l--,_+=n[s++]<>8),512&a.flags&&(Et[0]=255&_,Et[1]=_>>>8&255,a.check=b(a.check,Et,2,0)),_=0,dt=0,a.mode=U;case U:if(1024&a.flags){for(;dt<16;){if(0===l)break t;l--,_+=n[s++]<>>8&255,a.check=b(a.check,Et,2,0)),_=0,dt=0}else a.head&&(a.head.extra=null);a.mode=T;case T:if(1024&a.flags&&((ut=a.length)>l&&(ut=l),ut&&(a.head&&(yt=a.head.extra_len-a.length,a.head.extra||(a.head.extra=new Array(a.head.extra_len)),u.arraySet(a.head.extra,n,s,ut,yt)),512&a.flags&&(a.check=b(a.check,n,ut,s)),l-=ut,s+=ut,a.length-=ut),a.length))break t;a.length=0,a.mode=F;case F:if(2048&a.flags){if(0===l)break t;ut=0;do{yt=n[s+ut++],a.head&&yt&&a.length<65536&&(a.head.name+=String.fromCharCode(yt))}while(yt&&ut>9&1,a.head.done=!0),t.adler=a.check=0,a.mode=M;break;case j:for(;dt<32;){if(0===l)break t;l--,_+=n[s++]<>>=7&dt,dt-=7&dt,a.mode=nt;break}for(;dt<3;){if(0===l)break t;l--,_+=n[s++]<>>=1,dt-=1,3&_){case 0:a.mode=Y;break;case 1:if(h(a),a.mode=Q,e===x){_>>>=2,dt-=2;break t}break;case 2:a.mode=X;break;case 3:t.msg="invalid block type",a.mode=ot}_>>>=2,dt-=2;break;case Y:for(_>>>=7&dt,dt-=7&dt;dt<32;){if(0===l)break t;l--,_+=n[s++]<>>16^65535)){t.msg="invalid stored block lengths",a.mode=ot;break}if(a.length=65535&_,_=0,dt=0,a.mode=q,e===x)break t;case q:a.mode=G;case G:if(ut=a.length){if(ut>l&&(ut=l),ut>f&&(ut=f),0===ut)break t;u.arraySet(r,n,s,ut,o),l-=ut,s+=ut,f-=ut,o+=ut,a.length-=ut;break}a.mode=M;break;case X:for(;dt<14;){if(0===l)break t;l--,_+=n[s++]<>>=5,dt-=5,a.ndist=1+(31&_),_>>>=5,dt-=5,a.ncode=4+(15&_),_>>>=4,dt-=4,a.nlen>286||a.ndist>30){t.msg="too many length or distance symbols",a.mode=ot;break}a.have=0,a.mode=W;case W:for(;a.have>>=3,dt-=3}for(;a.have<19;)a.lens[At[a.have++]]=0;if(a.lencode=a.lendyn,a.lenbits=7,zt={bits:a.lenbits},xt=m(w,a.lens,0,19,a.lencode,0,a.work,zt),a.lenbits=zt.bits,xt){t.msg="invalid code lengths set",a.mode=ot;break}a.have=0,a.mode=J;case J:for(;a.have>>24,mt=St>>>16&255,wt=65535&St,!(gt<=dt);){if(0===l)break t;l--,_+=n[s++]<>>=gt,dt-=gt,a.lens[a.have++]=wt;else{if(16===wt){for(Bt=gt+2;dt>>=gt,dt-=gt,0===a.have){t.msg="invalid bit length repeat",a.mode=ot;break}yt=a.lens[a.have-1],ut=3+(3&_),_>>>=2,dt-=2}else if(17===wt){for(Bt=gt+3;dt>>=gt)),_>>>=3,dt-=3}else{for(Bt=gt+7;dt>>=gt)),_>>>=7,dt-=7}if(a.have+ut>a.nlen+a.ndist){t.msg="invalid bit length repeat",a.mode=ot;break}for(;ut--;)a.lens[a.have++]=yt}}if(a.mode===ot)break;if(0===a.lens[256]){t.msg="invalid code -- missing end-of-block",a.mode=ot;break}if(a.lenbits=9,zt={bits:a.lenbits},xt=m(p,a.lens,0,a.nlen,a.lencode,0,a.work,zt),a.lenbits=zt.bits,xt){t.msg="invalid literal/lengths set",a.mode=ot;break}if(a.distbits=6,a.distcode=a.distdyn,zt={bits:a.distbits},xt=m(v,a.lens,a.nlen,a.ndist,a.distcode,0,a.work,zt),a.distbits=zt.bits,xt){t.msg="invalid distances set",a.mode=ot;break}if(a.mode=Q,e===x)break t;case Q:a.mode=V;case V:if(l>=6&&f>=258){t.next_out=o,t.avail_out=f,t.next_in=s,t.avail_in=l,a.hold=_,a.bits=dt,g(t,_t),o=t.next_out,r=t.output,f=t.avail_out,s=t.next_in,n=t.input,l=t.avail_in,_=a.hold,dt=a.bits,a.mode===M&&(a.back=-1);break}for(a.back=0;St=a.lencode[_&(1<>>24,mt=St>>>16&255,wt=65535&St,!(gt<=dt);){if(0===l)break t;l--,_+=n[s++]<>pt)],gt=St>>>24,mt=St>>>16&255,wt=65535&St,!(pt+gt<=dt);){if(0===l)break t;l--,_+=n[s++]<>>=pt,dt-=pt,a.back+=pt}if(_>>>=gt,dt-=gt,a.back+=gt,a.length=wt,0===mt){a.mode=it;break}if(32&mt){a.back=-1,a.mode=M;break}if(64&mt){t.msg="invalid literal/length code",a.mode=ot;break}a.extra=15&mt,a.mode=$;case $:if(a.extra){for(Bt=a.extra;dt>>=a.extra,dt-=a.extra,a.back+=a.extra}a.was=a.length,a.mode=tt;case tt:for(;St=a.distcode[_&(1<>>24,mt=St>>>16&255,wt=65535&St,!(gt<=dt);){if(0===l)break t;l--,_+=n[s++]<>pt)],gt=St>>>24,mt=St>>>16&255,wt=65535&St,!(pt+gt<=dt);){if(0===l)break t;l--,_+=n[s++]<>>=pt,dt-=pt,a.back+=pt}if(_>>>=gt,dt-=gt,a.back+=gt,64&mt){t.msg="invalid distance code",a.mode=ot;break}a.offset=wt,a.extra=15&mt,a.mode=et;case et:if(a.extra){for(Bt=a.extra;dt>>=a.extra,dt-=a.extra,a.back+=a.extra}if(a.offset>a.dmax){t.msg="invalid distance too far back",a.mode=ot;break}a.mode=at;case at:if(0===f)break t;if(ut=_t-f,a.offset>ut){if((ut=a.offset-ut)>a.whave&&a.sane){t.msg="invalid distance too far back",a.mode=ot;break}ut>a.wnext?(ut-=a.wnext,ct=a.wsize-ut):ct=a.wnext-ut,ut>a.length&&(ut=a.length),bt=a.window}else bt=r,ct=o-a.offset,ut=a.length;ut>f&&(ut=f),f-=ut,a.length-=ut;do{r[o++]=bt[ct++]}while(--ut);0===a.length&&(a.mode=V);break;case it:if(0===f)break t;r[o++]=a.length,f--,a.mode=V;break;case nt:if(a.wrap){for(;dt<32;){if(0===l)break t;l--,_|=n[s++]<=1&&0===I[S];S--);if(E>S&&(E=S),0===S)return h[d++]=20971520,h[d++]=20971520,_.bits=1,0;for(B=1;B0&&(0===t||1!==S))return-1;for(U[1]=0,x=1;x<15;x++)U[x+1]=U[x]+I[x];for(z=0;z852||2===t&&C>592)return 1;for(;;){p=x-Z,f[z]w?(v=T[F+f[z]],k=O[D+f[z]]):(v=96,k=0),u=1<>Z)+(c-=u)]=p<<24|v<<16|k|0}while(0!==c);for(u=1<>=1;if(0!==u?(N&=u-1,N+=u):N=0,z++,0==--I[x]){if(x===S)break;x=e[a+f[z]]}if(x>E&&(N&g)!==b){for(0===Z&&(Z=E),m+=B,R=1<<(A=x-Z);A+Z852||2===t&&C>592)return 1;h[b=N&g]=E<<24|A<<16|m-d|0}}return 0!==N&&(h[m+N]=x-Z<<24|64<<16|0),_.bits=E,0}},{"../utils/common":3}],13:[function(t,e,a){"use strict";e.exports={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"}},{}],14:[function(t,e,a){"use strict";function i(t){for(var e=t.length;--e>=0;)t[e]=0}function n(t,e,a,i,n){this.static_tree=t,this.extra_bits=e,this.extra_base=a,this.elems=i,this.max_length=n,this.has_stree=t&&t.length}function r(t,e){this.dyn_tree=t,this.max_code=0,this.stat_desc=e}function s(t){return t<256?et[t]:et[256+(t>>>7)]}function o(t,e){t.pending_buf[t.pending++]=255&e,t.pending_buf[t.pending++]=e>>>8&255}function l(t,e,a){t.bi_valid>M-a?(t.bi_buf|=e<>M-t.bi_valid,t.bi_valid+=a-M):(t.bi_buf|=e<>>=1,a<<=1}while(--e>0);return a>>>1}function f(t){16===t.bi_valid?(o(t,t.bi_buf),t.bi_buf=0,t.bi_valid=0):t.bi_valid>=8&&(t.pending_buf[t.pending++]=255&t.bi_buf,t.bi_buf>>=8,t.bi_valid-=8)}function _(t,e){var a,i,n,r,s,o,l=e.dyn_tree,h=e.max_code,d=e.stat_desc.static_tree,f=e.stat_desc.has_stree,_=e.stat_desc.extra_bits,u=e.stat_desc.extra_base,c=e.stat_desc.max_length,b=0;for(r=0;r<=K;r++)t.bl_count[r]=0;for(l[2*t.heap[t.heap_max]+1]=0,a=t.heap_max+1;ac&&(r=c,b++),l[2*i+1]=r,i>h||(t.bl_count[r]++,s=0,i>=u&&(s=_[i-u]),o=l[2*i],t.opt_len+=o*(r+s),f&&(t.static_len+=o*(d[2*i+1]+s)));if(0!==b){do{for(r=c-1;0===t.bl_count[r];)r--;t.bl_count[r]--,t.bl_count[r+1]+=2,t.bl_count[c]--,b-=2}while(b>0);for(r=c;0!==r;r--)for(i=t.bl_count[r];0!==i;)(n=t.heap[--a])>h||(l[2*n+1]!==r&&(t.opt_len+=(r-l[2*n+1])*l[2*n],l[2*n+1]=r),i--)}}function u(t,e,a){var i,n,r=new Array(K+1),s=0;for(i=1;i<=K;i++)r[i]=s=s+a[i-1]<<1;for(n=0;n<=e;n++){var o=t[2*n+1];0!==o&&(t[2*n]=d(r[o]++,o))}}function c(){var t,e,a,i,r,s=new Array(K+1);for(a=0,i=0;i>=7;i8?o(t,t.bi_buf):t.bi_valid>0&&(t.pending_buf[t.pending++]=t.bi_buf),t.bi_buf=0,t.bi_valid=0}function m(t,e,a,i){g(t),i&&(o(t,a),o(t,~a)),A.arraySet(t.pending_buf,t.window,e,a,t.pending),t.pending+=a}function w(t,e,a,i){var n=2*e,r=2*a;return t[n]>1;a>=1;a--)p(t,r,a);n=l;do{a=t.heap[1],t.heap[1]=t.heap[t.heap_len--],p(t,r,1),i=t.heap[1],t.heap[--t.heap_max]=a,t.heap[--t.heap_max]=i,r[2*n]=r[2*a]+r[2*i],t.depth[n]=(t.depth[a]>=t.depth[i]?t.depth[a]:t.depth[i])+1,r[2*a+1]=r[2*i+1]=n,t.heap[1]=n++,p(t,r,1)}while(t.heap_len>=2);t.heap[--t.heap_max]=t.heap[1],_(t,e),u(r,h,t.bl_count)}function y(t,e,a){var i,n,r=-1,s=e[1],o=0,l=7,h=4;for(0===s&&(l=138,h=3),e[2*(a+1)+1]=65535,i=0;i<=a;i++)n=s,s=e[2*(i+1)+1],++o=3&&0===t.bl_tree[2*V[e]+1];e--);return t.opt_len+=3*(e+1)+5+5+4,e}function B(t,e,a,i){var n;for(l(t,e-257,5),l(t,a-1,5),l(t,i-4,4),n=0;n>>=1)if(1&a&&0!==t.dyn_ltree[2*e])return R;if(0!==t.dyn_ltree[18]||0!==t.dyn_ltree[20]||0!==t.dyn_ltree[26])return C;for(e=32;e0?(t.strm.data_type===N&&(t.strm.data_type=S(t)),k(t,t.l_desc),k(t,t.d_desc),s=z(t),n=t.opt_len+3+7>>>3,(r=t.static_len+3+7>>>3)<=n&&(n=r)):n=r=a+5,a+4<=n&&-1!==e?E(t,e,a,i):t.strategy===Z||r===n?(l(t,(D<<1)+(i?1:0),3),v(t,$,tt)):(l(t,(I<<1)+(i?1:0),3),B(t,t.l_desc.max_code+1,t.d_desc.max_code+1,s+1),v(t,t.dyn_ltree,t.dyn_dtree)),b(t),i&&g(t)},a._tr_tally=function(t,e,a){return t.pending_buf[t.d_buf+2*t.last_lit]=e>>>8&255,t.pending_buf[t.d_buf+2*t.last_lit+1]=255&e,t.pending_buf[t.l_buf+t.last_lit]=255&a,t.last_lit++,0===e?t.dyn_ltree[2*a]++:(t.matches++,e--,t.dyn_ltree[2*(at[a]+T+1)]++,t.dyn_dtree[2*s(e)]++),t.last_lit===t.lit_bufsize-1},a._tr_align=function(t){l(t,D<<1,3),h(t,Y,$),f(t)}},{"../utils/common":3}],15:[function(t,e,a){"use strict";e.exports=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}},{}],"/":[function(t,e,a){"use strict";var i={};(0,t("./lib/utils/common").assign)(i,t("./lib/deflate"),t("./lib/inflate"),t("./lib/zlib/constants")),e.exports=i},{"./lib/deflate":1,"./lib/inflate":2,"./lib/utils/common":3,"./lib/zlib/constants":6}]},{},[])("/")}); diff --git a/apps/assets/scripts/wvnc.js b/apps/assets/scripts/wvnc.js new file mode 100644 index 0000000..6f12e2f --- /dev/null +++ b/apps/assets/scripts/wvnc.js @@ -0,0 +1 @@ +(function(){var e;e=function(){function e(e){var t,n;this.socket=void 0,this.ws=void 0,this.canvas=void 0,n="decoder.js",this.scale=1,e.ws&&(this.ws=e.ws),this.canvas=e.element,"string"==typeof this.canvas&&(this.canvas=document.getElementById(this.canvas)),e.worker&&(n=e.worker),this.decoder=new Worker(n),(t=this).mouseMask=0,this.decoder.onmessage=function(e){return t.process(e.data)}}return e.prototype.init=function(){var n;return n=this,new Promise(function(e,t){return n.canvas?(n.initInputEvent(),e()):t("Canvas is not set")})},e.prototype.initInputEvent=function(){var n,s,o;if((s=this).canvas&&(n=function(e){var t;return t=s.canvas.getBoundingClientRect(),{x:Math.floor((e.clientX-t.left)/s.scale),y:Math.floor((e.clientY-t.top)/s.scale)}},o=function(e){var t;return t=n(e),s.sendPointEvent(t.x,t.y,s.mouseMask)},s.canvas))return s.canvas.style.cursor="none",s.canvas.oncontextmenu=function(e){return e.preventDefault(),!1},s.canvas.onmousemove=function(e){return o(e)},s.canvas.onmousedown=function(e){var t;return t=1<>8,s[2]=255&t,s[3]=t>>8,s[4]=n,this.socket.send(this.buildCommand(5,s))},e.prototype.sendKeyEvent=function(e,t){var n;if(this.socket)return(n=new Uint8Array(3))[0]=255&e,n[1]=e>>8,n[2]=t,console.log(e,t),this.socket.send(this.buildCommand(6,n))},e.prototype.buildCommand=function(e,t){var n,s;switch(s=void 0,typeof t){case"string":s=(new TextEncoder).encode(t);break;case"number":s=new Uint8Array([t]);break;default:s=t}return(n=new Uint8Array(s.length+3))[0]=e,n[2]=s.length>>8,n[1]=15&s.length,n.set(s,3),n.buffer},e.prototype.oncopy=function(e){return console.log("Get clipboard text: "+e)},e.prototype.onpassword=function(){return new Promise(function(e,t){return t("onpassword is not implemented")})},e.prototype.sendTextAsClipboard=function(e){if(this.socket)return console.log("send ",e),this.socket.send(this.buildCommand(7,e))},e.prototype.oncredential=function(){return new Promise(function(e,t){return t("oncredential is not implemented")})},e.prototype.consume=function(e){var t,n,s,o,r,a,i;switch(t=(n=new Uint8Array(e.data))[0],a=this,t){case 254:return n=n.subarray(1,n.length-1),s=new TextDecoder("utf-8"),console.log("Error",s.decode(n));case 129:return console.log("Request for password"),this.onpassword().then(function(e){return a.socket.send(a.buildCommand(2,e))});case 130:return console.log("Request for login"),this.oncredential().then(function(e,t){var n;return(n=new Uint8Array(e.length+t.length+1)).set((new TextEncoder).encode(e),0),n.set(["\0"],e.length),n.set((new TextEncoder).encode(t),e.length+1),a.socket.send(a.buildCommand(3,n))});case 131:return console.log("resize"),i=n[1]|n[2]<<8,r=n[3]|n[4]<<8,o=n[5],this.initCanvas(i,r,o),this.socket.send(this.buildCommand(4,1));case 132:return this.decoder.postMessage(n.buffer,[n.buffer]);case 133:return n=n.subarray(1),s=new TextDecoder("utf-8"),this.oncopy(s.decode(n)),this.socket.send(this.buildCommand(4,1));default:return console.log(t)}},e}(),window.WVNC=e}).call(this); \ No newline at end of file diff --git a/apps/assets/shs/antd.sh b/apps/assets/shs/antd.sh new file mode 100644 index 0000000..eb400e0 --- /dev/null +++ b/apps/assets/shs/antd.sh @@ -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 "$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 diff --git a/apps/controllers/ScriptController.lua b/apps/controllers/ScriptController.lua new file mode 100644 index 0000000..ba6af6a --- /dev/null +++ b/apps/controllers/ScriptController.lua @@ -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 \ No newline at end of file diff --git a/apps/controllers/WebVNCController.lua b/apps/controllers/WebVNCController.lua new file mode 100644 index 0000000..659bc60 --- /dev/null +++ b/apps/controllers/WebVNCController.lua @@ -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 \ No newline at end of file diff --git a/apps/controllers/WvncController.lua b/apps/controllers/WvncController.lua deleted file mode 100644 index 2e4dc91..0000000 --- a/apps/controllers/WvncController.lua +++ /dev/null @@ -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 \ No newline at end of file diff --git a/apps/views/default/index/testrq.ls b/apps/views/default/index/testrq.ls new file mode 100644 index 0000000..8625f20 --- /dev/null +++ b/apps/views/default/index/testrq.ls @@ -0,0 +1,11 @@ + +
+
+ First name:
+
+ Last name:
+

+ +
\ No newline at end of file diff --git a/apps/views/default/webVNC/index.ls b/apps/views/default/webVNC/index.ls new file mode 100644 index 0000000..c7af42e --- /dev/null +++ b/apps/views/default/webVNC/index.ls @@ -0,0 +1,7 @@ +

VNC screen here

+

ConnectDisconnect

+

+ + +

+ \ No newline at end of file diff --git a/apps/views/default/wvnc/index.ls b/apps/views/default/wvnc/index.ls deleted file mode 100644 index 66dcd9d..0000000 --- a/apps/views/default/wvnc/index.ls +++ /dev/null @@ -1,3 +0,0 @@ -

VNC screen here

-

ConnectSTOP

- \ No newline at end of file