@htmlbricks/hb-player-live 0.50.0-alpha.20 → 0.50.0-alpha.23

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/main.iife.js CHANGED
@@ -67,3 +67,4 @@ a=rtcp-mux\r
67
67
  a=rtpmap:118 `+t+`\r
68
68
  `+(s!==void 0?"a=fmtp:118 "+s+`\r
69
69
  `:"")}))).then(()=>{i(!0)}).catch(o=>{i(!1)}).finally(()=>{a.close()})}),this.getNonAdvertisedCodecs=()=>{Promise.all([["pcma/8000/2"],["multiopus/48000/6","channel_mapping=0,4,1,2,3,5;num_streams=4;coupled_streams=2"],["L16/48000/2"]].map(t=>this.supportsNonAdvertisedCodec(t[0],t[1]).then(s=>s?t[0]:!1))).then(t=>t.filter(s=>s!==!1)).then(t=>{this.nonAdvertisedCodecs=t,this.loadStream()})},this.onError=t=>{console.error("whep stream error",t),this.onOffline(),this.online=!1,this.restartTimeout===null&&(this.pc!==null&&(this.pc.close(),this.pc=null),this.restartTimeout=setTimeout(()=>{this.restartTimeout=null,this.loadStream()},this.retryPause),this.sessionUrl&&fetch(this.sessionUrl,{method:"DELETE"}),this.sessionUrl="",this.queuedCandidates=[])},this.createOffer=()=>{this.pc&&this.pc.createOffer().then(t=>{t.sdp=this.editOffer(t.sdp),this.offerData=this.parseOffer(t.sdp),this.pc&&this.pc.setLocalDescription(t).then(()=>{this.sendOffer(t)}).catch(s=>{this.onError(s.toString())})}).catch(t=>{this.onError(t.toString())})},this.onConnectionState=()=>{var t;this.restartTimeout===null&&((t=this.pc)==null?void 0:t.iceConnectionState)==="disconnected"&&this.onError(new Error("peer connection closed"))},this.onTrack=t=>{this.video.srcObject=t.streams[0],this.onOnline(),this.online=!0},this.requestICEServers=()=>{fetch(this.whepUri,{method:"OPTIONS"}).then(t=>{this.pc=new RTCPeerConnection({iceServers:this.linkToIceServers(t.headers.get("Link")),sdpSemantics:"unified-plan"});const s="sendrecv";this.pc.addTransceiver("video",{direction:s}),this.pc.addTransceiver("audio",{direction:s}),this.pc.onicecandidate=i=>this.onLocalCandidate(i),this.pc.oniceconnectionstatechange=()=>this.onConnectionState(),this.pc.ontrack=i=>this.onTrack(i),this.createOffer()}).catch(t=>{this.onError(t.toString())})},this.init=()=>{this.getNonAdvertisedCodecs()},this.video=e.videoElement,this.whepUri=e.whepUri,e.controls!==!1&&(this.video.controls=!0),e.muted!==!1&&(this.video.muted=!0),e.autoplay!==!0&&(this.video.autoplay=!0),e.playsInline!==!0&&(this.video.playsInline=!0),this.defaultControls=this.video.controls,this.onOnline=e.onOnline||(()=>{console.log("online")}),this.onOffline=e.onOffline||(()=>{console.log("offline")}),this.init()}sendLocalCandidates(e){fetch(this.sessionUrl,{method:"PATCH",headers:{"Content-Type":"application/trickle-ice-sdpfrag","If-Match":"*"},body:this.generateSdpFragment(this.offerData,e)}).then(t=>{switch(t.status){case 204:break;case 404:throw new Error("stream not found");default:throw new Error(`bad status code ${t.status}`)}}).catch(t=>{this.onError(t.toString())})}onLocalCandidate(e){this.restartTimeout===null&&e.candidate!==null&&(this.sessionUrl===""?this.queuedCandidates.push(e.candidate):this.sendLocalCandidates([e.candidate]))}onRemoteAnswer(e){this.restartTimeout!==null||this.pc===null||this.pc.setRemoteDescription(new RTCSessionDescription({type:"answer",sdp:e})).then(()=>{this.queuedCandidates.length!==0&&(this.sendLocalCandidates(this.queuedCandidates),this.queuedCandidates=[])}).catch(t=>{this.onError(t.toString())})}sendOffer(e){fetch(this.whepUri,{method:"POST",headers:{"Content-Type":"application/sdp"},body:e.sdp}).then(t=>{switch(t.status){case 201:break;case 404:throw new Error("stream not found");case 400:return t.json().then(s=>{throw new Error(s.error)});default:throw new Error(`bad status code ${t.status}`)}return this.sessionUrl=new URL(t.headers.get("location"),this.whepUri.replace("/whep","/")).toString(),console.log("session",this.sessionUrl),t.text().then(s=>this.onRemoteAnswer(s))}).catch(t=>{this.onError(t.toString())})}close(){this.pc&&this.pc.close(),this.pc=null,this.sessionUrl&&fetch(this.sessionUrl,{method:"DELETE"})}}var Gg=wt('<video id="video" part="video" class="video svelte-1ci041j" autoplay><track kind="captions" src="" srclang="en" label="English" default></video>',2),Vg=wt('<div style="flex: 1"><div class="subsection svelte-1ci041j"><div><!></div></div></div> <div style="flex:1"><div class="subsection svelte-1ci041j"><div style="flex:1"><div class="subsection svelte-1ci041j"><div><!></div></div></div> <div style="flex:1"><div class="subsection svelte-1ci041j"><div><!></div></div></div></div></div>',1),Kg=wt('<div style="flex: 1"><div class="subsection svelte-1ci041j"><div><!></div></div></div> <div style="flex:1"><div class="subsection svelte-1ci041j"><div style="flex:1"><div class="subsection svelte-1ci041j"><div><!></div></div></div></div></div>',1),Hg=wt('<div style="flex: 1"><div class="subsection svelte-1ci041j"><div><!></div></div></div>'),Yg=wt('<div part="replacewithtext" class="replacetext video svelte-1ci041j"><!></div>'),Wg=wt('<div class="replacetext video svelte-1ci041j" part="replacewithtext">offline</div>'),qg=wt('<div class="replacetext video svelte-1ci041j" part="replacewithtext">nouri</div>'),jg=wt('<div part="container" style="width: 100%;position:relative"><!> <!></div>');const Xg={hash:"svelte-1ci041j",code:'@import url("https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap");:host {font-family:"Roboto", sans-serif;}.replacetext.svelte-1ci041j {position:absolute;width:100%;height:100%;top:0px;}.video.svelte-1ci041j {width:100%;background-color:black;color:white;display:flex;align-items:center;justify-content:center;flex-direction:column;aspect-ratio:16/9;margin:auto;}.subsection.svelte-1ci041j {display:flex;height:100%;align-items:center;justify-content:center;flex-direction:column;}'};function Bl(n,e){Jn(e,!0),Wc(n,Xg);let t=Ht(e,"id",7,""),s=Ht(e,"style",7,""),i=Ht(e,"mediauri"),r=Ht(e,"forcecover",7,void 0),a=Ht(e,"media_type",7,"auto"),o=Ht(e,"no_controls",7,!1),c=Ht(e,"replacewithtext",7,void 0),l=Is(void 0),u=Is(!1),h=Is(void 0),d=Is(void 0),f=Is(void 0);Kn(()=>{if(o()&&o()!=="no"&&o()!=="false"&&o(!0),typeof c()=="string")try{c(JSON.parse(c()))}catch{}});function g(S,x){e.$$host.dispatchEvent(new CustomEvent(S,{detail:x}))}function p(S){if(console.log("setttviiiii",a()),ve(f,et(S)),g("htmlVideoInit",{htmlVideoElement:he(f),id:t()}),a()==="hls")if(S&&ht.isSupported()){const x=new ht({});x.loadSource(i()),x.attachMedia(S),x.on(ht.Events.MEDIA_ATTACHED,function(){S.muted=!0;try{S.play()}catch(b){console.error("cannot autoplay",b)}})}else S!=null&&S.canPlayType("application/vnd.apple.mpegurl")?(console.log("without Media Source Extensions"),S.src=i(),S.muted=!0,S.addEventListener("canplay",function(){try{S.play()}catch(x){console.error("cannot autoplay",x)}})):console.error("no hls support");else if(a()==="whep"){console.info("whep",i());try{let x=function(){console.info("offline whep"),g("liveStatus",{live:!1,id:t()}),ve(u,!1)},b=function(){console.info("online whep"),g("liveStatus",{live:!0,id:t()}),ve(u,!0)};console.info("whep",i()),ve(d,et(new $g({videoElement:S,whepUri:i(),onOnline:b,onOffline:x})));try{S.muted=!0,S.play()}catch(I){console.error("cannot autoplay whep",I)}}catch(x){console.error("whep error ....",x)}}else if(a()==="webrtc"){console.info("webrtc",i());try{let x=function(){g("liveStatus",{live:!1,id:t()}),ve(u,!1)},b=function(){g("liveStatus",{live:!0,id:t()}),ve(u,!0)};ve(h,et(new Bg({videoElement:S,wsUri:i(),onOnline:b,onOffline:x}))),he(h).start();try{S.muted=!0,S.play()}catch(I){console.error("cannot autoplay webrtc",I)}}catch(x){console.error("webrtc error ....",x)}}else console.error("unknown media type",a())}async function E(){function S(){console.log("reloading",he(u),i()),(!he(u)||!i())&&E().catch(x=>{console.error("reload uri",x)})}try{if(!i()){ve(l,et(setTimeout(S,5e3)));return}if(a()==="hls"){console.info("checking live");const x=await fetch(i());if(!x||x.status&&(x.status>299||x.status<199))throw new Error("wrong uri");ve(u,!0),g("liveStatus",{live:!0,id:t()})}else throw new Error("wrong media type")}catch{he(u)!==!1&&g("liveStatus",{live:!1,id:t()}),ve(u,!1),ve(l,et(setTimeout(S,5e3)))}}e.$$host.getVideoElement=()=>{if(he(f))return he(f)},jc(()=>(E().catch(()=>{console.error("merr")}).then(()=>{console.log("start live checker")}),()=>{console.log("destroying player"),he(l)&&(console.log("destroy live checker"),clearTimeout(he(l))),he(d)&&he(d).close()}));var v=jg(),T=ue(v);{var y=S=>{var x=Gg();qc(x,b=>p==null?void 0:p(b)),Gt(()=>x.controls=!o()),pe(S,x)};Kt(T,S=>{i()&&a()&&S(y)})}var A=Js(T,2);{var L=S=>{var x=Yg(),b=ue(x);{var I=k=>{var W=Vt(),K=mt(W);yt(K,e,"replacewithtext",{},B=>{var F=Vg(),U=mt(F),N=ue(U),P=ue(N),O=ue(P);yt(O,e,"replacetitle",{},We=>{var Me=cs();Gt(()=>{var Le;return us(Me,((Le=c())==null?void 0:Le.title)||"")}),pe(We,Me)}),ce(P),ce(N),ce(U);var H=Js(U,2),G=ue(H),q=ue(G),z=ue(q),Q=ue(z),ee=ue(Q);yt(ee,e,"replacesubtitle",{},We=>{var Me=cs();Gt(()=>{var Le;return us(Me,((Le=c())==null?void 0:Le.subtitle)||"")}),pe(We,Me)}),ce(Q),ce(z),ce(q);var fe=Js(q,2),Ee=ue(fe),be=ue(Ee),dt=ue(be);yt(dt,e,"replacetext",{},We=>{var Me=cs();Gt(()=>{var Le;return us(Me,((Le=c())==null?void 0:Le.text)||"")}),pe(We,Me)}),ce(be),ce(Ee),ce(fe),ce(G),ce(H),pe(B,F)}),pe(k,W)},w=k=>{var W=Vt(),K=mt(W);{var B=U=>{var N=Vt(),P=mt(N);yt(P,e,"replacewithtext",{},O=>{var H=Kg(),G=mt(H),q=ue(G),z=ue(q),Q=ue(z);yt(Q,e,"replacetitle",{},Me=>{var Le=cs();Gt(()=>{var Rt;return us(Le,((Rt=c())==null?void 0:Rt.title)||"")}),pe(Me,Le)}),ce(z),ce(q),ce(G);var ee=Js(G,2),fe=ue(ee),Ee=ue(fe),be=ue(Ee),dt=ue(be),We=ue(dt);yt(We,e,"replacesubtitle",{},Me=>{var Le=cs();Gt(()=>{var Rt;return us(Le,((Rt=c())==null?void 0:Rt.subtitle)||"")}),pe(Me,Le)}),ce(dt),ce(be),ce(Ee),ce(fe),ce(ee),pe(O,H)}),pe(U,N)},F=U=>{var N=Vt(),P=mt(N);{var O=H=>{var G=Vt(),q=mt(G);yt(q,e,"replacewithtext",{},z=>{var Q=Hg(),ee=ue(Q),fe=ue(ee),Ee=ue(fe);yt(Ee,e,"replacetitle",{},be=>{var dt=cs();Gt(()=>{var We;return us(dt,((We=c())==null?void 0:We.title)||"")}),pe(be,dt)}),ce(fe),ce(ee),ce(Q),pe(z,Q)}),pe(H,G)};Kt(P,H=>{var G;(G=c())!=null&&G.title&&H(O)},!0)}pe(U,N)};Kt(K,U=>{var N,P;(N=c())!=null&&N.title&&((P=c())!=null&&P.subtitle)?U(B):U(F,!1)},!0)}pe(k,W)};Kt(b,k=>{var W,K,B;(W=c())!=null&&W.title&&((K=c())!=null&&K.subtitle)&&((B=c())!=null&&B.text)?k(I):k(w,!1)})}ce(x),pe(S,x)},D=S=>{var x=Vt(),b=mt(x);{var I=k=>{var W=Wg();pe(k,W)},w=k=>{var W=Vt(),K=mt(W);{var B=F=>{var U=qg();pe(F,U)};Kt(K,F=>{i()||F(B)},!0)}pe(k,W)};Kt(b,k=>{i()&&!he(u)&&(!c()||!c().title&&!c().subtitle&&!c().text)?k(I):k(w,!1)},!0)}pe(S,x)};Kt(A,S=>{var x,b,I;r()||i()&&!he(u)&&((x=c())!=null&&x.title||(b=c())!=null&&b.subtitle||(I=c())!=null&&I.text)?S(L):S(D,!1)})}return ce(v),pe(n,v),Zn({get id(){return t()},set id(S=""){t(S),Et()},get style(){return s()},set style(S=""){s(S),Et()},get mediauri(){return i()},set mediauri(S){i(S),Et()},get forcecover(){return r()},set forcecover(S=void 0){r(S),Et()},get media_type(){return a()},set media_type(S="auto"){a(S),Et()},get no_controls(){return o()},set no_controls(S=!1){o(S),Et()},get replacewithtext(){return c()},set replacewithtext(S=void 0){c(S),Et()}})}customElements.define("hb-player-live",Jc(Bl,{id:{},style:{},mediauri:{},forcecover:{},media_type:{},no_controls:{},replacewithtext:{}},["replacewithtext","replacetitle","replacesubtitle","replacetext"],[],!0)),le.Component=Bl,Object.defineProperty(le,Symbol.toStringTag,{value:"Module"})})(this["player-live"]=this["player-live"]||{});
70
+ //# sourceMappingURL=main.iife.js.map