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 60.1 kB
"use strict";var e=require("jotai/utils"),n=require("react"),t=require("jotai"),r=require("@daily-co/daily-js");function i(e){return i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},i(e)}var a=function(){return a=Object.assign||function(e){for(var n,t=1,r=arguments.length;t<r;t++)for(var i in n=arguments[t])Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i]);return e},a.apply(this,arguments)};function o(e,n){var t={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&n.indexOf(r)<0&&(t[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(e);i<r.length;i++)n.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(t[r[i]]=e[r[i]])}return t}function u(e,n,t,r){return new(t||(t=Promise))(function(i,a){function o(e){try{l(r.next(e))}catch(e){a(e)}}function u(e){try{l(r.throw(e))}catch(e){a(e)}}function l(e){var n;e.done?i(e.value):(n=e.value,n instanceof t?n:new t(function(e){e(n)})).then(o,u)}l((r=r.apply(e,n||[])).next())})}function l(e,n){var t,r,i,a,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return a={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function u(u){return function(l){return function(u){if(t)throw new TypeError("Generator is already executing.");for(;a&&(a=0,u[0]&&(o=0)),o;)try{if(t=1,r&&(i=2&u[0]?r.return:u[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,u[1])).done)return i;switch(r=0,i&&(u=[2&u[0],i.value]),u[0]){case 0:case 1:i=u;break;case 4:return o.label++,{value:u[1],done:!1};case 5:o.label++,r=u[1],u=[0];continue;case 7:u=o.ops.pop(),o.trys.pop();continue;default:if(!(i=o.trys,(i=i.length>0&&i[i.length-1])||6!==u[0]&&2!==u[0])){o=0;continue}if(3===u[0]&&(!i||u[1]>i[0]&&u[1]<i[3])){o.label=u[1];break}if(6===u[0]&&o.label<i[1]){o.label=i[1],i=u;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(u);break}i[2]&&o.ops.pop(),o.trys.pop();continue}u=n.call(e,o)}catch(e){u=[6,e],r=0}finally{t=i=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,l])}}}function c(e){var n="function"==typeof Symbol&&Symbol.iterator,t=n&&e[n],r=0;if(t)return t.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")}function s(e,n){var t="function"==typeof Symbol&&e[Symbol.iterator];if(!t)return e;var r,i,a=t.call(e),o=[];try{for(;(void 0===n||n-- >0)&&!(r=a.next()).done;)o.push(r.value)}catch(e){i={error:e}}finally{try{r&&!r.done&&(t=a.return)&&t.call(a)}finally{if(i)throw i.error}}return o}function d(e,n,t){if(t||2===arguments.length)for(var r,i=0,a=n.length;i<a;i++)!r&&i in n||(r||(r=Array.prototype.slice.call(n,0,i)),r[i]=n[i]);return e.concat(r||Array.prototype.slice.call(n))}"function"==typeof SuppressedError&&SuppressedError;var f=n.createContext(null),v=function(){var e=n.useContext(f);return n.useDebugValue(e),e},p=n.createContext({on:function(){},off:function(){}}),m=-1,b=function(){return m--},g=1,y=function(){return g++},k=function(e,t,r){void 0===r&&(r=!1);var i=n.useContext(p),a=i.off,o=i.on,u=s(n.useState(!1),2),l=u[0],c=u[1],d=n.useRef(0),f=n.useMemo(function(){return r?b():y()},[r]);n.useEffect(function(){if(e&&!l){if(d.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(e,"' event is NOT registered."),t),void c(!0);d.current++;var n=setTimeout(function(){d.current=0},50);return o(e,t,f),function(){clearTimeout(n),a(e,f)}}},[t,e,f,l,a,o]),n.useDebugValue({event:e,eventId:f,isBlocked:l,callback:t})};function h(e,n){var t,r;if(e===n)return!0;if(Array.isArray(e)&&Array.isArray(n)){if(e.length!==n.length)return!1;for(var a=0;a<e.length;a++)if(!h(e[a],n[a]))return!1;return!0}if(MediaStream&&e instanceof MediaStream&&n instanceof MediaStream)return e.id===n.id&&e.active===n.active&&e.getTracks().length===n.getTracks().length&&e.getTracks().every(function(e,t){return h(e,n.getTracks()[t])});if(MediaStreamTrack&&e instanceof MediaStreamTrack&&n instanceof MediaStreamTrack)return e.id===n.id&&e.kind===n.kind&&e.readyState===n.readyState;if(e instanceof Date&&n instanceof Date)return e.getTime()===n.getTime();if(e instanceof RegExp&&n instanceof RegExp)return e.source===n.source&&e.flags===n.flags;if(e instanceof Set&&n instanceof Set){if(e.size!==n.size)return!1;var o=Array.from(e).sort(),u=Array.from(n).sort();return o.every(function(e,n){return h(e,u[n])})}if(e instanceof Map&&n instanceof Map){if(e.size!==n.size)return!1;try{for(var l=c(e.entries()),d=l.next();!d.done;d=l.next()){var f=s(d.value,2),v=f[0],p=f[1];if(!n.has(v)||!h(p,n.get(v)))return!1}}catch(e){t={error:e}}finally{try{d&&!d.done&&(r=l.return)&&r.call(l)}finally{if(t)throw t.error}}return!0}if("object"!==i(e)||null===e||"object"!==i(n)||null===n)return!1;var m=Object.keys(e),b=Object.keys(n);if(m.length!==b.length)return!1;for(a=0;a<m.length;a++){v=m[a];if(!Object.prototype.hasOwnProperty.call(n,v)||!h(e[v],n[v]))return!1}return!0}function S(e,n){if(e===n)return!0;if(e.length!==n.length)return!1;for(var t=0;t<e.length;t++){var r=e[t],a=n[t],o=null!==r&&"object"===i(r),u=null!==a&&"object"===i(a);if(o||u){if(!h(r,a))return!1}else if(r!==a)return!1}return!0}function C(e){return"daily-react-"+e}function A(e){var n=new Map,r=new Map;return function(i){if(!n.has(i)){var a=t.atom(function(n){var t=e.get(i)(n),a=r.get(i);return null!=a&&e.equals(t,a)?a:(r.set(i,t),t)});n.set(i,a)}return n.get(i)}}var w,x,E="::",L=function(e,n){return e+E+n},D=function(e,n){return I(L(e,n))},j=e.atomFamily(function(e){var n=t.atom([]);return n.debugLabel=C("participant-property-paths-".concat(e)),n}),I=e.atomFamily(function(e){var n=t.atom(null);return n.debugLabel=C("participant-property-".concat(e)),n}),V=A({equals:S,get:function(e){return function(n){var t=s(e.split(E),2),r=t[0];return t[1].split(";").map(function(e){return n(D(r,e))})}}}),R=function(e,r){var i,a=t.useAtomValue(Array.isArray(r)?V(function(e,n){return e+E+n.join(";")}(e,r)):I(L(e,r)));return n.useDebugValue(Array.isArray(r)?r.reduce(function(e,n,t){return e[n]=a[t],e},{}):((i={})[r]=a,i)),a},P="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function M(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var T=M(function(){if(x)return w;x=1;var e="Expected a function",n=/^\s+|\s+$/g,t=/^[-+]0x[0-9a-f]+$/i,r=/^0b[01]+$/i,a=/^0o[0-7]+$/i,o=parseInt,u="object"==i(P)&&P&&P.Object===Object&&P,l="object"==("undefined"==typeof self?"undefined":i(self))&&self&&self.Object===Object&&self,c=u||l||Function("return this")(),s=Object.prototype.toString,d=Math.max,f=Math.min,v=function(){return c.Date.now()};function p(n,t,r){var i,a,o,u,l,c,s=0,p=!1,b=!1,y=!0;if("function"!=typeof n)throw new TypeError(e);function k(e){var t=i,r=a;return i=a=void 0,s=e,u=n.apply(r,t)}function h(e){var n=e-c;return void 0===c||n>=t||n<0||b&&e-s>=o}function S(){var e=v();if(h(e))return C(e);l=setTimeout(S,function(e){var n=t-(e-c);return b?f(n,o-(e-s)):n}(e))}function C(e){return l=void 0,y&&i?k(e):(i=a=void 0,u)}function A(){var e=v(),n=h(e);if(i=arguments,a=this,c=e,n){if(void 0===l)return function(e){return s=e,l=setTimeout(S,t),p?k(e):u}(c);if(b)return l=setTimeout(S,t),k(c)}return void 0===l&&(l=setTimeout(S,t)),u}return t=g(t)||0,m(r)&&(p=!!r.leading,o=(b="maxWait"in r)?d(g(r.maxWait)||0,t):o,y="trailing"in r?!!r.trailing:y),A.cancel=function(){void 0!==l&&clearTimeout(l),s=0,i=c=a=l=void 0},A.flush=function(){return void 0===l?u:C(v())},A}function m(e){var n=i(e);return!!e&&("object"==n||"function"==n)}function b(e){return"symbol"==i(e)||function(e){return!!e&&"object"==i(e)}(e)&&"[object Symbol]"==s.call(e)}function g(e){if("number"==typeof e)return e;if(b(e))return NaN;if(m(e)){var i="function"==typeof e.valueOf?e.valueOf():e;e=m(i)?i+"":i}if("string"!=typeof e)return 0===e?e:+e;e=e.replace(n,"");var u=r.test(e);return u||a.test(e)?o(e.slice(2),u?2:8):t.test(e)?NaN:+e}return w=function(n,t,r){var i=!0,a=!0;if("function"!=typeof n)throw new TypeError(e);return m(r)&&(i="leading"in r?!!r.leading:i,a="trailing"in r?!!r.trailing:a),p(n,t,{leading:i,maxWait:t,trailing:a})}}()),_=function(e,t,r,i){void 0===r&&(r=500),void 0===i&&(i=!1);var a=n.useContext(p),o=a.off,u=a.on,l=n.useMemo(function(){var n;return Array.isArray(e)?e.reduce(function(e,n){return e[n]=i?b():y(),e},{}):((n={})[e]=i?b():y(),n)},[e,i]),c=n.useRef([]);k("call-instance-destroyed",n.useCallback(function(){c.current.length=0},[]));var s=n.useMemo(function(){return T(function(){0!==c.current.length&&(t(c.current),c.current.length=0)},r,{trailing:!0})},[t,r]);n.useEffect(function(){if(e){var n=function(e){c.current.push(e),s()};return Array.isArray(e)?e.forEach(function(e){return u(e,n,l[e])}):u(e,n,l[e]),function(){Array.isArray(e)?e.forEach(function(e){return o(e,l[e])}):o(e,l[e])}}},[s,e,l,o,u]),n.useDebugValue({event:e,eventId:l})},O=function e(n,t,r){if(void 0===t&&(t=""),void 0===r&&(r=new Set),"object"!==i(n)||null===n||r.has(n))return[t];r.add(n);var a=[];for(var o in n)if(Object.prototype.hasOwnProperty.call(n,o)){var u=t?"".concat(t,".").concat(o):o;a.push.apply(a,d([u],s(e(n[o],u,r)),!1))}return r.delete(n),a},F=function(e){return O(e)},q=function(e,n){return n.map(function(n){return function(e,n){return String(n).split(".").filter(function(e){return e.length}).reduce(function(e,n){return e&&e[n]},e)}(e,n)})},B=t.atom(null);B.debugLabel=C("active-id");var W=t.atom("");W.debugLabel=C("local-id");var U=t.atom(null);U.debugLabel=C("local-join-date");var N=t.atom([]);N.debugLabel=C("participant-ids");var z=e.atomFamily(function(e){var n=t.atom(null);return n.debugLabel=C("participant-".concat(e)),n}),G=t.atom([]);G.debugLabel=C("waiting-participants");var $=e.atomFamily(function(e){var n=t.atom({awaitingAccess:{level:"full"},id:e,name:""});return n.debugLabel=C("waiting-participant-".concat(e)),n}),H=A({equals:S,get:function(){return function(e){return e(G).map(function(n){return e($(n))})}}}),J=function(t){var r=t.children,i=v(),o=s(n.useState(!1),2),u=o[0],l=o[1],c=e.useAtomCallback(n.useCallback(function(e,n,t){n(W,t.local.session_id);var r=Object.values(t),i=r.map(function(e){return e.session_id});n(N,i),r.forEach(function(e){n(z(e.session_id),e);var t=F(e);n(j(e.session_id),t),t.forEach(function(t){var r=s(q(e,[t]),1)[0];n(D(e.session_id,t),r)})}),l(!0)},[]));n.useEffect(function(){if(i&&!u){var e=setInterval(function(){var n=i.participants();"local"in n&&(c(n),clearInterval(e))},100);return function(){clearInterval(e)}}},[i,u,c]);var f=n.useCallback(function(){if(i){var e=null==i?void 0:i.participants();e.local&&c(e)}},[i,c]);k("started-camera",f,!0),k("access-state-updated",f,!0),k("joining-meeting",e.useAtomCallback(n.useCallback(function(e,n){n(U,new Date),f()},[f])),!0),k("joined-meeting",n.useCallback(function(e){c(e.participants)},[c]),!0);var p=e.useAtomCallback(n.useCallback(function(e,n){n(W,""),n(B,null),e(N).forEach(function(e){return z.remove(e)}),n(N,[])},[]));return k("call-instance-destroyed",p,!0),k("left-meeting",p,!0),_(["active-speaker-change","participant-joined","participant-updated","participant-left"],e.useAtomCallback(n.useCallback(function(e,n,t){t.length&&t.forEach(function(t){switch(t.action){case"active-speaker-change":n(B,t.activeSpeaker.peerId),n(z(t.activeSpeaker.peerId),function(e){return e?a(a({},e),{last_active:new Date}):null});break;case"participant-joined":n(N,function(e){return e.includes(t.participant.session_id)?e:d(d([],s(e),!1),[t.participant.session_id],!1)}),n(z(t.participant.session_id),t.participant);var r=F(t.participant);n(j(t.participant.session_id),r),r.forEach(function(e){var r=s(q(t.participant,[e]),1)[0];n(D(t.participant.session_id,e),r)});break;case"participant-updated":n(z(t.participant.session_id),t.participant),t.participant.local&&n(W,t.participant.session_id);r=F(t.participant);var i=e(j(t.participant.session_id));(r.length!==i.length||r.some(function(e){return!i.includes(e)}))&&n(j(t.participant.session_id),r);var o=new Set(i),u=q(t.participant,r);r.forEach(function(e,r){var i=u[r];o.delete(e),n(D(t.participant.session_id,e),function(e){return h(e,i)?e:i})}),o.forEach(function(e){n(D(t.participant.session_id,e),null)});break;case"participant-left":n(N,function(e){return e.includes(t.participant.session_id)?e.filter(function(e){return e!==t.participant.session_id}):e}),z.remove(t.participant.session_id),e(j(t.participant.session_id)).forEach(function(e){I.remove(L(t.participant.session_id,e))}),j.remove(t.participant.session_id)}})},[])),100,!0),_(["waiting-participant-added","waiting-participant-updated","waiting-participant-removed"],e.useAtomCallback(n.useCallback(function(e,n,t){t.forEach(function(e){switch(e.action){case"waiting-participant-added":n(G,function(n){return n.includes(e.participant.id)?n:d(d([],s(n),!1),[e.participant.id],!1)}),n($(e.participant.id),e.participant);break;case"waiting-participant-updated":n($(e.participant.id),e.participant);break;case"waiting-participant-removed":n(G,function(n){return n.filter(function(n){return n!==e.participant.id})}),$.remove(e.participant.id)}})},[])),100,!0),n.createElement(n.Fragment,null,r)},Q=function(){var e=t.useAtomValue(W);return n.useDebugValue(e),e},K=function(){return!0},X=function(e){var r=void 0===e?{}:e,i=r.filter,a=void 0===i?K:i,o=r.ignoreLocal,u=void 0!==o&&o,l=Q(),c=t.useAtomValue(B),d=u&&c===l,f=!(null==a?void 0:a(c)),v=!d&&!f,p=s(n.useState(v?c:null),2),m=p[0],b=p[1];return n.useEffect(function(){d||f||b(c)},[f,d,c]),n.useDebugValue(m),m},Y=function(e){return["blocked","off"].includes(e)},Z=function(e,n){return"".concat(e).concat(";").concat(n)},ee=A({equals:h,get:function(e){return function(n){var t=s(e.split(";"),2),r=t[0],i=t[1];return n(N).filter(function(e){switch(r){case"local":case"owner":case"record":return n(D(e,r));case"remote":return!n(D(e,"local"));case"screen":var t=n(D(e,"tracks.screenAudio.state")),i=n(D(e,"tracks.screenVideo.state"));return!Y(t)||!Y(i);default:return!0}}).sort(function(e,t){switch(i){case"joined_at":case"session_id":case"user_id":case"user_name":var r=n(D(e,i)),a=n(D(t,i));if(void 0!==r||void 0!==a){if(void 0===r)return-1;if(void 0===a)return 1;if(r>a)return 1;if(r<a)return-1}return 0;default:return 0}})}}}),ne=function(r){var i=void 0===r?{}:r,a=i.filter,o=i.onActiveSpeakerChange,u=i.onParticipantJoined,l=i.onParticipantLeft,c=i.onParticipantUpdated,d=i.sort,f=t.useAtomValue(ee(Z("string"==typeof a?a:null,"string"==typeof d?d:null))),v="function"==typeof a||"function"==typeof d,p=n.useCallback(function(e){return"function"!=typeof a&&"function"!=typeof d?[]:f.map(function(n){return e(z(n))}).filter(function(e){return Boolean(e)}).filter("function"==typeof a?a:function(){return!0}).sort("function"==typeof d?d:function(){return 0}).map(function(e){return e.session_id}).filter(Boolean)},[a,f,d]),m=s(n.useState([]),2),b=m[0],g=m[1],y=e.useAtomCallback(n.useCallback(function(e){if(v){var n=p(e);h(n,b)||g(n)}},[b,p,v]));n.useEffect(function(){y()},[y]),_(["participant-joined","participant-updated","active-speaker-change","participant-left"],n.useCallback(function(e){e.length&&(e.forEach(function(e){switch(e.action){case"participant-joined":null==u||u(e);break;case"participant-updated":null==c||c(e);break;case"active-speaker-change":null==o||o(e);break;case"participant-left":null==l||l(e)}}),y())},[y,o,u,l,c]));var k="function"==typeof a||"function"==typeof d?b:f;return n.useDebugValue(k),k},te=A({equals:S,get:function(){return function(e){return e(ee(Z("screen",null))).map(function(n){return{local:e(D(n,"local")),screenAudio:e(D(n,"tracks.screenAudio")),screenVideo:e(D(n,"tracks.screenVideo")),screenId:"".concat(n,"-screen"),session_id:n}})}}}),re=function(e){var r=void 0===e?{}:e,i=r.onError,a=r.onLocalScreenShareStarted,o=r.onLocalScreenShareStopped,u=v(),l=n.useCallback(function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];null==u||u.startScreenShare.apply(u,d([],s(e),!1))},[u]),c=n.useCallback(function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];null==u||u.stopScreenShare.apply(u,d([],s(e),!1))},[u]);k("local-screen-share-started",n.useCallback(function(){return null==a?void 0:a()},[a])),k("local-screen-share-stopped",n.useCallback(function(){return null==o?void 0:o()},[o])),k("nonfatal-error",n.useCallback(function(e){"screen-share-error"===e.type&&(null==i||i(e))},[i]));var f=t.useAtomValue(te(void 0)),p={isSharingScreen:f.some(function(e){return e.local}),screens:f,startScreenShare:l,stopScreenShare:c};return n.useDebugValue(p),p},ie=function(e,t){void 0===t&&(t="video");var r=R(e,"tracks.".concat(t)),i=r?a(a({},r),{isOff:Y(r.state)}):{isOff:!0,persistentTrack:void 0,state:"off",subscribed:!1};return n.useDebugValue(i),i};function ae(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return n.useCallback(function(n){for(var t=0;t<e.length;t++){var r=e[t];"function"==typeof r?r(n):r&&"object"===i(r)&&(r.current=n)}},e)}var oe=n.memo(n.forwardRef(function(e,t){var r=e.onPlayFailed,i=e.sessionId,u=e.type,l=void 0===u?"audio":u,c=o(e,["onPlayFailed","sessionId","type"]),s=n.useRef(null),d=ie(i,l),f=ae(s,t),v=null==d?void 0:d.subscribed;return n.useEffect(function(){var e=s.current;if(e&&(null==d?void 0:d.persistentTrack)){var n=function(){e.play().catch(function(n){null==r||r({sessionId:i,target:e,type:l,message:n.message,name:n.name})})};return MediaStream?(e.addEventListener("canplay",n),e.srcObject=new MediaStream([null==d?void 0:d.persistentTrack]),function(){null==e||e.removeEventListener("canplay",n)}):(console.warn("MediaStream API not available. Can't setup ".concat(l," for ").concat(i)),void(null==r||r({sessionId:i,target:e,type:l,message:"MediaStream API not available",name:"MediaStream API not available"})))}},[null==d?void 0:d.persistentTrack,r,i,l]),k("participant-left",n.useCallback(function(e){var n=s.current;e.participant.session_id===i&&n&&(n.srcObject=null)},[i])),n.createElement("audio",a({autoPlay:!0,ref:f},c,{"data-session-id":i,"data-audio-type":l,"data-subscribed":v}))}));oe.displayName="DailyAudioTrack";var ue=n.memo(n.forwardRef(function(t,r){var i=t.autoSubscribeActiveSpeaker,a=void 0!==i&&i,o=t.maxSpeakers,c=void 0===o?5:o,f=t.onPlayFailed,p=t.playLocalScreenAudio,m=void 0!==p&&p,b=v(),g=s(n.useState(new Array(c).fill("")),2),y=g[0],k=g[1],h=re().screens,S=Q(),C=X({ignoreLocal:!0}),A=n.useRef(null);n.useImperativeHandle(r,function(){return{getActiveSpeakerAudio:function(){var e,n;return null!==(n=null===(e=A.current)||void 0===e?void 0:e.querySelector('audio[data-session-id="'.concat(C,'"][data-audio-type="audio"]')))&&void 0!==n?n:null},getAllAudio:function(){var e,n;return Array.from(null!==(n=null===(e=A.current)||void 0===e?void 0:e.querySelectorAll("audio"))&&void 0!==n?n:[])},getAudioBySessionId:function(e){var n,t;return null!==(t=null===(n=A.current)||void 0===n?void 0:n.querySelector('audio[data-session-id="'.concat(e,'"][data-audio-type="audio"]')))&&void 0!==t?t:null},getRmpAudio:function(){var e,n;return Array.from(null!==(n=null===(e=A.current)||void 0===e?void 0:e.querySelectorAll('audio[data-audio-type="rmpAudio"]'))&&void 0!==n?n:[])},getScreenAudio:function(){var e,n;return Array.from(null!==(n=null===(e=A.current)||void 0===e?void 0:e.querySelectorAll('audio[data-audio-type="screenAudio"]'))&&void 0!==n?n:[])},getRmpAudioBySessionId:function(e){var n,t;return null!==(t=null===(n=A.current)||void 0===n?void 0:n.querySelector('audio[data-session-id="'.concat(e,'"][data-audio-type="rmpAudio"]')))&&void 0!==t?t:null},getScreenAudioBySessionId:function(e){var n,t;return null!==(t=null===(n=A.current)||void 0===n?void 0:n.querySelector('audio[data-session-id="'.concat(e,'"][data-audio-type="screenAudio"]')))&&void 0!==t?t:null}}},[C]);var w=e.useAtomCallback(n.useCallback(function(e,n,t){return u(void 0,void 0,void 0,function(){var n,r,i;return l(this,function(o){if(n=Object.values(null!==(i=null==b?void 0:b.participants())&&void 0!==i?i:{}).filter(function(e){return!e.local&&Boolean(e.tracks.audio.subscribed)}),!(r=function(e){return n.some(function(n){return n.session_id===e})})(t)){if(!b||b.isDestroyed()||!a||b.subscribeToTracksAutomatically())return[2];b.updateParticipant(t,{setSubscribedTracks:{audio:!0}})}return k(function(i){var a;if(i.includes(t))return i;var o=function(e){return!e||!r(e)};if(i.some(o)){var u=i.findIndex(o);return i[u]=t,d([],s(i),!1)}var l=i.findIndex(function(e){return n.some(function(n){return n.session_id===e&&Y(n.tracks.audio.state)})});if(l>=0)return i[l]=t,d([],s(i),!1);var c=n.filter(function(e){return i.includes(e.session_id)&&e.session_id!==C}).sort(function(n,t){var r,i,a=null!==(r=e(D(n.session_id,"last_active")))&&void 0!==r?r:new Date("1970-01-01"),o=null!==(i=e(D(t.session_id,"last_active")))&&void 0!==i?i:new Date("1970-01-01");return a>o?1:a<o?-1:0});if(!c.length){var f=i.findIndex(function(e){return e!==C});return i[f]=t,d([],s(i),!1)}var v=i.indexOf(null===(a=c[0])||void 0===a?void 0:a.session_id);return i[v]=t,d([],s(i),!1)}),[2]})})},[C,a,b])),x=n.useCallback(function(e){k(function(n){if(!n.includes(e))return n;var t=d([],s(n),!1),r=t.indexOf(e);return t[r]="",t})},[]);_(["active-speaker-change","track-started","participant-left"],n.useCallback(function(e){e.forEach(function(e){switch(e.action){case"active-speaker-change":if(e.activeSpeaker.peerId===S)return;w(e.activeSpeaker.peerId);break;case"track-started":"audio"===e.track.kind&&e.participant&&!e.participant.local&&w(e.participant.session_id);break;case"participant-left":x(e.participant.session_id)}})},[w,S,x]),200);var E=ne({filter:n.useCallback(function(e){var n;return Boolean(null===(n=null==e?void 0:e.tracks)||void 0===n?void 0:n.rmpAudio)},[])});return n.createElement("div",{ref:A},y.map(function(e,t){return n.createElement(oe,{key:"speaker-slot-".concat(t),onPlayFailed:f,sessionId:e,type:"audio"})}),h.filter(function(e){return!!m||!e.local}).map(function(e){return n.createElement(oe,{key:e.screenId,onPlayFailed:f,sessionId:e.session_id,type:"screenAudio"})}),E.map(function(e){return n.createElement(oe,{key:"".concat(e,"-rmp"),onPlayFailed:f,sessionId:e,type:"rmpAudio"})}))}));ue.displayName="DailyAudio";var le=n.forwardRef(function(e,t){var r=e.automirror,i=e.fit,u=void 0===i?"contain":i,l=e.mirror,c=e.onResize,s=e.playableStyle,d=void 0===s?{}:s,f=e.sessionId,v=e.style,p=void 0===v?{}:v,m=e.type,b=void 0===m?"video":m,g=o(e,["automirror","fit","mirror","onResize","playableStyle","sessionId","style","type"]),y=Q()===f,k="screenVideo"===b,h=y&&!k,S=n.useRef(null),C=ae(S,t),A=ie(f,b),w=A.persistentTrack,x=h||k||!A.isOff,E=R(f,"tracks.".concat(b)),L=null==E?void 0:E.subscribed,D=n.useMemo(function(){if("boolean"==typeof l)return l;if(!r)return!1;if(!w)return h;var e=w.getSettings();return"facingMode"in e?h&&"user"===e.facingMode:h},[r,h,l,w]);return n.useEffect(function(){var e=S.current;if(e){var n=function(){var n=e.play();void 0!==n&&n.then(function(){e.controls=!1}).catch(function(n){e.controls=!0,console.warn("Failed to play video",n)})},t=function(){e.paused&&n()},r=function(){e.style.transform="scale(1)"},i=function(){e.style.transform="",setTimeout(function(){e.paused&&n()},100)},a=function(){"hidden"!==document.visibilityState&&e.paused&&n()};return e.addEventListener("canplay",t),e.addEventListener("enterpictureinpicture",r),e.addEventListener("leavepictureinpicture",i),document.addEventListener("visibilitychange",a),function(){e.removeEventListener("canplay",t),e.removeEventListener("enterpictureinpicture",r),e.removeEventListener("leavepictureinpicture",i),document.removeEventListener("visibilitychange",a)}}},[]),n.useEffect(function(){var e=S.current;if(e&&w){if(MediaStream)return e.srcObject=new MediaStream([w]),e.load(),function(){e.srcObject=null,e.load()};console.warn("MediaStream API not available. Can't setup ".concat(b," for ").concat(f))}},[f,b,w,null==w?void 0:w.id]),n.useEffect(function(){var e,n=S.current;if(c&&n)return t(),n.addEventListener("loadedmetadata",t),n.addEventListener("resize",t),function(){e&&cancelAnimationFrame(e),n.removeEventListener("loadedmetadata",t),n.removeEventListener("resize",t)};function t(){e&&cancelAnimationFrame(e),e=requestAnimationFrame(function(){var e=S.current;if(e&&!document.hidden){var n=e.videoWidth,t=e.videoHeight;n&&t&&(null==c||c({aspectRatio:n/t,height:t,width:n}))}})}},[c]),n.createElement("video",a({autoPlay:!0,muted:!0,playsInline:!0,ref:C,"data-local":y,"data-mirrored":D||void 0,"data-playable":x||void 0,"data-session-id":f,"data-subscribed":L,"data-video-type":b,style:a(a({objectFit:u,transform:D?"scale(-1, 1)":""},p),x?d:{})},g))});le.displayName="DailyVideo";var ce=n.createContext({refreshDevices:function(){return Promise.resolve()}}),se=t.atom("idle");se.debugLabel=C("camera-state");var de=t.atom("idle");de.debugLabel=C("microphone-state");var fe=t.atom([]);fe.debugLabel=C("camera-devices");var ve=t.atom([]);ve.debugLabel=C("microphone-devices");var pe=t.atom([]);pe.debugLabel=C("speaker-devices");var me=t.atom(null);me.debugLabel=C("last-camera-error");var be=function(t){var r=t.children,i=v(),o=e.useAtomCallback(n.useCallback(function(e,n){return u(void 0,void 0,void 0,function(){var e,t,r,a,o,u,c,s,d,f,v,p;return l(this,function(l){switch(l.label){case 0:if(void 0===(null===(v=null===navigator||void 0===navigator?void 0:navigator.mediaDevices)||void 0===v?void 0:v.getUserMedia)||void 0===(null===(p=null===navigator||void 0===navigator?void 0:navigator.mediaDevices)||void 0===p?void 0:p.enumerateDevices))return n(se,"not-supported"),n(de,"not-supported"),[2];if(!i)return[2];l.label=1;case 1:return l.trys.push([1,4,,5]),[4,i.enumerateDevices()];case 2:return e=l.sent().devices,t=e.filter(function(e){return"videoinput"===e.kind&&""!==e.deviceId}),r=e.filter(function(e){return"audioinput"===e.kind&&""!==e.deviceId}),a=e.filter(function(e){return"audiooutput"===e.kind&&""!==e.deviceId}),[4,i.getInputDevices()];case 3:return o=l.sent(),u=o.camera,c=o.mic,s=o.speaker,d=function(e,n,t){var r,i;return{device:n,selected:"deviceId"in e&&n.deviceId===e.deviceId,state:null!==(i=null===(r=t.find(function(e){return e.device.deviceId===n.deviceId}))||void 0===r?void 0:r.state)&&void 0!==i?i:"granted"}},f=function(e,n){return"default"===e.device.deviceId?-1:"default"===n.device.deviceId?1:e.device.label<n.device.label?-1:e.device.label>n.device.label?1:0},n(fe,function(e){return t.filter(Boolean).map(function(n){return d(u,n,e)}).sort(f)}),n(ve,function(e){return r.filter(Boolean).map(function(n){return d(c,n,e)}).sort(f)}),n(pe,function(e){return a.filter(Boolean).map(function(n){return d(s,n,e)}).sort(f)}),[3,5];case 4:return l.sent(),n(se,"not-supported"),n(de,"not-supported"),[3,5];case 5:return[2]}})})},[i])),c=e.useAtomCallback(n.useCallback(function(e,n){return u(void 0,void 0,void 0,function(){var t,r,u,c,s,d,f,v,p,m,b,g,y,k,h,S,C,A,w,x,E,L,D,j,I,V;return l(this,function(l){switch(l.label){case 0:if(!i)return[2];if(t=e(se),r=e(de),!(u=i.participants()).local)return[2];if(c=u.local.tracks,s="prompt",d="prompt",!navigator.permissions)return[3,5];l.label=1;case 1:return l.trys.push([1,4,,5]),[4,navigator.permissions.query({name:"camera"})];case 2:return f=l.sent(),s=f.state,[4,navigator.permissions.query({name:"microphone"})];case 3:return v=l.sent(),d=v.state,[3,5];case 4:return l.sent(),[3,5];case 5:return p="prompt"===s&&["idle","pending"].includes(t)&&"interrupted"===c.video.state&&!c.video.persistentTrack,m=["idle","pending"].includes(t)&&!c.video.persistentTrack&&Boolean(null===(y=c.video.off)||void 0===y?void 0:y.byUser),b="prompt"===d&&["idle","pending"].includes(r)&&"interrupted"===c.audio.state&&!c.audio.persistentTrack,g=["idle","pending"].includes(r)&&!c.audio.persistentTrack&&Boolean(null===(k=c.audio.off)||void 0===k?void 0:k.byUser),(null===(S=null===(h=c.audio)||void 0===h?void 0:h.blocked)||void 0===S?void 0:S.byDeviceInUse)?(n(de,"in-use"),n(ve,function(e){return e.map(function(e){return e.selected?a(a({},e),{state:"in-use"}):e})})):(null===(A=null===(C=c.audio)||void 0===C?void 0:C.blocked)||void 0===A?void 0:A.byDeviceMissing)?n(de,"not-found"):(null===(x=null===(w=c.audio)||void 0===w?void 0:w.blocked)||void 0===x?void 0:x.byPermissions)||"denied"===d?n(de,"blocked"):b?n(de,"pending"):g?n(de,"idle"):(n(de,"granted"),n(ve,function(e){return e.map(function(e){return e.selected?a(a({},e),{state:"granted"}):e})})),(null===(L=null===(E=c.video)||void 0===E?void 0:E.blocked)||void 0===L?void 0:L.byDeviceInUse)?(n(se,"in-use"),n(fe,function(e){return e.map(function(e){return e.selected?a(a({},e),{state:"in-use"}):e})})):(null===(j=null===(D=c.video)||void 0===D?void 0:D.blocked)||void 0===j?void 0:j.byDeviceMissing)?n(se,"not-found"):(null===(V=null===(I=c.video)||void 0===I?void 0:I.blocked)||void 0===V?void 0:V.byPermissions)||"denied"===s?n(se,"blocked"):p?n(se,"pending"):m?n(se,"idle"):(n(se,"granted"),n(fe,function(e){return e.map(function(e){return e.selected?a(a({},e),{state:"granted"}):e})})),o(),[2]}})})},[i,o]));return k("participant-updated",n.useCallback(function(e){e.participant.local&&c()},[c])),k("available-devices-updated",o),k("selected-devices-updated",o),k("camera-error",e.useAtomCallback(n.useCallback(function(e,n,t){var r,i,a,o,u,l,c;switch(n(me,t.error),null===(r=t.error)||void 0===r?void 0:r.type){case"cam-in-use":n(se,"in-use");break;case"mic-in-use":n(de,"in-use");break;case"cam-mic-in-use":n(se,"in-use"),n(de,"in-use");break;case"not-found":(null===(i=t.error)||void 0===i?void 0:i.missingMedia.includes("video"))&&n(se,"not-found"),(null===(a=t.error)||void 0===a?void 0:a.missingMedia.includes("audio"))&&n(de,"not-found");break;case"permissions":(null===(o=t.error)||void 0===o?void 0:o.blockedMedia.includes("video"))&&n(se,"blocked"),(null===(u=t.error)||void 0===u?void 0:u.blockedMedia.includes("audio"))&&n(de,"blocked");break;case"constraints":"invalid"===(null===(l=t.error)||void 0===l?void 0:l.reason)?(n(se,"constraints-invalid"),n(de,"constraints-invalid")):"none-specified"===(null===(c=t.error)||void 0===c?void 0:c.reason)&&(n(se,"constraints-none-specified"),n(de,"constraints-none-specified"));break;case"undefined-mediadevices":n(se,"undefined-mediadevices"),n(de,"undefined-mediadevices");break;default:n(se,"unknown"),n(de,"unknown")}},[]))),k("started-camera",e.useAtomCallback(n.useCallback(function(e,n){n(se,"granted"),n(de,"granted"),c()},[c]))),n.createElement(ce.Provider,{value:{refreshDevices:o}},r)},ge=t.atom({errorMsg:void 0,isLiveStreaming:!1,layout:void 0});ge.debugLabel=C("live-streaming");var ye=function(t){var r=t.children;return k("live-streaming-started",e.useAtomCallback(n.useCallback(function(e,n,t){n(ge,{isLiveStreaming:!0,layout:null==t?void 0:t.layout})},[]))),k("live-streaming-stopped",e.useAtomCallback(n.useCallback(function(e,n){n(ge,function(e){return a(a({},e),{isLiveStreaming:!1,layout:void 0})})},[]))),k("live-streaming-error",e.useAtomCallback(n.useCallback(function(e,n,t){n(ge,function(e){return a(a({},e),{errorMsg:t.errorMsg})})},[]))),k("left-meeting",e.useAtomCallback(n.useCallback(function(e,n){n(ge,{errorMsg:void 0,isLiveStreaming:!1,layout:void 0})},[]))),n.createElement(n.Fragment,null,r)},ke=t.atom("new");ke.debugLabel=C("meeting-state");var he=t.atom(null);he.debugLabel=C("meeting-error");var Se=t.atom(null);Se.debugLabel=C("non-fatal-error");var Ce=t.atom({data:void 0,topology:"none"});Ce.debugLabel=C("meeting-session-data");var Ae=function(t){var r=t.children,i=v(),a=e.useAtomCallback(n.useCallback(function(e,n){if(i){var t=i.meetingState();return n(ke,t),t}},[i]));k("loading",a),k("loaded",a),k("joining-meeting",a),k("joined-meeting",a),k("left-meeting",a),k("error",e.useAtomCallback(n.useCallback(function(e,n,t){n(he,t),a()},[a]))),k("nonfatal-error",e.useAtomCallback(n.useCallback(function(e,n,t){n(Se,t)},[])));var o=e.useAtomCallback(n.useCallback(function(e,n){i&&n(Ce,i.meetingSessionState())},[i]));return k("joined-meeting",o),k("meeting-session-state-updated",e.useAtomCallback(n.useCallback(function(e,n,t){n(Ce,t.meetingSessionState)},[]))),k("left-meeting",e.useAtomCallback(n.useCallback(function(e,n){n(Ce,{data:void 0,topology:"none"})},[]))),k("call-instance-destroyed",e.useAtomCallback(n.useCallback(function(e,n){n(ke,"new"),n(he,null),n(Se,null),n(Ce,{data:void 0,topology:"none"})},[]))),n.createElement(n.Fragment,null,r)},we=t.atom("none");we.debugLabel=C("topology");var xe=t.atom("unknown"),Ee=t.atom([]),Le=t.atom(100);Le.debugLabel=C("network-quality");var De=t.atom("good");De.debugLabel=C("network-threshold");var je=function(r){var i=r.children,a=v(),o=t.useAtomValue(we),c=e.useAtomCallback(n.useCallback(function(e,n){return u(void 0,void 0,void 0,function(){var e;return l(this,function(t){switch(t.label){case 0:return a?[4,a.getNetworkTopology()]:[2];case 1:return(e=t.sent())&&"none"!==(null==e?void 0:e.topology)?(n(we,e.topology),[2]):[2]}})})},[a]));return k("joined-meeting",c),k("network-connection",e.useAtomCallback(n.useCallback(function(e,n,t){if("connected"===t.event)"peer-to-peer"===t.type&&n(we,"peer"),"sfu"===t.type&&n(we,"sfu")},[]))),k("network-quality-change",e.useAtomCallback(n.useCallback(function(e,n,t){n(xe,function(e){return e!==t.networkState?t.networkState:e}),n(Ee,function(e){var n,r=null!==(n=t.networkStateReasons)&&void 0!==n?n:[];return S(e,r)?e:r}),n(Le,function(e){return e!==t.quality?t.quality:e}),n(De,function(e){return e!==t.threshold?t.threshold:e})},[]))),k("left-meeting",e.useAtomCallback(n.useCallback(function(e,n){n(we,"none"),n(xe,"unknown"),n(Ee,[]),n(Le,100),n(De,"good")},[]))),n.useEffect(function(){a&&"none"===o&&c()},[a,c,o]),n.createElement(n.Fragment,null,i)},Ie=t.atom({isLocalParticipantRecorded:!1,isRecording:!1});Ie.debugLabel=C("recording-state");var Ve=function(t){var r=t.children,i=Q(),o=ne({filter:"record"}),u=e.useAtomCallback(n.useCallback(function(e,n,t,r){var i=e(Ie),o={isLocalParticipantRecorded:i.isLocalParticipantRecorded,isRecording:i.isRecording,local:i.local,type:i.type},u={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:r,type:t?"local":null==i?void 0:i.type};h(o,u)||n(Ie,a(a({},o),u))},[]));return n.useEffect(function(){var e=o.length>0,n=o.includes(i||"local");u(e,n)},[i,u,o]),k("recording-started",e.useAtomCallback(n.useCallback(function(e,n,t){var r,a=!0;switch(t.type){case"cloud-beta":case"cloud":i&&"single-participant"===(null===(r=t.layout)||void 0===r?void 0:r.preset)&&t.layout.session_id!==i&&(a=!1)}n(Ie,{error:!1,isLocalParticipantRecorded:a,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})},[i]))),k("recording-stopped",e.useAtomCallback(n.useCallback(function(e,n){n(Ie,function(e){return a(a({},e),{isLocalParticipantRecorded:!1,isRecording:!1})})},[]))),k("recording-error",e.useAtomCallback(n.useCallback(function(e,n){n(Ie,function(e){return a(a({},e),{error:!0,isLocalParticipantRecorded:!1,isRecording:!1})})},[]))),k("left-meeting",e.useAtomCallback(n.useCallback(function(e,n){n(Ie,{isLocalParticipantRecorded:!1,isRecording:!1})},[]))),n.createElement(n.Fragment,null,r)},Re=function(){var e=t.useAtomValue(ke);return n.useDebugValue(e),e},Pe=t.atom(null);Pe.debugLabel=C("room-state");var Me=function(t){var r=t.children,i=v(),a=Re(),o=e.useAtomCallback(n.useCallback(function(e,n){return u(void 0,void 0,void 0,function(){var e;return l(this,function(t){switch(t.label){case 0:return i&&"left-meeting"!==a?[4,i.room()]:[2];case 1:return(e=t.sent())&&"id"in e&&n(Pe,e),[2,e]}})})},[i,a]));return k("access-state-updated",o),k("left-meeting",e.useAtomCallback(n.useCallback(function(e,n){return function(){n(Pe,null)}},[]))),n.createElement(n.Fragment,null,r)},Te=t.atom({isTranscribing:!1,model:"general",language:"en",transcriptions:[]});Te.debugLabel=C("transcription-state");var _e,Oe,Fe=function(t){var r=t.children;return k("transcription-started",e.useAtomCallback(n.useCallback(function(e,n,t){n(Te,{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})},[]))),k("transcription-stopped",e.useAtomCallback(n.useCallback(function(e,n,t){n(Te,function(e){return a(a({},e),{updatedBy:t.updatedBy,isTranscribing:!1})})},[]))),k("transcription-error",e.useAtomCallback(n.useCallback(function(e,n){n(Te,function(e){return a(a({},e),{error:!0,isTranscribing:!1})})},[]))),k("left-meeting",e.useAtomCallback(n.useCallback(function(e,n){n(Te,function(e){return a(a({},e),{isTranscribing:!1})})},[]))),k("app-message",e.useAtomCallback(n.useCallback(function(e,n,t){"transcription"===(null==t?void 0:t.fromId)&&n(Te,function(e){return a(a({},e),{isTranscribing:!0,transcriptions:d(d([],s(e.transcriptions),!1),[t.data],!1)})})},[]))),n.createElement(n.Fragment,null,r)},qe={},Be=function(){return!0},We={options:qe,shouldCreateInstance:Be},Ue=function(e,t){var i=void 0===t?We:t,o=i.parentElRef,c=i.options,d=void 0===c?qe:c,f=i.shouldCreateInstance,v=void 0===f?Be:f,p=s(n.useState(null),2),m=p[0],b=p[1],g=n.useRef();return n.useEffect(function(){if(("callFrame"!==e||null!==(null==o?void 0:o.current))&&v()){var n=function(){setTimeout(function(){return b(null)},0)},t=r.getCallInstance();if(!m&&t&&!t.isDestroyed())return t.once("call-instance-destroyed",n),void b(t);if(m)h(g.current,d)||function(e){u(this,void 0,void 0,function(){return l(this,function(n){switch(n.label){case 0:return[4,e.destroy()];case 1:return n.sent(),[2]}})})}(m);else{if(!t||t.isDestroyed()){switch(e){case"callFrame":t=(null==o?void 0:o.current)?r.createFrame(o.current,a({},d)):r.createFrame(a({},d));break;case"callObject":t=r.createCallObject(a({},d))}g.current=d}b(t),t.once("call-instance-destroyed",n)}}},[m,d,o,v,e]),m},Ne=function(e){return Ue("callObject",e)},ze=function(e,r){var i=void 0===r?{}:r,a=i.onParticipantLeft,o=i.onParticipantUpdated,u=t.useAtomValue(z(e));return _(["participant-updated","participant-left"],n.useCallback(function(n){var t=n.filter(function(n){return n.participant.session_id===e});t.length&&t.forEach(function(e){switch(e.action){case"participant-updated":null==o||o(e);break;case"participant-left":null==a||a(e)}})},[a,o,e])),n.useDebugValue(u),u},Ge="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"));var $e=M(Oe?_e:(Oe=1,_e=function e(n,t){if(n===t)return!0;if(n&&t&&"object"==i(n)&&"object"==i(t)){if(n.constructor!==t.constructor)return!1;var r,a,o;if(Array.isArray(n)){if((r=n.length)!=t.length)return!1;for(a=r;0!==a--;)if(!e(n[a],t[a]))return!1;return!0}if(n.constructor===RegExp)return n.source===t.source&&n.flags===t.flags;if(n.valueOf!==Object.prototype.valueOf)return n.valueOf()===t.valueOf();if(n.toString!==Object.prototype.toString)return n.toString()===t.toString();if((r=(o=Object.keys(n)).length)!==Object.keys(t).length)return!1;for(a=r;0!==a--;)if(!Object.prototype.hasOwnProperty.call(t,o[a]))return!1;for(a=r;0!==a--;){var u=o[a];if(!e(n[u],t[u]))return!1}return!0}return n!=n&&t!=t})),He=t.atom({state:"low",reason:"none"});He.debugLabel=C("cpu-load");var Je=function(){var e={meetingError:t.useAtomValue(he),nonFatalError:t.useAtomValue(Se)};return n.useDebugValue(e),e},Qe=t.atom(null);Qe.debugLabel=C("input-settings");var Ke=t.atom({hidden:0,present:0});Ke.debugLabel=C("participant-counts");var Xe=e.atomFamily(function(e){var n=t.atom({},function(n,t,r){t(Xe(e),r)});return n.debugLabel=C("participant-receive-settings-".concat(e)),n}),Ye=function(){var e=t.useAtomValue(Pe);return n.useDebugValue(e),e},Ze=t.atom(null);Ze.debugLabel=C("send-settings");exports.DailyAudio=ue,exports.DailyAudioTrack=oe,exports.DailyProvider=function(e){var r=e.children,i=e.jotaiStore,a=o(e,["children","jotaiStore"]),u=n.useRef({}),l=n.useCallback(function(e){var n,t,r,i;if("action"in e){var a=e.action,o=Array.from(null!==(i=null===(r=u.current)||void 0===r?void 0:r[a])&&void 0!==i?i:[]),l=o.filter(function(e){return s(e,1)[0]<0}),f=o.filter(function(e){return s(e,1)[0]>0}),v=d(d([],s(l),!1),s(f),!1);try{for(var p=c(v),m=p.next();!m.done;m=p.next()){(0,s(m.value,2)[1])(e)}}catch(e){n={error:e}}finally{try{m&&!m.done&&(t=p.return)&&t.call(p)}finally{if(n)throw n.error}}}},[]),v=n.useCallback(function(e){e&&Object.keys(u.current).forEach(function(n){e.off(n,l),e.isDestroyed()||e.on(n,l)})},[l]),m="callObject"in a?a.callObject:null,b=n.useMemo(function(){return"callObject"in a?{}:a},[a]),g=Ne({options:b,shouldCreateInstance:n.useCallback(function(){return!("callObject"in a)},[a])}),y=null!=m?m:g;n.useEffect(function(){y&&v(y)},[y,v]);var k=n.useCallback(function(e,n,t){var r,i;u.current[e]||(u.current[e]=new Map,y&&(y.off(e,l),y.isDestroyed()||y.on(e,l))),(null===(r=u.current[e])||void 0===r?void 0:r.has(t))||null===(i=u.current[e])||void 0===i||i.set(t,n)},[y,l]),h=n.useCallback(function(e,n){var t,r;null===(t=u.current[e])||void 0===t||t.delete(n),0===(null===(r=u.current[e])||void 0===r?void 0:r.size)&&(null==y||y.off(e,l),delete u.current[e])},[y,l]);return n.createElement(t.Provider,{store:i},n.createElement(f.Provider,{value:y},n.createElement(p.Provider,{value:{on:k,off:h}},n.createElement(Me,null,n.createElement(Ae,null,n.createElement(je,null,n.createElement(J,null,n.createElement(Ve,null,n.createElement(ye,null,n.createElement(Fe,null,n.createElement(be,null,r)))))))))))},exports.DailyVideo=le,exports.useActiveParticipant=function(e){var r=void 0===e?{}:e,i=r.ignoreLocal,a=void 0!==i&&i,o=r.onActiveSpeakerChange,u=v(),l=t.useAtomValue(B),c=s(n.useState(""),2),d=c[0],f=c[1],p=ze(d);return n.useEffect(function(){var e;if(u){var n=null===(e=null==u?void 0:u.participants())||void 0===e?void 0:e.local;a&&l===(null==n?void 0:n.session_id)||f(null!=l?l:"")}},[u,a,l]),k("active-speaker-change",n.useCallback(function(e){null==o||o(e)},[o])),n.useDebugValue(p),p},exports.useActiveSpeakerId=X,exports.useAppMessage=function(e){var t=(void 0===e?{}:e).onAppMessage,r=v(),i=n.useCallback(function(e,n){void 0===n&&(n="*"),r&&r.sendAppMessage(e,n)},[r]),a=n.useCallback(function(e){null==t||t(e,i)},[t,i]);return k("app-message",a),i},exports.useAudioLevel=function(e,t){var r=n.useRef();n.useEffect(function(){var n=this;if(e){var i="undefined"!=typeof AudioContext?AudioContext:void 0!==window.webkitAudioContext?window.webkitAudioContext:null;if(i){r.current||(r.current=new i);var a=r.current;if(a&&MediaStream){var o,c,s=a.createMediaStreamSource(new MediaStream([e]));return u(n,void 0,void 0,function(){var e;return l(this,function(n){switch(n.label){case 0:return n.trys.push([0,1,,6]),o=new AudioWorkletNode(a,"audiolevel"),c=a.createGain(),[3,6];case 1:n.sent(),n.label=2;case 2:return n.trys.push([2,4,,5]),[4,a.audioWorklet.addModule(Ge)];case 3:return n.sent(),o=new AudioWorkletNode(a,"audiolevel"),c=a.createGain(),[3,5];case 4:return e=n.sent(),console.error(e),[3,5];case 5:return[3,6];case 6:if(!o||!c)return[2];o.port.onmessage=function(e){var n=0;e.data.volume&&(n=e.data.volume),o&&t(n)},c.gain.value=0;try{s.connect(o).connect(c).connect(a.destination)}catch(e){console.warn(e)}return[2]}})}),function(){null==o||o.disconnect(),o=null,null==s||s.disconnect()}}}}},[t,e])},exports.useAudioLevelObserver=function(e,t,r,i){var a=v(),o=Q(),u=e===o;k("local-audio-level",n.useCallback(function(e){u&&t(e.audioLevel)},[t,u])),k("remote-participants-audio-level",n.useCallback(function(n){u||t(n.participantsAudioLevel[e])},[t,e,u])),n.useEffect(function(){if(a&&!a.isDestroyed()&&u&&!a.isLocalAudioLevelObserverRunning())try{a.startLocalAudioLevelObserver(i)}catch(e){null==r||r("Local audio level observer not supported in this browser")}},[a,r,i,u]),n.useEffect(function(){!a||a.isDestroyed()||u||a.isRemoteParticipantsAudioLevelObserverRunning()||a.startRemoteParticipantsAudioLevelObserver(i)},[a,i,u])},exports.useAudioTrack=function(e){return ie(e,"audio")},exports.useCPULoad=function(r){var i=(void 0===r?{}:r).onCPULoadChange,a=t.useAtomValue(He),o=v(),u=Re(),l=e.useAtomCallback(n.useCallback(function(e,n,t){var r=e(He);$e(r,t)||n(He,t)},[]));return n.useEffect(function(){var e=!0;if(o&&!o.isDestroyed()&&"joined-meeting"===u)return o.getCpuLoadStats().then(function(n){e&&l({state:n.cpuLoadState,reason:n.cpuLoadStateReason})}),function(){e=!1}},[o,u,l]),k("cpu-load-change",n.useCallback(function(e){l({state:e.cpuLoadState,reason:e.cpuLoadStateReason}),null==i||i(e)},[i,l])),n.useDebugValue(a),a},exports.useCallFrame=function(e){return Ue("callFrame",e)},exports.useCallObject=Ne,exports.useDaily=v,exports.useDailyError=Je,exports.useDailyEvent=k,exports.useDevices=function(){var e=v(),r=t.useAtomValue(se),i=t.useAtomValue(de),a=t.useAtomValue(fe),o=t.useAtomValue(ve),c=t.useAtomValue(pe),s=t.useAtomValue(me),d=n.useContext(ce).refreshDevices,f=n.useCallback(function(n){return u(void 0,void 0,void 0,function(){return l(this,function(t){switch(t.label){case 0:return[4,null==e?void 0:e.setInputDevicesAsync({audioDeviceId:null,videoDeviceId:n})];case 1:return t.sent(),[2]}})})},[e]),p=n.useCallback(function(n){return u(void 0,void 0,void 0,function(){return l(this,function(t){switch(t.label){case 0:return[4,null==e?void 0:e.setInputDevicesAsync({audioDeviceId:n,videoDeviceId:null})];case 1:return t.sent(),[2]}})})},[e]),m=n.useCallback(function(n){return u(void 0,void 0,void 0,function(){return l(this,function(t){switch(t.label){case 0:return[4,null==e?void 0:e.setOutputDeviceAsync({outputDeviceId:n})];case 1:return t.sent(),[2]}})})},[e]),b=["blocked","in-use","not-found","constraints-invalid","constraints-none-specified","undefined-mediadevices","unknown"],g={cameraError:s,cameras:a,camState:r,currentCam:a.find(function(e){return e.selected}),currentMic:o.find(function(e){return e.selected}),currentSpeaker:c.find(function(e){return e.selected}),hasCamError:b.includes(r),hasMicError:b.includes(i),microphones:o,micState:i,refreshDevices:d,setCamera:f,setMicrophone:p,setSpeaker:m,speakers:c};return n.useDebugValue(g),g},exports.useInputSettings=function(r){var i=void 0===r?{}:r,a=i.onError,o=i.onInputSettingsUpdated,u=t.useAtomValue(Qe),l=Je().nonFatalError,c=v(),f=e.useAtomCallback(n.useCallback(function(e,n,t){n(Qe,t)},[]));n.useEffect(function(){c&&c.getInputSettings().then(f)},[c,f]),k("input-settings-updated",n.useCallback(function(e){f(e.inputSettings),null==o||o(e)},[o,f])),k("nonfatal-error",n.useCallback(function(e){"input-settings-error"===e.type&&(null==a||a(e))},[a]));var p=n.useCallback(function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return null==c?void 0:c.updateInputSettings.apply(c,d([],s(e),!1))},[c]),m={errorMsg:"input-settings-error"===(null==l?void 0:l.type)?l.errorMsg:null,inputSettings:u,updateInputSettings:p};return n.useDebugValue(m),m},exports.useLiveStreaming=function(e){var r=void 0===e?{}:e,i=r.onLiveStreamingError,o=r.onLiveStreamingStarted,u=r.onLiveStreamingStopped,l=r.onLiveStreamingUpdated,c=r.onLiveStreamingWarning,f=v(),p=t.useAtomValue(ge);k("live-streaming-started",n.useCallback(function(e){null==o||o(e)},[o])),k("live-streaming-stopped",n.useCallback(function(e){null==u||u(e)},[u])),k("live-streaming-updated",n.useCallback(function(e){null==l||l(e)},[l])),k("live-streaming-error",n.useCallback(function(e){null==i||i(e)},[i])),k("nonfatal-error",n.useCallback(function(e){"live-streaming-warning"===e.type&&(null==c||c(e))},[c]));var m=n.useCallback(function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];f&&f.startLiveStreaming.apply(f,d([],s(e),!1))},[f]),b=n.useCallback(function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];f&&f.stopLiveStreaming.apply(f,d([],s(e),!1))},[f]),g=n.useCallback(function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];f&&f.updateLi