2 lines
5.2 KiB
JavaScript
2 lines
5.2 KiB
JavaScript
var C={},g={},h={},S;function m(){if(S)return h;S=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 g;O=1,Object.defineProperty(g,"__esModule",{value:!0}),g.encodePacket=void 0,g.encodePacketToBinary=o;const e=m(),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,a=({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||""));g.encodePacket=a;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));a(n,!1,P=>{u||(u=new TextEncoder),s(u.encode(P))})}return g}var T={},w={},j;function q(){if(j)return w;j=1,Object.defineProperty(w,"__esModule",{value:!0}),w.decode=w.encode=void 0;const e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",l=typeof Uint8Array>"u"?[]:new Uint8Array(256);for(let a=0;a<e.length;a++)l[e.charCodeAt(a)]=a;const b=a=>{let d=new Uint8Array(a),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};w.encode=b;const _=a=>{let d=a.length*.75,r=a.length,u,o=0,n,s,P,t;a[a.length-1]==="="&&(d--,a[a.length-2]==="="&&d--);const y=new ArrayBuffer(d),f=new Uint8Array(y);for(u=0;u<r;u+=4)n=l[a.charCodeAt(u)],s=l[a.charCodeAt(u+1)],P=l[a.charCodeAt(u+2)],t=l[a.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 w.decode=_,w}var U;function D(){if(U)return T;U=1,Object.defineProperty(T,"__esModule",{value:!0}),T.decodePacket=void 0;const e=m(),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:a(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 a=(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 k;function V(){return k||(k=1,function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.decodePayload=e.decodePacket=e.encodePayload=e.encodePacket=e.protocol=void 0,e.createPacketEncoderStream=u,e.createPacketDecoderStream=P;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 _=m(),a=String.fromCharCode(30),d=(t,y)=>{const f=t.length,i=new Array(f);let c=0;t.forEach((E,B)=>{(0,l.encodePacket)(E,!1,R=>{i[B]=R,++c===f&&y(i.join(a))})})};e.encodePayload=d;const r=(t,y)=>{const f=t.split(a),i=[];for(let c=0;c<f.length;c++){const E=(0,b.decodePacket)(f[c],y);if(i.push(E),E.type==="error")break}return i};e.decodePayload=r;function u(){return new TransformStream({transform(t,y){(0,l.encodePacketToBinary)(t,f=>{const i=f.length;let c;if(i<126)c=new Uint8Array(1),new DataView(c.buffer).setUint8(0,i);else if(i<65536){c=new Uint8Array(3);const E=new DataView(c.buffer);E.setUint8(0,126),E.setUint16(1,i)}else{c=new Uint8Array(9);const E=new DataView(c.buffer);E.setUint8(0,127),E.setBigUint64(1,BigInt(i))}t.data&&typeof t.data!="string"&&(c[0]|=128),y.enqueue(c),y.enqueue(f)})}})}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 i=0;for(let c=0;c<y;c++)f[c]=t[0][i++],i===t[0].length&&(t.shift(),i=0);return t.length&&i<t[0].length&&(t[0]=t[0].slice(i)),f}function P(t,y){o||(o=new TextDecoder);const f=[];let i=0,c=-1,E=!1;return new TransformStream({transform(B,R){for(f.push(B);;){if(i===0){if(n(f)<1)break;const A=s(f,1);E=(A[0]&128)===128,c=A[0]&127,c<126?i=3:c===126?i=1:i=2}else if(i===1){if(n(f)<2)break;const A=s(f,2);c=new DataView(A.buffer,A.byteOffset,A.length).getUint16(0),i=3}else if(i===2){if(n(f)<8)break;const A=s(f,8),p=new DataView(A.buffer,A.byteOffset,A.length),v=p.getUint32(0);if(v>Math.pow(2,53-32)-1){R.enqueue(_.ERROR_PACKET);break}c=v*Math.pow(2,32)+p.getUint32(4),i=3}else{if(n(f)<c)break;const A=s(f,c);R.enqueue((0,b.decodePacket)(E?A:o.decode(A),y)),i=0}if(c===0||c>t){R.enqueue(_.ERROR_PACKET);break}}}})}e.protocol=4}(C)),C}export{V as r};
|