@wasmer/io-devices
Version:
Isomorphic library to implement the experimental Wasmer I/O devices for wasmfs instances 🖼️🎮
7 lines (6 loc) • 2.91 kB
JavaScript
var b={FILE_PATH:{DEVICE_FRAMEBUFFER_ZERO:{PATH:"/_wasmer/dev/fb0",FRAME_BUFFER:"/_wasmer/dev/fb0/fb",VIRTUAL_SIZE:"/_wasmer/dev/fb0/virtual_size",DRAW:"/_wasmer/dev/fb0/draw",INPUT:"/_wasmer/dev/fb0/input"}}},TextDecoder=void 0;"object"===typeof window?TextDecoder=window.TextDecoder:"object"===typeof self?TextDecoder=self.TextDecoder:"function"===typeof require&&(TextDecoder=require("util").TextDecoder);
var e=function(){function d(a){this.wasmFs=a;this.wasmFs.volume.mkdirSync(b.FILE_PATH.DEVICE_FRAMEBUFFER_ZERO.PATH,{recursive:!0});this.wasmFs.volume.writeFileSync(b.FILE_PATH.DEVICE_FRAMEBUFFER_ZERO.FRAME_BUFFER,"");this.wasmFs.volume.writeFileSync(b.FILE_PATH.DEVICE_FRAMEBUFFER_ZERO.VIRTUAL_SIZE,"");this.wasmFs.volume.writeFileSync(b.FILE_PATH.DEVICE_FRAMEBUFFER_ZERO.DRAW,"");this.wasmFs.volume.writeFileSync(b.FILE_PATH.DEVICE_FRAMEBUFFER_ZERO.INPUT,"");this.windowSizeCallback=function(){};this.bufferIndexDisplayCallback=
function(){};this.inputCallback=function(){return new Uint8Array};this.fdFrameBuffer=this.wasmFs.volume.openSync(b.FILE_PATH.DEVICE_FRAMEBUFFER_ZERO.FRAME_BUFFER,"w+");this.fdBufferIndexDisplay=this.wasmFs.volume.openSync(b.FILE_PATH.DEVICE_FRAMEBUFFER_ZERO.DRAW,"w+");this.fdWindowSize=this.wasmFs.fs.openSync(b.FILE_PATH.DEVICE_FRAMEBUFFER_ZERO.VIRTUAL_SIZE,"w+");this.fdInput=this.wasmFs.volume.openSync(b.FILE_PATH.DEVICE_FRAMEBUFFER_ZERO.INPUT,"w+");var c=this,d=this.wasmFs.volume.fds[this.fdInput].node.read;
this.wasmFs.volume.fds[this.fdInput].node.read=function(){var a=c.inputCallback();c.wasmFs.volume.writeFileSync(b.FILE_PATH.DEVICE_FRAMEBUFFER_ZERO.INPUT,a);a=Array.prototype.slice.call(arguments);return d.apply(c.wasmFs.volume.fds[c.fdInput].node,a)};var f=this.wasmFs.volume.fds[this.fdWindowSize].node.write;this.wasmFs.volume.fds[this.fdWindowSize].node.write=function(){var a=Array.prototype.slice.call(arguments);a=f.apply(c.wasmFs.volume.fds[c.fdWindowSize].node,a);c.windowSizeCallback();return a};
var g=this.wasmFs.volume.fds[this.fdBufferIndexDisplay].node.write;this.wasmFs.volume.fds[this.fdBufferIndexDisplay].node.write=function(){var a=Array.prototype.slice.call(arguments);a=g.apply(c.wasmFs.volume.fds[c.fdBufferIndexDisplay].node,a);c.bufferIndexDisplayCallback();return a}}d.prototype.getFrameBuffer=function(){return this.wasmFs.fs.readFileSync(b.FILE_PATH.DEVICE_FRAMEBUFFER_ZERO.FRAME_BUFFER)};d.prototype.getWindowSize=function(){var a=this.wasmFs.fs.readFileSync(b.FILE_PATH.DEVICE_FRAMEBUFFER_ZERO.VIRTUAL_SIZE);
return 0<a.length?(a=(new TextDecoder("utf-8")).decode(a).split("x"),[parseInt(a[0],10),parseInt(a[1],10)]):[0,0]};d.prototype.setWindowSizeCallback=function(a){this.windowSizeCallback=a};d.prototype.setBufferIndexDisplayCallback=function(a){this.bufferIndexDisplayCallback=a};d.prototype.setInputCallback=function(a){this.inputCallback=a};return d}();export default e;export{b as IO_DEVICES_CONSTANTS,e as IoDevices}