2 lines
5.6 KiB
JavaScript
2 lines
5.6 KiB
JavaScript
import{r as O}from"./@socket.io.573b606e.js";import{r as v}from"./debug.b392f131.js";var _={},y={},d={},g;function C(){if(g)return d;g=1,Object.defineProperty(d,"__esModule",{value:!0}),d.hasBinary=d.isBinary=void 0;const u=typeof ArrayBuffer=="function",E=e=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(e):e.buffer instanceof ArrayBuffer,a=Object.prototype.toString,N=typeof Blob=="function"||typeof Blob<"u"&&a.call(Blob)==="[object BlobConstructor]",p=typeof File=="function"||typeof File<"u"&&a.call(File)==="[object FileConstructor]";function n(e){return u&&(e instanceof ArrayBuffer||E(e))||N&&e instanceof Blob||p&&e instanceof File}d.isBinary=n;function i(e,o){if(!e||typeof e!="object")return!1;if(Array.isArray(e)){for(let f=0,B=e.length;f<B;f++)if(i(e[f]))return!0;return!1}if(n(e))return!0;if(e.toJSON&&typeof e.toJSON=="function"&&arguments.length===1)return i(e.toJSON(),!0);for(const f in e)if(Object.prototype.hasOwnProperty.call(e,f)&&i(e[f]))return!0;return!1}return d.hasBinary=i,d}var w;function k(){if(w)return y;w=1,Object.defineProperty(y,"__esModule",{value:!0}),y.reconstructPacket=y.deconstructPacket=void 0;const u=C();function E(n){const i=[],e=n.data,o=n;return o.data=a(e,i),o.attachments=i.length,{packet:o,buffers:i}}y.deconstructPacket=E;function a(n,i){if(!n)return n;if((0,u.isBinary)(n)){const e={_placeholder:!0,num:i.length};return i.push(n),e}else if(Array.isArray(n)){const e=new Array(n.length);for(let o=0;o<n.length;o++)e[o]=a(n[o],i);return e}else if(typeof n=="object"&&!(n instanceof Date)){const e={};for(const o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=a(n[o],i));return e}return n}function N(n,i){return n.data=p(n.data,i),delete n.attachments,n}y.reconstructPacket=N;function p(n,i){if(!n)return n;if(n&&n._placeholder===!0){if(typeof n.num=="number"&&n.num>=0&&n.num<i.length)return i[n.num];throw new Error("illegal attachments")}else if(Array.isArray(n))for(let e=0;e<n.length;e++)n[e]=p(n[e],i);else if(typeof n=="object")for(const e in n)Object.prototype.hasOwnProperty.call(n,e)&&(n[e]=p(n[e],i));return n}return y}var R;function S(){return R||(R=1,function(u){Object.defineProperty(u,"__esModule",{value:!0}),u.Decoder=u.Encoder=u.PacketType=u.protocol=void 0;const E=O,a=k(),N=C(),n=(0,v().default)("socket.io-parser"),i=["connect","connect_error","disconnect","disconnecting","newListener","removeListener"];u.protocol=5;var e;(function(c){c[c.CONNECT=0]="CONNECT",c[c.DISCONNECT=1]="DISCONNECT",c[c.EVENT=2]="EVENT",c[c.ACK=3]="ACK",c[c.CONNECT_ERROR=4]="CONNECT_ERROR",c[c.BINARY_EVENT=5]="BINARY_EVENT",c[c.BINARY_ACK=6]="BINARY_ACK"})(e=u.PacketType||(u.PacketType={}));class o{constructor(t){this.replacer=t}encode(t){return n("encoding packet %j",t),(t.type===e.EVENT||t.type===e.ACK)&&(0,N.hasBinary)(t)?this.encodeAsBinary({type:t.type===e.EVENT?e.BINARY_EVENT:e.BINARY_ACK,nsp:t.nsp,data:t.data,id:t.id}):[this.encodeAsString(t)]}encodeAsString(t){let r=""+t.type;return(t.type===e.BINARY_EVENT||t.type===e.BINARY_ACK)&&(r+=t.attachments+"-"),t.nsp&&t.nsp!=="/"&&(r+=t.nsp+","),t.id!=null&&(r+=t.id),t.data!=null&&(r+=JSON.stringify(t.data,this.replacer)),n("encoded %j as %s",t,r),r}encodeAsBinary(t){const r=(0,a.deconstructPacket)(t),s=this.encodeAsString(r.packet),A=r.buffers;return A.unshift(s),A}}u.Encoder=o;function f(c){return Object.prototype.toString.call(c)==="[object Object]"}class B extends E.Emitter{constructor(t){super(),this.reviver=t}add(t){let r;if(typeof t=="string"){if(this.reconstructor)throw new Error("got plaintext data when reconstructing a packet");r=this.decodeString(t);const s=r.type===e.BINARY_EVENT;s||r.type===e.BINARY_ACK?(r.type=s?e.EVENT:e.ACK,this.reconstructor=new m(r),r.attachments===0&&super.emitReserved("decoded",r)):super.emitReserved("decoded",r)}else if((0,N.isBinary)(t)||t.base64)if(this.reconstructor)r=this.reconstructor.takeBinaryData(t),r&&(this.reconstructor=null,super.emitReserved("decoded",r));else throw new Error("got binary data when not reconstructing a packet");else throw new Error("Unknown type: "+t)}decodeString(t){let r=0;const s={type:Number(t.charAt(0))};if(e[s.type]===void 0)throw new Error("unknown packet type "+s.type);if(s.type===e.BINARY_EVENT||s.type===e.BINARY_ACK){const l=r+1;for(;t.charAt(++r)!=="-"&&r!=t.length;);const h=t.substring(l,r);if(h!=Number(h)||t.charAt(r)!=="-")throw new Error("Illegal attachments");s.attachments=Number(h)}if(t.charAt(r+1)==="/"){const l=r+1;for(;++r&&!(t.charAt(r)===","||r===t.length););s.nsp=t.substring(l,r)}else s.nsp="/";const A=t.charAt(r+1);if(A!==""&&Number(A)==A){const l=r+1;for(;++r;){const h=t.charAt(r);if(h==null||Number(h)!=h){--r;break}if(r===t.length)break}s.id=Number(t.substring(l,r+1))}if(t.charAt(++r)){const l=this.tryParse(t.substr(r));if(B.isPayloadValid(s.type,l))s.data=l;else throw new Error("invalid payload")}return n("decoded %s as %j",t,s),s}tryParse(t){try{return JSON.parse(t,this.reviver)}catch{return!1}}static isPayloadValid(t,r){switch(t){case e.CONNECT:return f(r);case e.DISCONNECT:return r===void 0;case e.CONNECT_ERROR:return typeof r=="string"||f(r);case e.EVENT:case e.BINARY_EVENT:return Array.isArray(r)&&(typeof r[0]=="number"||typeof r[0]=="string"&&i.indexOf(r[0])===-1);case e.ACK:case e.BINARY_ACK:return Array.isArray(r)}}destroy(){this.reconstructor&&(this.reconstructor.finishedReconstruction(),this.reconstructor=null)}}u.Decoder=B;class m{constructor(t){this.packet=t,this.buffers=[],this.reconPack=t}takeBinaryData(t){if(this.buffers.push(t),this.buffers.length===this.reconPack.attachments){const r=(0,a.reconstructPacket)(this.reconPack,this.buffers);return this.finishedReconstruction(),r}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}}}(_)),_}export{S as r};
|