"use strict";var s=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var _=(i,e)=>{for(var n in e)s(i,n,{get:e[n],enumerable:!0})},y=(i,e,n,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of p(e))!w.call(i,o)&&o!==n&&s(i,o,{get:()=>e[o],enumerable:!(t=u(e,o))||t.enumerable});return i};var f=i=>y(s({},"__esModule",{value:!0}),i);var E={};_(E,{allowedEvents:()=>m,allowedMethods:()=>h,default:()=>b});module.exports=f(E);var r=require("post-me"),m={success:1,error:1},h={},d=class{constructor({token:e,domain:n="https://app.corellium.com",instanceId:t,containerId:o}){this._token=e,this._appendedChild=null,this._domain=n,this._instanceId=t,this._containerId=o,this._connection=null,this._remoteHandle=null,this._localHandle=null,this._listeners={};let l=this.setupIframe();this.setupCommunication(l)}setupIframe(){let e=new URL("/web-player/login",this._domain).href,n=document.getElementById(this._containerId);if(!n)throw new Error("Could not append child to container.");let t=document.createElement("iframe");return t.src=e,t.name="child",t.title="Corellium Web Player",t.width="100%",t.style.border="none",t.id="web-player",t.style.display="none",t.style.minHeight="800px",t.style.maxHeight="100%",t.style.margin="0",t.allow="camera;microphone;clipboard-read; clipboard-write",n.appendChild(t)}setupCommunication(e){e.onload=()=>{if(!e.contentWindow)throw new Error("Could not get contentWindow from iframe.");let n=new r.WindowMessenger({localWindow:window,remoteWindow:e.contentWindow,remoteOrigin:this._domain});(0,r.ParentHandshake)(n,{},10,5e3).then(t=>{this._connection=t,this._remoteHandle=t.remoteHandle(),this._localHandle=t.localHandle(),this._localHandle.emit("connect",{token:this._token,instanceId:this._instanceId}),this._remoteHandle.addEventListener("message",o=>{if(o.status==="success"){setTimeout(()=>{let a=document.getElementById("corellium-loading"),c=document.getElementById("web-player");if(a&&(a.style.display="none"),!c)throw new Error("Could not find web-player element.");c.style.display="block",this._emit(o.status,o)},2e3);return}let l=document.getElementById("corellium-error");l&&(l.style.display="block"),this._emit(o.status,o)})}).catch(t=>{this._emit("error",t)})}}on(e,n){if(!m[e])throw new Error(`${e} is not allowed`);this._listeners[e]=n}_emit(e,n){typeof this._listeners[e]=="function"&&this._listeners[e](n)}_exec(e,n){var t;if(!h[e])throw new Error(`${e} is not allowed`);(t=this._remoteHandle)==null||t.call(e,n).catch(o=>{this._emit("error",o)})}},b=d;0&&(module.exports={allowedEvents,allowedMethods});