@hopecloud/jetstream-player 1.1.3 → 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/@types/player.type.d.ts +2 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=["ready","timeupdate","play","pause","loadedmetadata","ended","volumechange","error"];class t{options;iframe=null;constructor(e){this.options=e,this.iframe=this.generateIframe()}generateIframe(){const e=document.createElement("iframe");return e.allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture",e.allowFullscreen=!0,e.frameBorder="0",e.src=this.options.src,e.width=this.options.width||"480px",e.height=this.options.height||"270px",e.classList.add("jet-stream-iframe-player"),e}insertIframe(e){const t=document.querySelector(this.options.selector);t?t.appendChild(e):console.error(`Div with id "${this.options.selector}" not found.`)}}class i{options;origin="https://jstre.am";baseURL=new URL(this.origin);constructor(e){if(""===e.mediaId)throw new Error("mediaId not provided!");this.options=e}getRegionBasedOrigin(){const e=this.baseURL,t=e.hostname.split(".");return this.options.region&&"eu"===this.options.region&&(t.length>2?t.splice(1,0,"eu"):t.splice(0,0,"eu")),e.hostname=t.join("."),e.origin}appendPath(e,t){const i=String(e).trim();return 0===i.indexOf("/")?t+=i:t+=`/${i}`,t}buildSrc(){const e=new URL(`${this.getRegionBasedOrigin()}/embed/${this.options.mediaId}`);return this.options.playerId&&(e.href=this.appendPath(this.options.playerId,e.href)),"eu"===this.options.region&&e.searchParams.append("region","eu"),this.options.
|
|
1
|
+
const e=["ready","timeupdate","play","pause","loadedmetadata","ended","volumechange","error"];class t{options;iframe=null;constructor(e){this.options=e,this.iframe=this.generateIframe()}generateIframe(){const e=document.createElement("iframe");return e.allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture",e.allowFullscreen=!0,e.frameBorder="0",e.src=this.options.src,e.width=this.options.width||"480px",e.height=this.options.height||"270px",e.classList.add("jet-stream-iframe-player"),e}insertIframe(e){const t=document.querySelector(this.options.selector);t?t.appendChild(e):console.error(`Div with id "${this.options.selector}" not found.`)}}class i{options;origin="https://jstre.am";baseURL=new URL(this.origin);constructor(e){if(""===e.mediaId)throw new Error("mediaId not provided!");this.options=e}getRegionBasedOrigin(){const e=this.baseURL,t=e.hostname.split(".");return this.options.region&&"eu"===this.options.region&&(t.length>2?t.splice(1,0,"eu"):t.splice(0,0,"eu")),e.hostname=t.join("."),e.origin}appendPath(e,t){const i=String(e).trim();return 0===i.indexOf("/")?t+=i:t+=`/${i}`,t}buildSrc(){const e=new URL(`${this.getRegionBasedOrigin()}/embed/${this.options.mediaId}`);return this.options.playerId&&(e.href=this.appendPath(this.options.playerId,e.href)),"eu"===this.options.region&&e.searchParams.append("region","eu"),this.options.audioLang&&e.searchParams.append("audioLang",this.options.audioLang.toLowerCase()),this.options.subtitleLang&&e.searchParams.append("subtitleLang",this.options.subtitleLang.toLowerCase()),e.href}}const s="fixed",r="20px",n="20px",o="330px",a="180px";class h{containerSelector;iframe;observer=null;constructor(e,t){this.containerSelector=e,this.iframe=t,this.containerSelector=e,this.iframe=t,this.init()}init(){if(!this.iframe||!this.containerSelector)return;const e=document.querySelector(this.containerSelector);if(!e)throw new Error("Selector of iframe not found");this.observer=new IntersectionObserver((([{isIntersecting:t}])=>{if(t)e.style.height="auto",this.iframe.removeAttribute("style");else{const t=e.getBoundingClientRect().height;e.style.height=`${t}px`,this.iframe.style.position=s,this.iframe.style.bottom=r,this.iframe.style.right=n,this.iframe.style.width=o,this.iframe.style.height=a}}),{root:null,rootMargin:"0px",threshold:.1}),this.observer.observe(e)}destory(){this.observer&&(this.observer.disconnect(),this.observer=null)}}const d=e=>JSON.parse(e.data),c=e=>JSON.stringify(e),p=e=>{if("string"!=typeof e)return!1;try{return JSON.parse(e),!0}catch(e){return console.log("Error parsing JSON",e),!1}};class m{iframe=null;options;registeredEvents={};iFramePiP=null;constructor(e,s){this.options=s;const r=new i({mediaId:s.mediaId,playerId:s.playerId,region:s.region}).buildSrc(),n=new t({selector:e,src:r,width:this.options.width,height:this.options.height});this.iframe=n.iframe,this.iframe&&(n.insertIframe(this.iframe),this.iframe.addEventListener("load",(()=>{this.registerEvents(),this.subscribeToRegisteredEvents()}),{once:!0}),void 0!==this.options.sticky&&this.options.sticky&&(this.iFramePiP=new h(e,this.iframe)))}registerEvents(){!this.options.events||this.options.events&&Object.keys(this.options.events).length<0||Object.entries(this.options.events).forEach((([e,t])=>{e in this.registeredEvents||(this.registeredEvents[e]=t)}))}subscribeEventHandler(e){if(e.source!==this.iframe.contentWindow)return;const t=d(e),i=t.type;i in this.registeredEvents&&this.registeredEvents[i](t.value)}subscribeToRegisteredEvents(){window.addEventListener("message",this.subscribeEventHandler.bind(this))}dispatch(e){if(!this.iframe||!this.iframe.contentWindow)throw new Error("iframe is not provided or parent window not found!");this.iframe.contentWindow.postMessage(c(e),"*")}getterDispatch(e){return new Promise((t=>{this.dispatch(e),window.addEventListener("message",(i=>{const s=d(i);s.type===e.name&&t(s.value)}),{once:!0})}))}play(){this.dispatch({name:"play"})}pause(){this.dispatch({name:"pause"})}mute(){this.dispatch({name:"mute"})}unmute(){this.dispatch({name:"unmute"})}seekTo(e){this.dispatch({name:"seekTo",params:e})}playNext(){this.dispatch({name:"play-next"})}playPrev(){this.dispatch({name:"play-prev"})}isMuted(){return this.getterDispatch({name:"is-muted"})}isPaused(){return this.getterDispatch({name:"is-paused"})}getVideoCurrentTime(){return this.getterDispatch({name:"get-video-current-time"})}getDuration(){return this.getterDispatch({name:"get-duration"})}dispose(){window.removeEventListener("message",this.subscribeEventHandler.bind(this)),this.registeredEvents={},this.iFramePiP?.destory()}}export{m as JetstreamPlayer,c as denormalizeEventData,p as isValidEventData,d as normalizeEventData,e as playerListenEvents};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|