UNPKG

js-dos

Version:

Full-featured DOS player with multiple emulator backends

3 lines (2 loc) 30.6 kB
async function HumbleNet(moduleArg={}){var moduleRtn;var Module=moduleArg;var ENVIRONMENT_IS_WEB=!!globalThis.window;var ENVIRONMENT_IS_WORKER=!!globalThis.WorkerGlobalScope;var ENVIRONMENT_IS_NODE=globalThis.process?.versions?.node&&globalThis.process?.type!="renderer";if(ENVIRONMENT_IS_NODE){const{createRequire}=await import("node:module");var require=createRequire(import.meta.url)}var arguments_=[];var thisProgram="./this.program";var quit_=(status,toThrow)=>{throw toThrow};var _scriptName=import.meta.url;var scriptDirectory="";function locateFile(path){if(Module["locateFile"]){return Module["locateFile"](path,scriptDirectory)}return scriptDirectory+path}var readAsync,readBinary;if(ENVIRONMENT_IS_NODE){var fs=require("node:fs");if(_scriptName.startsWith("file:")){scriptDirectory=require("node:path").dirname(require("node:url").fileURLToPath(_scriptName))+"/"}readBinary=filename=>{filename=isFileURI(filename)?new URL(filename):filename;var ret=fs.readFileSync(filename);return ret};readAsync=async(filename,binary=true)=>{filename=isFileURI(filename)?new URL(filename):filename;var ret=fs.readFileSync(filename,binary?undefined:"utf8");return ret};if(process.argv.length>1){thisProgram=process.argv[1].replace(/\\/g,"/")}arguments_=process.argv.slice(2);quit_=(status,toThrow)=>{process.exitCode=status;throw toThrow}}else if(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER){try{scriptDirectory=new URL(".",_scriptName).href}catch{}{if(ENVIRONMENT_IS_WORKER){readBinary=url=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,false);xhr.responseType="arraybuffer";xhr.send(null);return new Uint8Array(xhr.response)}}readAsync=async url=>{if(isFileURI(url)){return new Promise((resolve,reject)=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,true);xhr.responseType="arraybuffer";xhr.onload=()=>{if(xhr.status==200||xhr.status==0&&xhr.response){resolve(xhr.response);return}reject(xhr.status)};xhr.onerror=reject;xhr.send(null)})}var response=await fetch(url,{credentials:"same-origin"});if(response.ok){return response.arrayBuffer()}throw new Error(response.status+" : "+response.url)}}}else{}var out=console.log.bind(console);var err=console.error.bind(console);var wasmBinary;var ABORT=false;var EXITSTATUS;var isFileURI=filename=>filename.startsWith("file://");var readyPromiseResolve,readyPromiseReject;var HEAP8,HEAPU8,HEAP16,HEAPU16,HEAP32,HEAPU32,HEAPF32,HEAPF64;var HEAP64,HEAPU64;var runtimeInitialized=false;var runtimeExited=false;function updateMemoryViews(){var b=wasmMemory.buffer;HEAP8=new Int8Array(b);HEAP16=new Int16Array(b);Module["HEAPU8"]=HEAPU8=new Uint8Array(b);HEAPU16=new Uint16Array(b);Module["HEAP32"]=HEAP32=new Int32Array(b);HEAPU32=new Uint32Array(b);HEAPF32=new Float32Array(b);HEAPF64=new Float64Array(b);HEAP64=new BigInt64Array(b);HEAPU64=new BigUint64Array(b)}function preRun(){if(Module["preRun"]){if(typeof Module["preRun"]=="function")Module["preRun"]=[Module["preRun"]];while(Module["preRun"].length){addOnPreRun(Module["preRun"].shift())}}callRuntimeCallbacks(onPreRuns)}function initRuntime(){runtimeInitialized=true;wasmExports["x"]()}function exitRuntime(){___funcs_on_exit();flush_NO_FILESYSTEM();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(onPostRuns)}function abort(what){Module["onAbort"]?.(what);what="Aborted("+what+")";err(what);ABORT=true;what+=". Build with -sASSERTIONS for more info.";var e=new WebAssembly.RuntimeError(what);readyPromiseReject?.(e);throw e}var wasmBinaryFile;function findWasmBinary(){if(Module["locateFile"]){return locateFile("webrtcnet.wasm")}return new URL("webrtcnet.wasm",import.meta.url).href}function getBinarySync(file){if(file==wasmBinaryFile&&wasmBinary){return new Uint8Array(wasmBinary)}if(readBinary){return readBinary(file)}throw"both async and sync fetching of the wasm failed"}async function getWasmBinary(binaryFile){if(!wasmBinary){try{var response=await readAsync(binaryFile);return new Uint8Array(response)}catch{}}return getBinarySync(binaryFile)}async function instantiateArrayBuffer(binaryFile,imports){try{var binary=await getWasmBinary(binaryFile);var instance=await WebAssembly.instantiate(binary,imports);return instance}catch(reason){err(`failed to asynchronously prepare wasm: ${reason}`);abort(reason)}}async function instantiateAsync(binary,binaryFile,imports){if(!binary&&!isFileURI(binaryFile)&&!ENVIRONMENT_IS_NODE){try{var response=fetch(binaryFile,{credentials:"same-origin"});var instantiationResult=await WebAssembly.instantiateStreaming(response,imports);return instantiationResult}catch(reason){err(`wasm streaming compile failed: ${reason}`);err("falling back to ArrayBuffer instantiation")}}return instantiateArrayBuffer(binaryFile,imports)}function getWasmImports(){var imports={a:wasmImports};return imports}async function createWasm(){function receiveInstance(instance,module){wasmExports=instance.exports;assignWasmExports(wasmExports);updateMemoryViews();return wasmExports}function receiveInstantiationResult(result){return receiveInstance(result["instance"])}var info=getWasmImports();if(Module["instantiateWasm"]){return new Promise((resolve,reject)=>{Module["instantiateWasm"](info,(inst,mod)=>{resolve(receiveInstance(inst,mod))})})}wasmBinaryFile??=findWasmBinary();var result=await instantiateAsync(wasmBinary,wasmBinaryFile,info);var exports=receiveInstantiationResult(result);return exports}class ExitStatus{name="ExitStatus";constructor(status){this.message=`Program terminated with exit(${status})`;this.status=status}}var callRuntimeCallbacks=callbacks=>{while(callbacks.length>0){callbacks.shift()(Module)}};var onPostRuns=[];var addOnPostRun=cb=>onPostRuns.push(cb);var onPreRuns=[];var addOnPreRun=cb=>onPreRuns.push(cb);var lengthBytesUTF8=str=>{var len=0;for(var i=0;i<str.length;++i){var c=str.charCodeAt(i);if(c<=127){len++}else if(c<=2047){len+=2}else if(c>=55296&&c<=57343){len+=4;++i}else{len+=3}}return len};var stringToUTF8Array=(str,heap,outIdx,maxBytesToWrite)=>{if(!(maxBytesToWrite>0))return 0;var startIdx=outIdx;var endIdx=outIdx+maxBytesToWrite-1;for(var i=0;i<str.length;++i){var u=str.codePointAt(i);if(u<=127){if(outIdx>=endIdx)break;heap[outIdx++]=u}else if(u<=2047){if(outIdx+1>=endIdx)break;heap[outIdx++]=192|u>>6;heap[outIdx++]=128|u&63}else if(u<=65535){if(outIdx+2>=endIdx)break;heap[outIdx++]=224|u>>12;heap[outIdx++]=128|u>>6&63;heap[outIdx++]=128|u&63}else{if(outIdx+3>=endIdx)break;heap[outIdx++]=240|u>>18;heap[outIdx++]=128|u>>12&63;heap[outIdx++]=128|u>>6&63;heap[outIdx++]=128|u&63;i++}}heap[outIdx]=0;return outIdx-startIdx};var intArrayFromString=(stringy,dontAddNull,length)=>{var len=length>0?length:lengthBytesUTF8(stringy)+1;var u8array=new Array(len);var numBytesWritten=stringToUTF8Array(stringy,u8array,0,u8array.length);if(dontAddNull)u8array.length=numBytesWritten;return u8array};var noExitRuntime=false;var stackRestore=val=>__emscripten_stack_restore(val);var stackSave=()=>_emscripten_stack_get_current();var exceptionCaught=[];var uncaughtExceptionCount=0;var ___cxa_begin_catch=ptr=>{var info=new ExceptionInfo(ptr);if(!info.get_caught()){info.set_caught(true);uncaughtExceptionCount--}info.set_rethrown(false);exceptionCaught.push(info);return ___cxa_get_exception_ptr(ptr)};var exceptionLast=0;var ___cxa_end_catch=()=>{_setThrew(0,0);var info=exceptionCaught.pop();___cxa_decrement_exception_refcount(info.excPtr);exceptionLast=0};class ExceptionInfo{constructor(excPtr){this.excPtr=excPtr;this.ptr=excPtr-24}set_type(type){HEAPU32[this.ptr+4>>2]=type}get_type(){return HEAPU32[this.ptr+4>>2]}set_destructor(destructor){HEAPU32[this.ptr+8>>2]=destructor}get_destructor(){return HEAPU32[this.ptr+8>>2]}set_caught(caught){caught=caught?1:0;HEAP8[this.ptr+12]=caught}get_caught(){return HEAP8[this.ptr+12]!=0}set_rethrown(rethrown){rethrown=rethrown?1:0;HEAP8[this.ptr+13]=rethrown}get_rethrown(){return HEAP8[this.ptr+13]!=0}init(type,destructor){this.set_adjusted_ptr(0);this.set_type(type);this.set_destructor(destructor)}set_adjusted_ptr(adjustedPtr){HEAPU32[this.ptr+16>>2]=adjustedPtr}get_adjusted_ptr(){return HEAPU32[this.ptr+16>>2]}}var setTempRet0=val=>__emscripten_tempret_set(val);var findMatchingCatch=args=>{var thrown=exceptionLast;if(!thrown){setTempRet0(0);return 0}var info=new ExceptionInfo(thrown);info.set_adjusted_ptr(thrown);var thrownType=info.get_type();if(!thrownType){setTempRet0(0);return thrown}for(var caughtType of args){if(caughtType===0||caughtType===thrownType){break}var adjusted_ptr_addr=info.ptr+16;if(___cxa_can_catch(caughtType,thrownType,adjusted_ptr_addr)){setTempRet0(caughtType);return thrown}}setTempRet0(thrownType);return thrown};var ___cxa_find_matching_catch_2=()=>findMatchingCatch([]);var ___cxa_find_matching_catch_3=arg0=>findMatchingCatch([arg0]);var ___cxa_throw=(ptr,type,destructor)=>{var info=new ExceptionInfo(ptr);info.init(type,destructor);___cxa_increment_exception_refcount(ptr);exceptionLast=ptr;uncaughtExceptionCount++;throw exceptionLast};var ___resumeException=ptr=>{if(!exceptionLast){exceptionLast=ptr}throw exceptionLast};var __abort_js=()=>abort("");var readEmAsmArgsArray=[];var readEmAsmArgs=(sigPtr,buf)=>{readEmAsmArgsArray.length=0;var ch;while(ch=HEAPU8[sigPtr++]){var wide=ch!=105;wide&=ch!=112;buf+=wide&&buf%8?4:0;readEmAsmArgsArray.push(ch==112?HEAPU32[buf>>2]:ch==106?HEAP64[buf>>3]:ch==105?HEAP32[buf>>2]:HEAPF64[buf>>3]);buf+=wide?8:4}return readEmAsmArgsArray};var runEmAsmFunction=(code,sigPtr,argbuf)=>{var args=readEmAsmArgs(sigPtr,argbuf);return ASM_CONSTS[code](...args)};var _emscripten_asm_const_int=(code,sigPtr,argbuf)=>runEmAsmFunction(code,sigPtr,argbuf);var _emscripten_date_now=()=>Date.now();var runtimeKeepaliveCounter=0;var keepRuntimeAlive=()=>noExitRuntime||runtimeKeepaliveCounter>0;var _proc_exit=code=>{EXITSTATUS=code;if(!keepRuntimeAlive()){Module["onExit"]?.(code);ABORT=true}quit_(code,new ExitStatus(code))};var exitJS=(status,implicit)=>{EXITSTATUS=status;if(!keepRuntimeAlive()){exitRuntime()}_proc_exit(status)};var _exit=exitJS;var __emscripten_runtime_keepalive_clear=()=>{noExitRuntime=false;runtimeKeepaliveCounter=0};var _emscripten_force_exit=status=>{__emscripten_runtime_keepalive_clear();_exit(status)};var abortOnCannotGrowMemory=requestedSize=>{abort("OOM")};var _emscripten_resize_heap=requestedSize=>{var oldSize=HEAPU8.length;requestedSize>>>=0;abortOnCannotGrowMemory(requestedSize)};var _fd_close=fd=>52;var INT53_MAX=9007199254740992;var INT53_MIN=-9007199254740992;var bigintToI53Checked=num=>num<INT53_MIN||num>INT53_MAX?NaN:Number(num);function _fd_seek(fd,offset,whence,newOffset){offset=bigintToI53Checked(offset);return 70}var printCharBuffers=[null,[],[]];var UTF8Decoder=globalThis.TextDecoder&&new TextDecoder;var findStringEnd=(heapOrArray,idx,maxBytesToRead,ignoreNul)=>{var maxIdx=idx+maxBytesToRead;if(ignoreNul)return maxIdx;while(heapOrArray[idx]&&!(idx>=maxIdx))++idx;return idx};var UTF8ArrayToString=(heapOrArray,idx=0,maxBytesToRead,ignoreNul)=>{var endPtr=findStringEnd(heapOrArray,idx,maxBytesToRead,ignoreNul);if(endPtr-idx>16&&heapOrArray.buffer&&UTF8Decoder){return UTF8Decoder.decode(heapOrArray.subarray(idx,endPtr))}var str="";while(idx<endPtr){var u0=heapOrArray[idx++];if(!(u0&128)){str+=String.fromCharCode(u0);continue}var u1=heapOrArray[idx++]&63;if((u0&224)==192){str+=String.fromCharCode((u0&31)<<6|u1);continue}var u2=heapOrArray[idx++]&63;if((u0&240)==224){u0=(u0&15)<<12|u1<<6|u2}else{u0=(u0&7)<<18|u1<<12|u2<<6|heapOrArray[idx++]&63}if(u0<65536){str+=String.fromCharCode(u0)}else{var ch=u0-65536;str+=String.fromCharCode(55296|ch>>10,56320|ch&1023)}}return str};var printChar=(stream,curr)=>{var buffer=printCharBuffers[stream];if(curr===0||curr===10){(stream===1?out:err)(UTF8ArrayToString(buffer));buffer.length=0}else{buffer.push(curr)}};var flush_NO_FILESYSTEM=()=>{_fflush(0);if(printCharBuffers[1].length)printChar(1,10);if(printCharBuffers[2].length)printChar(2,10)};var UTF8ToString=(ptr,maxBytesToRead,ignoreNul)=>ptr?UTF8ArrayToString(HEAPU8,ptr,maxBytesToRead,ignoreNul):"";var _fd_write=(fd,iov,iovcnt,pnum)=>{var num=0;for(var i=0;i<iovcnt;i++){var ptr=HEAPU32[iov>>2];var len=HEAPU32[iov+4>>2];iov+=8;for(var j=0;j<len;j++){printChar(fd,HEAPU8[ptr+j])}num+=len}HEAPU32[pnum>>2]=num;return 0};var wasmTableMirror=[];var getWasmTableEntry=funcPtr=>{var func=wasmTableMirror[funcPtr];if(!func){wasmTableMirror[funcPtr]=func=wasmTable.get(funcPtr)}return func};var getCFunc=ident=>{var func=Module["_"+ident];return func};var writeArrayToMemory=(array,buffer)=>{HEAP8.set(array,buffer)};var stringToUTF8=(str,outPtr,maxBytesToWrite)=>stringToUTF8Array(str,HEAPU8,outPtr,maxBytesToWrite);var stackAlloc=sz=>__emscripten_stack_alloc(sz);var stringToUTF8OnStack=str=>{var size=lengthBytesUTF8(str)+1;var ret=stackAlloc(size);stringToUTF8(str,ret,size);return ret};var ccall=(ident,returnType,argTypes,args,opts)=>{var toC={string:str=>{var ret=0;if(str!==null&&str!==undefined&&str!==0){ret=stringToUTF8OnStack(str)}return ret},array:arr=>{var ret=stackAlloc(arr.length);writeArrayToMemory(arr,ret);return ret}};function convertReturnValue(ret){if(returnType==="string"){return UTF8ToString(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<args.length;i++){var converter=toC[argTypes[i]];if(converter){if(stack===0)stack=stackSave();cArgs[i]=converter(args[i])}else{cArgs[i]=args[i]}}}var ret=func(...cArgs);function onDone(ret){if(stack!==0)stackRestore(stack);return convertReturnValue(ret)}ret=onDone(ret);return ret};var cwrap=(ident,returnType,argTypes,opts)=>{var numericArgs=!argTypes||argTypes.every(type=>type==="number"||type==="boolean");var numericRet=returnType!=="string";if(numericRet&&numericArgs&&!opts){return getCFunc(ident)}return(...args)=>ccall(ident,returnType,argTypes,args,opts)};var stringToNewUTF8=str=>{var size=lengthBytesUTF8(str)+1;var ret=_malloc(size);if(ret)stringToUTF8(str,ret,size);return ret};{if(Module["noExitRuntime"])noExitRuntime=Module["noExitRuntime"];if(Module["print"])out=Module["print"];if(Module["printErr"])err=Module["printErr"];if(Module["wasmBinary"])wasmBinary=Module["wasmBinary"];if(Module["arguments"])arguments_=Module["arguments"];if(Module["thisProgram"])thisProgram=Module["thisProgram"];if(Module["preInit"]){if(typeof Module["preInit"]=="function")Module["preInit"]=[Module["preInit"]];while(Module["preInit"].length>0){Module["preInit"].shift()()}}}Module["out"]=out;Module["cwrap"]=cwrap;Module["UTF8ToString"]=UTF8ToString;Module["lengthBytesUTF8"]=lengthBytesUTF8;Module["stringToNewUTF8"]=stringToNewUTF8;var ASM_CONSTS={15047:$0=>{if(Module.onNetworkError){Module.onNetworkError($0)}},15109:($0,$1)=>{var buff=new Uint8Array(Module.HEAPU8.buffer,$0,$1);return stringToUTF8Array(navigator.userAgent,buff,0,$1)},15230:$0=>{var libwebrtc={};if(!self.RTCPeerConnection||!self.RTCIceCandidate||!self.RTCSessionDescription)return 0;var ctx=$0;libwebrtc.connections=new Map;libwebrtc.channels=new Map;libwebrtc.on_event=Module.cwrap("libwebrtc_helper","number",["number","number","number","number","number","number","number"]);libwebrtc.options={};libwebrtc.create=function(){if(window.netConfig&&window.netConfig.debug){console.log("[DEBUG] RTCPeerConnection created",JSON.stringify(this.options,null,2))}var connection=new RTCPeerConnection(this.options,null);connection.trickle=true;connection.destroy=this.destroy;connection.ondatachannel=this.on_datachannel;connection.onicecandidate=this.on_candidate;connection.onsignalingstatechange=this.on_signalstatechange;connection.oniceconnectionstatechange=this.on_icestatechange;connection.id=this.connections.size+1;this.connections.set(connection.id,connection);return connection};libwebrtc.create_channel=function(connection,name){var ordered=window.netConfig?window.netConfig.ordered==true:false;if(window.netConfig&&window.netConfig.debug){console.log("[DEBUG] created channel",name,"ordered",ordered)}var channel=connection.createDataChannel(name,{ordered,maxRetransmits:ordered?null:0});channel.parent=connection;channel.user_data=connection.user_data;channel.binaryType="arraybuffer";channel.onopen=libwebrtc.on_channel_connected;channel.onclose=libwebrtc.on_channel_close;channel.onmessage=libwebrtc.on_channel_message;channel.onerror=libwebrtc.on_channel_error;channel._id=libwebrtc.channels.size+1;libwebrtc.channels.set(channel._id,channel);return channel};libwebrtc.on_sdp=function(){if(!this.trickle&&this.iceGatheringState!="complete"){return}var sdp=this.localDescription.sdp;var stack=stackSave();const array=intArrayFromString(sdp);const buffer=stackAlloc(array.length);Module.HEAPU8.set(array,buffer);libwebrtc.on_event(ctx,this.id,0,1,this.user_data,buffer,sdp.length);stackRestore(stack)};libwebrtc.on_candidate=function(event){if(!event){return}if(this.iceConnectionState==="completed"){Module.out("ignoring ice, were not trying to connect: "+this.iceConnectionState);return}if(!event.candidate){Module.out("no more candidates: "+this.iceGatheringState);if(!this.trickle){libwebrtc.on_sdp.call(this)}return}Module.out("ice candidate "+event.candidate.candidate+" -- "+this.iceGatheringState);if(this.trickle){var stack=stackSave();const array=intArrayFromString(event.candidate.candidate);const buffer=stackAlloc(array.length);Module.HEAPU8.set(array,buffer);libwebrtc.on_event(ctx,this.id,0,2,this.user_data,buffer,event.candidate.candidate.length);stackRestore(stack)}};libwebrtc.on_signalstatechange=function(event){Module.out("signalingState: "+this.signalingState)};libwebrtc.on_icestatechange=function(event){Module.out("icestate: "+this.iceConnectionState+" / iceGatheringState: "+this.iceGatheringState);if(this.iceConnectionState=="failed"||this.iceConnectionState=="disconnected"){this.close()}else if(this.iceConnectionState=="closed"){libwebrtc.on_disconnected.call(this,event)}else if(this.iceConnectionState=="completed"){libwebrtc.on_event(ctx,this.id,0,3,this.user_data,0,0)}if((this.iceConnectionState==="connected"||this.iceConnectionState==="completed")&&window.top){this.getStats().then(report=>{const stats=[];report.forEach(stat=>{stats.push({...stat})});window.top.postMessage({event:"mp.room.rtcstats",stats},"*")})}};libwebrtc.on_disconnected=function(event){var stack=stackSave();libwebrtc.on_event(ctx,this.id,0,4,this.user_data,0,0);stackRestore(stack);this.destroy()};libwebrtc.on_datachannel=function(event){Module.out("datachannel");var channel=event.channel;channel.parent=this;channel.user_data=this.user_data;channel.binaryType="arraybuffer";channel.onopen=libwebrtc.on_channel_accept;channel.onclose=libwebrtc.on_channel_close;channel.onmessage=libwebrtc.on_channel_message;channel.onerror=libwebrtc.on_channel_error;channel._id=libwebrtc.channels.size+1;libwebrtc.channels.set(channel._id,channel)};libwebrtc.on_channel_accept=function(event){Module.out("accept");var stack=stackSave();const array=intArrayFromString(this.label);const buffer=stackAlloc(array.length);Module.HEAPU8.set(array,buffer);libwebrtc.on_event(ctx,this.parent.id,this._id,5,this.user_data,buffer,this.label.length);stackRestore(stack)};libwebrtc.on_channel_connected=function(event){Module.out("connect");var stack=stackSave();const array=intArrayFromString(this.label);const buffer=stackAlloc(array.length);Module.HEAPU8.set(array,buffer);libwebrtc.on_event(ctx,this.parent.id,this._id,6,this.user_data,buffer,this.label.length);stackRestore(stack)};libwebrtc.on_channel_message=function(event){var stack=stackSave();var len=event.data.byteLength;var ptr=stackAlloc(len);var data=new Uint8Array(event.data);Module.HEAPU8.set(data,ptr);libwebrtc.on_event(ctx,this.parent.id,this._id,7,this.user_data,ptr,len);stackRestore(stack)};libwebrtc.on_channel_error=function(event){Module.out("Got channel error: "+event);this.close()};libwebrtc.on_channel_close=function(event){var stack=stackSave();libwebrtc.on_event(ctx,this.parent.id,this._id,8,this.user_data,0,0);stackRestore(stack)};libwebrtc.destroy=function(){libwebrtc.connections.set(this.id,undefined);this.ondatachannel=undefined;this.onicecandidate=undefined;this.onsignalingstatechange=undefined;this.oniceconnectionstatechange=undefined;libwebrtc.on_event(ctx,this.id,0,10,this.user_data,0,0);this.close();Module.out("Destroy webrtc: "+this.id)};Module.__libwebrtc=libwebrtc;return 1},21305:()=>{Module.__libwebrtc.options.iceServers=[]},21353:$0=>{const type=HEAP32[$0>>2];const urlPtr=HEAPU32[$0+4>>2];const usernamePtr=HEAPU32[$0+8>>2];const passwordPtr=HEAPU32[$0+12>>2];const url=urlPtr?UTF8ToString(urlPtr):"";const username=usernamePtr?UTF8ToString(usernamePtr):"";const password=passwordPtr?UTF8ToString(passwordPtr):"";if(!url){return}if(type===1){Module.__libwebrtc.options.iceServers.push({urls:url.startsWith("stun:")||url.startsWith("stuns:")?url:"stun:"+url});return}const iceServer={};if(username.length>0&&password.length>0){iceServer.username=username;iceServer.credential=password}if(url.startsWith("turn:")||url.startsWith("turns:")){iceServer.urls=url;Module.__libwebrtc.options.iceServers.push(iceServer)}else if(url.endsWith("5349")){iceServer.urls="turns:"+url;Module.__libwebrtc.options.iceServers.push(iceServer)}else{Module.__libwebrtc.options.iceServers.push({urls:"turn:"+url+"?transport=udp",...iceServer});Module.__libwebrtc.options.iceServers.push({urls:"turn:"+url+"?transport=tcp",...iceServer})}},22480:$0=>{var connection=Module.__libwebrtc.create();connection.user_data=$0;return connection.id},22579:($0,$1)=>{var connection=Module.__libwebrtc.connections.get($0);if(!connection){return}connection.user_data=$1},22698:$0=>{var connection=Module.__libwebrtc.connections.get($0);if(!connection){return 0}connection.default_channel=Module.__libwebrtc.create_channel(connection,"default");connection.createOffer({}).then(function(offer){connection.setLocalDescription(new RTCSessionDescription(offer)).then(function(){Module.__libwebrtc.on_sdp.call(connection)}).catch(function(error){alert("setLocalDescription(create): "+error)})}).catch(function(error){alert("createOffer: "+error)});return 1},23216:($0,$1)=>{var connection=Module.__libwebrtc.connections.get($0);if(!connection){return 0}var offer={};offer.type="offer";offer.sdp=UTF8ToString($1);connection.setRemoteDescription(new RTCSessionDescription(offer)).then(function(){connection.createAnswer().then(function(offer){connection.setLocalDescription(new RTCSessionDescription(offer)).then(function(){Module.__libwebrtc.on_sdp.call(connection)}).catch(function(error){alert("setLocalDescription(answer): "+error)})}).catch(function(error){alert("createAnswer: "+error)})}).catch(function(error){alert("setRemoteDescriptor(answer): "+error)});return 1},23885:($0,$1)=>{var connection=Module.__libwebrtc.connections.get($0);if(!connection){return 0}var offer={};offer.type="answer";offer.sdp=UTF8ToString($1);connection.setRemoteDescription(new RTCSessionDescription(offer)).then(function(){}).catch(function(error){alert("setRemoteDescriptor(answer): "+error)});return 1},24229:($0,$1)=>{var connection=Module.__libwebrtc.connections.get($0);if(!connection){return 0}var options={};options.candidate=UTF8ToString($1);options.sdpMLineIndex=0;if(connection.iceConnectionState=="checking"||connection.iceConnectionState=="connected"||connection.iceConnectionState=="new"){Module.out("AddIce: "+options.candidate);connection.addIceCandidate(new RTCIceCandidate(options)).catch(e=>{console.error("Failed to add ice candidate: "+e)})}else{Module.out("Not negotiating ("+connection.iceConnectionState+"), ignored candidate: "+options.candidate)}},24850:($0,$1)=>{var connection=Module.__libwebrtc.connections.get($0);if(!connection){return 0}var channel;if(connection.default_channel){channel=connection.default_channel;connection.default_channel=0}else{channel=Module.__libwebrtc.create_channel(connection,UTF8ToString($1))}return channel._id},25167:($0,$1,$2)=>{var channel=Module.__libwebrtc.channels.get($0);if(!channel){return-1}var data_in=new Uint8Array(Module.HEAPU8.buffer,$1,$2);var data=new Uint8Array($2);data.set(data_in);channel.send(data);return $2},25397:$0=>{var connection=Module.__libwebrtc.connections.get($0);if(!connection){return-1}Module.__libwebrtc.connections.set(connection.id,undefined);connection.close()},25576:$0=>{var channel=Module.__libwebrtc.channels.get($0);if(!channel){return-1}Module.__libwebrtc.connections.set(channel.id,undefined);channel.close()},25740:$0=>{var libwebsocket={};var ctx=$0;libwebsocket.sockets=new Map;libwebsocket.on_event=Module.cwrap("lws_helper","number",["number","number","number","number","number","number","number"]);libwebsocket.connect=function(url,protocol,user_data){try{var socket=new WebSocket(url,protocol);socket.binaryType="arraybuffer";socket.user_data=user_data;socket.protocol_id=0;socket.onopen=this.on_connect;socket.onmessage=this.on_message;socket.onclose=this.on_close;socket.onerror=this.on_error;socket.destroy=this.destroy;socket.id=this.sockets.size+1;this.sockets.set(socket.id,socket);return socket}catch(e){Module.out("Socket creation failed:"+e);return 0}};libwebsocket.on_connect=function(){var stack=stackSave();const array=intArrayFromString(this.protocol);const buffer=stackAlloc(array.length);Module.HEAPU8.set(array,buffer);var ret=libwebsocket.on_event(0,ctx,this.id,9,this.user_data,buffer,this.protocol.length);if(!ret){ret=libwebsocket.on_event(this.protocol_id,ctx,this.id,3,this.user_data,0,0)}if(ret){this.close()}stackRestore(stack)};libwebsocket.on_message=function(event){var stack=stackSave();var len=event.data.byteLength;var data=new Uint8Array(event.data);const ptr=stackAlloc(data.length);Module.HEAPU8.set(data,ptr);if(libwebsocket.on_event(this.protocol_id,ctx,this.id,6,this.user_data,ptr,len)){this.close()}stackRestore(stack)};libwebsocket.on_close=function(){libwebsocket.on_event(this.protocol_id,ctx,this.id,4,this.user_data,0,0);this.destroy()};libwebsocket.on_error=function(){libwebsocket.on_event(this.protocol_id,ctx,this.id,2,this.user_data,0,0);this.destroy()};libwebsocket.destroy=function(){if(libwebsocket.sockets.has(this.id)&&libwebsocket.sockets.get(this.id)!==undefined){libwebsocket.sockets.set(this.id,undefined);libwebsocket.on_event(this.protocol_id,ctx,this.id,11,this.user_data,0,0)}};Module.__libwebsocket=libwebsocket},27840:($0,$1,$2)=>{var socket=Module.__libwebsocket.connect(UTF8ToString($0),UTF8ToString($1),$2);if(!socket){return 0}return socket.id},27976:($0,$1,$2)=>{var socket=Module.__libwebsocket.sockets.get($0);if(!socket||socket.readyState!==1){return-1}var data_in=new Uint8Array(Module.HEAPU8.buffer,$1,$2);var data=new Uint8Array($2);data.set(data_in);socket.send(data);return $2}};function getNetConfigIceServersJson(){if(!window.netConfig||!window.netConfig.iceServers){return 0}return stringToNewUTF8(JSON.stringify(window.netConfig.iceServers))}function aliasQueryAdd(query,alias,peer){Module.aliasQueryAdd(UTF8ToString(query),UTF8ToString(alias),peer)}function aliasQueryEnd(query){Module.onAliasQueryEnd(UTF8ToString(query))}var _connectTo,_free,_wait,_myId,_registerAlias,_unregisterAlias,_queryAliases,_sendto,_recvfrom,_disconnect,_shutdown,_libwebrtc_helper,_lws_helper,_malloc,___funcs_on_exit,_fflush,_setThrew,__emscripten_tempret_set,__emscripten_stack_restore,__emscripten_stack_alloc,_emscripten_stack_get_current,___cxa_increment_exception_refcount,___cxa_decrement_exception_refcount,___cxa_can_catch,___cxa_get_exception_ptr,memory,__indirect_function_table,wasmMemory,wasmTable;function assignWasmExports(wasmExports){_connectTo=Module["_connectTo"]=wasmExports["y"];_free=Module["_free"]=wasmExports["z"];_wait=Module["_wait"]=wasmExports["A"];_myId=Module["_myId"]=wasmExports["B"];_registerAlias=Module["_registerAlias"]=wasmExports["C"];_unregisterAlias=Module["_unregisterAlias"]=wasmExports["D"];_queryAliases=Module["_queryAliases"]=wasmExports["E"];_sendto=Module["_sendto"]=wasmExports["G"];_recvfrom=Module["_recvfrom"]=wasmExports["H"];_disconnect=Module["_disconnect"]=wasmExports["I"];_shutdown=Module["_shutdown"]=wasmExports["J"];_libwebrtc_helper=Module["_libwebrtc_helper"]=wasmExports["K"];_lws_helper=Module["_lws_helper"]=wasmExports["L"];_malloc=Module["_malloc"]=wasmExports["M"];___funcs_on_exit=wasmExports["N"];_fflush=wasmExports["O"];_setThrew=wasmExports["P"];__emscripten_tempret_set=wasmExports["Q"];__emscripten_stack_restore=wasmExports["R"];__emscripten_stack_alloc=wasmExports["S"];_emscripten_stack_get_current=wasmExports["T"];___cxa_increment_exception_refcount=wasmExports["U"];___cxa_decrement_exception_refcount=wasmExports["V"];___cxa_can_catch=wasmExports["W"];___cxa_get_exception_ptr=wasmExports["X"];memory=wasmMemory=wasmExports["w"];__indirect_function_table=wasmTable=wasmExports["F"]}var wasmImports={i:___cxa_begin_catch,s:___cxa_end_catch,g:___cxa_find_matching_catch_2,b:___cxa_find_matching_catch_3,c:___cxa_throw,f:___resumeException,p:__abort_js,q:aliasQueryAdd,o:aliasQueryEnd,a:_emscripten_asm_const_int,k:_emscripten_date_now,u:_emscripten_force_exit,t:_emscripten_resize_heap,n:_fd_close,m:_fd_seek,j:_fd_write,v:getNetConfigIceServersJson,e:invoke_ii,h:invoke_iii,l:invoke_v,r:invoke_vi,d:invoke_vii};function invoke_iii(index,a1,a2){var sp=stackSave();try{return getWasmTableEntry(index)(a1,a2)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_ii(index,a1){var sp=stackSave();try{return getWasmTableEntry(index)(a1)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_v(index){var sp=stackSave();try{getWasmTableEntry(index)()}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_vi(index,a1){var sp=stackSave();try{getWasmTableEntry(index)(a1)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function invoke_vii(index,a1,a2){var sp=stackSave();try{getWasmTableEntry(index)(a1,a2)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0)}}function run(){preRun();function doRun(){Module["calledRun"]=true;if(ABORT)return;initRuntime();readyPromiseResolve?.(Module);Module["onRuntimeInitialized"]?.();postRun()}if(Module["setStatus"]){Module["setStatus"]("Running...");setTimeout(()=>{setTimeout(()=>Module["setStatus"](""),1);doRun()},1)}else{doRun()}}var wasmExports;wasmExports=await (createWasm());run();if(runtimeInitialized){moduleRtn=Module}else{moduleRtn=new Promise((resolve,reject)=>{readyPromiseResolve=resolve;readyPromiseReject=reject})} ;return moduleRtn}export default HumbleNet;