UNPKG

@inlivedev/inlive-js-sdk

Version:
1 lines 247 kB
const e={url:"",token:"",method:"GET",body:void 0,options:void 0},fetchHttp=async(t=e)=>{const{url:n,token:r,method:i,body:o,options:s}=t;if(0===n.trim().length)throw new Error("Please provide the url");const c={method:i||"GET",mode:"cors",referrerPolicy:"origin-when-cross-origin",headers:{Authorization:r?`Bearer ${r}`:"","Content-Type":"application/json"},body:"object"==typeof o&&"GET"!==i?JSON.stringify(o):void 0,...s};let u;u="undefined"!=typeof window&&window?(e,t)=>window.fetch(e,t):(e,t)=>import("node-fetch").then((({default:n})=>n(e,t)));const l=await u(n,c),d=l.headers.get("content-type");let h={};if(d&&d.includes("application/json"))h=await l.json();else{h=await l.text()}return l.ok&&l.status>=200&&l.status<300?Promise.resolve(h):Promise.reject(h)};var t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function getDefaultExportFromCjs(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function getAugmentedNamespace(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function a(){return this instanceof a?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}var n={exports:{}};const isObject$2=e=>"object"==typeof e&&null!==e,r=Symbol("skip"),isObjectCustom=e=>isObject$2(e)&&!(e instanceof RegExp)&&!(e instanceof Error)&&!(e instanceof Date),mapObject=(e,t,n,i=new WeakMap)=>{if(n={deep:!1,target:{},...n},i.has(e))return i.get(e);i.set(e,n.target);const{target:o}=n;delete n.target;const mapArray=e=>e.map((e=>isObjectCustom(e)?mapObject(e,t,n,i):e));if(Array.isArray(e))return mapArray(e);for(const[s,c]of Object.entries(e)){const u=t(s,c,e);if(u===r)continue;let[l,d,{shouldRecurse:h=!0}={}]=u;"__proto__"!==l&&(n.deep&&h&&isObjectCustom(d)&&(d=Array.isArray(d)?mapArray(d):mapObject(d,t,n,i)),o[l]=d)}return o};n.exports=(e,t,n)=>{if(!isObject$2(e))throw new TypeError(`Expected an object, got \`${e}\` (${typeof e})`);return mapObject(e,t,n)},n.exports.mapObjectSkip=r;var i=n.exports,o=getDefaultExportFromCjs(i),__assign=function(){return __assign=Object.assign||function __assign(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},__assign.apply(this,arguments)};function __awaiter(e,t,n,r){return new(n||(n=Promise))((function(i,o){function fulfilled(e){try{step(r.next(e))}catch(e){o(e)}}function rejected(e){try{step(r.throw(e))}catch(e){o(e)}}function step(e){e.done?i(e.value):function adopt(e){return e instanceof n?e:new n((function(t){t(e)}))}(e.value).then(fulfilled,rejected)}step((r=r.apply(e,t||[])).next())}))}function __generator(e,t){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:verb(0),throw:verb(1),return:verb(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function verb(c){return function(u){return function step(c){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(s=0)),s;)try{if(n=1,r&&(i=2&c[0]?r.return:c[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,c[1])).done)return i;switch(r=0,i&&(c=[2&c[0],i.value]),c[0]){case 0:case 1:i=c;break;case 4:return s.label++,{value:c[1],done:!1};case 5:s.label++,r=c[1],c=[0];continue;case 7:c=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==c[0]&&2!==c[0])){s=0;continue}if(3===c[0]&&(!i||c[1]>i[0]&&c[1]<i[3])){s.label=c[1];break}if(6===c[0]&&s.label<i[1]){s.label=i[1],i=c;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(c);break}i[2]&&s.ops.pop(),s.trys.pop();continue}c=t.call(e,s)}catch(e){c=[6,e],r=0}finally{n=i=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,u])}}}function __spreadArray(e,t,n){if(n||2===arguments.length)for(var r,i=0,o=t.length;i<o;i++)!r&&i in t||(r||(r=Array.prototype.slice.call(t,0,i)),r[i]=t[i]);return e.concat(r||Array.prototype.slice.call(t))}function lowerCase(e){return e.toLowerCase()}"function"==typeof SuppressedError&&SuppressedError;var s=[/([a-z0-9])([A-Z])/g,/([A-Z])([A-Z][a-z])/g],c=/[^A-Z0-9]+/gi;function replace(e,t,n){return t instanceof RegExp?e.replace(t,n):t.reduce((function(e,t){return e.replace(t,n)}),e)}function dotCase(e,t){return void 0===t&&(t={}),function noCase(e,t){void 0===t&&(t={});for(var n=t.splitRegexp,r=void 0===n?s:n,i=t.stripRegexp,o=void 0===i?c:i,u=t.transform,l=void 0===u?lowerCase:u,d=t.delimiter,h=void 0===d?" ":d,f=replace(replace(e,r,"$1\0$2"),o,"\0"),p=0,m=f.length;"\0"===f.charAt(p);)p++;for(;"\0"===f.charAt(m-1);)m--;return f.slice(p,m).split("\0").map(l).join(h)}(e,__assign({delimiter:"."},t))}var u=getAugmentedNamespace(Object.freeze({__proto__:null,snakeCase:function snakeCase$1(e,t){return void 0===t&&(t={}),dotCase(e,__assign({delimiter:"_"},t))}}));const l=i,{snakeCase:d}=u;var h=getDefaultExportFromCjs((function(e,t){return t=Object.assign({deep:!0,exclude:[],parsingOptions:{}},t),l(e,(function(e,n){return[(r=t.exclude,i=e,r.some((function(e){return"string"==typeof e?e===i:e.test(i)}))?e:d(e,t.parsingOptions)),n];var r,i}),t)}));const f=/[\p{Lu}]/u,p=/[\p{Ll}]/u,m=/^[\p{Lu}](?![\p{Lu}])/gu,v=/([\p{Alpha}\p{N}_]|$)/u,b=/[_.\- ]+/,y=new RegExp("^"+b.source),g=new RegExp(b.source+v.source,"gu"),w=new RegExp("\\d+"+v.source,"gu");function camelCase(e,t){if("string"!=typeof e&&!Array.isArray(e))throw new TypeError("Expected the input to be `string | string[]`");if(t={pascalCase:!1,preserveConsecutiveUppercase:!1,...t},0===(e=Array.isArray(e)?e.map((e=>e.trim())).filter((e=>e.length)).join("-"):e.trim()).length)return"";const n=!1===t.locale?e=>e.toLowerCase():e=>e.toLocaleLowerCase(t.locale),r=!1===t.locale?e=>e.toUpperCase():e=>e.toLocaleUpperCase(t.locale);if(1===e.length)return b.test(e)?"":t.pascalCase?r(e):n(e);return e!==n(e)&&(e=((e,t,n)=>{let r=!1,i=!1,o=!1;for(let s=0;s<e.length;s++){const c=e[s];r&&f.test(c)?(e=e.slice(0,s)+"-"+e.slice(s),r=!1,o=i,i=!0,s++):i&&o&&p.test(c)?(e=e.slice(0,s-1)+"-"+e.slice(s-1),o=i,i=!1,r=!0):(r=t(c)===c&&n(c)!==c,o=i,i=n(c)===c&&t(c)!==c)}return e})(e,n,r)),e=e.replace(y,""),e=t.preserveConsecutiveUppercase?((e,t)=>(m.lastIndex=0,e.replace(m,(e=>t(e)))))(e,n):n(e),t.pascalCase&&(e=r(e.charAt(0))+e.slice(1)),((e,t)=>(g.lastIndex=0,w.lastIndex=0,e.replace(g,((e,n)=>t(n))).replace(w,(e=>t(e)))))(e,r)}class QuickLRU extends Map{constructor(e={}){if(super(),!(e.maxSize&&e.maxSize>0))throw new TypeError("`maxSize` must be a number greater than 0");if("number"==typeof e.maxAge&&0===e.maxAge)throw new TypeError("`maxAge` must be a number greater than 0");this.maxSize=e.maxSize,this.maxAge=e.maxAge||Number.POSITIVE_INFINITY,this.onEviction=e.onEviction,this.cache=new Map,this.oldCache=new Map,this._size=0}_emitEvictions(e){if("function"==typeof this.onEviction)for(const[t,n]of e)this.onEviction(t,n.value)}_deleteIfExpired(e,t){return"number"==typeof t.expiry&&t.expiry<=Date.now()&&("function"==typeof this.onEviction&&this.onEviction(e,t.value),this.delete(e))}_getOrDeleteIfExpired(e,t){if(!1===this._deleteIfExpired(e,t))return t.value}_getItemValue(e,t){return t.expiry?this._getOrDeleteIfExpired(e,t):t.value}_peek(e,t){const n=t.get(e);return this._getItemValue(e,n)}_set(e,t){this.cache.set(e,t),this._size++,this._size>=this.maxSize&&(this._size=0,this._emitEvictions(this.oldCache),this.oldCache=this.cache,this.cache=new Map)}_moveToRecent(e,t){this.oldCache.delete(e),this._set(e,t)}*_entriesAscending(){for(const e of this.oldCache){const[t,n]=e;if(!this.cache.has(t)){!1===this._deleteIfExpired(t,n)&&(yield e)}}for(const e of this.cache){const[t,n]=e;!1===this._deleteIfExpired(t,n)&&(yield e)}}get(e){if(this.cache.has(e)){const t=this.cache.get(e);return this._getItemValue(e,t)}if(this.oldCache.has(e)){const t=this.oldCache.get(e);if(!1===this._deleteIfExpired(e,t))return this._moveToRecent(e,t),t.value}}set(e,t,{maxAge:n=this.maxAge}={}){const r="number"==typeof n&&n!==Number.POSITIVE_INFINITY?Date.now()+n:void 0;this.cache.has(e)?this.cache.set(e,{value:t,expiry:r}):this._set(e,{value:t,expiry:r})}has(e){return this.cache.has(e)?!this._deleteIfExpired(e,this.cache.get(e)):!!this.oldCache.has(e)&&!this._deleteIfExpired(e,this.oldCache.get(e))}peek(e){return this.cache.has(e)?this._peek(e,this.cache):this.oldCache.has(e)?this._peek(e,this.oldCache):void 0}delete(e){const t=this.cache.delete(e);return t&&this._size--,this.oldCache.delete(e)||t}clear(){this.cache.clear(),this.oldCache.clear(),this._size=0}resize(e){if(!(e&&e>0))throw new TypeError("`maxSize` must be a number greater than 0");const t=[...this._entriesAscending()],n=t.length-e;n<0?(this.cache=new Map(t),this.oldCache=new Map,this._size=t.length):(n>0&&this._emitEvictions(t.slice(0,n)),this.oldCache=new Map(t.slice(n)),this.cache=new Map,this._size=0),this.maxSize=e}*keys(){for(const[e]of this)yield e}*values(){for(const[,e]of this)yield e}*[Symbol.iterator](){for(const e of this.cache){const[t,n]=e;!1===this._deleteIfExpired(t,n)&&(yield[t,n.value])}for(const e of this.oldCache){const[t,n]=e;if(!this.cache.has(t)){!1===this._deleteIfExpired(t,n)&&(yield[t,n.value])}}}*entriesDescending(){let e=[...this.cache];for(let t=e.length-1;t>=0;--t){const n=e[t],[r,i]=n;!1===this._deleteIfExpired(r,i)&&(yield[r,i.value])}e=[...this.oldCache];for(let t=e.length-1;t>=0;--t){const n=e[t],[r,i]=n;if(!this.cache.has(r)){!1===this._deleteIfExpired(r,i)&&(yield[r,i.value])}}}*entriesAscending(){for(const[e,t]of this._entriesAscending())yield[e,t.value]}get size(){if(!this._size)return this.oldCache.size;let e=0;for(const t of this.oldCache.keys())this.cache.has(t)||e++;return Math.min(this._size+e,this.maxSize)}entries(){return this.entriesAscending()}forEach(e,t=this){for(const[n,r]of this.entriesAscending())e.call(t,r,n,this)}get[Symbol.toStringTag](){return JSON.stringify([...this.entriesAscending()])}}const _=new QuickLRU({maxSize:1e5}),isObject$1=e=>!("object"!=typeof e||null===e||e instanceof RegExp||e instanceof Error||e instanceof Date),camelCaseConvert=(e,t)=>{if(!isObject$1(e))return e;t={deep:!1,pascalCase:!1,...t};const{exclude:n,pascalCase:r,stopPaths:i,deep:s}=t,c=new Set(i),makeMapper=e=>(t,i)=>{if(s&&isObject$1(i)){const n=void 0===e?t:`${e}.${t}`;c.has(n)||(i=o(i,makeMapper(n)))}if(!n||!((e,t)=>e.some((e=>"string"==typeof e?e===t:(e.lastIndex=0,e.test(t)))))(n,t)){const e=r?`${t}_`:t;if(_.has(e))t=_.get(e);else{const n=camelCase(t,{pascalCase:r,locale:!1});t.length<100&&_.set(e,n),t=n}}return[t,i]};return o(e,makeMapper(void 0))};function camelcaseKeys(e,t){return Array.isArray(e)?Object.keys(e).map((n=>camelCaseConvert(e[n],t))):camelCaseConvert(e,t)}const onOpen=e=>({onOpen:t=>{e.client instanceof EventTarget&&t instanceof Function&&e.client.addEventListener("open",(e=>{t(e)}))}}),onError=e=>({onError:t=>{e.client instanceof EventTarget&&t instanceof Function&&e.client.addEventListener("error",(e=>{t(e)}))}}),onMessage=e=>({onMessage:t=>{e.client instanceof EventTarget&&t instanceof Function&&e.client.addEventListener("message",(e=>{if(e.data){let n=JSON.parse(e.data);n="object"==typeof n?n:{},t(camelcaseKeys(n,{deep:!0}))}}))}}),getEventKey=async(e,t)=>{let n=await fetchHttp({url:`${t}/auth/eventkey`,token:e,method:"POST"}).catch((e=>e));if(n)switch(n.code){case 200:e=n.data;break;case 404:throw new Error("Failed to get the event key because the stream ID is not found. Please provide a valid stream ID.");case 403:throw new Error("Failed to get event key because the authentication is failed. Check the API key")}return e},S=(()=>{const e={},isInstanceOfSet=(e,t)=>e[t]instanceof Set;return{publish:(t="",n={})=>{if(!t)throw new Error("Failed to process - event name is required");if("string"!=typeof t)throw new TypeError("Failed to process - event name must be in a string format");if(0===t.trim().length)throw new Error("Failed to process - event name must not be empty");if(isInstanceOfSet(e,t))for(const r of e[t])"function"==typeof r&&r(n);else e[t]=new Set},subscribe:(t,n)=>{if(!t)throw new Error("Failed to process - event name is required");if("string"!=typeof t)throw new TypeError("Failed to process - event name must be in a string format");if(0===t.trim().length)throw new Error("Failed to process - event name must not be empty");if("function"!=typeof n)throw new TypeError("Failed to process - please provide a callback function");isInstanceOfSet(e,t)||(e[t]=new Set),e[t].add(n);return{unsubscribe:()=>{e[t].delete(n)}}}}})();Object.freeze(S);const C={iceServers:[{urls:"turn:turn.inlive.app:3478",username:"inlive",credential:"inlivesdkturn"}]};Object.freeze(C);const E=(()=>{const{iceServers:e}=C;return{closeConnection:e=>{if(!(e instanceof RTCPeerConnection))throw new TypeError("Failed to process - Peer connection object is missing");e.close(),e=null},createLocalOffer:async e=>{if(!(e instanceof RTCPeerConnection))throw new TypeError("Failed to process - Peer connection object is missing");e.addEventListener("iceconnectionstatechange",(()=>{S.publish("stream:ice-connection-state-change-event",{type:"stream:ice-connection-state-change-event",detail:{connectionState:e.connectionState,iceConnectionState:e.iceConnectionState}})}));const t=new Promise((t=>{let n,r=!1;e&&e.addEventListener("icecandidate",(e=>{null!==e.candidate||r?n=setTimeout((()=>{r||(clearTimeout(n),r=!0,t(e))}),1e3):(clearTimeout(n),r=!0,t(e))}))})),n=await e.createOffer();await e.setLocalDescription(n),await t},openConnection:()=>new RTCPeerConnection({iceServers:e}),setRemoteOffer:(e,t)=>{if(e&&t){const n=new RTCSessionDescription(t);e.setRemoteDescription(n)}}}})();Object.freeze(E);const uuidv4=()=>{let e="";return window&&"undefined"!=typeof window&&(e=crypto.randomUUID?crypto.randomUUID():([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,(e=>(e^crypto.getRandomValues(new Uint8Array(1))[0]&15>>e/4).toString(16)))),e},A={baseUrl:"https://api.inlive.app",version:"v1"},I={baseUrl:"https://channel.inlive.app"};Object.freeze(I);var j=Object.freeze({__proto__:null,api:A,sse:I,webrtc:C}),T=Object.freeze({__proto__:null,config:j,fetchHttp,getEventKey,sse:()=>{let e={client:void 0};return Object.assign({},(e=>({subscribe:t=>{if("string"!=typeof t)throw new TypeError("Failed to process - URL must be a string");if(0===t.trim().length)throw new Error("Failed to process - URL cannot be empty");if(void 0!==e.client)throw new Error("Failed to process - Client was already subscribed to the specific channel. You can unsubscribe and resubscribe again to different channel");return e.client=new EventSource(t),e}}))(e),(e=>({unsubscribe:()=>{e.client instanceof EventSource&&(e.client.close(),e.client=void 0)}}))(e),onOpen(e),onError(e),onMessage(e),{publish:async(e,t)=>{if("string"!=typeof e||0===e.trim().length)throw new Error("Failed to process - Please provide the URL");if(!t)throw new Error("Failed to process - Please provide the data that wants to be published");if("object"!=typeof t)throw new TypeError("Failed to process - Data must be in an object format");return await fetchHttp({url:e,method:"POST",body:h(t)})}})},uuidv4,webrtc:E,websocket:()=>{let e={client:void 0};return Object.assign({},(e=>({subscribe:t=>{if("string"!=typeof t)throw new TypeError("Failed to process - URL must be a string");if(0===t.trim().length)throw new Error("Failed to process - URL cannot be empty");if(void 0!==e.client)throw new Error("Failed to process - Client was already subscribed to the specific channel. You can unsubscribe and resubscribe again to different channel");return e.client=new WebSocket(t),e}}))(e),(e=>({unsubscribe:()=>{e.client instanceof WebSocket&&(e.client.close(),e.client=void 0)}}))(e),onOpen(e),onError(e),onMessage(e))}}),x={exports:{}};function InitializationInstance(e){this.config=e}!function(e,n){var r="__lodash_hash_undefined__",i=9007199254740991,o="[object Arguments]",s="[object AsyncFunction]",c="[object Function]",u="[object GeneratorFunction]",l="[object Null]",d="[object Object]",h="[object Proxy]",f="[object Undefined]",p=/^\[object .+?Constructor\]$/,m=/^(?:0|[1-9]\d*)$/,v={};v["[object Float32Array]"]=v["[object Float64Array]"]=v["[object Int8Array]"]=v["[object Int16Array]"]=v["[object Int32Array]"]=v["[object Uint8Array]"]=v["[object Uint8ClampedArray]"]=v["[object Uint16Array]"]=v["[object Uint32Array]"]=!0,v[o]=v["[object Array]"]=v["[object ArrayBuffer]"]=v["[object Boolean]"]=v["[object DataView]"]=v["[object Date]"]=v["[object Error]"]=v[c]=v["[object Map]"]=v["[object Number]"]=v[d]=v["[object RegExp]"]=v["[object Set]"]=v["[object String]"]=v["[object WeakMap]"]=!1;var b="object"==typeof t&&t&&t.Object===Object&&t,y="object"==typeof self&&self&&self.Object===Object&&self,g=b||y||Function("return this")(),w=n&&!n.nodeType&&n,_=w&&e&&!e.nodeType&&e,S=_&&_.exports===w,C=S&&b.process,E=function(){try{var e=_&&_.require&&_.require("util").types;return e||C&&C.binding&&C.binding("util")}catch(e){}}(),A=E&&E.isTypedArray;var I,j=Array.prototype,T=Function.prototype,x=Object.prototype,k=g["__core-js_shared__"],L=T.toString,F=x.hasOwnProperty,O=(I=/[^.]+$/.exec(k&&k.keys&&k.keys.IE_PROTO||""))?"Symbol(src)_1."+I:"",D=x.toString,M=L.call(Object),R=RegExp("^"+L.call(F).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),z=S?g.Buffer:void 0,P=g.Symbol,V=g.Uint8Array,N=z?z.allocUnsafe:void 0,W=function overArg(e,t){return function(n){return e(t(n))}}(Object.getPrototypeOf,Object),G=Object.create,X=x.propertyIsEnumerable,Z=j.splice,H=P?P.toStringTag:void 0,Y=function(){try{var e=getNative(Object,"defineProperty");return e({},"",{}),e}catch(e){}}(),U=z?z.isBuffer:void 0,$=Math.max,J=Date.now,B=getNative(g,"Map"),K=getNative(Object,"create"),q=function(){function object(){}return function(e){if(!isObject(e))return{};if(G)return G(e);object.prototype=e;var t=new object;return object.prototype=void 0,t}}();function Hash(e){var t=-1,n=null==e?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function ListCache(e){var t=-1,n=null==e?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function MapCache(e){var t=-1,n=null==e?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function Stack(e){var t=this.__data__=new ListCache(e);this.size=t.size}function arrayLikeKeys(e,t){var n=ne(e),r=!n&&te(e),i=!n&&!r&&re(e),o=!n&&!r&&!i&&ae(e),s=n||r||i||o,c=s?function baseTimes(e,t){for(var n=-1,r=Array(e);++n<e;)r[n]=t(n);return r}(e.length,String):[],u=c.length;for(var l in e)!t&&!F.call(e,l)||s&&("length"==l||i&&("offset"==l||"parent"==l)||o&&("buffer"==l||"byteLength"==l||"byteOffset"==l)||isIndex(l,u))||c.push(l);return c}function assignMergeValue(e,t,n){(void 0!==n&&!eq(e[t],n)||void 0===n&&!(t in e))&&baseAssignValue(e,t,n)}function assignValue(e,t,n){var r=e[t];F.call(e,t)&&eq(r,n)&&(void 0!==n||t in e)||baseAssignValue(e,t,n)}function assocIndexOf(e,t){for(var n=e.length;n--;)if(eq(e[n][0],t))return n;return-1}function baseAssignValue(e,t,n){"__proto__"==t&&Y?Y(e,t,{configurable:!0,enumerable:!0,value:n,writable:!0}):e[t]=n}Hash.prototype.clear=function hashClear(){this.__data__=K?K(null):{},this.size=0},Hash.prototype.delete=function hashDelete(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t},Hash.prototype.get=function hashGet(e){var t=this.__data__;if(K){var n=t[e];return n===r?void 0:n}return F.call(t,e)?t[e]:void 0},Hash.prototype.has=function hashHas(e){var t=this.__data__;return K?void 0!==t[e]:F.call(t,e)},Hash.prototype.set=function hashSet(e,t){var n=this.__data__;return this.size+=this.has(e)?0:1,n[e]=K&&void 0===t?r:t,this},ListCache.prototype.clear=function listCacheClear(){this.__data__=[],this.size=0},ListCache.prototype.delete=function listCacheDelete(e){var t=this.__data__,n=assocIndexOf(t,e);return!(n<0)&&(n==t.length-1?t.pop():Z.call(t,n,1),--this.size,!0)},ListCache.prototype.get=function listCacheGet(e){var t=this.__data__,n=assocIndexOf(t,e);return n<0?void 0:t[n][1]},ListCache.prototype.has=function listCacheHas(e){return assocIndexOf(this.__data__,e)>-1},ListCache.prototype.set=function listCacheSet(e,t){var n=this.__data__,r=assocIndexOf(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this},MapCache.prototype.clear=function mapCacheClear(){this.size=0,this.__data__={hash:new Hash,map:new(B||ListCache),string:new Hash}},MapCache.prototype.delete=function mapCacheDelete(e){var t=getMapData(this,e).delete(e);return this.size-=t?1:0,t},MapCache.prototype.get=function mapCacheGet(e){return getMapData(this,e).get(e)},MapCache.prototype.has=function mapCacheHas(e){return getMapData(this,e).has(e)},MapCache.prototype.set=function mapCacheSet(e,t){var n=getMapData(this,e),r=n.size;return n.set(e,t),this.size+=n.size==r?0:1,this},Stack.prototype.clear=function stackClear(){this.__data__=new ListCache,this.size=0},Stack.prototype.delete=function stackDelete(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n},Stack.prototype.get=function stackGet(e){return this.__data__.get(e)},Stack.prototype.has=function stackHas(e){return this.__data__.has(e)},Stack.prototype.set=function stackSet(e,t){var n=this.__data__;if(n instanceof ListCache){var r=n.__data__;if(!B||r.length<199)return r.push([e,t]),this.size=++n.size,this;n=this.__data__=new MapCache(r)}return n.set(e,t),this.size=n.size,this};var Q=function createBaseFor(e){return function(t,n,r){for(var i=-1,o=Object(t),s=r(t),c=s.length;c--;){var u=s[e?c:++i];if(!1===n(o[u],u,o))break}return t}}();function baseGetTag(e){return null==e?void 0===e?f:l:H&&H in Object(e)?function getRawTag(e){var t=F.call(e,H),n=e[H];try{e[H]=void 0;var r=!0}catch(e){}var i=D.call(e);r&&(t?e[H]=n:delete e[H]);return i}(e):function objectToString(e){return D.call(e)}(e)}function baseIsArguments(e){return isObjectLike(e)&&baseGetTag(e)==o}function baseIsNative(e){return!(!isObject(e)||function isMasked(e){return!!O&&O in e}(e))&&(isFunction(e)?R:p).test(function toSource(e){if(null!=e){try{return L.call(e)}catch(e){}try{return e+""}catch(e){}}return""}(e))}function baseKeysIn(e){if(!isObject(e))return function nativeKeysIn(e){var t=[];if(null!=e)for(var n in Object(e))t.push(n);return t}(e);var t=isPrototype(e),n=[];for(var r in e)("constructor"!=r||!t&&F.call(e,r))&&n.push(r);return n}function baseMerge(e,t,n,r,i){e!==t&&Q(t,(function(o,s){if(i||(i=new Stack),isObject(o))!function baseMergeDeep(e,t,n,r,i,o,s){var c=safeGet(e,n),u=safeGet(t,n),l=s.get(u);if(l)return void assignMergeValue(e,n,l);var h=o?o(c,u,n+"",e,t,s):void 0,f=void 0===h;if(f){var p=ne(u),m=!p&&re(u),v=!p&&!m&&ae(u);h=u,p||m||v?ne(c)?h=c:!function isArrayLikeObject(e){return isObjectLike(e)&&isArrayLike(e)}(c)?m?(f=!1,h=function cloneBuffer(e,t){if(t)return e.slice();var n=e.length,r=N?N(n):new e.constructor(n);return e.copy(r),r}(u,!0)):v?(f=!1,h=function cloneTypedArray(e,t){var n=t?function cloneArrayBuffer(e){var t=new e.constructor(e.byteLength);return new V(t).set(new V(e)),t}(e.buffer):e.buffer;return new e.constructor(n,e.byteOffset,e.length)}(u,!0)):h=[]:h=function copyArray(e,t){var n=-1,r=e.length;t||(t=Array(r));for(;++n<r;)t[n]=e[n];return t}(c):function isPlainObject(e){if(!isObjectLike(e)||baseGetTag(e)!=d)return!1;var t=W(e);if(null===t)return!0;var n=F.call(t,"constructor")&&t.constructor;return"function"==typeof n&&n instanceof n&&L.call(n)==M}(u)||te(u)?(h=c,te(c)?h=function toPlainObject(e){return function copyObject(e,t,n,r){var i=!n;n||(n={});var o=-1,s=t.length;for(;++o<s;){var c=t[o],u=r?r(n[c],e[c],c,n,e):void 0;void 0===u&&(u=e[c]),i?baseAssignValue(n,c,u):assignValue(n,c,u)}return n}(e,keysIn(e))}(c):isObject(c)&&!isFunction(c)||(h=function initCloneObject(e){return"function"!=typeof e.constructor||isPrototype(e)?{}:q(W(e))}(u))):f=!1}f&&(s.set(u,h),i(h,u,r,o,s),s.delete(u));assignMergeValue(e,n,h)}(e,t,s,n,baseMerge,r,i);else{var c=r?r(safeGet(e,s),o,s+"",e,t,i):void 0;void 0===c&&(c=o),assignMergeValue(e,s,c)}}),keysIn)}function baseRest(e,t){return ee(function overRest(e,t,n){return t=$(void 0===t?e.length-1:t,0),function(){for(var r=arguments,i=-1,o=$(r.length-t,0),s=Array(o);++i<o;)s[i]=r[t+i];i=-1;for(var c=Array(t+1);++i<t;)c[i]=r[i];return c[t]=n(s),function apply(e,t,n){switch(n.length){case 0:return e.call(t);case 1:return e.call(t,n[0]);case 2:return e.call(t,n[0],n[1]);case 3:return e.call(t,n[0],n[1],n[2])}return e.apply(t,n)}(e,this,c)}}(e,t,identity),e+"")}function getMapData(e,t){var n=e.__data__;return function isKeyable(e){var t=typeof e;return"string"==t||"number"==t||"symbol"==t||"boolean"==t?"__proto__"!==e:null===e}(t)?n["string"==typeof t?"string":"hash"]:n.map}function getNative(e,t){var n=function getValue(e,t){return null==e?void 0:e[t]}(e,t);return baseIsNative(n)?n:void 0}function isIndex(e,t){var n=typeof e;return!!(t=null==t?i:t)&&("number"==n||"symbol"!=n&&m.test(e))&&e>-1&&e%1==0&&e<t}function isPrototype(e){var t=e&&e.constructor;return e===("function"==typeof t&&t.prototype||x)}function safeGet(e,t){if(("constructor"!==t||"function"!=typeof e[t])&&"__proto__"!=t)return e[t]}var ee=function shortOut(e){var t=0,n=0;return function(){var r=J(),i=16-(r-n);if(n=r,i>0){if(++t>=800)return arguments[0]}else t=0;return e.apply(void 0,arguments)}}(Y?function(e,t){return Y(e,"toString",{configurable:!0,enumerable:!1,value:(n=t,function(){return n}),writable:!0});var n}:identity);function eq(e,t){return e===t||e!=e&&t!=t}var te=baseIsArguments(function(){return arguments}())?baseIsArguments:function(e){return isObjectLike(e)&&F.call(e,"callee")&&!X.call(e,"callee")},ne=Array.isArray;function isArrayLike(e){return null!=e&&isLength(e.length)&&!isFunction(e)}var re=U||function stubFalse(){return!1};function isFunction(e){if(!isObject(e))return!1;var t=baseGetTag(e);return t==c||t==u||t==s||t==h}function isLength(e){return"number"==typeof e&&e>-1&&e%1==0&&e<=i}function isObject(e){var t=typeof e;return null!=e&&("object"==t||"function"==t)}function isObjectLike(e){return null!=e&&"object"==typeof e}var ae=A?function baseUnary(e){return function(t){return e(t)}}(A):function baseIsTypedArray(e){return isObjectLike(e)&&isLength(e.length)&&!!v[baseGetTag(e)]};function keysIn(e){return isArrayLike(e)?arrayLikeKeys(e,!0):baseKeysIn(e)}var ie=function createAssigner(e){return baseRest((function(t,n){var r=-1,i=n.length,o=i>1?n[i-1]:void 0,s=i>2?n[2]:void 0;for(o=e.length>3&&"function"==typeof o?(i--,o):void 0,s&&function isIterateeCall(e,t,n){if(!isObject(n))return!1;var r=typeof t;if("number"==r?isArrayLike(n)&&isIndex(t,n.length):"string"==r&&t in n)return eq(n[t],e);return!1}(n[0],n[1],s)&&(o=i<3?void 0:o,i=1),t=Object(t);++r<i;){var c=n[r];c&&e(t,c,r,o)}return t}))}((function(e,t,n){baseMerge(e,t,n)}));function identity(e){return e}e.exports=ie}(x,x.exports);const initStream=async(e,t)=>{if(e.constructor.name!==InitializationInstance.name)throw new TypeError("Failed to process because initialization is not valid. Please provide required initialization argument which is the initialization instance returned by the init() function");if(!t||void 0===t.streamId)throw new Error("Failed to process because the stream ID is not provided. Please provide the stream ID!");if("number"!=typeof t.streamId)throw new TypeError("Failed to process because the stream ID is not in a number format. The stream ID must be in a number format");if(!t.sessionDescription||!t.sessionDescription.type||!t.sessionDescription.sdp)throw new TypeError("Failed to process because the local description has wrong format");const{streamId:n,sessionDescription:r}=t,i=`${e.config.api.baseUrl}/${e.config.api.version}`;try{const t=r.toJSON(),o=await fetchHttp({url:`${i}/streams/${n}/init`,token:e.config.apiKey,method:"POST",body:t}),{code:s,data:c}=o;return{status:{code:s||null,type:"success",message:"Successfully initialize a stream session"},data:{sdp:c&&c.sdp?c.sdp:null,type:c&&c.type?c.type:null}}}catch(e){throw console.error(e),e}},prepareStream=async(e,t)=>{if(e.constructor.name!==InitializationInstance.name)throw new TypeError("Failed to process because initialization is not valid. Please provide required initialization argument which is the initialization instance returned by the init() function");if(!t)throw new Error("Failed to process because the stream ID is not provided. Please provide the stream ID!");if("number"!=typeof t)throw new TypeError("Failed to process because the stream ID is not in a number format. The stream ID must be in a number format");const n=`${e.config.api.baseUrl}/${e.config.api.version}`;try{const r=await fetchHttp({url:`${n}/streams/${t}/prepare`,token:e.config.apiKey,method:"POST",body:{}});if(r.code>=300)throw new Error("failed to request prepare endpoint:"+r.message);return!0}catch(e){throw console.error("error sdk prepare",e),e}},startStream=async(e,t)=>{if(e.constructor.name!==InitializationInstance.name)throw new TypeError("Failed to process because initialization is not valid. Please provide required initialization argument which is the initialization instance returned by the init() function");if(!t)throw new Error("Failed to process because the stream ID is not provided. Please provide the stream ID!");if("number"!=typeof t)throw new TypeError("Failed to process because the stream ID is not in a number format. The stream ID must be in a number format");const n=`${e.config.api.baseUrl}/${e.config.api.version}`;try{const r=await fetchHttp({url:`${n}/streams/${t}/start`,token:e.config.apiKey,method:"POST",body:{}});if(r.code>=300)throw new Error("failed to request start endpoint:"+r.message);return r.data}catch(e){throw console.error(e),e}},fetchStream=async(e,t)=>{if("string"!=typeof e||0===e.trim().length)throw new Error("Error because invalid API base url");if(null==t)throw new Error("Failed to get the stream data because the stream ID is empty. Please provide a stream ID");if("number"!=typeof t)throw new TypeError("Failed to get the stream data because the stream ID is not in number format. A stream ID must be number format");{let n=await fetchHttp({url:`${e}/streams/${t}`,method:"GET"}).catch((e=>e));if(n&&404===n.code)throw new Error("Failed to get the stream data because the stream ID is not found. Please provide a valid stream ID.");const r=n.data;return{id:r.id,name:r.name,slug:r.slug,description:r.description,hlsUrl:r.hls_url,dashUrl:r.dash_url,createdAt:r.created_at,updatedAt:r.updated_at,preparedAt:r.prepared_at,startedAt:r.start_time,endedAt:r.end_time,createdBy:r.created_by,updatedBy:r.updated_by,quality:r.quality}}},endStream=async(e,t)=>{if(e.constructor.name!==InitializationInstance.name)throw new TypeError("Failed to process because initialization is not valid. Please provide required initialization argument which is the initialization instance returned by the init() function");if(!t||void 0===t)throw new Error("Failed to process because the stream ID is not provided. Please provide the stream ID!");if("number"!=typeof t)throw new TypeError("Failed to process because the stream ID is not in a number format. The stream ID must be in a number format");const n=`${e.config.api.baseUrl}/${e.config.api.version}`;try{return await fetchHttp({url:`${n}/streams/${t}/end`,token:e.config.apiKey,method:"POST",body:{}}),!0}catch(e){throw console.error(e),e}},{webrtc:k}=T;class Stream{static READY="streamReady";static STARTED="streamStarted";static ENDED="streamEnded";static ERROR="streamError";static ICECANDIDATE="iceCandidate";static STATECHANGED="stateChanged";static STATE_NEW="new";static STATE_CONNECTING="connecting";static STATE_CONNECTED="connected";static STATE_COMPLETED="completed";static STATE_DISCONNECTED="disconnected";static STATE_READY="ready";static STATE_LIVE="live";static STATE_FAILED="failed";static STATE_ENDED="ended";constructor(e,t){this.app=e,this.id=t.id,this.state=Stream.STATE_NEW,this.name=t.name,this.data=t,this.mediaStream=null,this.peerConnection=null,this.eventHandlers={streamStarted:[],streamEnded:[],streamError:[],iceCandidate:[],stateChanged:[]},this.manifests={dash:"",hls:""},""!==t.dashUrl&&""!==t.hlsUrl&&(this.manifests.dash=t.dashUrl,this.manifests.hls=t.hlsUrl),this.pandingIceCandidates=[]}getAPIUrl(){return`${this.app.config.api.baseUrl}/${this.app.config.api.version}`}async subscribe(){let e=null;const t=this.getAPIUrl();if(void 0===this.app.config.apiKey||""===this.app.config.apiKey)e=new EventSource(`${t}/streams/${this.id}/events`,{withCredentials:!0});else{const n=await getEventKey(this.app.config.apiKey,t);e=new EventSource(`${t}/streams/${this.id}/events/${n}`,{withCredentials:!0})}this.setEventHandlers(e)}async setEventHandlers(e){e.addEventListener(Stream.STARTED,(e=>{this.dispatchEvent(Stream.STARTED,e.data)})),e.addEventListener(Stream.ENDED,(e=>{this.dispatchEvent(Stream.ENDED,e.data)})),e.addEventListener(Stream.ERROR,(e=>{this.dispatchEvent(Stream.ERROR,e.data)})),e.addEventListener(Stream.ICECANDIDATE,(e=>{const t=JSON.parse(e.data);this.addIceCandidate(t)}))}addIceCandidate(e){if(null===this.peerConnection)throw new Error("the peer connection is not set");const t=new RTCIceCandidate(e);null!==this.peerConnection.remoteDescription&&null===this.peerConnection.pendingRemoteDescription?this.peerConnection.addIceCandidate(t):this.pandingIceCandidates.push(t)}dispatchEvent(e,t){if(!(e in this.eventHandlers))throw new Error("Unknown event, available events are Stream.READY|Stream.STARTED|Stream.ENDED|Stream.ERROR|Stream.STATECHANGED");for(const n of this.eventHandlers[e])n(t)}on(e,t){void 0===this.eventHandlers[e]&&(this.eventHandlers[e]=[]),this.eventHandlers[e].push(t)}changeState(e){this.state=e,this.dispatchEvent(Stream.STATECHANGED,{state:e})}listenForWebRTCEvent(){this.peerConnection.addEventListener("icecandidate",(e=>{if(e.candidate){if(""===e.candidate.candidate)return;const{candidate:t}=e;this.sendIceCandidate(t)}})),this.peerConnection.addEventListener("iceconnectionstatechange",(()=>{switch(this.peerConnection.iceConnectionState){case"new":this.changeState(Stream.STATE_CONNECTING);break;case"connected":this.changeState(Stream.STATE_CONNECTED);break;case"completed":this.changeState(Stream.STATE_COMPLETED);break;case"disconnected":this.changeState(Stream.STATE_DISCONNECTED);break;case"closed":this.changeState(Stream.STATE_ENDED);break;case"failed":this.changeState(Stream.STATE_FAILED)}}))}addPendingIceCandidates(){for(const e of this.pandingIceCandidates)this.peerConnection?.addIceCandidate(e)}async init(e){this.state===Stream.STATE_NEW&&await this.prepare(),this.mediaStream=e,this.peerConnection=k.openConnection(),this.listenForWebRTCEvent();for(const t of e.getTracks())this.peerConnection.addTrack(t,e);const t=await this.peerConnection.createOffer();await this.peerConnection.setLocalDescription(t);const n=new Promise(((e,t)=>{this.on(Stream.STATECHANGED,(n=>{n.state===Stream.STATE_CONNECTED||n.state===Stream.STATE_COMPLETED?e(!0):n.state===Stream.STATE_FAILED&&t(!1)})),this.on(Stream.ERROR,(()=>t(!1)))})),r={streamId:this.id,sessionDescription:this.peerConnection.localDescription},i=await initStream(this.app,r);return this.peerConnection.setRemoteDescription(i.data),this.addPendingIceCandidates(),n}async sendIceCandidate(e){const t=this.getAPIUrl();let n=await fetchHttp({url:`${t}/streams/${this.id}/ice`,body:e.toJSON(),token:this.app.config.apiKey,method:"POST"});if(n)switch(n.code){case 404:throw new Error("the stream ID is not found. Please provide a valid stream ID.");case 400:throw new Error("Bad request, invalid ice candidate")}}async prepare(){await this.subscribe(),await prepareStream(this.app,this.id),this.changeState(Stream.STATE_READY)}async live(){if(this.state!==Stream.STATE_CONNECTED&&this.state!==Stream.STATE_COMPLETED)throw new Error("The live function is called before the state change to connected/completed. Use stream.on(Stream.STATECHANGED,(ev) => if(ev.state ===Stream.STATE_COMPLETED || ev.state ===Stream.STATE_CONNECTED){...}) to know when the connection is ready for live.");this.manifests=await startStream(this.app,this.id),this.data=await fetchStream(this.getAPIUrl(),this.id),this.changeState(Stream.STATE_LIVE)}async end(){await endStream(this.app,this.id),this.peerConnection&&this.peerConnection.close(),this.data=await fetchStream(this.getAPIUrl(),this.id),this.changeState(Stream.STATE_ENDED)}}function eq(e,t){return e===t||e!=e&&t!=t}function assocIndexOf(e,t){for(var n=e.length;n--;)if(eq(e[n][0],t))return n;return-1}var L=Array.prototype.splice;function ListCache(e){var t=-1,n=null==e?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}ListCache.prototype.clear=function listCacheClear(){this.__data__=[],this.size=0},ListCache.prototype.delete=function listCacheDelete(e){var t=this.__data__,n=assocIndexOf(t,e);return!(n<0)&&(n==t.length-1?t.pop():L.call(t,n,1),--this.size,!0)},ListCache.prototype.get=function listCacheGet(e){var t=this.__data__,n=assocIndexOf(t,e);return n<0?void 0:t[n][1]},ListCache.prototype.has=function listCacheHas(e){return assocIndexOf(this.__data__,e)>-1},ListCache.prototype.set=function listCacheSet(e,t){var n=this.__data__,r=assocIndexOf(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this};var F="object"==typeof global&&global&&global.Object===Object&&global,O="object"==typeof self&&self&&self.Object===Object&&self,D=F||O||Function("return this")(),M=D.Symbol,R=Object.prototype,z=R.hasOwnProperty,P=R.toString,V=M?M.toStringTag:void 0;var N=Object.prototype.toString;var W="[object Null]",G="[object Undefined]",X=M?M.toStringTag:void 0;function baseGetTag(e){return null==e?void 0===e?G:W:X&&X in Object(e)?function getRawTag(e){var t=z.call(e,V),n=e[V];try{e[V]=void 0;var r=!0}catch(e){}var i=P.call(e);return r&&(t?e[V]=n:delete e[V]),i}(e):function objectToString(e){return N.call(e)}(e)}function isObject(e){var t=typeof e;return null!=e&&("object"==t||"function"==t)}var Z="[object AsyncFunction]",H="[object Function]",Y="[object GeneratorFunction]",U="[object Proxy]";function isFunction(e){if(!isObject(e))return!1;var t=baseGetTag(e);return t==H||t==Y||t==Z||t==U}var $,J=D["__core-js_shared__"],B=($=/[^.]+$/.exec(J&&J.keys&&J.keys.IE_PROTO||""))?"Symbol(src)_1."+$:"";var K=Function.prototype.toString;var q=/^\[object .+?Constructor\]$/,Q=Function.prototype,ee=Object.prototype,te=Q.toString,ne=ee.hasOwnProperty,re=RegExp("^"+te.call(ne).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function baseIsNative(e){return!(!isObject(e)||function isMasked(e){return!!B&&B in e}(e))&&(isFunction(e)?re:q).test(function toSource(e){if(null!=e){try{return K.call(e)}catch(e){}try{return e+""}catch(e){}}return""}(e))}function getNative(e,t){var n=function getValue(e,t){return null==e?void 0:e[t]}(e,t);return baseIsNative(n)?n:void 0}var ae=getNative(D,"Map"),ie=getNative(Object,"create");var oe=Object.prototype.hasOwnProperty;var se=Object.prototype.hasOwnProperty;function Hash(e){var t=-1,n=null==e?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function getMapData(e,t){var n=e.__data__;return function isKeyable(e){var t=typeof e;return"string"==t||"number"==t||"symbol"==t||"boolean"==t?"__proto__"!==e:null===e}(t)?n["string"==typeof t?"string":"hash"]:n.map}function MapCache(e){var t=-1,n=null==e?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}Hash.prototype.clear=function hashClear(){this.__data__=ie?ie(null):{},this.size=0},Hash.prototype.delete=function hashDelete(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t},Hash.prototype.get=function hashGet(e){var t=this.__data__;if(ie){var n=t[e];return"__lodash_hash_undefined__"===n?void 0:n}return oe.call(t,e)?t[e]:void 0},Hash.prototype.has=function hashHas(e){var t=this.__data__;return ie?void 0!==t[e]:se.call(t,e)},Hash.prototype.set=function hashSet(e,t){var n=this.__data__;return this.size+=this.has(e)?0:1,n[e]=ie&&void 0===t?"__lodash_hash_undefined__":t,this},MapCache.prototype.clear=function mapCacheClear(){this.size=0,this.__data__={hash:new Hash,map:new(ae||ListCache),string:new Hash}},MapCache.prototype.delete=function mapCacheDelete(e){var t=getMapData(this,e).delete(e);return this.size-=t?1:0,t},MapCache.prototype.get=function mapCacheGet(e){return getMapData(this,e).get(e)},MapCache.prototype.has=function mapCacheHas(e){return getMapData(this,e).has(e)},MapCache.prototype.set=function mapCacheSet(e,t){var n=getMapData(this,e),r=n.size;return n.set(e,t),this.size+=n.size==r?0:1,this};function Stack(e){var t=this.__data__=new ListCache(e);this.size=t.size}Stack.prototype.clear=function stackClear(){this.__data__=new ListCache,this.size=0},Stack.prototype.delete=function stackDelete(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n},Stack.prototype.get=function stackGet(e){return this.__data__.get(e)},Stack.prototype.has=function stackHas(e){return this.__data__.has(e)},Stack.prototype.set=function stackSet(e,t){var n=this.__data__;if(n instanceof ListCache){var r=n.__data__;if(!ae||r.length<199)return r.push([e,t]),this.size=++n.size,this;n=this.__data__=new MapCache(r)}return n.set(e,t),this.size=n.size,this};var ce=function(){try{var e=getNative(Object,"defineProperty");return e({},"",{}),e}catch(e){}}();function baseAssignValue(e,t,n){"__proto__"==t&&ce?ce(e,t,{configurable:!0,enumerable:!0,value:n,writable:!0}):e[t]=n}function assignMergeValue(e,t,n){(void 0!==n&&!eq(e[t],n)||void 0===n&&!(t in e))&&baseAssignValue(e,t,n)}var ue=function createBaseFor(e){return function(t,n,r){for(var i=-1,o=Object(t),s=r(t),c=s.length;c--;){var u=s[e?c:++i];if(!1===n(o[u],u,o))break}return t}}(),le=ue,de="object"==typeof exports&&exports&&!exports.nodeType&&exports,he=de&&"object"==typeof module&&module&&!module.nodeType&&module,fe=he&&he.exports===de?D.Buffer:void 0,pe=fe?fe.allocUnsafe:void 0;var me=D.Uint8Array;function cloneTypedArray(e,t){var n=t?function cloneArrayBuffer(e){var t=new e.constructor(e.byteLength);return new me(t).set(new me(e)),t}(e.buffer):e.buffer;return new e.constructor(n,e.byteOffset,e.length)}var ve=Object.create,be=function(){function object(){}return function(e){if(!isObject(e))return{};if(ve)return ve(e);object.prototype=e;var t=new object;return object.prototype=void 0,t}}();var ye=function overArg(e,t){return function(n){return e(t(n))}}(Object.getPrototypeOf,Object),ge=Object.prototype;function isPrototype(e){var t=e&&e.constructor;return e===("function"==typeof t&&t.prototype||ge)}function isObjectLike(e){return null!=e&&"object"==typeof e}function baseIsArguments(e){return isObjectLike(e)&&"[object Arguments]"==baseGetTag(e)}var we=Object.prototype,_e=we.hasOwnProperty,Se=we.propertyIsEnumerable,Ce=baseIsArguments(function(){return arguments}())?baseIsArguments:function(e){return isObjectLike(e)&&_e.call(e,"callee")&&!Se.call(e,"callee")},Ee=Array.isArray,Ae=9007199254740991;function isLength(e){return"number"==typeof e&&e>-1&&e%1==0&&e<=Ae}function isArrayLike(e){return null!=e&&isLength(e.length)&&!isFunction(e)}var Ie="object"==typeof exports&&exports&&!exports.nodeType&&exports,je=Ie&&"object"==typeof module&&module&&!module.nodeType&&module,Te=je&&je.exports===Ie?D.Buffer:void 0,xe=(Te?Te.isBuffer:void 0)||function stubFalse(){return!1},ke="[object Object]",Le=Function.prototype,Fe=Object.prototype,Oe=Le.toString,De=Fe.hasOwnProperty,Me=Oe.call(Object);var Re={};Re["[object Float32Array]"]=Re["[object Float64Array]"]=Re["[object Int8Array]"]=Re["[object Int16Array]"]=Re["[object Int32Array]"]=Re["[object Uint8Array]"]=Re["[object Uint8ClampedArray]"]=Re["[object Uint16Array]"]=Re["[object Uint32Array]"]=!0,Re["[object Arguments]"]=Re["[object Array]"]=Re["[object ArrayBuffer]"]=Re["[object Boolean]"]=Re["[object DataView]"]=Re["[object Date]"]=Re["[object Error]"]=Re["[object Function]"]=Re["[object Map]"]=Re["[object Number]"]=Re["[object Object]"]=Re["[object RegExp]"]=Re["[object Set]"]=Re["[object String]"]=Re["[object WeakMap]"]=!1;var ze="object"==typeof exports&&exports&&!exports.nodeType&&exports,Pe=ze&&"object"==typeof module&&module&&!module.nodeType&&module,Ve=Pe&&Pe.exports===ze&&F.process,Ne=function(){try{var e=Pe&&Pe.require&&Pe.require("util").types;return e||Ve&&Ve.binding&&Ve.binding("util")}catch(e){}}(),We=Ne&&Ne.isTypedArray,Ge=We?function baseUnary(e){return function(t){return e(t)}}(We):function baseIsTypedArray(e){return isObjectLike(e)&&isLength(e.length)&&!!Re[baseGetTag(e)]};function safeGet(e,t){if(("constructor"!==t||"function"!=typeof e[t])&&"__proto__"!=t)return e[t]}var Xe=Object.prototype.hasOwnProperty;function assignValue(e,t,n){var r=e[t];Xe.call(e,t)&&eq(r,n)&&(void 0!==n||t in e)||baseAssignValue(e,t,n)}var Ze=9007199254740991,He=/^(?:0|[1-9]\d*)$/;function isIndex(e,t){var n=typeof e;return!!(t=null==t?Ze:t)&&("number"==n||"symbol"!=n&&He.test(e))&&e>-1&&e%1==0&&e<t}var Ye=Object.prototype.hasOwnProperty;function arrayLikeKeys(e,t){var n=Ee(e),r=!n&&Ce(e),i=!n&&!r&&xe(e),o=!n&&!r&&!i&&Ge(e),s=n||r||i||o,c=s?function baseTimes(e,t){for(var n=-1,r=Array(e);++n<e;)r[n]=t(n);return r}(e.length,String):[],u=c.length;for(var l in e)!t&&!Ye.call(e,l)||s&&("length"==l||i&&("offset"==l||"parent"==l)||o&&("buffer"==l||"byteLength"==l||"byteOffset"==l)||isIndex(l,u))||c.push(l);return c}var Ue=Object.prototype.hasOwnProperty;function baseKeysIn(e){if(!isObject(e))return function nativeKeysIn(e){var t=[];if(null!=e)for(var n in Object(e))t.push(n);return t}(e);var t=isPrototype(e),n=[];for(var r in e)("constructor"!=r||!t&&Ue.call(e,r))&&n.push(r);return n}function keysIn(e){return isArrayLike(e)?arrayLikeKeys(e,!0):baseKeysIn(e)}function toPlainObject(e){return function copyObject(e,t,n,r){var i=!n;n||(n={});for(var o=-1,s=t.length;++o<s;){var c=t[o],u=r?r(n[c],e[c],c,n,e):void 0;void 0===u&&(u=e[c]),i?baseAssignValue(n,c,u):assignValue(n,c,u)}return n}(e,keysIn(e))}function baseMergeDeep(e,t,n,r,i,o,s){var c=safeGet(e,n),u=safeGet(t,n),l=s.get(u);if(l)assignMergeValue(e,n,l);else{var d=o?o(c,u,n+"",e,t,s):void 0,h=void 0===d;if(h){var f=Ee(u),p=!f&&xe(u),m=!f&&!p&&Ge(u);d=u,f||p||m?Ee(c)?d=c:!function isArrayLikeObject(e){return isObjectLike(e)&&isArrayLike(e)}(c)?p?(h=!1,d=function cloneBuffer(e,t){if(t)return e.slice();var n=e.length,r=pe?pe(n):new e.constructor(n);return e.copy(r),r}(u,!0)):m?(h=!1,d=cloneTypedArray(u,!0)):d=[]:d=function copyArray(e,t){var n=-1,r=e.length;for(t||(t=Array(r));++n<r;)t[n]=e[n];return t}(c):function isPlainObject(e){if(!isObjectLike(e)||baseGetTag(e)!=ke)return!1;var t=ye(e);if(null===t)return!0;var n=De.call(t,"constructor")&&t.constructor;return"function"==typeof n&&n instanceof n&&Oe.call(n)==Me}(u)||Ce(u)?(d=c,Ce(c)?d=toPlainObject(c):isObject(c)&&!isFunction(c)||(d=function initCloneObject(e){return"function"!=typeof e.constructor||isPrototype(e)?{}:be(ye(e))}(u))):h=!1}h&&(s.set(u,d),i(d,u,r,o,s),s.delete(u)),assignMergeValue(e,n,d)}}function baseMerge(e,t,n,r,i){e!==t&&le(t,(function(o,s){if(i||(i=new Stack),isObject(o))baseMergeDeep(e,t,s,n,baseMerge,r,i);else{var c=r?r(safeGet(e,s),o,s+"",e,t,i):void 0;void 0===c&&(c=o),assignMergeValue(e,s,c)}}),keysIn)}function identity(e){return e}var $e=Math.max;var Je=ce?function(e,t){return ce(e,"toString",{configurable:!0,enumerable:!1,value:(n=t,function(){return n}),writable:!0});var n}:identity,Be=Date.now;var Ke=function shortOut(e){var t=0,n=0;return function(){var r=Be(),i=16-(r-n);if(n=r,i>0){if(++t>=800)return arguments[0]}else t=0;return e.apply(void 0,arguments)}}(Je);function baseRest(e,t){return Ke(function overRest(e,t,n){return t=$e(void 0===t?e.length-1:t,0),function(){for(var r=arguments,i=-1,o=$e(r.length-t,0),s=Array(o);++i<o;)s[i]=r[t+i];i=-1;for(var c=Array(t+1);++i<t;)c[i]=r[i];return c[t]=n(s),function apply(e,t,n){switch(n.length){case 0:return e.call(t);case 1:return e.call(t,n[0]);case 2:return e.call(t,n[0],n[1]);case 3:return e.call(t,n[0],n[1],n[2])}return e.apply(t,n)}(e,this,c)}}(e,t,identity),e+"")}var qe=function createAssigner(e){return baseRest((function(t,n){var r=-1,i=n.length,o=i>1?n[i-1]:void 0,s=i>2?n[2]:void 0;for(o=e.length>3&&"function"==typeof o?(i--,o):void 0,s&&function isIterateeCall(e,t,n){if(!isObject(n))return!1;var r=typeof t;return!!("number"==r?isArrayLike(n)&&isIndex(t,n.length):"string"==r&&t in n)&&eq(n[t],e)}(n[0],n[1],s)&&(o=i<3?void 0:o,i=1),t=Object(t);++r<i;){var c=n[r];c&&e(t,c,r,o)}return t}))}((function(e,t,n){baseMerge(e,t,n)})),Qe=qe;const et={page:1,pageSize:10};class Media{constructor(e){this.stream=e}attachTo(e){if(!(e instanceof HTMLVideoElement))throw new TypeError("Failed to process - input must be a video element");e.srcObject=this.stream,e.autoplay=!0,e.muted=!0,e.playsInline=!0,e.controls=!1}}const tt=(()=>{const e={video:{frameRate:30,width:{min:640,ideal:1280,max:1280},height:{min:360,ideal:720,max:720}},audio:!0};return{getUserMedia:async(t={})=>{const n=await navigator.mediaDevices.getUserMedia({video:e.video,audio:e.audio,...t});return new Media(n)}}})();Object.freeze(tt);var nt="3.4.0";function wait(e,t){return new Promise((function(n){return setTimeout(n,e,t)}))}function awaitIfAsync(e,t){try{var n=e();!function isPromise(e){return!!e&&"function"==typeof e.then}(n)?t(!0,n):n.then((function(e){return t(!0,e)}),(function(e){return t(!1,e)}))}catch(e){t(!1,e)}}function forEachWithBreaks(e,t,n){return void 0===n&&(n=16),__awaiter(this,void 0,void 0,(function(){var r,i,o;return __generator(this,(function(s){switch(s.label){case 0:r=Date.now(),i=0,s.label=1;case 1:return i<e.length?(t(e[i],i),(o=Date.now())>=r+n?(r=o,[4,wait(0)]):[3,3]):[3,4];case 2:s.sent(),s.label=3;case 3:return++i,[3,1];case 4:return[2]}}))}))}function suppressUnhandledRejectionWarning(e){e.then(void 0,(function(){}))}function x64Add(e,t){e=[e[0]>>>16,65535&e[0],e[1]>>>16,6553