diff --git a/apps/assets/coffee/WVNC.coffee b/apps/assets/coffee/WVNC.coffee index a9fd59c..57e0740 100644 --- a/apps/assets/coffee/WVNC.coffee +++ b/apps/assets/coffee/WVNC.coffee @@ -6,9 +6,8 @@ class WVNC extends window.classes.BaseObject @uri = @args[0] if @args and @args.length > 0 @canvas = undefined @canvas = ($ @args[1])[0] if @args and @args.length > 1 - @buffer = $("")[0] @lastPose = { x: 0, y: 0 } - @scale = 0.8 + @scale = 1.0 @decoder = new Worker('/assets/scripts/decoder.js') me = @ @mouseMask = 0 @@ -40,7 +39,7 @@ class WVNC extends window.classes.BaseObject me.sendPointEvent p.x, p.y, me.mouseMask return unless me.canvas - ($ me.canvas).css "cursor", "none" + #($ me.canvas).css "cursor", "none" ($ me.canvas).contextmenu (e) -> e.preventDefault() return false @@ -91,47 +90,30 @@ class WVNC extends window.classes.BaseObject initCanvas: (w, h , d) -> me = @ @depth = d - @buffer.width = w - @buffer.height = h + @canvas.width = w + @canvas.height = h @resolution = w: w, h: h, depth: @depth @decoder.postMessage @resolution - ctx = @buffer.getContext('2d') - data = ctx.createImageData w, h - ctx.putImageData data, 0, 0 - process: (data) -> - data.pixels = new Uint8ClampedArray data.pixels - data.pixels = data.pixels.subarray 10 if data.flag is 0 and @resolution.depth is 32 - ctx = @buffer.getContext('2d') - imgData = ctx.createImageData data.w, data.h - imgData.data.set data.pixels - ctx.putImageData imgData, data.x, data.y - - @draw() if data.x isnt @lastPose.x or data.y > @resolution.h - 10 - @lastPose = { x: data.x, y: data.y } + process: (msg) -> + if not @socket + return + data = new Uint8Array msg.buffer + #w = @buffer.width * @scale + #h = @buffer.height * @scale + ctx = @canvas.getContext "2d" + imgData = ctx.createImageData msg.w, msg.h + imgData.data.set data + ctx.putImageData imgData, msg.x, msg.y setScale: (n) -> @scale = n @draw() - draw: () -> - if not @socket - return - - w = @buffer.width * @scale - h = @buffer.height * @scale - @canvas.width = w - @canvas.height = h - ctx = @canvas.getContext "2d" - ctx.save() - ctx.scale @scale, @scale - ctx.clearRect 0, 0, w, h - ctx.drawImage @buffer, 0, 0 - ctx.restore() openSession: () -> me = @ @@ -152,7 +134,7 @@ class WVNC extends window.classes.BaseObject initConnection: () -> vncserver = "localhost:5901" data = new Uint8Array vncserver.length + 5 - data[0] = 16 # bbp + data[0] = 32 # bbp ### flag: 0: raw data no compress @@ -160,7 +142,7 @@ class WVNC extends window.classes.BaseObject 2: raw data compressed by zlib 3: jpeg data compressed by zlib ### - data[1] = 2 + data[1] = 3 data[2] = 50 # jpeg quality ## rate in milisecond rate = 30 @@ -237,11 +219,8 @@ class WVNC extends window.classes.BaseObject # status command for ack @socket.send(@buildCommand 0x04, 1) when 0x84 - #console.log "update" + # send data to web assembly for decoding @decoder.postMessage data.buffer, [data.buffer] - #@decodeFB d - # ack - #@socket.send(@buildCommand 0x04, 1) else console.log cmd diff --git a/apps/assets/coffee/decoder.coffee b/apps/assets/coffee/decoder.coffee index 978f4ee..af44fd9 100644 --- a/apps/assets/coffee/decoder.coffee +++ b/apps/assets/coffee/decoder.coffee @@ -1,84 +1,48 @@ #zlib library -importScripts('pako.min.js') -# jpeg library -importScripts('jpeg-decoder.js') +importScripts('wvnc_asm.js') +api = {} resolution = undefined -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 resolution.depth is 32 - step = resolution.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, resolution.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 = {} - 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] +#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'] ) + } onmessage = (e) -> - return resolution = e.data if e.data.depth - update e.data \ No newline at end of file + if e.data.depth + resolution = e.data + #api.destroyBuffer frame_buffer if frame_buffer + #frame_buffer = api.createBuffer resolution.w * resolution.h * 4 + #else if e.data.cleanup + # api.destroyBuffer frame_buffer if frame_buffer + else + datain = new Uint8Array e.data + 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, resolution.depth, size + #api.updateBuffer frame_buffer, p, datain.length, resolution.w, resolution.h, resolution.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.buffer = tmp.buffer + msg.x = x + msg.y = y + msg.w = w + msg.h = h + postMessage msg, [msg.buffer] + api.destroyBuffer p + if flag isnt 0x0 or resolution.depth isnt 32 + api.destroyBuffer po \ No newline at end of file diff --git a/apps/assets/scripts/decoder.js b/apps/assets/scripts/decoder.js index 94248eb..753ce1d 100644 --- a/apps/assets/scripts/decoder.js +++ b/apps/assets/scripts/decoder.js @@ -1,114 +1,50 @@ // Generated by CoffeeScript 1.9.3 - var decodeJPEG, decodeRaw, getImageData, onmessage, pixelValue, resolution, update; + var api, onmessage, resolution; - importScripts('pako.min.js'); + importScripts('wvnc_asm.js'); - importScripts('jpeg-decoder.js'); + api = {}; resolution = void 0; - pixelValue = function(value, depth) { - var pixel; - pixel = { - r: 255, - g: 255, - b: 255, - a: 255 + 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']) }; - 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 (resolution.depth === 32) { - return d.pixels; - } - step = resolution.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, resolution.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]); }; onmessage = function(e) { + var datain, dataout, flag, h, msg, p, po, size, tmp, w, x, y; if (e.data.depth) { return resolution = e.data; + } else { + datain = new Uint8Array(e.data); + 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, resolution.depth, size); + dataout = new Uint8Array(Module.HEAP8.buffer, po, size); + msg = {}; + tmp = new Uint8Array(size); + tmp.set(dataout, 0); + msg.buffer = tmp.buffer; + msg.x = x; + msg.y = y; + msg.w = w; + msg.h = h; + postMessage(msg, [msg.buffer]); + api.destroyBuffer(p); + if (flag !== 0x0 || resolution.depth !== 32) { + return api.destroyBuffer(po); + } } - return update(e.data); }; diff --git a/apps/assets/scripts/main.js b/apps/assets/scripts/main.js index 76bee10..2580aa8 100644 --- a/apps/assets/scripts/main.js +++ b/apps/assets/scripts/main.js @@ -176,12 +176,11 @@ if (this.args && this.args.length > 1) { this.canvas = ($(this.args[1]))[0]; } - this.buffer = $("")[0]; this.lastPose = { x: 0, y: 0 }; - this.scale = 0.8; + this.scale = 1.0; this.decoder = new Worker('/assets/scripts/decoder.js'); me = this; this.mouseMask = 0; @@ -228,7 +227,6 @@ if (!me.canvas) { return; } - ($(me.canvas)).css("cursor", "none"); ($(me.canvas)).contextmenu(function(e) { e.preventDefault(); return false; @@ -283,39 +281,29 @@ }; WVNC.prototype.initCanvas = function(w, h, d) { - var ctx, data, me; + var me; me = this; this.depth = d; - this.buffer.width = w; - this.buffer.height = h; + this.canvas.width = w; + this.canvas.height = h; this.resolution = { w: w, h: h, depth: this.depth }; - this.decoder.postMessage(this.resolution); - ctx = this.buffer.getContext('2d'); - data = ctx.createImageData(w, h); - return ctx.putImageData(data, 0, 0); + return this.decoder.postMessage(this.resolution); }; - WVNC.prototype.process = function(data) { - var ctx, imgData; - data.pixels = new Uint8ClampedArray(data.pixels); - if (data.flag === 0 && this.resolution.depth === 32) { - data.pixels = data.pixels.subarray(10); + WVNC.prototype.process = function(msg) { + var ctx, data, imgData; + if (!this.socket) { + return; } - ctx = this.buffer.getContext('2d'); - imgData = ctx.createImageData(data.w, data.h); - imgData.data.set(data.pixels); - ctx.putImageData(imgData, data.x, data.y); - if (data.x !== this.lastPose.x || data.y > this.resolution.h - 10) { - this.draw(); - } - return this.lastPose = { - x: data.x, - y: data.y - }; + data = new Uint8Array(msg.buffer); + ctx = this.canvas.getContext("2d"); + imgData = ctx.createImageData(msg.w, msg.h); + imgData.data.set(data); + return ctx.putImageData(imgData, msg.x, msg.y); }; WVNC.prototype.setScale = function(n) { @@ -323,23 +311,6 @@ return this.draw(); }; - WVNC.prototype.draw = function() { - var ctx, h, w; - if (!this.socket) { - return; - } - w = this.buffer.width * this.scale; - h = this.buffer.height * this.scale; - this.canvas.width = w; - this.canvas.height = h; - ctx = this.canvas.getContext("2d"); - ctx.save(); - ctx.scale(this.scale, this.scale); - ctx.clearRect(0, 0, w, h); - ctx.drawImage(this.buffer, 0, 0); - return ctx.restore(); - }; - WVNC.prototype.openSession = function() { var me; me = this; @@ -368,7 +339,7 @@ var data, rate, vncserver; vncserver = "localhost:5901"; data = new Uint8Array(vncserver.length + 5); - data[0] = 16; + data[0] = 32; /* flag: @@ -377,7 +348,7 @@ 2: raw data compressed by zlib 3: jpeg data compressed by zlib */ - data[1] = 2; + data[1] = 3; data[2] = 50; rate = 30; data[3] = rate & 0xFF; diff --git a/apps/assets/scripts/wvnc_asm.js b/apps/assets/scripts/wvnc_asm.js new file mode 100644 index 0000000..65b2c88 --- /dev/null +++ b/apps/assets/scripts/wvnc_asm.js @@ -0,0 +1,4 @@ +var Module=typeof Module!=="undefined"?Module:{};var moduleOverrides={};var key;for(key in Module){if(Module.hasOwnProperty(key)){moduleOverrides[key]=Module[key]}}Module["arguments"]=[];Module["thisProgram"]="./this.program";Module["quit"]=(function(status,toThrow){throw toThrow});Module["preRun"]=[];Module["postRun"]=[];var ENVIRONMENT_IS_WEB=false;var ENVIRONMENT_IS_WORKER=false;var ENVIRONMENT_IS_NODE=false;var ENVIRONMENT_IS_SHELL=false;ENVIRONMENT_IS_WEB=typeof window==="object";ENVIRONMENT_IS_WORKER=typeof importScripts==="function";ENVIRONMENT_IS_NODE=typeof process==="object"&&typeof require==="function"&&!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_WORKER;ENVIRONMENT_IS_SHELL=!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_NODE&&!ENVIRONMENT_IS_WORKER;var scriptDirectory="";function locateFile(path){if(Module["locateFile"]){return Module["locateFile"](path,scriptDirectory)}else{return scriptDirectory+path}}if(ENVIRONMENT_IS_NODE){scriptDirectory=__dirname+"/";var nodeFS;var nodePath;Module["read"]=function shell_read(filename,binary){var ret;if(!nodeFS)nodeFS=require("fs");if(!nodePath)nodePath=require("path");filename=nodePath["normalize"](filename);ret=nodeFS["readFileSync"](filename);return binary?ret:ret.toString()};Module["readBinary"]=function readBinary(filename){var ret=Module["read"](filename,true);if(!ret.buffer){ret=new Uint8Array(ret)}assert(ret.buffer);return ret};if(process["argv"].length>1){Module["thisProgram"]=process["argv"][1].replace(/\\/g,"/")}Module["arguments"]=process["argv"].slice(2);if(typeof module!=="undefined"){module["exports"]=Module}process["on"]("uncaughtException",(function(ex){if(!(ex instanceof ExitStatus)){throw ex}}));process["on"]("unhandledRejection",(function(reason,p){process["exit"](1)}));Module["quit"]=(function(status){process["exit"](status)});Module["inspect"]=(function(){return"[Emscripten Module object]"})}else if(ENVIRONMENT_IS_SHELL){if(typeof read!="undefined"){Module["read"]=function shell_read(f){return read(f)}}Module["readBinary"]=function readBinary(f){var data;if(typeof readbuffer==="function"){return new Uint8Array(readbuffer(f))}data=read(f,"binary");assert(typeof data==="object");return data};if(typeof scriptArgs!="undefined"){Module["arguments"]=scriptArgs}else if(typeof arguments!="undefined"){Module["arguments"]=arguments}if(typeof quit==="function"){Module["quit"]=(function(status){quit(status)})}}else if(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER){if(ENVIRONMENT_IS_WEB){if(document.currentScript){scriptDirectory=document.currentScript.src}}else{scriptDirectory=self.location.href}if(scriptDirectory.indexOf("blob:")!==0){scriptDirectory=scriptDirectory.substr(0,scriptDirectory.lastIndexOf("/")+1)}else{scriptDirectory=""}Module["read"]=function shell_read(url){var xhr=new XMLHttpRequest;xhr.open("GET",url,false);xhr.send(null);return xhr.responseText};if(ENVIRONMENT_IS_WORKER){Module["readBinary"]=function readBinary(url){var xhr=new XMLHttpRequest;xhr.open("GET",url,false);xhr.responseType="arraybuffer";xhr.send(null);return new Uint8Array(xhr.response)}}Module["readAsync"]=function readAsync(url,onload,onerror){var xhr=new XMLHttpRequest;xhr.open("GET",url,true);xhr.responseType="arraybuffer";xhr.onload=function xhr_onload(){if(xhr.status==200||xhr.status==0&&xhr.response){onload(xhr.response);return}onerror()};xhr.onerror=onerror;xhr.send(null)};Module["setWindowTitle"]=(function(title){document.title=title})}else{}var out=Module["print"]||(typeof console!=="undefined"?console.log.bind(console):typeof print!=="undefined"?print:null);var err=Module["printErr"]||(typeof printErr!=="undefined"?printErr:typeof console!=="undefined"&&console.warn.bind(console)||out);for(key in moduleOverrides){if(moduleOverrides.hasOwnProperty(key)){Module[key]=moduleOverrides[key]}}moduleOverrides=undefined;var STACK_ALIGN=16;function staticAlloc(size){var ret=STATICTOP;STATICTOP=STATICTOP+size+15&-16;return ret}function dynamicAlloc(size){var ret=HEAP32[DYNAMICTOP_PTR>>2];var end=ret+size+15&-16;HEAP32[DYNAMICTOP_PTR>>2]=end;if(end>=TOTAL_MEMORY){var success=enlargeMemory();if(!success){HEAP32[DYNAMICTOP_PTR>>2]=ret;return 0}}return ret}function alignMemory(size,factor){if(!factor)factor=STACK_ALIGN;var ret=size=Math.ceil(size/factor)*factor;return ret}var asm2wasmImports={"f64-rem":(function(x,y){return x%y}),"debugger":(function(){debugger})};var functionPointers=new Array(0);var GLOBAL_BASE=1024;var ABORT=false;var EXITSTATUS=0;function assert(condition,text){if(!condition){abort("Assertion failed: "+text)}}function getCFunc(ident){var func=Module["_"+ident];assert(func,"Cannot call unknown function "+ident+", make sure it is exported");return func}var JSfuncs={"stackSave":(function(){stackSave()}),"stackRestore":(function(){stackRestore()}),"arrayToC":(function(arr){var ret=stackAlloc(arr.length);writeArrayToMemory(arr,ret);return ret}),"stringToC":(function(str){var ret=0;if(str!==null&&str!==undefined&&str!==0){var len=(str.length<<2)+1;ret=stackAlloc(len);stringToUTF8(str,ret,len)}return ret})};var toC={"string":JSfuncs["stringToC"],"array":JSfuncs["arrayToC"]};function ccall(ident,returnType,argTypes,args,opts){function convertReturnValue(ret){if(returnType==="string")return Pointer_stringify(ret);if(returnType==="boolean")return Boolean(ret);return ret}var func=getCFunc(ident);var cArgs=[];var stack=0;if(args){for(var i=0;i>0];hasUtf|=t;if(t==0&&!length)break;i++;if(length&&i==length)break}if(!length)length=i;var ret="";if(hasUtf<128){var MAX_CHUNK=1024;var curr;while(length>0){curr=String.fromCharCode.apply(String,HEAPU8.subarray(ptr,ptr+Math.min(length,MAX_CHUNK)));ret=ret?ret+curr:curr;ptr+=MAX_CHUNK;length-=MAX_CHUNK}return ret}return UTF8ToString(ptr)}var UTF8Decoder=typeof TextDecoder!=="undefined"?new TextDecoder("utf8"):undefined;function UTF8ArrayToString(u8Array,idx){var endPtr=idx;while(u8Array[endPtr])++endPtr;if(endPtr-idx>16&&u8Array.subarray&&UTF8Decoder){return UTF8Decoder.decode(u8Array.subarray(idx,endPtr))}else{var u0,u1,u2,u3,u4,u5;var str="";while(1){u0=u8Array[idx++];if(!u0)return str;if(!(u0&128)){str+=String.fromCharCode(u0);continue}u1=u8Array[idx++]&63;if((u0&224)==192){str+=String.fromCharCode((u0&31)<<6|u1);continue}u2=u8Array[idx++]&63;if((u0&240)==224){u0=(u0&15)<<12|u1<<6|u2}else{u3=u8Array[idx++]&63;if((u0&248)==240){u0=(u0&7)<<18|u1<<12|u2<<6|u3}else{u4=u8Array[idx++]&63;if((u0&252)==248){u0=(u0&3)<<24|u1<<18|u2<<12|u3<<6|u4}else{u5=u8Array[idx++]&63;u0=(u0&1)<<30|u1<<24|u2<<18|u3<<12|u4<<6|u5}}}if(u0<65536){str+=String.fromCharCode(u0)}else{var ch=u0-65536;str+=String.fromCharCode(55296|ch>>10,56320|ch&1023)}}}}function UTF8ToString(ptr){return UTF8ArrayToString(HEAPU8,ptr)}function stringToUTF8Array(str,outU8Array,outIdx,maxBytesToWrite){if(!(maxBytesToWrite>0))return 0;var startIdx=outIdx;var endIdx=outIdx+maxBytesToWrite-1;for(var i=0;i=55296&&u<=57343){var u1=str.charCodeAt(++i);u=65536+((u&1023)<<10)|u1&1023}if(u<=127){if(outIdx>=endIdx)break;outU8Array[outIdx++]=u}else if(u<=2047){if(outIdx+1>=endIdx)break;outU8Array[outIdx++]=192|u>>6;outU8Array[outIdx++]=128|u&63}else if(u<=65535){if(outIdx+2>=endIdx)break;outU8Array[outIdx++]=224|u>>12;outU8Array[outIdx++]=128|u>>6&63;outU8Array[outIdx++]=128|u&63}else if(u<=2097151){if(outIdx+3>=endIdx)break;outU8Array[outIdx++]=240|u>>18;outU8Array[outIdx++]=128|u>>12&63;outU8Array[outIdx++]=128|u>>6&63;outU8Array[outIdx++]=128|u&63}else if(u<=67108863){if(outIdx+4>=endIdx)break;outU8Array[outIdx++]=248|u>>24;outU8Array[outIdx++]=128|u>>18&63;outU8Array[outIdx++]=128|u>>12&63;outU8Array[outIdx++]=128|u>>6&63;outU8Array[outIdx++]=128|u&63}else{if(outIdx+5>=endIdx)break;outU8Array[outIdx++]=252|u>>30;outU8Array[outIdx++]=128|u>>24&63;outU8Array[outIdx++]=128|u>>18&63;outU8Array[outIdx++]=128|u>>12&63;outU8Array[outIdx++]=128|u>>6&63;outU8Array[outIdx++]=128|u&63}}outU8Array[outIdx]=0;return outIdx-startIdx}function stringToUTF8(str,outPtr,maxBytesToWrite){return stringToUTF8Array(str,HEAPU8,outPtr,maxBytesToWrite)}function lengthBytesUTF8(str){var len=0;for(var i=0;i=55296&&u<=57343)u=65536+((u&1023)<<10)|str.charCodeAt(++i)&1023;if(u<=127){++len}else if(u<=2047){len+=2}else if(u<=65535){len+=3}else if(u<=2097151){len+=4}else if(u<=67108863){len+=5}else{len+=6}}return len}var UTF16Decoder=typeof TextDecoder!=="undefined"?new TextDecoder("utf-16le"):undefined;function allocateUTF8(str){var size=lengthBytesUTF8(str)+1;var ret=_malloc(size);if(ret)stringToUTF8Array(str,HEAP8,ret,size);return ret}var WASM_PAGE_SIZE=65536;var ASMJS_PAGE_SIZE=16777216;var MIN_TOTAL_MEMORY=16777216;function alignUp(x,multiple){if(x%multiple>0){x+=multiple-x%multiple}return x}var buffer,HEAP8,HEAPU8,HEAP16,HEAPU16,HEAP32,HEAPU32,HEAPF32,HEAPF64;function updateGlobalBuffer(buf){Module["buffer"]=buffer=buf}function updateGlobalBufferViews(){Module["HEAP8"]=HEAP8=new Int8Array(buffer);Module["HEAP16"]=HEAP16=new Int16Array(buffer);Module["HEAP32"]=HEAP32=new Int32Array(buffer);Module["HEAPU8"]=HEAPU8=new Uint8Array(buffer);Module["HEAPU16"]=HEAPU16=new Uint16Array(buffer);Module["HEAPU32"]=HEAPU32=new Uint32Array(buffer);Module["HEAPF32"]=HEAPF32=new Float32Array(buffer);Module["HEAPF64"]=HEAPF64=new Float64Array(buffer)}var STATIC_BASE,STATICTOP,staticSealed;var STACK_BASE,STACKTOP,STACK_MAX;var DYNAMIC_BASE,DYNAMICTOP_PTR;STATIC_BASE=STATICTOP=STACK_BASE=STACKTOP=STACK_MAX=DYNAMIC_BASE=DYNAMICTOP_PTR=0;staticSealed=false;function abortOnCannotGrowMemory(){abort("Cannot enlarge memory arrays. Either (1) compile with -s TOTAL_MEMORY=X with X higher than the current value "+TOTAL_MEMORY+", (2) compile with -s ALLOW_MEMORY_GROWTH=1 which allows increasing the size at runtime, or (3) if you want malloc to return NULL (0) instead of this abort, compile with -s ABORTING_MALLOC=0 ")}if(!Module["reallocBuffer"])Module["reallocBuffer"]=(function(size){var ret;try{var oldHEAP8=HEAP8;ret=new ArrayBuffer(size);var temp=new Int8Array(ret);temp.set(oldHEAP8)}catch(e){return false}var success=_emscripten_replace_memory(ret);if(!success)return false;return ret});function enlargeMemory(){var PAGE_MULTIPLE=Module["usingWasm"]?WASM_PAGE_SIZE:ASMJS_PAGE_SIZE;var LIMIT=2147483648-PAGE_MULTIPLE;if(HEAP32[DYNAMICTOP_PTR>>2]>LIMIT){return false}var OLD_TOTAL_MEMORY=TOTAL_MEMORY;TOTAL_MEMORY=Math.max(TOTAL_MEMORY,MIN_TOTAL_MEMORY);while(TOTAL_MEMORY>2]){if(TOTAL_MEMORY<=536870912){TOTAL_MEMORY=alignUp(2*TOTAL_MEMORY,PAGE_MULTIPLE)}else{TOTAL_MEMORY=Math.min(alignUp((3*TOTAL_MEMORY+2147483648)/4,PAGE_MULTIPLE),LIMIT)}}var replacement=Module["reallocBuffer"](TOTAL_MEMORY);if(!replacement||replacement.byteLength!=TOTAL_MEMORY){TOTAL_MEMORY=OLD_TOTAL_MEMORY;return false}updateGlobalBuffer(replacement);updateGlobalBufferViews();return true}var byteLength;try{byteLength=Function.prototype.call.bind(Object.getOwnPropertyDescriptor(ArrayBuffer.prototype,"byteLength").get);byteLength(new ArrayBuffer(4))}catch(e){byteLength=(function(buffer){return buffer.byteLength})}var TOTAL_STACK=Module["TOTAL_STACK"]||5242880;var TOTAL_MEMORY=Module["TOTAL_MEMORY"]||16777216;if(TOTAL_MEMORY0){var callback=callbacks.shift();if(typeof callback=="function"){callback();continue}var func=callback.func;if(typeof func==="number"){if(callback.arg===undefined){Module["dynCall_v"](func)}else{Module["dynCall_vi"](func,callback.arg)}}else{func(callback.arg===undefined?null:callback.arg)}}}var __ATPRERUN__=[];var __ATINIT__=[];var __ATMAIN__=[];var __ATEXIT__=[];var __ATPOSTRUN__=[];var runtimeInitialized=false;var runtimeExited=false;function preRun(){if(Module["preRun"]){if(typeof Module["preRun"]=="function")Module["preRun"]=[Module["preRun"]];while(Module["preRun"].length){addOnPreRun(Module["preRun"].shift())}}callRuntimeCallbacks(__ATPRERUN__)}function ensureInitRuntime(){if(runtimeInitialized)return;runtimeInitialized=true;callRuntimeCallbacks(__ATINIT__)}function preMain(){callRuntimeCallbacks(__ATMAIN__)}function exitRuntime(){callRuntimeCallbacks(__ATEXIT__);runtimeExited=true}function postRun(){if(Module["postRun"]){if(typeof Module["postRun"]=="function")Module["postRun"]=[Module["postRun"]];while(Module["postRun"].length){addOnPostRun(Module["postRun"].shift())}}callRuntimeCallbacks(__ATPOSTRUN__)}function addOnPreRun(cb){__ATPRERUN__.unshift(cb)}function addOnPostRun(cb){__ATPOSTRUN__.unshift(cb)}function writeArrayToMemory(array,buffer){HEAP8.set(array,buffer)}function writeAsciiToMemory(str,buffer,dontAddNull){for(var i=0;i>0]=str.charCodeAt(i)}if(!dontAddNull)HEAP8[buffer>>0]=0}var runDependencies=0;var runDependencyWatcher=null;var dependenciesFulfilled=null;function addRunDependency(id){runDependencies++;if(Module["monitorRunDependencies"]){Module["monitorRunDependencies"](runDependencies)}}function removeRunDependency(id){runDependencies--;if(Module["monitorRunDependencies"]){Module["monitorRunDependencies"](runDependencies)}if(runDependencies==0){if(runDependencyWatcher!==null){clearInterval(runDependencyWatcher);runDependencyWatcher=null}if(dependenciesFulfilled){var callback=dependenciesFulfilled;dependenciesFulfilled=null;callback()}}}Module["preloadedImages"]={};Module["preloadedAudios"]={};var dataURIPrefix="data:application/octet-stream;base64,";function isDataURI(filename){return String.prototype.startsWith?filename.startsWith(dataURIPrefix):filename.indexOf(dataURIPrefix)===0}function integrateWasmJS(){var wasmTextFile="wvnc_asm.wast";var wasmBinaryFile="wvnc_asm.wasm";var asmjsCodeFile="wvnc_asm.temp.asm.js";if(!isDataURI(wasmTextFile)){wasmTextFile=locateFile(wasmTextFile)}if(!isDataURI(wasmBinaryFile)){wasmBinaryFile=locateFile(wasmBinaryFile)}if(!isDataURI(asmjsCodeFile)){asmjsCodeFile=locateFile(asmjsCodeFile)}var wasmPageSize=64*1024;var info={"global":null,"env":null,"asm2wasm":asm2wasmImports,"parent":Module};var exports=null;function mergeMemory(newBuffer){var oldBuffer=Module["buffer"];if(newBuffer.byteLength>2]=poolPtr;HEAP32[environ>>2]=envPtr}else{envPtr=HEAP32[environ>>2];poolPtr=HEAP32[envPtr>>2]}var strings=[];var totalSize=0;for(var key in ENV){if(typeof ENV[key]==="string"){var line=key+"="+ENV[key];strings.push(line);totalSize+=line.length}}if(totalSize>TOTAL_ENV_SIZE){throw new Error("Environment size exceeded TOTAL_ENV_SIZE!")}var ptrSize=4;for(var i=0;i>2]=poolPtr;poolPtr+=line.length+1}HEAP32[envPtr+strings.length*ptrSize>>2]=0}var SYSCALLS={varargs:0,get:(function(varargs){SYSCALLS.varargs+=4;var ret=HEAP32[SYSCALLS.varargs-4>>2];return ret}),getStr:(function(){var ret=Pointer_stringify(SYSCALLS.get());return ret}),get64:(function(){var low=SYSCALLS.get(),high=SYSCALLS.get();if(low>=0)assert(high===0);else assert(high===-1);return low}),getZero:(function(){assert(SYSCALLS.get()===0)})};function ___syscall140(which,varargs){SYSCALLS.varargs=varargs;try{var stream=SYSCALLS.getStreamFromFD(),offset_high=SYSCALLS.get(),offset_low=SYSCALLS.get(),result=SYSCALLS.get(),whence=SYSCALLS.get();var offset=offset_low;FS.llseek(stream,offset,whence);HEAP32[result>>2]=stream.position;if(stream.getdents&&offset===0&&whence===0)stream.getdents=null;return 0}catch(e){if(typeof FS==="undefined"||!(e instanceof FS.ErrnoError))abort(e);return-e.errno}}function ___syscall146(which,varargs){SYSCALLS.varargs=varargs;try{var stream=SYSCALLS.get(),iov=SYSCALLS.get(),iovcnt=SYSCALLS.get();var ret=0;if(!___syscall146.buffers){___syscall146.buffers=[null,[],[]];___syscall146.printChar=(function(stream,curr){var buffer=___syscall146.buffers[stream];assert(buffer);if(curr===0||curr===10){(stream===1?out:err)(UTF8ArrayToString(buffer,0));buffer.length=0}else{buffer.push(curr)}})}for(var i=0;i>2];var len=HEAP32[iov+(i*8+4)>>2];for(var j=0;j>2]=value;return value}DYNAMICTOP_PTR=staticAlloc(4);STACK_BASE=STACKTOP=alignMemory(STATICTOP);STACK_MAX=STACK_BASE+TOTAL_STACK;DYNAMIC_BASE=alignMemory(STACK_MAX);HEAP32[DYNAMICTOP_PTR>>2]=DYNAMIC_BASE;staticSealed=true;Module["wasmTableSize"]=212;Module["wasmMaxTableSize"]=212;Module.asmGlobalArg={};Module.asmLibraryArg={"abort":abort,"enlargeMemory":enlargeMemory,"getTotalMemory":getTotalMemory,"abortOnCannotGrowMemory":abortOnCannotGrowMemory,"___buildEnvironment":___buildEnvironment,"___setErrNo":___setErrNo,"___syscall140":___syscall140,"___syscall146":___syscall146,"___syscall54":___syscall54,"___syscall6":___syscall6,"_emscripten_memcpy_big":_emscripten_memcpy_big,"_exit":_exit,"_getenv":_getenv,"DYNAMICTOP_PTR":DYNAMICTOP_PTR,"STACKTOP":STACKTOP};var asm=Module["asm"](Module.asmGlobalArg,Module.asmLibraryArg,buffer);Module["asm"]=asm;var ___emscripten_environ_constructor=Module["___emscripten_environ_constructor"]=(function(){return Module["asm"]["___emscripten_environ_constructor"].apply(null,arguments)});var ___errno_location=Module["___errno_location"]=(function(){return Module["asm"]["___errno_location"].apply(null,arguments)});var _create_buffer=Module["_create_buffer"]=(function(){return Module["asm"]["_create_buffer"].apply(null,arguments)});var _decode=Module["_decode"]=(function(){return Module["asm"]["_decode"].apply(null,arguments)});var _destroy_buffer=Module["_destroy_buffer"]=(function(){return Module["asm"]["_destroy_buffer"].apply(null,arguments)});var _emscripten_replace_memory=Module["_emscripten_replace_memory"]=(function(){return Module["asm"]["_emscripten_replace_memory"].apply(null,arguments)});var _free=Module["_free"]=(function(){return Module["asm"]["_free"].apply(null,arguments)});var _malloc=Module["_malloc"]=(function(){return Module["asm"]["_malloc"].apply(null,arguments)});var _update=Module["_update"]=(function(){return Module["asm"]["_update"].apply(null,arguments)});var stackAlloc=Module["stackAlloc"]=(function(){return Module["asm"]["stackAlloc"].apply(null,arguments)});var stackRestore=Module["stackRestore"]=(function(){return Module["asm"]["stackRestore"].apply(null,arguments)});var stackSave=Module["stackSave"]=(function(){return Module["asm"]["stackSave"].apply(null,arguments)});var dynCall_vi=Module["dynCall_vi"]=(function(){return Module["asm"]["dynCall_vi"].apply(null,arguments)});Module["asm"]=asm;Module["cwrap"]=cwrap;function ExitStatus(status){this.name="ExitStatus";this.message="Program terminated with exit("+status+")";this.status=status}ExitStatus.prototype=new Error;ExitStatus.prototype.constructor=ExitStatus;var initialStackTop;dependenciesFulfilled=function runCaller(){if(!Module["calledRun"])run();if(!Module["calledRun"])dependenciesFulfilled=runCaller};function run(args){args=args||Module["arguments"];if(runDependencies>0){return}preRun();if(runDependencies>0)return;if(Module["calledRun"])return;function doRun(){if(Module["calledRun"])return;Module["calledRun"]=true;if(ABORT)return;ensureInitRuntime();preMain();if(Module["onRuntimeInitialized"])Module["onRuntimeInitialized"]();postRun()}if(Module["setStatus"]){Module["setStatus"]("Running...");setTimeout((function(){setTimeout((function(){Module["setStatus"]("")}),1);doRun()}),1)}else{doRun()}}Module["run"]=run;function exit(status,implicit){if(implicit&&Module["noExitRuntime"]&&status===0){return}if(Module["noExitRuntime"]){}else{ABORT=true;EXITSTATUS=status;STACKTOP=initialStackTop;exitRuntime();if(Module["onExit"])Module["onExit"](status)}Module["quit"](status,new ExitStatus(status))}function abort(what){if(Module["onAbort"]){Module["onAbort"](what)}if(what!==undefined){out(what);err(what);what=JSON.stringify(what)}else{what=""}ABORT=true;EXITSTATUS=1;throw"abort("+what+"). Build with -s ASSERTIONS=1 for more info."}Module["abort"]=abort;if(Module["preInit"]){if(typeof Module["preInit"]=="function")Module["preInit"]=[Module["preInit"]];while(Module["preInit"].length>0){Module["preInit"].pop()()}}Module["noExitRuntime"]=true;run() + + + diff --git a/apps/assets/scripts/wvnc_asm.wasm b/apps/assets/scripts/wvnc_asm.wasm new file mode 100644 index 0000000..9b2bcd7 Binary files /dev/null and b/apps/assets/scripts/wvnc_asm.wasm differ diff --git a/apps/router.lua b/apps/router.lua index 4f17091..8cec404 100644 --- a/apps/router.lua +++ b/apps/router.lua @@ -17,7 +17,7 @@ LOG_ROOT = WWW_ROOT..DIR_SEP.."logs" -- require needed library require(BASE_FRW.."silk.api") - +POLICY.mimes["application/wasm"] = true -- registry object store global variables local REGISTRY = {} -- set logging level