quickvo-player 0.2.8 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,181 +1,219 @@
1
- var Q = Object.defineProperty;
2
- var X = (h) => {
1
+ var Y = Object.defineProperty;
2
+ var Z = (h) => {
3
3
  throw TypeError(h);
4
4
  };
5
- var tt = (h, o, a) => o in h ? Q(h, o, { enumerable: !0, configurable: !0, writable: !0, value: a }) : h[o] = a;
6
- var m = (h, o, a) => tt(h, typeof o != "symbol" ? o + "" : o, a), Z = (h, o, a) => o.has(h) || X("Cannot " + a);
7
- var I = (h, o, a) => (Z(h, o, "read from private field"), a ? a.call(h) : o.get(h)), J = (h, o, a) => o.has(h) ? X("Cannot add the same private member more than once") : o instanceof WeakSet ? o.add(h) : o.set(h, a), H = (h, o, a, u) => (Z(h, o, "write to private field"), u ? u.call(h, a) : o.set(h, a), a);
8
- const D = '(function(){"use strict";class P{pendingPayloads=[];payload=new Uint8Array(0);chunks=[];push=t=>{this.pendingPayloads.push(t)};next=(t=0)=>{this.payload=this.payload.slice(t);const s=this.pendingPayloads.shift();if(!s)return!1;const e=new Uint8Array(this.payload.byteLength+s.byteLength);return e.set(this.payload,0),e.set(s,this.payload.byteLength),this.payload=e,new DataView(this.payload.buffer)};pushChunk=t=>{this.chunks.push(t),this.chunks.length>1e3&&this.chunks.shift()};destroy=()=>{this.pendingPayloads=[],this.payload=new Uint8Array(0),this.chunks=[]}}const I=(y,t)=>{const s=new Uint8Array(y),e=new Uint8Array(t),n=new Uint8Array(11+s.length+e.length);let a=0;return n[a++]=1,n[a++]=s[1],n[a++]=s[2],n[a++]=s[3],n[a++]=255,n[a++]=225,n[a++]=s.length>>8&255,n[a++]=s.length&255,n.set(s,a),a+=s.length,n[a++]=1,n[a++]=e.length>>8&255,n[a++]=e.length&255,n.set(e,a),n},T=y=>{let t=0;const s=new DataView(y.buffer),e=s.getUint8(t);if(t=t+1,e!==1)throw new Error("Invalid AVC version");const n=s.getUint8(t)&255;t=t+1;const a=s.getUint8(t)&255;t=t+1;const o=s.getUint8(t)&255;t=t+1;const c=`avc1.${Array.from([n,a,o],U=>U.toString(16).padStart(2,"0")).join("")}`,r=(s.getUint8(t)&3)-1;t=t+1;const g=s.getUint8(t)&31;t=t+1;const p=s.getUint16(t,!1);t=t+2;const h=new Uint8Array(s.buffer.slice(t,t+p));t=t+p;const d=s.getUint8(t)&31;t=t+1;const u=s.getUint16(t,!1);t=t+2;const f=new Uint8Array(s.buffer.slice(t,t+u));return t=t+u,{version:e,codec:c,profile:n,compatibility:a,level:o,lengthSizeMinusOne:r,numOfSequenceParameterSets:g,sequenceParameterSetLength:p,sps:h,numOfPictureParameterSets:d,pictureParameterSetLength:u,pps:f}},M=y=>{const t=new Uint8Array(4+y.length);return new DataView(t.buffer).setUint32(0,y.length,!1),t.set(y,4),t},C=y=>{let t=0;for(const n of y)t+=n.length;const s=new Uint8Array(t);let e=0;for(const n of y){const a=n;s.set(a,e),e+=a.length}return s},D=y=>{let t="unknown";switch(y){case 1:case 2:case 27:case 36:t="video";break;case 3:case 4:case 15:t="audio";break;case 6:t="subtitle";break;case 134:t="ad";break}return t};class x{pat;pmt;audioConfig;videoConfig;payloadMap=new Map;on={};constructor(){}parse=async t=>{let s=0;for(;!(s+188>t.byteLength);){if(t.getInt8(s)!=71){s++;continue}await this.parsePacket(t,s),s+=188}return s};parsePacket=async(t,s)=>{if(s+188>t.byteLength)throw new Error("Invalid TS packet");if(t.getUint8(s)!==71)throw new Error("Invalid TS packet");let e=s;const n=this.parseHeader(t,e);e+=4;const{transport_error_indicator:a,pid:o,payload_unit_start_indicator:l,adaptation_field_control:i}=n;if(a===1||o===void 0)return;let c=184;if(i===2||i===3){const r=t.getUint8(e);e+=1,this.parseAdaptationField(t,e),e+=r,c-=r}if(i===3&&(c-=1),i===1||i===3){const r=new Uint8Array(t.buffer.slice(e,e+c));if(o===0)return this.parsePAT(t,e);{const{programs:h=[]}=this.pat||{};if(h.find(u=>u.pmt_pid===o))return this.parsePMT(t,e)}const{streams:g=[]}=this.pmt||{},p=g.find(h=>h.elementary_pid===o);if(p){if(l===1){const h=this.payloadMap.get(o);if(h){switch(p.kind){case"audio":{const d=await this.parseAudio(h);this.on.chunk&&this.on.chunk(d)}break;case"video":{const d=await this.parseVideo(h);this.on.chunk&&this.on.chunk(d),await new Promise(u=>setTimeout(()=>u(!0),0))}break}this.payloadMap.delete(o)}}{this.payloadMap.has(o)||this.payloadMap.set(o,new Uint8Array);const h=this.payloadMap.get(o),d=new Uint8Array(h.byteLength+r.byteLength);d.set(h,0),d.set(r,h.byteLength),this.payloadMap.set(o,d)}}}};parseHeader=(t,s)=>{let e=s;const n=t.getUint8(e),a=t.getUint8(e+1),o=t.getUint8(e+2),l=t.getUint8(e+3),i=(a&128)>>7;if(i===1)return{sync_byte:n,transport_error_indicator:i};const c=(a&64)>>6,r=(a&32)>>5,g=(a&31)<<8|o,p=(l&192)>>6,h=l>>4&3,d=l&15;return{sync_byte:n,transport_error_indicator:i,payload_unit_start_indicator:c,transport_priority:r,pid:g,transport_scrambling_control:p,adaptation_field_control:h,continuity_counter:d}};parsePAT=(t,s)=>{let e=s,n;{const l=t.getUint8(e);e+=1;const i=t.getUint8(e);if(e+=1,i!==0)throw new Error("Invalid PAT table_id");const c=t.getUint16(e)&4095;e+=2;const r=t.getUint16(e);e+=2;const g=(t.getUint8(e)&62)>>1,p=t.getUint8(e)&1;e+=1;const h=t.getUint8(e);e+=1;const d=t.getUint8(e);e+=1,n={pointer_field:l,table_id:i,section_length:c,transport_stream_id:r,version_number:g,current_next_indicator:p,section_number:h,last_section_number:d}}const a=[];{const l=n.section_length-5-4,i=e+l;for(;e<i;){const c=t.getUint16(e),r=t.getUint16(e+2)&8191;e+=4,c!==0&&r>=32&&r<=8190&&a.push({program_number:c,pmt_pid:r})}}const o=t.getUint32(e);this.pat={header:n,programs:a,crc32:o},this.on.debug&&this.on.debug({pat:this.pat})};parsePMT=(t,s)=>{let e=s,n;{const l=t.getUint8(e);e+=1;const i=t.getUint8(e);if(e+=1,i!==2)throw new Error("Invalid PMT table_id");const c=t.getUint16(e)&4095;e+=2;const r=t.getUint16(e);e+=2;const g=(t.getUint8(e)&62)>>1,p=t.getUint8(e)&1;e+=1;const h=t.getUint8(e);e+=1;const d=t.getUint8(e);e+=1;const u=t.getUint16(e)&8191;e+=2;const f=t.getUint16(e)&4095;e+=2,n={pointer_field:l,table_id:i,section_length:c,transport_stream_id:r,version_number:g,current_next_indicator:p,section_number:h,last_section_number:d,pcr_pid:u,program_info_length:f}}const a=[];{const l=n.section_length-9-4,i=e+l;for(;e<i;){const c=t.getUint8(e),r=D(c),g=t.getUint16(e+1)&8191,p=t.getUint16(e+3)&4095;if(e+=5,g<32||g>8190){console.warn(`Invalid elementary_pid: 0x${g.toString(16)}`);continue}a.push({kind:r,stream_type:c,elementary_pid:g,es_info_length:p})}}const o=t.getUint32(e);this.pmt={header:n,streams:a,crc32:o},this.on.debug&&this.on.debug({pmt:this.pmt})};parseAdaptationField=(t,s)=>{let e=s,n,a,o,l;const i=t.getUint8(e),c=!!(i&128),r=!!(i&64),g=!!(i&32),p=!!(i&16),h=!!(i&8),d=!!(i&4),u=!!(i&2),f=!!(i&1);e+=1;const U=(_,b)=>{let m=BigInt(0);m|=BigInt(_.getUint16(b))<<25n,m|=BigInt(_.getUint16(b+1))<<17n,m|=BigInt(_.getUint16(b+2))<<9n,m|=BigInt(_.getUint16(b+3))<<1n,m|=BigInt(_.getUint16(b+4)>>7);const S=(_.getUint16(b+4)&1)<<8|_.getUint16(b+5);return m=m*300n+BigInt(S),m};if(p&&(n=U(t,e),e+=6),h&&(a=U(t,e),e+=6),d&&(o=t.getInt8(e),e+=1),u){const _=t.getUint8(e);e+=1,l=new Uint8Array(t.buffer,e,_),e+=_}return{discontinuity_indicator:c,random_access_indicator:r,elementary_stream_priority_indicator:g,pcr_flag:p,opcr_flag:h,splicing_point_flag:d,transport_private_data_flag:u,adaptation_field_extension_flag:f,pcr:n,opcr:a,splice_countdown:o,transport_private_data:l}};parseAudio=async t=>{const s=new DataView(t.buffer);let e=0,n,a;{const o=s.getUint8(e)===0&&s.getUint8(e+1)===0&&s.getUint8(e+2)===1;if(e+=3,!o)throw new Error("invalid ts audio payload.");const l=s.getUint8(e);e+=1;const i=s.getUint8(e)<<8|s.getUint8(e+1);e+=2;let c,r,g,p,h;{const f=s.getUint8(e);e+=1,c=f>>4&3,r=(f>>3&1)===1,g=(f>>2&1)===1,p=(f>>1&1)===1,h=(f&1)===1}let d,u;{const f=s.getUint8(e);e+=1;const U=f>>6,_=s.getUint8(e);e+=1,(U&2)===2&&(d=this.parsePtsDts(s,e)),(U&1)===1?u=this.parsePtsDts(s,e+5):u=d,e+=_}n={stream_id:l,pes_packet_length:i,scrambling_control:c,priority:r,data_alignment:g,copyright:p,original_copy:h,pts:d,dts:u}}a=t.slice(e);{if(!this.audioConfig&&s.getUint8(e)===255){const g=s.getUint8(e+2),p=s.getUint8(e+3);let h,d;d=g>>2&15,h=(g&1)<<2|p>>6;const u=`mp4a.40.${h}`,U=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350][d];this.audioConfig={kind:"audio",codec:u,sampleRate:U,numberOfChannels:h},this.on.config&&this.on.config(this.audioConfig)}const{dts:o=0,pts:l=0}=n,i=l-o,c=a.slice(7);return{kind:"audio",type:"key",dts:o,pts:l,cts:i,data:c}}};parseVideo=async t=>{const s=new DataView(t.buffer);let e=0,n,a;{const o=s.getUint8(e)===0&&s.getUint8(e+1)===0&&s.getUint8(e+2)===1;if(e+=3,!o)throw new Error("invalid ts video payload.");const l=s.getUint8(e);e+=1;const i=s.getUint8(e)<<8|s.getUint8(e+1);e+=2;let c,r,g,p,h;{const f=s.getUint8(e);e+=1,c=f>>4&3,r=(f>>3&1)===1,g=(f>>2&1)===1,p=(f>>1&1)===1,h=(f&1)===1}let d,u;{const f=s.getUint8(e);e+=1;const U=f>>6,_=s.getUint8(e);e+=1,(U&2)===2&&(d=this.parsePtsDts(s,e)),(U&1)===1?u=this.parsePtsDts(s,e+5):u=d,e+=_}n={stream_id:l,pes_packet_length:i,scrambling_control:c,priority:r,data_alignment:g,copyright:p,original_copy:h,pts:d,dts:u}}a=t.slice(e);{const o=this.getNalus(a);if(!this.videoConfig){let h,d;if(h=o.find(f=>f.type===7)?.nalu.slice(4),d=o.find(f=>f.type===8)?.nalu.slice(4),h&&d){const u=I(h,d),{codec:f}=T(u);this.videoConfig={kind:"video",codec:f,description:u,sps:h,pps:d},this.on.config&&this.on.config(this.videoConfig)}}const l=[];let i="delta";for(const h of o){const{type:d,nalu:u}=h;switch(d){case 6:case 9:l.push(u);break;case 1:i="delta",l.push(u);break;case 5:i="key",l.push(u);break}}const c=C(l),{dts:r=0,pts:g=0}=n,p=g-r;return{kind:"video",type:i,dts:r,pts:g,cts:p,data:c,nalus:l}}};parsePtsDts(t,s){const e=t.getUint8(s),n=t.getUint8(s+1),a=t.getUint8(s+2),o=t.getUint8(s+3),l=t.getUint8(s+4),i=(BigInt(e)&0b00001110n)<<29n|(BigInt(n)&0b11111111n)<<22n|(BigInt(a)&0b11111110n)<<14n|(BigInt(o)&0b11111111n)<<7n|(BigInt(l)&0b11111110n)>>1n;return Number(i)/90}getNalus=t=>{const s=[];let e=0;for(;!(e+4>t.byteLength);){if(t[e]!==0||t[e+1]!==0||t[e+2]!==1){e+=1;continue}e+=3;let n=e;const a=t[e]&31;for(e+=1;!(e+1>t.byteLength);){if(t[e]!==0||t[e+1]!==0||t[e+2]!==1){e+=1;continue}break}let o=e-n;if(t[e-1]===0&&(o-=1),o!==0){const l=t.slice(n,n+o),i=M(l);s.push({type:a,nalu:i})}}return s}}const k=(y,t)=>y.getUint8(t)<<16|y.getUint8(t+1)<<8|y.getUint8(t+2);class L{audioConfig;videoConfig;header;textDecoder=new TextDecoder("utf-8");on={};constructor(){}parse=async t=>{let s=0;for(this.header||(this.parseHeader(t,s),s+=9);this.isSurplusTag(t,s)!==!1;){const n=this.parseTagHeader(t,s+4),{tagType:a,dataSize:o,timestamp:l}=n;if(a){const i=this.parseTagBody(a,t,s+4+11,o);switch(a){case"script":this.on.info&&this.on.info(i);break;case"audio":{const{accPacketType:c}=i;if(c===0){const{codec:r,sampleRate:g,channelConfiguration:p}=i;this.audioConfig={kind:"audio",codec:r,sampleRate:g,numberOfChannels:p},this.on.config&&this.on.config(this.audioConfig)}else{const{cts:r,data:g}=i,p="key",h=r===void 0?void 0:r+l;this.on.chunk&&this.on.chunk({kind:"audio",type:p,dts:l,pts:h,cts:r,data:g})}}break;case"video":{const{avcPacketType:c}=i;if(c===0){const{codec:r,sps:g,pps:p,data:h}=i;this.videoConfig={kind:"video",codec:r,description:h,sps:g,pps:p},this.on.config&&this.on.config(this.videoConfig)}else{const{frameType:r,cts:g,data:p,nalus:h}=i,d=r===1?"key":"delta",u=g===void 0?void 0:g+l;this.on.chunk&&this.on.chunk({kind:"video",type:d,dts:l,pts:u,cts:g,data:p,nalus:h})}}break}s=s+4+11+o}await new Promise(i=>setTimeout(()=>i(!0),8))}return s};parseHeader=(t,s)=>{let e,n,a,o;e=t.getUint8(s)<<16|t.getUint8(s+1)<<8|t.getUint8(s+2),n=t.getUint8(3);{const i=t.getUint8(0).toString(2).padStart(5,"0").split(""),[,,c,,r]=i;a={audio:r==="1",video:c==="1"}}o=t.getUint32(5),this.header={signature:e,version:n,flags:a,dataOffset:o}};isSurplusTag=(t,s)=>{let e=!0;const n=t.byteLength;if(s+4>n)e=!1;else if(s+4+11>n)e=!1;else{const a=k(t,s+4+1);s+4+11+a>n&&(e=!1)}return e};parseTagHeader=(t,s)=>{let e,n,a,o,l;{const i=t.getUint8(s);let c;switch(i){case 18:c="script";break;case 8:c="audio";break;case 9:c="video";break}e=c}return n=k(t,s+1),a=k(t,s+4),o=t.getUint8(s+7),l=k(t,s+8),{tagType:e,dataSize:n,timestamp:a,timestampExtended:o,streamID:l}};parseTagBody=(t,s,e,n)=>{let a;switch(t){case"script":a=this.parseMetaData(s,e);break;case"audio":a=this.parseAudio(s,e,n);break;case"video":a=this.parseVideo(s,e,n);break}return a};parseMetaData=(t,s)=>{let e=s;{if(t.getUint8(e)!==2)throw new Error("Invalid AMF type for onMetaData (expected 0x02)");e=e+1}const n=t.getUint16(e,!1);e=e+2;{const l=new Int8Array(t.buffer.slice(e,e+n));if((this.textDecoder?.decode(l)||"")!=="onMetaData")throw new Error("Expected \'onMetaData\' string");e=e+n}const a=this.getAmfType(t,e);return e=e+1,this.getAMFValue(t,e,a).value};parseAudio=(t,s,e)=>{let n=s;const a=t.getUint8(n),o=a>>4&15,l=a>>2&3,i=a>>1&1,c=a&1;n=n+1;const r=t.getUint8(n);n=n+1;const g=e,p=new Uint8Array(t.buffer.slice(n,n+g));if(o===10&&r===0){const h=t.getUint8(n),d=t.getUint8(n+1),u=h>>3&31,f=(h&7)<<1|d>>7,U=d>>3&15,_=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350],b=`mp4a.40.${u}`,m=_[f];return{soundFormat:o,soundRate:l,soundSize:i,soundType:c,accPacketType:r,data:p,samplingFrequencyIndex:f,channelConfiguration:U,codec:b,sampleRate:m}}return{soundFormat:o,soundRate:l,soundSize:i,soundType:c,accPacketType:r,data:p}};parseVideo=(t,s,e)=>{let n=s;const a=t.getUint8(n),o=a>>4&15,l=a&15;n=n+1;const i=t.getUint8(n);n=n+1;const c=k(t,n);n=n+3;const r=e-5,g=new Uint8Array(t.buffer.slice(n,n+r));switch(l){case 7:if(i===0){const p=T(g);return{frameType:o,codecID:l,avcPacketType:i,cts:c,data:g,...p}}else if(i===1){const p=[],h=n+e-5;for(;!(n+4>h);){const d=t.getUint32(n,!1),u=new Uint8Array(t.buffer.slice(n,n+4+d));n+=4+d,p.push(u)}return{frameType:o,codecID:l,avcPacketType:i,cts:c,data:g,nalus:p}}break;default:throw new Error("Unsupported codecID")}return{frameType:o,codecID:l,avcPacketType:i,cts:c,data:g}};getAmfType=(t,s)=>t.getUint8(s);getAMFName=(t,s,e)=>{const n=new Uint8Array(t.buffer.slice(s,s+e));return this.textDecoder?.decode(n)||""};getAMFValue=(t,s,e)=>{let n=s,a,o=0;switch(e){case 0:a=t.getFloat64(n,!1),o=8;break;case 1:a=!!t.getUint8(n),o=1;break;case 2:{a="";const i=t.getUint16(n,!1);n=n+2;const c=new Int8Array(t.buffer,n,i).filter(g=>g!==0);a=(this.textDecoder?.decode(c)||"").trim(),o=2+i}break;case 3:for(a={};n<t.byteLength;){const i=t.getUint16(n,!1);if(i===0)break;n=n+2;const c=this.getAMFName(t,n,i);n=n+i;const r=this.getAmfType(t,n);if(r===6)break;n=n+1;const g=this.getAMFValue(t,n,r);n=n+g.length,a[c]=g.value,o=2+i+1+g.length}break;case 8:{a={};const i=t.getUint32(n,!1);n=n+4;for(let c=0;c<i;c++){const r=t.getUint16(n,!1);n=n+2;const g=this.getAMFName(t,n,r);n=n+r;const p=this.getAmfType(t,n);n=n+1;const h=this.getAMFValue(t,n,p);n=n+h.length,a[g]=h.value,o=2+r+1+h.length}}break;case 10:{a=[];const i=t.getUint32(n,!1);n=n+4;for(let c=0;c<i;c++){const r=this.getAmfType(t,n);n=n+1;const g=this.getAMFValue(t,n,r);n=n+g.length,a.push(g.value),o=1+g.length}}break}return{amfType:e,length:o,value:a}}}class O{pattern;cacher=new P;isParseing=!1;offset=0;parser;on={};constructor(){}init=t=>{switch(this.destroy(),this.pattern=t,this.pattern){case"flv":this.parser=new L;break;case"hls":this.parser=new x;break;default:throw new Error("is error pattern.")}this.parser.on.debug=s=>this.on.debug&&this.on.debug(s),this.parser.on.info=s=>this.on.info&&this.on.info(s),this.parser.on.config=s=>this.on.config&&this.on.config(s),this.parser.on.chunk=s=>{this.cacher.pushChunk(s),this.on.chunk&&this.on.chunk(s)}};push=t=>{this.cacher.push(t),this.isParseing===!1&&this.parse()};destroy=()=>{this.cacher.destroy(),this.isParseing=!1,this.offset=0};parse=async()=>{try{if(this.isParseing=!0,!this.pattern)throw new Error("You need to set the pattern.");if(!this.parser)throw new Error("You need to init parser.");for(;;){const t=this.cacher.next(this.offset);if(this.offset=0,!t)break;this.offset=await this.parser.parse(t)}this.isParseing=!1}catch{this.destroy()}}}const A=new O;A.on.info=y=>postMessage({action:"on.info",data:y}),A.on.config=y=>postMessage({action:"on.config",data:y}),A.on.chunk=y=>postMessage({action:"on.chunk",data:y}),A.on.debug=y=>postMessage({action:"on.debug",data:y}),onmessage=y=>{const{action:t,data:s}=y.data,e=A[t];e&&e(s)}})();\n', _ = typeof self < "u" && self.Blob && new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);", D], { type: "text/javascript;charset=utf-8" });
9
- function L(h) {
5
+ var et = (h, o, u) => o in h ? Y(h, o, { enumerable: !0, configurable: !0, writable: !0, value: u }) : h[o] = u;
6
+ var y = (h, o, u) => et(h, typeof o != "symbol" ? o + "" : o, u), Q = (h, o, u) => o.has(h) || Z("Cannot " + u);
7
+ var S = (h, o, u) => (Q(h, o, "read from private field"), u ? u.call(h) : o.get(h)), K = (h, o, u) => o.has(h) ? Z("Cannot add the same private member more than once") : o instanceof WeakSet ? o.add(h) : o.set(h, u), H = (h, o, u, a) => (Q(h, o, "write to private field"), a ? a.call(h, u) : o.set(h, u), u);
8
+ const x = '(function(){"use strict";class P{pendingPayloads=[];payload=new Uint8Array(0);chunks=[];push=t=>{this.pendingPayloads.push(t)};next=(t=0)=>{this.payload=this.payload.slice(t);const s=this.pendingPayloads.shift();if(!s)return!1;const e=new Uint8Array(this.payload.byteLength+s.byteLength);return e.set(this.payload,0),e.set(s,this.payload.byteLength),this.payload=e,new DataView(this.payload.buffer)};pushChunk=t=>{this.chunks.push(t),this.chunks.length>100&&this.chunks.shift()};destroy=()=>{this.pendingPayloads=[],this.payload=new Uint8Array(0),this.chunks=[]}}const I=(y,t)=>{const s=new Uint8Array(y),e=new Uint8Array(t),n=new Uint8Array(11+s.length+e.length);let a=0;return n[a++]=1,n[a++]=s[1],n[a++]=s[2],n[a++]=s[3],n[a++]=255,n[a++]=225,n[a++]=s.length>>8&255,n[a++]=s.length&255,n.set(s,a),a+=s.length,n[a++]=1,n[a++]=e.length>>8&255,n[a++]=e.length&255,n.set(e,a),n},T=y=>{let t=0;const s=new DataView(y.buffer),e=s.getUint8(t);if(t=t+1,e!==1)throw new Error("Invalid AVC version");const n=s.getUint8(t)&255;t=t+1;const a=s.getUint8(t)&255;t=t+1;const o=s.getUint8(t)&255;t=t+1;const c=`avc1.${Array.from([n,a,o],U=>U.toString(16).padStart(2,"0")).join("")}`,r=(s.getUint8(t)&3)-1;t=t+1;const g=s.getUint8(t)&31;t=t+1;const p=s.getUint16(t,!1);t=t+2;const h=new Uint8Array(s.buffer.slice(t,t+p));t=t+p;const d=s.getUint8(t)&31;t=t+1;const u=s.getUint16(t,!1);t=t+2;const f=new Uint8Array(s.buffer.slice(t,t+u));return t=t+u,{version:e,codec:c,profile:n,compatibility:a,level:o,lengthSizeMinusOne:r,numOfSequenceParameterSets:g,sequenceParameterSetLength:p,sps:h,numOfPictureParameterSets:d,pictureParameterSetLength:u,pps:f}},M=y=>{const t=new Uint8Array(4+y.length);return new DataView(t.buffer).setUint32(0,y.length,!1),t.set(y,4),t},C=y=>{let t=0;for(const n of y)t+=n.length;const s=new Uint8Array(t);let e=0;for(const n of y){const a=n;s.set(a,e),e+=a.length}return s},D=y=>{let t="unknown";switch(y){case 1:case 2:case 27:case 36:t="video";break;case 3:case 4:case 15:t="audio";break;case 6:t="subtitle";break;case 134:t="ad";break}return t};class x{pat;pmt;audioConfig;videoConfig;payloadMap=new Map;on={};constructor(){}parse=async t=>{let s=0;for(;!(s+188>t.byteLength);){if(t.getInt8(s)!=71){s++;continue}await this.parsePacket(t,s),s+=188}return s};parsePacket=async(t,s)=>{if(s+188>t.byteLength)throw new Error("Invalid TS packet");if(t.getUint8(s)!==71)throw new Error("Invalid TS packet");let e=s;const n=this.parseHeader(t,e);e+=4;const{transport_error_indicator:a,pid:o,payload_unit_start_indicator:l,adaptation_field_control:i}=n;if(a===1||o===void 0)return;let c=184;if(i===2||i===3){const r=t.getUint8(e);e+=1,this.parseAdaptationField(t,e),e+=r,c-=r}if(i===3&&(c-=1),i===1||i===3){const r=new Uint8Array(t.buffer.slice(e,e+c));if(o===0)return this.parsePAT(t,e);{const{programs:h=[]}=this.pat||{};if(h.find(u=>u.pmt_pid===o))return this.parsePMT(t,e)}const{streams:g=[]}=this.pmt||{},p=g.find(h=>h.elementary_pid===o);if(p){if(l===1){const h=this.payloadMap.get(o);if(h){switch(p.kind){case"audio":{const d=await this.parseAudio(h);this.on.chunk&&this.on.chunk(d)}break;case"video":{const d=await this.parseVideo(h);this.on.chunk&&this.on.chunk(d),await new Promise(u=>setTimeout(()=>u(!0),0))}break}this.payloadMap.delete(o)}}{this.payloadMap.has(o)||this.payloadMap.set(o,new Uint8Array);const h=this.payloadMap.get(o),d=new Uint8Array(h.byteLength+r.byteLength);d.set(h,0),d.set(r,h.byteLength),this.payloadMap.set(o,d)}}}};parseHeader=(t,s)=>{let e=s;const n=t.getUint8(e),a=t.getUint8(e+1),o=t.getUint8(e+2),l=t.getUint8(e+3),i=(a&128)>>7;if(i===1)return{sync_byte:n,transport_error_indicator:i};const c=(a&64)>>6,r=(a&32)>>5,g=(a&31)<<8|o,p=(l&192)>>6,h=l>>4&3,d=l&15;return{sync_byte:n,transport_error_indicator:i,payload_unit_start_indicator:c,transport_priority:r,pid:g,transport_scrambling_control:p,adaptation_field_control:h,continuity_counter:d}};parsePAT=(t,s)=>{let e=s,n;{const l=t.getUint8(e);e+=1;const i=t.getUint8(e);if(e+=1,i!==0)throw new Error("Invalid PAT table_id");const c=t.getUint16(e)&4095;e+=2;const r=t.getUint16(e);e+=2;const g=(t.getUint8(e)&62)>>1,p=t.getUint8(e)&1;e+=1;const h=t.getUint8(e);e+=1;const d=t.getUint8(e);e+=1,n={pointer_field:l,table_id:i,section_length:c,transport_stream_id:r,version_number:g,current_next_indicator:p,section_number:h,last_section_number:d}}const a=[];{const l=n.section_length-5-4,i=e+l;for(;e<i;){const c=t.getUint16(e),r=t.getUint16(e+2)&8191;e+=4,c!==0&&r>=32&&r<=8190&&a.push({program_number:c,pmt_pid:r})}}const o=t.getUint32(e);this.pat={header:n,programs:a,crc32:o},this.on.debug&&this.on.debug({pat:this.pat})};parsePMT=(t,s)=>{let e=s,n;{const l=t.getUint8(e);e+=1;const i=t.getUint8(e);if(e+=1,i!==2)throw new Error("Invalid PMT table_id");const c=t.getUint16(e)&4095;e+=2;const r=t.getUint16(e);e+=2;const g=(t.getUint8(e)&62)>>1,p=t.getUint8(e)&1;e+=1;const h=t.getUint8(e);e+=1;const d=t.getUint8(e);e+=1;const u=t.getUint16(e)&8191;e+=2;const f=t.getUint16(e)&4095;e+=2,n={pointer_field:l,table_id:i,section_length:c,transport_stream_id:r,version_number:g,current_next_indicator:p,section_number:h,last_section_number:d,pcr_pid:u,program_info_length:f}}const a=[];{const l=n.section_length-9-4,i=e+l;for(;e<i;){const c=t.getUint8(e),r=D(c),g=t.getUint16(e+1)&8191,p=t.getUint16(e+3)&4095;if(e+=5,g<32||g>8190){console.warn(`Invalid elementary_pid: 0x${g.toString(16)}`);continue}a.push({kind:r,stream_type:c,elementary_pid:g,es_info_length:p})}}const o=t.getUint32(e);this.pmt={header:n,streams:a,crc32:o},this.on.debug&&this.on.debug({pmt:this.pmt})};parseAdaptationField=(t,s)=>{let e=s,n,a,o,l;const i=t.getUint8(e),c=!!(i&128),r=!!(i&64),g=!!(i&32),p=!!(i&16),h=!!(i&8),d=!!(i&4),u=!!(i&2),f=!!(i&1);e+=1;const U=(_,b)=>{let m=BigInt(0);m|=BigInt(_.getUint16(b))<<25n,m|=BigInt(_.getUint16(b+1))<<17n,m|=BigInt(_.getUint16(b+2))<<9n,m|=BigInt(_.getUint16(b+3))<<1n,m|=BigInt(_.getUint16(b+4)>>7);const S=(_.getUint16(b+4)&1)<<8|_.getUint16(b+5);return m=m*300n+BigInt(S),m};if(p&&(n=U(t,e),e+=6),h&&(a=U(t,e),e+=6),d&&(o=t.getInt8(e),e+=1),u){const _=t.getUint8(e);e+=1,l=new Uint8Array(t.buffer,e,_),e+=_}return{discontinuity_indicator:c,random_access_indicator:r,elementary_stream_priority_indicator:g,pcr_flag:p,opcr_flag:h,splicing_point_flag:d,transport_private_data_flag:u,adaptation_field_extension_flag:f,pcr:n,opcr:a,splice_countdown:o,transport_private_data:l}};parseAudio=async t=>{const s=new DataView(t.buffer);let e=0,n,a;{const o=s.getUint8(e)===0&&s.getUint8(e+1)===0&&s.getUint8(e+2)===1;if(e+=3,!o)throw new Error("invalid ts audio payload.");const l=s.getUint8(e);e+=1;const i=s.getUint8(e)<<8|s.getUint8(e+1);e+=2;let c,r,g,p,h;{const f=s.getUint8(e);e+=1,c=f>>4&3,r=(f>>3&1)===1,g=(f>>2&1)===1,p=(f>>1&1)===1,h=(f&1)===1}let d,u;{const f=s.getUint8(e);e+=1;const U=f>>6,_=s.getUint8(e);e+=1,(U&2)===2&&(d=this.parsePtsDts(s,e)),(U&1)===1?u=this.parsePtsDts(s,e+5):u=d,e+=_}n={stream_id:l,pes_packet_length:i,scrambling_control:c,priority:r,data_alignment:g,copyright:p,original_copy:h,pts:d,dts:u}}a=t.slice(e);{if(!this.audioConfig&&s.getUint8(e)===255){const g=s.getUint8(e+2),p=s.getUint8(e+3);let h,d;d=g>>2&15,h=(g&1)<<2|p>>6;const u=`mp4a.40.${h}`,U=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350][d];this.audioConfig={kind:"audio",codec:u,sampleRate:U,numberOfChannels:h},this.on.config&&this.on.config(this.audioConfig)}const{dts:o=0,pts:l=0}=n,i=l-o,c=a.slice(7);return{kind:"audio",type:"key",dts:o,pts:l,cts:i,data:c}}};parseVideo=async t=>{const s=new DataView(t.buffer);let e=0,n,a;{const o=s.getUint8(e)===0&&s.getUint8(e+1)===0&&s.getUint8(e+2)===1;if(e+=3,!o)throw new Error("invalid ts video payload.");const l=s.getUint8(e);e+=1;const i=s.getUint8(e)<<8|s.getUint8(e+1);e+=2;let c,r,g,p,h;{const f=s.getUint8(e);e+=1,c=f>>4&3,r=(f>>3&1)===1,g=(f>>2&1)===1,p=(f>>1&1)===1,h=(f&1)===1}let d,u;{const f=s.getUint8(e);e+=1;const U=f>>6,_=s.getUint8(e);e+=1,(U&2)===2&&(d=this.parsePtsDts(s,e)),(U&1)===1?u=this.parsePtsDts(s,e+5):u=d,e+=_}n={stream_id:l,pes_packet_length:i,scrambling_control:c,priority:r,data_alignment:g,copyright:p,original_copy:h,pts:d,dts:u}}a=t.slice(e);{const o=this.getNalus(a);if(!this.videoConfig){let h,d;if(h=o.find(f=>f.type===7)?.nalu.slice(4),d=o.find(f=>f.type===8)?.nalu.slice(4),h&&d){const u=I(h,d),{codec:f}=T(u);this.videoConfig={kind:"video",codec:f,description:u,sps:h,pps:d},this.on.config&&this.on.config(this.videoConfig)}}const l=[];let i="delta";for(const h of o){const{type:d,nalu:u}=h;switch(d){case 6:case 9:l.push(u);break;case 1:i="delta",l.push(u);break;case 5:i="key",l.push(u);break}}const c=C(l),{dts:r=0,pts:g=0}=n,p=g-r;return{kind:"video",type:i,dts:r,pts:g,cts:p,data:c,nalus:l}}};parsePtsDts(t,s){const e=t.getUint8(s),n=t.getUint8(s+1),a=t.getUint8(s+2),o=t.getUint8(s+3),l=t.getUint8(s+4),i=(BigInt(e)&0b00001110n)<<29n|(BigInt(n)&0b11111111n)<<22n|(BigInt(a)&0b11111110n)<<14n|(BigInt(o)&0b11111111n)<<7n|(BigInt(l)&0b11111110n)>>1n;return Number(i)/90}getNalus=t=>{const s=[];let e=0;for(;!(e+4>t.byteLength);){if(t[e]!==0||t[e+1]!==0||t[e+2]!==1){e+=1;continue}e+=3;let n=e;const a=t[e]&31;for(e+=1;!(e+1>t.byteLength);){if(t[e]!==0||t[e+1]!==0||t[e+2]!==1){e+=1;continue}break}let o=e-n;if(t[e-1]===0&&(o-=1),o!==0){const l=t.slice(n,n+o),i=M(l);s.push({type:a,nalu:i})}}return s}}const k=(y,t)=>y.getUint8(t)<<16|y.getUint8(t+1)<<8|y.getUint8(t+2);class L{audioConfig;videoConfig;header;textDecoder=new TextDecoder("utf-8");on={};constructor(){}parse=async t=>{let s=0;for(this.header||(this.parseHeader(t,s),s+=9);this.isSurplusTag(t,s)!==!1;){const n=this.parseTagHeader(t,s+4),{tagType:a,dataSize:o,timestamp:l}=n;if(a){const i=this.parseTagBody(a,t,s+4+11,o);switch(a){case"script":this.on.info&&this.on.info(i);break;case"audio":{const{accPacketType:c}=i;if(c===0){const{codec:r,sampleRate:g,channelConfiguration:p}=i;this.audioConfig={kind:"audio",codec:r,sampleRate:g,numberOfChannels:p},this.on.config&&this.on.config(this.audioConfig)}else{const{cts:r,data:g}=i,p="key",h=r===void 0?void 0:r+l;this.on.chunk&&this.on.chunk({kind:"audio",type:p,dts:l,pts:h,cts:r,data:g})}}break;case"video":{const{avcPacketType:c}=i;if(c===0){const{codec:r,sps:g,pps:p,data:h}=i;this.videoConfig={kind:"video",codec:r,description:h,sps:g,pps:p},this.on.config&&this.on.config(this.videoConfig)}else{const{frameType:r,cts:g,data:p,nalus:h}=i,d=r===1?"key":"delta",u=g===void 0?void 0:g+l;this.on.chunk&&this.on.chunk({kind:"video",type:d,dts:l,pts:u,cts:g,data:p,nalus:h})}}break}s=s+4+11+o}await new Promise(i=>setTimeout(()=>i(!0),8))}return s};parseHeader=(t,s)=>{let e,n,a,o;e=t.getUint8(s)<<16|t.getUint8(s+1)<<8|t.getUint8(s+2),n=t.getUint8(3);{const i=t.getUint8(0).toString(2).padStart(5,"0").split(""),[,,c,,r]=i;a={audio:r==="1",video:c==="1"}}o=t.getUint32(5),this.header={signature:e,version:n,flags:a,dataOffset:o}};isSurplusTag=(t,s)=>{let e=!0;const n=t.byteLength;if(s+4>n)e=!1;else if(s+4+11>n)e=!1;else{const a=k(t,s+4+1);s+4+11+a>n&&(e=!1)}return e};parseTagHeader=(t,s)=>{let e,n,a,o,l;{const i=t.getUint8(s);let c;switch(i){case 18:c="script";break;case 8:c="audio";break;case 9:c="video";break}e=c}return n=k(t,s+1),a=k(t,s+4),o=t.getUint8(s+7),l=k(t,s+8),{tagType:e,dataSize:n,timestamp:a,timestampExtended:o,streamID:l}};parseTagBody=(t,s,e,n)=>{let a;switch(t){case"script":a=this.parseMetaData(s,e);break;case"audio":a=this.parseAudio(s,e,n);break;case"video":a=this.parseVideo(s,e,n);break}return a};parseMetaData=(t,s)=>{let e=s;{if(t.getUint8(e)!==2)throw new Error("Invalid AMF type for onMetaData (expected 0x02)");e=e+1}const n=t.getUint16(e,!1);e=e+2;{const l=new Int8Array(t.buffer.slice(e,e+n));if((this.textDecoder?.decode(l)||"")!=="onMetaData")throw new Error("Expected \'onMetaData\' string");e=e+n}const a=this.getAmfType(t,e);return e=e+1,this.getAMFValue(t,e,a).value};parseAudio=(t,s,e)=>{let n=s;const a=t.getUint8(n),o=a>>4&15,l=a>>2&3,i=a>>1&1,c=a&1;n=n+1;const r=t.getUint8(n);n=n+1;const g=e,p=new Uint8Array(t.buffer.slice(n,n+g));if(o===10&&r===0){const h=t.getUint8(n),d=t.getUint8(n+1),u=h>>3&31,f=(h&7)<<1|d>>7,U=d>>3&15,_=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350],b=`mp4a.40.${u}`,m=_[f];return{soundFormat:o,soundRate:l,soundSize:i,soundType:c,accPacketType:r,data:p,samplingFrequencyIndex:f,channelConfiguration:U,codec:b,sampleRate:m}}return{soundFormat:o,soundRate:l,soundSize:i,soundType:c,accPacketType:r,data:p}};parseVideo=(t,s,e)=>{let n=s;const a=t.getUint8(n),o=a>>4&15,l=a&15;n=n+1;const i=t.getUint8(n);n=n+1;const c=k(t,n);n=n+3;const r=e-5,g=new Uint8Array(t.buffer.slice(n,n+r));switch(l){case 7:if(i===0){const p=T(g);return{frameType:o,codecID:l,avcPacketType:i,cts:c,data:g,...p}}else if(i===1){const p=[],h=n+e-5;for(;!(n+4>h);){const d=t.getUint32(n,!1),u=new Uint8Array(t.buffer.slice(n,n+4+d));n+=4+d,p.push(u)}return{frameType:o,codecID:l,avcPacketType:i,cts:c,data:g,nalus:p}}break;default:throw new Error("Unsupported codecID")}return{frameType:o,codecID:l,avcPacketType:i,cts:c,data:g}};getAmfType=(t,s)=>t.getUint8(s);getAMFName=(t,s,e)=>{const n=new Uint8Array(t.buffer.slice(s,s+e));return this.textDecoder?.decode(n)||""};getAMFValue=(t,s,e)=>{let n=s,a,o=0;switch(e){case 0:a=t.getFloat64(n,!1),o=8;break;case 1:a=!!t.getUint8(n),o=1;break;case 2:{a="";const i=t.getUint16(n,!1);n=n+2;const c=new Int8Array(t.buffer,n,i).filter(g=>g!==0);a=(this.textDecoder?.decode(c)||"").trim(),o=2+i}break;case 3:for(a={};n<t.byteLength;){const i=t.getUint16(n,!1);if(i===0)break;n=n+2;const c=this.getAMFName(t,n,i);n=n+i;const r=this.getAmfType(t,n);if(r===6)break;n=n+1;const g=this.getAMFValue(t,n,r);n=n+g.length,a[c]=g.value,o=2+i+1+g.length}break;case 8:{a={};const i=t.getUint32(n,!1);n=n+4;for(let c=0;c<i;c++){const r=t.getUint16(n,!1);n=n+2;const g=this.getAMFName(t,n,r);n=n+r;const p=this.getAmfType(t,n);n=n+1;const h=this.getAMFValue(t,n,p);n=n+h.length,a[g]=h.value,o=2+r+1+h.length}}break;case 10:{a=[];const i=t.getUint32(n,!1);n=n+4;for(let c=0;c<i;c++){const r=this.getAmfType(t,n);n=n+1;const g=this.getAMFValue(t,n,r);n=n+g.length,a.push(g.value),o=1+g.length}}break}return{amfType:e,length:o,value:a}}}class O{pattern;cacher=new P;isParseing=!1;offset=0;parser;on={};constructor(){}init=t=>{switch(this.destroy(),this.pattern=t,this.pattern){case"flv":this.parser=new L;break;case"hls":this.parser=new x;break;default:throw new Error("is error pattern.")}this.parser.on.debug=s=>this.on.debug&&this.on.debug(s),this.parser.on.info=s=>this.on.info&&this.on.info(s),this.parser.on.config=s=>this.on.config&&this.on.config(s),this.parser.on.chunk=s=>{this.cacher.pushChunk(s),this.on.chunk&&this.on.chunk(s)}};push=t=>{this.cacher.push(t),this.isParseing===!1&&this.parse()};destroy=()=>{this.cacher.destroy(),this.isParseing=!1,this.offset=0};parse=async()=>{try{if(this.isParseing=!0,!this.pattern)throw new Error("You need to set the pattern.");if(!this.parser)throw new Error("You need to init parser.");for(;;){const t=this.cacher.next(this.offset);if(this.offset=0,!t)break;this.offset=await this.parser.parse(t)}this.isParseing=!1}catch{this.destroy()}}}const A=new O;A.on.info=y=>postMessage({action:"on.info",data:y}),A.on.config=y=>postMessage({action:"on.config",data:y}),A.on.chunk=y=>postMessage({action:"on.chunk",data:y}),A.on.debug=y=>postMessage({action:"on.debug",data:y}),onmessage=y=>{const{action:t,data:s}=y.data,e=A[t];e&&e(s)}})();\n', _ = typeof self < "u" && self.Blob && new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);", x], { type: "text/javascript;charset=utf-8" });
9
+ function R(h) {
10
10
  let o;
11
11
  try {
12
12
  if (o = _ && (self.URL || self.webkitURL).createObjectURL(_), !o) throw "";
13
- const a = new Worker(o, {
13
+ const u = new Worker(o, {
14
14
  name: h == null ? void 0 : h.name
15
15
  });
16
- return a.addEventListener("error", () => {
16
+ return u.addEventListener("error", () => {
17
17
  (self.URL || self.webkitURL).revokeObjectURL(o);
18
- }), a;
18
+ }), u;
19
19
  } catch {
20
20
  return new Worker(
21
- "data:text/javascript;charset=utf-8," + encodeURIComponent(D),
21
+ "data:text/javascript;charset=utf-8," + encodeURIComponent(x),
22
22
  {
23
23
  name: h == null ? void 0 : h.name
24
24
  }
25
25
  );
26
26
  }
27
27
  }
28
- class V {
28
+ class I {
29
29
  constructor() {
30
- m(this, "worker", new L());
31
- m(this, "on", {});
32
- m(this, "init", (o) => this.worker.postMessage({ action: "init", data: o }));
33
- m(this, "push", (o) => this.worker.postMessage({ action: "push", data: o }));
34
- m(this, "destroy", () => {
30
+ y(this, "worker", new R());
31
+ y(this, "on", {});
32
+ y(this, "init", (o) => this.worker.postMessage({ action: "init", data: o }));
33
+ y(this, "push", (o) => this.worker.postMessage({ action: "push", data: o }));
34
+ y(this, "destroy", () => {
35
35
  this.worker.postMessage({ action: "destroy", data: {} }), this.worker.terminate();
36
36
  });
37
37
  this.worker.onmessage = (o) => {
38
- const { action: a, data: u } = o.data;
39
- switch (a) {
38
+ const { action: u, data: a } = o.data;
39
+ switch (u) {
40
40
  case "on.info":
41
- this.on.info && this.on.info(u);
41
+ this.on.info && this.on.info(a);
42
42
  break;
43
43
  case "on.config":
44
- this.on.config && this.on.config(u);
44
+ this.on.config && this.on.config(a);
45
45
  break;
46
46
  case "on.chunk":
47
- this.on.chunk && this.on.chunk(u);
47
+ this.on.chunk && this.on.chunk(a);
48
48
  break;
49
49
  case "on.debug":
50
- this.on.debug && this.on.debug(u);
50
+ this.on.debug && this.on.debug(a);
51
51
  break;
52
52
  }
53
53
  };
54
54
  }
55
55
  }
56
- const S = `(function(){"use strict";class r{pattern="flv";audioDecoderConfig;audioDecoder;videoDecoderConfig;videoDecoder;hasKeyFrame=!1;baseTime=0;pendingChunks=[];currentChunk;isProcessing=!1;decodeTimer=0;frameTrack=!1;isFrameTrack=!1;fameTrackOption={flv:[30,50],hls:[200,300],dash:[50,100],rtmp:[50,100]};decodingSpeedRatio=1;maxDecodingSpeedRatio=2;decodingSpeed=16;fps=0;firstVideoChunkTimestamp;secondVideoChunkTimestamp;frameStartTime;lastRenderTime;nextRenderTime;on={audio:{},video:{}};constructor(){}init=e=>{this.destroy(),this.pattern=e,this.baseTime=new Date().getTime()-performance.now(),this.initDecodeInterval()};initAudio=e=>{this.audio.destroy(),this.audioDecoderConfig={...e},this.audioDecoder=new AudioDecoder({output:i=>{const o=this.decodingSpeedRatio;this.on.audio.decode&&this.on.audio.decode({audioData:i,playbackRate:o})},error:i=>{this.on.audio.error&&this.on.audio.error(i)}}),this.audioDecoder.configure(this.audioDecoderConfig)};initVideo=e=>{this.video.destroy(),this.videoDecoderConfig={...e},this.videoDecoder=new VideoDecoder({output:async i=>{this.frameStartTime||(this.frameStartTime=i.timestamp);const o=i.timestamp-this.frameStartTime+this.baseTime*1e3,s=await createImageBitmap(i);i.close(),s.width>0&&s.height>0?(this.on.video.decode&&this.on.video.decode({timestamp:o,bitmap:s}),this.currentChunk&&this.currentChunk.kind==="video"&&this.currentChunk.nalus&&this.on.nalus&&this.on.nalus(this.currentChunk.nalus)):s.close()},error:i=>{this.on.video.error&&this.on.video.error(i)}}),this.videoDecoder.configure(this.videoDecoderConfig)};setFrameTrack=e=>{this.frameTrack=e,this.frameTrack===!1&&(this.decodingSpeedRatio=1)};push=e=>{this.pendingChunks.push(e)};destroy=()=>{this.audio.destroy(),this.video.destroy(),this.pendingChunks=[],this.firstVideoChunkTimestamp=void 0,this.secondVideoChunkTimestamp=void 0,this.frameStartTime=void 0,this.lastRenderTime=void 0,this.nextRenderTime=void 0,clearInterval(this.decodeTimer)};initDecodeInterval=()=>{let e=this.decodingSpeed/this.decodingSpeedRatio;const i=this.baseTime+performance.now();if(this.lastRenderTime||(this.lastRenderTime=i),this.fps=Math.round(1e3/(i-this.lastRenderTime)),this.lastRenderTime=i,this.nextRenderTime){const o=this.lastRenderTime-this.nextRenderTime;e-=o}this.nextRenderTime=this.lastRenderTime+e,this.decodeTimer=setTimeout(()=>{this.decode(),this.initDecodeInterval()},e)};decode=()=>{if(this.isProcessing!==!0){for(this.isProcessing=!0;;){this.currentChunk=this.pendingChunks.shift();const e=this.pendingChunks.length;if(this.frameTrack){const[s,n]=this.fameTrackOption[this.pattern];if(e<=s&&(this.isFrameTrack=!1),e>=n&&(this.isFrameTrack=!0),this.isFrameTrack){const a=Math.min(1+(e-s)/100,this.maxDecodingSpeedRatio);this.decodingSpeedRatio=Number(a.toFixed(1))}else this.decodingSpeedRatio=1}if(this.on.analysis){const{decodingSpeed:s,decodingSpeedRatio:n,fps:a}=this;this.on.analysis({decodingSpeed:s,decodingSpeedRatio:n,fps:a,cacheLength:e})}if(!this.currentChunk)break;const{kind:i,init:o}=this.currentChunk;switch(i){case"audio":this.decodeAudio(o);break;case"video":this.decodeVideo(o);break}if(i==="video")break}this.isProcessing=!1}};decodeAudio=e=>{if(!this.audioDecoder)return;const i=new EncodedAudioChunk(e);this.audioDecoder.decode(i)};decodeVideo=e=>{if(this.videoDecoder&&(e.type==="key"&&(this.hasKeyFrame=!0),this.firstVideoChunkTimestamp?this.secondVideoChunkTimestamp||(this.secondVideoChunkTimestamp=e.timestamp,this.decodingSpeed=(this.secondVideoChunkTimestamp-this.firstVideoChunkTimestamp)/1e3):this.firstVideoChunkTimestamp=e.timestamp,this.hasKeyFrame)){const i=new EncodedVideoChunk(e);this.videoDecoder.decode(i)}};audio={flush:()=>{this.audioDecoder?.flush()},destroy:()=>{this.audioDecoderConfig=void 0,this.audioDecoder?.close(),this.audioDecoder=void 0}};video={flush:()=>{this.videoDecoder?.flush()},destroy:()=>{this.videoDecoderConfig=void 0,this.videoDecoder?.close(),this.videoDecoder=void 0,this.hasKeyFrame=!1}}}const d=new r;d.on.audio.decode=t=>postMessage({action:"on.audio.decode",data:t}),d.on.audio.error=t=>postMessage({action:"on.audio.error",data:t}),d.on.video.decode=t=>postMessage({action:"on.video.decode",data:t}),d.on.video.error=t=>postMessage({action:"on.video.error",data:t}),d.on.nalus=t=>postMessage({action:"on.nalus",data:t}),d.on.analysis=t=>postMessage({action:"on.analysis",data:t}),onmessage=t=>{const{action:e,data:i}=t.data,o=d[e];o&&o(i)}})();
57
- `, C = typeof self < "u" && self.Blob && new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);", S], { type: "text/javascript;charset=utf-8" });
58
- function F(h) {
56
+ const M = `(function(){"use strict";class r{pattern="flv";audioDecoderConfig;audioDecoder;videoDecoderConfig;videoDecoder;hasKeyFrame=!1;baseTime=0;pendingChunks=[];currentChunk;isProcessing=!1;decodeTimer=0;frameTrack=!1;isFrameTrack=!1;fameTrackOption={flv:[30,50],hls:[200,300],dash:[50,100],rtmp:[50,100]};decodingSpeedRatio=1;maxDecodingSpeedRatio=2;decodingSpeed=16;fps=0;firstVideoChunkTimestamp;secondVideoChunkTimestamp;frameStartTime;lastRenderTime;nextRenderTime;on={audio:{},video:{}};constructor(){}init=e=>{this.destroy(),this.pattern=e,this.baseTime=new Date().getTime()-performance.now(),this.initDecodeInterval()};initAudio=e=>{this.audio.destroy(),this.audioDecoderConfig={...e},this.audioDecoder=new AudioDecoder({output:i=>{const t=this.decodingSpeedRatio;this.on.audio.decode&&this.on.audio.decode({audioData:i,playbackRate:t})},error:i=>{this.on.audio.error&&this.on.audio.error(i)}}),this.audioDecoder.configure(this.audioDecoderConfig)};initVideo=e=>{this.video.destroy(),this.videoDecoderConfig={...e},this.videoDecoder=new VideoDecoder({output:async i=>{this.frameStartTime||(this.frameStartTime=i.timestamp);const t=i.timestamp-this.frameStartTime+this.baseTime*1e3,s=await createImageBitmap(i);i.close(),s.width>0&&s.height>0?(this.on.video.decode&&this.on.video.decode({timestamp:t,bitmap:s}),this.currentChunk&&this.currentChunk.kind==="video"&&this.currentChunk.nalus&&this.on.nalus&&this.on.nalus(this.currentChunk.nalus)):s.close()},error:i=>{this.on.video.error&&this.on.video.error(i)}}),this.videoDecoder.configure(this.videoDecoderConfig)};setFrameTrack=e=>{this.frameTrack=e,this.frameTrack===!1&&(this.decodingSpeedRatio=1)};push=e=>{this.pendingChunks.push(e)};destroy=()=>{this.audio.destroy(),this.video.destroy(),this.pendingChunks=[],this.firstVideoChunkTimestamp=void 0,this.secondVideoChunkTimestamp=void 0,this.frameStartTime=void 0,this.lastRenderTime=void 0,this.nextRenderTime=void 0,clearInterval(this.decodeTimer)};initDecodeInterval=()=>{let e=this.decodingSpeed/this.decodingSpeedRatio;const i=this.baseTime+performance.now();if(this.lastRenderTime||(this.lastRenderTime=i),this.fps=Math.round(1e3/(i-this.lastRenderTime)),this.lastRenderTime=i,this.nextRenderTime){const t=this.lastRenderTime-this.nextRenderTime;e-=t}this.nextRenderTime=this.lastRenderTime+e,this.decodeTimer=setTimeout(()=>{this.decode(),this.initDecodeInterval()},e)};decode=()=>{if(this.isProcessing!==!0){for(this.isProcessing=!0;this.currentChunk=this.pendingChunks.shift(),!!this.currentChunk;){const e=this.pendingChunks.length;if(this.frameTrack){const[s,n]=this.fameTrackOption[this.pattern];if(e<=s&&(this.isFrameTrack=!1),e>=n&&(this.isFrameTrack=!0),this.isFrameTrack){const a=Math.min(1+(e-s)/100,this.maxDecodingSpeedRatio);this.decodingSpeedRatio=Number(a.toFixed(1))}else this.decodingSpeedRatio=1}if(this.on.analysis){const{decodingSpeed:s,decodingSpeedRatio:n,fps:a}=this;this.on.analysis({decodingSpeed:s,decodingSpeedRatio:n,fps:a,cacheLength:e})}const{kind:i,init:t}=this.currentChunk;switch(i){case"audio":this.decodeAudio(t);break;case"video":this.decodeVideo(t);break}if(i==="video")break}this.isProcessing=!1}};decodeAudio=e=>{if(!this.audioDecoder)return;const i=new EncodedAudioChunk(e);this.audioDecoder.decode(i)};decodeVideo=e=>{if(this.videoDecoder&&(e.type==="key"&&(this.hasKeyFrame=!0),this.firstVideoChunkTimestamp?this.secondVideoChunkTimestamp||(this.secondVideoChunkTimestamp=e.timestamp,this.decodingSpeed=(this.secondVideoChunkTimestamp-this.firstVideoChunkTimestamp)/1e3):this.firstVideoChunkTimestamp=e.timestamp,this.hasKeyFrame)){const i=new EncodedVideoChunk(e);this.videoDecoder.decode(i)}};audio={flush:()=>{this.audioDecoder?.flush()},destroy:()=>{this.audioDecoderConfig=void 0,this.audioDecoder?.close(),this.audioDecoder=void 0}};video={flush:()=>{this.videoDecoder?.flush()},destroy:()=>{this.videoDecoderConfig=void 0,this.videoDecoder?.close(),this.videoDecoder=void 0,this.hasKeyFrame=!1}}}const d=new r;d.on.audio.decode=o=>postMessage({action:"on.audio.decode",data:o},[o.audioData]),d.on.audio.error=o=>postMessage({action:"on.audio.error",data:o}),d.on.video.decode=o=>postMessage({action:"on.video.decode",data:o},[o.bitmap]),d.on.video.error=o=>postMessage({action:"on.video.error",data:o}),d.on.nalus=o=>postMessage({action:"on.nalus",data:o}),d.on.analysis=o=>postMessage({action:"on.analysis",data:o}),onmessage=o=>{const{action:e,data:i}=o.data,t=d[e];t&&t(i)}})();
57
+ `, C = typeof self < "u" && self.Blob && new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);", M], { type: "text/javascript;charset=utf-8" });
58
+ function V(h) {
59
59
  let o;
60
60
  try {
61
61
  if (o = C && (self.URL || self.webkitURL).createObjectURL(C), !o) throw "";
62
- const a = new Worker(o, {
62
+ const u = new Worker(o, {
63
63
  name: h == null ? void 0 : h.name
64
64
  });
65
- return a.addEventListener("error", () => {
65
+ return u.addEventListener("error", () => {
66
66
  (self.URL || self.webkitURL).revokeObjectURL(o);
67
- }), a;
67
+ }), u;
68
68
  } catch {
69
69
  return new Worker(
70
- "data:text/javascript;charset=utf-8," + encodeURIComponent(S),
70
+ "data:text/javascript;charset=utf-8," + encodeURIComponent(M),
71
71
  {
72
72
  name: h == null ? void 0 : h.name
73
73
  }
74
74
  );
75
75
  }
76
76
  }
77
- class N {
77
+ class L {
78
78
  constructor() {
79
- m(this, "worker", new F());
80
- m(this, "on", { audio: {}, video: {} });
81
- m(this, "init", (o) => this.worker.postMessage({ action: "init", data: o }));
82
- m(this, "initAudio", (o) => this.worker.postMessage({ action: "initAudio", data: o }));
83
- m(this, "initVideo", (o) => this.worker.postMessage({ action: "initVideo", data: o }));
84
- m(this, "push", (o) => this.worker.postMessage({ action: "push", data: o }));
85
- m(this, "setFrameTrack", (o) => this.worker.postMessage({ action: "setFrameTrack", data: o }));
86
- m(this, "destroy", () => {
79
+ y(this, "worker", new V());
80
+ y(this, "on", { audio: {}, video: {} });
81
+ y(this, "init", (o) => this.worker.postMessage({ action: "init", data: o }));
82
+ y(this, "initAudio", (o) => this.worker.postMessage({ action: "initAudio", data: o }));
83
+ y(this, "initVideo", (o) => this.worker.postMessage({ action: "initVideo", data: o }));
84
+ y(this, "push", (o) => this.worker.postMessage({ action: "push", data: o }));
85
+ y(this, "setFrameTrack", (o) => this.worker.postMessage({ action: "setFrameTrack", data: o }));
86
+ y(this, "destroy", () => {
87
87
  this.worker.postMessage({ action: "destroy" }), this.worker.terminate();
88
88
  });
89
89
  this.worker.onmessage = (o) => {
90
- const { action: a, data: u } = o.data;
91
- switch (a) {
90
+ const { action: u, data: a } = o.data;
91
+ switch (u) {
92
92
  case "on.audio.decode":
93
- this.on.audio.decode && this.on.audio.decode(u);
93
+ this.on.audio.decode && this.on.audio.decode(a);
94
94
  break;
95
95
  case "on.audio.error":
96
- this.on.audio.error && this.on.audio.error(u);
96
+ this.on.audio.error && this.on.audio.error(a);
97
97
  break;
98
98
  case "on.video.decode":
99
- this.on.video.decode && this.on.video.decode(u);
99
+ this.on.video.decode && this.on.video.decode(a);
100
100
  break;
101
101
  case "on.video.error":
102
- this.on.video.error && this.on.video.error(u);
102
+ this.on.video.error && this.on.video.error(a);
103
103
  break;
104
104
  case "on.nalus":
105
- this.on.nalus && this.on.nalus(u);
105
+ this.on.nalus && this.on.nalus(a);
106
106
  break;
107
107
  case "on.analysis":
108
- this.on.analysis && this.on.analysis(u);
108
+ this.on.analysis && this.on.analysis(a);
109
109
  break;
110
110
  }
111
111
  };
112
112
  }
113
113
  }
114
- var B = Object.defineProperty, G = (h, o, a) => o in h ? B(h, o, { enumerable: !0, configurable: !0, writable: !0, value: a }) : h[o] = a, y = (h, o, a) => G(h, typeof o != "symbol" ? o + "" : o, a);
115
- class O {
116
- constructor(o, a) {
117
- y(this, "inputStream", new MediaStream()), y(this, "outputStream", new MediaStream()), y(this, "inputGain", 1), y(this, "enhanceGain", 1), y(this, "bgsGain", 1), y(this, "bgmGain", 1), y(this, "outputGain", 1), y(this, "mixAudioMap", /* @__PURE__ */ new Map()), y(this, "audioContext", new AudioContext()), y(this, "sourceNode"), y(this, "inputGainNode"), y(this, "enhanceGainNode"), y(this, "bgsGainNode"), y(this, "bgmGainNode"), y(this, "analyserNode"), y(this, "analyserArrayData"), y(this, "outputGainNode"), y(this, "destinationNode"), y(this, "filterStream", (u) => u), y(this, "stop", () => {
114
+ const D = `(function(){"use strict";class h{renderMap=new Map;constructor(){}push=async t=>{const{timestamp:s}=t,{bitmap:e}=t;if(e.height===0||e.width===0)return e.close();const n=[...this.renderMap.keys()];for(const i of n){const a=this.renderMap.get(i);if(!a)continue;const{pause:f=!1,writer:c,option:d}=a;if(f!==!0)if(i==="default"||!d){const o=new VideoFrame(e,{timestamp:s});c.write(o),o.close()}else{const{sx:o=0,sy:w=0,sw:y=e.width,sh:M=e.height}=d,u=await createImageBitmap(e,o,w,y,M),p=new VideoFrame(u,{timestamp:s});u.close(),c.write(p),p.close()}}e.close()};addCut=t=>{const{key:s,writable:e,option:n}={key:"default",...t},i=e.getWriter();this.renderMap.set(s,{writable:e,writer:i,option:n,pause:!1})};delCut=t=>{this.renderMap.delete(t)};setCut=t=>{const{key:s,cutOption:e}={key:"default",...t},n=this.renderMap.get(s);n&&this.renderMap.set(s,{...n,option:e})};setPause=t=>{const{key:s,pause:e}={key:"default",...t},n=this.renderMap.get(s);n&&this.renderMap.set(s,{...n,pause:e})};destroy=()=>{this.renderMap=new Map}}const l=new h;onmessage=r=>{const{action:t,data:s}=r.data,e=l[t];e&&e(s)}})();
115
+ `, v = typeof self < "u" && self.Blob && new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);", D], { type: "text/javascript;charset=utf-8" });
116
+ function N(h) {
117
+ let o;
118
+ try {
119
+ if (o = v && (self.URL || self.webkitURL).createObjectURL(v), !o) throw "";
120
+ const u = new Worker(o, {
121
+ name: h == null ? void 0 : h.name
122
+ });
123
+ return u.addEventListener("error", () => {
124
+ (self.URL || self.webkitURL).revokeObjectURL(o);
125
+ }), u;
126
+ } catch {
127
+ return new Worker(
128
+ "data:text/javascript;charset=utf-8," + encodeURIComponent(D),
118
129
  {
119
- const u = this.inputStream.getTracks();
120
- for (const n of u)
130
+ name: h == null ? void 0 : h.name
131
+ }
132
+ );
133
+ }
134
+ }
135
+ class F {
136
+ constructor() {
137
+ y(this, "worker", new N());
138
+ y(this, "push", (o) => this.worker.postMessage({ action: "push", data: o }, [o.bitmap]));
139
+ y(this, "addCut", (o) => this.worker.postMessage({ action: "addCut", data: o }, [o.writable]));
140
+ y(this, "delCut", (o) => this.worker.postMessage({ action: "delCut", data: o }));
141
+ y(this, "setCut", (o) => this.worker.postMessage({ action: "setCut", data: o }));
142
+ y(this, "setPause", (o) => this.worker.postMessage({ action: "setPause", data: o }));
143
+ y(this, "destroy", () => {
144
+ this.worker.postMessage({ action: "destroy", data: {} }), this.worker.terminate();
145
+ });
146
+ }
147
+ }
148
+ var B = Object.defineProperty, G = (h, o, u) => o in h ? B(h, o, { enumerable: !0, configurable: !0, writable: !0, value: u }) : h[o] = u, m = (h, o, u) => G(h, typeof o != "symbol" ? o + "" : o, u);
149
+ class W {
150
+ constructor(o, u) {
151
+ m(this, "inputStream", new MediaStream()), m(this, "outputStream", new MediaStream()), m(this, "inputGain", 1), m(this, "enhanceGain", 1), m(this, "bgsGain", 1), m(this, "bgmGain", 1), m(this, "outputGain", 1), m(this, "mixAudioMap", /* @__PURE__ */ new Map()), m(this, "audioContext", new AudioContext()), m(this, "sourceNode"), m(this, "highPassNode"), m(this, "lowPassNode"), m(this, "inputGainNode"), m(this, "enhanceGainNode"), m(this, "bgsGainNode"), m(this, "bgmGainNode"), m(this, "analyserNode"), m(this, "analyserArrayData"), m(this, "outputGainNode"), m(this, "destinationNode"), m(this, "filterStream", (a) => a), m(this, "stop", () => {
152
+ {
153
+ const a = this.inputStream.getTracks();
154
+ for (const n of a)
121
155
  n.stop(), this.inputStream.removeTrack(n);
122
156
  }
123
- }), y(this, "getStream", () => this.filterStream(this.outputStream)), y(this, "setMute", (u = !0) => {
124
- u ? this.analyserNode.disconnect(this.outputGainNode) : this.analyserNode.connect(this.outputGainNode);
125
- }), y(this, "setInputGain", (u) => {
126
- this.inputGain = u, this.inputGainNode.gain.setValueAtTime(u, this.audioContext.currentTime);
127
- }), y(this, "setEnhanceGain", async (u) => {
128
- this.enhanceGain = u + 1, this.enhanceGainNode.gain.setValueAtTime(this.enhanceGain, this.audioContext.currentTime);
129
- }), y(this, "setBgsGain", (u) => {
130
- this.bgsGain = u, this.bgsGainNode.gain.setValueAtTime(u, this.audioContext.currentTime);
131
- }), y(this, "setBgmGain", (u) => {
132
- this.bgmGain = u, this.bgmGainNode.gain.setValueAtTime(u, this.audioContext.currentTime);
133
- }), y(this, "setOutputGain", (u) => {
134
- this.outputGain = u, this.outputGainNode.gain.setValueAtTime(this.outputGain, this.audioContext.currentTime);
135
- }), y(this, "getVolume", () => {
136
- const { analyserNode: u, analyserArrayData: n } = this;
137
- u.getByteFrequencyData(n);
157
+ }), m(this, "pause", async (a) => {
158
+ const n = this.inputStream.getTracks();
159
+ for (const r of n)
160
+ r.enabled = !a;
161
+ }), m(this, "getStream", () => this.filterStream(this.outputStream)), m(this, "setMute", (a = !0) => {
162
+ a ? this.analyserNode.disconnect(this.outputGainNode) : this.analyserNode.connect(this.outputGainNode);
163
+ }), m(this, "setInputGain", (a) => {
164
+ this.inputGain = a, this.inputGainNode.gain.setValueAtTime(a, this.audioContext.currentTime);
165
+ }), m(this, "setEnhanceGain", async (a) => {
166
+ this.enhanceGain = a + 1, this.enhanceGainNode.gain.setValueAtTime(this.enhanceGain, this.audioContext.currentTime);
167
+ }), m(this, "setBgsGain", (a) => {
168
+ this.bgsGain = a, this.bgsGainNode.gain.setValueAtTime(a, this.audioContext.currentTime);
169
+ }), m(this, "setBgmGain", (a) => {
170
+ this.bgmGain = a, this.bgmGainNode.gain.setValueAtTime(a, this.audioContext.currentTime);
171
+ }), m(this, "setOutputGain", (a) => {
172
+ this.outputGain = a, this.outputGainNode.gain.setValueAtTime(this.outputGain, this.audioContext.currentTime);
173
+ }), m(this, "getVolume", () => {
174
+ const { analyserNode: a, analyserArrayData: n } = this;
175
+ a.getByteFrequencyData(n);
138
176
  let r = 0;
139
177
  for (let i = 0; i < n.length; i++)
140
178
  r += n[i];
141
179
  return Math.ceil(r / n.length);
142
- }), y(this, "mixAudio", (u, n = "bgm") => new Promise(async (r, i) => {
180
+ }), m(this, "mixAudio", (a, n = "bgm") => new Promise(async (r, i) => {
143
181
  try {
144
182
  {
145
183
  const s = this.mixAudioMap.get(n);
146
184
  s && s.stop();
147
185
  }
148
186
  const t = n === "bgs" ? this.bgsGainNode : this.bgmGainNode, e = this.audioContext.createBufferSource();
149
- this.mixAudioMap.set(n, e), e.buffer = u, e.connect(t), e.onended = () => {
187
+ this.mixAudioMap.set(n, e), e.buffer = a, e.connect(t), e.onended = () => {
150
188
  e.disconnect(t), this.mixAudioMap.delete(n), r(!0);
151
189
  }, e.start(0);
152
190
  } catch (t) {
153
191
  i(t);
154
192
  }
155
- })), y(this, "mixAudioStop", (u) => {
156
- const n = this.mixAudioMap.get(u);
193
+ })), m(this, "mixAudioStop", (a) => {
194
+ const n = this.mixAudioMap.get(a);
157
195
  n == null || n.stop();
158
- }), y(this, "changeMix", (u, n) => {
159
- const r = u === "bgs" ? this.bgsGainNode : this.bgmGainNode;
196
+ }), m(this, "changeMix", (a, n) => {
197
+ const r = a === "bgs" ? this.bgsGainNode : this.bgmGainNode;
160
198
  n ? r.connect(this.destinationNode) : r.disconnect(this.destinationNode);
161
- }), a && (this.audioContext = a), this.inputStream = o, this.sourceNode = this.audioContext.createMediaStreamSource(this.inputStream), this.inputGainNode = this.audioContext.createGain(), this.inputGainNode.gain.setValueAtTime(this.inputGain, this.audioContext.currentTime), this.enhanceGainNode = this.audioContext.createGain(), this.enhanceGainNode.gain.setValueAtTime(this.enhanceGain, this.audioContext.currentTime), this.bgsGainNode = this.audioContext.createGain(), this.bgsGainNode.gain.setValueAtTime(this.bgsGain, this.audioContext.currentTime), this.bgmGainNode = this.audioContext.createGain(), this.bgmGainNode.gain.setValueAtTime(this.bgmGain, this.audioContext.currentTime), this.analyserNode = this.audioContext.createAnalyser(), this.analyserNode.fftSize = 512, this.analyserArrayData = new Uint8Array(this.analyserNode.frequencyBinCount), this.outputGainNode = this.audioContext.createGain(), this.outputGainNode.gain.setValueAtTime(this.outputGain, this.audioContext.currentTime), this.destinationNode = this.audioContext.createMediaStreamDestination(), this.outputStream = this.destinationNode.stream;
199
+ }), u && (this.audioContext = u), this.inputStream = o, this.sourceNode = this.audioContext.createMediaStreamSource(this.inputStream), this.highPassNode = this.audioContext.createBiquadFilter(), this.highPassNode.type = "highpass", this.highPassNode.frequency.value = 100, this.lowPassNode = this.audioContext.createBiquadFilter(), this.lowPassNode.type = "lowpass", this.lowPassNode.frequency.value = 8e3, this.inputGainNode = this.audioContext.createGain(), this.inputGainNode.gain.setValueAtTime(this.inputGain, this.audioContext.currentTime), this.enhanceGainNode = this.audioContext.createGain(), this.enhanceGainNode.gain.setValueAtTime(this.enhanceGain, this.audioContext.currentTime), this.bgsGainNode = this.audioContext.createGain(), this.bgsGainNode.gain.setValueAtTime(this.bgsGain, this.audioContext.currentTime), this.bgmGainNode = this.audioContext.createGain(), this.bgmGainNode.gain.setValueAtTime(this.bgmGain, this.audioContext.currentTime), this.analyserNode = this.audioContext.createAnalyser(), this.analyserNode.fftSize = 512, this.analyserArrayData = new Uint8Array(this.analyserNode.frequencyBinCount), this.outputGainNode = this.audioContext.createGain(), this.outputGainNode.gain.setValueAtTime(this.outputGain, this.audioContext.currentTime), this.destinationNode = this.audioContext.createMediaStreamDestination(), this.outputStream = this.destinationNode.stream;
162
200
  {
163
- const { sourceNode: u, inputGainNode: n, enhanceGainNode: r, bgsGainNode: i, bgmGainNode: t, analyserNode: e, outputGainNode: s, destinationNode: l } = this;
164
- u.connect(n), n.connect(r), r.connect(e), i.connect(e), t.connect(e), r.connect(l), i.connect(l), t.connect(l), e.connect(s), s.connect(this.audioContext.destination);
201
+ const { sourceNode: a, highPassNode: n, lowPassNode: r, inputGainNode: i, enhanceGainNode: t, bgsGainNode: e, bgmGainNode: s, analyserNode: l, outputGainNode: c, destinationNode: d } = this;
202
+ a.connect(n), n.connect(r), r.connect(i), i.connect(t), t.connect(l), e.connect(l), s.connect(l), t.connect(d), e.connect(d), s.connect(d), l.connect(c), c.connect(this.audioContext.destination);
165
203
  }
166
204
  this.setMute(!0), this.audioContext.resume();
167
205
  }
168
206
  }
169
207
  const E = async (h, o) => {
170
208
  try {
171
- const { format: a, numberOfChannels: u, numberOfFrames: n, sampleRate: r } = o, i = h.createBuffer(u, n, r);
172
- for (let t = 0; t < u; t++) {
209
+ const { format: u, numberOfChannels: a, numberOfFrames: n, sampleRate: r } = o, i = h.createBuffer(a, n, r);
210
+ for (let t = 0; t < a; t++) {
173
211
  const e = o.allocationSize({ planeIndex: t }), s = new Uint8Array(e);
174
212
  o.copyTo(s, { planeIndex: t });
175
213
  const l = new DataView(s.buffer), c = i.getChannelData(t);
176
214
  for (let d = 0; d < n; d++) {
177
215
  let p;
178
- switch (a) {
216
+ switch (u) {
179
217
  case "s16":
180
218
  // 16-bit signed PCM (范围: -32768 ~ 32767)
181
219
  case "s16-planar":
@@ -192,101 +230,63 @@ const E = async (h, o) => {
192
230
  p = (l.getUint8(d) - 128) / 128;
193
231
  break;
194
232
  default:
195
- throw new Error(`Unsupported audio format: ${a}`);
233
+ throw new Error(`Unsupported audio format: ${u}`);
196
234
  }
197
235
  c[d] = Math.max(-1, Math.min(1, p));
198
236
  }
199
237
  }
200
238
  return i;
201
- } catch (a) {
202
- throw console.error("Failed to convert AudioData to AudioBuffer:", a), a;
239
+ } catch (u) {
240
+ throw console.error("Failed to convert AudioData to AudioBuffer:", u), u;
203
241
  }
204
242
  };
205
- class W {
243
+ class O {
206
244
  constructor() {
207
- m(this, "prAudioStream");
208
- m(this, "audioContext");
209
- m(this, "destination");
210
- m(this, "stream", new MediaStream());
211
- m(this, "nextStartTime", 0);
212
- m(this, "pendingSources", []);
213
- m(this, "init", (o) => {
214
- o || (o = new (window.AudioContext || window.webkitAudioContext)()), this.audioContext = o, this.destination = this.audioContext.createMediaStreamDestination(), this.stream = new MediaStream(), this.stream.addTrack(this.destination.stream.getAudioTracks()[0]), this.prAudioStream = new O(this.stream, this.audioContext), this.nextStartTime = 0, this.pendingSources = [];
245
+ y(this, "prAudioStream");
246
+ y(this, "audioContext");
247
+ y(this, "destination");
248
+ y(this, "stream", new MediaStream());
249
+ y(this, "nextStartTime", 0);
250
+ y(this, "pendingSources", []);
251
+ y(this, "init", (o) => {
252
+ o || (o = new (window.AudioContext || window.webkitAudioContext)()), this.audioContext = o, this.destination = this.audioContext.createMediaStreamDestination(), this.stream = new MediaStream(), this.stream.addTrack(this.destination.stream.getAudioTracks()[0]), this.prAudioStream = new W(this.stream, this.audioContext), this.nextStartTime = 0, this.pendingSources = [];
215
253
  });
216
- m(this, "getStream", () => {
254
+ y(this, "getStream", () => {
217
255
  var o;
218
256
  return (o = this.prAudioStream) == null ? void 0 : o.getStream();
219
257
  });
220
258
  }
221
259
  async push(o) {
222
- const { audioData: a, playbackRate: u = 1 } = o;
260
+ const { audioData: u, playbackRate: a = 1 } = o;
223
261
  if (!this.audioContext || !this.destination) return;
224
- let n = await E(this.audioContext, a);
225
- if (a.close(), !n) return;
262
+ let n = await E(this.audioContext, u);
263
+ if (u.close(), !n) return;
226
264
  const r = this.audioContext.createBufferSource();
227
- r.buffer = n, r.playbackRate.value = u;
228
- const i = -1200 * Math.log2(u);
265
+ r.buffer = n, r.playbackRate.value = a;
266
+ const i = -1200 * Math.log2(a);
229
267
  r.detune.value = i, r.connect(this.destination);
230
- const t = Math.max(this.nextStartTime, this.audioContext.currentTime), e = n.duration / u;
268
+ const t = Math.max(this.nextStartTime, this.audioContext.currentTime), e = n.duration / a;
231
269
  this.nextStartTime = t + e, r.start(t), this.pendingSources.push(r), r.onended = () => {
232
270
  this.pendingSources = this.pendingSources.filter((s) => s !== r);
233
271
  }, this.audioContext.state === "suspended" && await this.audioContext.resume();
234
272
  }
235
273
  destroy() {
236
- var o, a;
237
- (o = this.audioContext) == null || o.close(), this.audioContext = void 0, this.destination = void 0, this.nextStartTime = 0, (a = this.prAudioStream) == null || a.stop(), this.pendingSources.forEach((u) => u.stop()), this.pendingSources = [];
274
+ var o, u;
275
+ (o = this.audioContext) == null || o.close(), this.audioContext = void 0, this.destination = void 0, this.nextStartTime = 0, (u = this.prAudioStream) == null || u.stop(), this.pendingSources.forEach((a) => a.stop()), this.pendingSources = [];
238
276
  }
239
277
  }
240
- const R = `(function(){"use strict";class o{writable;writer;cutOption;pause=!1;constructor(){}init=({writable:t})=>{this.destroy(),this.writable=t,this.writer=this.writable.getWriter()};push=async t=>{if(this.pause)return;const{timestamp:s}=t;let{bitmap:i}=t;if(this.cutOption){const{sx:n=0,sy:c=0,sw:h=i.width,sh:u=i.height}=this.cutOption;i=await createImageBitmap(i,n,c,h,u)}const r=new VideoFrame(i,{timestamp:s});this.cutOption&&i.close(),this.writer.write(r),r.close()};setCut=t=>{this.cutOption=t};setPause=t=>{this.pause=t};destroy=()=>{this.writable=void 0,this.writer=void 0,this.cutOption=void 0}}const a=new o;onmessage=e=>{const{action:t,data:s}=e.data,i=a[t];i&&i(s)}})();
241
- `, v = typeof self < "u" && self.Blob && new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);", R], { type: "text/javascript;charset=utf-8" });
242
- function j(h) {
243
- let o;
244
- try {
245
- if (o = v && (self.URL || self.webkitURL).createObjectURL(v), !o) throw "";
246
- const a = new Worker(o, {
247
- name: h == null ? void 0 : h.name
248
- });
249
- return a.addEventListener("error", () => {
250
- (self.URL || self.webkitURL).revokeObjectURL(o);
251
- }), a;
252
- } catch {
253
- return new Worker(
254
- "data:text/javascript;charset=utf-8," + encodeURIComponent(R),
255
- {
256
- name: h == null ? void 0 : h.name
257
- }
258
- );
259
- }
260
- }
261
- class z {
262
- constructor() {
263
- m(this, "worker", new j());
264
- m(this, "init", ({ writable: o }) => this.worker.postMessage({ action: "init", data: { writable: o } }, [o]));
265
- m(this, "push", (o) => this.worker.postMessage({ action: "push", data: o }));
266
- m(this, "setCut", async (o) => this.worker.postMessage({ action: "setCut", data: o }));
267
- m(this, "setPause", (o) => this.worker.postMessage({ action: "setPause", data: o }));
268
- m(this, "destroy", () => {
269
- this.worker.postMessage({ action: "destroy", data: {} }), this.worker.terminate();
270
- });
271
- }
272
- }
273
- const q = (h) => {
278
+ const j = (h) => {
274
279
  const o = h.toLowerCase();
275
280
  return o.includes(".m3u8") || o.includes("hls") || o.includes("master.m3u8") || o.match(/index\d*\.m3u8/) ? "hls" : o.includes(".mpd") || o.includes("dash") ? "dash" : o.startsWith("rtmp://") || o.startsWith("rtmps://") ? "rtmp" : o.includes(".flv") || o.includes("flv") && !o.includes("flash") ? "flv" : "unknown";
276
- }, M = (h) => {
281
+ }, z = (h) => {
277
282
  const o = (h == null ? void 0 : h.getTracks()) || [];
278
- for (const a of o)
279
- a.stop();
280
- }, A = () => {
281
- const h = new MediaStreamTrackGenerator({ kind: "video" }), o = new MediaStream([h]), a = new z();
282
- return a.init({ writable: h.writable }), { worker: a, stream: o, destroy: () => {
283
- a.destroy(), M(o);
284
- } };
283
+ for (const u of o)
284
+ u.stop();
285
285
  };
286
- class $ {
286
+ class q {
287
287
  constructor() {
288
- m(this, "resolvesMap", /* @__PURE__ */ new Map());
289
- m(this, "index", 0);
288
+ y(this, "resolvesMap", /* @__PURE__ */ new Map());
289
+ y(this, "index", 0);
290
290
  /**
291
291
  *
292
292
  * @param eventKey 唯一key
@@ -294,126 +294,128 @@ class $ {
294
294
  * @param timeout 超时时间 ms
295
295
  * @returns
296
296
  */
297
- m(this, "add", (o, a = () => !1, u = 0) => new Promise((n) => {
297
+ y(this, "add", (o, u = () => !1, a = 0) => new Promise((n) => {
298
298
  var t, e;
299
- if (a()) return n(!0);
299
+ if (u()) return n(!0);
300
300
  this.resolvesMap.has(o) || this.resolvesMap.set(o, /* @__PURE__ */ new Map()), this.index++;
301
301
  const r = `${this.index}`;
302
- if (u = Math.max(0, u), u === 0) {
302
+ if (a = Math.max(0, a), a === 0) {
303
303
  (t = this.resolvesMap.get(o)) == null || t.set(r, { resolve: n, timer: 0 });
304
304
  return;
305
305
  }
306
306
  const i = window.setTimeout(() => {
307
307
  this.emit(o);
308
- }, u);
308
+ }, a);
309
309
  (e = this.resolvesMap.get(o)) == null || e.set(r, { resolve: n, timer: i });
310
310
  }));
311
- m(this, "emit", async (o) => {
312
- const a = this.resolvesMap.get(o);
313
- if (!a) return;
314
- const u = [...a.keys()];
315
- for (const n of u) {
316
- const r = a.get(n);
317
- r && (clearTimeout(r.timer), r.resolve(), a.delete(n));
311
+ y(this, "emit", async (o) => {
312
+ const u = this.resolvesMap.get(o);
313
+ if (!u) return;
314
+ const a = [...u.keys()];
315
+ for (const n of a) {
316
+ const r = u.get(n);
317
+ r && (clearTimeout(r.timer), r.resolve(), u.delete(n));
318
318
  }
319
319
  });
320
320
  }
321
321
  }
322
- const Y = (h) => {
322
+ const X = (h) => {
323
323
  const o = new DataView(h.buffer);
324
- let a = 0, u, n, r;
325
- u = o.getUint32(a, !1), a += 4;
324
+ let u = 0, a, n, r;
325
+ a = o.getUint32(u, !1), u += 4;
326
326
  {
327
- const i = o.getUint8(a), t = i >> 7 & 1, e = i >> 5 & 3, s = i & 31;
328
- n = { forbidden_zero_bit: t, nal_ref_idc: e, nal_unit_type: s }, a += 1;
327
+ const i = o.getUint8(u), t = i >> 7 & 1, e = i >> 5 & 3, s = i & 31;
328
+ n = { forbidden_zero_bit: t, nal_ref_idc: e, nal_unit_type: s }, u += 1;
329
329
  }
330
330
  {
331
- const i = u - 1;
332
- r = new Uint8Array(o.buffer.slice(a, a + i));
331
+ const i = a - 1;
332
+ r = new Uint8Array(o.buffer.slice(u, u + i));
333
333
  }
334
- return { size: u, header: n, data: r };
334
+ return { size: a, header: n, data: r };
335
335
  };
336
- var P, U;
337
- class x {
336
+ var P, U, J;
337
+ class A {
338
+ // 实例变量:统一管理当前请求的中止
338
339
  constructor(o = {}) {
339
- J(this, P, {
340
- timeout: 5 * 1e3
340
+ K(this, P, {
341
+ timeout: 5 * 1e3,
342
+ check: !1
341
343
  });
342
- J(this, U);
344
+ K(this, U, null);
343
345
  /**
344
- *
345
- * @param input string | URL | Request
346
- * @param init RequestInit
346
+ * 检查资源可用性(HEAD 请求)—— 用实例变量控制器
347
347
  */
348
- m(this, "check", (o, a) => new Promise(async (u, n) => {
349
- var i;
350
- this.stop(), H(this, U, new AbortController());
351
- const r = window.setTimeout(() => {
348
+ K(this, J, (o, u) => new Promise(async (a) => {
349
+ H(this, U, new AbortController());
350
+ const { signal: n } = S(this, U), r = S(this, P).timeout, i = setTimeout(() => {
352
351
  var t;
353
- (t = I(this, U)) == null || t.abort("Timeout."), n({ status: "timeout", reason: "" });
354
- }, I(this, P).timeout);
355
- try {
356
- const t = await fetch(o, { ...a, method: "HEAD", signal: (i = I(this, U)) == null ? void 0 : i.signal });
357
- t.status === 200 ? u({ status: "successed", reason: "" }) : n({ status: "failed", reason: `${t.status}` });
358
- } catch (t) {
359
- n({ status: "error", reason: t.message });
360
- }
361
- clearTimeout(r);
352
+ (t = S(this, U)) == null || t.abort(`Timeout (${r}ms)`);
353
+ }, r);
354
+ await fetch(o, { cache: "no-store", ...u, method: "HEAD", signal: n }).then((t) => {
355
+ clearTimeout(i), a({ status: t.status === 200 ? "successed" : "failed", reason: t.status === 200 ? "" : `HTTP ${t.status}` });
356
+ }).catch((t) => {
357
+ if (clearTimeout(i), t.name === "AbortError") {
358
+ const e = n.reason || "Actively stopped";
359
+ a({
360
+ status: e.includes("Timeout") ? "timeout" : "stopped",
361
+ reason: e
362
+ });
363
+ } else
364
+ a({ status: "error", reason: t.message });
365
+ });
362
366
  }));
363
367
  /**
364
- *
365
- * @param input string | URL | Request
366
- * @param init RequestInit
368
+ * 发起数据请求(GET/POST 等)—— 用实例变量控制器
367
369
  */
368
- m(this, "request", async (o, a) => new Promise(async (u, n) => {
369
- var r;
370
+ y(this, "request", (o, u) => new Promise(async (a, n) => {
370
371
  try {
371
- await this.check(o, a), H(this, U, new AbortController());
372
- const i = await fetch(o, { ...a, signal: (r = I(this, U)) == null ? void 0 : r.signal });
373
- u(i);
374
- } catch (i) {
375
- this.stop(), n(i);
372
+ this.stop(), S(this, P).check && await S(this, J).call(this, o), H(this, U, new AbortController());
373
+ const { signal: r } = S(this, U), i = await fetch(o, { cache: "no-store", ...u, signal: r });
374
+ a(i);
375
+ } catch (r) {
376
+ n(r);
376
377
  }
377
378
  }));
378
- /**
379
- * stop
380
- */
381
- m(this, "stop", () => {
379
+ y(this, "stop", () => {
382
380
  var o;
383
- ((o = I(this, U)) == null ? void 0 : o.signal.aborted) === !1 && I(this, U).abort("Actively stop.");
381
+ if (((o = S(this, U)) == null ? void 0 : o.signal.aborted) === !1) {
382
+ const u = new Error("Actively stopped.");
383
+ u.name = "AbortError", S(this, U).abort(u);
384
+ }
384
385
  });
385
- H(this, P, { ...I(this, P), ...o });
386
+ H(this, P, { ...S(this, P), ...o });
386
387
  }
387
388
  }
388
- P = new WeakMap(), U = new WeakMap();
389
- class et {
389
+ P = new WeakMap(), U = new WeakMap(), J = new WeakMap();
390
+ class tt {
390
391
  constructor(o = {}) {
391
- m(this, "option", {
392
+ y(this, "option", {
392
393
  debug: !1,
393
394
  frameTrack: !1
394
395
  });
395
- m(this, "prFetch", new x());
396
- m(this, "getSegmentsFetch", new x());
397
- m(this, "prResolves", new $());
398
- m(this, "url", "");
399
- m(this, "demuxerWorker");
400
- m(this, "decoderWorker");
401
- m(this, "audioPlayer");
402
- m(this, "renderWorker");
403
- m(this, "stream");
404
- m(this, "on", { demuxer: {}, decoder: {} });
405
- m(this, "cutRenders", /* @__PURE__ */ new Map());
396
+ y(this, "prFetch", new A());
397
+ y(this, "getSegmentsFetch", new A());
398
+ y(this, "prResolves", new q());
399
+ y(this, "url", "");
400
+ y(this, "start_resolve");
401
+ y(this, "demuxerWorker");
402
+ y(this, "decoderWorker");
403
+ y(this, "audioPlayer");
404
+ y(this, "renderWorker");
405
+ y(this, "stream");
406
+ y(this, "on", { demuxer: {}, decoder: {} });
407
+ y(this, "cutRenders", /* @__PURE__ */ new Map());
406
408
  // @ts-ignore
407
- m(this, "trackGenerator");
409
+ y(this, "trackGenerator");
408
410
  /**
409
411
  * 开始播放
410
412
  * @param url : string
411
413
  */
412
- m(this, "start", async (o) => {
414
+ y(this, "start", async (o) => {
413
415
  await this.stop(), this.url = o;
414
- const a = q(o);
415
- if (a === "unknown") throw new Error("This address cannot be parsed.");
416
- switch (this.init(a), a) {
416
+ const u = j(o);
417
+ if (u === "unknown") throw new Error("This address cannot be parsed.");
418
+ switch (this.init(u), u) {
417
419
  case "flv":
418
420
  this.flv.start();
419
421
  break;
@@ -425,134 +427,146 @@ class et {
425
427
  /**
426
428
  * 停止
427
429
  */
428
- m(this, "stop", async () => {
429
- var a, u, n, r, i;
430
+ y(this, "stop", async () => {
431
+ var o, u, a, n;
430
432
  try {
431
433
  this.url = "", clearInterval(this.hls.getSegmentsTimer), this.prFetch.stop(), this.getSegmentsFetch.stop();
432
- } catch (t) {
433
- console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m", "color:#0097ff;", "------->pr-player: error", t);
434
+ } catch (r) {
435
+ console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m", "color:#0097ff;", "------->pr-player: error", r);
434
436
  }
435
- (a = this.demuxerWorker) == null || a.destroy(), (u = this.decoderWorker) == null || u.destroy(), (n = this.renderWorker) == null || n.destroy();
436
- const o = [...this.cutRenders.keys()];
437
- for (const t of o)
438
- (r = this.cutRenders.get(t)) == null || r.worker.destroy(), this.cutRenders.delete(t);
439
- M(this.stream), (i = this.audioPlayer) == null || i.destroy();
437
+ (o = this.demuxerWorker) == null || o.destroy(), (u = this.decoderWorker) == null || u.destroy(), (a = this.renderWorker) == null || a.destroy(), this.cutRenders = /* @__PURE__ */ new Map(), z(this.stream), (n = this.audioPlayer) == null || n.destroy();
440
438
  });
441
439
  /**
442
440
  * 获取媒体流
443
441
  */
444
- m(this, "getStream", () => this.stream);
442
+ y(this, "getStream", () => this.stream);
445
443
  /**
446
444
  * 设置暂停
447
445
  * @param pause: boolean
448
446
  */
449
- m(this, "setPause", (o) => {
450
- var a;
451
- (a = this.renderWorker) == null || a.setPause(o);
447
+ y(this, "setPause", (o) => {
448
+ var u;
449
+ (u = this.renderWorker) == null || u.setPause({ pause: o });
452
450
  });
453
451
  /**
454
452
  * 是否静音 默认为true
455
453
  * @param state?: boolean
456
454
  */
457
- m(this, "setMute", (o) => {
458
- var a, u;
459
- return (u = (a = this.audioPlayer) == null ? void 0 : a.prAudioStream) == null ? void 0 : u.setMute(o);
455
+ y(this, "setMute", (o) => {
456
+ var u, a;
457
+ return (a = (u = this.audioPlayer) == null ? void 0 : u.prAudioStream) == null ? void 0 : a.setMute(o);
458
+ });
459
+ /**
460
+ * 设置输出音量
461
+ * @param gain
462
+ */
463
+ y(this, "setOutputGain", (o) => {
464
+ var u, a;
465
+ (a = (u = this.audioPlayer) == null ? void 0 : u.prAudioStream) == null || a.setOutputGain(o);
460
466
  });
461
467
  /**
462
468
  * 是否开启追帧
463
469
  * @param frameTrack?: boolean
464
470
  */
465
- m(this, "setFrameTrack", (o) => {
466
- var a;
467
- this.option.frameTrack = o, (a = this.decoderWorker) == null || a.setFrameTrack(o);
471
+ y(this, "setFrameTrack", (o) => {
472
+ var u;
473
+ this.option.frameTrack = o, (u = this.decoderWorker) == null || u.setFrameTrack(o);
468
474
  });
469
475
  /**
470
476
  * 是否已准备好
471
477
  */
472
- m(this, "isReady", () => {
478
+ y(this, "isReady", () => {
473
479
  const o = () => {
474
- var a;
475
- return ((a = this.stream) == null ? void 0 : a.active) === !0;
480
+ var u;
481
+ return ((u = this.stream) == null ? void 0 : u.active) === !0;
476
482
  };
477
483
  return this.prResolves.add("isReady", o);
478
484
  });
479
- m(this, "cut", {
485
+ y(this, "cut", {
480
486
  /**
481
487
  * 创建剪切
482
488
  */
483
- create: (o, a) => {
484
- let u = this.cutRenders.get(o);
485
- return u ? (u.worker.setCut(a), u.worker.setPause(!1), u) : (u = A(), u.worker.setCut(a), this.cutRenders.set(o, u), u);
489
+ create: (o, u) => {
490
+ var r;
491
+ const a = new MediaStreamTrackGenerator({ kind: "video" }), n = new MediaStream([a]);
492
+ return (r = this.renderWorker) == null || r.addCut({ key: o, writable: a.writable, option: u }), this.cutRenders.set(o, { stream: n }), n;
486
493
  },
487
494
  /**
488
- * 获取媒体流
495
+ * 设置剪切
489
496
  */
490
- getStream: (o) => {
497
+ setCut: (o, u) => {
491
498
  var a;
492
- return (a = this.cutRenders.get(o)) == null ? void 0 : a.stream;
499
+ (a = this.renderWorker) == null || a.setCut({ key: o, cutOption: u });
493
500
  },
494
501
  /**
495
- * 设置暂停
496
- * @param pause: boolean
502
+ * 获取媒体流
497
503
  */
498
- setPause: (o, a) => {
504
+ getStream: (o) => {
499
505
  var u;
500
- (u = this.cutRenders.get(o)) == null || u.worker.setPause(a);
506
+ return (u = this.cutRenders.get(o)) == null ? void 0 : u.stream;
501
507
  },
502
508
  /**
503
509
  * 移除剪切
504
510
  */
505
511
  remove: (o) => {
512
+ var u;
513
+ (u = this.renderWorker) == null || u.delCut(o), this.cutRenders.delete(o);
514
+ },
515
+ /**
516
+ * 设置暂停
517
+ * @param pause: boolean
518
+ */
519
+ setPause: (o, u) => {
506
520
  var a;
507
- (a = this.cutRenders.get(o)) == null || a.destroy(), this.cutRenders.delete(o);
521
+ (a = this.renderWorker) == null || a.setPause({ key: o, pause: u });
508
522
  }
509
523
  });
510
524
  /**
511
525
  * 初始化
512
526
  */
513
- m(this, "init", (o) => {
514
- this.initDecoder(o), this.initRender(), this.initDemuxer(o), this.audioPlayer = new W(), this.audioPlayer.init();
527
+ y(this, "init", (o) => {
528
+ this.initDecoder(o), this.initRender(), this.initDemuxer(o), this.audioPlayer = new O(), this.audioPlayer.init();
515
529
  });
516
530
  /**
517
531
  * 初始化解复器
518
532
  */
519
- m(this, "initDemuxer", (o) => {
520
- this.demuxerWorker = new V(), this.demuxerWorker.init(o), this.demuxerWorker.on.debug = (a) => {
521
- this.option.debug && this.on.debug && this.on.debug(a);
522
- }, this.demuxerWorker.on.info = (a) => {
523
- this.option.debug && console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m", "color:#0097ff;", "------->pr-player: info", a), this.on.demuxer.info && this.on.demuxer.info(a);
524
- }, this.demuxerWorker.on.config = (a) => {
533
+ y(this, "initDemuxer", (o) => {
534
+ this.demuxerWorker = new I(), this.demuxerWorker.init(o), this.demuxerWorker.on.debug = (u) => {
535
+ this.option.debug && this.on.debug && this.on.debug(u);
536
+ }, this.demuxerWorker.on.info = (u) => {
537
+ this.option.debug && console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m", "color:#0097ff;", "------->pr-player: info", u), this.on.demuxer.info && this.on.demuxer.info(u);
538
+ }, this.demuxerWorker.on.config = (u) => {
525
539
  var n, r;
526
- this.option.debug && console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m", "color:#0097ff;", "------->pr-player: config", a), this.on.demuxer.config && this.on.demuxer.config(a);
527
- const { kind: u } = a;
528
- switch (u) {
540
+ this.option.debug && console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m", "color:#0097ff;", "------->pr-player: config", u), this.on.demuxer.config && this.on.demuxer.config(u);
541
+ const { kind: a } = u;
542
+ switch (a) {
529
543
  case "audio":
530
544
  {
531
- const { codec: i, sampleRate: t, numberOfChannels: e } = a;
545
+ const { codec: i, sampleRate: t, numberOfChannels: e } = u;
532
546
  (n = this.decoderWorker) == null || n.initAudio({ codec: i, sampleRate: t, numberOfChannels: e });
533
547
  }
534
548
  break;
535
549
  case "video":
536
550
  {
537
- const { codec: i, description: t } = a;
551
+ const { codec: i, description: t } = u;
538
552
  (r = this.decoderWorker) == null || r.initVideo({ codec: i, description: t });
539
553
  }
540
554
  break;
541
555
  }
542
- }, this.demuxerWorker.on.chunk = (a) => {
543
- if (this.on.demuxer.chunk && this.on.demuxer.chunk(a), !this.decoderWorker) return;
544
- const { kind: u } = a;
545
- switch (u) {
556
+ }, this.demuxerWorker.on.chunk = (u) => {
557
+ if (this.on.demuxer.chunk && this.on.demuxer.chunk(u), !this.decoderWorker) return;
558
+ const { kind: a } = u;
559
+ switch (a) {
546
560
  case "audio":
547
561
  {
548
- const { type: n, dts: r, data: i } = a, t = r * 1e3;
549
- this.decoderWorker.push({ kind: u, init: { type: n, timestamp: t, data: i } });
562
+ const { type: n, dts: r, data: i } = u, t = r * 1e3;
563
+ this.decoderWorker.push({ kind: a, init: { type: n, timestamp: t, data: i } });
550
564
  }
551
565
  break;
552
566
  case "video":
553
567
  {
554
- const { type: n, dts: r, data: i, nalus: t = [] } = a, e = r * 1e3;
555
- this.decoderWorker.push({ kind: u, init: { type: n, timestamp: e, data: i }, nalus: t });
568
+ const { type: n, dts: r, data: i, nalus: t = [] } = u, e = r * 1e3;
569
+ this.decoderWorker.push({ kind: a, init: { type: n, timestamp: e, data: i }, nalus: t });
556
570
  }
557
571
  break;
558
572
  }
@@ -561,132 +575,150 @@ class et {
561
575
  /**
562
576
  * 初始化解码器
563
577
  */
564
- m(this, "initDecoder", (o) => {
565
- this.decoderWorker = new N(), this.decoderWorker.init(o);
566
- const { frameTrack: a = !1 } = this.option;
567
- this.decoderWorker.setFrameTrack(a), this.decoderWorker.on.audio.decode = (u) => {
578
+ y(this, "initDecoder", (o) => {
579
+ this.decoderWorker = new L(), this.decoderWorker.init(o);
580
+ const { frameTrack: u = !1 } = this.option;
581
+ this.decoderWorker.setFrameTrack(u), this.decoderWorker.on.audio.decode = (a) => {
568
582
  var n;
569
- (n = this.audioPlayer) == null || n.push(u), this.on.decoder.audio && this.on.decoder.audio(u);
570
- }, this.decoderWorker.on.audio.error = (u) => {
571
- this.option.debug && console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m", "color:#0097ff;", "------->pr-player: audio.error ", u), this.on.error && this.on.error(u);
572
- }, this.decoderWorker.on.video.decode = async (u) => {
573
- var r, i;
574
- (r = this.renderWorker) == null || r.push(u);
575
- const n = [...this.cutRenders.keys()];
576
- for (const t of n)
577
- (i = this.cutRenders.get(t)) == null || i.worker.push(u);
578
- this.on.decoder.video && this.on.decoder.video(u), u.bitmap.close();
579
- }, this.decoderWorker.on.video.error = (u) => {
580
- this.on.error && this.on.error(u);
581
- }, this.decoderWorker.on.nalus = async (u) => {
582
- for (const n of u) {
583
+ (n = this.audioPlayer) == null || n.push(a), this.on.decoder.audio && this.on.decoder.audio(a);
584
+ }, this.decoderWorker.on.audio.error = (a) => {
585
+ this.option.debug && console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m", "color:#0097ff;", "------->pr-player: audio.error ", a), this.on.error && this.on.error(a);
586
+ }, this.decoderWorker.on.video.decode = async (a) => {
587
+ var n;
588
+ this.start_resolve && (this.start_resolve(!0), this.start_resolve = void 0), (n = this.renderWorker) == null || n.push(a), this.on.decoder.video && this.on.decoder.video(a);
589
+ }, this.decoderWorker.on.video.error = (a) => {
590
+ this.on.error && this.on.error(a);
591
+ }, this.decoderWorker.on.nalus = async (a) => {
592
+ for (const n of a) {
583
593
  if (n.byteLength <= 4) continue;
584
- const { header: r, data: i } = Y(n), { nal_unit_type: t } = r;
594
+ const { header: r, data: i } = X(n), { nal_unit_type: t } = r;
585
595
  t === 6 && this.on.decoder.sei && this.on.decoder.sei(i);
586
596
  }
587
- }, this.decoderWorker.on.analysis = (u) => {
588
- this.on.decoder.analysis && this.on.decoder.analysis(u);
597
+ }, this.decoderWorker.on.analysis = (a) => {
598
+ this.on.decoder.analysis && this.on.decoder.analysis(a);
589
599
  };
590
600
  });
591
601
  /**
592
602
  * 初始化渲染器
593
603
  */
594
- m(this, "initRender", () => {
595
- const { worker: o, stream: a } = A();
596
- this.renderWorker = o, this.stream = a, this.renderWorker.setPause(!1);
604
+ y(this, "initRender", () => {
605
+ var a, n;
606
+ this.renderWorker = new F();
607
+ const o = new MediaStreamTrackGenerator({ kind: "video" }), u = new MediaStream([o]);
608
+ (a = this.renderWorker) == null || a.addCut({ writable: o.writable }), this.stream = u, (n = this.renderWorker) == null || n.setPause({ pause: !1 });
597
609
  });
598
- m(this, "flv", {
599
- start: async () => {
600
- var o, a;
610
+ y(this, "flv", {
611
+ start: () => new Promise(async (o, u) => {
612
+ var a, n;
601
613
  try {
602
- let u = await this.prFetch.request(this.url);
603
- if (u.status !== 200 && (await new Promise((r) => setTimeout(() => r(!0), 500)), u = await this.prFetch.request(this.url)), u.status !== 200 && (await new Promise((r) => setTimeout(() => r(!0), 500)), u = await this.prFetch.request(this.url)), u.status !== 200) throw new Error("request is error.");
604
- const n = (o = u.body) == null ? void 0 : o.getReader();
605
- if (!n) throw new Error("reader is error.");
614
+ this.start_resolve = o;
615
+ let r, i = 0;
606
616
  for (; ; ) {
607
- const { done: r, value: i } = await n.read();
608
- if (i && ((a = this.demuxerWorker) == null || a.push(i)), r || this.url === "") break;
617
+ i += 1;
618
+ try {
619
+ r = await this.prFetch.request(this.url);
620
+ } catch (e) {
621
+ console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m", "color:#0097ff;", "------->Breathe: error", e);
622
+ }
623
+ if ((r == null ? void 0 : r.status) === 200 || i === 3) break;
624
+ await new Promise((e) => setTimeout(() => e(!0), 500));
609
625
  }
610
- } catch (u) {
611
- if ((u == null ? void 0 : u.name) !== "AbortError") throw Error(u);
612
- this.on.error && this.on.error(u);
626
+ if (!r || r.status !== 200) return u("request is error.");
627
+ const t = (a = r.body) == null ? void 0 : a.getReader();
628
+ if (!t) return u("reader is error.");
629
+ for (; ; ) {
630
+ const { done: e, value: s } = await t.read();
631
+ if (s && ((n = this.demuxerWorker) == null || n.push(s)), e || this.url === "") break;
632
+ }
633
+ } catch (r) {
634
+ r.name !== "AbortError" && u(r);
613
635
  }
614
- }
636
+ })
615
637
  });
616
- m(this, "hls", {
638
+ y(this, "hls", {
617
639
  isLive: !1,
618
640
  urls: [],
619
641
  url: "",
620
642
  getSegmentsTimer: 0,
621
643
  parse: async (o) => {
622
- const a = new TextDecoder("utf-8").decode(o).split(`
623
- `).map((e) => e.replace("\r", "")), u = this.url.substring(0, this.url.lastIndexOf("/") + 1);
644
+ const u = new TextDecoder("utf-8").decode(o).split(`
645
+ `).map((e) => e.replace("\r", "")), a = this.url.substring(0, this.url.lastIndexOf("/") + 1);
624
646
  let n = 4, r = 0, i = !1;
625
647
  const t = [];
626
- for (const e of a)
648
+ for (const e of u)
627
649
  e.startsWith("#EXTINF:") ? n = parseFloat(e.split(":")[1].split(",")[0]) : e.startsWith("#EXT-X-TARGETDURATION:") ? r = parseInt(e.split(":")[1]) : e.startsWith("#EXT-X-ENDLIST") ? i = !1 : e.startsWith("#EXT-X-MEDIA-SEQUENCE:") ? i = !0 : e.includes(".ts") && !e.startsWith("#") && t.push({
628
- url: e.startsWith("http") ? e : u + e,
650
+ url: e.startsWith("http") ? e : a + e,
629
651
  duration: n,
630
652
  isLive: i
631
653
  });
632
- return { baseUrl: u, targetDuration: r, isLive: i, segments: t };
654
+ return { baseUrl: a, targetDuration: r, isLive: i, segments: t };
633
655
  },
634
656
  getSegments: async () => {
635
657
  var o;
636
658
  try {
637
- let a = await this.getSegmentsFetch.request(this.url);
638
- if (a.status !== 200 && (await new Promise((n) => setTimeout(() => n(!0), 500)), a = await this.getSegmentsFetch.request(this.url)), a.status !== 200 && (await new Promise((n) => setTimeout(() => n(!0), 500)), a = await this.getSegmentsFetch.request(this.url)), a.status !== 200) throw new Error("request is error.");
639
- const u = (o = a.body) == null ? void 0 : o.getReader();
640
- if (!u) throw new Error("reader is error.");
659
+ let u, a = 0;
660
+ for (; ; ) {
661
+ a += 1;
662
+ try {
663
+ u = await this.getSegmentsFetch.request(this.url);
664
+ } catch (r) {
665
+ console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m", "color:#0097ff;", "------->Breathe: error", r);
666
+ }
667
+ if ((u == null ? void 0 : u.status) === 200 || a === 3) break;
668
+ await new Promise((r) => setTimeout(() => r(!0), 500));
669
+ }
670
+ if (!u || u.status !== 200) throw new Error("request is error.");
671
+ const n = (o = u.body) == null ? void 0 : o.getReader();
672
+ if (!n) throw new Error("reader is error.");
641
673
  for (; ; ) {
642
- const { done: n, value: r } = await u.read();
643
- if (r) {
644
- const i = await this.hls.parse(r), { segments: t = [], isLive: e = !1 } = i;
645
- this.hls.isLive = e, e === !1 && (this.option.frameTrack = !1);
646
- let s = Array.from(t, (c) => c.url);
647
- const l = s.findIndex((c) => c === this.hls.url);
648
- l !== -1 && (s = s.slice(l + 1)), this.hls.urls = s;
674
+ const { done: r, value: i } = await n.read();
675
+ if (i) {
676
+ const t = await this.hls.parse(i), { segments: e = [], isLive: s = !1 } = t;
677
+ this.hls.isLive = s, s === !1 && (this.option.frameTrack = !1);
678
+ let l = Array.from(e, (d) => d.url);
679
+ const c = l.findIndex((d) => d === this.hls.url);
680
+ c !== -1 && (l = l.slice(c + 1)), this.hls.urls = l;
649
681
  }
650
- if (n || this.url === "") break;
682
+ if (r || this.url === "") break;
651
683
  }
652
- } catch (a) {
653
- this.on.error && this.on.error(a);
684
+ } catch (u) {
685
+ u.name !== "AbortError" && this.on.error && this.on.error(u);
654
686
  }
655
687
  },
656
- start: async () => {
657
- var o, a, u;
688
+ start: () => new Promise(async (o, u) => {
689
+ var a, n, r;
658
690
  try {
659
- for (await this.hls.getSegments(), this.hls.getSegmentsTimer = window.setInterval(this.hls.getSegments, 500), this.hls.isLive === !1 && (clearInterval(this.hls.getSegmentsTimer), (o = this.decoderWorker) == null ? void 0 : o.setFrameTrack(!1)); ; ) {
660
- const n = this.hls.urls.shift();
661
- if (n) {
662
- this.hls.url = n;
663
- const r = (a = (await this.prFetch.request(n)).body) == null ? void 0 : a.getReader();
664
- if (!r) throw new Error("segment reader is error.");
691
+ for (this.start_resolve = o, this.hls.url = "", this.hls.urls = [], await this.hls.getSegments(), this.hls.getSegmentsTimer = window.setInterval(this.hls.getSegments, 500), this.hls.isLive === !1 && (clearInterval(this.hls.getSegmentsTimer), (a = this.decoderWorker) == null ? void 0 : a.setFrameTrack(!1)); ; ) {
692
+ const i = this.hls.urls.shift();
693
+ if (i) {
694
+ this.hls.url = i;
695
+ const t = (n = (await this.prFetch.request(i)).body) == null ? void 0 : n.getReader();
696
+ if (!t) throw new Error("segment reader is error.");
665
697
  for (; ; ) {
666
- const { done: i, value: t } = await r.read();
667
- if (t && ((u = this.demuxerWorker) == null || u.push(t)), i || this.url === "") break;
698
+ const { done: e, value: s } = await t.read();
699
+ if (s && ((r = this.demuxerWorker) == null || r.push(s)), e || this.url === "") break;
668
700
  }
669
701
  } else
670
- await new Promise((r) => setTimeout(() => r(!0), 300));
702
+ await new Promise((t) => setTimeout(() => t(!0), 300));
671
703
  }
672
- } catch (n) {
673
- if ((n == null ? void 0 : n.name) !== "AbortError") throw Error(n);
704
+ } catch (i) {
705
+ i.name !== "AbortError" && u(i);
674
706
  }
675
- }
707
+ })
676
708
  });
677
- const { debug: a = !1 } = o;
678
- this.option.debug = a;
709
+ const { debug: u = !1 } = o;
710
+ this.option.debug = u;
679
711
  }
680
712
  }
681
713
  var commonjsGlobal = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}, indexMinimal = {}, minimal$1 = {}, aspromise, hasRequiredAspromise;
682
714
  function requireAspromise() {
683
715
  if (hasRequiredAspromise) return aspromise;
684
716
  hasRequiredAspromise = 1, aspromise = h;
685
- function h(o, a) {
686
- for (var u = new Array(arguments.length - 1), n = 0, r = 2, i = !0; r < arguments.length; )
687
- u[n++] = arguments[r++];
717
+ function h(o, u) {
718
+ for (var a = new Array(arguments.length - 1), n = 0, r = 2, i = !0; r < arguments.length; )
719
+ a[n++] = arguments[r++];
688
720
  return new Promise(function(e, s) {
689
- u[n] = function(c) {
721
+ a[n] = function(c) {
690
722
  if (i)
691
723
  if (i = !1, c)
692
724
  s(c);
@@ -697,7 +729,7 @@ function requireAspromise() {
697
729
  }
698
730
  };
699
731
  try {
700
- o.apply(a || null, u);
732
+ o.apply(u || null, a);
701
733
  } catch (l) {
702
734
  i && (i = !1, s(l));
703
735
  }
@@ -717,25 +749,25 @@ function requireBase64() {
717
749
  ++s;
718
750
  return Math.ceil(t.length * 3) / 4 - s;
719
751
  };
720
- for (var a = new Array(64), u = new Array(123), n = 0; n < 64; )
721
- u[a[n] = n < 26 ? n + 65 : n < 52 ? n + 71 : n < 62 ? n - 4 : n - 59 | 43] = n++;
752
+ for (var u = new Array(64), a = new Array(123), n = 0; n < 64; )
753
+ a[u[n] = n < 26 ? n + 65 : n < 52 ? n + 71 : n < 62 ? n - 4 : n - 59 | 43] = n++;
722
754
  o.encode = function(t, e, s) {
723
755
  for (var l = null, c = [], d = 0, p = 0, f; e < s; ) {
724
756
  var w = t[e++];
725
757
  switch (p) {
726
758
  case 0:
727
- c[d++] = a[w >> 2], f = (w & 3) << 4, p = 1;
759
+ c[d++] = u[w >> 2], f = (w & 3) << 4, p = 1;
728
760
  break;
729
761
  case 1:
730
- c[d++] = a[f | w >> 4], f = (w & 15) << 2, p = 2;
762
+ c[d++] = u[f | w >> 4], f = (w & 15) << 2, p = 2;
731
763
  break;
732
764
  case 2:
733
- c[d++] = a[f | w >> 6], c[d++] = a[w & 63], p = 0;
765
+ c[d++] = u[f | w >> 6], c[d++] = u[w & 63], p = 0;
734
766
  break;
735
767
  }
736
768
  d > 8191 && ((l || (l = [])).push(String.fromCharCode.apply(String, c)), d = 0);
737
769
  }
738
- return p && (c[d++] = a[f], c[d++] = 61, p === 1 && (c[d++] = 61)), l ? (d && l.push(String.fromCharCode.apply(String, c.slice(0, d))), l.join("")) : String.fromCharCode.apply(String, c.slice(0, d));
770
+ return p && (c[d++] = u[f], c[d++] = 61, p === 1 && (c[d++] = 61)), l ? (d && l.push(String.fromCharCode.apply(String, c.slice(0, d))), l.join("")) : String.fromCharCode.apply(String, c.slice(0, d));
739
771
  };
740
772
  var r = "invalid encoding";
741
773
  o.decode = function(t, e, s) {
@@ -743,7 +775,7 @@ function requireBase64() {
743
775
  var f = t.charCodeAt(p++);
744
776
  if (f === 61 && c > 1)
745
777
  break;
746
- if ((f = u[f]) === void 0)
778
+ if ((f = a[f]) === void 0)
747
779
  throw Error(r);
748
780
  switch (c) {
749
781
  case 0:
@@ -775,27 +807,27 @@ function requireEventemitter() {
775
807
  function h() {
776
808
  this._listeners = {};
777
809
  }
778
- return h.prototype.on = function(a, u, n) {
779
- return (this._listeners[a] || (this._listeners[a] = [])).push({
780
- fn: u,
810
+ return h.prototype.on = function(u, a, n) {
811
+ return (this._listeners[u] || (this._listeners[u] = [])).push({
812
+ fn: a,
781
813
  ctx: n || this
782
814
  }), this;
783
- }, h.prototype.off = function(a, u) {
784
- if (a === void 0)
815
+ }, h.prototype.off = function(u, a) {
816
+ if (u === void 0)
785
817
  this._listeners = {};
786
- else if (u === void 0)
787
- this._listeners[a] = [];
818
+ else if (a === void 0)
819
+ this._listeners[u] = [];
788
820
  else
789
- for (var n = this._listeners[a], r = 0; r < n.length; )
790
- n[r].fn === u ? n.splice(r, 1) : ++r;
821
+ for (var n = this._listeners[u], r = 0; r < n.length; )
822
+ n[r].fn === a ? n.splice(r, 1) : ++r;
791
823
  return this;
792
- }, h.prototype.emit = function(a) {
793
- var u = this._listeners[a];
794
- if (u) {
824
+ }, h.prototype.emit = function(u) {
825
+ var a = this._listeners[u];
826
+ if (a) {
795
827
  for (var n = [], r = 1; r < arguments.length; )
796
828
  n.push(arguments[r++]);
797
- for (r = 0; r < u.length; )
798
- u[r].fn.apply(u[r++].ctx, n);
829
+ for (r = 0; r < a.length; )
830
+ a[r].fn.apply(a[r++].ctx, n);
799
831
  }
800
832
  return this;
801
833
  }, eventemitter;
@@ -843,12 +875,12 @@ function requireFloat() {
843
875
  e((d << 31 | p + 127 << 23 | f) >>> 0, l, c);
844
876
  }
845
877
  }
846
- r.writeFloatLE = i.bind(null, o), r.writeFloatBE = i.bind(null, a);
878
+ r.writeFloatLE = i.bind(null, o), r.writeFloatBE = i.bind(null, u);
847
879
  function t(e, s, l) {
848
880
  var c = e(s, l), d = (c >> 31) * 2 + 1, p = c >>> 23 & 255, f = c & 8388607;
849
881
  return p === 255 ? f ? NaN : d * (1 / 0) : p === 0 ? d * 1401298464324817e-60 * f : d * Math.pow(2, p - 150) * (f + 8388608);
850
882
  }
851
- r.readFloatLE = t.bind(null, u), r.readFloatBE = t.bind(null, n);
883
+ r.readFloatLE = t.bind(null, a), r.readFloatBE = t.bind(null, n);
852
884
  }(), typeof Float64Array < "u" ? function() {
853
885
  var i = new Float64Array([-0]), t = new Uint8Array(i.buffer), e = t[7] === 128;
854
886
  function s(p, f, w) {
@@ -890,21 +922,21 @@ function requireFloat() {
890
922
  }
891
923
  }
892
924
  }
893
- r.writeDoubleLE = i.bind(null, o, 0, 4), r.writeDoubleBE = i.bind(null, a, 4, 0);
925
+ r.writeDoubleLE = i.bind(null, o, 0, 4), r.writeDoubleBE = i.bind(null, u, 4, 0);
894
926
  function t(e, s, l, c, d) {
895
927
  var p = e(c, d + s), f = e(c, d + l), w = (f >> 31) * 2 + 1, b = f >>> 20 & 2047, g = 4294967296 * (f & 1048575) + p;
896
928
  return b === 2047 ? g ? NaN : w * (1 / 0) : b === 0 ? w * 5e-324 * g : w * Math.pow(2, b - 1075) * (g + 4503599627370496);
897
929
  }
898
- r.readDoubleLE = t.bind(null, u, 0, 4), r.readDoubleBE = t.bind(null, n, 4, 0);
930
+ r.readDoubleLE = t.bind(null, a, 0, 4), r.readDoubleBE = t.bind(null, n, 4, 0);
899
931
  }(), r;
900
932
  }
901
933
  function o(r, i, t) {
902
934
  i[t] = r & 255, i[t + 1] = r >>> 8 & 255, i[t + 2] = r >>> 16 & 255, i[t + 3] = r >>> 24;
903
935
  }
904
- function a(r, i, t) {
936
+ function u(r, i, t) {
905
937
  i[t] = r >>> 24, i[t + 1] = r >>> 16 & 255, i[t + 2] = r >>> 8 & 255, i[t + 3] = r & 255;
906
938
  }
907
- function u(r, i) {
939
+ function a(r, i) {
908
940
  return (r[i] | r[i + 1] << 8 | r[i + 2] << 16 | r[i + 3] << 24) >>> 0;
909
941
  }
910
942
  function n(r, i) {
@@ -931,20 +963,20 @@ var utf8 = {}, hasRequiredUtf8;
931
963
  function requireUtf8() {
932
964
  return hasRequiredUtf8 || (hasRequiredUtf8 = 1, function(h) {
933
965
  var o = h;
934
- o.length = function(u) {
935
- for (var n = 0, r = 0, i = 0; i < u.length; ++i)
936
- r = u.charCodeAt(i), r < 128 ? n += 1 : r < 2048 ? n += 2 : (r & 64512) === 55296 && (u.charCodeAt(i + 1) & 64512) === 56320 ? (++i, n += 4) : n += 3;
966
+ o.length = function(a) {
967
+ for (var n = 0, r = 0, i = 0; i < a.length; ++i)
968
+ r = a.charCodeAt(i), r < 128 ? n += 1 : r < 2048 ? n += 2 : (r & 64512) === 55296 && (a.charCodeAt(i + 1) & 64512) === 56320 ? (++i, n += 4) : n += 3;
937
969
  return n;
938
- }, o.read = function(u, n, r) {
970
+ }, o.read = function(a, n, r) {
939
971
  var i = r - n;
940
972
  if (i < 1)
941
973
  return "";
942
974
  for (var t = null, e = [], s = 0, l; n < r; )
943
- l = u[n++], l < 128 ? e[s++] = l : l > 191 && l < 224 ? e[s++] = (l & 31) << 6 | u[n++] & 63 : l > 239 && l < 365 ? (l = ((l & 7) << 18 | (u[n++] & 63) << 12 | (u[n++] & 63) << 6 | u[n++] & 63) - 65536, e[s++] = 55296 + (l >> 10), e[s++] = 56320 + (l & 1023)) : e[s++] = (l & 15) << 12 | (u[n++] & 63) << 6 | u[n++] & 63, s > 8191 && ((t || (t = [])).push(String.fromCharCode.apply(String, e)), s = 0);
975
+ l = a[n++], l < 128 ? e[s++] = l : l > 191 && l < 224 ? e[s++] = (l & 31) << 6 | a[n++] & 63 : l > 239 && l < 365 ? (l = ((l & 7) << 18 | (a[n++] & 63) << 12 | (a[n++] & 63) << 6 | a[n++] & 63) - 65536, e[s++] = 55296 + (l >> 10), e[s++] = 56320 + (l & 1023)) : e[s++] = (l & 15) << 12 | (a[n++] & 63) << 6 | a[n++] & 63, s > 8191 && ((t || (t = [])).push(String.fromCharCode.apply(String, e)), s = 0);
944
976
  return t ? (s && t.push(String.fromCharCode.apply(String, e.slice(0, s))), t.join("")) : String.fromCharCode.apply(String, e.slice(0, s));
945
- }, o.write = function(u, n, r) {
946
- for (var i = r, t, e, s = 0; s < u.length; ++s)
947
- t = u.charCodeAt(s), t < 128 ? n[r++] = t : t < 2048 ? (n[r++] = t >> 6 | 192, n[r++] = t & 63 | 128) : (t & 64512) === 55296 && ((e = u.charCodeAt(s + 1)) & 64512) === 56320 ? (t = 65536 + ((t & 1023) << 10) + (e & 1023), ++s, n[r++] = t >> 18 | 240, n[r++] = t >> 12 & 63 | 128, n[r++] = t >> 6 & 63 | 128, n[r++] = t & 63 | 128) : (n[r++] = t >> 12 | 224, n[r++] = t >> 6 & 63 | 128, n[r++] = t & 63 | 128);
977
+ }, o.write = function(a, n, r) {
978
+ for (var i = r, t, e, s = 0; s < a.length; ++s)
979
+ t = a.charCodeAt(s), t < 128 ? n[r++] = t : t < 2048 ? (n[r++] = t >> 6 | 192, n[r++] = t & 63 | 128) : (t & 64512) === 55296 && ((e = a.charCodeAt(s + 1)) & 64512) === 56320 ? (t = 65536 + ((t & 1023) << 10) + (e & 1023), ++s, n[r++] = t >> 18 | 240, n[r++] = t >> 12 & 63 | 128, n[r++] = t >> 6 & 63 | 128, n[r++] = t & 63 | 128) : (n[r++] = t >> 12 | 224, n[r++] = t >> 6 & 63 | 128, n[r++] = t & 63 | 128);
948
980
  return r - i;
949
981
  };
950
982
  }(utf8)), utf8;
@@ -953,13 +985,13 @@ var pool_1, hasRequiredPool;
953
985
  function requirePool() {
954
986
  if (hasRequiredPool) return pool_1;
955
987
  hasRequiredPool = 1, pool_1 = h;
956
- function h(o, a, u) {
957
- var n = u || 8192, r = n >>> 1, i = null, t = n;
988
+ function h(o, u, a) {
989
+ var n = a || 8192, r = n >>> 1, i = null, t = n;
958
990
  return function(s) {
959
991
  if (s < 1 || s > r)
960
992
  return o(s);
961
993
  t + s > n && (i = o(n), t = 0);
962
- var l = a.call(i, t, t += s);
994
+ var l = u.call(i, t, t += s);
963
995
  return t & 7 && (t = (t | 7) + 1), l;
964
996
  };
965
997
  }
@@ -973,18 +1005,18 @@ function requireLongbits() {
973
1005
  function o(r, i) {
974
1006
  this.lo = r >>> 0, this.hi = i >>> 0;
975
1007
  }
976
- var a = o.zero = new o(0, 0);
977
- a.toNumber = function() {
1008
+ var u = o.zero = new o(0, 0);
1009
+ u.toNumber = function() {
978
1010
  return 0;
979
- }, a.zzEncode = a.zzDecode = function() {
1011
+ }, u.zzEncode = u.zzDecode = function() {
980
1012
  return this;
981
- }, a.length = function() {
1013
+ }, u.length = function() {
982
1014
  return 1;
983
1015
  };
984
- var u = o.zeroHash = "\0\0\0\0\0\0\0\0";
1016
+ var a = o.zeroHash = "\0\0\0\0\0\0\0\0";
985
1017
  o.fromNumber = function(i) {
986
1018
  if (i === 0)
987
- return a;
1019
+ return u;
988
1020
  var t = i < 0;
989
1021
  t && (i = -i);
990
1022
  var e = i >>> 0, s = (i - e) / 4294967296 >>> 0;
@@ -997,7 +1029,7 @@ function requireLongbits() {
997
1029
  i = h.Long.fromString(i);
998
1030
  else
999
1031
  return o.fromNumber(parseInt(i, 10));
1000
- return i.low || i.high ? new o(i.low >>> 0, i.high >>> 0) : a;
1032
+ return i.low || i.high ? new o(i.low >>> 0, i.high >>> 0) : u;
1001
1033
  }, o.prototype.toNumber = function(i) {
1002
1034
  if (!i && this.hi >>> 31) {
1003
1035
  var t = ~this.lo + 1 >>> 0, e = ~this.hi >>> 0;
@@ -1009,7 +1041,7 @@ function requireLongbits() {
1009
1041
  };
1010
1042
  var n = String.prototype.charCodeAt;
1011
1043
  return o.fromHash = function(i) {
1012
- return i === u ? a : new o(
1044
+ return i === a ? u : new o(
1013
1045
  (n.call(i, 0) | n.call(i, 1) << 8 | n.call(i, 2) << 16 | n.call(i, 3) << 24) >>> 0,
1014
1046
  (n.call(i, 4) | n.call(i, 5) << 8 | n.call(i, 6) << 16 | n.call(i, 7) << 24) >>> 0
1015
1047
  );
@@ -1082,21 +1114,21 @@ function requireMinimal$1() {
1082
1114
  var t = o.LongBits.fromHash(r);
1083
1115
  return o.Long ? o.Long.fromBits(t.lo, t.hi, i) : t.toNumber(!!i);
1084
1116
  };
1085
- function a(n, r, i) {
1117
+ function u(n, r, i) {
1086
1118
  for (var t = Object.keys(r), e = 0; e < t.length; ++e)
1087
1119
  (n[t[e]] === void 0 || !i) && (n[t[e]] = r[t[e]]);
1088
1120
  return n;
1089
1121
  }
1090
- o.merge = a, o.lcFirst = function(r) {
1122
+ o.merge = u, o.lcFirst = function(r) {
1091
1123
  return r.charAt(0).toLowerCase() + r.substring(1);
1092
1124
  };
1093
- function u(n) {
1125
+ function a(n) {
1094
1126
  function r(i, t) {
1095
1127
  if (!(this instanceof r))
1096
1128
  return new r(i, t);
1097
1129
  Object.defineProperty(this, "message", { get: function() {
1098
1130
  return i;
1099
- } }), Error.captureStackTrace ? Error.captureStackTrace(this, r) : Object.defineProperty(this, "stack", { value: new Error().stack || "" }), t && a(this, t);
1131
+ } }), Error.captureStackTrace ? Error.captureStackTrace(this, r) : Object.defineProperty(this, "stack", { value: new Error().stack || "" }), t && u(this, t);
1100
1132
  }
1101
1133
  return r.prototype = Object.create(Error.prototype, {
1102
1134
  constructor: {
@@ -1127,7 +1159,7 @@ function requireMinimal$1() {
1127
1159
  }
1128
1160
  }), r;
1129
1161
  }
1130
- o.newError = u, o.ProtocolError = u("ProtocolError"), o.oneOfGetter = function(r) {
1162
+ o.newError = a, o.ProtocolError = a("ProtocolError"), o.oneOfGetter = function(r) {
1131
1163
  for (var i = {}, t = 0; t < r.length; ++t)
1132
1164
  i[r[t]] = 1;
1133
1165
  return function() {
@@ -1165,7 +1197,7 @@ var writer, hasRequiredWriter;
1165
1197
  function requireWriter() {
1166
1198
  if (hasRequiredWriter) return writer;
1167
1199
  hasRequiredWriter = 1, writer = e;
1168
- var h = requireMinimal$1(), o, a = h.LongBits, u = h.base64, n = h.utf8;
1200
+ var h = requireMinimal$1(), o, u = h.LongBits, a = h.base64, n = h.utf8;
1169
1201
  function r(b, g, k) {
1170
1202
  this.fn = b, this.len = g, this.next = void 0, this.val = k;
1171
1203
  }
@@ -1208,7 +1240,7 @@ function requireWriter() {
1208
1240
  g
1209
1241
  )).len, this;
1210
1242
  }, e.prototype.int32 = function(g) {
1211
- return g < 0 ? this._push(p, 10, a.fromNumber(g)) : this.uint32(g);
1243
+ return g < 0 ? this._push(p, 10, u.fromNumber(g)) : this.uint32(g);
1212
1244
  }, e.prototype.sint32 = function(g) {
1213
1245
  return this.uint32((g << 1 ^ g >> 31) >>> 0);
1214
1246
  };
@@ -1220,10 +1252,10 @@ function requireWriter() {
1220
1252
  g[k++] = b.lo;
1221
1253
  }
1222
1254
  e.prototype.uint64 = function(g) {
1223
- var k = a.from(g);
1255
+ var k = u.from(g);
1224
1256
  return this._push(p, k.length(), k);
1225
1257
  }, e.prototype.int64 = e.prototype.uint64, e.prototype.sint64 = function(g) {
1226
- var k = a.from(g).zzEncode();
1258
+ var k = u.from(g).zzEncode();
1227
1259
  return this._push(p, k.length(), k);
1228
1260
  }, e.prototype.bool = function(g) {
1229
1261
  return this._push(l, 1, g ? 1 : 0);
@@ -1234,7 +1266,7 @@ function requireWriter() {
1234
1266
  e.prototype.fixed32 = function(g) {
1235
1267
  return this._push(f, 4, g >>> 0);
1236
1268
  }, e.prototype.sfixed32 = e.prototype.fixed32, e.prototype.fixed64 = function(g) {
1237
- var k = a.from(g);
1269
+ var k = u.from(g);
1238
1270
  return this._push(f, 4, k.lo)._push(f, 4, k.hi);
1239
1271
  }, e.prototype.sfixed64 = e.prototype.fixed64, e.prototype.float = function(g) {
1240
1272
  return this._push(h.float.writeFloatLE, 4, g);
@@ -1244,16 +1276,16 @@ function requireWriter() {
1244
1276
  var w = h.Array.prototype.set ? function(g, k, T) {
1245
1277
  k.set(g, T);
1246
1278
  } : function(g, k, T) {
1247
- for (var K = 0; K < g.length; ++K)
1248
- k[T + K] = g[K];
1279
+ for (var $ = 0; $ < g.length; ++$)
1280
+ k[T + $] = g[$];
1249
1281
  };
1250
1282
  return e.prototype.bytes = function(g) {
1251
1283
  var k = g.length >>> 0;
1252
1284
  if (!k)
1253
1285
  return this._push(l, 1, 0);
1254
1286
  if (h.isString(g)) {
1255
- var T = e.alloc(k = u.length(g));
1256
- u.decode(g, T, 0), g = T;
1287
+ var T = e.alloc(k = a.length(g));
1288
+ a.decode(g, T, 0), g = T;
1257
1289
  }
1258
1290
  return this.uint32(k)._push(w, k, g);
1259
1291
  }, e.prototype.string = function(g) {
@@ -1277,15 +1309,15 @@ function requireWriter() {
1277
1309
  var writer_buffer, hasRequiredWriter_buffer;
1278
1310
  function requireWriter_buffer() {
1279
1311
  if (hasRequiredWriter_buffer) return writer_buffer;
1280
- hasRequiredWriter_buffer = 1, writer_buffer = a;
1312
+ hasRequiredWriter_buffer = 1, writer_buffer = u;
1281
1313
  var h = requireWriter();
1282
- (a.prototype = Object.create(h.prototype)).constructor = a;
1314
+ (u.prototype = Object.create(h.prototype)).constructor = u;
1283
1315
  var o = requireMinimal$1();
1284
- function a() {
1316
+ function u() {
1285
1317
  h.call(this);
1286
1318
  }
1287
- a._configure = function() {
1288
- a.alloc = o._Buffer_allocUnsafe, a.writeBytesBuffer = o.Buffer && o.Buffer.prototype instanceof Uint8Array && o.Buffer.prototype.set.name === "set" ? function(r, i, t) {
1319
+ u._configure = function() {
1320
+ u.alloc = o._Buffer_allocUnsafe, u.writeBytesBuffer = o.Buffer && o.Buffer.prototype instanceof Uint8Array && o.Buffer.prototype.set.name === "set" ? function(r, i, t) {
1289
1321
  i.set(r, t);
1290
1322
  } : function(r, i, t) {
1291
1323
  if (r.copy)
@@ -1293,24 +1325,24 @@ function requireWriter_buffer() {
1293
1325
  else for (var e = 0; e < r.length; )
1294
1326
  i[t++] = r[e++];
1295
1327
  };
1296
- }, a.prototype.bytes = function(r) {
1328
+ }, u.prototype.bytes = function(r) {
1297
1329
  o.isString(r) && (r = o._Buffer_from(r, "base64"));
1298
1330
  var i = r.length >>> 0;
1299
- return this.uint32(i), i && this._push(a.writeBytesBuffer, i, r), this;
1331
+ return this.uint32(i), i && this._push(u.writeBytesBuffer, i, r), this;
1300
1332
  };
1301
- function u(n, r, i) {
1333
+ function a(n, r, i) {
1302
1334
  n.length < 40 ? o.utf8.write(n, r, i) : r.utf8Write ? r.utf8Write(n, i) : r.write(n, i);
1303
1335
  }
1304
- return a.prototype.string = function(r) {
1336
+ return u.prototype.string = function(r) {
1305
1337
  var i = o.Buffer.byteLength(r);
1306
- return this.uint32(i), i && this._push(u, i, r), this;
1307
- }, a._configure(), writer_buffer;
1338
+ return this.uint32(i), i && this._push(a, i, r), this;
1339
+ }, u._configure(), writer_buffer;
1308
1340
  }
1309
1341
  var reader, hasRequiredReader;
1310
1342
  function requireReader() {
1311
1343
  if (hasRequiredReader) return reader;
1312
1344
  hasRequiredReader = 1, reader = r;
1313
- var h = requireMinimal$1(), o, a = h.LongBits, u = h.utf8;
1345
+ var h = requireMinimal$1(), o, u = h.LongBits, a = h.utf8;
1314
1346
  function n(c, d) {
1315
1347
  return RangeError("index out of range: " + c.pos + " + " + (d || 1) + " > " + c.len);
1316
1348
  }
@@ -1348,7 +1380,7 @@ function requireReader() {
1348
1380
  return d >>> 1 ^ -(d & 1) | 0;
1349
1381
  };
1350
1382
  function e() {
1351
- var c = new a(0, 0), d = 0;
1383
+ var c = new u(0, 0), d = 0;
1352
1384
  if (this.len - this.pos > 4) {
1353
1385
  for (; d < 4; ++d)
1354
1386
  if (c.lo = (c.lo | (this.buf[this.pos] & 127) << d * 7) >>> 0, this.buf[this.pos++] < 128)
@@ -1396,7 +1428,7 @@ function requireReader() {
1396
1428
  function l() {
1397
1429
  if (this.pos + 8 > this.len)
1398
1430
  throw n(this, 8);
1399
- return new a(s(this.buf, this.pos += 4), s(this.buf, this.pos += 4));
1431
+ return new u(s(this.buf, this.pos += 4), s(this.buf, this.pos += 4));
1400
1432
  }
1401
1433
  return r.prototype.float = function() {
1402
1434
  if (this.pos + 4 > this.len)
@@ -1421,7 +1453,7 @@ function requireReader() {
1421
1453
  return this._slice.call(this.buf, p, f);
1422
1454
  }, r.prototype.string = function() {
1423
1455
  var d = this.bytes();
1424
- return u.read(d, 0, d.length);
1456
+ return a.read(d, 0, d.length);
1425
1457
  }, r.prototype.skip = function(d) {
1426
1458
  if (typeof d == "number") {
1427
1459
  if (this.pos + d > this.len)
@@ -1484,19 +1516,19 @@ function requireReader() {
1484
1516
  var reader_buffer, hasRequiredReader_buffer;
1485
1517
  function requireReader_buffer() {
1486
1518
  if (hasRequiredReader_buffer) return reader_buffer;
1487
- hasRequiredReader_buffer = 1, reader_buffer = a;
1519
+ hasRequiredReader_buffer = 1, reader_buffer = u;
1488
1520
  var h = requireReader();
1489
- (a.prototype = Object.create(h.prototype)).constructor = a;
1521
+ (u.prototype = Object.create(h.prototype)).constructor = u;
1490
1522
  var o = requireMinimal$1();
1491
- function a(u) {
1492
- h.call(this, u);
1523
+ function u(a) {
1524
+ h.call(this, a);
1493
1525
  }
1494
- return a._configure = function() {
1495
- o.Buffer && (a.prototype._slice = o.Buffer.prototype.slice);
1496
- }, a.prototype.string = function() {
1526
+ return u._configure = function() {
1527
+ o.Buffer && (u.prototype._slice = o.Buffer.prototype.slice);
1528
+ }, u.prototype.string = function() {
1497
1529
  var n = this.uint32();
1498
1530
  return this.buf.utf8Slice ? this.buf.utf8Slice(this.pos, this.pos = Math.min(this.pos + n, this.len)) : this.buf.toString("utf-8", this.pos, this.pos = Math.min(this.pos + n, this.len));
1499
- }, a._configure(), reader_buffer;
1531
+ }, u._configure(), reader_buffer;
1500
1532
  }
1501
1533
  var rpc = {}, service, hasRequiredService;
1502
1534
  function requireService() {
@@ -1504,17 +1536,17 @@ function requireService() {
1504
1536
  hasRequiredService = 1, service = o;
1505
1537
  var h = requireMinimal$1();
1506
1538
  (o.prototype = Object.create(h.EventEmitter.prototype)).constructor = o;
1507
- function o(a, u, n) {
1508
- if (typeof a != "function")
1539
+ function o(u, a, n) {
1540
+ if (typeof u != "function")
1509
1541
  throw TypeError("rpcImpl must be a function");
1510
- h.EventEmitter.call(this), this.rpcImpl = a, this.requestDelimited = !!u, this.responseDelimited = !!n;
1542
+ h.EventEmitter.call(this), this.rpcImpl = u, this.requestDelimited = !!a, this.responseDelimited = !!n;
1511
1543
  }
1512
- return o.prototype.rpcCall = function a(u, n, r, i, t) {
1544
+ return o.prototype.rpcCall = function u(a, n, r, i, t) {
1513
1545
  if (!i)
1514
1546
  throw TypeError("request must be specified");
1515
1547
  var e = this;
1516
1548
  if (!t)
1517
- return h.asPromise(a, e, u, n, r, i);
1549
+ return h.asPromise(u, e, a, n, r, i);
1518
1550
  if (!e.rpcImpl) {
1519
1551
  setTimeout(function() {
1520
1552
  t(Error("already ended"));
@@ -1523,11 +1555,11 @@ function requireService() {
1523
1555
  }
1524
1556
  try {
1525
1557
  return e.rpcImpl(
1526
- u,
1558
+ a,
1527
1559
  n[e.requestDelimited ? "encodeDelimited" : "encode"](i).finish(),
1528
1560
  function(l, c) {
1529
1561
  if (l)
1530
- return e.emit("error", l, u), t(l);
1562
+ return e.emit("error", l, a), t(l);
1531
1563
  if (c === null) {
1532
1564
  e.end(
1533
1565
  /* endedByRPC */
@@ -1539,19 +1571,19 @@ function requireService() {
1539
1571
  try {
1540
1572
  c = r[e.responseDelimited ? "decodeDelimited" : "decode"](c);
1541
1573
  } catch (d) {
1542
- return e.emit("error", d, u), t(d);
1574
+ return e.emit("error", d, a), t(d);
1543
1575
  }
1544
- return e.emit("data", c, u), t(null, c);
1576
+ return e.emit("data", c, a), t(null, c);
1545
1577
  }
1546
1578
  );
1547
1579
  } catch (s) {
1548
- e.emit("error", s, u), setTimeout(function() {
1580
+ e.emit("error", s, a), setTimeout(function() {
1549
1581
  t(s);
1550
1582
  }, 0);
1551
1583
  return;
1552
1584
  }
1553
- }, o.prototype.end = function(u) {
1554
- return this.rpcImpl && (u || this.rpcImpl(null, null, null), this.rpcImpl = null, this.emit("end").off()), this;
1585
+ }, o.prototype.end = function(a) {
1586
+ return this.rpcImpl && (a || this.rpcImpl(null, null, null), this.rpcImpl = null, this.emit("end").off()), this;
1555
1587
  }, service;
1556
1588
  }
1557
1589
  var hasRequiredRpc;
@@ -1569,11 +1601,11 @@ var hasRequiredIndexMinimal;
1569
1601
  function requireIndexMinimal() {
1570
1602
  return hasRequiredIndexMinimal || (hasRequiredIndexMinimal = 1, function(h) {
1571
1603
  var o = h;
1572
- o.build = "minimal", o.Writer = requireWriter(), o.BufferWriter = requireWriter_buffer(), o.Reader = requireReader(), o.BufferReader = requireReader_buffer(), o.util = requireMinimal$1(), o.rpc = requireRpc(), o.roots = requireRoots(), o.configure = a;
1573
- function a() {
1604
+ o.build = "minimal", o.Writer = requireWriter(), o.BufferWriter = requireWriter_buffer(), o.Reader = requireReader(), o.BufferReader = requireReader_buffer(), o.util = requireMinimal$1(), o.rpc = requireRpc(), o.roots = requireRoots(), o.configure = u;
1605
+ function u() {
1574
1606
  o.util._configure(), o.Writer._configure(o.BufferWriter), o.Reader._configure(o.BufferReader);
1575
1607
  }
1576
- a();
1608
+ u();
1577
1609
  }(indexMinimal)), indexMinimal;
1578
1610
  }
1579
1611
  var minimal, hasRequiredMinimal;
@@ -1586,10 +1618,10 @@ const $Reader = minimalExports.Reader, $Writer = minimalExports.Writer, $util =
1586
1618
  return h.quick = function() {
1587
1619
  const o = {};
1588
1620
  return o.voice = function() {
1589
- const a = {};
1590
- return a.proto = function() {
1591
- const u = {};
1592
- return u.SeiData = function() {
1621
+ const u = {};
1622
+ return u.proto = function() {
1623
+ const a = {};
1624
+ return a.SeiData = function() {
1593
1625
  function n(r) {
1594
1626
  if (r) for (let i = Object.keys(r), t = 0; t < i.length; ++t) r[i[t]] != null && (this[i[t]] = r[i[t]]);
1595
1627
  }
@@ -1682,10 +1714,10 @@ const $Reader = minimalExports.Reader, $Writer = minimalExports.Writer, $util =
1682
1714
  }, n.getTypeUrl = function(i) {
1683
1715
  return i === void 0 && (i = "type.googleapis.com"), i + "/com.quick.voice.proto.SeiData";
1684
1716
  }, n;
1685
- }(), u.EventType = function() {
1717
+ }(), a.EventType = function() {
1686
1718
  const n = {}, r = Object.create(n);
1687
1719
  return r[n[0] = "Layout"] = 0, r[n[1] = "Custom"] = 1, r;
1688
- }(), u.LayoutData = function() {
1720
+ }(), a.LayoutData = function() {
1689
1721
  function n(i) {
1690
1722
  if (this.userMap = {}, i) for (let t = Object.keys(i), e = 0; e < t.length; ++e) i[t[e]] != null && (this[t[e]] = i[t[e]]);
1691
1723
  }
@@ -1844,7 +1876,7 @@ const $Reader = minimalExports.Reader, $Writer = minimalExports.Writer, $util =
1844
1876
  }, n.getTypeUrl = function(t) {
1845
1877
  return t === void 0 && (t = "type.googleapis.com"), t + "/com.quick.voice.proto.LayoutData";
1846
1878
  }, n;
1847
- }(), u.UserInfo = function() {
1879
+ }(), a.UserInfo = function() {
1848
1880
  function n(i) {
1849
1881
  if (this.audios = [], this.videos = [], i) for (let t = Object.keys(i), e = 0; e < t.length; ++e) i[t[e]] != null && (this[t[e]] = i[t[e]]);
1850
1882
  }
@@ -1967,7 +1999,7 @@ const $Reader = minimalExports.Reader, $Writer = minimalExports.Writer, $util =
1967
1999
  }, n.getTypeUrl = function(t) {
1968
2000
  return t === void 0 && (t = "type.googleapis.com"), t + "/com.quick.voice.proto.UserInfo";
1969
2001
  }, n;
1970
- }(), u.AudioInfo = function() {
2002
+ }(), a.AudioInfo = function() {
1971
2003
  function n(i) {
1972
2004
  if (i) for (let t = Object.keys(i), e = 0; e < t.length; ++e) i[t[e]] != null && (this[t[e]] = i[t[e]]);
1973
2005
  }
@@ -2072,7 +2104,7 @@ const $Reader = minimalExports.Reader, $Writer = minimalExports.Writer, $util =
2072
2104
  }, n.getTypeUrl = function(t) {
2073
2105
  return t === void 0 && (t = "type.googleapis.com"), t + "/com.quick.voice.proto.AudioInfo";
2074
2106
  }, n;
2075
- }(), u.VideoInfo = function() {
2107
+ }(), a.VideoInfo = function() {
2076
2108
  function n(i) {
2077
2109
  if (i) for (let t = Object.keys(i), e = 0; e < t.length; ++e) i[t[e]] != null && (this[t[e]] = i[t[e]]);
2078
2110
  }
@@ -2198,7 +2230,7 @@ const $Reader = minimalExports.Reader, $Writer = minimalExports.Writer, $util =
2198
2230
  }, n.getTypeUrl = function(t) {
2199
2231
  return t === void 0 && (t = "type.googleapis.com"), t + "/com.quick.voice.proto.VideoInfo";
2200
2232
  }, n;
2201
- }(), u.CustomInfo = function() {
2233
+ }(), a.CustomInfo = function() {
2202
2234
  function n(i) {
2203
2235
  if (this.customKeyMap = {}, i) for (let t = Object.keys(i), e = 0; e < t.length; ++e) i[t[e]] != null && (this[t[e]] = i[t[e]]);
2204
2236
  }
@@ -2305,17 +2337,17 @@ const $Reader = minimalExports.Reader, $Writer = minimalExports.Writer, $util =
2305
2337
  }, n.getTypeUrl = function(t) {
2306
2338
  return t === void 0 && (t = "type.googleapis.com"), t + "/com.quick.voice.proto.CustomInfo";
2307
2339
  }, n;
2308
- }(), u.LayoutType = function() {
2340
+ }(), a.LayoutType = function() {
2309
2341
  const n = {}, r = Object.create(n);
2310
2342
  return r[n[0] = "AudioAndVideo"] = 0, r[n[1] = "OnlyAudio"] = 1, r[n[2] = "OnlyVideo"] = 2, r;
2311
- }(), u.AudioType = function() {
2343
+ }(), a.AudioType = function() {
2312
2344
  const n = {}, r = Object.create(n);
2313
2345
  return r[n[0] = "Microphone"] = 0, r[n[1] = "SystemVoice"] = 1, r;
2314
- }(), u.VideoType = function() {
2346
+ }(), a.VideoType = function() {
2315
2347
  const n = {}, r = Object.create(n);
2316
2348
  return r[n[0] = "Camera"] = 0, r[n[1] = "Screen"] = 1, r;
2317
- }(), u;
2318
- }(), a;
2349
+ }(), a;
2350
+ }(), u;
2319
2351
  }(), o;
2320
2352
  }(), h;
2321
2353
  })(), createAudioInfo = () => ({
@@ -2336,27 +2368,27 @@ const $Reader = minimalExports.Reader, $Writer = minimalExports.Writer, $util =
2336
2368
  });
2337
2369
  class RoomUser {
2338
2370
  constructor() {
2339
- m(this, "userId", "");
2340
- m(this, "mc_audio");
2371
+ y(this, "userId", "");
2372
+ y(this, "mc_audio");
2341
2373
  // 麦克风
2342
- m(this, "mc_video");
2374
+ y(this, "mc_video");
2343
2375
  // 摄像头
2344
- m(this, "ss_audio");
2376
+ y(this, "ss_audio");
2345
2377
  // 屏幕共享视频
2346
- m(this, "ss_video");
2378
+ y(this, "ss_video");
2347
2379
  // 屏幕共享音频
2348
- m(this, "updateTime", 0);
2349
- m(this, "getUpdateTimeKey", () => {
2380
+ y(this, "updateTime", 0);
2381
+ y(this, "getUpdateTimeKey", () => {
2350
2382
  const o = [];
2351
2383
  return this.mc_audio && o.push(this.mc_audio.updateTime), this.mc_video && o.push(this.mc_video.updateTime), this.ss_audio && o.push(this.ss_audio.updateTime), this.ss_video && o.push(this.ss_video.updateTime), o.join("_");
2352
2384
  });
2353
- m(this, "init", (o) => {
2385
+ y(this, "init", (o) => {
2354
2386
  var t, e, s, l;
2355
- const { id: a, audios: u = [], videos: n = [] } = o;
2356
- this.userId = a;
2387
+ const { id: u, audios: a = [], videos: n = [] } = o;
2388
+ this.userId = u;
2357
2389
  const r = this.getUpdateTimeKey();
2358
2390
  this.mc_audio && (this.mc_audio.remove = !0), this.mc_video && (this.mc_video.remove = !0), this.ss_audio && (this.ss_audio.remove = !0), this.ss_video && (this.ss_video.remove = !0);
2359
- for (const c of u) {
2391
+ for (const c of a) {
2360
2392
  const { type: d = 0, isEnable: p = !1, isMute: f = !1, updateTime: w, volume: b = 0 } = c;
2361
2393
  switch (d) {
2362
2394
  case 0:
@@ -2394,27 +2426,26 @@ class RoomUser {
2394
2426
  const i = this.getUpdateTimeKey();
2395
2427
  r !== i && (this.updateTime = (/* @__PURE__ */ new Date()).getTime());
2396
2428
  });
2397
- m(this, "destroy", () => {
2398
- var o, a;
2399
- (o = this.mc_video) != null && o.destroy && this.mc_video.destroy(), (a = this.ss_video) != null && a.destroy && this.ss_video.destroy(), this.mc_audio = void 0, this.mc_video = void 0, this.ss_audio = void 0, this.ss_video = void 0;
2429
+ y(this, "destroy", () => {
2430
+ this.mc_audio = void 0, this.mc_video = void 0, this.ss_audio = void 0, this.ss_video = void 0;
2400
2431
  });
2401
2432
  }
2402
2433
  }
2403
2434
  const parseSEI = (h) => {
2404
- let o = 0, a = 0;
2435
+ let o = 0, u = 0;
2405
2436
  for (; ; ) {
2406
2437
  const n = h[o];
2407
- if (a = a + n, o = o + 1, n !== 255) break;
2438
+ if (u = u + n, o = o + 1, n !== 255) break;
2408
2439
  }
2409
- let u = 0;
2440
+ let a = 0;
2410
2441
  for (; ; ) {
2411
2442
  const n = h[o];
2412
- if (u = u + n, o = o + 1, n !== 255) break;
2443
+ if (a = a + n, o = o + 1, n !== 255) break;
2413
2444
  }
2414
- if (a === 5) {
2445
+ if (u === 5) {
2415
2446
  const n = h.slice(o, o + 16), i = Array.from(n, (f) => f.toString(16).padStart(2, "0")).join("");
2416
2447
  o = o + 16;
2417
- const t = u - 16, e = h.slice(o, o + t), s = com.quick.voice.proto.SeiData.decode(e), { event: l = 0 } = s, c = s.data;
2448
+ const t = a - 16, e = h.slice(o, o + t), s = com.quick.voice.proto.SeiData.decode(e), { event: l = 0 } = s, c = s.data;
2418
2449
  let d;
2419
2450
  switch (l) {
2420
2451
  case 0:
@@ -2429,85 +2460,80 @@ const parseSEI = (h) => {
2429
2460
  };
2430
2461
  class QuickVoPlayer {
2431
2462
  constructor(o = {}) {
2432
- m(this, "option", {
2463
+ y(this, "option", {
2433
2464
  debug: !1,
2434
2465
  ws: "wss://livep2p.devplay.cc/websocket"
2435
2466
  });
2436
- m(this, "displayMode", "original");
2437
- m(this, "prPlayer");
2438
- m(this, "dom");
2439
- m(this, "room", {
2467
+ y(this, "displayMode", "original");
2468
+ y(this, "prPlayer");
2469
+ y(this, "dom");
2470
+ y(this, "room", {
2440
2471
  roomId: "",
2441
2472
  updateTime: "",
2442
2473
  author: "",
2443
2474
  version: ""
2444
2475
  });
2445
- m(this, "usersMap", /* @__PURE__ */ new Map());
2446
- m(this, "on", {
2476
+ y(this, "usersMap", /* @__PURE__ */ new Map());
2477
+ y(this, "on", {
2447
2478
  users: (o) => {
2448
2479
  },
2449
2480
  analysis: (o) => {
2450
2481
  }
2451
2482
  });
2452
- m(this, "start", async (o) => (this.stop(), this.prPlayer.start(o)));
2453
- m(this, "stop", () => {
2483
+ y(this, "start", async (o) => (this.stop(), this.prPlayer.start(o)));
2484
+ y(this, "stop", () => {
2454
2485
  this.prPlayer.stop(), this.usersMap = /* @__PURE__ */ new Map(), this.room.roomId = "", this.room.author = "", this.room.updateTime = "", this.room.version = "";
2455
2486
  });
2456
- m(this, "setMute", (o) => {
2487
+ y(this, "setMute", (o) => {
2457
2488
  this.prPlayer.setMute(o);
2458
2489
  });
2459
- m(this, "getStream", () => this.prPlayer.getStream());
2460
- m(this, "getAllUseUpdateKey", () => {
2490
+ y(this, "setOutputGain", (o) => {
2491
+ var u, a;
2492
+ (a = (u = this.prPlayer.audioPlayer) == null ? void 0 : u.prAudioStream) == null || a.setOutputGain(o);
2493
+ });
2494
+ y(this, "getStream", () => this.prPlayer.getStream());
2495
+ y(this, "getAllUseUpdateKey", () => {
2461
2496
  const o = [...this.usersMap.values()];
2462
- return Array.from(o, (u) => u.updateTime).join("_");
2497
+ return Array.from(o, (a) => a.updateTime).join("_");
2463
2498
  });
2464
- m(this, "checkAndCreateUser", (o, a) => {
2465
- var u, n;
2466
- if (this.usersMap.has(o)) {
2467
- const r = this.usersMap.get(o);
2468
- if (r == null || r.init(a), r != null && r.mc_video) {
2469
- const { sx: i, sy: t, sw: e, sh: s } = r.mc_video;
2470
- (u = r == null ? void 0 : r.mc_video.worker) == null || u.setCut({ sx: i, sy: t, sw: e, sh: s });
2499
+ y(this, "checkAndCreateUser", (o, u) => {
2500
+ !this.usersMap.has(o) && this.usersMap.set(o, new RoomUser());
2501
+ const a = this.usersMap.get(o);
2502
+ if (a) {
2503
+ if (a.init(u), a.mc_video && a.mc_video.stream === void 0) {
2504
+ const { sx: n, sy: r, sw: i, sh: t } = a.mc_video, e = `${a.userId}_mc_video`, s = this.prPlayer.cut.create(e, { sx: n, sy: r, sw: i, sh: t });
2505
+ this.displayMode === "original" && this.prPlayer.cut.setPause(e, !0), a.mc_video.stream = s;
2471
2506
  }
2472
- if (r != null && r.ss_video) {
2473
- const { sx: i, sy: t, sw: e, sh: s } = r.ss_video;
2474
- (n = r == null ? void 0 : r.ss_video.worker) == null || n.setCut({ sx: i, sy: t, sw: e, sh: s });
2507
+ if (a.ss_video && a.ss_video.stream === void 0) {
2508
+ const { sx: n, sy: r, sw: i, sh: t } = a.ss_video, e = `${a.userId}_ss_video`, s = this.prPlayer.cut.create(e, { sx: n, sy: r, sw: i, sh: t });
2509
+ this.displayMode === "original" && this.prPlayer.cut.setPause(e, !0), a.ss_video.stream = s;
2475
2510
  }
2476
- } else {
2477
- const r = new RoomUser();
2478
- if (this.usersMap.set(o, r), r.init(a), r) {
2479
- if (r.mc_video) {
2480
- const { sx: i, sy: t, sw: e, sh: s } = r.mc_video, l = `${r.userId}_mc_video`, { worker: c, stream: d, destroy: p } = this.prPlayer.cut.create(l, { sx: i, sy: t, sw: e, sh: s });
2481
- r.mc_video.worker = c, this.displayMode === "original" && c.setPause(!0), r.mc_video.stream = d, r.mc_video.destroy = () => {
2482
- p(), this.prPlayer.cut.remove(l), this.usersMap.delete(r.userId);
2483
- };
2484
- }
2485
- if (r.ss_video) {
2486
- const { sx: i, sy: t, sw: e, sh: s } = r.ss_video, l = `${r.userId}_ss_video`, { worker: c, stream: d, destroy: p } = this.prPlayer.cut.create(l, { sx: i, sy: t, sw: e, sh: s });
2487
- r.ss_video.worker = c, this.displayMode === "original" && c.setPause(!0), r.ss_video.stream = d, r.ss_video.destroy = () => {
2488
- p(), this.prPlayer.cut.remove(l), this.usersMap.delete(r.userId);
2489
- };
2490
- }
2511
+ if (a != null && a.mc_video) {
2512
+ const n = `${a.userId}_mc_video`, { sx: r, sy: i, sw: t, sh: e } = a.mc_video;
2513
+ this.prPlayer.cut.setCut(n, { sx: r, sy: i, sw: t, sh: e });
2514
+ }
2515
+ if (a != null && a.ss_video) {
2516
+ const n = `${a.userId}_ss_video`, { sx: r, sy: i, sw: t, sh: e } = a.ss_video;
2517
+ this.prPlayer.cut.setCut(n, { sx: r, sy: i, sw: t, sh: e });
2491
2518
  }
2492
2519
  }
2493
2520
  });
2494
- m(this, "setDisplayMode", (o) => {
2495
- var a, u, n, r, i, t, e, s;
2521
+ y(this, "setDisplayMode", (o) => {
2496
2522
  switch (this.displayMode = o, o) {
2497
2523
  case "original":
2498
2524
  {
2499
2525
  this.prPlayer.setPause(!1);
2500
- const l = [...this.usersMap.values()];
2501
- for (const c of l)
2502
- (u = (a = c.mc_video) == null ? void 0 : a.worker) == null || u.setPause(!0), (r = (n = c.ss_video) == null ? void 0 : n.worker) == null || r.setPause(!0);
2526
+ const u = [...this.usersMap.keys()];
2527
+ for (const a of u)
2528
+ this.prPlayer.cut.setPause(`${a}_mc_video`, !0), this.prPlayer.cut.setPause(`${a}_ss_video`, !0);
2503
2529
  }
2504
2530
  break;
2505
2531
  case "cut":
2506
2532
  {
2507
2533
  this.prPlayer.setPause(!0);
2508
- const l = [...this.usersMap.values()];
2509
- for (const c of l)
2510
- (t = (i = c.mc_video) == null ? void 0 : i.worker) == null || t.setPause(!1), (s = (e = c.ss_video) == null ? void 0 : e.worker) == null || s.setPause(!1);
2534
+ const u = [...this.usersMap.keys()];
2535
+ for (const a of u)
2536
+ this.prPlayer.cut.setPause(`${a}_mc_video`, !1), this.prPlayer.cut.setPause(`${a}_ss_video`, !1);
2511
2537
  }
2512
2538
  break;
2513
2539
  }
@@ -2515,21 +2541,21 @@ class QuickVoPlayer {
2515
2541
  /**
2516
2542
  * 监听SEI信息
2517
2543
  */
2518
- m(this, "onSEI", (o) => {
2544
+ y(this, "onSEI", (o) => {
2519
2545
  try {
2520
- const a = parseSEI(o);
2521
- if (!a) return;
2522
- const { event: u, data: n } = a;
2523
- switch (u) {
2546
+ const u = parseSEI(o);
2547
+ if (!u) return;
2548
+ const { event: a, data: n } = u;
2549
+ switch (a) {
2524
2550
  case 0:
2525
2551
  {
2526
2552
  const { roomId: r, userMap: i } = n;
2527
2553
  if (r !== this.room.roomId) return;
2528
2554
  const t = this.getAllUseUpdateKey(), e = Object.keys(i);
2529
2555
  {
2530
- const l = [...this.usersMap.values()];
2556
+ const l = [...this.usersMap.keys()];
2531
2557
  for (const c of l)
2532
- e.includes(c.userId) || c == null || c.destroy();
2558
+ e.includes(c) || (this.prPlayer.cut.remove(`${c}_mc_video`), this.prPlayer.cut.remove(`${c}_ss_video`), this.usersMap.delete(c));
2533
2559
  }
2534
2560
  for (const l of e) {
2535
2561
  const c = i[l];
@@ -2549,15 +2575,25 @@ class QuickVoPlayer {
2549
2575
  }
2550
2576
  break;
2551
2577
  }
2552
- } catch (a) {
2553
- console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m", "color:#0097ff;", "------->onSEI: error", a);
2578
+ } catch (u) {
2579
+ console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m", "color:#0097ff;", "------->onSEI: error", u);
2554
2580
  }
2555
2581
  });
2556
- m(this, "onAnalysis", (o) => {
2582
+ y(this, "onAnalysis", (o) => {
2557
2583
  this.on.analysis && this.on.analysis(o);
2558
2584
  });
2559
- const { debug: a = !1 } = o;
2560
- this.option.debug = a, this.prPlayer = new et({ debug: a }), this.prPlayer.on.demuxer.chunk = (u) => {
2585
+ const a = btoa(encodeURI(JSON.stringify({
2586
+ appId: "A6B499768801E248ACA11E5F842DB6DF",
2587
+ userId: "web_breathe",
2588
+ // "authId":"mobilePackageName" | "webRequestHostOrigin",
2589
+ platform: "web",
2590
+ version: "1.0.1"
2591
+ // 连接版本号
2592
+ }))), n = `${this.option.ws}?s=${a}&t=${Date.now()}`;
2593
+ let r = new WebSocket(n);
2594
+ console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m", "color:#0097ff;", "------->Breathe: ws", r);
2595
+ const { debug: i = !1 } = o;
2596
+ this.option.debug = i, this.prPlayer = new tt({ debug: i }), this.prPlayer.on.demuxer.chunk = (t) => {
2561
2597
  }, this.prPlayer.on.decoder.sei = this.onSEI, this.prPlayer.on.decoder.analysis = this.onAnalysis;
2562
2598
  }
2563
2599
  }