quickvo-player 0.1.4 → 0.1.6
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 +11 -311
- package/dist/QuickVoPlayer.d.ts +0 -1
- package/dist/index.js +155 -156
- package/dist/index.umd.cjs +4 -4
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var X = (h) => {
|
|
|
3
3
|
throw TypeError(h);
|
|
4
4
|
};
|
|
5
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
|
|
6
|
+
var g = (h, o, a) => tt(h, typeof o != "symbol" ? o + "" : o, a), Z = (h, o, a) => o.has(h) || X("Cannot " + a);
|
|
7
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
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;on={};parser;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.debug=y=>postMessage({action:"onDebug",data:y}),A.on.info=y=>postMessage({action:"onInfo",data:y}),A.on.config=y=>postMessage({action:"onConfig",data:y}),A.on.chunk=y=>postMessage({action:"onChunk",data:y}),onmessage=y=>{const{action:t,data:s}=y.data,e=A[t];e&&e(s)}})();\n', T = typeof self < "u" && self.Blob && new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);", D], { type: "text/javascript;charset=utf-8" });
|
|
9
9
|
function L(h) {
|
|
@@ -27,11 +27,11 @@ function L(h) {
|
|
|
27
27
|
}
|
|
28
28
|
class N {
|
|
29
29
|
constructor() {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
g(this, "worker", new L());
|
|
31
|
+
g(this, "on", {});
|
|
32
|
+
g(this, "init", (o) => this.worker.postMessage({ action: "init", data: o }));
|
|
33
|
+
g(this, "push", (o) => this.worker.postMessage({ action: "push", data: o }));
|
|
34
|
+
g(this, "destroy", () => {
|
|
35
35
|
this.worker.postMessage({ action: "destroy", data: {} }), this.worker.terminate();
|
|
36
36
|
});
|
|
37
37
|
this.worker.onmessage = (o) => {
|
|
@@ -76,11 +76,11 @@ function F(h) {
|
|
|
76
76
|
}
|
|
77
77
|
class B {
|
|
78
78
|
constructor() {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
79
|
+
g(this, "worker", new F());
|
|
80
|
+
g(this, "on", { audio: {}, video: {} });
|
|
81
|
+
g(this, "init", (o) => this.worker.postMessage({ action: "init", data: o }));
|
|
82
|
+
g(this, "setFrameTrack", (o) => this.worker.postMessage({ action: "setFrameTrack", data: o }));
|
|
83
|
+
g(this, "audio", {
|
|
84
84
|
init: (o) => this.worker.postMessage({ type: "audio", action: "init", data: o }),
|
|
85
85
|
push: (o) => this.worker.postMessage({ type: "audio", action: "push", data: o }),
|
|
86
86
|
flush: () => this.worker.postMessage({ type: "audio", action: "flush" }),
|
|
@@ -88,7 +88,7 @@ class B {
|
|
|
88
88
|
this.worker.postMessage({ type: "audio", action: "destroy" });
|
|
89
89
|
}
|
|
90
90
|
});
|
|
91
|
-
|
|
91
|
+
g(this, "video", {
|
|
92
92
|
init: (o) => this.worker.postMessage({ type: "video", action: "init", data: o }),
|
|
93
93
|
push: (o) => this.worker.postMessage({ type: "video", action: "push", data: o }),
|
|
94
94
|
flush: () => this.worker.postMessage({ type: "video", action: "flush" }),
|
|
@@ -96,7 +96,7 @@ class B {
|
|
|
96
96
|
this.worker.postMessage({ type: "video", action: "destroy", data: {} });
|
|
97
97
|
}
|
|
98
98
|
});
|
|
99
|
-
|
|
99
|
+
g(this, "destroy", () => {
|
|
100
100
|
this.worker.postMessage({ action: "destroy" }), this.worker.terminate();
|
|
101
101
|
});
|
|
102
102
|
this.worker.onmessage = (o) => {
|
|
@@ -205,16 +205,16 @@ const V = async (h, o) => {
|
|
|
205
205
|
};
|
|
206
206
|
class W {
|
|
207
207
|
constructor() {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
208
|
+
g(this, "prAudioStream");
|
|
209
|
+
g(this, "audioContext");
|
|
210
|
+
g(this, "destination");
|
|
211
|
+
g(this, "stream", new MediaStream());
|
|
212
|
+
g(this, "nextStartTime", 0);
|
|
213
|
+
g(this, "pendingSources", []);
|
|
214
|
+
g(this, "init", (o) => {
|
|
215
215
|
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 = [];
|
|
216
216
|
});
|
|
217
|
-
|
|
217
|
+
g(this, "getStream", () => {
|
|
218
218
|
var o;
|
|
219
219
|
return (o = this.prAudioStream) == null ? void 0 : o.getStream();
|
|
220
220
|
});
|
|
@@ -223,13 +223,15 @@ class W {
|
|
|
223
223
|
const { audioData: a, playbackRate: u = 1 } = o;
|
|
224
224
|
try {
|
|
225
225
|
if (!this.audioContext || !this.destination) return;
|
|
226
|
-
|
|
226
|
+
let r = await V(this.audioContext, a);
|
|
227
227
|
if (!r) return;
|
|
228
228
|
const n = this.audioContext.createBufferSource();
|
|
229
|
-
n.buffer = r, n.playbackRate.value = u
|
|
230
|
-
const i = Math.
|
|
231
|
-
|
|
232
|
-
|
|
229
|
+
n.buffer = r, n.playbackRate.value = u;
|
|
230
|
+
const i = -1200 * Math.log2(u);
|
|
231
|
+
n.detune.value = i, n.connect(this.destination);
|
|
232
|
+
const t = Math.max(this.nextStartTime, this.audioContext.currentTime), e = r.duration / u;
|
|
233
|
+
this.nextStartTime = t + e, n.start(t), this.pendingSources.push(n), n.onended = () => {
|
|
234
|
+
this.pendingSources = this.pendingSources.filter((s) => s !== n);
|
|
233
235
|
}, this.audioContext.state === "suspended" && await this.audioContext.resume();
|
|
234
236
|
} finally {
|
|
235
237
|
a.close();
|
|
@@ -263,12 +265,12 @@ function j(h) {
|
|
|
263
265
|
}
|
|
264
266
|
class z {
|
|
265
267
|
constructor() {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
268
|
+
g(this, "worker", new j());
|
|
269
|
+
g(this, "init", ({ writable: o }) => this.worker.postMessage({ action: "init", data: { writable: o } }, [o]));
|
|
270
|
+
g(this, "push", (o) => this.worker.postMessage({ action: "push", data: o }));
|
|
271
|
+
g(this, "setCut", async (o) => this.worker.postMessage({ action: "setCut", data: o }));
|
|
272
|
+
g(this, "setPause", (o) => this.worker.postMessage({ action: "setPause", data: o }));
|
|
273
|
+
g(this, "destroy", () => {
|
|
272
274
|
this.worker.postMessage({ action: "destroy", data: {} }), this.worker.terminate();
|
|
273
275
|
});
|
|
274
276
|
}
|
|
@@ -288,8 +290,8 @@ const q = (h) => {
|
|
|
288
290
|
};
|
|
289
291
|
class $ {
|
|
290
292
|
constructor() {
|
|
291
|
-
|
|
292
|
-
|
|
293
|
+
g(this, "resolvesMap", /* @__PURE__ */ new Map());
|
|
294
|
+
g(this, "index", 0);
|
|
293
295
|
/**
|
|
294
296
|
*
|
|
295
297
|
* @param eventKey 唯一key
|
|
@@ -297,7 +299,7 @@ class $ {
|
|
|
297
299
|
* @param timeout 超时时间 ms
|
|
298
300
|
* @returns
|
|
299
301
|
*/
|
|
300
|
-
|
|
302
|
+
g(this, "add", (o, a = () => !1, u = 0) => new Promise((r) => {
|
|
301
303
|
var t, e;
|
|
302
304
|
if (a()) return r(!0);
|
|
303
305
|
this.resolvesMap.has(o) || this.resolvesMap.set(o, /* @__PURE__ */ new Map()), this.index++;
|
|
@@ -311,7 +313,7 @@ class $ {
|
|
|
311
313
|
}, u);
|
|
312
314
|
(e = this.resolvesMap.get(o)) == null || e.set(n, { resolve: r, timer: i });
|
|
313
315
|
}));
|
|
314
|
-
|
|
316
|
+
g(this, "emit", async (o) => {
|
|
315
317
|
const a = this.resolvesMap.get(o);
|
|
316
318
|
if (!a) return;
|
|
317
319
|
const u = [...a.keys()];
|
|
@@ -349,7 +351,7 @@ class C {
|
|
|
349
351
|
* @param input string | URL | Request
|
|
350
352
|
* @param init RequestInit
|
|
351
353
|
*/
|
|
352
|
-
|
|
354
|
+
g(this, "check", (o, a) => new Promise(async (u, r) => {
|
|
353
355
|
var i;
|
|
354
356
|
this.stop(), H(this, U, new AbortController());
|
|
355
357
|
const n = window.setTimeout(() => {
|
|
@@ -369,7 +371,7 @@ class C {
|
|
|
369
371
|
* @param input string | URL | Request
|
|
370
372
|
* @param init RequestInit
|
|
371
373
|
*/
|
|
372
|
-
|
|
374
|
+
g(this, "request", async (o, a) => new Promise(async (u, r) => {
|
|
373
375
|
var n;
|
|
374
376
|
try {
|
|
375
377
|
I(this, R).check && await this.check(o, a), H(this, U, new AbortController());
|
|
@@ -382,7 +384,7 @@ class C {
|
|
|
382
384
|
/**
|
|
383
385
|
* stop
|
|
384
386
|
*/
|
|
385
|
-
|
|
387
|
+
g(this, "stop", () => {
|
|
386
388
|
var o;
|
|
387
389
|
((o = I(this, U)) == null ? void 0 : o.signal.aborted) === !1 && I(this, U).abort("Actively stop.");
|
|
388
390
|
});
|
|
@@ -392,33 +394,33 @@ class C {
|
|
|
392
394
|
R = new WeakMap(), U = new WeakMap();
|
|
393
395
|
class et {
|
|
394
396
|
constructor(o = {}) {
|
|
395
|
-
|
|
397
|
+
g(this, "option", {
|
|
396
398
|
debug: !1,
|
|
397
399
|
frameTrack: !1
|
|
398
400
|
});
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
401
|
+
g(this, "prFetch", new C());
|
|
402
|
+
g(this, "prResolves", new $());
|
|
403
|
+
g(this, "url", "");
|
|
404
|
+
g(this, "demuxerWorker");
|
|
405
|
+
g(this, "decoderWorker");
|
|
406
|
+
g(this, "audioPlayer");
|
|
407
|
+
g(this, "renderWorker");
|
|
408
|
+
g(this, "stream");
|
|
409
|
+
g(this, "on", { demuxer: {}, decoder: {} });
|
|
410
|
+
g(this, "cutRenders", /* @__PURE__ */ new Map());
|
|
409
411
|
// @ts-ignore
|
|
410
|
-
|
|
412
|
+
g(this, "trackGenerator");
|
|
411
413
|
/**
|
|
412
414
|
* 初始化
|
|
413
415
|
*/
|
|
414
|
-
|
|
416
|
+
g(this, "init", () => {
|
|
415
417
|
this.initDecoder(), this.initRender(), this.audioPlayer = new W(), this.audioPlayer.init();
|
|
416
418
|
});
|
|
417
419
|
/**
|
|
418
420
|
* 开始播放
|
|
419
421
|
* @param url : string
|
|
420
422
|
*/
|
|
421
|
-
|
|
423
|
+
g(this, "start", async (o) => {
|
|
422
424
|
this.stop(), this.url = o, this.init();
|
|
423
425
|
const a = q(o);
|
|
424
426
|
if (a === "unknown") throw new Error("This address cannot be parsed.");
|
|
@@ -434,7 +436,7 @@ class et {
|
|
|
434
436
|
/**
|
|
435
437
|
* 停止
|
|
436
438
|
*/
|
|
437
|
-
|
|
439
|
+
g(this, "stop", async () => {
|
|
438
440
|
var a, u, r, n, i;
|
|
439
441
|
try {
|
|
440
442
|
clearInterval(this.hls.getSegmentsTimer), this.prFetch.stop();
|
|
@@ -450,12 +452,12 @@ class et {
|
|
|
450
452
|
/**
|
|
451
453
|
* 获取媒体流
|
|
452
454
|
*/
|
|
453
|
-
|
|
455
|
+
g(this, "getStream", () => this.stream);
|
|
454
456
|
/**
|
|
455
457
|
* 设置暂停
|
|
456
458
|
* @param pause: boolean
|
|
457
459
|
*/
|
|
458
|
-
|
|
460
|
+
g(this, "setPause", (o) => {
|
|
459
461
|
var a;
|
|
460
462
|
(a = this.renderWorker) == null || a.setPause(o);
|
|
461
463
|
});
|
|
@@ -463,7 +465,7 @@ class et {
|
|
|
463
465
|
* 是否静音 默认为true
|
|
464
466
|
* @param state?: boolean
|
|
465
467
|
*/
|
|
466
|
-
|
|
468
|
+
g(this, "setMute", (o) => {
|
|
467
469
|
var a, u;
|
|
468
470
|
return (u = (a = this.audioPlayer) == null ? void 0 : a.prAudioStream) == null ? void 0 : u.setMute(o);
|
|
469
471
|
});
|
|
@@ -471,14 +473,14 @@ class et {
|
|
|
471
473
|
* 是否开启追帧
|
|
472
474
|
* @param frameTrack?: boolean
|
|
473
475
|
*/
|
|
474
|
-
|
|
476
|
+
g(this, "setFrameTrack", (o) => {
|
|
475
477
|
var a;
|
|
476
478
|
(a = this.decoderWorker) == null || a.setFrameTrack(o);
|
|
477
479
|
});
|
|
478
480
|
/**
|
|
479
481
|
* 是否已准备好
|
|
480
482
|
*/
|
|
481
|
-
|
|
483
|
+
g(this, "isReady", () => {
|
|
482
484
|
const o = () => {
|
|
483
485
|
var a;
|
|
484
486
|
return ((a = this.stream) == null ? void 0 : a.active) === !0;
|
|
@@ -488,7 +490,7 @@ class et {
|
|
|
488
490
|
/**
|
|
489
491
|
* 初始化解复器
|
|
490
492
|
*/
|
|
491
|
-
|
|
493
|
+
g(this, "initDemuxer", (o) => {
|
|
492
494
|
this.demuxerWorker = new N(), this.demuxerWorker.init(o), this.demuxerWorker.on.debug = (a) => {
|
|
493
495
|
this.option.debug && console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m", "color:#0097ff;", "------->pr-player: debug", a);
|
|
494
496
|
}, this.demuxerWorker.on.info = (a) => {
|
|
@@ -541,7 +543,7 @@ class et {
|
|
|
541
543
|
/**
|
|
542
544
|
* 初始化解码器
|
|
543
545
|
*/
|
|
544
|
-
|
|
546
|
+
g(this, "initDecoder", () => {
|
|
545
547
|
this.decoderWorker = new B(), this.decoderWorker.on.audio.decode = (o) => {
|
|
546
548
|
var a;
|
|
547
549
|
(a = this.audioPlayer) == null || a.push(o), this.on.decoder.audio && this.on.decoder.audio(o);
|
|
@@ -561,11 +563,11 @@ class et {
|
|
|
561
563
|
/**
|
|
562
564
|
* 初始化渲染器
|
|
563
565
|
*/
|
|
564
|
-
|
|
566
|
+
g(this, "initRender", () => {
|
|
565
567
|
const { worker: o, stream: a } = A();
|
|
566
568
|
this.renderWorker = o, this.stream = a, this.renderWorker.setPause(!1);
|
|
567
569
|
});
|
|
568
|
-
|
|
570
|
+
g(this, "cut", {
|
|
569
571
|
/**
|
|
570
572
|
* 创建剪切
|
|
571
573
|
*/
|
|
@@ -596,7 +598,7 @@ class et {
|
|
|
596
598
|
(a = this.cutRenders.get(o)) == null || a.destroy(), this.cutRenders.delete(o);
|
|
597
599
|
}
|
|
598
600
|
});
|
|
599
|
-
|
|
601
|
+
g(this, "flv", {
|
|
600
602
|
start: async () => {
|
|
601
603
|
var o, a;
|
|
602
604
|
try {
|
|
@@ -614,7 +616,7 @@ class et {
|
|
|
614
616
|
}
|
|
615
617
|
}
|
|
616
618
|
});
|
|
617
|
-
|
|
619
|
+
g(this, "hls", {
|
|
618
620
|
isLive: !1,
|
|
619
621
|
urls: [],
|
|
620
622
|
url: "",
|
|
@@ -894,8 +896,8 @@ function requireFloat() {
|
|
|
894
896
|
}
|
|
895
897
|
n.writeDoubleLE = i.bind(null, o, 0, 4), n.writeDoubleBE = i.bind(null, a, 4, 0);
|
|
896
898
|
function t(e, s, l, c, d) {
|
|
897
|
-
var p = e(c, d + s), f = e(c, d + l), w = (f >> 31) * 2 + 1, b = f >>> 20 & 2047,
|
|
898
|
-
return b === 2047 ?
|
|
899
|
+
var p = e(c, d + s), f = e(c, d + l), w = (f >> 31) * 2 + 1, b = f >>> 20 & 2047, m = 4294967296 * (f & 1048575) + p;
|
|
900
|
+
return b === 2047 ? m ? NaN : w * (1 / 0) : b === 0 ? w * 5e-324 * m : w * Math.pow(2, b - 1075) * (m + 4503599627370496);
|
|
899
901
|
}
|
|
900
902
|
n.readDoubleLE = t.bind(null, u, 0, 4), n.readDoubleBE = t.bind(null, r, 4, 0);
|
|
901
903
|
}(), n;
|
|
@@ -1168,8 +1170,8 @@ function requireWriter() {
|
|
|
1168
1170
|
if (hasRequiredWriter) return writer;
|
|
1169
1171
|
hasRequiredWriter = 1, writer = e;
|
|
1170
1172
|
var h = requireMinimal$1(), o, a = h.LongBits, u = h.base64, r = h.utf8;
|
|
1171
|
-
function n(b,
|
|
1172
|
-
this.fn = b, this.len =
|
|
1173
|
+
function n(b, m, k) {
|
|
1174
|
+
this.fn = b, this.len = m, this.next = void 0, this.val = k;
|
|
1173
1175
|
}
|
|
1174
1176
|
function i() {
|
|
1175
1177
|
}
|
|
@@ -1188,89 +1190,89 @@ function requireWriter() {
|
|
|
1188
1190
|
return new e();
|
|
1189
1191
|
};
|
|
1190
1192
|
};
|
|
1191
|
-
e.create = s(), e.alloc = function(
|
|
1192
|
-
return new h.Array(
|
|
1193
|
-
}, h.Array !== Array && (e.alloc = h.pool(e.alloc, h.Array.prototype.subarray)), e.prototype._push = function(
|
|
1194
|
-
return this.tail = this.tail.next = new n(
|
|
1193
|
+
e.create = s(), e.alloc = function(m) {
|
|
1194
|
+
return new h.Array(m);
|
|
1195
|
+
}, h.Array !== Array && (e.alloc = h.pool(e.alloc, h.Array.prototype.subarray)), e.prototype._push = function(m, k, _) {
|
|
1196
|
+
return this.tail = this.tail.next = new n(m, k, _), this.len += k, this;
|
|
1195
1197
|
};
|
|
1196
|
-
function l(b,
|
|
1197
|
-
|
|
1198
|
+
function l(b, m, k) {
|
|
1199
|
+
m[k] = b & 255;
|
|
1198
1200
|
}
|
|
1199
|
-
function c(b,
|
|
1201
|
+
function c(b, m, k) {
|
|
1200
1202
|
for (; b > 127; )
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
+
m[k++] = b & 127 | 128, b >>>= 7;
|
|
1204
|
+
m[k] = b;
|
|
1203
1205
|
}
|
|
1204
|
-
function d(b,
|
|
1205
|
-
this.len = b, this.next = void 0, this.val =
|
|
1206
|
+
function d(b, m) {
|
|
1207
|
+
this.len = b, this.next = void 0, this.val = m;
|
|
1206
1208
|
}
|
|
1207
|
-
d.prototype = Object.create(n.prototype), d.prototype.fn = c, e.prototype.uint32 = function(
|
|
1209
|
+
d.prototype = Object.create(n.prototype), d.prototype.fn = c, e.prototype.uint32 = function(m) {
|
|
1208
1210
|
return this.len += (this.tail = this.tail.next = new d(
|
|
1209
|
-
(
|
|
1210
|
-
|
|
1211
|
+
(m = m >>> 0) < 128 ? 1 : m < 16384 ? 2 : m < 2097152 ? 3 : m < 268435456 ? 4 : 5,
|
|
1212
|
+
m
|
|
1211
1213
|
)).len, this;
|
|
1212
|
-
}, e.prototype.int32 = function(
|
|
1213
|
-
return
|
|
1214
|
-
}, e.prototype.sint32 = function(
|
|
1215
|
-
return this.uint32((
|
|
1214
|
+
}, e.prototype.int32 = function(m) {
|
|
1215
|
+
return m < 0 ? this._push(p, 10, a.fromNumber(m)) : this.uint32(m);
|
|
1216
|
+
}, e.prototype.sint32 = function(m) {
|
|
1217
|
+
return this.uint32((m << 1 ^ m >> 31) >>> 0);
|
|
1216
1218
|
};
|
|
1217
|
-
function p(b,
|
|
1219
|
+
function p(b, m, k) {
|
|
1218
1220
|
for (; b.hi; )
|
|
1219
|
-
|
|
1221
|
+
m[k++] = b.lo & 127 | 128, b.lo = (b.lo >>> 7 | b.hi << 25) >>> 0, b.hi >>>= 7;
|
|
1220
1222
|
for (; b.lo > 127; )
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
+
m[k++] = b.lo & 127 | 128, b.lo = b.lo >>> 7;
|
|
1224
|
+
m[k++] = b.lo;
|
|
1223
1225
|
}
|
|
1224
|
-
e.prototype.uint64 = function(
|
|
1225
|
-
var k = a.from(
|
|
1226
|
+
e.prototype.uint64 = function(m) {
|
|
1227
|
+
var k = a.from(m);
|
|
1226
1228
|
return this._push(p, k.length(), k);
|
|
1227
|
-
}, e.prototype.int64 = e.prototype.uint64, e.prototype.sint64 = function(
|
|
1228
|
-
var k = a.from(
|
|
1229
|
+
}, e.prototype.int64 = e.prototype.uint64, e.prototype.sint64 = function(m) {
|
|
1230
|
+
var k = a.from(m).zzEncode();
|
|
1229
1231
|
return this._push(p, k.length(), k);
|
|
1230
|
-
}, e.prototype.bool = function(
|
|
1231
|
-
return this._push(l, 1,
|
|
1232
|
+
}, e.prototype.bool = function(m) {
|
|
1233
|
+
return this._push(l, 1, m ? 1 : 0);
|
|
1232
1234
|
};
|
|
1233
|
-
function f(b,
|
|
1234
|
-
|
|
1235
|
+
function f(b, m, k) {
|
|
1236
|
+
m[k] = b & 255, m[k + 1] = b >>> 8 & 255, m[k + 2] = b >>> 16 & 255, m[k + 3] = b >>> 24;
|
|
1235
1237
|
}
|
|
1236
|
-
e.prototype.fixed32 = function(
|
|
1237
|
-
return this._push(f, 4,
|
|
1238
|
-
}, e.prototype.sfixed32 = e.prototype.fixed32, e.prototype.fixed64 = function(
|
|
1239
|
-
var k = a.from(
|
|
1238
|
+
e.prototype.fixed32 = function(m) {
|
|
1239
|
+
return this._push(f, 4, m >>> 0);
|
|
1240
|
+
}, e.prototype.sfixed32 = e.prototype.fixed32, e.prototype.fixed64 = function(m) {
|
|
1241
|
+
var k = a.from(m);
|
|
1240
1242
|
return this._push(f, 4, k.lo)._push(f, 4, k.hi);
|
|
1241
|
-
}, e.prototype.sfixed64 = e.prototype.fixed64, e.prototype.float = function(
|
|
1242
|
-
return this._push(h.float.writeFloatLE, 4,
|
|
1243
|
-
}, e.prototype.double = function(
|
|
1244
|
-
return this._push(h.float.writeDoubleLE, 8,
|
|
1243
|
+
}, e.prototype.sfixed64 = e.prototype.fixed64, e.prototype.float = function(m) {
|
|
1244
|
+
return this._push(h.float.writeFloatLE, 4, m);
|
|
1245
|
+
}, e.prototype.double = function(m) {
|
|
1246
|
+
return this._push(h.float.writeDoubleLE, 8, m);
|
|
1245
1247
|
};
|
|
1246
|
-
var w = h.Array.prototype.set ? function(
|
|
1247
|
-
k.set(
|
|
1248
|
-
} : function(
|
|
1249
|
-
for (var K = 0; K <
|
|
1250
|
-
k[_ + K] =
|
|
1248
|
+
var w = h.Array.prototype.set ? function(m, k, _) {
|
|
1249
|
+
k.set(m, _);
|
|
1250
|
+
} : function(m, k, _) {
|
|
1251
|
+
for (var K = 0; K < m.length; ++K)
|
|
1252
|
+
k[_ + K] = m[K];
|
|
1251
1253
|
};
|
|
1252
|
-
return e.prototype.bytes = function(
|
|
1253
|
-
var k =
|
|
1254
|
+
return e.prototype.bytes = function(m) {
|
|
1255
|
+
var k = m.length >>> 0;
|
|
1254
1256
|
if (!k)
|
|
1255
1257
|
return this._push(l, 1, 0);
|
|
1256
|
-
if (h.isString(
|
|
1257
|
-
var _ = e.alloc(k = u.length(
|
|
1258
|
-
u.decode(
|
|
1258
|
+
if (h.isString(m)) {
|
|
1259
|
+
var _ = e.alloc(k = u.length(m));
|
|
1260
|
+
u.decode(m, _, 0), m = _;
|
|
1259
1261
|
}
|
|
1260
|
-
return this.uint32(k)._push(w, k,
|
|
1261
|
-
}, e.prototype.string = function(
|
|
1262
|
-
var k = r.length(
|
|
1263
|
-
return k ? this.uint32(k)._push(r.write, k,
|
|
1262
|
+
return this.uint32(k)._push(w, k, m);
|
|
1263
|
+
}, e.prototype.string = function(m) {
|
|
1264
|
+
var k = r.length(m);
|
|
1265
|
+
return k ? this.uint32(k)._push(r.write, k, m) : this._push(l, 1, 0);
|
|
1264
1266
|
}, e.prototype.fork = function() {
|
|
1265
1267
|
return this.states = new t(this), this.head = this.tail = new n(i, 0, 0), this.len = 0, this;
|
|
1266
1268
|
}, e.prototype.reset = function() {
|
|
1267
1269
|
return this.states ? (this.head = this.states.head, this.tail = this.states.tail, this.len = this.states.len, this.states = this.states.next) : (this.head = this.tail = new n(i, 0, 0), this.len = 0), this;
|
|
1268
1270
|
}, e.prototype.ldelim = function() {
|
|
1269
|
-
var
|
|
1270
|
-
return this.reset().uint32(_), _ && (this.tail.next =
|
|
1271
|
+
var m = this.head, k = this.tail, _ = this.len;
|
|
1272
|
+
return this.reset().uint32(_), _ && (this.tail.next = m.next, this.tail = k, this.len += _), this;
|
|
1271
1273
|
}, e.prototype.finish = function() {
|
|
1272
|
-
for (var
|
|
1273
|
-
|
|
1274
|
+
for (var m = this.head.next, k = this.constructor.alloc(this.len), _ = 0; m; )
|
|
1275
|
+
m.fn(m.val, k, _), _ += m.len, m = m.next;
|
|
1274
1276
|
return k;
|
|
1275
1277
|
}, e._configure = function(b) {
|
|
1276
1278
|
o = b, e.create = s(), o._configure();
|
|
@@ -2338,21 +2340,21 @@ const $Reader = minimalExports.Reader, $Writer = minimalExports.Writer, $util =
|
|
|
2338
2340
|
});
|
|
2339
2341
|
class RoomUser {
|
|
2340
2342
|
constructor() {
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
+
g(this, "userId", "");
|
|
2344
|
+
g(this, "mc_audio");
|
|
2343
2345
|
// 麦克风
|
|
2344
|
-
|
|
2346
|
+
g(this, "mc_video");
|
|
2345
2347
|
// 摄像头
|
|
2346
|
-
|
|
2348
|
+
g(this, "ss_audio");
|
|
2347
2349
|
// 屏幕共享视频
|
|
2348
|
-
|
|
2350
|
+
g(this, "ss_video");
|
|
2349
2351
|
// 屏幕共享音频
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
+
g(this, "updateTime", 0);
|
|
2353
|
+
g(this, "getUpdateTimeKey", () => {
|
|
2352
2354
|
const o = [];
|
|
2353
2355
|
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("_");
|
|
2354
2356
|
});
|
|
2355
|
-
|
|
2357
|
+
g(this, "init", (o) => {
|
|
2356
2358
|
var t, e, s, l;
|
|
2357
2359
|
const { id: a, audios: u = [], videos: r = [] } = o;
|
|
2358
2360
|
this.userId = a;
|
|
@@ -2376,18 +2378,18 @@ class RoomUser {
|
|
|
2376
2378
|
}
|
|
2377
2379
|
}
|
|
2378
2380
|
for (const c of r) {
|
|
2379
|
-
const { type: d = 0, isEnable: p, isMute: f, updateTime: w, width: b, height:
|
|
2381
|
+
const { type: d = 0, isEnable: p, isMute: f, updateTime: w, width: b, height: m, x: k, y: _ } = c;
|
|
2380
2382
|
switch (d) {
|
|
2381
2383
|
case 0:
|
|
2382
2384
|
{
|
|
2383
2385
|
if (this.mc_video || (this.mc_video = createVideoInfo()), this.mc_video.remove = !1, this.mc_video.updateTime === w) break;
|
|
2384
|
-
this.mc_video.isEnable = !!p, this.mc_video.isMute = !!f, this.mc_video.updateTime = Number(w) || 0, this.mc_video.sx = k || 0, this.mc_video.sy = _ || 0, this.mc_video.sw = b || 0, this.mc_video.sh =
|
|
2386
|
+
this.mc_video.isEnable = !!p, this.mc_video.isMute = !!f, this.mc_video.updateTime = Number(w) || 0, this.mc_video.sx = k || 0, this.mc_video.sy = _ || 0, this.mc_video.sw = b || 0, this.mc_video.sh = m || 0;
|
|
2385
2387
|
}
|
|
2386
2388
|
break;
|
|
2387
2389
|
case 1:
|
|
2388
2390
|
{
|
|
2389
2391
|
if (this.ss_video || (this.ss_video = createVideoInfo()), this.ss_video.remove = !1, this.ss_video.updateTime === w) break;
|
|
2390
|
-
this.ss_video.isEnable = !!p, this.ss_video.isMute = !!f, this.ss_video.updateTime = Number(w) || 0, this.ss_video.sx = k || 0, this.ss_video.sy = _ || 0, this.ss_video.sw = b || 0, this.ss_video.sh =
|
|
2392
|
+
this.ss_video.isEnable = !!p, this.ss_video.isMute = !!f, this.ss_video.updateTime = Number(w) || 0, this.ss_video.sx = k || 0, this.ss_video.sy = _ || 0, this.ss_video.sw = b || 0, this.ss_video.sh = m || 0;
|
|
2391
2393
|
}
|
|
2392
2394
|
break;
|
|
2393
2395
|
}
|
|
@@ -2396,7 +2398,7 @@ class RoomUser {
|
|
|
2396
2398
|
const i = this.getUpdateTimeKey();
|
|
2397
2399
|
n !== i && (this.updateTime = (/* @__PURE__ */ new Date()).getTime());
|
|
2398
2400
|
});
|
|
2399
|
-
|
|
2401
|
+
g(this, "destroy", () => {
|
|
2400
2402
|
var o, a;
|
|
2401
2403
|
(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;
|
|
2402
2404
|
});
|
|
@@ -2431,39 +2433,36 @@ const parseSEI = (h) => {
|
|
|
2431
2433
|
};
|
|
2432
2434
|
class QuickVoPlayer {
|
|
2433
2435
|
constructor(o = {}) {
|
|
2434
|
-
|
|
2436
|
+
g(this, "option", {
|
|
2435
2437
|
debug: !1
|
|
2436
2438
|
});
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2439
|
+
g(this, "displayMode", "original");
|
|
2440
|
+
g(this, "prPlayer");
|
|
2441
|
+
g(this, "dom");
|
|
2442
|
+
g(this, "room", {
|
|
2441
2443
|
roomId: "",
|
|
2442
2444
|
updateTime: "",
|
|
2443
2445
|
author: "",
|
|
2444
2446
|
version: ""
|
|
2445
2447
|
});
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
+
g(this, "usersMap", /* @__PURE__ */ new Map());
|
|
2449
|
+
g(this, "on", {
|
|
2448
2450
|
users: (o) => {
|
|
2449
2451
|
}
|
|
2450
2452
|
});
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
});
|
|
2454
|
-
m(this, "start", async (o) => (this.stop(), this.prPlayer.start(o)));
|
|
2455
|
-
m(this, "stop", () => {
|
|
2453
|
+
g(this, "start", async (o) => (this.stop(), this.prPlayer.start(o)));
|
|
2454
|
+
g(this, "stop", () => {
|
|
2456
2455
|
this.prPlayer.stop(), this.usersMap = /* @__PURE__ */ new Map(), this.room.roomId = "", this.room.author = "", this.room.updateTime = "", this.room.version = "";
|
|
2457
2456
|
});
|
|
2458
|
-
|
|
2457
|
+
g(this, "setMute", (o) => {
|
|
2459
2458
|
this.prPlayer.setMute(o);
|
|
2460
2459
|
});
|
|
2461
|
-
|
|
2462
|
-
|
|
2460
|
+
g(this, "getStream", () => this.prPlayer.getStream());
|
|
2461
|
+
g(this, "getAllUseUpdateKey", () => {
|
|
2463
2462
|
const o = [...this.usersMap.values()];
|
|
2464
2463
|
return Array.from(o, (u) => u.updateTime).join("_");
|
|
2465
2464
|
});
|
|
2466
|
-
|
|
2465
|
+
g(this, "checkAndCreateUser", (o, a) => {
|
|
2467
2466
|
var u, r;
|
|
2468
2467
|
if (this.usersMap.has(o)) {
|
|
2469
2468
|
const n = this.usersMap.get(o);
|
|
@@ -2496,7 +2495,7 @@ class QuickVoPlayer {
|
|
|
2496
2495
|
/**
|
|
2497
2496
|
* 监听SEI信息
|
|
2498
2497
|
*/
|
|
2499
|
-
|
|
2498
|
+
g(this, "onSEI", (o) => {
|
|
2500
2499
|
try {
|
|
2501
2500
|
const a = parseSEI(o);
|
|
2502
2501
|
if (!a) return;
|
|
@@ -2518,7 +2517,7 @@ class QuickVoPlayer {
|
|
|
2518
2517
|
}
|
|
2519
2518
|
const s = this.getAllUseUpdateKey();
|
|
2520
2519
|
if (t !== s && this.on.users) {
|
|
2521
|
-
const l = [...this.usersMap.values()], c = Array.from(l, ({ userId: d, mc_audio: p, mc_video: f, ss_audio: w, ss_video: b, updateTime:
|
|
2520
|
+
const l = [...this.usersMap.values()], c = Array.from(l, ({ userId: d, mc_audio: p, mc_video: f, ss_audio: w, ss_video: b, updateTime: m }) => ({ userId: d, mc_audio: p, mc_video: f, ss_audio: w, ss_video: b, updateTime: m }));
|
|
2522
2521
|
this.on.users(c);
|
|
2523
2522
|
}
|
|
2524
2523
|
}
|
|
@@ -2534,7 +2533,7 @@ class QuickVoPlayer {
|
|
|
2534
2533
|
console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m", "color:#0097ff;", "------->onSEI: error", a);
|
|
2535
2534
|
}
|
|
2536
2535
|
});
|
|
2537
|
-
|
|
2536
|
+
g(this, "setDisplayMode", (o) => {
|
|
2538
2537
|
var a, u, r, n, i, t, e, s;
|
|
2539
2538
|
switch (this.displayMode = o, o) {
|
|
2540
2539
|
case "original":
|