UNPKG

@daily-co/daily-react

Version:

Daily React makes it easier to integrate [@daily-co/daily-js](https://www.npmjs.com/package/@daily-co/daily-js) in React applications.

1 lines 56.7 kB
import{atomFamily as n,useAtomCallback as e}from"jotai/utils";import t,{createContext as i,useContext as r,useDebugValue as o,useState as a,useRef as u,useMemo as c,useEffect as l,useCallback as d,memo as s,forwardRef as f,useImperativeHandle as v}from"react";import{atom as p,useAtomValue as g,Provider as m,useAtom as y}from"jotai";import b from"@daily-co/daily-js";function h(n){return h="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},h(n)}var S=function(){return S=Object.assign||function(n){for(var e,t=1,i=arguments.length;t<i;t++)for(var r in e=arguments[t])Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n},S.apply(this,arguments)};function k(n,e){var t={};for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&e.indexOf(i)<0&&(t[i]=n[i]);if(null!=n&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(n);r<i.length;r++)e.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(n,i[r])&&(t[i[r]]=n[i[r]])}return t}function w(n,e,t,i){return new(t||(t=Promise))(function(r,o){function a(n){try{c(i.next(n))}catch(n){o(n)}}function u(n){try{c(i.throw(n))}catch(n){o(n)}}function c(n){var e;n.done?r(n.value):(e=n.value,e instanceof t?e:new t(function(n){n(e)})).then(a,u)}c((i=i.apply(n,e||[])).next())})}function A(n,e){var t,i,r,o,a={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(u){return function(c){return function(u){if(t)throw new TypeError("Generator is already executing.");for(;o&&(o=0,u[0]&&(a=0)),a;)try{if(t=1,i&&(r=2&u[0]?i.return:u[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,u[1])).done)return r;switch(i=0,r&&(u=[2&u[0],r.value]),u[0]){case 0:case 1:r=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,i=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!(r=a.trys,(r=r.length>0&&r[r.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!r||u[1]>r[0]&&u[1]<r[3])){a.label=u[1];break}if(6===u[0]&&a.label<r[1]){a.label=r[1],r=u;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(u);break}r[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(n,a)}catch(n){u=[6,n],i=0}finally{t=r=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,c])}}}function L(n){var e="function"==typeof Symbol&&Symbol.iterator,t=e&&n[e],i=0;if(t)return t.call(n);if(n&&"number"==typeof n.length)return{next:function(){return n&&i>=n.length&&(n=void 0),{value:n&&n[i++],done:!n}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function j(n,e){var t="function"==typeof Symbol&&n[Symbol.iterator];if(!t)return n;var i,r,o=t.call(n),a=[];try{for(;(void 0===e||e-- >0)&&!(i=o.next()).done;)a.push(i.value)}catch(n){r={error:n}}finally{try{i&&!i.done&&(t=o.return)&&t.call(o)}finally{if(r)throw r.error}}return a}function E(n,e,t){if(t||2===arguments.length)for(var i,r=0,o=e.length;r<o;r++)!i&&r in e||(i||(i=Array.prototype.slice.call(e,0,r)),i[r]=e[r]);return n.concat(i||Array.prototype.slice.call(e))}"function"==typeof SuppressedError&&SuppressedError;var I=i(null),_=function(){var n=r(I);return o(n),n},O=i({on:function(){},off:function(){}}),M=-1,P=function(){return M--},T=1,R=function(){return T++},x=function(n,e,t){void 0===t&&(t=!1);var i=r(O),d=i.off,s=i.on,f=j(a(!1),2),v=f[0],p=f[1],g=u(0),m=c(function(){return t?P():R()},[t]);l(function(){if(n&&!v){if(g.current>1e5)return console.error("useDailyEvent called with potentially non-memoized event callback or due to too many re-renders.\n Memoize using useCallback to avoid re-render loop or reduce the amount of state transitions the callback depends on.\n Passed callback for '".concat(n,"' event is NOT registered."),e),void p(!0);g.current++;var t=setTimeout(function(){g.current=0},50);return s(n,e,m),function(){clearTimeout(t),d(n,m)}}},[e,n,m,v,d,s]),o({event:n,eventId:m,isBlocked:v,callback:e})};function D(n,e){var t,i;if(n===e)return!0;if(Array.isArray(n)&&Array.isArray(e)){if(n.length!==e.length)return!1;for(var r=0;r<n.length;r++)if(!D(n[r],e[r]))return!1;return!0}if(MediaStream&&n instanceof MediaStream&&e instanceof MediaStream)return n.id===e.id&&n.active===e.active&&n.getTracks().length===e.getTracks().length&&n.getTracks().every(function(n,t){return D(n,e.getTracks()[t])});if(MediaStreamTrack&&n instanceof MediaStreamTrack&&e instanceof MediaStreamTrack)return n.id===e.id&&n.kind===e.kind&&n.readyState===e.readyState;if(n instanceof Date&&e instanceof Date)return n.getTime()===e.getTime();if(n instanceof RegExp&&e instanceof RegExp)return n.source===e.source&&n.flags===e.flags;if(n instanceof Set&&e instanceof Set){if(n.size!==e.size)return!1;var o=Array.from(n).sort(),a=Array.from(e).sort();return o.every(function(n,e){return D(n,a[e])})}if(n instanceof Map&&e instanceof Map){if(n.size!==e.size)return!1;try{for(var u=L(n.entries()),c=u.next();!c.done;c=u.next()){var l=j(c.value,2),d=l[0],s=l[1];if(!e.has(d)||!D(s,e.get(d)))return!1}}catch(n){t={error:n}}finally{try{c&&!c.done&&(i=u.return)&&i.call(u)}finally{if(t)throw t.error}}return!0}if("object"!==h(n)||null===n||"object"!==h(e)||null===e)return!1;var f=Object.keys(n),v=Object.keys(e);if(f.length!==v.length)return!1;for(r=0;r<f.length;r++){d=f[r];if(!Object.prototype.hasOwnProperty.call(e,d)||!D(n[d],e[d]))return!1}return!0}function C(n,e){if(n===e)return!0;if(n.length!==e.length)return!1;for(var t=0;t<n.length;t++){var i=n[t],r=e[t],o=null!==i&&"object"===h(i),a=null!==r&&"object"===h(r);if(o||a){if(!D(i,r))return!1}else if(i!==r)return!1}return!0}function F(n){return"daily-react-"+n}function B(n){var e=new Map,t=new Map;return function(i){if(!e.has(i)){var r=p(function(e){var r=n.get(i)(e),o=t.get(i);return null!=o&&n.equals(r,o)?o:(t.set(i,r),r)});e.set(i,r)}return e.get(i)}}var q,W,U="::",N=function(n,e){return n+U+e},z=function(n,e){return G(N(n,e))},V=n(function(n){var e=p([]);return e.debugLabel=F("participant-property-paths-".concat(n)),e}),G=n(function(n){var e=p(null);return e.debugLabel=F("participant-property-".concat(n)),e}),$=B({equals:C,get:function(n){return function(e){var t=j(n.split(U),2),i=t[0];return t[1].split(";").map(function(n){return e(z(i,n))})}}}),H=function(n,e){var t,i=g(Array.isArray(e)?$(function(n,e){return n+U+e.join(";")}(n,e)):G(N(n,e)));return o(Array.isArray(e)?e.reduce(function(n,e,t){return n[e]=i[t],n},{}):((t={})[e]=i,t)),i},J="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function Q(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}var K=Q(function(){if(W)return q;W=1;var n="Expected a function",e=/^\s+|\s+$/g,t=/^[-+]0x[0-9a-f]+$/i,i=/^0b[01]+$/i,r=/^0o[0-7]+$/i,o=parseInt,a="object"==h(J)&&J&&J.Object===Object&&J,u="object"==("undefined"==typeof self?"undefined":h(self))&&self&&self.Object===Object&&self,c=a||u||Function("return this")(),l=Object.prototype.toString,d=Math.max,s=Math.min,f=function(){return c.Date.now()};function v(e,t,i){var r,o,a,u,c,l,v=0,g=!1,y=!1,b=!0;if("function"!=typeof e)throw new TypeError(n);function h(n){var t=r,i=o;return r=o=void 0,v=n,u=e.apply(i,t)}function S(n){var e=n-l;return void 0===l||e>=t||e<0||y&&n-v>=a}function k(){var n=f();if(S(n))return w(n);c=setTimeout(k,function(n){var e=t-(n-l);return y?s(e,a-(n-v)):e}(n))}function w(n){return c=void 0,b&&r?h(n):(r=o=void 0,u)}function A(){var n=f(),e=S(n);if(r=arguments,o=this,l=n,e){if(void 0===c)return function(n){return v=n,c=setTimeout(k,t),g?h(n):u}(l);if(y)return c=setTimeout(k,t),h(l)}return void 0===c&&(c=setTimeout(k,t)),u}return t=m(t)||0,p(i)&&(g=!!i.leading,a=(y="maxWait"in i)?d(m(i.maxWait)||0,t):a,b="trailing"in i?!!i.trailing:b),A.cancel=function(){void 0!==c&&clearTimeout(c),v=0,r=l=o=c=void 0},A.flush=function(){return void 0===c?u:w(f())},A}function p(n){var e=h(n);return!!n&&("object"==e||"function"==e)}function g(n){return"symbol"==h(n)||function(n){return!!n&&"object"==h(n)}(n)&&"[object Symbol]"==l.call(n)}function m(n){if("number"==typeof n)return n;if(g(n))return NaN;if(p(n)){var a="function"==typeof n.valueOf?n.valueOf():n;n=p(a)?a+"":a}if("string"!=typeof n)return 0===n?n:+n;n=n.replace(e,"");var u=i.test(n);return u||r.test(n)?o(n.slice(2),u?2:8):t.test(n)?NaN:+n}return q=function(e,t,i){var r=!0,o=!0;if("function"!=typeof e)throw new TypeError(n);return p(i)&&(r="leading"in i?!!i.leading:r,o="trailing"in i?!!i.trailing:o),v(e,t,{leading:r,maxWait:t,trailing:o})}}()),X=function(n,e,t,i){void 0===t&&(t=500),void 0===i&&(i=!1);var a=r(O),s=a.off,f=a.on,v=c(function(){var e;return Array.isArray(n)?n.reduce(function(n,e){return n[e]=i?P():R(),n},{}):((e={})[n]=i?P():R(),e)},[n,i]),p=u([]);x("call-instance-destroyed",d(function(){p.current.length=0},[]));var g=c(function(){return K(function(){0!==p.current.length&&(e(p.current),p.current.length=0)},t,{trailing:!0})},[e,t]);l(function(){if(n){var e=function(n){p.current.push(n),g()};return Array.isArray(n)?n.forEach(function(n){return f(n,e,v[n])}):f(n,e,v[n]),function(){Array.isArray(n)?n.forEach(function(n){return s(n,v[n])}):s(n,v[n])}}},[g,n,v,s,f]),o({event:n,eventId:v})},Y=function n(e,t,i){if(void 0===t&&(t=""),void 0===i&&(i=new Set),"object"!==h(e)||null===e||i.has(e))return[t];i.add(e);var r=[];for(var o in e)if(Object.prototype.hasOwnProperty.call(e,o)){var a=t?"".concat(t,".").concat(o):o;r.push.apply(r,E([a],j(n(e[o],a,i)),!1))}return i.delete(e),r},Z=function(n){return Y(n)},nn=function(n,e){return e.map(function(e){return function(n,e){return String(e).split(".").filter(function(n){return n.length}).reduce(function(n,e){return n&&n[e]},n)}(n,e)})},en=p(null);en.debugLabel=F("active-id");var tn=p("");tn.debugLabel=F("local-id");var rn=p(null);rn.debugLabel=F("local-join-date");var on=p([]);on.debugLabel=F("participant-ids");var an=n(function(n){var e=p(null);return e.debugLabel=F("participant-".concat(n)),e}),un=p([]);un.debugLabel=F("waiting-participants");var cn=n(function(n){var e=p({awaitingAccess:{level:"full"},id:n,name:""});return e.debugLabel=F("waiting-participant-".concat(n)),e}),ln=B({equals:C,get:function(){return function(n){return n(un).map(function(e){return n(cn(e))})}}}),dn=function(n){var i=n.children,r=_(),o=j(a(!1),2),u=o[0],c=o[1],s=e(d(function(n,e,t){e(tn,t.local.session_id);var i=Object.values(t),r=i.map(function(n){return n.session_id});e(on,r),i.forEach(function(n){e(an(n.session_id),n);var t=Z(n);e(V(n.session_id),t),t.forEach(function(t){var i=j(nn(n,[t]),1)[0];e(z(n.session_id,t),i)})}),c(!0)},[]));l(function(){if(r&&!u){var n=setInterval(function(){var e=r.participants();"local"in e&&(s(e),clearInterval(n))},100);return function(){clearInterval(n)}}},[r,u,s]);var f=d(function(){if(r){var n=null==r?void 0:r.participants();n.local&&s(n)}},[r,s]);x("started-camera",f,!0),x("access-state-updated",f,!0),x("joining-meeting",e(d(function(n,e){e(rn,new Date),f()},[f])),!0),x("joined-meeting",d(function(n){s(n.participants)},[s]),!0);var v=e(d(function(n,e){e(tn,""),e(en,null),n(on).forEach(function(n){return an.remove(n)}),e(on,[])},[]));return x("call-instance-destroyed",v,!0),x("left-meeting",v,!0),X(["active-speaker-change","participant-joined","participant-updated","participant-left"],e(d(function(n,e,t){t.length&&t.forEach(function(t){switch(t.action){case"active-speaker-change":e(en,t.activeSpeaker.peerId),e(an(t.activeSpeaker.peerId),function(n){return n?S(S({},n),{last_active:new Date}):null});break;case"participant-joined":e(on,function(n){return n.includes(t.participant.session_id)?n:E(E([],j(n),!1),[t.participant.session_id],!1)}),e(an(t.participant.session_id),t.participant);var i=Z(t.participant);e(V(t.participant.session_id),i),i.forEach(function(n){var i=j(nn(t.participant,[n]),1)[0];e(z(t.participant.session_id,n),i)});break;case"participant-updated":e(an(t.participant.session_id),t.participant),t.participant.local&&e(tn,t.participant.session_id);i=Z(t.participant);var r=n(V(t.participant.session_id));(i.length!==r.length||i.some(function(n){return!r.includes(n)}))&&e(V(t.participant.session_id),i);var o=new Set(r),a=nn(t.participant,i);i.forEach(function(n,i){var r=a[i];o.delete(n),e(z(t.participant.session_id,n),function(n){return D(n,r)?n:r})}),o.forEach(function(n){e(z(t.participant.session_id,n),null)});break;case"participant-left":e(on,function(n){return n.includes(t.participant.session_id)?n.filter(function(n){return n!==t.participant.session_id}):n}),an.remove(t.participant.session_id),n(V(t.participant.session_id)).forEach(function(n){G.remove(N(t.participant.session_id,n))}),V.remove(t.participant.session_id)}})},[])),100,!0),X(["waiting-participant-added","waiting-participant-updated","waiting-participant-removed"],e(d(function(n,e,t){t.forEach(function(n){switch(n.action){case"waiting-participant-added":e(un,function(e){return e.includes(n.participant.id)?e:E(E([],j(e),!1),[n.participant.id],!1)}),e(cn(n.participant.id),n.participant);break;case"waiting-participant-updated":e(cn(n.participant.id),n.participant);break;case"waiting-participant-removed":e(un,function(e){return e.filter(function(e){return e!==n.participant.id})}),cn.remove(n.participant.id)}})},[])),100,!0),t.createElement(t.Fragment,null,i)},sn=function(){var n=g(tn);return o(n),n},fn=function(){return!0},vn=function(n){var e=void 0===n?{}:n,t=e.filter,i=void 0===t?fn:t,r=e.ignoreLocal,u=void 0!==r&&r,c=sn(),d=g(en),s=u&&d===c,f=!(null==i?void 0:i(d)),v=j(a(!s&&!f?d:null),2),p=v[0],m=v[1];return l(function(){s||f||m(d)},[f,s,d]),o(p),p},pn=function(n){return["blocked","off"].includes(n)},gn=function(n,e){return"".concat(n).concat(";").concat(e)},mn=B({equals:D,get:function(n){return function(e){var t=j(n.split(";"),2),i=t[0],r=t[1];return e(on).filter(function(n){switch(i){case"local":case"owner":case"record":return e(z(n,i));case"remote":return!e(z(n,"local"));case"screen":var t=e(z(n,"tracks.screenAudio.state")),r=e(z(n,"tracks.screenVideo.state"));return!pn(t)||!pn(r);default:return!0}}).sort(function(n,t){switch(r){case"joined_at":case"session_id":case"user_id":case"user_name":var i=e(z(n,r)),o=e(z(t,r));if(void 0!==i||void 0!==o){if(void 0===i)return-1;if(void 0===o)return 1;if(i>o)return 1;if(i<o)return-1}return 0;default:return 0}})}}}),yn=function(n){var t=void 0===n?{}:n,i=t.filter,r=t.onActiveSpeakerChange,u=t.onParticipantJoined,c=t.onParticipantLeft,s=t.onParticipantUpdated,f=t.sort,v=g(mn(gn("string"==typeof i?i:null,"string"==typeof f?f:null))),p="function"==typeof i||"function"==typeof f,m=d(function(n){return"function"!=typeof i&&"function"!=typeof f?[]:v.map(function(e){return n(an(e))}).filter(function(n){return Boolean(n)}).filter("function"==typeof i?i:function(){return!0}).sort("function"==typeof f?f:function(){return 0}).map(function(n){return n.session_id}).filter(Boolean)},[i,v,f]),y=j(a([]),2),b=y[0],h=y[1],S=e(d(function(n){if(p){var e=m(n);D(e,b)||h(e)}},[b,m,p]));l(function(){S()},[S]),X(["participant-joined","participant-updated","active-speaker-change","participant-left"],d(function(n){n.length&&(n.forEach(function(n){switch(n.action){case"participant-joined":null==u||u(n);break;case"participant-updated":null==s||s(n);break;case"active-speaker-change":null==r||r(n);break;case"participant-left":null==c||c(n)}}),S())},[S,r,u,c,s]));var k="function"==typeof i||"function"==typeof f?b:v;return o(k),k},bn=B({equals:C,get:function(){return function(n){return n(mn(gn("screen",null))).map(function(e){return{local:n(z(e,"local")),screenAudio:n(z(e,"tracks.screenAudio")),screenVideo:n(z(e,"tracks.screenVideo")),screenId:"".concat(e,"-screen"),session_id:e}})}}}),hn=function(n){var e=void 0===n?{}:n,t=e.onError,i=e.onLocalScreenShareStarted,r=e.onLocalScreenShareStopped,a=_(),u=d(function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];null==a||a.startScreenShare.apply(a,E([],j(n),!1))},[a]),c=d(function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];null==a||a.stopScreenShare.apply(a,E([],j(n),!1))},[a]);x("local-screen-share-started",d(function(){return null==i?void 0:i()},[i])),x("local-screen-share-stopped",d(function(){return null==r?void 0:r()},[r])),x("nonfatal-error",d(function(n){"screen-share-error"===n.type&&(null==t||t(n))},[t]));var l=g(bn(void 0)),s={isSharingScreen:l.some(function(n){return n.local}),screens:l,startScreenShare:u,stopScreenShare:c};return o(s),s},Sn=function(n,e){void 0===e&&(e="video");var t=H(n,"tracks.".concat(e)),i=t?S(S({},t),{isOff:pn(t.state)}):{isOff:!0,persistentTrack:void 0,state:"off",subscribed:!1};return o(i),i};function kn(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];return d(function(e){for(var t=0;t<n.length;t++){var i=n[t];"function"==typeof i?i(e):i&&"object"===h(i)&&(i.current=e)}},n)}var wn=s(f(function(n,e){var i=n.onPlayFailed,r=n.sessionId,o=n.type,a=void 0===o?"audio":o,c=k(n,["onPlayFailed","sessionId","type"]),s=u(null),f=Sn(r,a),v=kn(s,e),p=null==f?void 0:f.subscribed;return l(function(){var n=s.current;if(n&&(null==f?void 0:f.persistentTrack)){var e=function(){n.play().catch(function(e){null==i||i({sessionId:r,target:n,type:a,message:e.message,name:e.name})})};return MediaStream?(n.addEventListener("canplay",e),n.srcObject=new MediaStream([null==f?void 0:f.persistentTrack]),function(){null==n||n.removeEventListener("canplay",e)}):(console.warn("MediaStream API not available. Can't setup ".concat(a," for ").concat(r)),void(null==i||i({sessionId:r,target:n,type:a,message:"MediaStream API not available",name:"MediaStream API not available"})))}},[null==f?void 0:f.persistentTrack,i,r,a]),x("participant-left",d(function(n){var e=s.current;n.participant.session_id===r&&e&&(e.srcObject=null)},[r])),t.createElement("audio",S({autoPlay:!0,ref:v},c,{"data-session-id":r,"data-audio-type":a,"data-subscribed":p}))}));wn.displayName="DailyAudioTrack";var An=s(f(function(n,i){var r=n.autoSubscribeActiveSpeaker,o=void 0!==r&&r,c=n.maxSpeakers,l=void 0===c?5:c,s=n.onPlayFailed,f=n.playLocalScreenAudio,p=void 0!==f&&f,g=_(),m=j(a(new Array(l).fill("")),2),y=m[0],b=m[1],h=hn().screens,S=sn(),k=vn({ignoreLocal:!0}),L=u(null);v(i,function(){return{getActiveSpeakerAudio:function(){var n,e;return null!==(e=null===(n=L.current)||void 0===n?void 0:n.querySelector('audio[data-session-id="'.concat(k,'"][data-audio-type="audio"]')))&&void 0!==e?e:null},getAllAudio:function(){var n,e;return Array.from(null!==(e=null===(n=L.current)||void 0===n?void 0:n.querySelectorAll("audio"))&&void 0!==e?e:[])},getAudioBySessionId:function(n){var e,t;return null!==(t=null===(e=L.current)||void 0===e?void 0:e.querySelector('audio[data-session-id="'.concat(n,'"][data-audio-type="audio"]')))&&void 0!==t?t:null},getRmpAudio:function(){var n,e;return Array.from(null!==(e=null===(n=L.current)||void 0===n?void 0:n.querySelectorAll('audio[data-audio-type="rmpAudio"]'))&&void 0!==e?e:[])},getScreenAudio:function(){var n,e;return Array.from(null!==(e=null===(n=L.current)||void 0===n?void 0:n.querySelectorAll('audio[data-audio-type="screenAudio"]'))&&void 0!==e?e:[])},getRmpAudioBySessionId:function(n){var e,t;return null!==(t=null===(e=L.current)||void 0===e?void 0:e.querySelector('audio[data-session-id="'.concat(n,'"][data-audio-type="rmpAudio"]')))&&void 0!==t?t:null},getScreenAudioBySessionId:function(n){var e,t;return null!==(t=null===(e=L.current)||void 0===e?void 0:e.querySelector('audio[data-session-id="'.concat(n,'"][data-audio-type="screenAudio"]')))&&void 0!==t?t:null}}},[k]);var I=e(d(function(n,e,t){return w(void 0,void 0,void 0,function(){var e,i,r;return A(this,function(a){if(e=Object.values(null!==(r=null==g?void 0:g.participants())&&void 0!==r?r:{}).filter(function(n){return!n.local&&Boolean(n.tracks.audio.subscribed)}),!(i=function(n){return e.some(function(e){return e.session_id===n})})(t)){if(!g||g.isDestroyed()||!o||g.subscribeToTracksAutomatically())return[2];g.updateParticipant(t,{setSubscribedTracks:{audio:!0}})}return b(function(r){var o;if(r.includes(t))return r;var a=function(n){return!n||!i(n)};if(r.some(a)){var u=r.findIndex(a);return r[u]=t,E([],j(r),!1)}var c=r.findIndex(function(n){return e.some(function(e){return e.session_id===n&&pn(e.tracks.audio.state)})});if(c>=0)return r[c]=t,E([],j(r),!1);var l=e.filter(function(n){return r.includes(n.session_id)&&n.session_id!==k}).sort(function(e,t){var i,r,o=null!==(i=n(z(e.session_id,"last_active")))&&void 0!==i?i:new Date("1970-01-01"),a=null!==(r=n(z(t.session_id,"last_active")))&&void 0!==r?r:new Date("1970-01-01");return o>a?1:o<a?-1:0});if(!l.length){var d=r.findIndex(function(n){return n!==k});return r[d]=t,E([],j(r),!1)}var s=r.indexOf(null===(o=l[0])||void 0===o?void 0:o.session_id);return r[s]=t,E([],j(r),!1)}),[2]})})},[k,o,g])),O=d(function(n){b(function(e){if(!e.includes(n))return e;var t=E([],j(e),!1),i=t.indexOf(n);return t[i]="",t})},[]);X(["active-speaker-change","track-started","participant-left"],d(function(n){n.forEach(function(n){switch(n.action){case"active-speaker-change":if(n.activeSpeaker.peerId===S)return;I(n.activeSpeaker.peerId);break;case"track-started":"audio"===n.track.kind&&n.participant&&!n.participant.local&&I(n.participant.session_id);break;case"participant-left":O(n.participant.session_id)}})},[I,S,O]),200);var M=yn({filter:d(function(n){var e;return Boolean(null===(e=null==n?void 0:n.tracks)||void 0===e?void 0:e.rmpAudio)},[])});return t.createElement("div",{ref:L},y.map(function(n,e){return t.createElement(wn,{key:"speaker-slot-".concat(e),onPlayFailed:s,sessionId:n,type:"audio"})}),h.filter(function(n){return!!p||!n.local}).map(function(n){return t.createElement(wn,{key:n.screenId,onPlayFailed:s,sessionId:n.session_id,type:"screenAudio"})}),M.map(function(n){return t.createElement(wn,{key:"".concat(n,"-rmp"),onPlayFailed:s,sessionId:n,type:"rmpAudio"})}))}));An.displayName="DailyAudio";var Ln=f(function(n,e){var i=n.automirror,r=n.fit,o=void 0===r?"contain":r,a=n.mirror,d=n.onResize,s=n.playableStyle,f=void 0===s?{}:s,v=n.sessionId,p=n.style,g=void 0===p?{}:p,m=n.type,y=void 0===m?"video":m,b=k(n,["automirror","fit","mirror","onResize","playableStyle","sessionId","style","type"]),h=sn()===v,w="screenVideo"===y,A=h&&!w,L=u(null),j=kn(L,e),E=Sn(v,y),I=E.persistentTrack,_=A||w||!E.isOff,O=H(v,"tracks.".concat(y)),M=null==O?void 0:O.subscribed,P=c(function(){if("boolean"==typeof a)return a;if(!i)return!1;if(!I)return A;var n=I.getSettings();return"facingMode"in n?A&&"user"===n.facingMode:A},[i,A,a,I]);return l(function(){var n=L.current;if(n){var e=function(){var e=n.play();void 0!==e&&e.then(function(){n.controls=!1}).catch(function(e){n.controls=!0,console.warn("Failed to play video",e)})},t=function(){n.paused&&e()},i=function(){n.style.transform="scale(1)"},r=function(){n.style.transform="",setTimeout(function(){n.paused&&e()},100)},o=function(){"hidden"!==document.visibilityState&&n.paused&&e()};return n.addEventListener("canplay",t),n.addEventListener("enterpictureinpicture",i),n.addEventListener("leavepictureinpicture",r),document.addEventListener("visibilitychange",o),function(){n.removeEventListener("canplay",t),n.removeEventListener("enterpictureinpicture",i),n.removeEventListener("leavepictureinpicture",r),document.removeEventListener("visibilitychange",o)}}},[]),l(function(){var n=L.current;if(n&&I){if(MediaStream)return n.srcObject=new MediaStream([I]),n.load(),function(){n.srcObject=null,n.load()};console.warn("MediaStream API not available. Can't setup ".concat(y," for ").concat(v))}},[v,y,I,null==I?void 0:I.id]),l(function(){var n,e=L.current;if(d&&e)return t(),e.addEventListener("loadedmetadata",t),e.addEventListener("resize",t),function(){n&&cancelAnimationFrame(n),e.removeEventListener("loadedmetadata",t),e.removeEventListener("resize",t)};function t(){n&&cancelAnimationFrame(n),n=requestAnimationFrame(function(){var n=L.current;if(n&&!document.hidden){var e=n.videoWidth,t=n.videoHeight;e&&t&&(null==d||d({aspectRatio:e/t,height:t,width:e}))}})}},[d]),t.createElement("video",S({autoPlay:!0,muted:!0,playsInline:!0,ref:j,"data-local":h,"data-mirrored":P||void 0,"data-playable":_||void 0,"data-session-id":v,"data-subscribed":M,"data-video-type":y,style:S(S({objectFit:o,transform:P?"scale(-1, 1)":""},g),_?f:{})},b))});Ln.displayName="DailyVideo";var jn=i({refreshDevices:function(){return Promise.resolve()}}),En=p("idle");En.debugLabel=F("camera-state");var In=p("idle");In.debugLabel=F("microphone-state");var _n=p([]);_n.debugLabel=F("camera-devices");var On=p([]);On.debugLabel=F("microphone-devices");var Mn=p([]);Mn.debugLabel=F("speaker-devices");var Pn=p(null);Pn.debugLabel=F("last-camera-error");var Tn=function(n){var i=n.children,r=_(),o=e(d(function(n,e){return w(void 0,void 0,void 0,function(){var n,t,i,o,a,u,c,l,d,s,f,v;return A(this,function(p){switch(p.label){case 0:if(void 0===(null===(f=null===navigator||void 0===navigator?void 0:navigator.mediaDevices)||void 0===f?void 0:f.getUserMedia)||void 0===(null===(v=null===navigator||void 0===navigator?void 0:navigator.mediaDevices)||void 0===v?void 0:v.enumerateDevices))return e(En,"not-supported"),e(In,"not-supported"),[2];if(!r)return[2];p.label=1;case 1:return p.trys.push([1,4,,5]),[4,r.enumerateDevices()];case 2:return n=p.sent().devices,t=n.filter(function(n){return"videoinput"===n.kind&&""!==n.deviceId}),i=n.filter(function(n){return"audioinput"===n.kind&&""!==n.deviceId}),o=n.filter(function(n){return"audiooutput"===n.kind&&""!==n.deviceId}),[4,r.getInputDevices()];case 3:return a=p.sent(),u=a.camera,c=a.mic,l=a.speaker,d=function(n,e,t){var i,r;return{device:e,selected:"deviceId"in n&&e.deviceId===n.deviceId,state:null!==(r=null===(i=t.find(function(n){return n.device.deviceId===e.deviceId}))||void 0===i?void 0:i.state)&&void 0!==r?r:"granted"}},s=function(n,e){return"default"===n.device.deviceId?-1:"default"===e.device.deviceId?1:n.device.label<e.device.label?-1:n.device.label>e.device.label?1:0},e(_n,function(n){return t.filter(Boolean).map(function(e){return d(u,e,n)}).sort(s)}),e(On,function(n){return i.filter(Boolean).map(function(e){return d(c,e,n)}).sort(s)}),e(Mn,function(n){return o.filter(Boolean).map(function(e){return d(l,e,n)}).sort(s)}),[3,5];case 4:return p.sent(),e(En,"not-supported"),e(In,"not-supported"),[3,5];case 5:return[2]}})})},[r])),a=e(d(function(n,e){return w(void 0,void 0,void 0,function(){var t,i,a,u,c,l,d,s,f,v,p,g,m,y,b,h,k,w,L,j,E,I,_,O,M,P;return A(this,function(A){switch(A.label){case 0:if(!r)return[2];if(t=n(En),i=n(In),!(a=r.participants()).local)return[2];if(u=a.local.tracks,c="prompt",l="prompt",!navigator.permissions)return[3,5];A.label=1;case 1:return A.trys.push([1,4,,5]),[4,navigator.permissions.query({name:"camera"})];case 2:return d=A.sent(),c=d.state,[4,navigator.permissions.query({name:"microphone"})];case 3:return s=A.sent(),l=s.state,[3,5];case 4:return A.sent(),[3,5];case 5:return f="prompt"===c&&["idle","pending"].includes(t)&&"interrupted"===u.video.state&&!u.video.persistentTrack,v=["idle","pending"].includes(t)&&!u.video.persistentTrack&&Boolean(null===(m=u.video.off)||void 0===m?void 0:m.byUser),p="prompt"===l&&["idle","pending"].includes(i)&&"interrupted"===u.audio.state&&!u.audio.persistentTrack,g=["idle","pending"].includes(i)&&!u.audio.persistentTrack&&Boolean(null===(y=u.audio.off)||void 0===y?void 0:y.byUser),(null===(h=null===(b=u.audio)||void 0===b?void 0:b.blocked)||void 0===h?void 0:h.byDeviceInUse)?(e(In,"in-use"),e(On,function(n){return n.map(function(n){return n.selected?S(S({},n),{state:"in-use"}):n})})):(null===(w=null===(k=u.audio)||void 0===k?void 0:k.blocked)||void 0===w?void 0:w.byDeviceMissing)?e(In,"not-found"):(null===(j=null===(L=u.audio)||void 0===L?void 0:L.blocked)||void 0===j?void 0:j.byPermissions)||"denied"===l?e(In,"blocked"):p?e(In,"pending"):g?e(In,"idle"):(e(In,"granted"),e(On,function(n){return n.map(function(n){return n.selected?S(S({},n),{state:"granted"}):n})})),(null===(I=null===(E=u.video)||void 0===E?void 0:E.blocked)||void 0===I?void 0:I.byDeviceInUse)?(e(En,"in-use"),e(_n,function(n){return n.map(function(n){return n.selected?S(S({},n),{state:"in-use"}):n})})):(null===(O=null===(_=u.video)||void 0===_?void 0:_.blocked)||void 0===O?void 0:O.byDeviceMissing)?e(En,"not-found"):(null===(P=null===(M=u.video)||void 0===M?void 0:M.blocked)||void 0===P?void 0:P.byPermissions)||"denied"===c?e(En,"blocked"):f?e(En,"pending"):v?e(En,"idle"):(e(En,"granted"),e(_n,function(n){return n.map(function(n){return n.selected?S(S({},n),{state:"granted"}):n})})),o(),[2]}})})},[r,o]));return x("participant-updated",d(function(n){n.participant.local&&a()},[a])),x("available-devices-updated",o),x("selected-devices-updated",o),x("camera-error",e(d(function(n,e,t){var i,r,o,a,u,c,l;switch(e(Pn,t.error),null===(i=t.error)||void 0===i?void 0:i.type){case"cam-in-use":e(En,"in-use");break;case"mic-in-use":e(In,"in-use");break;case"cam-mic-in-use":e(En,"in-use"),e(In,"in-use");break;case"not-found":(null===(r=t.error)||void 0===r?void 0:r.missingMedia.includes("video"))&&e(En,"not-found"),(null===(o=t.error)||void 0===o?void 0:o.missingMedia.includes("audio"))&&e(In,"not-found");break;case"permissions":(null===(a=t.error)||void 0===a?void 0:a.blockedMedia.includes("video"))&&e(En,"blocked"),(null===(u=t.error)||void 0===u?void 0:u.blockedMedia.includes("audio"))&&e(In,"blocked");break;case"constraints":"invalid"===(null===(c=t.error)||void 0===c?void 0:c.reason)?(e(En,"constraints-invalid"),e(In,"constraints-invalid")):"none-specified"===(null===(l=t.error)||void 0===l?void 0:l.reason)&&(e(En,"constraints-none-specified"),e(In,"constraints-none-specified"));break;case"undefined-mediadevices":e(En,"undefined-mediadevices"),e(In,"undefined-mediadevices");break;default:e(En,"unknown"),e(In,"unknown")}},[]))),x("started-camera",e(d(function(n,e){e(En,"granted"),e(In,"granted"),a()},[a]))),t.createElement(jn.Provider,{value:{refreshDevices:o}},i)},Rn=p({errorMsg:void 0,isLiveStreaming:!1,layout:void 0});Rn.debugLabel=F("live-streaming");var xn=function(n){var i=n.children;return x("live-streaming-started",e(d(function(n,e,t){e(Rn,{isLiveStreaming:!0,layout:null==t?void 0:t.layout})},[]))),x("live-streaming-stopped",e(d(function(n,e){e(Rn,function(n){return S(S({},n),{isLiveStreaming:!1,layout:void 0})})},[]))),x("live-streaming-error",e(d(function(n,e,t){e(Rn,function(n){return S(S({},n),{errorMsg:t.errorMsg})})},[]))),x("left-meeting",e(d(function(n,e){e(Rn,{errorMsg:void 0,isLiveStreaming:!1,layout:void 0})},[]))),t.createElement(t.Fragment,null,i)},Dn=p("new");Dn.debugLabel=F("meeting-state");var Cn=p(null);Cn.debugLabel=F("meeting-error");var Fn=p(null);Fn.debugLabel=F("non-fatal-error");var Bn=p({data:void 0,topology:"none"});Bn.debugLabel=F("meeting-session-data");var qn=function(n){var i=n.children,r=_(),o=e(d(function(n,e){if(r){var t=r.meetingState();return e(Dn,t),t}},[r]));x("loading",o),x("loaded",o),x("joining-meeting",o),x("joined-meeting",o),x("left-meeting",o),x("error",e(d(function(n,e,t){e(Cn,t),o()},[o]))),x("nonfatal-error",e(d(function(n,e,t){e(Fn,t)},[])));var a=e(d(function(n,e){r&&e(Bn,r.meetingSessionState())},[r]));return x("joined-meeting",a),x("meeting-session-state-updated",e(d(function(n,e,t){e(Bn,t.meetingSessionState)},[]))),x("left-meeting",e(d(function(n,e){e(Bn,{data:void 0,topology:"none"})},[]))),x("call-instance-destroyed",e(d(function(n,e){e(Dn,"new"),e(Cn,null),e(Fn,null),e(Bn,{data:void 0,topology:"none"})},[]))),t.createElement(t.Fragment,null,i)},Wn=p("none");Wn.debugLabel=F("topology");var Un=p("unknown"),Nn=p([]),zn=p(100);zn.debugLabel=F("network-quality");var Vn=p("good");Vn.debugLabel=F("network-threshold");var Gn=function(n){var i=n.children,r=_(),o=g(Wn),a=e(d(function(n,e){return w(void 0,void 0,void 0,function(){var n;return A(this,function(t){switch(t.label){case 0:return r?[4,r.getNetworkTopology()]:[2];case 1:return(n=t.sent())&&"none"!==(null==n?void 0:n.topology)?(e(Wn,n.topology),[2]):[2]}})})},[r]));return x("joined-meeting",a),x("network-connection",e(d(function(n,e,t){if("connected"===t.event)"peer-to-peer"===t.type&&e(Wn,"peer"),"sfu"===t.type&&e(Wn,"sfu")},[]))),x("network-quality-change",e(d(function(n,e,t){e(Un,function(n){return n!==t.networkState?t.networkState:n}),e(Nn,function(n){var e,i=null!==(e=t.networkStateReasons)&&void 0!==e?e:[];return C(n,i)?n:i}),e(zn,function(n){return n!==t.quality?t.quality:n}),e(Vn,function(n){return n!==t.threshold?t.threshold:n})},[]))),x("left-meeting",e(d(function(n,e){e(Wn,"none"),e(Un,"unknown"),e(Nn,[]),e(zn,100),e(Vn,"good")},[]))),l(function(){r&&"none"===o&&a()},[r,a,o]),t.createElement(t.Fragment,null,i)},$n=p({isLocalParticipantRecorded:!1,isRecording:!1});$n.debugLabel=F("recording-state");var Hn=function(n){var i=n.children,r=sn(),o=yn({filter:"record"}),a=e(d(function(n,e,t,i){var r=n($n),o={isLocalParticipantRecorded:r.isLocalParticipantRecorded,isRecording:r.isRecording,local:r.local,type:r.type},a={isLocalParticipantRecorded:"local"!==(null==o?void 0:o.type)&&(null==o?void 0:o.type)?o.isLocalParticipantRecorded:t,isRecording:"local"!==(null==o?void 0:o.type)&&(null==o?void 0:o.type)?o.isRecording:t,local:"local"!==(null==o?void 0:o.type)&&(null==o?void 0:o.type)||!t?null==o?void 0:o.local:i,type:t?"local":null==r?void 0:r.type};D(o,a)||e($n,S(S({},o),a))},[]));return l(function(){var n=o.length>0,e=o.includes(r||"local");a(n,e)},[r,a,o]),x("recording-started",e(d(function(n,e,t){var i,o=!0;switch(t.type){case"cloud-beta":case"cloud":r&&"single-participant"===(null===(i=t.layout)||void 0===i?void 0:i.preset)&&t.layout.session_id!==r&&(o=!1)}e($n,{error:!1,isLocalParticipantRecorded:o,isRecording:!0,layout:null==t?void 0:t.layout,local:null==t?void 0:t.local,recordingId:null==t?void 0:t.recordingId,recordingStartedDate:new Date,startedBy:null==t?void 0:t.startedBy,type:null==t?void 0:t.type})},[r]))),x("recording-stopped",e(d(function(n,e){e($n,function(n){return S(S({},n),{isLocalParticipantRecorded:!1,isRecording:!1})})},[]))),x("recording-error",e(d(function(n,e){e($n,function(n){return S(S({},n),{error:!0,isLocalParticipantRecorded:!1,isRecording:!1})})},[]))),x("left-meeting",e(d(function(n,e){e($n,{isLocalParticipantRecorded:!1,isRecording:!1})},[]))),t.createElement(t.Fragment,null,i)},Jn=function(){var n=g(Dn);return o(n),n},Qn=p(null);Qn.debugLabel=F("room-state");var Kn=function(n){var i=n.children,r=_(),o=Jn(),a=e(d(function(n,e){return w(void 0,void 0,void 0,function(){var n;return A(this,function(t){switch(t.label){case 0:return r&&"left-meeting"!==o?[4,r.room()]:[2];case 1:return(n=t.sent())&&"id"in n&&e(Qn,n),[2,n]}})})},[r,o]));return x("access-state-updated",a),x("left-meeting",e(d(function(n,e){return function(){e(Qn,null)}},[]))),t.createElement(t.Fragment,null,i)},Xn=p({isTranscribing:!1,model:"general",language:"en",transcriptions:[]});Xn.debugLabel=F("transcription-state");var Yn,Zn,ne=function(n){var i=n.children;return x("transcription-started",e(d(function(n,e,t){e(Xn,{error:!1,transcriptionStartDate:new Date,isTranscribing:!0,transcriptions:[],endpointing:t.endpointing,extra:t.extra,includeRawResponse:t.includeRawResponse,instanceId:t.instanceId,language:t.language,model:t.model,profanity_filter:t.profanity_filter,punctuate:t.punctuate,redact:t.redact,startedBy:t.startedBy,tier:t.tier})},[]))),x("transcription-stopped",e(d(function(n,e,t){e(Xn,function(n){return S(S({},n),{updatedBy:t.updatedBy,isTranscribing:!1})})},[]))),x("transcription-error",e(d(function(n,e){e(Xn,function(n){return S(S({},n),{error:!0,isTranscribing:!1})})},[]))),x("left-meeting",e(d(function(n,e){e(Xn,function(n){return S(S({},n),{isTranscribing:!1})})},[]))),x("app-message",e(d(function(n,e,t){"transcription"===(null==t?void 0:t.fromId)&&e(Xn,function(n){return S(S({},n),{isTranscribing:!0,transcriptions:E(E([],j(n.transcriptions),!1),[t.data],!1)})})},[]))),t.createElement(t.Fragment,null,i)},ee={},te=function(){return!0},ie={options:ee,shouldCreateInstance:te},re=function(n,e){var t=void 0===e?ie:e,i=t.parentElRef,r=t.options,o=void 0===r?ee:r,c=t.shouldCreateInstance,d=void 0===c?te:c,s=j(a(null),2),f=s[0],v=s[1],p=u();return l(function(){if(("callFrame"!==n||null!==(null==i?void 0:i.current))&&d()){var e=function(){setTimeout(function(){return v(null)},0)},t=b.getCallInstance();if(!f&&t&&!t.isDestroyed())return t.once("call-instance-destroyed",e),void v(t);if(f)D(p.current,o)||function(n){w(this,void 0,void 0,function(){return A(this,function(e){switch(e.label){case 0:return[4,n.destroy()];case 1:return e.sent(),[2]}})})}(f);else{if(!t||t.isDestroyed()){switch(n){case"callFrame":t=(null==i?void 0:i.current)?b.createFrame(i.current,S({},o)):b.createFrame(S({},o));break;case"callObject":t=b.createCallObject(S({},o))}p.current=o}v(t),t.once("call-instance-destroyed",e)}}},[f,o,i,d,n]),f},oe=function(n){return re("callObject",n)},ae=function(n){var e=n.children,i=n.jotaiStore,r=k(n,["children","jotaiStore"]),o=u({}),a=d(function(n){var e,t,i,r;if("action"in n){var a=n.action,u=Array.from(null!==(r=null===(i=o.current)||void 0===i?void 0:i[a])&&void 0!==r?r:[]),c=u.filter(function(n){return j(n,1)[0]<0}),l=u.filter(function(n){return j(n,1)[0]>0}),d=E(E([],j(c),!1),j(l),!1);try{for(var s=L(d),f=s.next();!f.done;f=s.next()){(0,j(f.value,2)[1])(n)}}catch(n){e={error:n}}finally{try{f&&!f.done&&(t=s.return)&&t.call(s)}finally{if(e)throw e.error}}}},[]),s=d(function(n){n&&Object.keys(o.current).forEach(function(e){n.off(e,a),n.isDestroyed()||n.on(e,a)})},[a]),f="callObject"in r?r.callObject:null,v=c(function(){return"callObject"in r?{}:r},[r]),p=oe({options:v,shouldCreateInstance:d(function(){return!("callObject"in r)},[r])}),g=null!=f?f:p;l(function(){g&&s(g)},[g,s]);var y=d(function(n,e,t){var i,r;o.current[n]||(o.current[n]=new Map,g&&(g.off(n,a),g.isDestroyed()||g.on(n,a))),(null===(i=o.current[n])||void 0===i?void 0:i.has(t))||null===(r=o.current[n])||void 0===r||r.set(t,e)},[g,a]),b=d(function(n,e){var t,i;null===(t=o.current[n])||void 0===t||t.delete(e),0===(null===(i=o.current[n])||void 0===i?void 0:i.size)&&(null==g||g.off(n,a),delete o.current[n])},[g,a]);return t.createElement(m,{store:i},t.createElement(I.Provider,{value:g},t.createElement(O.Provider,{value:{on:y,off:b}},t.createElement(Kn,null,t.createElement(qn,null,t.createElement(Gn,null,t.createElement(dn,null,t.createElement(Hn,null,t.createElement(xn,null,t.createElement(ne,null,t.createElement(Tn,null,e)))))))))))},ue=function(n,e){var t=void 0===e?{}:e,i=t.onParticipantLeft,r=t.onParticipantUpdated,a=g(an(n));return X(["participant-updated","participant-left"],d(function(e){var t=e.filter(function(e){return e.participant.session_id===n});t.length&&t.forEach(function(n){switch(n.action){case"participant-updated":null==r||r(n);break;case"participant-left":null==i||i(n)}})},[i,r,n])),o(a),a},ce=function(n){var e=void 0===n?{}:n,t=e.ignoreLocal,i=void 0!==t&&t,r=e.onActiveSpeakerChange,u=_(),c=g(en),s=j(a(""),2),f=s[0],v=s[1],p=ue(f);return l(function(){var n;if(u){var e=null===(n=null==u?void 0:u.participants())||void 0===n?void 0:n.local;i&&c===(null==e?void 0:e.session_id)||v(null!=c?c:"")}},[u,i,c]),x("active-speaker-change",d(function(n){null==r||r(n)},[r])),o(p),p},le=function(n){var e=(void 0===n?{}:n).onAppMessage,t=_(),i=d(function(n,e){void 0===e&&(e="*"),t&&t.sendAppMessage(n,e)},[t]),r=d(function(n){null==e||e(n,i)},[e,i]);return x("app-message",r),i},de="data:application/javascript;charset=utf8,".concat(encodeURIComponent("\n class AudioLevelProcessor extends AudioWorkletProcessor {\n volume;\n interval;\n nextFrame;\n \n constructor() {\n super();\n this.volume = 0;\n this.interval = 25;\n this.nextFrame = this.interval;\n }\n \n get intervalInFrames() {\n // sampleRate is globally defined in AudioWorklets.\n // See https://developer.mozilla.org/en-US/docs/Web/API/AudioWorkletGlobalScope\n // eslint-disable-next-line no-undef\n return (this.interval / 1000) * sampleRate;\n }\n \n process(inputList) {\n const firstInput = inputList[0];\n \n if (firstInput.length > 0) {\n const inputData = firstInput[0];\n let total = 0;\n \n for (let i = 0; i < inputData.length; ++i) {\n total += Math.abs(inputData[i]);\n }\n \n const rms = Math.sqrt(total / inputData.length);\n this.volume = Math.max(0, Math.min(1, rms));\n \n this.nextFrame -= inputData.length;\n if (this.nextFrame < 0) {\n this.nextFrame += this.intervalInFrames;\n this.port.postMessage({ volume: this.volume });\n }\n }\n \n return true;\n }\n }\n \n registerProcessor('audiolevel', AudioLevelProcessor); \n")),se=function(n,e){var t=u();l(function(){var i=this;if(n){var r="undefined"!=typeof AudioContext?AudioContext:void 0!==window.webkitAudioContext?window.webkitAudioContext:null;if(r){t.current||(t.current=new r);var o=t.current;if(o&&MediaStream){var a,u,c=o.createMediaStreamSource(new MediaStream([n]));return w(i,void 0,void 0,function(){var n;return A(this,function(t){switch(t.label){case 0:return t.trys.push([0,1,,6]),a=new AudioWorkletNode(o,"audiolevel"),u=o.createGain(),[3,6];case 1:t.sent(),t.label=2;case 2:return t.trys.push([2,4,,5]),[4,o.audioWorklet.addModule(de)];case 3:return t.sent(),a=new AudioWorkletNode(o,"audiolevel"),u=o.createGain(),[3,5];case 4:return n=t.sent(),console.error(n),[3,5];case 5:return[3,6];case 6:if(!a||!u)return[2];a.port.onmessage=function(n){var t=0;n.data.volume&&(t=n.data.volume),a&&e(t)},u.gain.value=0;try{c.connect(a).connect(u).connect(o.destination)}catch(n){console.warn(n)}return[2]}})}),function(){null==a||a.disconnect(),a=null,null==c||c.disconnect()}}}}},[e,n])},fe=function(n,e,t,i){var r=_(),o=sn(),a=n===o;x("local-audio-level",d(function(n){a&&e(n.audioLevel)},[e,a])),x("remote-participants-audio-level",d(function(t){a||e(t.participantsAudioLevel[n])},[e,n,a])),l(function(){if(r&&!r.isDestroyed()&&a&&!r.isLocalAudioLevelObserverRunning())try{r.startLocalAudioLevelObserver(i)}catch(n){null==t||t("Local audio level observer not supported in this browser")}},[r,t,i,a]),l(function(){!r||r.isDestroyed()||a||r.isRemoteParticipantsAudioLevelObserverRunning()||r.startRemoteParticipantsAudioLevelObserver(i)},[r,i,a])},ve=function(n){return Sn(n,"audio")},pe=function(n){return re("callFrame",n)};var ge=Q(Zn?Yn:(Zn=1,Yn=function n(e,t){if(e===t)return!0;if(e&&t&&"object"==h(e)&&"object"==h(t)){if(e.constructor!==t.constructor)return!1;var i,r,o;if(Array.isArray(e)){if((i=e.length)!=t.length)return!1;for(r=i;0!==r--;)if(!n(e[r],t[r]))return!1;return!0}if(e.constructor===RegExp)return e.source===t.source&&e.flags===t.flags;if(e.valueOf!==Object.prototype.valueOf)return e.valueOf()===t.valueOf();if(e.toString!==Object.prototype.toString)return e.toString()===t.toString();if((i=(o=Object.keys(e)).length)!==Object.keys(t).length)return!1;for(r=i;0!==r--;)if(!Object.prototype.hasOwnProperty.call(t,o[r]))return!1;for(r=i;0!==r--;){var a=o[r];if(!n(e[a],t[a]))return!1}return!0}return e!=e&&t!=t})),me=p({state:"low",reason:"none"});me.debugLabel=F("cpu-load");var ye=function(n){var t=(void 0===n?{}:n).onCPULoadChange,i=g(me),r=_(),a=Jn(),u=e(d(function(n,e,t){var i=n(me);ge(i,t)||e(me,t)},[]));return l(function(){var n=!0;if(r&&!r.isDestroyed()&&"joined-meeting"===a)return r.getCpuLoadStats().then(function(e){n&&u({state:e.cpuLoadState,reason:e.cpuLoadStateReason})}),function(){n=!1}},[r,a,u]),x("cpu-load-change",d(function(n){u({state:n.cpuLoadState,reason:n.cpuLoadStateReason}),null==t||t(n)},[t,u])),o(i),i},be=function(){var n={meetingError:g(Cn),nonFatalError:g(Fn)};return o(n),n},he=function(){var n=_(),e=g(En),t=g(In),i=g(_n),a=g(On),u=g(Mn),c=g(Pn),l=r(jn).refreshDevices,s=d(function(e){return w(void 0,void 0,void 0,function(){return A(this,function(t){switch(t.label){case 0:return[4,null==n?void 0:n.setInputDevicesAsync({audioDeviceId:null,videoDeviceId:e})];case 1:return t.sent(),[2]}})})},[n]),f=d(function(e){return w(void 0,void 0,void 0,function(){return A(this,function(t){switch(t.label){case 0:return[4,null==n?void 0:n.setInputDevicesAsync({audioDeviceId:e,videoDeviceId:null})];case 1:return t.sent(),[2]}})})},[n]),v=d(function(e){return w(void 0,void 0,void 0,function(){return A(this,function(t){switch(t.label){case 0:return[4,null==n?void 0:n.setOutputDeviceAsync({outputDeviceId:e})];case 1:return t.sent(),[2]}})})},[n]),p=["blocked","in-use","not-found","constraints-invalid","constraints-none-specified","undefined-mediadevices","unknown"],m={cameraError:c,cameras:i,camState:e,currentCam:i.find(function(n){return n.selected}),currentMic:a.find(function(n){return n.selected}),currentSpeaker:u.find(function(n){return n.selected}),hasCamError:p.includes(e),hasMicError:p.includes(t),microphones:a,micState:t,refreshDevices:l,setCamera:s,setMicrophone:f,setSpeaker:v,speakers:u};return o(m),m},Se=p(null);Se.debugLabel=F("input-settings");var ke=function(n){var t=void 0===n?{}:n,i=t.onError,r=t.onInputSettingsUpdated,a=g(Se),u=be().nonFatalError,c=_(),s=e(d(function(n,e,t){e(Se,t)},[]));l(function(){c&&c.getInputSettings().then(s)},[c,s]),x("input-settings-updated",d(function(n){s(n.inputSettings),null==r||r(n)},[r,s])),x("nonfatal-error",d(function(n){"input-settings-error"===n.type&&(null==i||i(n))},[i]));var f=d(function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];return null==c?void 0:c.updateInputSettings.apply(c,E([],j(n),!1))},[c]),v={errorMsg:"input-settings-error"===(null==u?void 0:u.type)?u.errorMsg:null,inputSettings:a,updateInputSettings:f};return o(v),v},we=function(n){var e=void 0===n?{}:n,t=e.onLiveStreamingError,i=e.onLiveStreamingStarted,r=e.onLiveStreamingStopped,a=e.onLiveStreamingUpdated,u=e.onLiveStreamingWarning,c=_(),l=g(Rn);x("live-streaming-started",d(function(n){null==i||i(n)},[i])),x("live-streaming-stopped",d(function(n){null==r||r(n)},[r])),x("live-streaming-updated",d(function(n){null==a||a(n)},[a])),x("live-streaming-error",d(function(n){null==t||t(n)},[t])),x("nonfatal-error",d(function(n){"live-streaming-warning"===n.type&&(null==u||u(n))},[u]));var s=d(function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];c&&c.startLiveStreaming.apply(c,E([],j(n),!1))},[c]),f=d(function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];c&&c.stopLiveStreaming.apply(c,E([],j(n),!1))},[c]),v=d(function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];c&&c.updateLiveStreaming.apply(c,E([],j(n),!1))},[c]),p=S(S({},l),{startLiveStreaming:s,stopLiveStreaming:f,updateLiveStreaming:v});return o(p),p},Ae=function(){var n=g(tn),e=ue(n);return o(e),e},Le=function(n){var e=(void 0===n?{}:n).onError,t=g(Bn);x("nonfatal-error",d(function(n){"meeting-session-data-error"===n.type&&(null==e||e(n))},[e]));var i={data:null==t?void 0:t.data,topology:null==t?void 0:t.topology};return o(i),i},je=function(n){var e=void 0===n?{}:n,t=e.onNetworkConnection,i=e.onNetworkQualityChange,r=_(),a=g(Wn),u=g(Un),c=g(Nn),l=g(zn),s=g(Vn);x("network-connection",d(function(n){null==t||t(n)},[t])),x("network-quality-change",d(function(n){null==i||i(n)},[i]));var f=d(function(){return w(void 0,void 0,void 0,function(){var n;return A(this,function(e){switch(e.label){case 0:return[4,null==r?void 0:r.getNetworkStats()];case 1:return[2,null==(n=e.sent())?void 0:n.stats]}})})},[r]),v={getStats:f,networkState:u,networkStateReasons:c,quality:l,threshold:s,topology:a};return o(v),v},Ee=p({hidden:0,present:0});Ee.debugLabel=F("participant-counts");var Ie=function(n){var t=(void 0===n?{}:n).onParticipantCountsUpdated,i=_(),r=g(Ee),a=e(d(function(n,e,t){e(Ee,t)},[]));return x("participant-counts-updated",d(function(n){a(n.participantCounts),null==t||t(n)},[t,a])),l(function(){i&&!i.isDestroyed()&&a(i.participantCounts())},[i,a]),o(r),r},_e=function(n){var e,t,i,r,a,u,c,l,d,s=sn(),f=H(null!=n?n:s,"permissions"),v="boolean"==typeof(null==f?void 0:f.canSend)?null==f?void 0:f.canSend:Boolean(null===(e=null==f?void 0:f.canSend)||void 0===e?void 0:e.has("audio")),p="boolean"==typeof(null==f?void 0:f.canSend)?null==f?void 0:f.canSend:Boolean(null===(t=null==f?void 0:f.canSend)||void 0===t?void 0:t.has("video")),g="boolean"==typeof(null==f?void 0:f.canSend)?null==f?void 0:f.canSend:Boolean(null===(i=null==f?void 0:f.canSend)||void 0===i?void 0:i.has("customAudio")),m="boolean"==typeof(null==f?void 0:f.canSend)?null==f?void 0:f.canSend:Boolean(null===(r=null==f?void 0:f.canSend)||void 0===r?void 0:r.has("customVideo")),y="boolean"==typeof(null==f?void 0:f.canSend)?null==f?void 0:f.canSend:Boolean(null===(a=null==f?void 0:f.canSend)||void 0===a?void 0:a.has("screenAudio")),b="boolean"==typeof(null==f?void 0:f.canSend)?null==f?void 0:f.canSend:Boolean(null===(u=null==f?void 0:f.canSend)||void 0===u?void 0:u.has("screenVideo")),h={canAdminParticipants:"boolean"==typeof(null==f?void 0:f.canAdmin)?null==f?void 0:f.canAdmin:Boolean(null===(c=null==f?void 0:f.canAdmin)||void 0===c?void 0:c.has("participants")),canAdminStreaming:"boolean"==typeof(null==f?void 0:f.canAdmin)?null==f?void 0:f.canAdmin:Boolean(null===(l=null==f?void 0:f.canAdmin)||void 0===l?void 0:l.has("streaming")),canAdminTranscription:"boolean"==typeof(null==f?void 0:f.canAdmin)?null==f?void 0:f.canAdmin:Boolean(null===(d=null==f?void 0:f.canAdmin)||void 0===d?void 0:d.has("transcription")),canSendAudio:v,canSendCustomAudio:g,canSendCustomVideo:m,canSendScreenAudio:y,canSendScreenVideo:b,canSendVideo:p,hasPresence:null==f?void 0:f.hasPresence,permissions:f};return o(h),h},Oe=n(function(n){var e=p({},function(e,t,i){t(Oe(n),i)});return e.debugLabel=F("participant-receive-settings-".concat(n)),e}),Me=function(n){var t=void 0===n?{}:n,i=t.id,r=