@mux/studio-embed
Advanced tools
Comparing version 0.3.1 to 0.4.2-alpha.4
@@ -1,1 +0,1 @@ | ||
var muxStudioEmbed=(()=>{var l=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var v=(a,e)=>{for(var t in e)l(a,t,{get:e[t],enumerable:!0})},T=(a,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of f(e))!E.call(a,r)&&r!==t&&l(a,r,{get:()=>e[r],enumerable:!(n=d(e,r))||n.enumerable});return a};var g=a=>T(l({},"__esModule",{value:!0}),a);var N={};v(N,{PostMessageEvents:()=>s,createStudio:()=>b,eventNames:()=>i});var i=["ERROR","LIVESTREAM_STARTED","LIVESTREAM_ENDED","PARTICIPANT_JOINED","PARTICIPANT_LEFT","LOADING_STATUS_CHANGED","CAMERA_STARTED","CAMERA_STOPPED","MIC_STARTED","MIC_STOPPED","CONNECTION_QUALITY_CHANGED","HEIGHT_CHANGED"],s=(e=>(e.PORT_TRANSFER="PORT_TRANSFER",e))(s||{});var b=async(a,e,t)=>{if(typeof a!="string")throw new Error("Token must be provided and be a string");if(document.querySelector("#mux-studio-embed")!==null)throw new Error("Studio already embedded. Only one studio can be embedded at a time");let n=null;if(e instanceof HTMLElement?n=e:typeof e=="string"&&(n=document.querySelector(e)),!n)throw new Error("Invalid target element supplied");return new o(a,n,t!=null?t:{})},o=class{constructor(e,t,n){this.autoSize=!0;this._setupIframe=()=>{if(this.iframe===null)return;let e=this.iframe;e.title="Mux Studio Embed",e.id="mux-studio-embed",e.allowFullscreen=!0,e.allow="camera; microphone; fullscreen; display-capture; allow-same-origin; allow-presentation",this.autoSize&&(e.style.width="100%",e.style.height="768px"),e.style.display="block",e.style.border="none";let t=`https://0-3-1.studio.mux.dev/iframe?token=${this.token}`;this.background&&(t+=`&bg=${encodeURIComponent(this.background)}`),this.overlay&&(t+=`&ov=${encodeURIComponent(this.overlay)}`),t+=`&as=${this.autoSize?"1":"0"}`,e.src=t,e.onload=this._iframeLoaded.bind(this),this.target.appendChild(e)};this._iframeLoaded=()=>{var e;this.iframe!==null&&((e=this.iframe.contentWindow)==null||e.postMessage("PORT_TRANSFER","*",[this.channel.port2]),this.channel.port1.onmessage=this._onRecieveMessage)};this._onRecieveMessage=e=>{let{eventName:t,eventData:n}=e.data;t==="HEIGHT_CHANGED"&&this._updateIframeHeight(n.height),this.eventCallbacks[t].forEach(r=>r(n))};this._updateIframeHeight=e=>{this.iframe===null||!this.autoSize||(this.iframe.style.height=e.toString(10)+"px")};this.on=(e,t)=>{this.eventCallbacks[e].has(t)||this.eventCallbacks[e].add(t)};this.offAll=()=>{i.forEach(e=>this.eventCallbacks[e].clear())};this.remove=()=>{var e;this.offAll(),(e=this.iframe)==null||e.remove(),this.iframe=null};var m,u,h;this.token=e,this.target=t,this.iframe=document.createElement("iframe"),this.channel=new MessageChannel,this.background=(m=n==null?void 0:n.background)!=null?m:null,this.overlay=(u=n==null?void 0:n.overlay)!=null?u:null,this.autoSize=(h=n==null?void 0:n.autoSize)!=null?h:!0;let r=i.map(c=>[c,new Set]);this.eventCallbacks=Object.fromEntries(r),this._setupIframe()}off(e,t){t?this.eventCallbacks[e].delete(t):this.eventCallbacks[e].clear()}};return g(N);})(); | ||
var muxStudioEmbed=(()=>{var s=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var T=(n,e)=>{for(var t in e)s(n,t,{get:e[t],enumerable:!0})},v=(n,e,t,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of u(e))!f.call(n,r)&&r!==t&&s(n,r,{get:()=>e[r],enumerable:!(a=d(e,r))||a.enumerable});return n};var p=n=>v(s({},"__esModule",{value:!0}),n);var b={};T(b,{createStudio:()=>g});var i=["ERROR","LIVESTREAM_STARTED","LIVESTREAM_ENDED","PARTICIPANT_JOINED","PARTICIPANT_LEFT","LOADING_STATUS_CHANGED","CAMERA_STARTED","CAMERA_STOPPED","MIC_STARTED","MIC_STOPPED","CONNECTION_QUALITY_CHANGED","HEIGHT_CHANGED","REQUEST_THEME"];var g=async(n,e,t)=>{if(typeof n!="string")throw new Error("Token must be provided and be a string");if(document.querySelector("#mux-studio-embed")!==null)throw new Error("Studio already embedded. Only one studio can be embedded at a time");let a=null;if(e instanceof HTMLElement?a=e:typeof e=="string"&&(a=document.querySelector(e)),!a)throw new Error("Invalid target element supplied");return new l(n,a,t!=null?t:{})},l=class{constructor(e,t,a){this.autoSize=!0;this._setupIframe=()=>{if(this.iframe===null)return;let e=this.iframe;e.title="Mux Studio Embed",e.id="mux-studio-embed",e.allowFullscreen=!0,e.allow="camera; microphone; fullscreen; display-capture; allow-same-origin; allow-presentation",this.autoSize&&(e.style.width="100%",e.style.height="768px"),e.style.display="block",e.style.border="none";let t=`https://0-4-2-alpha-4.studio.mux.dev/iframe?token=${this.token}`;this.background&&(t+=`&bg=${encodeURIComponent(this.background)}`),this.overlay&&(t+=`&ov=${encodeURIComponent(this.overlay)}`),t+=`&as=${this.autoSize?"1":"0"}`,e.src=t,e.onload=this._iframeLoaded.bind(this),this.target.appendChild(e)};this._iframeLoaded=()=>{var e;this.iframe!==null&&((e=this.iframe.contentWindow)==null||e.postMessage("PORT_TRANSFER","*",[this.channel.port2]),this.channel.port1.onmessage=this._onRecieveMessage)};this._onRecieveMessage=e=>{let{name:t,data:a}=e.data;switch(t){case"HEIGHT_CHANGED":this._updateIframeHeight(a.height);break;case"REQUEST_THEME":this._sendTheme();break}this.eventCallbacks[t].forEach(r=>r(a))};this._updateIframeHeight=e=>{this.iframe===null||!this.autoSize||(this.iframe.style.height=e.toString(10)+"px")};this._sendTheme=()=>{let e={name:"THEME_UPDATE",theme:this.theme};this.channel.port1.postMessage(e)};this.on=(e,t)=>{this.eventCallbacks[e].has(t)||this.eventCallbacks[e].add(t)};this.offAll=()=>{i.forEach(e=>this.eventCallbacks[e].clear())};this.updateTheme=e=>{this.theme={...this.theme,...e},this._sendTheme()};this.remove=()=>{var e;this.offAll(),(e=this.iframe)==null||e.remove(),this.iframe=null};var m,h,o,E;this.token=e,this.target=t,this.iframe=document.createElement("iframe"),this.channel=new MessageChannel,this.background=(m=a==null?void 0:a.background)!=null?m:null,this.overlay=(h=a==null?void 0:a.overlay)!=null?h:null,this.autoSize=(o=a==null?void 0:a.autoSize)!=null?o:!0,this.theme=(E=a==null?void 0:a.theme)!=null?E:{};let r=i.map(c=>[c,new Set]);this.eventCallbacks=Object.fromEntries(r),this._setupIframe()}off(e,t){t?this.eventCallbacks[e].delete(t):this.eventCallbacks[e].clear()}};return p(b);})(); |
@@ -1,2 +0,3 @@ | ||
import { EventName } from './events'; | ||
import { EventName } from 'shared'; | ||
import { ThemeOptions } from 'shared'; | ||
interface Options { | ||
@@ -6,2 +7,3 @@ background?: string; | ||
autoSize?: boolean; | ||
theme?: ThemeOptions; | ||
} | ||
@@ -26,2 +28,3 @@ /** | ||
autoSize: boolean; | ||
theme: ThemeOptions; | ||
constructor(token: string, target: HTMLElement, options: Options); | ||
@@ -37,6 +40,7 @@ /** | ||
_onRecieveMessage: (event: MessageEvent<{ | ||
eventName: EventName; | ||
eventData: any; | ||
name: EventName; | ||
data: any; | ||
}>) => void; | ||
_updateIframeHeight: (height: number) => void; | ||
_sendTheme: () => void; | ||
/** | ||
@@ -57,2 +61,7 @@ * Register an event listener | ||
/** | ||
* Updates the theme for this studio, supports partial updates | ||
* @param theme The new theme | ||
*/ | ||
updateTheme: (theme: ThemeOptions) => void; | ||
/** | ||
* Removes the iframe from the DOM and destroys it | ||
@@ -62,2 +71,7 @@ */ | ||
} | ||
export * from './events'; | ||
/** | ||
* Make importing easier for consumers | ||
* Be specific about which types to export, we don't want to export types | ||
* only used internally that we may want to change at will. | ||
*/ | ||
export type { ThemeOptions, EventName } from 'shared'; |
{ | ||
"name": "@mux/studio-embed", | ||
"version": "0.3.1", | ||
"version": "0.4.2-alpha.4", | ||
"description": "", | ||
@@ -46,2 +46,5 @@ "license": "UNLICENSED", | ||
}, | ||
"dependencies": { | ||
"shared": "^0.3.0" | ||
}, | ||
"publishConfig": { | ||
@@ -48,0 +51,0 @@ "access": "restricted" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15944
120
1
6
+ Addedshared@^0.3.0