quickvo-player 0.2.9 → 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/README.md +5 -24
- package/dist/QuickVoPlayer.d.ts +1 -0
- package/dist/RoomUser.d.ts +0 -3
- package/dist/index.js +329 -290
- package/dist/index.umd.cjs +4 -4
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
1
|
+
var Y = Object.defineProperty;
|
|
2
|
+
var Z = (h) => {
|
|
3
3
|
throw TypeError(h);
|
|
4
4
|
};
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
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
|
|
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 "";
|
|
@@ -18,20 +18,20 @@ function L(h) {
|
|
|
18
18
|
}), u;
|
|
19
19
|
} catch {
|
|
20
20
|
return new Worker(
|
|
21
|
-
"data:text/javascript;charset=utf-8," + encodeURIComponent(
|
|
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
|
|
28
|
+
class I {
|
|
29
29
|
constructor() {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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) => {
|
|
@@ -53,9 +53,9 @@ class V {
|
|
|
53
53
|
};
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
-
const
|
|
57
|
-
`, C = typeof self < "u" && self.Blob && new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",
|
|
58
|
-
function
|
|
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 "";
|
|
@@ -67,23 +67,23 @@ function F(h) {
|
|
|
67
67
|
}), u;
|
|
68
68
|
} catch {
|
|
69
69
|
return new Worker(
|
|
70
|
-
"data:text/javascript;charset=utf-8," + encodeURIComponent(
|
|
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
|
|
77
|
+
class L {
|
|
78
78
|
constructor() {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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) => {
|
|
@@ -111,35 +111,73 @@ class N {
|
|
|
111
111
|
};
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
|
-
|
|
115
|
-
|
|
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),
|
|
129
|
+
{
|
|
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 {
|
|
116
150
|
constructor(o, u) {
|
|
117
|
-
|
|
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", () => {
|
|
118
152
|
{
|
|
119
153
|
const a = this.inputStream.getTracks();
|
|
120
154
|
for (const n of a)
|
|
121
155
|
n.stop(), this.inputStream.removeTrack(n);
|
|
122
156
|
}
|
|
123
|
-
}),
|
|
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) => {
|
|
124
162
|
a ? this.analyserNode.disconnect(this.outputGainNode) : this.analyserNode.connect(this.outputGainNode);
|
|
125
|
-
}),
|
|
163
|
+
}), m(this, "setInputGain", (a) => {
|
|
126
164
|
this.inputGain = a, this.inputGainNode.gain.setValueAtTime(a, this.audioContext.currentTime);
|
|
127
|
-
}),
|
|
165
|
+
}), m(this, "setEnhanceGain", async (a) => {
|
|
128
166
|
this.enhanceGain = a + 1, this.enhanceGainNode.gain.setValueAtTime(this.enhanceGain, this.audioContext.currentTime);
|
|
129
|
-
}),
|
|
167
|
+
}), m(this, "setBgsGain", (a) => {
|
|
130
168
|
this.bgsGain = a, this.bgsGainNode.gain.setValueAtTime(a, this.audioContext.currentTime);
|
|
131
|
-
}),
|
|
169
|
+
}), m(this, "setBgmGain", (a) => {
|
|
132
170
|
this.bgmGain = a, this.bgmGainNode.gain.setValueAtTime(a, this.audioContext.currentTime);
|
|
133
|
-
}),
|
|
171
|
+
}), m(this, "setOutputGain", (a) => {
|
|
134
172
|
this.outputGain = a, this.outputGainNode.gain.setValueAtTime(this.outputGain, this.audioContext.currentTime);
|
|
135
|
-
}),
|
|
173
|
+
}), m(this, "getVolume", () => {
|
|
136
174
|
const { analyserNode: a, analyserArrayData: n } = this;
|
|
137
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
|
-
}),
|
|
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);
|
|
@@ -152,16 +190,16 @@ class O {
|
|
|
152
190
|
} catch (t) {
|
|
153
191
|
i(t);
|
|
154
192
|
}
|
|
155
|
-
})),
|
|
193
|
+
})), m(this, "mixAudioStop", (a) => {
|
|
156
194
|
const n = this.mixAudioMap.get(a);
|
|
157
195
|
n == null || n.stop();
|
|
158
|
-
}),
|
|
196
|
+
}), m(this, "changeMix", (a, n) => {
|
|
159
197
|
const r = a === "bgs" ? this.bgsGainNode : this.bgmGainNode;
|
|
160
198
|
n ? r.connect(this.destinationNode) : r.disconnect(this.destinationNode);
|
|
161
|
-
}), u && (this.audioContext = u), 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: a,
|
|
164
|
-
a.connect(n), n.connect(r), r.connect(
|
|
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
|
}
|
|
@@ -202,18 +240,18 @@ const E = async (h, o) => {
|
|
|
202
240
|
throw console.error("Failed to convert AudioData to AudioBuffer:", u), u;
|
|
203
241
|
}
|
|
204
242
|
};
|
|
205
|
-
class
|
|
243
|
+
class O {
|
|
206
244
|
constructor() {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
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
|
|
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
|
-
|
|
254
|
+
y(this, "getStream", () => {
|
|
217
255
|
var o;
|
|
218
256
|
return (o = this.prAudioStream) == null ? void 0 : o.getStream();
|
|
219
257
|
});
|
|
@@ -237,56 +275,18 @@ class W {
|
|
|
237
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
|
|
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 u = new Worker(o, {
|
|
247
|
-
name: h == null ? void 0 : h.name
|
|
248
|
-
});
|
|
249
|
-
return u.addEventListener("error", () => {
|
|
250
|
-
(self.URL || self.webkitURL).revokeObjectURL(o);
|
|
251
|
-
}), u;
|
|
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
|
-
},
|
|
281
|
+
}, z = (h) => {
|
|
277
282
|
const o = (h == null ? void 0 : h.getTracks()) || [];
|
|
278
283
|
for (const u of o)
|
|
279
284
|
u.stop();
|
|
280
|
-
}, A = () => {
|
|
281
|
-
const h = new MediaStreamTrackGenerator({ kind: "video" }), o = new MediaStream([h]), u = new z();
|
|
282
|
-
return u.init({ writable: h.writable }), { worker: u, stream: o, destroy: () => {
|
|
283
|
-
u.destroy(), M(o);
|
|
284
|
-
} };
|
|
285
285
|
};
|
|
286
|
-
class
|
|
286
|
+
class q {
|
|
287
287
|
constructor() {
|
|
288
|
-
|
|
289
|
-
|
|
288
|
+
y(this, "resolvesMap", /* @__PURE__ */ new Map());
|
|
289
|
+
y(this, "index", 0);
|
|
290
290
|
/**
|
|
291
291
|
*
|
|
292
292
|
* @param eventKey 唯一key
|
|
@@ -294,7 +294,7 @@ class $ {
|
|
|
294
294
|
* @param timeout 超时时间 ms
|
|
295
295
|
* @returns
|
|
296
296
|
*/
|
|
297
|
-
|
|
297
|
+
y(this, "add", (o, u = () => !1, a = 0) => new Promise((n) => {
|
|
298
298
|
var t, e;
|
|
299
299
|
if (u()) return n(!0);
|
|
300
300
|
this.resolvesMap.has(o) || this.resolvesMap.set(o, /* @__PURE__ */ new Map()), this.index++;
|
|
@@ -308,7 +308,7 @@ class $ {
|
|
|
308
308
|
}, a);
|
|
309
309
|
(e = this.resolvesMap.get(o)) == null || e.set(r, { resolve: n, timer: i });
|
|
310
310
|
}));
|
|
311
|
-
|
|
311
|
+
y(this, "emit", async (o) => {
|
|
312
312
|
const u = this.resolvesMap.get(o);
|
|
313
313
|
if (!u) return;
|
|
314
314
|
const a = [...u.keys()];
|
|
@@ -319,7 +319,7 @@ class $ {
|
|
|
319
319
|
});
|
|
320
320
|
}
|
|
321
321
|
}
|
|
322
|
-
const
|
|
322
|
+
const X = (h) => {
|
|
323
323
|
const o = new DataView(h.buffer);
|
|
324
324
|
let u = 0, a, n, r;
|
|
325
325
|
a = o.getUint32(u, !1), u += 4;
|
|
@@ -333,85 +333,87 @@ const Y = (h) => {
|
|
|
333
333
|
}
|
|
334
334
|
return { size: a, header: n, data: r };
|
|
335
335
|
};
|
|
336
|
-
var P, U;
|
|
337
|
-
class
|
|
336
|
+
var P, U, J;
|
|
337
|
+
class A {
|
|
338
|
+
// 实例变量:统一管理当前请求的中止
|
|
338
339
|
constructor(o = {}) {
|
|
339
|
-
|
|
340
|
-
timeout: 5 * 1e3
|
|
340
|
+
K(this, P, {
|
|
341
|
+
timeout: 5 * 1e3,
|
|
342
|
+
check: !1
|
|
341
343
|
});
|
|
342
|
-
|
|
344
|
+
K(this, U, null);
|
|
343
345
|
/**
|
|
344
|
-
*
|
|
345
|
-
* @param input string | URL | Request
|
|
346
|
-
* @param init RequestInit
|
|
346
|
+
* 检查资源可用性(HEAD 请求)—— 用实例变量控制器
|
|
347
347
|
*/
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
this
|
|
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 =
|
|
354
|
-
},
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
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
|
-
|
|
369
|
-
var r;
|
|
370
|
+
y(this, "request", (o, u) => new Promise(async (a, n) => {
|
|
370
371
|
try {
|
|
371
|
-
|
|
372
|
-
const
|
|
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 });
|
|
373
374
|
a(i);
|
|
374
|
-
} catch (
|
|
375
|
-
|
|
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 =
|
|
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, { ...
|
|
386
|
+
H(this, P, { ...S(this, P), ...o });
|
|
386
387
|
}
|
|
387
388
|
}
|
|
388
|
-
P = new WeakMap(), U = new WeakMap();
|
|
389
|
-
class
|
|
389
|
+
P = new WeakMap(), U = new WeakMap(), J = new WeakMap();
|
|
390
|
+
class tt {
|
|
390
391
|
constructor(o = {}) {
|
|
391
|
-
|
|
392
|
+
y(this, "option", {
|
|
392
393
|
debug: !1,
|
|
393
394
|
frameTrack: !1
|
|
394
395
|
});
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
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
|
-
|
|
409
|
+
y(this, "trackGenerator");
|
|
408
410
|
/**
|
|
409
411
|
* 开始播放
|
|
410
412
|
* @param url : string
|
|
411
413
|
*/
|
|
412
|
-
|
|
414
|
+
y(this, "start", async (o) => {
|
|
413
415
|
await this.stop(), this.url = o;
|
|
414
|
-
const u =
|
|
416
|
+
const u = j(o);
|
|
415
417
|
if (u === "unknown") throw new Error("This address cannot be parsed.");
|
|
416
418
|
switch (this.init(u), u) {
|
|
417
419
|
case "flv":
|
|
@@ -425,64 +427,76 @@ class et {
|
|
|
425
427
|
/**
|
|
426
428
|
* 停止
|
|
427
429
|
*/
|
|
428
|
-
|
|
429
|
-
var u, a, n
|
|
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 (
|
|
433
|
-
console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m", "color:#0097ff;", "------->pr-player: error",
|
|
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
|
-
(
|
|
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
|
-
|
|
442
|
+
y(this, "getStream", () => this.stream);
|
|
445
443
|
/**
|
|
446
444
|
* 设置暂停
|
|
447
445
|
* @param pause: boolean
|
|
448
446
|
*/
|
|
449
|
-
|
|
447
|
+
y(this, "setPause", (o) => {
|
|
450
448
|
var u;
|
|
451
|
-
(u = this.renderWorker) == null || u.setPause(o);
|
|
449
|
+
(u = this.renderWorker) == null || u.setPause({ pause: o });
|
|
452
450
|
});
|
|
453
451
|
/**
|
|
454
452
|
* 是否静音 默认为true
|
|
455
453
|
* @param state?: boolean
|
|
456
454
|
*/
|
|
457
|
-
|
|
455
|
+
y(this, "setMute", (o) => {
|
|
458
456
|
var u, a;
|
|
459
457
|
return (a = (u = this.audioPlayer) == null ? void 0 : u.prAudioStream) == null ? void 0 : a.setMute(o);
|
|
460
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);
|
|
466
|
+
});
|
|
461
467
|
/**
|
|
462
468
|
* 是否开启追帧
|
|
463
469
|
* @param frameTrack?: boolean
|
|
464
470
|
*/
|
|
465
|
-
|
|
471
|
+
y(this, "setFrameTrack", (o) => {
|
|
466
472
|
var u;
|
|
467
473
|
this.option.frameTrack = o, (u = this.decoderWorker) == null || u.setFrameTrack(o);
|
|
468
474
|
});
|
|
469
475
|
/**
|
|
470
476
|
* 是否已准备好
|
|
471
477
|
*/
|
|
472
|
-
|
|
478
|
+
y(this, "isReady", () => {
|
|
473
479
|
const o = () => {
|
|
474
480
|
var u;
|
|
475
481
|
return ((u = this.stream) == null ? void 0 : u.active) === !0;
|
|
476
482
|
};
|
|
477
483
|
return this.prResolves.add("isReady", o);
|
|
478
484
|
});
|
|
479
|
-
|
|
485
|
+
y(this, "cut", {
|
|
480
486
|
/**
|
|
481
487
|
* 创建剪切
|
|
482
488
|
*/
|
|
483
489
|
create: (o, u) => {
|
|
484
|
-
|
|
485
|
-
|
|
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;
|
|
493
|
+
},
|
|
494
|
+
/**
|
|
495
|
+
* 设置剪切
|
|
496
|
+
*/
|
|
497
|
+
setCut: (o, u) => {
|
|
498
|
+
var a;
|
|
499
|
+
(a = this.renderWorker) == null || a.setCut({ key: o, cutOption: u });
|
|
486
500
|
},
|
|
487
501
|
/**
|
|
488
502
|
* 获取媒体流
|
|
@@ -491,33 +505,33 @@ class et {
|
|
|
491
505
|
var u;
|
|
492
506
|
return (u = this.cutRenders.get(o)) == null ? void 0 : u.stream;
|
|
493
507
|
},
|
|
508
|
+
/**
|
|
509
|
+
* 移除剪切
|
|
510
|
+
*/
|
|
511
|
+
remove: (o) => {
|
|
512
|
+
var u;
|
|
513
|
+
(u = this.renderWorker) == null || u.delCut(o), this.cutRenders.delete(o);
|
|
514
|
+
},
|
|
494
515
|
/**
|
|
495
516
|
* 设置暂停
|
|
496
517
|
* @param pause: boolean
|
|
497
518
|
*/
|
|
498
519
|
setPause: (o, u) => {
|
|
499
520
|
var a;
|
|
500
|
-
(a = this.
|
|
501
|
-
},
|
|
502
|
-
/**
|
|
503
|
-
* 移除剪切
|
|
504
|
-
*/
|
|
505
|
-
remove: (o) => {
|
|
506
|
-
var u;
|
|
507
|
-
(u = this.cutRenders.get(o)) == null || u.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
|
-
|
|
514
|
-
this.initDecoder(o), this.initRender(), this.initDemuxer(o), this.audioPlayer = new
|
|
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
|
-
|
|
520
|
-
this.demuxerWorker = new
|
|
533
|
+
y(this, "initDemuxer", (o) => {
|
|
534
|
+
this.demuxerWorker = new I(), this.demuxerWorker.init(o), this.demuxerWorker.on.debug = (u) => {
|
|
521
535
|
this.option.debug && this.on.debug && this.on.debug(u);
|
|
522
536
|
}, this.demuxerWorker.on.info = (u) => {
|
|
523
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);
|
|
@@ -561,8 +575,8 @@ class et {
|
|
|
561
575
|
/**
|
|
562
576
|
* 初始化解码器
|
|
563
577
|
*/
|
|
564
|
-
|
|
565
|
-
this.decoderWorker = new
|
|
578
|
+
y(this, "initDecoder", (o) => {
|
|
579
|
+
this.decoderWorker = new L(), this.decoderWorker.init(o);
|
|
566
580
|
const { frameTrack: u = !1 } = this.option;
|
|
567
581
|
this.decoderWorker.setFrameTrack(u), this.decoderWorker.on.audio.decode = (a) => {
|
|
568
582
|
var n;
|
|
@@ -570,18 +584,14 @@ class et {
|
|
|
570
584
|
}, this.decoderWorker.on.audio.error = (a) => {
|
|
571
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);
|
|
572
586
|
}, this.decoderWorker.on.video.decode = async (a) => {
|
|
573
|
-
var
|
|
574
|
-
(
|
|
575
|
-
const n = [...this.cutRenders.keys()];
|
|
576
|
-
for (const t of n)
|
|
577
|
-
(i = this.cutRenders.get(t)) == null || i.worker.push(a);
|
|
578
|
-
this.on.decoder.video && this.on.decoder.video(a), a.bitmap.close();
|
|
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);
|
|
579
589
|
}, this.decoderWorker.on.video.error = (a) => {
|
|
580
590
|
this.on.error && this.on.error(a);
|
|
581
591
|
}, this.decoderWorker.on.nalus = async (a) => {
|
|
582
592
|
for (const n of a) {
|
|
583
593
|
if (n.byteLength <= 4) continue;
|
|
584
|
-
const { header: r, data: i } =
|
|
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
597
|
}, this.decoderWorker.on.analysis = (a) => {
|
|
@@ -591,29 +601,41 @@ class et {
|
|
|
591
601
|
/**
|
|
592
602
|
* 初始化渲染器
|
|
593
603
|
*/
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
this.renderWorker =
|
|
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
|
-
|
|
599
|
-
start: async () => {
|
|
600
|
-
var
|
|
610
|
+
y(this, "flv", {
|
|
611
|
+
start: () => new Promise(async (o, u) => {
|
|
612
|
+
var a, n;
|
|
601
613
|
try {
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
const n = (o = a.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
|
-
|
|
608
|
-
|
|
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));
|
|
625
|
+
}
|
|
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;
|
|
609
632
|
}
|
|
610
|
-
} catch (
|
|
611
|
-
|
|
612
|
-
this.on.error && this.on.error(a);
|
|
633
|
+
} catch (r) {
|
|
634
|
+
r.name !== "AbortError" && u(r);
|
|
613
635
|
}
|
|
614
|
-
}
|
|
636
|
+
})
|
|
615
637
|
});
|
|
616
|
-
|
|
638
|
+
y(this, "hls", {
|
|
617
639
|
isLive: !1,
|
|
618
640
|
urls: [],
|
|
619
641
|
url: "",
|
|
@@ -634,45 +656,55 @@ class et {
|
|
|
634
656
|
getSegments: async () => {
|
|
635
657
|
var o;
|
|
636
658
|
try {
|
|
637
|
-
let u =
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
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:
|
|
643
|
-
if (
|
|
644
|
-
const
|
|
645
|
-
this.hls.isLive =
|
|
646
|
-
let
|
|
647
|
-
const
|
|
648
|
-
|
|
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 (
|
|
682
|
+
if (r || this.url === "") break;
|
|
651
683
|
}
|
|
652
684
|
} catch (u) {
|
|
653
|
-
this.on.error && this.on.error(u);
|
|
685
|
+
u.name !== "AbortError" && this.on.error && this.on.error(u);
|
|
654
686
|
}
|
|
655
687
|
},
|
|
656
|
-
start: async () => {
|
|
657
|
-
var
|
|
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), (
|
|
660
|
-
const
|
|
661
|
-
if (
|
|
662
|
-
this.hls.url =
|
|
663
|
-
const
|
|
664
|
-
if (!
|
|
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:
|
|
667
|
-
if (
|
|
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((
|
|
702
|
+
await new Promise((t) => setTimeout(() => t(!0), 300));
|
|
671
703
|
}
|
|
672
|
-
} catch (
|
|
673
|
-
|
|
704
|
+
} catch (i) {
|
|
705
|
+
i.name !== "AbortError" && u(i);
|
|
674
706
|
}
|
|
675
|
-
}
|
|
707
|
+
})
|
|
676
708
|
});
|
|
677
709
|
const { debug: u = !1 } = o;
|
|
678
710
|
this.option.debug = u;
|
|
@@ -1244,8 +1276,8 @@ 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
|
|
1248
|
-
k[T +
|
|
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;
|
|
@@ -2336,21 +2368,21 @@ const $Reader = minimalExports.Reader, $Writer = minimalExports.Writer, $util =
|
|
|
2336
2368
|
});
|
|
2337
2369
|
class RoomUser {
|
|
2338
2370
|
constructor() {
|
|
2339
|
-
|
|
2340
|
-
|
|
2371
|
+
y(this, "userId", "");
|
|
2372
|
+
y(this, "mc_audio");
|
|
2341
2373
|
// 麦克风
|
|
2342
|
-
|
|
2374
|
+
y(this, "mc_video");
|
|
2343
2375
|
// 摄像头
|
|
2344
|
-
|
|
2376
|
+
y(this, "ss_audio");
|
|
2345
2377
|
// 屏幕共享视频
|
|
2346
|
-
|
|
2378
|
+
y(this, "ss_video");
|
|
2347
2379
|
// 屏幕共享音频
|
|
2348
|
-
|
|
2349
|
-
|
|
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
|
-
|
|
2385
|
+
y(this, "init", (o) => {
|
|
2354
2386
|
var t, e, s, l;
|
|
2355
2387
|
const { id: u, audios: a = [], videos: n = [] } = o;
|
|
2356
2388
|
this.userId = u;
|
|
@@ -2394,9 +2426,8 @@ class RoomUser {
|
|
|
2394
2426
|
const i = this.getUpdateTimeKey();
|
|
2395
2427
|
r !== i && (this.updateTime = (/* @__PURE__ */ new Date()).getTime());
|
|
2396
2428
|
});
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
(o = this.mc_video) != null && o.destroy && this.mc_video.destroy(), (u = this.ss_video) != null && u.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
|
}
|
|
@@ -2429,82 +2460,80 @@ const parseSEI = (h) => {
|
|
|
2429
2460
|
};
|
|
2430
2461
|
class QuickVoPlayer {
|
|
2431
2462
|
constructor(o = {}) {
|
|
2432
|
-
|
|
2463
|
+
y(this, "option", {
|
|
2433
2464
|
debug: !1,
|
|
2434
2465
|
ws: "wss://livep2p.devplay.cc/websocket"
|
|
2435
2466
|
});
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
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
|
-
|
|
2446
|
-
|
|
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
|
-
|
|
2453
|
-
|
|
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
|
-
|
|
2487
|
+
y(this, "setMute", (o) => {
|
|
2457
2488
|
this.prPlayer.setMute(o);
|
|
2458
2489
|
});
|
|
2459
|
-
|
|
2460
|
-
|
|
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
2497
|
return Array.from(o, (a) => a.updateTime).join("_");
|
|
2463
2498
|
});
|
|
2464
|
-
|
|
2465
|
-
var n, r;
|
|
2499
|
+
y(this, "checkAndCreateUser", (o, u) => {
|
|
2466
2500
|
!this.usersMap.has(o) && this.usersMap.set(o, new RoomUser());
|
|
2467
2501
|
const a = this.usersMap.get(o);
|
|
2468
2502
|
if (a) {
|
|
2469
|
-
if (a.init(u), a.mc_video && a.mc_video.
|
|
2470
|
-
const { sx:
|
|
2471
|
-
|
|
2472
|
-
p(), this.prPlayer.cut.remove(l), a.mc_video = void 0;
|
|
2473
|
-
};
|
|
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;
|
|
2474
2506
|
}
|
|
2475
|
-
if (a.ss_video && a.ss_video.
|
|
2476
|
-
const { sx:
|
|
2477
|
-
|
|
2478
|
-
p(), this.prPlayer.cut.remove(l), a.ss_video = void 0;
|
|
2479
|
-
};
|
|
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;
|
|
2480
2510
|
}
|
|
2481
2511
|
if (a != null && a.mc_video) {
|
|
2482
|
-
const { sx:
|
|
2483
|
-
|
|
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 });
|
|
2484
2514
|
}
|
|
2485
2515
|
if (a != null && a.ss_video) {
|
|
2486
|
-
const { sx:
|
|
2487
|
-
|
|
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 });
|
|
2488
2518
|
}
|
|
2489
2519
|
}
|
|
2490
2520
|
});
|
|
2491
|
-
|
|
2492
|
-
var u, a, n, r, i, t, e, s;
|
|
2521
|
+
y(this, "setDisplayMode", (o) => {
|
|
2493
2522
|
switch (this.displayMode = o, o) {
|
|
2494
2523
|
case "original":
|
|
2495
2524
|
{
|
|
2496
2525
|
this.prPlayer.setPause(!1);
|
|
2497
|
-
const
|
|
2498
|
-
for (const
|
|
2499
|
-
|
|
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);
|
|
2500
2529
|
}
|
|
2501
2530
|
break;
|
|
2502
2531
|
case "cut":
|
|
2503
2532
|
{
|
|
2504
2533
|
this.prPlayer.setPause(!0);
|
|
2505
|
-
const
|
|
2506
|
-
for (const
|
|
2507
|
-
|
|
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);
|
|
2508
2537
|
}
|
|
2509
2538
|
break;
|
|
2510
2539
|
}
|
|
@@ -2512,7 +2541,7 @@ class QuickVoPlayer {
|
|
|
2512
2541
|
/**
|
|
2513
2542
|
* 监听SEI信息
|
|
2514
2543
|
*/
|
|
2515
|
-
|
|
2544
|
+
y(this, "onSEI", (o) => {
|
|
2516
2545
|
try {
|
|
2517
2546
|
const u = parseSEI(o);
|
|
2518
2547
|
if (!u) return;
|
|
@@ -2524,9 +2553,9 @@ class QuickVoPlayer {
|
|
|
2524
2553
|
if (r !== this.room.roomId) return;
|
|
2525
2554
|
const t = this.getAllUseUpdateKey(), e = Object.keys(i);
|
|
2526
2555
|
{
|
|
2527
|
-
const l = [...this.usersMap.
|
|
2556
|
+
const l = [...this.usersMap.keys()];
|
|
2528
2557
|
for (const c of l)
|
|
2529
|
-
e.includes(c
|
|
2558
|
+
e.includes(c) || (this.prPlayer.cut.remove(`${c}_mc_video`), this.prPlayer.cut.remove(`${c}_ss_video`), this.usersMap.delete(c));
|
|
2530
2559
|
}
|
|
2531
2560
|
for (const l of e) {
|
|
2532
2561
|
const c = i[l];
|
|
@@ -2550,11 +2579,21 @@ class QuickVoPlayer {
|
|
|
2550
2579
|
console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m", "color:#0097ff;", "------->onSEI: error", u);
|
|
2551
2580
|
}
|
|
2552
2581
|
});
|
|
2553
|
-
|
|
2582
|
+
y(this, "onAnalysis", (o) => {
|
|
2554
2583
|
this.on.analysis && this.on.analysis(o);
|
|
2555
2584
|
});
|
|
2556
|
-
const
|
|
2557
|
-
|
|
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) => {
|
|
2558
2597
|
}, this.prPlayer.on.decoder.sei = this.onSEI, this.prPlayer.on.decoder.analysis = this.onAnalysis;
|
|
2559
2598
|
}
|
|
2560
2599
|
}
|