Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@daily-co/daily-react

Package Overview
Dependencies
Maintainers
19
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@daily-co/daily-react - npm Package Compare versions

Comparing version 0.7.1 to 0.7.2

dist/DailyLiveStreaming.d.ts

2

dist/daily-react.cjs.production.min.js

@@ -1,2 +0,2 @@

"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var n=require("react"),t=e(n),i=require("recoil"),r=e(require("lodash.throttle")),a=e(require("@daily-co/daily-js"));function o(e,n,t,i,r,a,o){try{var u=e[a](o),c=u.value}catch(e){return void t(e)}u.done?n(c):Promise.resolve(c).then(i,r)}function u(e){return function(){var n=this,t=arguments;return new Promise((function(i,r){var a=e.apply(n,t);function u(e){o(a,i,r,u,c,"next",e)}function c(e){o(a,i,r,u,c,"throw",e)}u(void 0)}))}}function c(){return(c=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])}return e}).apply(this,arguments)}function l(e,n){if(null==e)return{};var t,i,r={},a=Object.keys(e);for(i=0;i<a.length;i++)n.indexOf(t=a[i])>=0||(r[t]=e[t]);return r}function s(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,i=new Array(n);t<n;t++)i[t]=e[t];return i}var d=n.createContext(null),f=function(){return n.useContext(d)},v=n.createContext({on:function(){},off:function(){}}),p=0,y=function(){return p++},m=function(e,t){var i=n.useContext(v),r=i.off,a=i.on,o=n.useState(!1),u=o[0],c=o[1],l=n.useRef(0),s=n.useMemo((function(){return y()}),[]);n.useEffect((function(){if(e&&!u){if(l.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 '"+e+"' event is NOT registered.",t),void c(!0);l.current++;var n=setTimeout((function(){l.current=0}),50);return a(e,t,s),function(){clearTimeout(n),r(e,s)}}}),[t,e,s,u,r,a])},g=function(e,t,i){void 0===i&&(i=100);var a=n.useContext(v),o=a.off,u=a.on,c=n.useMemo((function(){var n;return Array.isArray(e)?e.reduce((function(e,n){return e[n]=y(),e}),{}):((n={})[e]=y(),n)}),[e]),l=n.useRef([]),s=n.useMemo((function(){return r((function(){0!==l.current.length&&(t(l.current),l.current=[])}),i,{trailing:!0})}),[t,i]);n.useEffect((function(){if(e){var n=function(e){l.current.push(e),setTimeout(s,0)};return Array.isArray(e)?e.forEach((function(e){return u(e,n,c[e])})):u(e,n,c[e]),function(){Array.isArray(e)?e.forEach((function(e){return o(e,c[e])})):o(e,c[e])}}}),[s,e,c,o,u])},k=i.atom({key:"daily-react-active-id",default:null}),b=i.atom({key:"daily-react-local-id",default:""}),h=i.atom({key:"daily-react-participants-objects",default:[]}),S=i.selectorFamily({key:"daily-react-participant",get:function(e){return function(n){var t;return null!=(t=(0,n.get)(h).find((function(n){return n.session_id===e})))?t:null}}}),R=i.selectorFamily({key:"daily-react-participant-property",get:function(e){var n=e.id,t=e.properties;return function(e){var i,r;return r=null!=(i=(0,e.get)(h).find((function(e){return e.session_id===n})))?i:null,t.map((function(e){return function(e,n){return String(n).split(".").filter((function(e){return e.length})).reduce((function(e,n){return e&&e[n]}),e)}(r,e)}))}}}),C=function(e){var r=e.children,a=f(),o=i.useRecoilCallback((function(e){var n=e.transact_UNSTABLE;return function(e){n((function(n){var t=n.set;t(b,e.local.session_id),t(h,Object.values(e))}))}}),[]);n.useEffect((function(){if(a){var e=setInterval((function(){var n=a.participants();"local"in n&&(o(n),clearInterval(e))}),100);return function(){clearInterval(e)}}}),[a,o]);var u=n.useCallback((function(){if(a){var e=null==a?void 0:a.participants();e.local&&o(e)}}),[a,o]);return m("started-camera",u),m("access-state-updated",u),m("joining-meeting",u),m("joined-meeting",n.useCallback((function(e){o(e.participants)}),[o])),g(["active-speaker-change","participant-joined","participant-updated","participant-left"],i.useRecoilCallback((function(e){var n=e.transact_UNSTABLE;return function(e){n((function(n){var t=n.reset,i=n.set;e.forEach((function(e){switch(e.action){case"active-speaker-change":var n=e.activeSpeaker.peerId;i(k,n),i(h,(function(e){return[].concat(e).map((function(e){return e.session_id===n?c({},e,{last_active:new Date}):e}))}));break;case"participant-joined":i(h,(function(n){return[].concat(n,[e.participant]).filter((function(e,n,t){return t.findIndex((function(n){return n.session_id===e.session_id}))==n}))}));break;case"participant-updated":i(h,(function(n){return[].concat(n).map((function(n){return n.session_id===e.participant.session_id?c({},e.participant,{last_active:n.last_active}):n}))})),e.participant.local&&i(b,(function(n){return n!==e.participant.session_id?e.participant.session_id:n}));break;case"participant-left":i(h,(function(n){return[].concat(n).filter((function(n){return e.participant.session_id!==n.session_id}))}));break;case"left-meeting":t(b),t(h)}}))}))}}),[])),t.createElement(t.Fragment,null,r)},A=function(){return i.useRecoilValue(b)||null},E=function(){return!0},I=function(e){var t=void 0===e?{}:e,r=t.filter,a=void 0===r?E:r,o=t.ignoreLocal,u=void 0!==o&&o,c=A(),l=i.useRecoilValue(k),s=n.useState(null),d=s[0],f=s[1];return n.useEffect((function(){u&&l===c||(null==a?void 0:a(l))&&f(l)}),[a,c,u,l]),d},w=Boolean,x=function(){return 0},L=function(e){var t=void 0===e?{filter:w,sort:x}:e,r=t.filter,a=void 0===r?w:r,o=t.onActiveSpeakerChange,u=t.onParticipantJoined,c=t.onParticipantLeft,l=t.onParticipantUpdated,s=t.sort,d=void 0===s?x:s,f=i.useRecoilValue(h),v=n.useMemo((function(){var e=w;switch(a){case"local":e=function(e){return e.local};break;case"owner":e=function(e){return e.owner};break;case"record":e=function(e){return e.record};break;case"remote":e=function(e){return!e.local};break;case"screen":e=function(e){return e.screen};break;default:e=a}return e}),[a]),p=n.useMemo((function(){var e;switch(d){case"joined_at":case"session_id":case"user_id":case"user_name":e=function(e,n){var t=e[d],i=n[d];if(void 0!==t||void 0!==i){if(void 0===t)return-1;if(void 0===i)return 1;if(t>i)return 1;if(t<i)return-1}return 0};break;default:e=d}return e}),[d]),y=n.useMemo((function(){return f.filter(v).sort(p).map((function(e){return e.session_id})).filter(Boolean)}),[f,v,p]);return g(["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==l||l(e);break;case"active-speaker-change":null==o||o(e);break;case"participant-left":null==c||c(e)}}))}),[o,u,c,l])),y},T=function(e){var t=void 0===e?{}:e,i=t.onLocalScreenShareStarted,r=t.onLocalScreenShareStopped,a=f(),o=n.useCallback((function(e){null==a||a.startScreenShare(e)}),[a]),u=n.useCallback((function(){null==a||a.stopScreenShare()}),[a]);m("local-screen-share-started",n.useCallback((function(){return null==i?void 0:i()}),[i])),m("local-screen-share-stopped",n.useCallback((function(){return null==r?void 0:r()}),[r]));var c=L({filter:"screen"}),l=n.useMemo((function(){return c.map((function(e){var n,t=Object.values(null!=(n=null==a||null==a.participants?void 0:a.participants())?n:{}).find((function(n){return n.session_id===e}));if(t)return{local:t.local,screenAudio:t.tracks.screenAudio,screenVideo:t.tracks.screenVideo,screenId:e+"-screen",session_id:e}})).filter((function(e){return!!e}))}),[a,c]);return{isSharingScreen:l.some((function(e){return e.local})),screens:l,startScreenShare:o,stopScreenShare:u}},_=function(e,n){var t=i.useRecoilValue(R({id:e,properties:Array.isArray(n)?n:[n]}));return Array.isArray(n)?t:t[0]},P=function(e,n){void 0===n&&(n="video");var t=_(e,"tracks."+n);return t?c({},t,{isOff:"blocked"===t.state||"off"===t.state}):{isOff:!0,persistentTrack:void 0,state:"off",subscribed:!1}};function D(){for(var e=arguments.length,t=new Array(e),i=0;i<e;i++)t[i]=arguments[i];return n.useCallback((function(e){for(var n=0;n<t.length;n++){var i=t[n];"function"==typeof i?i(e):i&&"object"==typeof i&&(i.current=e)}}),t)}var M=n.memo(n.forwardRef((function(e,i){var r=e.onPlayFailed,a=e.sessionId,o=e.type,u=void 0===o?"audio":o,c=l(e,["onPlayFailed","sessionId","type"]),s=n.useRef(null),d=P(a,u),f=D(s,i);return n.useEffect((function(){var e=s.current;if(e&&(null==d?void 0:d.persistentTrack)){var n,t=function(){n=setTimeout((function(){(e.readyState!==e.HAVE_ENOUGH_DATA||e.paused)&&(null==r||r({sessionId:a,target:e,type:u}))}),1500)},i=function(){clearTimeout(n)};return e.addEventListener("canplay",t),e.addEventListener("play",i),e.srcObject=new MediaStream([null==d?void 0:d.persistentTrack]),function(){null==e||e.removeEventListener("canplay",t),null==e||e.removeEventListener("play",i)}}}),[null==d?void 0:d.persistentTrack,r,a,u]),n.useMemo((function(){return t.createElement("audio",Object.assign({autoPlay:!0,playsInline:!0,ref:f},c,{"data-session-id":a,"data-audio-type":u}))}),[f,c,a,u])})));M.displayName="DailyAudioTrack";var j=n.memo(n.forwardRef((function(e,r){var a=e.maxSpeakers,o=e.onPlayFailed,c=e.playLocalScreenAudio,l=void 0!==c&&c,s=n.useState(new Array(void 0===a?5:a).fill("")),d=s[0],f=s[1],v=T().screens,p=A(),y=I({ignoreLocal:!0}),m=n.useRef(null);n.useImperativeHandle(r,(function(){return{getActiveSpeakerAudio:function(){var e,n;return null!=(e=null==(n=m.current)?void 0:n.querySelector('audio[data-session-id="'+y+'"][data-audio-type="audio"]'))?e:null},getAllAudio:function(){var e,n;return Array.from(null!=(e=null==(n=m.current)?void 0:n.querySelectorAll("audio"))?e:[])},getAudioBySessionId:function(e){var n,t;return null!=(n=null==(t=m.current)?void 0:t.querySelector('audio[data-session-id="'+e+'"][data-audio-type="audio"]'))?n:null},getScreenAudio:function(){var e,n;return Array.from(null!=(e=null==(n=m.current)?void 0:n.querySelectorAll('audio[data-audio-type="screenAudio"]'))?e:[])},getScreenAudioBySessionId:function(e){var n,t;return null!=(n=null==(t=m.current)?void 0:t.querySelector('audio[data-session-id="'+e+'"][data-audio-type="screenAudio"]'))?n:null}}}),[y]);var k=L({filter:n.useCallback((function(e){return!e.local&&Boolean(e.tracks.audio.subscribed)}),[])}),b=i.useRecoilCallback((function(e){var n=e.snapshot;return function(){var e=u((function*(e){if(k.includes(e)){var t=(yield n.getPromise(h)).filter((function(e){return k.includes(e.session_id)}));f((function(n){var i;if(n.includes(e))return n;var r=function(e){return!e||!k.includes(e)};if(n.some(r)){var a=n.findIndex(r);return n[a]=e,[].concat(n)}var o=n.findIndex((function(e){return t.some((function(n){return n.session_id===e&&["blocked","off"].includes(n.tracks.audio.state)}))}));if(o>=0)return n[o]=e,[].concat(n);var u=t.filter((function(e){return n.includes(e.session_id)&&e.session_id!==y})).sort((function(e,n){var t,i,r=null!=(t=null==e?void 0:e.last_active)?t:new Date("1970-01-01"),a=null!=(i=null==n?void 0:n.last_active)?i:new Date("1970-01-01");return r>a?1:r<a?-1:0}));if(!u.length){var c=n.findIndex((function(e){return e!==y}));return n[c]=e,[].concat(n)}var l=n.indexOf(null==(i=u[0])?void 0:i.session_id);return n[l]=e,[].concat(n)}))}}));return function(n){return e.apply(this,arguments)}}()}),[y,k]),S=n.useCallback((function(e){f((function(n){if(!n.includes(e))return n;var t=[].concat(n),i=t.indexOf(e);return t[i]="",t}))}),[]);g(["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===p)return;b(e.activeSpeaker.peerId);break;case"track-started":"audio"===e.track.kind&&e.participant&&!e.participant.local&&b(e.participant.session_id);break;case"participant-left":S(e.participant.session_id)}}))}),[b,p,S]));var R=n.useMemo((function(){return d.map((function(e,n){return t.createElement(M,{key:"speaker-slot-"+n,onPlayFailed:o,sessionId:e,type:"audio"})}))}),[o,d]),C=n.useMemo((function(){return v.filter((function(e){return!!l||!e.local})).map((function(e){return t.createElement(M,{key:e.screenId,onPlayFailed:o,sessionId:e.session_id,type:"screenAudio"})}))}),[o,l,v]);return t.createElement("div",{ref:m},R,C)})));j.displayName="DailyAudio";var O=n.forwardRef((function(e,i){var r=e.automirror,a=e.fit,o=void 0===a?"contain":a,u=e.mirror,s=e.onResize,d=e.playableStyle,f=void 0===d?{}:d,v=e.sessionId,p=e.style,y=void 0===p?{}:p,m=e.type,g=void 0===m?"video":m,k=l(e,["automirror","fit","mirror","onResize","playableStyle","sessionId","style","type"]),b=A()===v,h="screenVideo"===g,S=b&&!h,R=n.useRef(null),C=D(R,i),E=P(v,g),I=E.persistentTrack,w=S||h||!E.isOff,x=_(v,"tracks."+g+".subscribed"),L=n.useMemo((function(){if("boolean"==typeof u)return u;if(!r)return!1;if(!I)return S;var e=I.getSettings();return"facingMode"in e?S&&"user"===e.facingMode:S}),[r,S,u,I]);return n.useEffect((function(){var e=R.current;if(e){var n=function(){e.paused&&e.play()},t=function(){e.style.transform="scale(1)"},i=function(){e.style.transform="",setTimeout((function(){e.paused&&e.play()}),100)},r=function(){"hidden"!==document.visibilityState&&e.paused&&e.play()};return e.addEventListener("canplay",n),e.addEventListener("enterpictureinpicture",t),e.addEventListener("leavepictureinpicture",i),document.addEventListener("visibilitychange",r),function(){e.removeEventListener("canplay",n),e.removeEventListener("enterpictureinpicture",t),e.removeEventListener("leavepictureinpicture",i),document.removeEventListener("visibilitychange",r)}}}),[]),n.useEffect((function(){var e=R.current;if(e&&I)return e.srcObject=new MediaStream([I]),e.load(),function(){e.srcObject=null,e.load()}}),[I,null==I?void 0:I.id]),n.useEffect((function(){var e=R.current;if(s&&e){var n,t=function(){e&&(n&&cancelAnimationFrame(n),n=requestAnimationFrame((function(){if(!document.hidden){var n=null==e?void 0:e.videoWidth,t=null==e?void 0:e.videoHeight;n&&t&&s({aspectRatio:n/t,height:t,width:n})}})))};return t(),null==e||e.addEventListener("resize",t),function(){return null==e?void 0:e.removeEventListener("resize",t)}}}),[s,I]),t.createElement("video",Object.assign({autoPlay:!0,muted:!0,playsInline:!0,ref:C,"data-local":b,"data-mirrored":L||void 0,"data-playable":w||void 0,"data-session-id":v,"data-subscribed":x,"data-video-type":g,style:c({objectFit:o,transform:L?"scale(-1, 1)":""},y,w?f:{})},k))}));O.displayName="DailyVideo";var V=n.createContext({refreshDevices:function(){return Promise.resolve()}}),B=i.atom({key:"daily-react-general-camera-state",default:"idle"}),U=i.atom({key:"daily-react-general-microphone-state",default:"idle"}),F=i.atom({key:"daily-react-camera-devices",default:[]}),N=i.atom({key:"daily-react-microphone-devices",default:[]}),q=i.atom({key:"daily-react-speaker-devices",default:[]}),W=i.atom({key:"daily-react-last-camera-error",default:null}),z=function(e){var r=e.children,a=f(),o=i.useRecoilCallback((function(e){var n=e.transact_UNSTABLE;return u((function*(){var e,t,i,r;if(void 0!==(null==(e=navigator)||null==(t=e.mediaDevices)?void 0:t.getUserMedia)&&void 0!==(null==(i=navigator)||null==(r=i.mediaDevices)?void 0:r.enumerateDevices)){if(a)try{var o=(yield a.enumerateDevices()).devices,u=o.filter((function(e){return"videoinput"===e.kind&&""!==e.deviceId})),c=o.filter((function(e){return"audioinput"===e.kind&&""!==e.deviceId})),l=o.filter((function(e){return"audiooutput"===e.kind&&""!==e.deviceId})),s=yield a.getInputDevices(),d=s.camera,f=s.mic,v=s.speaker,p=function(e,n,t){var i,r;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.state)?i:"granted"}},y=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((function(e){var n=e.set;n(F,(function(e){return u.filter(Boolean).map((function(n){return p(d,n,e)})).sort(y)})),n(N,(function(e){return c.filter(Boolean).map((function(n){return p(f,n,e)})).sort(y)})),n(q,(function(e){return l.filter(Boolean).map((function(n){return p(v,n,e)})).sort(y)}))}))}catch(e){n((function(e){var n=e.set;n(B,"not-supported"),n(U,"not-supported")}))}}else n((function(e){var n=e.set;n(B,"not-supported"),n(U,"not-supported")}))}))}),[a]),l=i.useRecoilCallback((function(e){var n=e.set,t=e.snapshot,i=e.transact_UNSTABLE;return u((function*(){var e,r,u,l,s,d,f,v,p,y,m,g,k,b;if(a){var h=yield t.getPromise(B),S=yield t.getPromise(U),R=a.participants();if(R.local){var C=R.local.tracks,A=["idle","pending"].includes(h)&&"interrupted"===C.video.state&&!C.video.persistentTrack,E=["idle","pending"].includes(h)&&!C.video.persistentTrack&&Boolean(null==(e=C.video.off)?void 0:e.byUser),I=["idle","pending"].includes(S)&&"interrupted"===C.audio.state&&!C.audio.persistentTrack,w=["idle","pending"].includes(S)&&!C.audio.persistentTrack&&Boolean(null==(r=C.audio.off)?void 0:r.byUser);(null==(u=C.audio)||null==(l=u.blocked)?void 0:l.byDeviceInUse)?i((function(e){var n=e.set;n(U,"in-use"),n(N,(function(e){return e.map((function(e){return e.selected?c({},e,{state:"in-use"}):e}))}))})):(null==(s=C.audio)||null==(d=s.blocked)?void 0:d.byDeviceMissing)?n(U,"not-found"):(null==(f=C.audio)||null==(v=f.blocked)?void 0:v.byPermissions)?n(U,"blocked"):I?n(U,"pending"):w?n(U,"idle"):i((function(e){var n=e.set;n(U,"granted"),n(N,(function(e){return e.map((function(e){return e.selected?c({},e,{state:"granted"}):e}))}))})),(null==(p=C.video)||null==(y=p.blocked)?void 0:y.byDeviceInUse)?i((function(e){var n=e.set;n(B,"in-use"),n(F,(function(e){return e.map((function(e){return e.selected?c({},e,{state:"in-use"}):e}))}))})):(null==(m=C.video)||null==(g=m.blocked)?void 0:g.byDeviceMissing)?n(B,"not-found"):(null==(k=C.video)||null==(b=k.blocked)?void 0:b.byPermissions)?n(B,"blocked"):A?n(B,"pending"):E?n(B,"idle"):i((function(e){var n=e.set;n(B,"granted"),n(F,(function(e){return e.map((function(e){return e.selected?c({},e,{state:"granted"}):e}))}))})),o()}}}))}),[a,o]);return m("participant-updated",n.useCallback((function(e){e.participant.local&&l()}),[l])),m("available-devices-updated",o),m("selected-devices-updated",o),m("camera-error",i.useRecoilCallback((function(e){var n=e.transact_UNSTABLE;return function(e){n((function(n){var t,i,r,a,o,u,c,l=n.set;switch(l(W,e.error),null==(t=e.error)?void 0:t.type){case"cam-in-use":l(B,"in-use");break;case"mic-in-use":l(U,"in-use");break;case"cam-mic-in-use":l(B,"in-use"),l(U,"in-use");break;case"not-found":(null==(i=e.error)?void 0:i.missingMedia.includes("video"))&&l(B,"not-found"),(null==(r=e.error)?void 0:r.missingMedia.includes("audio"))&&l(U,"not-found");break;case"permissions":(null==(a=e.error)?void 0:a.blockedMedia.includes("video"))&&l(B,"blocked"),(null==(o=e.error)?void 0:o.blockedMedia.includes("audio"))&&l(U,"blocked");break;case"constraints":"invalid"===(null==(u=e.error)?void 0:u.reason)?(l(B,"constraints-invalid"),l(U,"constraints-invalid")):"none-specified"===(null==(c=e.error)?void 0:c.reason)&&(l(B,"constraints-none-specified"),l(U,"constraints-none-specified"));break;case"undefined-mediadevices":l(B,"undefined-mediadevices"),l(U,"undefined-mediadevices");break;case"unknown":default:l(B,"unknown"),l(U,"unknown")}}))}}),[])),m("started-camera",i.useRecoilCallback((function(e){var n=e.transact_UNSTABLE;return function(){n((function(e){var n=e.set;n(B,"granted"),n(U,"granted")})),l()}}),[l])),t.createElement(V.Provider,{value:{refreshDevices:o}},r)},H=i.atom({key:"daily-react-room",default:null}),G=function(e){var n=e.children,r=f(),a=i.useRecoilCallback((function(e){var n=e.set;return u((function*(){if(r&&"left-meeting"!==r.meetingState()){var e=yield r.room();return e&&"id"in e&&n(H,e),e}}))}),[r]);return m("access-state-updated",a),t.createElement(t.Fragment,null,n)},Q=function(e,t){var r=void 0===t?{}:t,a=r.onParticipantLeft,o=r.onParticipantUpdated,u=i.useRecoilValue(S(e));return g(["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])),u},J="data:application/javascript;charset=utf8,"+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"),$=i.atom({key:"daily-react-input-settings",default:null}),K=i.atom({key:"daily-react-input-settings-error",default:null}),X=i.atom({key:"daily-react-live-streaming",default:{errorMsg:void 0,isLiveStreaming:!1,layout:void 0}}),Y=i.atom({key:"daily-react-topology",default:"none"}),Z=i.atom({key:"daily-react-networkQuality",default:100}),ee=i.atom({key:"daily-react-networkThreshold",default:"good"}),ne=i.atomFamily({key:"daily-react-participant-receive-settings",default:{}}),te=i.atom({key:"daily-react-recording",default:{isLocalParticipantRecorded:!1,isRecording:!1}}),ie=function(){return i.useRecoilValue(H)},re=i.atom({key:"daily-react-transcription",default:{isTranscriptionEnabled:!1,isTranscribing:!1,model:"general",language:"en",transcriptions:[]}}),ae=i.atom({key:"daily-react-waiting-participants",default:[]}),oe=i.atomFamily({key:"daily-react-waiting-participant",default:{awaitingAccess:{level:"full"},id:"",name:""}}),ue=i.selector({key:"daily-react-waitingParticipantsSelector",get:function(e){var n=e.get;return n(ae).map((function(e){return n(oe(e))}))}});exports.DailyAudio=j,exports.DailyAudioTrack=M,exports.DailyProvider=function(e){var r=e.children,o=e.recoilRootProps,u=void 0===o?{}:o,c=l(e,["children","recoilRootProps"]),f=n.useState("callObject"in c?c.callObject:null),p=f[0],y=f[1],m=n.useRef({});n.useEffect((function(){var e;if("callObject"in c){var n=(null==p?void 0:p._callFrameId)!==(null==c||null==(e=c.callObject)?void 0:e._callFrameId);c.callObject?(n||!p&&c.callObject)&&y(c.callObject):y(null)}}),[p,c]);var g=n.useCallback((function(e){if("action"in e)for(var n,t=function(e,n){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(t)return(t=t.call(e)).next.bind(t);if(Array.isArray(e)||(t=function(e,n){if(e){if("string"==typeof e)return s(e,void 0);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?s(e,void 0):void 0}}(e))){t&&(e=t);var i=0;return function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(null!=(i=null==(r=m.current)||null==(a=r[e.action])?void 0:a.values())?i:[]);!(n=t()).done;){var i,r,a;(0,n.value)(e)}}),[]),k=n.useCallback((function(e){e&&Object.keys(m.current).forEach((function(n){e.off(n,g).on(n,g)}))}),[g]);n.useEffect((function(){if(!p){if("callObject"in c)return y(c.callObject),void k(c.callObject);var e=a.createCallObject(c);y(e),k(e)}}),[p,k,c]);var b=n.useCallback((function(e,n,t){var i,r;m.current[e]||(m.current[e]=new Map,p&&p.off(e,g).on(e,g)),(null==(i=m.current[e])?void 0:i.has(t))||null==(r=m.current[e])||r.set(t,n)}),[p,g]),h=n.useCallback((function(e,n){var t,i;null==(t=m.current[e])||t.delete(n),0===(null==(i=m.current[e])?void 0:i.size)&&(null==p||p.off(e,g),delete m.current[e])}),[p,g]);return t.createElement(i.RecoilRoot,Object.assign({},u),t.createElement(d.Provider,{value:p},t.createElement(v.Provider,{value:{on:b,off:h}},t.createElement(G,null,t.createElement(C,null,t.createElement(z,null,r))))))},exports.DailyVideo=O,exports.useActiveParticipant=function(e){var t=void 0===e?{}:e,r=t.ignoreLocal,a=void 0!==r&&r,o=t.onActiveSpeakerChange,u=f(),c=i.useRecoilValue(k),l=n.useState(""),s=l[1],d=Q(l[0]);return n.useEffect((function(){var e;if(u){var n=null==u||null==(e=u.participants())?void 0:e.local;a&&c===(null==n?void 0:n.session_id)||s(null!=c?c:"")}}),[u,a,c]),m("active-speaker-change",n.useCallback((function(e){null==o||o(e)}),[o])),d},exports.useActiveSpeakerId=I,exports.useAppMessage=function(e){var t=(void 0===e?{}:e).onAppMessage,i=f(),r=n.useCallback((function(e,n){void 0===n&&(n="*"),i&&i.sendAppMessage(e,n)}),[i]),a=n.useCallback((function(e){null==t||t(e,r)}),[t,r]);return m("app-message",a),r},exports.useAudioLevel=function(e,t){var i=n.useRef();n.useEffect((function(){if(e){var n="undefined"!=typeof AudioContext?AudioContext:void 0!==window.webkitAudioContext?window.webkitAudioContext:null;if(n){i.current||(i.current=new n);var r=i.current;if(r){var a,o=r.createMediaStreamSource(new MediaStream([e]));return function(){var e=u((function*(){try{a=new AudioWorkletNode(r,"audiolevel")}catch(e){try{yield r.audioWorklet.addModule(J),a=new AudioWorkletNode(r,"audiolevel")}catch(e){console.error(e)}}if(a){a.port.onmessage=function(e){var n=0;e.data.volume&&(n=e.data.volume),a&&t(n)};try{o.connect(a).connect(r.destination)}catch(e){console.warn(e)}}}));return function(){return e.apply(this,arguments)}}()(),function(){var e;null==(e=a)||e.disconnect(),a=null,null==o||o.disconnect()}}}}}),[t,e])},exports.useAudioTrack=function(e){return P(e,"audio")},exports.useDaily=f,exports.useDailyEvent=m,exports.useDevices=function(){var e=f(),t=i.useRecoilValue(B),r=i.useRecoilValue(U),a=i.useRecoilValue(F),o=i.useRecoilValue(N),c=i.useRecoilValue(q),l=i.useRecoilValue(W),s=n.useContext(V).refreshDevices,d=n.useCallback(function(){var n=u((function*(n){yield null==e?void 0:e.setInputDevicesAsync({audioDeviceId:null,videoDeviceId:n})}));return function(e){return n.apply(this,arguments)}}(),[e]),v=n.useCallback(function(){var n=u((function*(n){yield null==e?void 0:e.setInputDevicesAsync({audioDeviceId:n,videoDeviceId:null})}));return function(e){return n.apply(this,arguments)}}(),[e]),p=n.useCallback(function(){var n=u((function*(n){yield null==e?void 0:e.setOutputDeviceAsync({outputDeviceId:n})}));return function(e){return n.apply(this,arguments)}}(),[e]),y=["blocked","in-use","not-found","constraints-invalid","constraints-none-specified","undefined-mediadevices","unknown"];return{cameraError:l,cameras:a,camState:t,hasCamError:y.includes(t),hasMicError:y.includes(r),microphones:o,micState:r,refreshDevices:s,setCamera:d,setMicrophone:v,setSpeaker:p,speakers:c}},exports.useInputSettings=function(e){var t=void 0===e?{}:e,r=t.onError,a=t.onInputSettingsUpdated,o=i.useRecoilValue($),u=i.useRecoilValue(K),c=f(),l=i.useRecoilCallback((function(e){var n=e.set;return function(e){n($,e)}}),[]);return n.useEffect((function(){c&&c.getInputSettings().then(l)}),[c,l]),m("input-settings-updated",n.useCallback((function(e){l(e.inputSettings),null==a||a(e)}),[a,l])),m("nonfatal-error",i.useRecoilCallback((function(e){var n=e.set;return function(e){"input-settings-error"===e.type&&(n(K,e.errorMsg),null==r||r(e))}}),[r])),{errorMsg:u,inputSettings:o,updateInputSettings:n.useCallback((function(e){null==c||c.updateInputSettings(e)}),[c])}},exports.useLiveStreaming=function(e){var t=void 0===e?{}:e,r=t.onLiveStreamingError,a=t.onLiveStreamingStarted,o=t.onLiveStreamingStopped,u=f(),l=i.useRecoilValue(X);return m("live-streaming-started",i.useRecoilCallback((function(e){var n=e.set;return function(e){n(X,{isLiveStreaming:!0,layout:null==e?void 0:e.layout}),null==a||a(e)}}),[a])),m("live-streaming-stopped",i.useRecoilCallback((function(e){var n=e.set;return function(e){n(X,(function(e){return c({},e,{isLiveStreaming:!1,layout:void 0})})),null==o||o(e)}}),[o])),m("live-streaming-error",i.useRecoilCallback((function(e){var n=e.set;return function(e){n(X,(function(n){return c({},n,{errorMsg:e.errorMsg})})),null==r||r(e)}}),[r])),c({},l,{startLiveStreaming:n.useCallback((function(e){u&&u.startLiveStreaming(e)}),[u]),stopLiveStreaming:n.useCallback((function(){u&&u.stopLiveStreaming()}),[u]),updateLiveStreaming:n.useCallback((function(e){u&&u.updateLiveStreaming({layout:e.layout})}),[u])})},exports.useLocalParticipant=function(){var e=i.useRecoilValue(b);return Q(e)},exports.useLocalSessionId=A,exports.useMediaTrack=P,exports.useNetwork=function(e){var t=void 0===e?{}:e,r=t.onNetworkConnection,a=t.onNetworkQualityChange,o=f(),c=i.useRecoilValue(Y),l=i.useRecoilValue(Z),s=i.useRecoilValue(ee),d=i.useRecoilCallback((function(e){var n=e.set;return u((function*(){if(o){var e=yield o.getNetworkTopology();e&&"none"!==(null==e?void 0:e.topology)&&n(Y,e.topology)}}))}),[o]),v=i.useRecoilCallback((function(e){var n=e.transact_UNSTABLE;return function(e){n((function(n){var t=n.set;switch(e.event){case"connected":"peer-to-peer"===e.type&&t(Y,"peer"),"sfu"===e.type&&t(Y,"sfu")}})),null==r||r(e)}}),[r]),p=i.useRecoilCallback((function(e){var n=e.transact_UNSTABLE;return function(e){n((function(n){var t=n.set;t(Z,(function(n){return n!==e.quality?e.quality:n})),t(ee,(function(n){return n!==e.threshold?e.threshold:n}))})),null==a||a(e)}}),[a]);return m("joined-meeting",d),m("network-connection",v),m("network-quality-change",p),n.useEffect((function(){o&&!c&&d()}),[o,d,c]),{getStats:n.useCallback(u((function*(){var e=yield null==o?void 0:o.getNetworkStats();return null==e?void 0:e.stats})),[o]),quality:l,threshold:s,topology:c}},exports.useParticipant=Q,exports.useParticipantIds=L,exports.useParticipantProperty=_,exports.useReceiveSettings=function(e){var t=void 0===e?{}:e,r=t.id,a=void 0===r?"base":r,o=t.onReceiveSettingsUpdated,u=i.useRecoilValue(ne("base")),l=i.useRecoilValue(ne(a)),s=f();m("receive-settings-updated",i.useRecoilCallback((function(e){var n=e.transact_UNSTABLE;return function(e){n((function(n){for(var t=n.reset,i=n.set,r=c({},e.receiveSettings),o=0,u=Object.entries(r);o<u.length;o++){var l=u[o],s=l[1];i(ne(l[0]),s)}a in r||t(ne(a))})),null==o||o(e)}}),[a,o]));var d=n.useCallback((function(e){s&&"joined-meeting"===s.meetingState()&&(null==s||null==s.updateReceiveSettings||s.updateReceiveSettings(e))}),[s]);return{receiveSettings:"base"===a||0===Object.keys(l).length?u:l,updateReceiveSettings:d}},exports.useRecording=function(e){var t=void 0===e?{}:e,r=t.onRecordingData,a=t.onRecordingError,o=t.onRecordingStarted,u=t.onRecordingStopped,l=f(),s=i.useRecoilValue(te),d=i.useSetRecoilState(te),v=A(),p=L({filter:"record"});return n.useEffect((function(){var e=p.length>0,n=p.includes(null!=v?v:"local");d((function(t){return c({},t,{isLocalParticipantRecorded:"local"!==(null==t?void 0:t.type)&&(null==t?void 0:t.type)?t.isLocalParticipantRecorded:e,isRecording:"local"!==(null==t?void 0:t.type)&&(null==t?void 0:t.type)?t.isRecording:e,local:"local"!==(null==t?void 0:t.type)&&(null==t?void 0:t.type)||!e?null==t?void 0:t.local:n,type:e?"local":null==t?void 0:t.type})}))}),[v,p,d]),m("recording-started",i.useRecoilCallback((function(e){var n=e.set;return function(e){var t=!0;switch(e.type){case"cloud-beta":case"cloud":var i;v&&"single-participant"===(null==(i=e.layout)?void 0:i.preset)&&e.layout.session_id!==v&&(t=!1)}n(te,{error:!1,isLocalParticipantRecorded:t,isRecording:!0,layout:null==e?void 0:e.layout,local:null==e?void 0:e.local,recordingId:null==e?void 0:e.recordingId,recordingStartedDate:new Date,startedBy:null==e?void 0:e.startedBy,type:null==e?void 0:e.type}),null==o||o(e)}}),[v,o])),m("recording-stopped",i.useRecoilCallback((function(e){var n=e.set;return function(e){n(te,(function(e){return c({},e,{isLocalParticipantRecorded:!1,isRecording:!1})})),null==u||u(e)}}),[u])),m("recording-error",i.useRecoilCallback((function(e){var n=e.set;return function(e){n(te,(function(e){return c({},e,{error:!0,isLocalParticipantRecorded:!1,isRecording:!1})})),null==a||a(e)}}),[a])),m("recording-data",n.useCallback((function(e){null==r||r(e)}),[r])),c({},s,{startRecording:n.useCallback((function(e){l&&l.startRecording(e)}),[l]),stopRecording:n.useCallback((function(){l&&l.stopRecording()}),[l]),updateRecording:n.useCallback((function(e){l&&l.updateRecording(e)}),[l])})},exports.useRoom=ie,exports.useScreenAudioTrack=function(e){return P(e,"screenAudio")},exports.useScreenShare=T,exports.useScreenVideoTrack=function(e){return P(e,"screenVideo")},exports.useThrottledDailyEvent=g,exports.useTranscription=function(e){var t,r=void 0===e?{}:e,a=r.onTranscriptionAppData,o=r.onTranscriptionError,u=r.onTranscriptionStarted,l=r.onTranscriptionStopped,s=f(),d=i.useRecoilValue(re),v=i.useSetRecoilState(re),p=ie();return n.useEffect((function(){var e;(null==p||null==(e=p.domainConfig)?void 0:e.enable_transcription)&&v((function(e){return c({},e,{isTranscriptionEnabled:!0})}))}),[null==p||null==(t=p.domainConfig)?void 0:t.enable_transcription,v]),m("transcription-started",i.useRecoilCallback((function(e){var n=e.set;return function(e){n(re,c({isTranscriptionEnabled:!0,error:!1,isTranscribing:!0,transcriptionStartDate:new Date,transcriptions:[]},e)),null==u||u(e)}}),[u])),m("transcription-stopped",i.useRecoilCallback((function(e){var n=e.set;return function(e){n(re,(function(n){return c({},n,{updatedBy:null==e?void 0:e.updatedBy,isTranscribing:!1})})),null==l||l(e)}}),[l])),m("transcription-error",i.useRecoilCallback((function(e){var n=e.set;return function(e){n(re,(function(e){return c({},e,{error:!0,isTranscribing:!1})})),null==o||o(e)}}),[o])),m("app-message",i.useRecoilCallback((function(e){var n=e.set;return function(e){var t;"transcription"===(null==e?void 0:e.fromId)&&(null==e||null==(t=e.data)?void 0:t.is_final)&&(n(re,(function(n){return c({},n,{isTranscribing:!0,transcriptions:[].concat(n.transcriptions,[e.data])})})),null==a||a(e))}}),[a])),c({},d,{startTranscription:n.useCallback((function(e){s&&s.startTranscription(e)}),[s]),stopTranscription:n.useCallback((function(){s&&s.stopTranscription()}),[s])})},exports.useVideoTrack=function(e){return P(e,"video")},exports.useWaitingParticipants=function(e){var t=void 0===e?{}:e,r=t.onWaitingParticipantAdded,a=t.onWaitingParticipantRemoved,o=t.onWaitingParticipantUpdated,u=f(),c=i.useRecoilValue(ue),l=i.useRecoilCallback((function(e){var n=e.transact_UNSTABLE;return function(e){n((function(n){var t=n.set;t(ae,(function(n){return n.includes(e.participant.id)?n:[].concat(n,[e.participant.id])})),t(oe(e.participant.id),e.participant)})),null==r||r(e)}}),[r]),s=i.useRecoilCallback((function(e){var n=e.transact_UNSTABLE;return function(e){n((function(n){var t=n.reset;(0,n.set)(ae,(function(n){return n.filter((function(n){return n!==e.participant.id}))})),t(oe(e.participant.id))})),null==a||a(e)}}),[a]),d=i.useRecoilCallback((function(e){var n=e.set;return function(e){n(oe(e.participant.id),e.participant),null==o||o(e)}}),[o]);m("waiting-participant-added",l),m("waiting-participant-removed",s),m("waiting-participant-updated",d);var v=n.useCallback((function(e,n){"*"!==e?null==u||u.updateWaitingParticipant(e,{grantRequestedAccess:n}):null==u||u.updateWaitingParticipants({"*":{grantRequestedAccess:n}})}),[u]);return{waitingParticipants:c,grantAccess:n.useCallback((function(e){v(e,!0)}),[v]),denyAccess:n.useCallback((function(e){v(e,!1)}),[v])}};
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var n=require("react"),t=e(n),i=require("recoil"),r=e(require("lodash.throttle")),a=e(require("@daily-co/daily-js"));function o(e,n,t,i,r,a,o){try{var u=e[a](o),c=u.value}catch(e){return void t(e)}u.done?n(c):Promise.resolve(c).then(i,r)}function u(e){return function(){var n=this,t=arguments;return new Promise((function(i,r){var a=e.apply(n,t);function u(e){o(a,i,r,u,c,"next",e)}function c(e){o(a,i,r,u,c,"throw",e)}u(void 0)}))}}function c(){return(c=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])}return e}).apply(this,arguments)}function l(e,n){if(null==e)return{};var t,i,r={},a=Object.keys(e);for(i=0;i<a.length;i++)n.indexOf(t=a[i])>=0||(r[t]=e[t]);return r}function s(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,i=new Array(n);t<n;t++)i[t]=e[t];return i}var d=n.createContext(null),f=function(){return n.useContext(d)},v=n.createContext({on:function(){},off:function(){}}),p=0,m=function(){return p++},y=function(e,t){var i=n.useContext(v),r=i.off,a=i.on,o=n.useState(!1),u=o[0],c=o[1],l=n.useRef(0),s=n.useMemo((function(){return m()}),[]);n.useEffect((function(){if(e&&!u){if(l.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 '"+e+"' event is NOT registered.",t),void c(!0);l.current++;var n=setTimeout((function(){l.current=0}),50);return a(e,t,s),function(){clearTimeout(n),r(e,s)}}}),[t,e,s,u,r,a])},g=function(e,t,i){void 0===i&&(i=100);var a=n.useContext(v),o=a.off,u=a.on,c=n.useMemo((function(){var n;return Array.isArray(e)?e.reduce((function(e,n){return e[n]=m(),e}),{}):((n={})[e]=m(),n)}),[e]),l=n.useRef([]),s=n.useMemo((function(){return r((function(){0!==l.current.length&&(t(l.current),l.current=[])}),i,{trailing:!0})}),[t,i]);n.useEffect((function(){if(e){var n=function(e){l.current.push(e),setTimeout(s,0)};return Array.isArray(e)?e.forEach((function(e){return u(e,n,c[e])})):u(e,n,c[e]),function(){Array.isArray(e)?e.forEach((function(e){return o(e,c[e])})):o(e,c[e])}}}),[s,e,c,o,u])},k=i.atom({key:"daily-react-active-id",default:null}),b=i.atom({key:"daily-react-local-id",default:""}),h=i.atom({key:"daily-react-participants-objects",default:[]}),S=i.selectorFamily({key:"daily-react-participant",get:function(e){return function(n){var t;return null!=(t=(0,n.get)(h).find((function(n){return n.session_id===e})))?t:null}}}),R=i.selectorFamily({key:"daily-react-participant-property",get:function(e){var n=e.id,t=e.properties;return function(e){var i,r;return r=null!=(i=(0,e.get)(h).find((function(e){return e.session_id===n})))?i:null,t.map((function(e){return function(e,n){return String(n).split(".").filter((function(e){return e.length})).reduce((function(e,n){return e&&e[n]}),e)}(r,e)}))}}}),C=function(e){var r=e.children,a=f(),o=i.useRecoilCallback((function(e){var n=e.transact_UNSTABLE;return function(e){n((function(n){var t=n.set;t(b,e.local.session_id),t(h,Object.values(e))}))}}),[]);n.useEffect((function(){if(a){var e=setInterval((function(){var n=a.participants();"local"in n&&(o(n),clearInterval(e))}),100);return function(){clearInterval(e)}}}),[a,o]);var u=n.useCallback((function(){if(a){var e=null==a?void 0:a.participants();e.local&&o(e)}}),[a,o]);return y("started-camera",u),y("access-state-updated",u),y("joining-meeting",u),y("joined-meeting",n.useCallback((function(e){o(e.participants)}),[o])),g(["active-speaker-change","participant-joined","participant-updated","participant-left"],i.useRecoilCallback((function(e){var n=e.transact_UNSTABLE;return function(e){n((function(n){var t=n.reset,i=n.set;e.forEach((function(e){switch(e.action){case"active-speaker-change":var n=e.activeSpeaker.peerId;i(k,n),i(h,(function(e){return[].concat(e).map((function(e){return e.session_id===n?c({},e,{last_active:new Date}):e}))}));break;case"participant-joined":i(h,(function(n){return[].concat(n,[e.participant]).filter((function(e,n,t){return t.findIndex((function(n){return n.session_id===e.session_id}))==n}))}));break;case"participant-updated":i(h,(function(n){return[].concat(n).map((function(n){return n.session_id===e.participant.session_id?c({},e.participant,{last_active:n.last_active}):n}))})),e.participant.local&&i(b,(function(n){return n!==e.participant.session_id?e.participant.session_id:n}));break;case"participant-left":i(h,(function(n){return[].concat(n).filter((function(n){return e.participant.session_id!==n.session_id}))}));break;case"left-meeting":t(b),t(h)}}))}))}}),[])),t.createElement(t.Fragment,null,r)},A=function(){return i.useRecoilValue(b)||null},E=function(){return!0},I=function(e){var t=void 0===e?{}:e,r=t.filter,a=void 0===r?E:r,o=t.ignoreLocal,u=void 0!==o&&o,c=A(),l=i.useRecoilValue(k),s=n.useState(null),d=s[0],f=s[1];return n.useEffect((function(){u&&l===c||(null==a?void 0:a(l))&&f(l)}),[a,c,u,l]),d},w=Boolean,x=function(){return 0},L=function(e){var t=void 0===e?{filter:w,sort:x}:e,r=t.filter,a=void 0===r?w:r,o=t.onActiveSpeakerChange,u=t.onParticipantJoined,c=t.onParticipantLeft,l=t.onParticipantUpdated,s=t.sort,d=void 0===s?x:s,f=i.useRecoilValue(h),v=n.useMemo((function(){var e=w;switch(a){case"local":e=function(e){return e.local};break;case"owner":e=function(e){return e.owner};break;case"record":e=function(e){return e.record};break;case"remote":e=function(e){return!e.local};break;case"screen":e=function(e){return e.screen};break;default:e=a}return e}),[a]),p=n.useMemo((function(){var e;switch(d){case"joined_at":case"session_id":case"user_id":case"user_name":e=function(e,n){var t=e[d],i=n[d];if(void 0!==t||void 0!==i){if(void 0===t)return-1;if(void 0===i)return 1;if(t>i)return 1;if(t<i)return-1}return 0};break;default:e=d}return e}),[d]),m=n.useMemo((function(){return f.filter(v).sort(p).map((function(e){return e.session_id})).filter(Boolean)}),[f,v,p]);return g(["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==l||l(e);break;case"active-speaker-change":null==o||o(e);break;case"participant-left":null==c||c(e)}}))}),[o,u,c,l])),m},T=function(e){var t=void 0===e?{}:e,i=t.onLocalScreenShareStarted,r=t.onLocalScreenShareStopped,a=f(),o=n.useCallback((function(e){null==a||a.startScreenShare(e)}),[a]),u=n.useCallback((function(){null==a||a.stopScreenShare()}),[a]);y("local-screen-share-started",n.useCallback((function(){return null==i?void 0:i()}),[i])),y("local-screen-share-stopped",n.useCallback((function(){return null==r?void 0:r()}),[r]));var c=L({filter:"screen"}),l=n.useMemo((function(){return c.map((function(e){var n,t=Object.values(null!=(n=null==a||null==a.participants?void 0:a.participants())?n:{}).find((function(n){return n.session_id===e}));if(t)return{local:t.local,screenAudio:t.tracks.screenAudio,screenVideo:t.tracks.screenVideo,screenId:e+"-screen",session_id:e}})).filter((function(e){return!!e}))}),[a,c]);return{isSharingScreen:l.some((function(e){return e.local})),screens:l,startScreenShare:o,stopScreenShare:u}},_=function(e,n){var t=i.useRecoilValue(R({id:e,properties:Array.isArray(n)?n:[n]}));return Array.isArray(n)?t:t[0]},P=function(e,n){void 0===n&&(n="video");var t=_(e,"tracks."+n);return t?c({},t,{isOff:"blocked"===t.state||"off"===t.state}):{isOff:!0,persistentTrack:void 0,state:"off",subscribed:!1}};function D(){for(var e=arguments.length,t=new Array(e),i=0;i<e;i++)t[i]=arguments[i];return n.useCallback((function(e){for(var n=0;n<t.length;n++){var i=t[n];"function"==typeof i?i(e):i&&"object"==typeof i&&(i.current=e)}}),t)}var M=n.memo(n.forwardRef((function(e,i){var r=e.onPlayFailed,a=e.sessionId,o=e.type,u=void 0===o?"audio":o,c=l(e,["onPlayFailed","sessionId","type"]),s=n.useRef(null),d=P(a,u),f=D(s,i);return n.useEffect((function(){var e=s.current;if(e&&(null==d?void 0:d.persistentTrack)){var n,t=function(){n=setTimeout((function(){(e.readyState!==e.HAVE_ENOUGH_DATA||e.paused)&&(null==r||r({sessionId:a,target:e,type:u}))}),1500)},i=function(){clearTimeout(n)};return e.addEventListener("canplay",t),e.addEventListener("play",i),e.srcObject=new MediaStream([null==d?void 0:d.persistentTrack]),function(){null==e||e.removeEventListener("canplay",t),null==e||e.removeEventListener("play",i)}}}),[null==d?void 0:d.persistentTrack,r,a,u]),n.useMemo((function(){return t.createElement("audio",Object.assign({autoPlay:!0,playsInline:!0,ref:f},c,{"data-session-id":a,"data-audio-type":u}))}),[f,c,a,u])})));M.displayName="DailyAudioTrack";var j=n.memo(n.forwardRef((function(e,r){var a=e.maxSpeakers,o=e.onPlayFailed,c=e.playLocalScreenAudio,l=void 0!==c&&c,s=n.useState(new Array(void 0===a?5:a).fill("")),d=s[0],f=s[1],v=T().screens,p=A(),m=I({ignoreLocal:!0}),y=n.useRef(null);n.useImperativeHandle(r,(function(){return{getActiveSpeakerAudio:function(){var e,n;return null!=(e=null==(n=y.current)?void 0:n.querySelector('audio[data-session-id="'+m+'"][data-audio-type="audio"]'))?e:null},getAllAudio:function(){var e,n;return Array.from(null!=(e=null==(n=y.current)?void 0:n.querySelectorAll("audio"))?e:[])},getAudioBySessionId:function(e){var n,t;return null!=(n=null==(t=y.current)?void 0:t.querySelector('audio[data-session-id="'+e+'"][data-audio-type="audio"]'))?n:null},getScreenAudio:function(){var e,n;return Array.from(null!=(e=null==(n=y.current)?void 0:n.querySelectorAll('audio[data-audio-type="screenAudio"]'))?e:[])},getScreenAudioBySessionId:function(e){var n,t;return null!=(n=null==(t=y.current)?void 0:t.querySelector('audio[data-session-id="'+e+'"][data-audio-type="screenAudio"]'))?n:null}}}),[m]);var k=L({filter:n.useCallback((function(e){return!e.local&&Boolean(e.tracks.audio.subscribed)}),[])}),b=i.useRecoilCallback((function(e){var n=e.snapshot;return function(){var e=u((function*(e){if(k.includes(e)){var t=(yield n.getPromise(h)).filter((function(e){return k.includes(e.session_id)}));f((function(n){var i;if(n.includes(e))return n;var r=function(e){return!e||!k.includes(e)};if(n.some(r)){var a=n.findIndex(r);return n[a]=e,[].concat(n)}var o=n.findIndex((function(e){return t.some((function(n){return n.session_id===e&&["blocked","off"].includes(n.tracks.audio.state)}))}));if(o>=0)return n[o]=e,[].concat(n);var u=t.filter((function(e){return n.includes(e.session_id)&&e.session_id!==m})).sort((function(e,n){var t,i,r=null!=(t=null==e?void 0:e.last_active)?t:new Date("1970-01-01"),a=null!=(i=null==n?void 0:n.last_active)?i:new Date("1970-01-01");return r>a?1:r<a?-1:0}));if(!u.length){var c=n.findIndex((function(e){return e!==m}));return n[c]=e,[].concat(n)}var l=n.indexOf(null==(i=u[0])?void 0:i.session_id);return n[l]=e,[].concat(n)}))}}));return function(n){return e.apply(this,arguments)}}()}),[m,k]),S=n.useCallback((function(e){f((function(n){if(!n.includes(e))return n;var t=[].concat(n),i=t.indexOf(e);return t[i]="",t}))}),[]);g(["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===p)return;b(e.activeSpeaker.peerId);break;case"track-started":"audio"===e.track.kind&&e.participant&&!e.participant.local&&b(e.participant.session_id);break;case"participant-left":S(e.participant.session_id)}}))}),[b,p,S]));var R=n.useMemo((function(){return d.map((function(e,n){return t.createElement(M,{key:"speaker-slot-"+n,onPlayFailed:o,sessionId:e,type:"audio"})}))}),[o,d]),C=n.useMemo((function(){return v.filter((function(e){return!!l||!e.local})).map((function(e){return t.createElement(M,{key:e.screenId,onPlayFailed:o,sessionId:e.session_id,type:"screenAudio"})}))}),[o,l,v]);return t.createElement("div",{ref:y},R,C)})));j.displayName="DailyAudio";var O=n.forwardRef((function(e,i){var r=e.automirror,a=e.fit,o=void 0===a?"contain":a,u=e.mirror,s=e.onResize,d=e.playableStyle,f=void 0===d?{}:d,v=e.sessionId,p=e.style,m=void 0===p?{}:p,y=e.type,g=void 0===y?"video":y,k=l(e,["automirror","fit","mirror","onResize","playableStyle","sessionId","style","type"]),b=A()===v,h="screenVideo"===g,S=b&&!h,R=n.useRef(null),C=D(R,i),E=P(v,g),I=E.persistentTrack,w=S||h||!E.isOff,x=_(v,"tracks."+g+".subscribed"),L=n.useMemo((function(){if("boolean"==typeof u)return u;if(!r)return!1;if(!I)return S;var e=I.getSettings();return"facingMode"in e?S&&"user"===e.facingMode:S}),[r,S,u,I]);return n.useEffect((function(){var e=R.current;if(e){var n=function(){e.paused&&e.play()},t=function(){e.style.transform="scale(1)"},i=function(){e.style.transform="",setTimeout((function(){e.paused&&e.play()}),100)},r=function(){"hidden"!==document.visibilityState&&e.paused&&e.play()};return e.addEventListener("canplay",n),e.addEventListener("enterpictureinpicture",t),e.addEventListener("leavepictureinpicture",i),document.addEventListener("visibilitychange",r),function(){e.removeEventListener("canplay",n),e.removeEventListener("enterpictureinpicture",t),e.removeEventListener("leavepictureinpicture",i),document.removeEventListener("visibilitychange",r)}}}),[]),n.useEffect((function(){var e=R.current;if(e&&I)return e.srcObject=new MediaStream([I]),e.load(),function(){e.srcObject=null,e.load()}}),[I,null==I?void 0:I.id]),n.useEffect((function(){var e,n=R.current;if(s&&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=R.current;if(e&&!document.hidden){var n=e.videoWidth,t=e.videoHeight;n&&t&&(null==s||s({aspectRatio:n/t,height:t,width:n}))}}))}}),[s]),t.createElement("video",Object.assign({autoPlay:!0,muted:!0,playsInline:!0,ref:C,"data-local":b,"data-mirrored":L||void 0,"data-playable":w||void 0,"data-session-id":v,"data-subscribed":x,"data-video-type":g,style:c({objectFit:o,transform:L?"scale(-1, 1)":""},m,w?f:{})},k))}));O.displayName="DailyVideo";var V=n.createContext({refreshDevices:function(){return Promise.resolve()}}),F=i.atom({key:"daily-react-general-camera-state",default:"idle"}),B=i.atom({key:"daily-react-general-microphone-state",default:"idle"}),U=i.atom({key:"daily-react-camera-devices",default:[]}),N=i.atom({key:"daily-react-microphone-devices",default:[]}),q=i.atom({key:"daily-react-speaker-devices",default:[]}),W=i.atom({key:"daily-react-last-camera-error",default:null}),z=function(e){var r=e.children,a=f(),o=i.useRecoilCallback((function(e){var n=e.transact_UNSTABLE;return u((function*(){var e,t,i,r;if(void 0!==(null==(e=navigator)||null==(t=e.mediaDevices)?void 0:t.getUserMedia)&&void 0!==(null==(i=navigator)||null==(r=i.mediaDevices)?void 0:r.enumerateDevices)){if(a)try{var o=(yield a.enumerateDevices()).devices,u=o.filter((function(e){return"videoinput"===e.kind&&""!==e.deviceId})),c=o.filter((function(e){return"audioinput"===e.kind&&""!==e.deviceId})),l=o.filter((function(e){return"audiooutput"===e.kind&&""!==e.deviceId})),s=yield a.getInputDevices(),d=s.camera,f=s.mic,v=s.speaker,p=function(e,n,t){var i,r;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.state)?i:"granted"}},m=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((function(e){var n=e.set;n(U,(function(e){return u.filter(Boolean).map((function(n){return p(d,n,e)})).sort(m)})),n(N,(function(e){return c.filter(Boolean).map((function(n){return p(f,n,e)})).sort(m)})),n(q,(function(e){return l.filter(Boolean).map((function(n){return p(v,n,e)})).sort(m)}))}))}catch(e){n((function(e){var n=e.set;n(F,"not-supported"),n(B,"not-supported")}))}}else n((function(e){var n=e.set;n(F,"not-supported"),n(B,"not-supported")}))}))}),[a]),l=i.useRecoilCallback((function(e){var n=e.set,t=e.snapshot,i=e.transact_UNSTABLE;return u((function*(){var e,r,u,l,s,d,f,v,p,m,y,g,k,b;if(a){var h=yield t.getPromise(F),S=yield t.getPromise(B),R=a.participants();if(R.local){var C=R.local.tracks,A=["idle","pending"].includes(h)&&"interrupted"===C.video.state&&!C.video.persistentTrack,E=["idle","pending"].includes(h)&&!C.video.persistentTrack&&Boolean(null==(e=C.video.off)?void 0:e.byUser),I=["idle","pending"].includes(S)&&"interrupted"===C.audio.state&&!C.audio.persistentTrack,w=["idle","pending"].includes(S)&&!C.audio.persistentTrack&&Boolean(null==(r=C.audio.off)?void 0:r.byUser);(null==(u=C.audio)||null==(l=u.blocked)?void 0:l.byDeviceInUse)?i((function(e){var n=e.set;n(B,"in-use"),n(N,(function(e){return e.map((function(e){return e.selected?c({},e,{state:"in-use"}):e}))}))})):(null==(s=C.audio)||null==(d=s.blocked)?void 0:d.byDeviceMissing)?n(B,"not-found"):(null==(f=C.audio)||null==(v=f.blocked)?void 0:v.byPermissions)?n(B,"blocked"):I?n(B,"pending"):w?n(B,"idle"):i((function(e){var n=e.set;n(B,"granted"),n(N,(function(e){return e.map((function(e){return e.selected?c({},e,{state:"granted"}):e}))}))})),(null==(p=C.video)||null==(m=p.blocked)?void 0:m.byDeviceInUse)?i((function(e){var n=e.set;n(F,"in-use"),n(U,(function(e){return e.map((function(e){return e.selected?c({},e,{state:"in-use"}):e}))}))})):(null==(y=C.video)||null==(g=y.blocked)?void 0:g.byDeviceMissing)?n(F,"not-found"):(null==(k=C.video)||null==(b=k.blocked)?void 0:b.byPermissions)?n(F,"blocked"):A?n(F,"pending"):E?n(F,"idle"):i((function(e){var n=e.set;n(F,"granted"),n(U,(function(e){return e.map((function(e){return e.selected?c({},e,{state:"granted"}):e}))}))})),o()}}}))}),[a,o]);return y("participant-updated",n.useCallback((function(e){e.participant.local&&l()}),[l])),y("available-devices-updated",o),y("selected-devices-updated",o),y("camera-error",i.useRecoilCallback((function(e){var n=e.transact_UNSTABLE;return function(e){n((function(n){var t,i,r,a,o,u,c,l=n.set;switch(l(W,e.error),null==(t=e.error)?void 0:t.type){case"cam-in-use":l(F,"in-use");break;case"mic-in-use":l(B,"in-use");break;case"cam-mic-in-use":l(F,"in-use"),l(B,"in-use");break;case"not-found":(null==(i=e.error)?void 0:i.missingMedia.includes("video"))&&l(F,"not-found"),(null==(r=e.error)?void 0:r.missingMedia.includes("audio"))&&l(B,"not-found");break;case"permissions":(null==(a=e.error)?void 0:a.blockedMedia.includes("video"))&&l(F,"blocked"),(null==(o=e.error)?void 0:o.blockedMedia.includes("audio"))&&l(B,"blocked");break;case"constraints":"invalid"===(null==(u=e.error)?void 0:u.reason)?(l(F,"constraints-invalid"),l(B,"constraints-invalid")):"none-specified"===(null==(c=e.error)?void 0:c.reason)&&(l(F,"constraints-none-specified"),l(B,"constraints-none-specified"));break;case"undefined-mediadevices":l(F,"undefined-mediadevices"),l(B,"undefined-mediadevices");break;case"unknown":default:l(F,"unknown"),l(B,"unknown")}}))}}),[])),y("started-camera",i.useRecoilCallback((function(e){var n=e.transact_UNSTABLE;return function(){n((function(e){var n=e.set;n(F,"granted"),n(B,"granted")})),l()}}),[l])),t.createElement(V.Provider,{value:{refreshDevices:o}},r)},H=i.atom({key:"daily-react-live-streaming",default:{errorMsg:void 0,isLiveStreaming:!1,layout:void 0}}),G=function(e){var n=e.children;return y("live-streaming-started",i.useRecoilCallback((function(e){var n=e.set;return function(e){n(H,{isLiveStreaming:!0,layout:null==e?void 0:e.layout})}}),[])),y("live-streaming-stopped",i.useRecoilCallback((function(e){var n=e.set;return function(){n(H,(function(e){return c({},e,{isLiveStreaming:!1,layout:void 0})}))}}),[])),y("live-streaming-error",i.useRecoilCallback((function(e){var n=e.set;return function(e){n(H,(function(n){return c({},n,{errorMsg:e.errorMsg})}))}}),[])),t.createElement(t.Fragment,null,n)},Q=i.atom({key:"daily-react-recording",default:{isLocalParticipantRecorded:!1,isRecording:!1}}),J=function(e){var r=e.children,a=i.useSetRecoilState(Q),o=A(),u=L({filter:"record"});return n.useEffect((function(){var e=u.length>0,n=u.includes(null!=o?o:"local");a((function(t){return c({},t,{isLocalParticipantRecorded:"local"!==(null==t?void 0:t.type)&&(null==t?void 0:t.type)?t.isLocalParticipantRecorded:e,isRecording:"local"!==(null==t?void 0:t.type)&&(null==t?void 0:t.type)?t.isRecording:e,local:"local"!==(null==t?void 0:t.type)&&(null==t?void 0:t.type)||!e?null==t?void 0:t.local:n,type:e?"local":null==t?void 0:t.type})}))}),[o,u,a]),y("recording-started",i.useRecoilCallback((function(e){var n=e.set;return function(e){var t=!0;switch(e.type){case"cloud-beta":case"cloud":var i;o&&"single-participant"===(null==(i=e.layout)?void 0:i.preset)&&e.layout.session_id!==o&&(t=!1)}n(Q,{error:!1,isLocalParticipantRecorded:t,isRecording:!0,layout:null==e?void 0:e.layout,local:null==e?void 0:e.local,recordingId:null==e?void 0:e.recordingId,recordingStartedDate:new Date,startedBy:null==e?void 0:e.startedBy,type:null==e?void 0:e.type})}}),[o])),y("recording-stopped",i.useRecoilCallback((function(e){var n=e.set;return function(){n(Q,(function(e){return c({},e,{isLocalParticipantRecorded:!1,isRecording:!1})}))}}),[])),y("recording-error",i.useRecoilCallback((function(e){var n=e.set;return function(){n(Q,(function(e){return c({},e,{error:!0,isLocalParticipantRecorded:!1,isRecording:!1})}))}}),[])),t.createElement(t.Fragment,null,r)},$=i.atom({key:"daily-react-room",default:null}),K=function(e){var n=e.children,r=f(),a=i.useRecoilCallback((function(e){var n=e.set;return u((function*(){if(r&&"left-meeting"!==r.meetingState()){var e=yield r.room();return e&&"id"in e&&n($,e),e}}))}),[r]);return y("access-state-updated",a),t.createElement(t.Fragment,null,n)},X=function(e,t){var r=void 0===t?{}:t,a=r.onParticipantLeft,o=r.onParticipantUpdated,u=i.useRecoilValue(S(e));return g(["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])),u},Y="data:application/javascript;charset=utf8,"+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"),Z=i.atom({key:"daily-react-input-settings",default:null}),ee=i.atom({key:"daily-react-input-settings-error",default:null}),ne=i.atom({key:"daily-react-topology",default:"none"}),te=i.atom({key:"daily-react-networkQuality",default:100}),ie=i.atom({key:"daily-react-networkThreshold",default:"good"}),re=i.atomFamily({key:"daily-react-participant-receive-settings",default:{}}),ae=function(){return i.useRecoilValue($)},oe=i.atom({key:"daily-react-transcription",default:{isTranscriptionEnabled:!1,isTranscribing:!1,model:"general",language:"en",transcriptions:[]}}),ue=i.atom({key:"daily-react-waiting-participants",default:[]}),ce=i.atomFamily({key:"daily-react-waiting-participant",default:{awaitingAccess:{level:"full"},id:"",name:""}}),le=i.selector({key:"daily-react-waitingParticipantsSelector",get:function(e){var n=e.get;return n(ue).map((function(e){return n(ce(e))}))}});exports.DailyAudio=j,exports.DailyAudioTrack=M,exports.DailyProvider=function(e){var r=e.children,o=e.recoilRootProps,u=void 0===o?{}:o,c=l(e,["children","recoilRootProps"]),f=n.useState("callObject"in c?c.callObject:null),p=f[0],m=f[1],y=n.useRef({});n.useEffect((function(){var e;if("callObject"in c){var n=(null==p?void 0:p._callFrameId)!==(null==c||null==(e=c.callObject)?void 0:e._callFrameId);c.callObject?(n||!p&&c.callObject)&&m(c.callObject):m(null)}}),[p,c]);var g=n.useCallback((function(e){if("action"in e)for(var n,t=function(e,n){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(t)return(t=t.call(e)).next.bind(t);if(Array.isArray(e)||(t=function(e,n){if(e){if("string"==typeof e)return s(e,void 0);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?s(e,void 0):void 0}}(e))){t&&(e=t);var i=0;return function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(null!=(i=null==(r=y.current)||null==(a=r[e.action])?void 0:a.values())?i:[]);!(n=t()).done;){var i,r,a;(0,n.value)(e)}}),[]),k=n.useCallback((function(e){e&&Object.keys(y.current).forEach((function(n){e.off(n,g).on(n,g)}))}),[g]);n.useEffect((function(){if(!p){if("callObject"in c)return m(c.callObject),void k(c.callObject);var e=a.createCallObject(c);m(e),k(e)}}),[p,k,c]);var b=n.useCallback((function(e,n,t){var i,r;y.current[e]||(y.current[e]=new Map,p&&p.off(e,g).on(e,g)),(null==(i=y.current[e])?void 0:i.has(t))||null==(r=y.current[e])||r.set(t,n)}),[p,g]),h=n.useCallback((function(e,n){var t,i;null==(t=y.current[e])||t.delete(n),0===(null==(i=y.current[e])?void 0:i.size)&&(null==p||p.off(e,g),delete y.current[e])}),[p,g]);return t.createElement(i.RecoilRoot,Object.assign({},u),t.createElement(d.Provider,{value:p},t.createElement(v.Provider,{value:{on:b,off:h}},t.createElement(K,null,t.createElement(C,null,t.createElement(J,null,t.createElement(G,null,t.createElement(z,null,r))))))))},exports.DailyVideo=O,exports.useActiveParticipant=function(e){var t=void 0===e?{}:e,r=t.ignoreLocal,a=void 0!==r&&r,o=t.onActiveSpeakerChange,u=f(),c=i.useRecoilValue(k),l=n.useState(""),s=l[1],d=X(l[0]);return n.useEffect((function(){var e;if(u){var n=null==u||null==(e=u.participants())?void 0:e.local;a&&c===(null==n?void 0:n.session_id)||s(null!=c?c:"")}}),[u,a,c]),y("active-speaker-change",n.useCallback((function(e){null==o||o(e)}),[o])),d},exports.useActiveSpeakerId=I,exports.useAppMessage=function(e){var t=(void 0===e?{}:e).onAppMessage,i=f(),r=n.useCallback((function(e,n){void 0===n&&(n="*"),i&&i.sendAppMessage(e,n)}),[i]),a=n.useCallback((function(e){null==t||t(e,r)}),[t,r]);return y("app-message",a),r},exports.useAudioLevel=function(e,t){var i=n.useRef();n.useEffect((function(){if(e){var n="undefined"!=typeof AudioContext?AudioContext:void 0!==window.webkitAudioContext?window.webkitAudioContext:null;if(n){i.current||(i.current=new n);var r=i.current;if(r){var a,o=r.createMediaStreamSource(new MediaStream([e]));return function(){var e=u((function*(){try{a=new AudioWorkletNode(r,"audiolevel")}catch(e){try{yield r.audioWorklet.addModule(Y),a=new AudioWorkletNode(r,"audiolevel")}catch(e){console.error(e)}}if(a){a.port.onmessage=function(e){var n=0;e.data.volume&&(n=e.data.volume),a&&t(n)};try{o.connect(a).connect(r.destination)}catch(e){console.warn(e)}}}));return function(){return e.apply(this,arguments)}}()(),function(){var e;null==(e=a)||e.disconnect(),a=null,null==o||o.disconnect()}}}}}),[t,e])},exports.useAudioTrack=function(e){return P(e,"audio")},exports.useDaily=f,exports.useDailyEvent=y,exports.useDevices=function(){var e=f(),t=i.useRecoilValue(F),r=i.useRecoilValue(B),a=i.useRecoilValue(U),o=i.useRecoilValue(N),c=i.useRecoilValue(q),l=i.useRecoilValue(W),s=n.useContext(V).refreshDevices,d=n.useCallback(function(){var n=u((function*(n){yield null==e?void 0:e.setInputDevicesAsync({audioDeviceId:null,videoDeviceId:n})}));return function(e){return n.apply(this,arguments)}}(),[e]),v=n.useCallback(function(){var n=u((function*(n){yield null==e?void 0:e.setInputDevicesAsync({audioDeviceId:n,videoDeviceId:null})}));return function(e){return n.apply(this,arguments)}}(),[e]),p=n.useCallback(function(){var n=u((function*(n){yield null==e?void 0:e.setOutputDeviceAsync({outputDeviceId:n})}));return function(e){return n.apply(this,arguments)}}(),[e]),m=["blocked","in-use","not-found","constraints-invalid","constraints-none-specified","undefined-mediadevices","unknown"];return{cameraError:l,cameras:a,camState:t,hasCamError:m.includes(t),hasMicError:m.includes(r),microphones:o,micState:r,refreshDevices:s,setCamera:d,setMicrophone:v,setSpeaker:p,speakers:c}},exports.useInputSettings=function(e){var t=void 0===e?{}:e,r=t.onError,a=t.onInputSettingsUpdated,o=i.useRecoilValue(Z),u=i.useRecoilValue(ee),c=f(),l=i.useRecoilCallback((function(e){var n=e.set;return function(e){n(Z,e)}}),[]);return n.useEffect((function(){c&&c.getInputSettings().then(l)}),[c,l]),y("input-settings-updated",n.useCallback((function(e){l(e.inputSettings),null==a||a(e)}),[a,l])),y("nonfatal-error",i.useRecoilCallback((function(e){var n=e.set;return function(e){"input-settings-error"===e.type&&(n(ee,e.errorMsg),null==r||r(e))}}),[r])),{errorMsg:u,inputSettings:o,updateInputSettings:n.useCallback((function(e){null==c||c.updateInputSettings(e)}),[c])}},exports.useLiveStreaming=function(e){var t=void 0===e?{}:e,r=t.onLiveStreamingError,a=t.onLiveStreamingStarted,o=t.onLiveStreamingStopped,u=f(),l=i.useRecoilValue(H);return y("live-streaming-started",n.useCallback((function(e){null==a||a(e)}),[a])),y("live-streaming-stopped",n.useCallback((function(e){null==o||o(e)}),[o])),y("live-streaming-error",n.useCallback((function(e){null==r||r(e)}),[r])),c({},l,{startLiveStreaming:n.useCallback((function(e){u&&u.startLiveStreaming(e)}),[u]),stopLiveStreaming:n.useCallback((function(){u&&u.stopLiveStreaming()}),[u]),updateLiveStreaming:n.useCallback((function(e){u&&u.updateLiveStreaming({layout:e.layout})}),[u])})},exports.useLocalParticipant=function(){var e=i.useRecoilValue(b);return X(e)},exports.useLocalSessionId=A,exports.useMediaTrack=P,exports.useNetwork=function(e){var t=void 0===e?{}:e,r=t.onNetworkConnection,a=t.onNetworkQualityChange,o=f(),c=i.useRecoilValue(ne),l=i.useRecoilValue(te),s=i.useRecoilValue(ie),d=i.useRecoilCallback((function(e){var n=e.set;return u((function*(){if(o){var e=yield o.getNetworkTopology();e&&"none"!==(null==e?void 0:e.topology)&&n(ne,e.topology)}}))}),[o]),v=i.useRecoilCallback((function(e){var n=e.transact_UNSTABLE;return function(e){n((function(n){var t=n.set;switch(e.event){case"connected":"peer-to-peer"===e.type&&t(ne,"peer"),"sfu"===e.type&&t(ne,"sfu")}})),null==r||r(e)}}),[r]),p=i.useRecoilCallback((function(e){var n=e.transact_UNSTABLE;return function(e){n((function(n){var t=n.set;t(te,(function(n){return n!==e.quality?e.quality:n})),t(ie,(function(n){return n!==e.threshold?e.threshold:n}))})),null==a||a(e)}}),[a]);return y("joined-meeting",d),y("network-connection",v),y("network-quality-change",p),n.useEffect((function(){o&&!c&&d()}),[o,d,c]),{getStats:n.useCallback(u((function*(){var e=yield null==o?void 0:o.getNetworkStats();return null==e?void 0:e.stats})),[o]),quality:l,threshold:s,topology:c}},exports.useParticipant=X,exports.useParticipantIds=L,exports.useParticipantProperty=_,exports.useReceiveSettings=function(e){var t=void 0===e?{}:e,r=t.id,a=void 0===r?"base":r,o=t.onReceiveSettingsUpdated,u=i.useRecoilValue(re("base")),l=i.useRecoilValue(re(a)),s=f();y("receive-settings-updated",i.useRecoilCallback((function(e){var n=e.transact_UNSTABLE;return function(e){n((function(n){for(var t=n.reset,i=n.set,r=c({},e.receiveSettings),o=0,u=Object.entries(r);o<u.length;o++){var l=u[o],s=l[1];i(re(l[0]),s)}a in r||t(re(a))})),null==o||o(e)}}),[a,o]));var d=n.useCallback((function(e){s&&"joined-meeting"===s.meetingState()&&(null==s||null==s.updateReceiveSettings||s.updateReceiveSettings(e))}),[s]);return{receiveSettings:"base"===a||0===Object.keys(l).length?u:l,updateReceiveSettings:d}},exports.useRecording=function(e){var t=void 0===e?{}:e,r=t.onRecordingData,a=t.onRecordingError,o=t.onRecordingStarted,u=t.onRecordingStopped,l=f(),s=i.useRecoilValue(Q);return y("recording-started",n.useCallback((function(e){null==o||o(e)}),[o])),y("recording-stopped",n.useCallback((function(e){null==u||u(e)}),[u])),y("recording-error",n.useCallback((function(e){null==a||a(e)}),[a])),y("recording-data",n.useCallback((function(e){null==r||r(e)}),[r])),c({},s,{startRecording:n.useCallback((function(e){l&&l.startRecording(e)}),[l]),stopRecording:n.useCallback((function(){l&&l.stopRecording()}),[l]),updateRecording:n.useCallback((function(e){l&&l.updateRecording(e)}),[l])})},exports.useRoom=ae,exports.useScreenAudioTrack=function(e){return P(e,"screenAudio")},exports.useScreenShare=T,exports.useScreenVideoTrack=function(e){return P(e,"screenVideo")},exports.useThrottledDailyEvent=g,exports.useTranscription=function(e){var t,r=void 0===e?{}:e,a=r.onTranscriptionAppData,o=r.onTranscriptionError,u=r.onTranscriptionStarted,l=r.onTranscriptionStopped,s=f(),d=i.useRecoilValue(oe),v=i.useSetRecoilState(oe),p=ae();return n.useEffect((function(){var e;(null==p||null==(e=p.domainConfig)?void 0:e.enable_transcription)&&v((function(e){return c({},e,{isTranscriptionEnabled:!0})}))}),[null==p||null==(t=p.domainConfig)?void 0:t.enable_transcription,v]),y("transcription-started",i.useRecoilCallback((function(e){var n=e.set;return function(e){n(oe,c({isTranscriptionEnabled:!0,error:!1,isTranscribing:!0,transcriptionStartDate:new Date,transcriptions:[]},e)),null==u||u(e)}}),[u])),y("transcription-stopped",i.useRecoilCallback((function(e){var n=e.set;return function(e){n(oe,(function(n){return c({},n,{updatedBy:null==e?void 0:e.updatedBy,isTranscribing:!1})})),null==l||l(e)}}),[l])),y("transcription-error",i.useRecoilCallback((function(e){var n=e.set;return function(e){n(oe,(function(e){return c({},e,{error:!0,isTranscribing:!1})})),null==o||o(e)}}),[o])),y("app-message",i.useRecoilCallback((function(e){var n=e.set;return function(e){var t;"transcription"===(null==e?void 0:e.fromId)&&(null==e||null==(t=e.data)?void 0:t.is_final)&&(n(oe,(function(n){return c({},n,{isTranscribing:!0,transcriptions:[].concat(n.transcriptions,[e.data])})})),null==a||a(e))}}),[a])),c({},d,{startTranscription:n.useCallback((function(e){s&&s.startTranscription(e)}),[s]),stopTranscription:n.useCallback((function(){s&&s.stopTranscription()}),[s])})},exports.useVideoTrack=function(e){return P(e,"video")},exports.useWaitingParticipants=function(e){var t=void 0===e?{}:e,r=t.onWaitingParticipantAdded,a=t.onWaitingParticipantRemoved,o=t.onWaitingParticipantUpdated,u=f(),c=i.useRecoilValue(le),l=i.useRecoilCallback((function(e){var n=e.transact_UNSTABLE;return function(e){n((function(n){var t=n.set;t(ue,(function(n){return n.includes(e.participant.id)?n:[].concat(n,[e.participant.id])})),t(ce(e.participant.id),e.participant)})),null==r||r(e)}}),[r]),s=i.useRecoilCallback((function(e){var n=e.transact_UNSTABLE;return function(e){n((function(n){var t=n.reset;(0,n.set)(ue,(function(n){return n.filter((function(n){return n!==e.participant.id}))})),t(ce(e.participant.id))})),null==a||a(e)}}),[a]),d=i.useRecoilCallback((function(e){var n=e.set;return function(e){n(ce(e.participant.id),e.participant),null==o||o(e)}}),[o]);y("waiting-participant-added",l),y("waiting-participant-removed",s),y("waiting-participant-updated",d);var v=n.useCallback((function(e,n){"*"!==e?null==u||u.updateWaitingParticipant(e,{grantRequestedAccess:n}):null==u||u.updateWaitingParticipants({"*":{grantRequestedAccess:n}})}),[u]);return{waitingParticipants:c,grantAccess:n.useCallback((function(e){v(e,!0)}),[v]),denyAccess:n.useCallback((function(e){v(e,!1)}),[v])}};
//# sourceMappingURL=daily-react.cjs.production.min.js.map

@@ -14,42 +14,12 @@ import { DailyEventObjectNoPayload, DailyEventObjectRecordingData, DailyEventObjectRecordingStarted, DailyStreamingLayoutConfig, DailyStreamingOptions } from '@daily-co/daily-js';

}) => void;
/**
* Determines whether an error occurred during the last recording attempt.
*/
error?: boolean | undefined;
/**
* Determines whether the local participant is being recorded, based on the recording settings.
*/
isLocalParticipantRecorded: boolean;
/**
* Determines whether a recording is currently running or not.
*/
isRecording: boolean;
/**
* Contains the last applied cloud recording layout config.
*/
layout?: import("@daily-co/daily-js").DailyStreamingDefaultLayoutConfig | import("@daily-co/daily-js").DailyStreamingSingleParticipantLayoutConfig | import("@daily-co/daily-js").DailyStreamingActiveParticipantLayoutConfig | import("@daily-co/daily-js").DailyStreamingPortraitLayoutConfig | import("@daily-co/daily-js").DailyStreamingCustomLayoutConfig | undefined;
/**
* Determines whether the recording is running locally.
* See [enable_recording](https://docs.daily.co/reference/rest-api/rooms/config#enable_recording).
*/
local?: boolean | undefined;
/**
* Contains the recording id.
*/
recordingId?: string | undefined;
/**
* Contains the date when the 'recording-started' event was received.
* This doesn't necessarily match the date the recording was actually started.
*/
recordingStartedDate?: Date | undefined;
/**
* Contains the session_id of the participant who started the recording.
*/
startedBy?: string | undefined;
/**
* Contains the recording type.
* See [enable_recording](https://docs.daily.co/reference/rest-api/rooms/config#enable_recording).
*/
type?: string | undefined;
};
export {};
{
"version": "0.7.1",
"version": "0.7.2",
"license": "BSD-2-Clause",

@@ -4,0 +4,0 @@ "keywords": [

@@ -9,5 +9,5 @@ import {

import { useCallback } from 'react';
import { atom, useRecoilCallback, useRecoilValue } from 'recoil';
import { useRecoilValue } from 'recoil';
import { RECOIL_PREFIX } from '../lib/constants';
import { liveStreamingState } from '../DailyLiveStreaming';
import { useDaily } from './useDaily';

@@ -22,17 +22,2 @@ import { useDailyEvent } from './useDailyEvent';

interface LiveStreamingState {
errorMsg?: string;
isLiveStreaming: boolean;
layout?: DailyStreamingLayoutConfig;
}
const liveStreamingState = atom<LiveStreamingState>({
key: RECOIL_PREFIX + 'live-streaming',
default: {
errorMsg: undefined,
isLiveStreaming: false,
layout: undefined,
},
});
/**

@@ -54,11 +39,6 @@ * This hook allows to setup [live streaming events](https://docs.daily.co/reference/daily-js/events/live-streaming-events),

'live-streaming-started',
useRecoilCallback(
({ set }) =>
(ev: DailyEventObjectLiveStreamingStarted) => {
set(liveStreamingState, {
isLiveStreaming: true,
layout: ev?.layout,
});
onLiveStreamingStarted?.(ev);
},
useCallback(
(ev: DailyEventObjectLiveStreamingStarted) => {
onLiveStreamingStarted?.(ev);
},
[onLiveStreamingStarted]

@@ -70,12 +50,6 @@ )

'live-streaming-stopped',
useRecoilCallback(
({ set }) =>
(ev: DailyEventObjectLiveStreamingStopped) => {
set(liveStreamingState, (prevState) => ({
...prevState,
isLiveStreaming: false,
layout: undefined,
}));
onLiveStreamingStopped?.(ev);
},
useCallback(
(ev: DailyEventObjectLiveStreamingStopped) => {
onLiveStreamingStopped?.(ev);
},
[onLiveStreamingStopped]

@@ -87,11 +61,6 @@ )

'live-streaming-error',
useRecoilCallback(
({ set }) =>
(ev: DailyEventObjectLiveStreamingError) => {
set(liveStreamingState, (prevState) => ({
...prevState,
errorMsg: ev.errorMsg,
}));
onLiveStreamingError?.(ev);
},
useCallback(
(ev: DailyEventObjectLiveStreamingError) => {
onLiveStreamingError?.(ev);
},
[onLiveStreamingError]

@@ -98,0 +67,0 @@ )

@@ -8,15 +8,8 @@ import {

} from '@daily-co/daily-js';
import { useCallback, useEffect } from 'react';
import {
atom,
useRecoilCallback,
useRecoilValue,
useSetRecoilState,
} from 'recoil';
import { useCallback } from 'react';
import { useRecoilValue } from 'recoil';
import { RECOIL_PREFIX } from '../lib/constants';
import { recordingState } from '../DailyRecordings';
import { useDaily } from './useDaily';
import { useDailyEvent } from './useDailyEvent';
import { useLocalSessionId } from './useLocalSessionId';
import { useParticipantIds } from './useParticipantIds';

@@ -30,52 +23,2 @@ interface UseRecordingArgs {

interface RecordingState {
/**
* Determines whether an error occurred during the last recording attempt.
*/
error?: boolean;
/**
* Determines whether the local participant is being recorded, based on the recording settings.
*/
isLocalParticipantRecorded: boolean;
/**
* Determines whether a recording is currently running or not.
*/
isRecording: boolean;
/**
* Contains the last applied cloud recording layout config.
*/
layout?: DailyStreamingLayoutConfig;
/**
* Determines whether the recording is running locally.
* See [enable_recording](https://docs.daily.co/reference/rest-api/rooms/config#enable_recording).
*/
local?: boolean;
/**
* Contains the recording id.
*/
recordingId?: string;
/**
* Contains the date when the 'recording-started' event was received.
* This doesn't necessarily match the date the recording was actually started.
*/
recordingStartedDate?: Date;
/**
* Contains the session_id of the participant who started the recording.
*/
startedBy?: string;
/**
* Contains the recording type.
* See [enable_recording](https://docs.daily.co/reference/rest-api/rooms/config#enable_recording).
*/
type?: string;
}
const recordingState = atom<RecordingState>({
key: RECOIL_PREFIX + 'recording',
default: {
isLocalParticipantRecorded: false,
isRecording: false,
},
});
export const useRecording = ({

@@ -89,73 +32,10 @@ onRecordingData,

const state = useRecoilValue(recordingState);
const setState = useSetRecoilState(recordingState);
const localSessionId = useLocalSessionId();
const recordingParticipantIds = useParticipantIds({
filter: 'record',
});
/**
* Update recording state, whenever amount of recording participants changes.
*/
useEffect(() => {
const hasRecordingParticipants = recordingParticipantIds.length > 0;
const isLocalParticipantRecording = recordingParticipantIds.includes(
localSessionId ?? 'local'
);
setState((s) => ({
...s,
// In case type is local or not set, determine based on recording participants
isLocalParticipantRecorded:
s?.type === 'local' || !s?.type
? hasRecordingParticipants
: s.isLocalParticipantRecorded,
isRecording:
s?.type === 'local' || !s?.type
? hasRecordingParticipants
: s.isRecording,
local:
(s?.type === 'local' || !s?.type) && hasRecordingParticipants
? isLocalParticipantRecording
: s?.local,
/**
* Set type in case recording participants are detected.
* We only set `record` on participants, when recording type is 'local'.
*/
type: hasRecordingParticipants ? 'local' : s?.type,
}));
}, [localSessionId, recordingParticipantIds, setState]);
useDailyEvent(
'recording-started',
useRecoilCallback(
({ set }) =>
(ev: DailyEventObjectRecordingStarted) => {
let isLocalParticipantRecorded = true;
switch (ev.type) {
case 'cloud-beta':
case 'cloud': {
if (
localSessionId &&
ev.layout?.preset === 'single-participant' &&
ev.layout.session_id !== localSessionId
) {
isLocalParticipantRecorded = false;
}
break;
}
}
set(recordingState, {
error: false,
isLocalParticipantRecorded,
isRecording: true,
layout: ev?.layout,
local: ev?.local,
recordingId: ev?.recordingId,
recordingStartedDate: new Date(),
startedBy: ev?.startedBy,
type: ev?.type,
});
onRecordingStarted?.(ev);
},
[localSessionId, onRecordingStarted]
useCallback(
(ev: DailyEventObjectRecordingStarted) => {
onRecordingStarted?.(ev);
},
[onRecordingStarted]
)

@@ -165,12 +45,6 @@ );

'recording-stopped',
useRecoilCallback(
({ set }) =>
(ev: DailyEventObjectNoPayload) => {
set(recordingState, (prevState) => ({
...prevState,
isLocalParticipantRecorded: false,
isRecording: false,
}));
onRecordingStopped?.(ev);
},
useCallback(
(ev: DailyEventObjectNoPayload) => {
onRecordingStopped?.(ev);
},
[onRecordingStopped]

@@ -181,13 +55,6 @@ )

'recording-error',
useRecoilCallback(
({ set }) =>
(ev: DailyEventObjectNoPayload) => {
set(recordingState, (prevState) => ({
...prevState,
error: true,
isLocalParticipantRecorded: false,
isRecording: false,
}));
onRecordingError?.(ev);
},
useCallback(
(ev: DailyEventObjectNoPayload) => {
onRecordingError?.(ev);
},
[onRecordingError]

@@ -194,0 +61,0 @@ )

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc