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

@daily-co/daily-react-hooks

Package Overview
Dependencies
Maintainers
26
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

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

Comparing version 0.3.0 to 0.4.0

dist/DailyDevices.d.ts

2

dist/daily-react-hooks.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 t=e(require("@daily-co/daily-js")),n=require("react"),i=e(n),r=require("recoil"),a=e(require("lodash.throttle"));function u(e,t,n,i,r,a,u){try{var o=e[a](u),c=o.value}catch(e){return void n(e)}o.done?t(c):Promise.resolve(c).then(i,r)}function o(e){return function(){var t=this,n=arguments;return new Promise((function(i,r){var a=e.apply(t,n);function o(e){u(a,i,r,o,c,"next",e)}function c(e){u(a,i,r,o,c,"throw",e)}o(void 0)}))}}function c(){return(c=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e}).apply(this,arguments)}function l(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,i=new Array(t);n<t;n++)i[n]=e[n];return i}var s=n.createContext(null),d=n.createContext({on:function(){},off:function(){}}),f=function(){return n.useContext(s)},v=0,p=function(){return v++},g=function(e,t){var i=n.useContext(d),r=i.off,a=i.on,u=n.useState(!1),o=u[0],c=u[1],l=n.useRef(0),s=n.useMemo((function(){return p()}),[]);n.useEffect((function(){if(e&&!o){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,o,r,a])},m=function(e,t,i){void 0===i&&(i=100);var r=n.useContext(d),u=r.off,o=r.on,c=n.useMemo((function(){return p()}),[]),l=n.useRef([]),s=n.useMemo((function(){return a((function(){0!==l.current.length&&(t(l.current),l.current=[])}),i,{trailing:!0})}),[t,i]);n.useEffect((function(){if(e)return o(e,(function(e){l.current.push(e),setTimeout(s,0)}),c),function(){u(e,c)}}),[s,e,c,u,o])},k=r.atom({key:"local-id",default:""}),b=r.atom({key:"participants-objects",default:[]}),y=r.selectorFamily({key:"participant",get:function(e){return function(t){var n;return null!=(n=(0,t.get)(b).find((function(t){return t.session_id===e})))?n:null}}}),h=r.selectorFamily({key:"participant-property",get:function(e){var t=e.id,n=e.property;return function(e){var i,r=null!=(i=(0,e.get)(b).find((function(e){return e.session_id===t})))?i:null;return r?function(e,t){return t.split(".").reduce((function(e,t){return null==e?void 0:e[t]}),e)}(r,n):null}}}),R=function(e){var t=e.children,a=f();g("active-speaker-change",r.useRecoilCallback((function(e){var t=e.set,n=e.snapshot;return function(){var e=o((function*(e){var i=e.activeSpeaker.peerId,r=yield n.getPromise(y(i));!r&&a&&(r=a.participants()[i]),r&&t(b,(function(e){return[].concat(e).map((function(e){return e.session_id===i?c({},e,{last_active:new Date}):e}))}))}));return function(t){return e.apply(this,arguments)}}()}),[a]));var u=r.useRecoilCallback((function(e){var t=e.set;return function(){var e=o((function*(e){t(k,e.local.session_id),t(b,Object.values(e))}));return function(t){return e.apply(this,arguments)}}()}),[]);n.useEffect((function(){if(a){var e=setInterval((function(){var t=a.participants();"local"in t&&(u(t),clearInterval(e))}),100);return function(){clearInterval(e)}}}),[a,u]);var l=n.useCallback((function(){if(a){var e=null==a?void 0:a.participants();e.local&&u(e)}}),[a,u]);return g("started-camera",l),g("access-state-updated",l),g("joining-meeting",l),g("joined-meeting",n.useCallback((function(e){u(e.participants)}),[u])),m("participant-joined",r.useRecoilCallback((function(e){var t=e.set;return function(){var e=o((function*(e){e.length&&t(b,(function(t){return[].concat(t,e.map((function(e){return e.participant}))).filter((function(e,t,n){return n.findIndex((function(t){return t.session_id===e.session_id}))==t}))}))}));return function(t){return e.apply(this,arguments)}}()}),[])),m("participant-updated",r.useRecoilCallback((function(e){var t=e.transact_UNSTABLE;return function(e){t((function(t){var n=t.set;e.forEach((function(e){var t=e.participant;n(b,(function(e){return[].concat(e).map((function(e){return e.session_id===t.session_id?t:e}))}))}))}))}}),[])),m("participant-left",r.useRecoilCallback((function(e){var t=e.set;return function(e){t(b,(function(t){return[].concat(t).filter((function(t){return!e.some((function(e){return e.participant.session_id===t.session_id}))}))}))}}),[])),g("left-meeting",r.useRecoilCallback((function(e){var t=e.reset;return function(){t(k),t(b)}}),[])),i.createElement(i.Fragment,null,t)},S=r.atom({key:"room",default:null}),C=function(e){var t=e.children,n=f(),a=r.useRecoilCallback((function(e){var t=e.set;return o((function*(){if(n&&"left-meeting"!==n.meetingState()){var e=yield n.room();return e&&"id"in e&&t(S,e),e}}))}),[n]);return g("access-state-updated",a),i.createElement(i.Fragment,null,t)},T=function(e,t){var i=void 0===t?{}:t,a=i.onParticipantLeft,u=i.onParticipantUpdated,o=r.useRecoilValue(y(e));return m("participant-updated",n.useCallback((function(t){var n=t.filter((function(t){return t.participant.session_id===e}));n.length&&n.forEach((function(e){setTimeout((function(){return null==u?void 0:u(e)}),0)}))}),[u,e])),m("participant-left",n.useCallback((function(t){if(t.filter((function(t){return t.participant.session_id===e})).length){var n=t[t.length-1];setTimeout((function(){return null==a?void 0:a(n)}),0)}}),[a,e])),o},E=r.atom({key:"active-id",default:""}),I=r.atomFamily({key:"media-track",default:{state:"loading",subscribed:!1}}),_=function(e,t){void 0===t&&(t="video");var i=f(),a=n.useMemo((function(){return e+"-"+t}),[e,t]),u=r.useRecoilValue(I(a)),o=r.useRecoilCallback((function(n){var i=n.transact_UNSTABLE;return function(n){var r=n.filter((function(t){return t.participant.session_id===e}));r.length&&i((function(e){var n=e.reset,i=e.set;r.forEach((function(e){switch(e.action){case"participant-joined":case"participant-updated":i(I(a),e.participant.tracks[t]);break;case"participant-left":n(I(a))}}))}))}}),[a,e,t]);m("participant-joined",o),m("participant-updated",o),m("participant-left",o),g("joined-meeting",r.useRecoilCallback((function(e){var n=e.set;return function(e){n(I(a),e.participants.local.tracks[t])}}),[a,t]));var l=r.useRecoilCallback((function(e){var t=e.set;return function(e){e&&t(I(a),e)}}),[a]);return n.useEffect((function(){var n,r;if(i){var a=null==i?void 0:i.participants();if(a){var u=Object.values(a).find((function(t){return t.session_id===e}));u&&l(null!=(n=null==(r=u.tracks)?void 0:r[t])?n:null)}}}),[i,e,l,t]),u?c({},u,{isOff:"blocked"===u.state||"off"===u.state}):{isOff:!0,persistentTrack:void 0,state:"off",subscribed:!1}},w=r.atom({key:"general-camera-state",default:"pending"}),A=r.atom({key:"general-microphone-state",default:"pending"}),L=r.atom({key:"camera-devices",default:[]}),P=r.atom({key:"microphone-devices",default:[]}),j=r.atom({key:"speaker-devices",default:[]}),x=r.atom({key:"input-settings",default:null}),O=r.atom({key:"input-settings-error",default:null}),D=r.atom({key:"live-streaming",default:{errorMsg:void 0,isLiveStreaming:!1,layout:void 0}}),V=function(){return r.useRecoilValue(k)||null},M=r.atom({key:"topology",default:"peer"}),U=r.atom({key:"networkQuality",default:100}),B=r.atom({key:"networkThreshold",default:"good"}),N=Boolean,q=function(){return 0},F=function(e){var t=void 0===e?{filter:N,sort:q}:e,i=t.filter,a=void 0===i?N:i,u=t.onActiveSpeakerChange,c=t.onParticipantJoined,l=t.onParticipantLeft,s=t.onParticipantUpdated,d=t.sort,f=void 0===d?q:d,v=r.useRecoilValue(b),p=n.useMemo((function(){var e,t=N;switch(a){case"local":t=function(e){return e.local};break;case"owner":t=function(e){return e.owner};break;case"record":t=function(e){return e.record};break;case"remote":t=function(e){return!e.local};break;case"screen":t=function(e){return e.screen};break;default:t=a}switch(f){case"joined_at":case"session_id":case"user_id":case"user_name":e=function(e,t){return e[f]<t[f]?-1:e[f]>t[f]?1:0};break;default:e=f}return v.filter(t).sort(e).map((function(e){return e.session_id})).filter(Boolean)}),[v,a,f]);return m("participant-joined",n.useCallback((function(e){e.length&&e.forEach((function(e){return setTimeout((function(){return null==c?void 0:c(e)}),0)}))}),[c])),m("participant-updated",n.useCallback((function(e){e.length&&e.forEach((function(e){return setTimeout((function(){return null==s?void 0:s(e)}),0)}))}),[s])),m("active-speaker-change",n.useCallback(function(){var e=o((function*(e){e.length&&e.forEach((function(e){return setTimeout((function(){return null==u?void 0:u(e)}),0)}))}));return function(t){return e.apply(this,arguments)}}(),[u])),m("participant-left",n.useCallback((function(e){e.length&&e.forEach((function(e){return setTimeout((function(){return null==l?void 0:l(e)}),0)}))}),[l])),p},W=r.atomFamily({key:"participant-receive-settings",default:{}}),z=r.atom({key:"recording",default:{isLocalParticipantRecorded:!1,isRecording:!1}}),Q=r.atom({key:"waiting-participants",default:[]}),J=r.atomFamily({key:"waiting-participant",default:{awaitingAccess:{level:"full"},id:"",name:""}}),$=r.selector({key:"waitingParticipantsSelector",get:function(e){var t=e.get;return t(Q).map((function(e){return t(J(e))}))}});exports.DailyProvider=function(e){var a=e.children,u=function(e,t){if(null==e)return{};var n,i,r={},a=Object.keys(e);for(i=0;i<a.length;i++)t.indexOf(n=a[i])>=0||(r[n]=e[n]);return r}(e,["children"]),o=n.useState("callObject"in u?u.callObject:null),c=o[0],f=o[1],v=n.useRef({});n.useEffect((function(){var e;"callObject"in u&&c&&u.callObject&&(null==c?void 0:c._callFrameId)!==(null==u||null==(e=u.callObject)?void 0:e._callFrameId)&&f(u.callObject)}),[c,u]);var p=n.useCallback((function(e){if("action"in e)for(var t,n=function(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return l(e,void 0);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?l(e,void 0):void 0}}(e))){n&&(e=n);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=v.current)||null==(a=r[e.action])?void 0:a.values())?i:[]);!(t=n()).done;){var i,r,a;(0,t.value)(e)}}),[]),g=n.useCallback((function(e){e&&Object.keys(v.current).forEach((function(t){e.off(t,p).on(t,p)}))}),[p]);n.useEffect((function(){if(!c){if("callObject"in u)return f(u.callObject),void g(u.callObject);var e=t.createCallObject(u);f(e),g(e)}}),[c,g,u]);var m=n.useCallback((function(e,t,n){var i,r;v.current[e]||(v.current[e]=new Map,c&&c.off(e,p).on(e,p)),(null==(i=v.current[e])?void 0:i.has(n))||null==(r=v.current[e])||r.set(n,t)}),[c,p]),k=n.useCallback((function(e,t){var n,i;null==(n=v.current[e])||n.delete(t),0===(null==(i=v.current[e])?void 0:i.size)&&(null==c||c.off(e,p),delete v.current[e])}),[c,p]);return i.createElement(r.RecoilRoot,null,i.createElement(s.Provider,{value:c},i.createElement(d.Provider,{value:{on:m,off:k}},i.createElement(C,null,i.createElement(R,null,a)))))},exports.useActiveParticipant=function(e){var t=void 0===e?{}:e,i=t.ignoreLocal,a=void 0!==i&&i,u=t.onActiveSpeakerChange,o=f(),c=r.useRecoilValue(E),l=n.useState(""),s=l[1],d=T(l[0]);return n.useEffect((function(){var e;if(o){var t=null==o||null==(e=o.participants())?void 0:e.local;a&&c===(null==t?void 0:t.session_id)||s(c)}}),[o,a,c]),g("active-speaker-change",r.useRecoilCallback((function(e){var t=e.set;return function(e){t(E,e.activeSpeaker.peerId),setTimeout((function(){return null==u?void 0:u(e)}),0)}}),[u])),d},exports.useAppMessage=function(e){var t=(void 0===e?{}:e).onAppMessage,i=f(),r=n.useCallback((function(e,t){void 0===t&&(t="*"),i&&i.sendAppMessage(e,t)}),[i]),a=n.useCallback((function(e){null==t||t(e,r)}),[t,r]);return g("app-message",a),r},exports.useAudioTrack=function(e){return _(e,"audio")},exports.useDaily=f,exports.useDailyEvent=g,exports.useDevices=function(){var e=f(),t=r.useRecoilValue(w),i=r.useRecoilValue(A),a=r.useRecoilValue(L),u=r.useRecoilValue(P),l=r.useRecoilValue(j),s=r.useRecoilCallback((function(t){var n=t.transact_UNSTABLE;return o((function*(){var t,i,r,a;if(void 0!==(null==(t=navigator)||null==(i=t.mediaDevices)?void 0:i.getUserMedia)&&void 0!==(null==(r=navigator)||null==(a=r.mediaDevices)?void 0:a.enumerateDevices)){if(e)try{var u=(yield e.enumerateDevices()).devices,o=u.filter((function(e){return"videoinput"===e.kind&&""!==e.deviceId})),c=u.filter((function(e){return"audioinput"===e.kind&&""!==e.deviceId})),l=u.filter((function(e){return"audiooutput"===e.kind&&""!==e.deviceId})),s=yield e.getInputDevices(),d=s.camera,f=s.mic,v=s.speaker,p=function(e,t,n){var i,r;return{device:t,selected:"deviceId"in e&&t.deviceId===e.deviceId,state:null!=(i=null==(r=n.find((function(e){return e.device.deviceId===t.deviceId})))?void 0:r.state)?i:"granted"}},g=function(e,t){return"default"===e.device.deviceId?-1:"default"===t.device.deviceId?1:e.device.label<t.device.label?-1:e.device.label>t.device.label?1:0};n((function(e){var t=e.set;t(L,(function(e){return o.filter(Boolean).map((function(t){return p(d,t,e)})).sort(g)})),t(P,(function(e){return c.filter(Boolean).map((function(t){return p(f,t,e)})).sort(g)})),t(j,(function(e){return l.filter(Boolean).map((function(t){return p(v,t,e)})).sort(g)}))}))}catch(e){n((function(e){var t=e.set;t(w,"not-supported"),t(A,"not-supported")}))}}else n((function(e){var t=e.set;t(w,"not-supported"),t(A,"not-supported")}))}))}),[e]),d=r.useRecoilCallback((function(t){var n=t.set,i=t.snapshot,r=t.transact_UNSTABLE;return o((function*(){var t,a,u,o,l,d,f,v,p,g,m,k;if(e){var b=yield i.getPromise(w),y=yield i.getPromise(A),h=e.participants().local.tracks,R="pending"===b&&"interrupted"===h.video.state,S="pending"===y&&"interrupted"===h.audio.state;(null==(t=h.audio)||null==(a=t.blocked)?void 0:a.byDeviceInUse)?r((function(e){var t=e.set;t(A,"in-use"),t(P,(function(e){return e.map((function(e){return e.selected?c({},e,{state:"in-use"}):e}))}))})):(null==(u=h.audio)||null==(o=u.blocked)?void 0:o.byDeviceMissing)?n(A,"not-found"):(null==(l=h.audio)||null==(d=l.blocked)?void 0:d.byPermissions)?n(A,"blocked"):S||r((function(e){var t=e.set;t(A,"granted"),t(P,(function(e){return e.map((function(e){return e.selected?c({},e,{state:"granted"}):e}))}))})),(null==(f=h.video)||null==(v=f.blocked)?void 0:v.byDeviceInUse)?r((function(e){var t=e.set;t(w,"in-use"),t(L,(function(e){return e.map((function(e){return e.selected?c({},e,{state:"in-use"}):e}))}))})):(null==(p=h.video)||null==(g=p.blocked)?void 0:g.byDeviceMissing)?n(w,"not-found"):(null==(m=h.video)||null==(k=m.blocked)?void 0:k.byPermissions)?n(w,"blocked"):R||r((function(e){var t=e.set;t(w,"granted"),t(L,(function(e){return e.map((function(e){return e.selected?c({},e,{state:"granted"}):e}))}))})),s()}}))}),[e,s]);g("participant-updated",n.useCallback((function(e){e.participant.local&&d()}),[d])),g("available-devices-updated",s),g("camera-error",r.useRecoilCallback((function(e){var t=e.set,n=e.transact_UNSTABLE;return function(e){var i=e.error,r=e.errorMsg,a=r.audioOk,u=r.errorMsg,o=r.videoOk;switch(null==i?void 0:i.type){case"cam-in-use":t(w,"in-use");break;case"mic-in-use":t(A,"in-use");break;case"cam-mic-in-use":n((function(e){var t=e.set;t(w,"in-use"),t(A,"in-use")}));break;default:switch(u){case"devices error":n((function(e){var t=e.set;o||t(w,"not-found"),a||t(A,"not-found")}));break;case"not allowed":n((function(e){var t=e.set;t(w,"blocked"),t(A,"blocked")})),d()}}}}),[d])),g("error",r.useRecoilCallback((function(e){var t=e.transact_UNSTABLE;return function(e){switch(e.errorMsg){case"not allowed":t((function(e){var t=e.set;t(w,"blocked"),t(A,"blocked")})),d()}}}),[d])),g("started-camera",r.useRecoilCallback((function(e){var t=e.transact_UNSTABLE;return function(){t((function(e){var t=e.set;t(w,"granted"),t(A,"granted")})),d()}}),[d]));var v=n.useCallback(function(){var t=o((function*(t){yield null==e?void 0:e.setInputDevicesAsync({audioDeviceId:null,videoDeviceId:t}),s()}));return function(e){return t.apply(this,arguments)}}(),[e,s]),p=n.useCallback(function(){var t=o((function*(t){yield null==e?void 0:e.setInputDevicesAsync({audioDeviceId:t,videoDeviceId:null}),s()}));return function(e){return t.apply(this,arguments)}}(),[e,s]),m=n.useCallback(function(){var t=o((function*(t){yield null==e?void 0:e.setOutputDeviceAsync({outputDeviceId:t}),s()}));return function(e){return t.apply(this,arguments)}}(),[e,s]);return{cameras:a,camState:t,hasCamError:["blocked","in-use","not-found"].includes(t),hasMicError:["blocked","in-use","not-found"].includes(i),microphones:u,micState:i,refreshDevices:s,setCamera:v,setMicrophone:p,setSpeaker:m,speakers:l}},exports.useInputSettings=function(e){var t=void 0===e?{}:e,i=t.onError,a=t.onInputSettingsUpdated,u=r.useRecoilValue(x),o=r.useRecoilValue(O),c=f(),l=r.useRecoilCallback((function(e){var t=e.set;return function(e){t(x,e)}}),[]);return n.useEffect((function(){c&&c.getInputSettings().then(l)}),[c,l]),g("input-settings-updated",n.useCallback((function(e){l(e.inputSettings),setTimeout((function(){return null==a?void 0:a(e)}),0)}),[a,l])),g("nonfatal-error",r.useRecoilCallback((function(e){var t=e.set;return function(e){"input-settings-error"===e.type&&(t(O,e.errorMsg),setTimeout((function(){return null==i?void 0:i(e)}),0))}}),[i])),{errorMsg:o,inputSettings:u,updateInputSettings:n.useCallback((function(e){null==c||c.updateInputSettings(e)}),[c])}},exports.useLiveStreaming=function(e){var t=void 0===e?{}:e,i=t.onLiveStreamingError,a=t.onLiveStreamingStarted,u=t.onLiveStreamingStopped,o=f(),l=r.useRecoilValue(D);return g("live-streaming-started",r.useRecoilCallback((function(e){var t=e.set;return function(e){t(D,{isLiveStreaming:!0,layout:null==e?void 0:e.layout}),setTimeout((function(){return null==a?void 0:a(e)}),0)}}),[a])),g("live-streaming-stopped",r.useRecoilCallback((function(e){var t=e.set;return function(e){t(D,(function(e){return c({},e,{isLiveStreaming:!1,layout:void 0})})),setTimeout((function(){return null==u?void 0:u(e)}),0)}}),[u])),g("live-streaming-error",r.useRecoilCallback((function(e){var t=e.set;return function(e){t(D,(function(t){return c({},t,{errorMsg:e.errorMsg})})),setTimeout((function(){return null==i?void 0:i(e)}),0)}}),[i])),c({},l,{startLiveStreaming:n.useCallback((function(e){o&&o.startLiveStreaming(e)}),[o]),stopLiveStreaming:n.useCallback((function(){o&&o.stopLiveStreaming()}),[o]),updateLiveStreaming:n.useCallback((function(e){o&&o.updateLiveStreaming({layout:e.layout})}),[o])})},exports.useLocalParticipant=function(){var e=r.useRecoilValue(k);return T(e)},exports.useLocalSessionId=V,exports.useMediaTrack=_,exports.useNetwork=function(e){var t=void 0===e?{}:e,i=t.onNetworkConnection,a=t.onNetworkQualityChange,u=f(),c=r.useRecoilValue(M),l=r.useRecoilValue(U),s=r.useRecoilValue(B),d=r.useRecoilCallback((function(e){var t=e.transact_UNSTABLE;return function(e){t((function(t){var n=t.set;switch(e.event){case"connected":"peer-to-peer"===e.type&&n(M,"peer"),"sfu"===e.type&&n(M,"sfu")}})),setTimeout((function(){return null==i?void 0:i(e)}),0)}}),[i]),v=r.useRecoilCallback((function(e){var t=e.transact_UNSTABLE;return function(e){t((function(t){var n=t.set;n(U,(function(t){return t!==e.quality?e.quality:t})),n(B,(function(t){return t!==e.threshold?e.threshold:t}))})),setTimeout((function(){return null==a?void 0:a(e)}),0)}}),[a]);return g("network-connection",d),g("network-quality-change",v),{getStats:n.useCallback(o((function*(){var e=yield null==u?void 0:u.getNetworkStats();return null==e?void 0:e.stats})),[u]),quality:l,threshold:s,topology:c}},exports.useParticipant=T,exports.useParticipantIds=F,exports.useParticipantProperty=function(e,t){return r.useRecoilValue(h({id:e,property:t}))},exports.useReceiveSettings=function(e){var t=void 0===e?{}:e,i=t.id,a=void 0===i?"base":i,u=t.onReceiveSettingsUpdated,o=r.useRecoilValue(W("base")),l=r.useRecoilValue(W(a)),s=f();g("receive-settings-updated",r.useRecoilCallback((function(e){var t=e.transact_UNSTABLE;return function(e){t((function(t){for(var n=t.reset,i=t.set,r=c({},e.receiveSettings),u=0,o=Object.entries(r);u<o.length;u++){var l=o[u],s=l[1];i(W(l[0]),s)}a in r||n(W(a))})),setTimeout((function(){return null==u?void 0:u(e)}),0)}}),[a,u]));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?o:l,updateReceiveSettings:d}},exports.useRecording=function(e){var t=void 0===e?{}:e,i=t.onRecordingData,a=t.onRecordingError,u=t.onRecordingStarted,o=t.onRecordingStopped,l=f(),s=r.useRecoilValue(z),d=r.useSetRecoilState(z),v=V(),p=F({filter:"record"});return n.useEffect((function(){var e=p.length>0,t=p.includes(null!=v?v:"local");d((function(n){return c({},n,{isLocalParticipantRecorded:"local"!==(null==n?void 0:n.type)&&(null==n?void 0:n.type)?n.isLocalParticipantRecorded:e,isRecording:"local"!==(null==n?void 0:n.type)&&(null==n?void 0:n.type)?n.isRecording:e,local:"local"!==(null==n?void 0:n.type)&&(null==n?void 0:n.type)||!e?null==n?void 0:n.local:t,type:e?"local":null==n?void 0:n.type})}))}),[v,p,d]),g("recording-started",r.useRecoilCallback((function(e){var t=e.set;return function(e){var n=!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&&(n=!1)}t(z,{error:!1,isLocalParticipantRecorded:n,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}),setTimeout((function(){return null==u?void 0:u(e)}),0)}}),[v,u])),g("recording-stopped",r.useRecoilCallback((function(e){var t=e.set;return function(e){t(z,(function(e){return c({},e,{isLocalParticipantRecorded:!1,isRecording:!1})})),setTimeout((function(){return null==o?void 0:o(e)}),0)}}),[o])),g("recording-error",r.useRecoilCallback((function(e){var t=e.set;return function(e){t(z,(function(e){return c({},e,{error:!0,isLocalParticipantRecorded:!1,isRecording:!1})})),setTimeout((function(){return null==a?void 0:a(e)}),0)}}),[a])),g("recording-data",n.useCallback((function(e){null==i||i(e)}),[i])),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=function(){return r.useRecoilValue(S)},exports.useScreenAudioTrack=function(e){return _(e,"screenAudio")},exports.useScreenShare=function(e){var t=void 0===e?{}:e,i=t.onLocalScreenShareStarted,r=t.onLocalScreenShareStopped,a=f(),u=n.useCallback((function(e){null==a||a.startScreenShare(e)}),[a]),o=n.useCallback((function(){null==a||a.stopScreenShare()}),[a]);g("local-screen-share-started",n.useCallback((function(){return null==i?void 0:i()}),[i])),g("local-screen-share-stopped",n.useCallback((function(){return null==r?void 0:r()}),[r]));var c=F({filter:"screen"}),l=n.useMemo((function(){return c.map((function(e){var t,n=Object.values(null!=(t=null==a||null==a.participants?void 0:a.participants())?t:{}).find((function(t){return t.session_id===e}));if(n)return{local:n.local,screenAudio:n.tracks.screenAudio,screenVideo:n.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:u,stopScreenShare:o}},exports.useScreenVideoTrack=function(e){return _(e,"screenVideo")},exports.useThrottledDailyEvent=m,exports.useVideoTrack=function(e){return _(e,"video")},exports.useWaitingParticipants=function(e){var t=void 0===e?{}:e,i=t.onWaitingParticipantAdded,a=t.onWaitingParticipantRemoved,u=t.onWaitingParticipantUpdated,o=f(),c=r.useRecoilValue($),l=r.useRecoilCallback((function(e){var t=e.transact_UNSTABLE;return function(e){t((function(t){var n=t.set;n(Q,(function(t){return t.includes(e.participant.id)?t:[].concat(t,[e.participant.id])})),n(J(e.participant.id),e.participant)})),setTimeout((function(){return null==i?void 0:i(e)}),0)}}),[i]),s=r.useRecoilCallback((function(e){var t=e.transact_UNSTABLE;return function(e){t((function(t){var n=t.reset;(0,t.set)(Q,(function(t){return t.filter((function(t){return t!==e.participant.id}))})),n(J(e.participant.id))})),setTimeout((function(){return null==a?void 0:a(e)}),0)}}),[a]),d=r.useRecoilCallback((function(e){var t=e.set;return function(e){t(J(e.participant.id),e.participant),setTimeout((function(){return null==u?void 0:u(e)}),0)}}),[u]);g("waiting-participant-added",l),g("waiting-participant-removed",s),g("waiting-participant-updated",d);var v=n.useCallback((function(e,t){"*"!==e?null==o||o.updateWaitingParticipant(e,{grantRequestedAccess:t}):null==o||o.updateWaitingParticipants({"*":{grantRequestedAccess:t}})}),[o]);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 t=e(require("@daily-co/daily-js")),n=require("react"),r=e(n),i=require("recoil"),u=e(require("lodash.throttle"));function o(e,t,n,r,i,u,o){try{var a=e[u](o),c=a.value}catch(e){return void n(e)}a.done?t(c):Promise.resolve(c).then(r,i)}function a(e){return function(){var t=this,n=arguments;return new Promise((function(r,i){var u=e.apply(t,n);function a(e){o(u,r,i,a,c,"next",e)}function c(e){o(u,r,i,a,c,"throw",e)}a(void 0)}))}}function c(){return(c=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function l(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var s=n.createContext(null),d=n.createContext({refreshDevices:function(){return Promise.resolve()}}),f=function(){return n.useContext(s)},v=n.createContext({on:function(){},off:function(){}}),p=0,g=function(){return p++},m=function(e,t){var r=n.useContext(v),i=r.off,u=r.on,o=n.useState(!1),a=o[0],c=o[1],l=n.useRef(0),s=n.useMemo((function(){return g()}),[]);n.useEffect((function(){if(e&&!a){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 u(e,t,s),function(){clearTimeout(n),i(e,s)}}}),[t,e,s,a,i,u])},k=i.atom({key:"general-camera-state",default:"pending"}),b=i.atom({key:"general-microphone-state",default:"pending"}),y=i.atom({key:"camera-devices",default:[]}),h=i.atom({key:"microphone-devices",default:[]}),R=i.atom({key:"speaker-devices",default:[]}),S=function(e){var t=e.children,u=f(),o=i.useRecoilCallback((function(e){var t=e.transact_UNSTABLE;return a((function*(){var e,n,r,i;if(void 0!==(null==(e=navigator)||null==(n=e.mediaDevices)?void 0:n.getUserMedia)&&void 0!==(null==(r=navigator)||null==(i=r.mediaDevices)?void 0:i.enumerateDevices)){if(u)try{var o=(yield u.enumerateDevices()).devices,a=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 u.getInputDevices(),d=s.camera,f=s.mic,v=s.speaker,p=function(e,t,n){var r,i;return{device:t,selected:"deviceId"in e&&t.deviceId===e.deviceId,state:null!=(r=null==(i=n.find((function(e){return e.device.deviceId===t.deviceId})))?void 0:i.state)?r:"granted"}},g=function(e,t){return"default"===e.device.deviceId?-1:"default"===t.device.deviceId?1:e.device.label<t.device.label?-1:e.device.label>t.device.label?1:0};t((function(e){var t=e.set;t(y,(function(e){return a.filter(Boolean).map((function(t){return p(d,t,e)})).sort(g)})),t(h,(function(e){return c.filter(Boolean).map((function(t){return p(f,t,e)})).sort(g)})),t(R,(function(e){return l.filter(Boolean).map((function(t){return p(v,t,e)})).sort(g)}))}))}catch(e){t((function(e){var t=e.set;t(k,"not-supported"),t(b,"not-supported")}))}}else t((function(e){var t=e.set;t(k,"not-supported"),t(b,"not-supported")}))}))}),[u]),l=i.useRecoilCallback((function(e){var t=e.set,n=e.snapshot,r=e.transact_UNSTABLE;return a((function*(){var e,i,a,l,s,d,f,v,p,g,m,R;if(u){var S=yield n.getPromise(k),C=yield n.getPromise(b),T=u.participants().local.tracks,E="pending"===S&&"interrupted"===T.video.state,A="pending"===C&&"interrupted"===T.audio.state;(null==(e=T.audio)||null==(i=e.blocked)?void 0:i.byDeviceInUse)?r((function(e){var t=e.set;t(b,"in-use"),t(h,(function(e){return e.map((function(e){return e.selected?c({},e,{state:"in-use"}):e}))}))})):(null==(a=T.audio)||null==(l=a.blocked)?void 0:l.byDeviceMissing)?t(b,"not-found"):(null==(s=T.audio)||null==(d=s.blocked)?void 0:d.byPermissions)?t(b,"blocked"):A||r((function(e){var t=e.set;t(b,"granted"),t(h,(function(e){return e.map((function(e){return e.selected?c({},e,{state:"granted"}):e}))}))})),(null==(f=T.video)||null==(v=f.blocked)?void 0:v.byDeviceInUse)?r((function(e){var t=e.set;t(k,"in-use"),t(y,(function(e){return e.map((function(e){return e.selected?c({},e,{state:"in-use"}):e}))}))})):(null==(p=T.video)||null==(g=p.blocked)?void 0:g.byDeviceMissing)?t(k,"not-found"):(null==(m=T.video)||null==(R=m.blocked)?void 0:R.byPermissions)?t(k,"blocked"):E||r((function(e){var t=e.set;t(k,"granted"),t(y,(function(e){return e.map((function(e){return e.selected?c({},e,{state:"granted"}):e}))}))})),o()}}))}),[u,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 t=e.set,n=e.transact_UNSTABLE;return function(e){var r=e.error,i=e.errorMsg,u=i.audioOk,o=i.errorMsg,a=i.videoOk;switch(null==r?void 0:r.type){case"cam-in-use":t(k,"in-use");break;case"mic-in-use":t(b,"in-use");break;case"cam-mic-in-use":n((function(e){var t=e.set;t(k,"in-use"),t(b,"in-use")}));break;default:switch(o){case"devices error":n((function(e){var t=e.set;a||t(k,"not-found"),u||t(b,"not-found")}));break;case"not allowed":n((function(e){var t=e.set;t(k,"blocked"),t(b,"blocked")})),l()}}}}),[l])),m("error",i.useRecoilCallback((function(e){var t=e.transact_UNSTABLE;return function(e){switch(e.errorMsg){case"not allowed":t((function(e){var t=e.set;t(k,"blocked"),t(b,"blocked")})),l()}}}),[l])),m("started-camera",i.useRecoilCallback((function(e){var t=e.transact_UNSTABLE;return function(){t((function(e){var t=e.set;t(k,"granted"),t(b,"granted")})),l()}}),[l])),r.createElement(d.Provider,{value:{refreshDevices:o}},t)},C=function(e,t,r){void 0===r&&(r=100);var i=n.useContext(v),o=i.off,a=i.on,c=n.useMemo((function(){return g()}),[]),l=n.useRef([]),s=n.useMemo((function(){return u((function(){0!==l.current.length&&(t(l.current),l.current=[])}),r,{trailing:!0})}),[t,r]);n.useEffect((function(){if(e)return a(e,(function(e){l.current.push(e),setTimeout(s,0)}),c),function(){o(e,c)}}),[s,e,c,o,a])},T=i.atom({key:"local-id",default:""}),E=i.atom({key:"participants-objects",default:[]}),A=i.selectorFamily({key:"participant",get:function(e){return function(t){var n;return null!=(n=(0,t.get)(E).find((function(t){return t.session_id===e})))?n:null}}}),I=i.selectorFamily({key:"participant-property",get:function(e){var t=e.id,n=e.properties;return function(e){var r,i;return i=null!=(r=(0,e.get)(E).find((function(e){return e.session_id===t})))?r:null,n.map((function(e){return function(e,t){return String(t).split(".").filter((function(e){return e.length})).reduce((function(e,t){return e&&e[t]}),e)}(i,e)}))}}}),P=function(e){var t=e.children,u=f();m("active-speaker-change",i.useRecoilCallback((function(e){var t=e.set,n=e.snapshot;return function(){var e=a((function*(e){var r=e.activeSpeaker.peerId,i=yield n.getPromise(A(r));!i&&u&&(i=u.participants()[r]),i&&t(E,(function(e){return[].concat(e).map((function(e){return e.session_id===r?c({},e,{last_active:new Date}):e}))}))}));return function(t){return e.apply(this,arguments)}}()}),[u]));var o=i.useRecoilCallback((function(e){var t=e.set;return function(){var e=a((function*(e){t(T,e.local.session_id),t(E,Object.values(e))}));return function(t){return e.apply(this,arguments)}}()}),[]);n.useEffect((function(){if(u){var e=setInterval((function(){var t=u.participants();"local"in t&&(o(t),clearInterval(e))}),100);return function(){clearInterval(e)}}}),[u,o]);var l=n.useCallback((function(){if(u){var e=null==u?void 0:u.participants();e.local&&o(e)}}),[u,o]);return m("started-camera",l),m("access-state-updated",l),m("joining-meeting",l),m("joined-meeting",n.useCallback((function(e){o(e.participants)}),[o])),C("participant-joined",i.useRecoilCallback((function(e){var t=e.set;return function(){var e=a((function*(e){e.length&&t(E,(function(t){return[].concat(t,e.map((function(e){return e.participant}))).filter((function(e,t,n){return n.findIndex((function(t){return t.session_id===e.session_id}))==t}))}))}));return function(t){return e.apply(this,arguments)}}()}),[])),C("participant-updated",i.useRecoilCallback((function(e){var t=e.transact_UNSTABLE;return function(e){t((function(t){var n=t.set;e.forEach((function(e){var t=e.participant;n(E,(function(e){return[].concat(e).map((function(e){return e.session_id===t.session_id?t:e}))}))}))}))}}),[])),C("participant-left",i.useRecoilCallback((function(e){var t=e.set;return function(e){t(E,(function(t){return[].concat(t).filter((function(t){return!e.some((function(e){return e.participant.session_id===t.session_id}))}))}))}}),[])),m("left-meeting",i.useRecoilCallback((function(e){var t=e.reset;return function(){t(T),t(E)}}),[])),r.createElement(r.Fragment,null,t)},w=i.atom({key:"room",default:null}),x=function(e){var t=e.children,n=f(),u=i.useRecoilCallback((function(e){var t=e.set;return a((function*(){if(n&&"left-meeting"!==n.meetingState()){var e=yield n.room();return e&&"id"in e&&t(w,e),e}}))}),[n]);return m("access-state-updated",u),r.createElement(r.Fragment,null,t)},L=function(e,t){var r=void 0===t?{}:t,u=r.onParticipantLeft,o=r.onParticipantUpdated,a=i.useRecoilValue(A(e));return C("participant-updated",n.useCallback((function(t){var n=t.filter((function(t){return t.participant.session_id===e}));n.length&&n.forEach((function(e){setTimeout((function(){return null==o?void 0:o(e)}),0)}))}),[o,e])),C("participant-left",n.useCallback((function(t){if(t.filter((function(t){return t.participant.session_id===e})).length){var n=t[t.length-1];setTimeout((function(){return null==u?void 0:u(n)}),0)}}),[u,e])),a},_=i.atom({key:"active-id",default:""}),j=function(e,t){var n=i.useRecoilValue(I({id:e,properties:Array.isArray(t)?t:[t]}));return Array.isArray(t)?n:n[0]},D=function(e,t){void 0===t&&(t="video");var n=j(e,"tracks."+t);return n?c({},n,{isOff:"blocked"===n.state||"off"===n.state}):{isOff:!0,persistentTrack:void 0,state:"off",subscribed:!1}},O=i.atom({key:"input-settings",default:null}),V=i.atom({key:"input-settings-error",default:null}),M=i.atom({key:"live-streaming",default:{errorMsg:void 0,isLiveStreaming:!1,layout:void 0}}),U=function(){return i.useRecoilValue(T)||null},B=i.atom({key:"topology",default:"peer"}),N=i.atom({key:"networkQuality",default:100}),q=i.atom({key:"networkThreshold",default:"good"}),F=Boolean,W=function(){return 0},z=function(e){var t=void 0===e?{filter:F,sort:W}:e,r=t.filter,u=void 0===r?F:r,o=t.onActiveSpeakerChange,c=t.onParticipantJoined,l=t.onParticipantLeft,s=t.onParticipantUpdated,d=t.sort,f=void 0===d?W:d,v=i.useRecoilValue(E),p=n.useMemo((function(){var e,t=F;switch(u){case"local":t=function(e){return e.local};break;case"owner":t=function(e){return e.owner};break;case"record":t=function(e){return e.record};break;case"remote":t=function(e){return!e.local};break;case"screen":t=function(e){return e.screen};break;default:t=u}switch(f){case"joined_at":case"session_id":case"user_id":case"user_name":e=function(e,t){var n=e[f],r=t[f];if(void 0!==n||void 0!==r){if(void 0===n)return-1;if(void 0===r)return 1;if(n>r)return 1;if(n<r)return-1}return 0};break;default:e=f}return v.filter(t).sort(e).map((function(e){return e.session_id})).filter(Boolean)}),[v,u,f]);return C("participant-joined",n.useCallback((function(e){e.length&&e.forEach((function(e){return setTimeout((function(){return null==c?void 0:c(e)}),0)}))}),[c])),C("participant-updated",n.useCallback((function(e){e.length&&e.forEach((function(e){return setTimeout((function(){return null==s?void 0:s(e)}),0)}))}),[s])),C("active-speaker-change",n.useCallback(function(){var e=a((function*(e){e.length&&e.forEach((function(e){return setTimeout((function(){return null==o?void 0:o(e)}),0)}))}));return function(t){return e.apply(this,arguments)}}(),[o])),C("participant-left",n.useCallback((function(e){e.length&&e.forEach((function(e){return setTimeout((function(){return null==l?void 0:l(e)}),0)}))}),[l])),p},Q=i.atomFamily({key:"participant-receive-settings",default:{}}),J=i.atom({key:"recording",default:{isLocalParticipantRecorded:!1,isRecording:!1}}),$=i.atom({key:"waiting-participants",default:[]}),G=i.atomFamily({key:"waiting-participant",default:{awaitingAccess:{level:"full"},id:"",name:""}}),H=i.selector({key:"waitingParticipantsSelector",get:function(e){var t=e.get;return t($).map((function(e){return t(G(e))}))}});exports.DailyProvider=function(e){var u=e.children,o=function(e,t){if(null==e)return{};var n,r,i={},u=Object.keys(e);for(r=0;r<u.length;r++)t.indexOf(n=u[r])>=0||(i[n]=e[n]);return i}(e,["children"]),a=n.useState("callObject"in o?o.callObject:null),c=a[0],d=a[1],f=n.useRef({});n.useEffect((function(){var e;if("callObject"in o){var t=(null==c?void 0:c._callFrameId)!==(null==o||null==(e=o.callObject)?void 0:e._callFrameId);o.callObject?(t||!c&&o.callObject)&&d(o.callObject):d(null)}}),[c,o]);var p=n.useCallback((function(e){if("action"in e)for(var t,n=function(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return l(e,void 0);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?l(e,void 0):void 0}}(e))){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}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!=(r=null==(i=f.current)||null==(u=i[e.action])?void 0:u.values())?r:[]);!(t=n()).done;){var r,i,u;(0,t.value)(e)}}),[]),g=n.useCallback((function(e){e&&Object.keys(f.current).forEach((function(t){e.off(t,p).on(t,p)}))}),[p]);n.useEffect((function(){if(!c){if("callObject"in o)return d(o.callObject),void g(o.callObject);var e=t.createCallObject(o);d(e),g(e)}}),[c,g,o]);var m=n.useCallback((function(e,t,n){var r,i;f.current[e]||(f.current[e]=new Map,c&&c.off(e,p).on(e,p)),(null==(r=f.current[e])?void 0:r.has(n))||null==(i=f.current[e])||i.set(n,t)}),[c,p]),k=n.useCallback((function(e,t){var n,r;null==(n=f.current[e])||n.delete(t),0===(null==(r=f.current[e])?void 0:r.size)&&(null==c||c.off(e,p),delete f.current[e])}),[c,p]);return r.createElement(i.RecoilRoot,null,r.createElement(s.Provider,{value:c},r.createElement(v.Provider,{value:{on:m,off:k}},r.createElement(x,null,r.createElement(P,null,r.createElement(S,null,u))))))},exports.useActiveParticipant=function(e){var t=void 0===e?{}:e,r=t.ignoreLocal,u=void 0!==r&&r,o=t.onActiveSpeakerChange,a=f(),c=i.useRecoilValue(_),l=n.useState(""),s=l[1],d=L(l[0]);return n.useEffect((function(){var e;if(a){var t=null==a||null==(e=a.participants())?void 0:e.local;u&&c===(null==t?void 0:t.session_id)||s(c)}}),[a,u,c]),m("active-speaker-change",i.useRecoilCallback((function(e){var t=e.set;return function(e){t(_,e.activeSpeaker.peerId),setTimeout((function(){return null==o?void 0:o(e)}),0)}}),[o])),d},exports.useAppMessage=function(e){var t=(void 0===e?{}:e).onAppMessage,r=f(),i=n.useCallback((function(e,t){void 0===t&&(t="*"),r&&r.sendAppMessage(e,t)}),[r]),u=n.useCallback((function(e){null==t||t(e,i)}),[t,i]);return m("app-message",u),i},exports.useAudioTrack=function(e){return D(e,"audio")},exports.useDaily=f,exports.useDailyEvent=m,exports.useDevices=function(){var e=f(),t=i.useRecoilValue(k),r=i.useRecoilValue(b),u=i.useRecoilValue(y),o=i.useRecoilValue(h),c=i.useRecoilValue(R),l=n.useContext(d).refreshDevices,s=n.useCallback(function(){var t=a((function*(t){yield null==e?void 0:e.setInputDevicesAsync({audioDeviceId:null,videoDeviceId:t})}));return function(e){return t.apply(this,arguments)}}(),[e]),v=n.useCallback(function(){var t=a((function*(t){yield null==e?void 0:e.setInputDevicesAsync({audioDeviceId:t,videoDeviceId:null})}));return function(e){return t.apply(this,arguments)}}(),[e]),p=n.useCallback(function(){var t=a((function*(t){yield null==e?void 0:e.setOutputDeviceAsync({outputDeviceId:t})}));return function(e){return t.apply(this,arguments)}}(),[e]);return{cameras:u,camState:t,hasCamError:["blocked","in-use","not-found"].includes(t),hasMicError:["blocked","in-use","not-found"].includes(r),microphones:o,micState:r,refreshDevices:l,setCamera:s,setMicrophone:v,setSpeaker:p,speakers:c}},exports.useInputSettings=function(e){var t=void 0===e?{}:e,r=t.onError,u=t.onInputSettingsUpdated,o=i.useRecoilValue(O),a=i.useRecoilValue(V),c=f(),l=i.useRecoilCallback((function(e){var t=e.set;return function(e){t(O,e)}}),[]);return n.useEffect((function(){c&&c.getInputSettings().then(l)}),[c,l]),m("input-settings-updated",n.useCallback((function(e){l(e.inputSettings),setTimeout((function(){return null==u?void 0:u(e)}),0)}),[u,l])),m("nonfatal-error",i.useRecoilCallback((function(e){var t=e.set;return function(e){"input-settings-error"===e.type&&(t(V,e.errorMsg),setTimeout((function(){return null==r?void 0:r(e)}),0))}}),[r])),{errorMsg:a,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,u=t.onLiveStreamingStarted,o=t.onLiveStreamingStopped,a=f(),l=i.useRecoilValue(M);return m("live-streaming-started",i.useRecoilCallback((function(e){var t=e.set;return function(e){t(M,{isLiveStreaming:!0,layout:null==e?void 0:e.layout}),setTimeout((function(){return null==u?void 0:u(e)}),0)}}),[u])),m("live-streaming-stopped",i.useRecoilCallback((function(e){var t=e.set;return function(e){t(M,(function(e){return c({},e,{isLiveStreaming:!1,layout:void 0})})),setTimeout((function(){return null==o?void 0:o(e)}),0)}}),[o])),m("live-streaming-error",i.useRecoilCallback((function(e){var t=e.set;return function(e){t(M,(function(t){return c({},t,{errorMsg:e.errorMsg})})),setTimeout((function(){return null==r?void 0:r(e)}),0)}}),[r])),c({},l,{startLiveStreaming:n.useCallback((function(e){a&&a.startLiveStreaming(e)}),[a]),stopLiveStreaming:n.useCallback((function(){a&&a.stopLiveStreaming()}),[a]),updateLiveStreaming:n.useCallback((function(e){a&&a.updateLiveStreaming({layout:e.layout})}),[a])})},exports.useLocalParticipant=function(){var e=i.useRecoilValue(T);return L(e)},exports.useLocalSessionId=U,exports.useMediaTrack=D,exports.useNetwork=function(e){var t=void 0===e?{}:e,r=t.onNetworkConnection,u=t.onNetworkQualityChange,o=f(),c=i.useRecoilValue(B),l=i.useRecoilValue(N),s=i.useRecoilValue(q),d=i.useRecoilCallback((function(e){var t=e.transact_UNSTABLE;return function(e){t((function(t){var n=t.set;switch(e.event){case"connected":"peer-to-peer"===e.type&&n(B,"peer"),"sfu"===e.type&&n(B,"sfu")}})),setTimeout((function(){return null==r?void 0:r(e)}),0)}}),[r]),v=i.useRecoilCallback((function(e){var t=e.transact_UNSTABLE;return function(e){t((function(t){var n=t.set;n(N,(function(t){return t!==e.quality?e.quality:t})),n(q,(function(t){return t!==e.threshold?e.threshold:t}))})),setTimeout((function(){return null==u?void 0:u(e)}),0)}}),[u]);return m("network-connection",d),m("network-quality-change",v),{getStats:n.useCallback(a((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=L,exports.useParticipantIds=z,exports.useParticipantProperty=j,exports.useReceiveSettings=function(e){var t=void 0===e?{}:e,r=t.id,u=void 0===r?"base":r,o=t.onReceiveSettingsUpdated,a=i.useRecoilValue(Q("base")),l=i.useRecoilValue(Q(u)),s=f();m("receive-settings-updated",i.useRecoilCallback((function(e){var t=e.transact_UNSTABLE;return function(e){t((function(t){for(var n=t.reset,r=t.set,i=c({},e.receiveSettings),o=0,a=Object.entries(i);o<a.length;o++){var l=a[o],s=l[1];r(Q(l[0]),s)}u in i||n(Q(u))})),setTimeout((function(){return null==o?void 0:o(e)}),0)}}),[u,o]));var d=n.useCallback((function(e){s&&"joined-meeting"===s.meetingState()&&(null==s||null==s.updateReceiveSettings||s.updateReceiveSettings(e))}),[s]);return{receiveSettings:"base"===u||0===Object.keys(l).length?a:l,updateReceiveSettings:d}},exports.useRecording=function(e){var t=void 0===e?{}:e,r=t.onRecordingData,u=t.onRecordingError,o=t.onRecordingStarted,a=t.onRecordingStopped,l=f(),s=i.useRecoilValue(J),d=i.useSetRecoilState(J),v=U(),p=z({filter:"record"});return n.useEffect((function(){var e=p.length>0,t=p.includes(null!=v?v:"local");d((function(n){return c({},n,{isLocalParticipantRecorded:"local"!==(null==n?void 0:n.type)&&(null==n?void 0:n.type)?n.isLocalParticipantRecorded:e,isRecording:"local"!==(null==n?void 0:n.type)&&(null==n?void 0:n.type)?n.isRecording:e,local:"local"!==(null==n?void 0:n.type)&&(null==n?void 0:n.type)||!e?null==n?void 0:n.local:t,type:e?"local":null==n?void 0:n.type})}))}),[v,p,d]),m("recording-started",i.useRecoilCallback((function(e){var t=e.set;return function(e){var n=!0;switch(e.type){case"cloud-beta":case"cloud":var r;v&&"single-participant"===(null==(r=e.layout)?void 0:r.preset)&&e.layout.session_id!==v&&(n=!1)}t(J,{error:!1,isLocalParticipantRecorded:n,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}),setTimeout((function(){return null==o?void 0:o(e)}),0)}}),[v,o])),m("recording-stopped",i.useRecoilCallback((function(e){var t=e.set;return function(e){t(J,(function(e){return c({},e,{isLocalParticipantRecorded:!1,isRecording:!1})})),setTimeout((function(){return null==a?void 0:a(e)}),0)}}),[a])),m("recording-error",i.useRecoilCallback((function(e){var t=e.set;return function(e){t(J,(function(e){return c({},e,{error:!0,isLocalParticipantRecorded:!1,isRecording:!1})})),setTimeout((function(){return null==u?void 0:u(e)}),0)}}),[u])),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=function(){return i.useRecoilValue(w)},exports.useScreenAudioTrack=function(e){return D(e,"screenAudio")},exports.useScreenShare=function(e){var t=void 0===e?{}:e,r=t.onLocalScreenShareStarted,i=t.onLocalScreenShareStopped,u=f(),o=n.useCallback((function(e){null==u||u.startScreenShare(e)}),[u]),a=n.useCallback((function(){null==u||u.stopScreenShare()}),[u]);m("local-screen-share-started",n.useCallback((function(){return null==r?void 0:r()}),[r])),m("local-screen-share-stopped",n.useCallback((function(){return null==i?void 0:i()}),[i]));var c=z({filter:"screen"}),l=n.useMemo((function(){return c.map((function(e){var t,n=Object.values(null!=(t=null==u||null==u.participants?void 0:u.participants())?t:{}).find((function(t){return t.session_id===e}));if(n)return{local:n.local,screenAudio:n.tracks.screenAudio,screenVideo:n.tracks.screenVideo,screenId:e+"-screen",session_id:e}})).filter((function(e){return!!e}))}),[u,c]);return{isSharingScreen:l.some((function(e){return e.local})),screens:l,startScreenShare:o,stopScreenShare:a}},exports.useScreenVideoTrack=function(e){return D(e,"screenVideo")},exports.useThrottledDailyEvent=C,exports.useVideoTrack=function(e){return D(e,"video")},exports.useWaitingParticipants=function(e){var t=void 0===e?{}:e,r=t.onWaitingParticipantAdded,u=t.onWaitingParticipantRemoved,o=t.onWaitingParticipantUpdated,a=f(),c=i.useRecoilValue(H),l=i.useRecoilCallback((function(e){var t=e.transact_UNSTABLE;return function(e){t((function(t){var n=t.set;n($,(function(t){return t.includes(e.participant.id)?t:[].concat(t,[e.participant.id])})),n(G(e.participant.id),e.participant)})),setTimeout((function(){return null==r?void 0:r(e)}),0)}}),[r]),s=i.useRecoilCallback((function(e){var t=e.transact_UNSTABLE;return function(e){t((function(t){var n=t.reset;(0,t.set)($,(function(t){return t.filter((function(t){return t!==e.participant.id}))})),n(G(e.participant.id))})),setTimeout((function(){return null==u?void 0:u(e)}),0)}}),[u]),d=i.useRecoilCallback((function(e){var t=e.set;return function(e){t(G(e.participant.id),e.participant),setTimeout((function(){return null==o?void 0:o(e)}),0)}}),[o]);m("waiting-participant-added",l),m("waiting-participant-removed",s),m("waiting-participant-updated",d);var v=n.useCallback((function(e,t){"*"!==e?null==a||a.updateWaitingParticipant(e,{grantRequestedAccess:t}):null==a||a.updateWaitingParticipants({"*":{grantRequestedAccess:t}})}),[a]);return{waitingParticipants:c,grantAccess:n.useCallback((function(e){v(e,!0)}),[v]),denyAccess:n.useCallback((function(e){v(e,!1)}),[v])}};
//# sourceMappingURL=daily-react-hooks.cjs.production.min.js.map
import { DailyParticipant } from '@daily-co/daily-js';
import React from 'react';
import type { Paths } from '../types/paths';
import type { Paths } from './types/paths';
/**

@@ -12,3 +12,3 @@ * Extends DailyParticipant with convenient additional properties.

id: string;
property: Paths<ExtendedDailyParticipant>;
properties: Paths<ExtendedDailyParticipant>[];
};

@@ -15,0 +15,0 @@ export declare const localIdState: import("recoil").RecoilState<string>;

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

import { MediaTrackState } from './useMediaTrack';
/**

@@ -5,2 +6,2 @@ * Returns a participant's audio track and state.

*/
export declare const useAudioTrack: (participantId: string) => import("./useMediaTrack").MediaTrackState;
export declare const useAudioTrack: (participantId: string) => MediaTrackState;

@@ -1,8 +0,1 @@

declare type GeneralState = 'pending' | 'not-supported' | 'granted' | 'blocked' | 'in-use' | 'not-found';
declare type DeviceState = 'granted' | 'in-use';
export interface StatefulDevice {
device: MediaDeviceInfo;
selected: boolean;
state: DeviceState;
}
/**

@@ -15,7 +8,7 @@ * This hook allows access to information about the user's devices and their state.

*/
cameras: StatefulDevice[];
cameras: import("../DailyDevices").StatefulDevice[];
/**
* The general state for camera access.
*/
camState: GeneralState;
camState: "pending" | "not-supported" | "granted" | "blocked" | "in-use" | "not-found";
/**

@@ -32,7 +25,7 @@ * Indicates that there's an issue with camera devices.

*/
microphones: StatefulDevice[];
microphones: import("../DailyDevices").StatefulDevice[];
/**
* The general state for microphone access.
*/
micState: GeneralState;
micState: "pending" | "not-supported" | "granted" | "blocked" | "in-use" | "not-found";
/**

@@ -57,4 +50,3 @@ * Refreshes the list of devices using [enumerateDevices](https://docs.daily.co/reference/daily-js/instance-methods/enumerate-devices).

*/
speakers: StatefulDevice[];
speakers: import("../DailyDevices").StatefulDevice[];
};
export {};

@@ -1,6 +0,6 @@

import { DailyEventObject, DailyEventObjectGenericError, DailyEventObjectLiveStreamingStarted, DailyLiveStreamingOptions, DailyStreamingLayoutConfig } from '@daily-co/daily-js';
import { DailyEventObject, DailyEventObjectLiveStreamingError, DailyEventObjectLiveStreamingStarted, DailyLiveStreamingOptions, DailyStreamingLayoutConfig } from '@daily-co/daily-js';
interface UseLiveStreamingArgs {
onLiveStreamingStarted?(ev: DailyEventObjectLiveStreamingStarted): void;
onLiveStreamingStopped?(ev: DailyEventObject): void;
onLiveStreamingError?(ev: DailyEventObjectGenericError): void;
onLiveStreamingError?(ev: DailyEventObjectLiveStreamingError): void;
}

@@ -7,0 +7,0 @@ /**

@@ -1,8 +0,14 @@

import type { Paths } from '../../types/paths';
import { ExtendedDailyParticipant } from '../DailyParticipants';
import type { NumericKeys } from '../types/NumericKeys';
import type { Paths } from '../types/paths';
import type { PathValue } from '../types/pathValue';
declare type UseParticipantPropertyReturnType<T extends ExtendedDailyParticipant, P extends Paths<T> | Paths<T>[]> = P extends Paths<T>[] ? {
[K in keyof P]: K extends NumericKeys ? PathValue<T, P[K]> : never;
} : P extends Paths<T> ? PathValue<T, P> : never;
/**
* Returns a participant's property that you subscribe to.
* @param participantId The participant's session_id.
* @param propertyPath the participant property that you want to subscribe to.
* @param propertyPaths the array of participant property that you want to subscribe to.
*/
export declare const useParticipantProperty: (participantId: string, propertyPath: Paths<ExtendedDailyParticipant>) => any;
export declare const useParticipantProperty: <T extends ExtendedDailyParticipant, P extends Paths<T, keyof T> | [Paths<T, keyof T>, ...Paths<T, keyof T>[]]>(participantId: string, propertyPaths: P) => UseParticipantPropertyReturnType<T, P>;
export {};

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

import { MediaTrackState } from './useMediaTrack';
/**

@@ -5,2 +6,2 @@ * Returns a participant's screenAudio track and state.

*/
export declare const useScreenAudioTrack: (participantId: string) => import("./useMediaTrack").MediaTrackState;
export declare const useScreenAudioTrack: (participantId: string) => MediaTrackState;

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

import { MediaTrackState } from './useMediaTrack';
/**

@@ -5,2 +6,2 @@ * Returns a participant's screenVideo track and state.

*/
export declare const useScreenVideoTrack: (participantId: string) => import("./useMediaTrack").MediaTrackState;
export declare const useScreenVideoTrack: (participantId: string) => MediaTrackState;

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

import { MediaTrackState } from './useMediaTrack';
/**

@@ -5,2 +6,2 @@ * Returns a participant's video track and state.

*/
export declare const useVideoTrack: (participantId: string) => import("./useMediaTrack").MediaTrackState;
export declare const useVideoTrack: (participantId: string) => MediaTrackState;

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

export { StatefulDevice } from './DailyDevices';
export { ExtendedDailyParticipant } from './DailyParticipants';

@@ -8,3 +9,3 @@ export { DailyProvider } from './DailyProvider';

export { useDailyEvent } from './hooks/useDailyEvent';
export { StatefulDevice, useDevices } from './hooks/useDevices';
export { useDevices } from './hooks/useDevices';
export { useInputSettings } from './hooks/useInputSettings';

@@ -11,0 +12,0 @@ export { useLiveStreaming } from './hooks/useLiveStreaming';

{
"version": "0.3.0",
"version": "0.4.0",
"license": "BSD-2-Clause",

@@ -35,3 +35,3 @@ "keywords": [

"peerDependencies": {
"@daily-co/daily-js": ">=0.29.0 <1",
"@daily-co/daily-js": ">=0.30.0 <1",
"react": ">=16.13.1",

@@ -91,2 +91,3 @@ "recoil": "^0.7.0"

"faker": "^5.5.3",
"fs-extra": "^10.1.0",
"husky": "^7.0.2",

@@ -93,0 +94,0 @@ "jest": "^27.0.5",

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

import { useMediaTrack } from './useMediaTrack';
import { MediaTrackState, useMediaTrack } from './useMediaTrack';

@@ -7,3 +7,3 @@ /**

*/
export const useAudioTrack = (participantId: string) =>
export const useAudioTrack = (participantId: string): MediaTrackState =>
useMediaTrack(participantId, 'audio');

@@ -0,48 +1,14 @@

import { useCallback, useContext } from 'react';
import { useRecoilValue } from 'recoil';
import {
DailyEventObjectCameraError,
DailyEventObjectFatalError,
DailyEventObjectParticipant,
} from '@daily-co/daily-js';
import { useCallback } from 'react';
import { atom, useRecoilCallback, useRecoilValue } from 'recoil';
cameraDevicesState,
generalCameraState,
generalMicrophoneState,
microphoneDevicesState,
speakerDevicesState,
} from '../DailyDevices';
import { DailyDevicesContext } from '../DailyDevicesContext';
import { useDaily } from './useDaily';
import { useDailyEvent } from './useDailyEvent';
type GeneralState =
| 'pending'
| 'not-supported'
| 'granted'
| 'blocked'
| 'in-use'
| 'not-found';
type DeviceState = 'granted' | 'in-use';
export interface StatefulDevice {
device: MediaDeviceInfo;
selected: boolean;
state: DeviceState;
}
const generalCameraState = atom<GeneralState>({
key: 'general-camera-state',
default: 'pending',
});
const generalMicrophoneState = atom<GeneralState>({
key: 'general-microphone-state',
default: 'pending',
});
const cameraDevicesState = atom<StatefulDevice[]>({
key: 'camera-devices',
default: [],
});
const microphoneDevicesState = atom<StatefulDevice[]>({
key: 'microphone-devices',
default: [],
});
const speakerDevicesState = atom<StatefulDevice[]>({
key: 'speaker-devices',
default: [],
});
/**

@@ -60,259 +26,5 @@ * This hook allows access to information about the user's devices and their state.

/**
* Refreshes list of available devices using enumerateDevices.
* Previous device states are kept in place, otherwise states are initialized as 'granted'.
*/
const refreshDevices = useRecoilCallback(
({ transact_UNSTABLE }) =>
async () => {
/**
* Check for legacy browsers.
*/
if (
typeof navigator?.mediaDevices?.getUserMedia === 'undefined' ||
typeof navigator?.mediaDevices?.enumerateDevices === 'undefined'
) {
transact_UNSTABLE(({ set }) => {
set(generalCameraState, 'not-supported');
set(generalMicrophoneState, 'not-supported');
});
return;
}
const { refreshDevices } = useContext(DailyDevicesContext);
if (!daily) return;
try {
const { devices } = await daily.enumerateDevices();
/**
* Filter out "empty" devices for when device access has not been granted (yet).
*/
const cams = devices.filter(
(d) => d.kind === 'videoinput' && d.deviceId !== ''
);
const mics = devices.filter(
(d) => d.kind === 'audioinput' && d.deviceId !== ''
);
const speakers = devices.filter(
(d) => d.kind === 'audiooutput' && d.deviceId !== ''
);
const { camera, mic, speaker } = await daily.getInputDevices();
const mapDevice = (
device: {} | MediaDeviceInfo,
d: MediaDeviceInfo,
prevDevices: StatefulDevice[]
) => ({
device: d,
selected: 'deviceId' in device && d.deviceId === device.deviceId,
state:
prevDevices.find((p) => p.device.deviceId === d.deviceId)
?.state ?? 'granted',
});
const sortDeviceByLabel = (a: StatefulDevice, b: StatefulDevice) => {
if (a.device.deviceId === 'default') return -1;
if (b.device.deviceId === 'default') return 1;
if (a.device.label < b.device.label) return -1;
if (a.device.label > b.device.label) return 1;
return 0;
};
transact_UNSTABLE(({ set }) => {
set(cameraDevicesState, (prevCams) =>
cams
.filter(Boolean)
.map<StatefulDevice>((d) => mapDevice(camera, d, prevCams))
.sort(sortDeviceByLabel)
);
set(microphoneDevicesState, (prevMics) =>
mics
.filter(Boolean)
.map<StatefulDevice>((d) => mapDevice(mic, d, prevMics))
.sort(sortDeviceByLabel)
);
set(speakerDevicesState, (prevSpeakers) =>
speakers
.filter(Boolean)
.map<StatefulDevice>((d) => mapDevice(speaker, d, prevSpeakers))
.sort(sortDeviceByLabel)
);
});
} catch (e) {
transact_UNSTABLE(({ set }) => {
set(generalCameraState, 'not-supported');
set(generalMicrophoneState, 'not-supported');
});
}
},
[daily]
);
/**
* Updates general and specific device states, based on blocked status.
*/
const updateDeviceStates = useRecoilCallback(
({ set, snapshot, transact_UNSTABLE }) =>
async () => {
if (!daily) return;
const currentCamState = await snapshot.getPromise(generalCameraState);
const currentMicState = await snapshot.getPromise(
generalMicrophoneState
);
const { tracks } = daily.participants().local;
const awaitingCamAccess =
currentCamState === 'pending' && tracks.video.state === 'interrupted';
const awaitingMicAccess =
currentMicState === 'pending' && tracks.audio.state === 'interrupted';
if (tracks.audio?.blocked?.byDeviceInUse) {
transact_UNSTABLE(({ set }) => {
set(generalMicrophoneState, 'in-use');
set(microphoneDevicesState, (mics) =>
mics.map<StatefulDevice>((m) =>
m.selected ? { ...m, state: 'in-use' } : m
)
);
});
} else if (tracks.audio?.blocked?.byDeviceMissing) {
set(generalMicrophoneState, 'not-found');
} else if (tracks.audio?.blocked?.byPermissions) {
set(generalMicrophoneState, 'blocked');
} else if (!awaitingMicAccess) {
transact_UNSTABLE(({ set }) => {
set(generalMicrophoneState, 'granted');
set(microphoneDevicesState, (mics) =>
mics.map<StatefulDevice>((m) =>
m.selected ? { ...m, state: 'granted' } : m
)
);
});
}
if (tracks.video?.blocked?.byDeviceInUse) {
transact_UNSTABLE(({ set }) => {
set(generalCameraState, 'in-use');
set(cameraDevicesState, (cams) =>
cams.map<StatefulDevice>((m) =>
m.selected ? { ...m, state: 'in-use' } : m
)
);
});
} else if (tracks.video?.blocked?.byDeviceMissing) {
set(generalCameraState, 'not-found');
} else if (tracks.video?.blocked?.byPermissions) {
set(generalCameraState, 'blocked');
} else if (!awaitingCamAccess) {
transact_UNSTABLE(({ set }) => {
set(generalCameraState, 'granted');
set(cameraDevicesState, (cams) =>
cams.map<StatefulDevice>((m) =>
m.selected ? { ...m, state: 'granted' } : m
)
);
});
}
refreshDevices();
},
[daily, refreshDevices]
);
useDailyEvent(
'participant-updated',
useCallback(
(ev: DailyEventObjectParticipant) => {
if (!ev.participant.local) return;
updateDeviceStates();
},
[updateDeviceStates]
)
);
useDailyEvent('available-devices-updated', refreshDevices);
useDailyEvent(
'camera-error',
useRecoilCallback(
({ set, transact_UNSTABLE }) =>
({
error,
errorMsg: { audioOk, errorMsg, videoOk },
}: DailyEventObjectCameraError) => {
switch (error?.type) {
case 'cam-in-use':
set(generalCameraState, 'in-use');
break;
case 'mic-in-use':
set(generalMicrophoneState, 'in-use');
break;
case 'cam-mic-in-use':
transact_UNSTABLE(({ set }) => {
set(generalCameraState, 'in-use');
set(generalMicrophoneState, 'in-use');
});
break;
default:
switch (errorMsg) {
case 'devices error':
transact_UNSTABLE(({ set }) => {
if (!videoOk) set(generalCameraState, 'not-found');
if (!audioOk) set(generalMicrophoneState, 'not-found');
});
break;
case 'not allowed': {
transact_UNSTABLE(({ set }) => {
set(generalCameraState, 'blocked');
set(generalMicrophoneState, 'blocked');
});
updateDeviceStates();
break;
}
}
break;
}
},
[updateDeviceStates]
)
);
useDailyEvent(
'error',
useRecoilCallback(
({ transact_UNSTABLE }) =>
({ errorMsg }: DailyEventObjectFatalError) => {
switch (errorMsg) {
case 'not allowed': {
transact_UNSTABLE(({ set }) => {
set(generalCameraState, 'blocked');
set(generalMicrophoneState, 'blocked');
});
updateDeviceStates();
break;
}
}
},
[updateDeviceStates]
)
);
/**
* Update all device state, when camera is started.
*/
useDailyEvent(
'started-camera',
useRecoilCallback(
({ transact_UNSTABLE }) =>
() => {
transact_UNSTABLE(({ set }) => {
set(generalCameraState, 'granted');
set(generalMicrophoneState, 'granted');
});
updateDeviceStates();
},
[updateDeviceStates]
)
);
/**
* Sets video input device to given deviceId.

@@ -326,5 +38,4 @@ */

});
refreshDevices();
},
[daily, refreshDevices]
[daily]
);

@@ -341,5 +52,4 @@

});
refreshDevices();
},
[daily, refreshDevices]
[daily]
);

@@ -355,5 +65,4 @@

});
refreshDevices();
},
[daily, refreshDevices]
[daily]
);

@@ -360,0 +69,0 @@

import {
DailyEventObject,
DailyEventObjectGenericError,
DailyEventObjectLiveStreamingError,
DailyEventObjectLiveStreamingStarted,

@@ -17,3 +17,3 @@ DailyLiveStreamingOptions,

onLiveStreamingStopped?(ev: DailyEventObject): void;
onLiveStreamingError?(ev: DailyEventObjectGenericError): void;
onLiveStreamingError?(ev: DailyEventObjectLiveStreamingError): void;
}

@@ -85,3 +85,3 @@

({ set }) =>
(ev: DailyEventObjectGenericError) => {
(ev: DailyEventObjectLiveStreamingError) => {
set(liveStreamingState, (prevState) => ({

@@ -88,0 +88,0 @@ ...prevState,

@@ -1,25 +0,7 @@

import {
DailyEventObjectParticipant,
DailyEventObjectParticipants,
DailyParticipant,
DailyTrackState,
} from '@daily-co/daily-js';
import { useEffect, useMemo } from 'react';
import { atomFamily, useRecoilCallback, useRecoilValue } from 'recoil';
import { DailyParticipant, DailyTrackState } from '@daily-co/daily-js';
import { useDaily } from './useDaily';
import { useDailyEvent } from './useDailyEvent';
import { useThrottledDailyEvent } from './useThrottledDailyEvent';
import { useParticipantProperty } from './useParticipantProperty';
type MediaType = keyof DailyParticipant['tracks'];
// TODO: Handle optional tracks better
const mediaTrackState = atomFamily<DailyTrackState | undefined, string>({
key: 'media-track',
default: {
state: 'loading',
subscribed: false,
},
});
export interface MediaTrackState extends DailyTrackState {

@@ -41,64 +23,4 @@ isOff: boolean;

): MediaTrackState => {
const daily = useDaily();
const key = useMemo(() => `${participantId}-${type}`, [participantId, type]);
const trackState = useRecoilValue(mediaTrackState(key));
const trackState = useParticipantProperty(participantId, `tracks.${type}`);
const handleNewParticipantState = useRecoilCallback(
({ transact_UNSTABLE }) =>
(evts: DailyEventObjectParticipant[]) => {
const filteredEvts = evts.filter(
(ev) => ev.participant.session_id === participantId
);
if (!filteredEvts.length) return;
transact_UNSTABLE(({ reset, set }) => {
filteredEvts.forEach((ev) => {
switch (ev.action) {
case 'participant-joined':
case 'participant-updated':
set(mediaTrackState(key), ev.participant.tracks[type]);
break;
case 'participant-left':
reset(mediaTrackState(key));
break;
}
});
});
},
[key, participantId, type]
);
useThrottledDailyEvent('participant-joined', handleNewParticipantState);
useThrottledDailyEvent('participant-updated', handleNewParticipantState);
useThrottledDailyEvent('participant-left', handleNewParticipantState);
useDailyEvent(
'joined-meeting',
useRecoilCallback(
({ set }) =>
(ev: DailyEventObjectParticipants) => {
set(mediaTrackState(key), ev.participants.local.tracks[type]);
},
[key, type]
)
);
const setInitialState = useRecoilCallback(
({ set }) =>
(initialState: DailyTrackState | null) => {
if (!initialState) return;
set(mediaTrackState(key), initialState);
},
[key]
);
useEffect(() => {
if (!daily) return;
const participants = daily?.participants();
if (!participants) return;
const participant = Object.values(participants).find(
(p) => p.session_id === participantId
);
if (!participant) return;
setInitialState(participant.tracks?.[type] ?? null);
}, [daily, participantId, setInitialState, type]);
if (!trackState)

@@ -105,0 +27,0 @@ return {

@@ -95,4 +95,15 @@ import {

sortFn = (a, b) => {
if (a[sort] < b[sort]) return -1;
if (a[sort] > b[sort]) return 1;
// joined_at can technically be undefined. so in that
// case, sort whichever has a value first. though, it
// should only be undefined in prejoin, when there are
// no other participants to sort so... really this
// shouldn't happen :)
let aSort = a[sort];
let bSort = b[sort];
if (aSort !== undefined || bSort !== undefined) {
if (aSort === undefined) return -1;
if (bSort === undefined) return 1;
if (aSort > bSort) return 1;
if (aSort < bSort) return -1;
}
return 0;

@@ -99,0 +110,0 @@ };

import { useRecoilValue } from 'recoil';
import type { Paths } from '../../types/paths';
import {

@@ -8,15 +7,39 @@ ExtendedDailyParticipant,

} from '../DailyParticipants';
import type { NumericKeys } from '../types/NumericKeys';
import type { Paths } from '../types/paths';
import type { PathValue } from '../types/pathValue';
type UseParticipantPropertyReturnType<
T extends ExtendedDailyParticipant,
P extends Paths<T> | Paths<T>[]
> = P extends Paths<T>[]
? { [K in keyof P]: K extends NumericKeys ? PathValue<T, P[K]> : never }
: P extends Paths<T>
? PathValue<T, P>
: never;
/**
* Returns a participant's property that you subscribe to.
* @param participantId The participant's session_id.
* @param propertyPath the participant property that you want to subscribe to.
* @param propertyPaths the array of participant property that you want to subscribe to.
*/
export const useParticipantProperty = (
export const useParticipantProperty = <
T extends ExtendedDailyParticipant,
P extends Paths<T> | [Paths<T>, ...Paths<T>[]]
>(
participantId: string,
propertyPath: Paths<ExtendedDailyParticipant>
) => {
return useRecoilValue(
participantPropertyState({ id: participantId, property: propertyPath })
propertyPaths: P
): UseParticipantPropertyReturnType<T, P> => {
const participantProperties = useRecoilValue(
participantPropertyState({
id: participantId,
properties: (Array.isArray(propertyPaths)
? propertyPaths
: [propertyPaths]) as Paths<ExtendedDailyParticipant>[],
})
);
return Array.isArray(propertyPaths)
? participantProperties
: participantProperties[0];
};

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

import { useMediaTrack } from './useMediaTrack';
import { MediaTrackState, useMediaTrack } from './useMediaTrack';

@@ -7,3 +7,3 @@ /**

*/
export const useScreenAudioTrack = (participantId: string) =>
export const useScreenAudioTrack = (participantId: string): MediaTrackState =>
useMediaTrack(participantId, 'screenAudio');

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

import { useMediaTrack } from './useMediaTrack';
import { MediaTrackState, useMediaTrack } from './useMediaTrack';

@@ -7,3 +7,3 @@ /**

*/
export const useScreenVideoTrack = (participantId: string) =>
export const useScreenVideoTrack = (participantId: string): MediaTrackState =>
useMediaTrack(participantId, 'screenVideo');

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

import { useMediaTrack } from './useMediaTrack';
import { MediaTrackState, useMediaTrack } from './useMediaTrack';

@@ -7,3 +7,3 @@ /**

*/
export const useVideoTrack = (participantId: string) =>
export const useVideoTrack = (participantId: string): MediaTrackState =>
useMediaTrack(participantId, 'video');

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

export { StatefulDevice } from './DailyDevices';
export { ExtendedDailyParticipant } from './DailyParticipants';

@@ -8,3 +9,3 @@ export { DailyProvider } from './DailyProvider';

export { useDailyEvent } from './hooks/useDailyEvent';
export { StatefulDevice, useDevices } from './hooks/useDevices';
export { useDevices } from './hooks/useDevices';
export { useInputSettings } from './hooks/useInputSettings';

@@ -11,0 +12,0 @@ export { useLiveStreaming } from './hooks/useLiveStreaming';

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