2 lines
5.3 KiB
JavaScript
2 lines
5.3 KiB
JavaScript
var m={},w={},h={},p;function C(){if(p)return h;p=1,Object.defineProperty(h,"__esModule",{value:!0}),h.ERROR_PACKET=h.PACKET_TYPES_REVERSE=h.PACKET_TYPES=void 0;const e=Object.create(null);h.PACKET_TYPES=e,e.open="0",e.close="1",e.ping="2",e.pong="3",e.message="4",e.upgrade="5",e.noop="6";const l=Object.create(null);h.PACKET_TYPES_REVERSE=l,Object.keys(e).forEach(_=>{l[e[_]]=_});const b={type:"error",data:"parser error"};return h.ERROR_PACKET=b,h}var O;function K(){if(O)return w;O=1,Object.defineProperty(w,"__esModule",{value:!0}),w.encodePacket=w.encodePacketToBinary=void 0;const e=C(),l=typeof Blob=="function"||typeof Blob<"u"&&Object.prototype.toString.call(Blob)==="[object BlobConstructor]",b=typeof ArrayBuffer=="function",_=n=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(n):n&&n.buffer instanceof ArrayBuffer,i=({type:n,data:s},P,t)=>l&&s instanceof Blob?P?t(s):d(s,t):b&&(s instanceof ArrayBuffer||_(s))?P?t(s):d(new Blob([s]),t):t(e.PACKET_TYPES[n]+(s||""));w.encodePacket=i;const d=(n,s)=>{const P=new FileReader;return P.onload=function(){const t=P.result.split(",")[1];s("b"+(t||""))},P.readAsDataURL(n)};function r(n){return n instanceof Uint8Array?n:n instanceof ArrayBuffer?new Uint8Array(n):new Uint8Array(n.buffer,n.byteOffset,n.byteLength)}let u;function o(n,s){if(l&&n.data instanceof Blob)return n.data.arrayBuffer().then(r).then(s);if(b&&(n.data instanceof ArrayBuffer||_(n.data)))return s(r(n.data));i(n,!1,P=>{u||(u=new TextEncoder),s(u.encode(P))})}return w.encodePacketToBinary=o,w}var T={},g={},k;function q(){if(k)return g;k=1,Object.defineProperty(g,"__esModule",{value:!0}),g.decode=g.encode=void 0;const e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",l=typeof Uint8Array>"u"?[]:new Uint8Array(256);for(let i=0;i<e.length;i++)l[e.charCodeAt(i)]=i;const b=i=>{let d=new Uint8Array(i),r,u=d.length,o="";for(r=0;r<u;r+=3)o+=e[d[r]>>2],o+=e[(d[r]&3)<<4|d[r+1]>>4],o+=e[(d[r+1]&15)<<2|d[r+2]>>6],o+=e[d[r+2]&63];return u%3===2?o=o.substring(0,o.length-1)+"=":u%3===1&&(o=o.substring(0,o.length-2)+"=="),o};g.encode=b;const _=i=>{let d=i.length*.75,r=i.length,u,o=0,n,s,P,t;i[i.length-1]==="="&&(d--,i[i.length-2]==="="&&d--);const y=new ArrayBuffer(d),f=new Uint8Array(y);for(u=0;u<r;u+=4)n=l[i.charCodeAt(u)],s=l[i.charCodeAt(u+1)],P=l[i.charCodeAt(u+2)],t=l[i.charCodeAt(u+3)],f[o++]=n<<2|s>>4,f[o++]=(s&15)<<4|P>>2,f[o++]=(P&3)<<6|t&63;return y};return g.decode=_,g}var j;function D(){if(j)return T;j=1,Object.defineProperty(T,"__esModule",{value:!0}),T.decodePacket=void 0;const e=C(),l=q(),b=typeof ArrayBuffer=="function",_=(r,u)=>{if(typeof r!="string")return{type:"message",data:d(r,u)};const o=r.charAt(0);return o==="b"?{type:"message",data:i(r.substring(1),u)}:e.PACKET_TYPES_REVERSE[o]?r.length>1?{type:e.PACKET_TYPES_REVERSE[o],data:r.substring(1)}:{type:e.PACKET_TYPES_REVERSE[o]}:e.ERROR_PACKET};T.decodePacket=_;const i=(r,u)=>{if(b){const o=(0,l.decode)(r);return d(o,u)}else return{base64:!0,data:r}},d=(r,u)=>{switch(u){case"blob":return r instanceof Blob?r:new Blob([r]);case"arraybuffer":default:return r instanceof ArrayBuffer?r:r.buffer}};return T}var U;function V(){return U||(U=1,function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.decodePayload=e.decodePacket=e.encodePayload=e.encodePacket=e.protocol=e.createPacketDecoderStream=e.createPacketEncoderStream=void 0;const l=K();Object.defineProperty(e,"encodePacket",{enumerable:!0,get:function(){return l.encodePacket}});const b=D();Object.defineProperty(e,"decodePacket",{enumerable:!0,get:function(){return b.decodePacket}});const _=C(),i=String.fromCharCode(30),d=(t,y)=>{const f=t.length,a=new Array(f);let c=0;t.forEach((E,B)=>{(0,l.encodePacket)(E,!1,R=>{a[B]=R,++c===f&&y(a.join(i))})})};e.encodePayload=d;const r=(t,y)=>{const f=t.split(i),a=[];for(let c=0;c<f.length;c++){const E=(0,b.decodePacket)(f[c],y);if(a.push(E),E.type==="error")break}return a};e.decodePayload=r;function u(){return new TransformStream({transform(t,y){(0,l.encodePacketToBinary)(t,f=>{const a=f.length;let c;if(a<126)c=new Uint8Array(1),new DataView(c.buffer).setUint8(0,a);else if(a<65536){c=new Uint8Array(3);const E=new DataView(c.buffer);E.setUint8(0,126),E.setUint16(1,a)}else{c=new Uint8Array(9);const E=new DataView(c.buffer);E.setUint8(0,127),E.setBigUint64(1,BigInt(a))}t.data&&typeof t.data!="string"&&(c[0]|=128),y.enqueue(c),y.enqueue(f)})}})}e.createPacketEncoderStream=u;let o;function n(t){return t.reduce((y,f)=>y+f.length,0)}function s(t,y){if(t[0].length===y)return t.shift();const f=new Uint8Array(y);let a=0;for(let c=0;c<y;c++)f[c]=t[0][a++],a===t[0].length&&(t.shift(),a=0);return t.length&&a<t[0].length&&(t[0]=t[0].slice(a)),f}function P(t,y){o||(o=new TextDecoder);const f=[];let a=0,c=-1,E=!1;return new TransformStream({transform(B,R){for(f.push(B);;){if(a===0){if(n(f)<1)break;const A=s(f,1);E=(A[0]&128)===128,c=A[0]&127,c<126?a=3:c===126?a=1:a=2}else if(a===1){if(n(f)<2)break;const A=s(f,2);c=new DataView(A.buffer,A.byteOffset,A.length).getUint16(0),a=3}else if(a===2){if(n(f)<8)break;const A=s(f,8),S=new DataView(A.buffer,A.byteOffset,A.length),v=S.getUint32(0);if(v>Math.pow(2,53-32)-1){R.enqueue(_.ERROR_PACKET);break}c=v*Math.pow(2,32)+S.getUint32(4),a=3}else{if(n(f)<c)break;const A=s(f,c);R.enqueue((0,b.decodePacket)(E?A:o.decode(A),y)),a=0}if(c===0||c>t){R.enqueue(_.ERROR_PACKET);break}}}})}e.createPacketDecoderStream=P,e.protocol=4}(m)),m}export{V as r};
|