"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../transport.js"),t=require("./websocket-constructor.browser.js"),r=require("../../../../engine.io-parser/build/esm/index.js");class s extends e.Transport{get name(){return"webtransport"}doOpen(){"function"==typeof WebTransport&&(this.transport=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name]),this.transport.closed.then((()=>{this.onClose()})).catch((e=>{this.onError("webtransport error",e)})),this.transport.ready.then((()=>{this.transport.createBidirectionalStream().then((e=>{const t=r.createPacketDecoderStream(Number.MAX_SAFE_INTEGER,this.socket.binaryType),s=e.readable.pipeThrough(t).getReader(),i=r.createPacketEncoderStream();i.readable.pipeTo(e.writable),this.writer=i.writable.getWriter();const n=()=>{s.read().then((e=>{let{done:t,value:r}=e;t||(this.onPacket(r),n())})).catch((e=>{}))};n();const o={type:"open"};this.query.sid&&(o.data=`{"sid":"${this.query.sid}"}`),this.writer.write(o).then((()=>this.onOpen()))}))})))}write(e){this.writable=!1;for(let r=0;r<e.length;r++){const s=e[r],i=r===e.length-1;this.writer.write(s).then((()=>{i&&t.nextTick((()=>{this.writable=!0,this.emitReserved("drain")}),this.setTimeoutFn)}))}}doClose(){var e;null===(e=this.transport)||void 0===e||e.close()}}exports.WT=s;
//# sourceMappingURL=webtransport.js.map
