@daily-co/daily-react-hooks
Advanced tools
Comparing version 0.1.1 to 0.2.0
@@ -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"),r=e(n),i=require("recoil");function a(e,t,n,r,i,a,o){try{var u=e[a](o),c=u.value}catch(e){return void n(e)}u.done?t(c):Promise.resolve(c).then(r,i)}function o(e){return function(){var t=this,n=arguments;return new Promise((function(r,i){var o=e.apply(t,n);function u(e){a(o,r,i,u,c,"next",e)}function c(e){a(o,r,i,u,c,"throw",e)}u(void 0)}))}}function u(){return(u=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)}var c=["children"],l=n.createContext(null),s=n.createContext({on:function(){},off:function(){}}),f=function(){return n.useContext(l)},d=0,p=function(){return d++},v=function(e,t){var r=n.useContext(s),i=r.on,a=r.off,o=n.useState(!1),u=o[0],c=o[1],l=n.useRef(0),f=n.useMemo((function(){return p()}),[]);n.useEffect((function(){if(e&&!u){if(l.current>1e3)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 i(e,t,f),function(){clearTimeout(n),a(e,f)}}}),[t,e,f,u,a,i])};function h(e,t){return e(t={exports:{}},t.exports),t.exports}var g=h((function(e){var t=function(e){var t=Object.prototype,n=t.hasOwnProperty,r="function"==typeof Symbol?Symbol:{},i=r.iterator||"@@iterator",a=r.asyncIterator||"@@asyncIterator",o=r.toStringTag||"@@toStringTag";function u(e,t,n,r){var i=Object.create((t&&t.prototype instanceof s?t:s).prototype),a=new x(r||[]);return i._invoke=function(e,t,n){var r="suspendedStart";return function(i,a){if("executing"===r)throw new Error("Generator is already running");if("completed"===r){if("throw"===i)throw a;return{value:void 0,done:!0}}for(n.method=i,n.arg=a;;){var o=n.delegate;if(o){var u=y(o,n);if(u){if(u===l)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if("suspendedStart"===r)throw r="completed",n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r="executing";var s=c(e,t,n);if("normal"===s.type){if(r=n.done?"completed":"suspendedYield",s.arg===l)continue;return{value:s.arg,done:n.done}}"throw"===s.type&&(r="completed",n.method="throw",n.arg=s.arg)}}}(e,n,a),i}function c(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}e.wrap=u;var l={};function s(){}function f(){}function d(){}var p={};p[i]=function(){return this};var v=Object.getPrototypeOf,h=v&&v(v(R([])));h&&h!==t&&n.call(h,i)&&(p=h);var g=d.prototype=s.prototype=Object.create(p);function k(e){["next","throw","return"].forEach((function(t){e[t]=function(e){return this._invoke(t,e)}}))}function m(e,t){var r;this._invoke=function(i,a){function o(){return new t((function(r,o){!function r(i,a,o,u){var l=c(e[i],e,a);if("throw"!==l.type){var s=l.arg,f=s.value;return f&&"object"==typeof f&&n.call(f,"__await")?t.resolve(f.__await).then((function(e){r("next",e,o,u)}),(function(e){r("throw",e,o,u)})):t.resolve(f).then((function(e){s.value=e,o(s)}),(function(e){return r("throw",e,o,u)}))}u(l.arg)}(i,a,r,o)}))}return r=r?r.then(o,o):o()}}function y(e,t){var n=e.iterator[t.method];if(void 0===n){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=void 0,y(e,t),"throw"===t.method))return l;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return l}var r=c(n,e.iterator,t.arg);if("throw"===r.type)return t.method="throw",t.arg=r.arg,t.delegate=null,l;var i=r.arg;return i?i.done?(t[e.resultName]=i.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,l):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,l)}function b(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function w(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function x(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(b,this),this.reset(!0)}function R(e){if(e){var t=e[i];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,a=function t(){for(;++r<e.length;)if(n.call(e,r))return t.value=e[r],t.done=!1,t;return t.value=void 0,t.done=!0,t};return a.next=a}}return{next:C}}function C(){return{value:void 0,done:!0}}return f.prototype=g.constructor=d,d.constructor=f,d[o]=f.displayName="GeneratorFunction",e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===f||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,d):(e.__proto__=d,o in e||(e[o]="GeneratorFunction")),e.prototype=Object.create(g),e},e.awrap=function(e){return{__await:e}},k(m.prototype),m.prototype[a]=function(){return this},e.AsyncIterator=m,e.async=function(t,n,r,i,a){void 0===a&&(a=Promise);var o=new m(u(t,n,r,i),a);return e.isGeneratorFunction(n)?o:o.next().then((function(e){return e.done?e.value:o.next()}))},k(g),g[o]="Generator",g[i]=function(){return this},g.toString=function(){return"[object Generator]"},e.keys=function(e){var t=[];for(var n in e)t.push(n);return t.reverse(),function n(){for(;t.length;){var r=t.pop();if(r in e)return n.value=r,n.done=!1,n}return n.done=!0,n}},e.values=R,x.prototype={constructor:x,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(w),!e)for(var t in this)"t"===t.charAt(0)&&n.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function r(n,r){return o.type="throw",o.arg=e,t.next=n,r&&(t.method="next",t.arg=void 0),!!r}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],o=a.completion;if("root"===a.tryLoc)return r("end");if(a.tryLoc<=this.prev){var u=n.call(a,"catchLoc"),c=n.call(a,"finallyLoc");if(u&&c){if(this.prev<a.catchLoc)return r(a.catchLoc,!0);if(this.prev<a.finallyLoc)return r(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return r(a.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return r(a.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var a=i;break}}a&&("break"===e||"continue"===e)&&a.tryLoc<=t&&t<=a.finallyLoc&&(a=null);var o=a?a.completion:{};return o.type=e,o.arg=t,a?(this.method="next",this.next=a.finallyLoc,l):this.complete(o)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),l},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),w(n),l}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var i=r.arg;w(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:R(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),l}},e}(e.exports);try{regeneratorRuntime=t}catch(e){Function("r","regeneratorRuntime = r")(t)}})),k=i.atomFamily({key:"participant",default:null}),m=function(e,t){var r=void 0===t?{}:t,a=r.onParticipantLeft,c=r.onParticipantUpdated,l=f(),s=i.useRecoilValue(k(e)),d=i.useRecoilCallback((function(t){var n=t.set;return function(t){n(k(e),t)}}),[e]);return n.useEffect((function(){var t;if(l){var n=Object.values(null!=(t=l.participants())?t:{}).find((function(t){return t.session_id===e}));n&&d(n)}}),[l,d,e]),v("active-speaker-change",i.useRecoilCallback((function(t){var n=t.set,r=t.snapshot;return function(){var t=o(g.mark((function t(i){var a;return g.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(i.activeSpeaker.peerId===e){t.next=2;break}return t.abrupt("return");case 2:return t.next=4,r.getPromise(k(e));case 4:if(!(a=t.sent)&&l&&(a=l.participants()[e]),a){t.next=8;break}return t.abrupt("return");case 8:n(k(e),u({},a,{last_active:new Date}));case 9:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}()}),[l,e])),v("participant-updated",i.useRecoilCallback((function(t){var n=t.set;return function(t){t.participant.session_id===e&&(n(k(e),t.participant),null==c||c(t))}}),[c,e])),v("participant-left",i.useRecoilCallback((function(t){var n=t.reset;return function(t){t.participant.session_id===e&&(n(k(e)),null==a||a(t))}}),[a,e])),s},y=i.atom({key:"active-id",default:""}),b=i.atomFamily({key:"media-track",default:{state:"loading",subscribed:!1}}),w=function(e,t){void 0===t&&(t="video");var r=f(),a=n.useMemo((function(){return e+"-"+t}),[e,t]),o=i.useRecoilValue(b(a)),c=i.useRecoilCallback((function(n){var r=n.set,i=n.reset;return function(n){if(n.participant.session_id===e)switch(n.action){case"participant-joined":case"participant-updated":r(b(a),n.participant.tracks[t]);break;case"participant-left":i(b(a))}}}),[a,e,t]);v("participant-joined",c),v("participant-updated",c),v("participant-left",c),v("joined-meeting",i.useRecoilCallback((function(e){var n=e.set;return function(e){n(b(a),e.participants.local.tracks[t])}}),[a,t]));var l=i.useRecoilCallback((function(e){var t=e.set;return function(e){e&&t(b(a),e)}}),[a]);return n.useEffect((function(){if(r){var n=null==r?void 0:r.participants();if(n){var i=Object.values(n).find((function(t){return t.session_id===e}));i&&l(i.tracks[t])}}}),[r,e,l,t]),u({},o,{isOff:"blocked"===o.state||"off"===o.state})},x=i.atom({key:"general-camera-state",default:"pending"}),R=i.atom({key:"general-microphone-state",default:"pending"}),C=i.atom({key:"camera-devices",default:[]}),S=i.atom({key:"microphone-devices",default:[]}),L=i.atom({key:"speaker-devices",default:[]}),E=i.atom({key:"input-settings",default:null}),P=i.atom({key:"input-settings-error",default:null}),_=i.atom({key:"live-streaming",default:{errorMsg:void 0,isLiveStreaming:!1,layout:void 0}}),j=i.atom({key:"local-id",default:""}),O=function(){var e=f(),t=i.useRecoilValue(j),r=i.useRecoilCallback((function(e){var t=e.set;return function(e){e&&t(j,e)}}),[]);return n.useEffect((function(){var n;if(e&&!t){if(null==(n=e.participants())||!n.local){var i=function(e){var t,n;null!=e&&null!=(t=e.participant)&&t.local&&r(null==e||null==(n=e.participant)?void 0:n.session_id)};return e.on("participant-updated",i),function(){e.off("participant-updated",i)}}r(e.participants().local.session_id)}}),[e,r,t]),m(t)},I=i.atom({key:"topology",default:"peer"}),D=i.atom({key:"networkQuality",default:100}),V=i.atom({key:"networkThreshold",default:"good"}),M=function(e,t,r){void 0===r&&(r=100);var i=n.useContext(s),a=i.on,o=i.off,u=n.useMemo((function(){return p()}),[]),c=n.useRef([]);n.useEffect((function(){if(e){var n=function(){0!==c.current.length&&(t(c.current),c.current=[])},i=setInterval(n,r);return a(e,(function(e){c.current.push(e)}),u),function(){clearInterval(i),n(),o(e,u)}}}),[t,e,u,o,a,r])},A=i.atom({key:"participants",default:[]}),T=Boolean,N=function(){return 0},F=function(e){var t=void 0===e?{filter:T,sort:N}:e,r=t.filter,a=void 0===r?T:r,u=t.onActiveSpeakerChange,c=t.onParticipantJoined,l=t.onParticipantLeft,s=t.onParticipantUpdated,d=t.sort,p=void 0===d?N:d,h=f(),k=n.useState([]),m=k[0],y=k[1],b=n.useCallback((function(e){var 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;default:t=a}switch(p){case"joined_at":case"session_id":case"user_id":case"user_name":n=function(e,t){return e[p]<t[p]?-1:e[p]>t[p]?1:0};break;default:n=p}var r=Object.values(e).filter(t).sort(n).map((function(e){return e.session_id})).filter(Boolean);y((function(e){return e.length===r.length&&e.every((function(e,t){return r[t]===e}))?e:r}))}),[a,p]),w=i.useRecoilCallback((function(e){var t=e.set;return function(){var e=o(g.mark((function e(n){var r;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:r=Object.values(null!=n?n:{}).map((function(e){return e.session_id})),t(A,(function(e){return[].concat(e,r).filter((function(e,t,n){return n.indexOf(e)==t}))})),b(null!=n?n:{});case 3:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()}),[b]);return n.useEffect((function(){h&&w(h.participants())}),[h,w]),v("joined-meeting",i.useRecoilCallback((function(e){var t=e.set;return o(g.mark((function e(){var n,r;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(h){e.next=2;break}return e.abrupt("return");case 2:n=h.participants(),r=n.local,t(A,(function(e){return[].concat(e,[r.session_id]).filter((function(e,t,n){return n.indexOf(e)==t}))})),b(n);case 6:case"end":return e.stop()}}),e)})))}),[h,b])),M("participant-joined",i.useRecoilCallback((function(e){var t=e.set;return function(){var e=o(g.mark((function e(n){return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n.length){e.next=2;break}return e.abrupt("return");case 2:t(A,(function(e){return[].concat(e,n.map((function(e){return e.participant.session_id}))).filter((function(e,t,n){return n.indexOf(e)==t}))})),h&&b(h.participants()),n.forEach((function(e){return null==c?void 0:c(e)}));case 5:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()}),[h,c,b])),M("participant-updated",i.useRecoilCallback((function(){return function(e){e.length&&(h&&b(h.participants()),e.forEach((function(e){return null==s?void 0:s(e)})))}}),[h,s,b])),M("active-speaker-change",i.useRecoilCallback((function(){return function(){var e=o(g.mark((function e(t){return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t.length){e.next=2;break}return e.abrupt("return");case 2:h&&b(h.participants()),t.forEach((function(e){return null==u?void 0:u(e)}));case 4:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()}),[h,u,b])),M("participant-left",i.useRecoilCallback((function(e){var t=e.set;return function(){var e=o(g.mark((function e(n){return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n.length){e.next=2;break}return e.abrupt("return");case 2:t(A,(function(e){return[].concat(e).filter((function(e){return!n.some((function(t){return t.participant.session_id===e}))}))})),h&&b(h.participants()),n.forEach((function(e){return null==l?void 0:l(e)}));case 5:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()}),[h,l,b])),m},q=i.atomFamily({key:"participant-receive-settings",default:{}}),G=i.atom({key:"recording",default:{isLocalParticipantRecorded:!1,isRecording:!1}}),U=i.atom({key:"room",default:null}),B=i.atom({key:"waiting-participants",default:[]}),W=i.atomFamily({key:"waiting-participant",default:{awaitingAccess:{level:"full"},id:"",name:""}}),z=i.selector({key:"waitingParticipantsSelector",get:function(e){var t=e.get;return t(B).map((function(e){return t(W(e))}))}});exports.DailyProvider=function(e){var a=e.children,o=function(e,t){if(null==e)return{};var n,r,i={},a=Object.keys(e);for(r=0;r<a.length;r++)t.indexOf(n=a[r])>=0||(i[n]=e[n]);return i}(e,c),u=n.useRef("callObject"in o?o.callObject:null),f=n.useRef({}),d=n.useCallback((function(e){var t,n,r;"action"in e&&Array.from(null!=(t=null==(n=f.current)||null==(r=n[e.action])?void 0:r.values())?t:[]).forEach((function(t){t(e)}))}),[]),p=n.useCallback((function(e){e&&Object.keys(f.current).forEach((function(t){e.off(t,d).on(t,d)}))}),[d]);n.useEffect((function(){if(!u.current){if("callObject"in o)return u.current=o.callObject,void p(o.callObject);var e=t.createCallObject(o);u.current=e,p(e)}}),[p,o]);var v=n.useCallback((function(e,t,n){var r,i,a;f.current[e]||(f.current[e]=new Map,u.current&&(null==(i=u.current)||i.on(e,d))),null!=(r=f.current[e])&&r.has(n)||null==(a=f.current[e])||a.set(n,t)}),[d]),h=n.useCallback((function(e,t){var n,r,i;null==(n=f.current[e])||n.delete(t),0===(null==(r=f.current[e])?void 0:r.size)&&(u.current&&(null==(i=u.current)||i.off(e,d)),delete f.current[e])}),[d]);return r.createElement(i.RecoilRoot,null,r.createElement(l.Provider,{value:u.current},r.createElement(s.Provider,{value:{on:v,off:h}},a)))},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(y),l=n.useState(""),s=l[1],d=m(l[0]);return n.useEffect((function(){var e;if(u){var t=null==u||null==(e=u.participants())?void 0:e.local;a&&c===(null==t?void 0:t.session_id)||s(c)}}),[u,a,c]),v("active-speaker-change",i.useRecoilCallback((function(e){var t=e.set;return function(e){t(y,e.activeSpeaker.peerId),null==o||o(e)}}),[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]),a=n.useCallback((function(e){null==t||t(e,i)}),[t,i]);return v("app-message",a),i},exports.useAudioTrack=function(e){return w(e,"audio")},exports.useDaily=f,exports.useDailyEvent=v,exports.useDevices=function(){var e=f(),t=i.useRecoilValue(x),r=i.useRecoilValue(R),a=i.useRecoilValue(C),c=i.useRecoilValue(S),l=i.useRecoilValue(L),s=i.useRecoilCallback((function(t){var n=t.set;return o(g.mark((function t(){var r,i,a,o,u,c,l,s,f,d,p,v,h,k;return g.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(void 0!==(null==(r=navigator)||null==(i=r.mediaDevices)?void 0:i.getUserMedia)&&void 0!==(null==(a=navigator)||null==(o=a.mediaDevices)?void 0:o.enumerateDevices)){t.next=4;break}return n(x,"not-supported"),n(R,"not-supported"),t.abrupt("return");case 4:if(e){t.next=6;break}return t.abrupt("return");case 6:return t.prev=6,t.next=9,e.enumerateDevices();case 9:return c=(u=t.sent.devices).filter((function(e){return"videoinput"===e.kind&&""!==e.deviceId})),l=u.filter((function(e){return"audioinput"===e.kind&&""!==e.deviceId})),s=u.filter((function(e){return"audiooutput"===e.kind&&""!==e.deviceId})),t.next=16,e.getInputDevices();case 16:d=(f=t.sent).camera,p=f.mic,v=f.speaker,h=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"}},k=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(C,(function(e){return c.filter(Boolean).map((function(t){return h(d,t,e)})).sort(k)})),n(S,(function(e){return l.filter(Boolean).map((function(t){return h(p,t,e)})).sort(k)})),n(L,(function(e){return s.filter(Boolean).map((function(t){return h(v,t,e)})).sort(k)})),t.next=31;break;case 27:t.prev=27,t.t0=t.catch(6),n(x,"not-supported"),n(R,"not-supported");case 31:case"end":return t.stop()}}),t,null,[[6,27]])})))}),[e]),d=i.useRecoilCallback((function(t){var n=t.set,r=t.snapshot;return o(g.mark((function t(){var i,a,o,c,l,f,d,p,v,h,k,m,y,b,w,L,E;return g.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(e){t.next=2;break}return t.abrupt("return");case 2:return t.next=4,r.getPromise(x);case 4:return y=t.sent,t.next=7,r.getPromise(R);case 7:b=t.sent,w=e.participants().local.tracks,L="pending"===y&&"interrupted"===w.video.state,E="pending"===b&&"interrupted"===w.audio.state,null!=(i=w.audio)&&null!=(a=i.blocked)&&a.byDeviceInUse?(n(R,"in-use"),n(S,(function(e){return e.map((function(e){return e.selected?u({},e,{state:"in-use"}):e}))}))):null!=(o=w.audio)&&null!=(c=o.blocked)&&c.byDeviceMissing?n(R,"not-found"):null!=(l=w.audio)&&null!=(f=l.blocked)&&f.byPermissions?n(R,"blocked"):E||(n(R,"granted"),n(S,(function(e){return e.map((function(e){return e.selected?u({},e,{state:"granted"}):e}))}))),null!=(d=w.video)&&null!=(p=d.blocked)&&p.byDeviceInUse?(n(x,"in-use"),n(C,(function(e){return e.map((function(e){return e.selected?u({},e,{state:"in-use"}):e}))}))):null!=(v=w.video)&&null!=(h=v.blocked)&&h.byDeviceMissing?n(x,"not-found"):null!=(k=w.video)&&null!=(m=k.blocked)&&m.byPermissions?n(x,"blocked"):L||(n(x,"granted"),n(C,(function(e){return e.map((function(e){return e.selected?u({},e,{state:"granted"}):e}))}))),s();case 14:case"end":return t.stop()}}),t)})))}),[e,s]);v("participant-updated",n.useCallback((function(e){e.participant.local&&d()}),[d])),v("camera-error",i.useRecoilCallback((function(e){var t=e.set;return function(e){var n=e.errorMsg,r=n.errorMsg,i=n.audioOk,a=n.videoOk,o=e.error;switch(null==o?void 0:o.type){case"cam-in-use":t(x,"in-use");break;case"mic-in-use":t(R,"in-use");break;case"cam-mic-in-use":t(x,"in-use"),t(R,"in-use");break;default:switch(r){case"devices error":a||t(x,"not-found"),i||t(R,"not-found");break;case"not allowed":t(x,"blocked"),t(R,"blocked"),d()}}}}),[d])),v("error",i.useRecoilCallback((function(e){var t=e.set;return function(e){switch(e.errorMsg){case"not allowed":t(x,"blocked"),t(R,"blocked"),d()}}}),[d])),v("started-camera",i.useRecoilCallback((function(e){var t=e.set;return function(){t(x,"granted"),t(R,"granted"),d()}}),[d]));var p=n.useCallback(function(){var t=o(g.mark((function t(n){return g.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,null==e?void 0:e.setInputDevicesAsync({videoDeviceId:n});case 2:s();case 3:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),[e,s]),h=n.useCallback(function(){var t=o(g.mark((function t(n){return g.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,null==e?void 0:e.setInputDevicesAsync({audioDeviceId:n});case 2:s();case 3:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),[e,s]),k=n.useCallback(function(){var t=o(g.mark((function t(n){return g.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:null==e||e.setOutputDevice({outputDeviceId:n}),s();case 2:case"end":return t.stop()}}),t)})));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(r),microphones:c,micState:r,refreshDevices:s,setCamera:p,setMicrophone:h,setSpeaker:k,speakers:l}},exports.useInputSettings=function(e){var t=void 0===e?{}:e,r=t.onError,a=t.onInputSettingsUpdated,o=i.useRecoilValue(E),u=i.useRecoilValue(P),c=f(),l=i.useRecoilCallback((function(e){var t=e.set;return function(e){t(E,e)}}),[]);return n.useEffect((function(){c&&c.getInputSettings().then(l)}),[c,l]),v("input-settings-updated",n.useCallback((function(e){l(e.inputSettings),null==a||a(e)}),[a,l])),v("nonfatal-error",i.useRecoilCallback((function(e){var t=e.set;return function(e){"input-settings-error"===e.type&&(t(P,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.onLiveStreamingStarted,a=t.onLiveStreamingStopped,o=t.onLiveStreamingError,c=f(),l=i.useRecoilValue(_);return v("live-streaming-started",i.useRecoilCallback((function(e){var t=e.set;return function(e){t(_,{isLiveStreaming:!0,layout:null==e?void 0:e.layout}),null==r||r(e)}}),[r])),v("live-streaming-stopped",i.useRecoilCallback((function(e){var t=e.set;return function(e){t(_,(function(e){return u({},e,{isLiveStreaming:!1,layout:void 0})})),null==a||a(e)}}),[a])),v("live-streaming-error",i.useRecoilCallback((function(e){var t=e.set;return function(e){t(_,(function(t){return u({},t,{errorMsg:e.errorMsg})})),null==o||o(e)}}),[o])),u({},l,{startLiveStreaming:n.useCallback((function(e){c&&c.startLiveStreaming(e)}),[c]),stopLiveStreaming:n.useCallback((function(){c&&c.stopLiveStreaming()}),[c]),updateLiveStreaming:n.useCallback((function(e){c&&c.updateLiveStreaming({layout:e.layout})}),[c])})},exports.useLocalParticipant=O,exports.useMediaTrack=w,exports.useNetwork=function(e){var t=void 0===e?{}:e,r=t.onNetworkConnection,a=t.onNetworkQualityChange,u=f(),c=i.useRecoilValue(I),l=i.useRecoilValue(D),s=i.useRecoilValue(V),d=i.useRecoilCallback((function(e){var t=e.set;return function(e){switch(e.event){case"connected":"peer-to-peer"===e.type&&t(I,"peer"),"sfu"===e.type&&t(I,"sfu")}null==r||r(e)}}),[r]),p=i.useRecoilCallback((function(e){var t=e.set;return function(e){t(D,(function(t){return t!==e.quality?e.quality:t})),t(V,(function(t){return t!==e.threshold?e.threshold:t})),null==a||a(e)}}),[a]);return v("network-connection",d),v("network-quality-change",p),{getStats:n.useCallback(o(g.mark((function e(){var t;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,null==u?void 0:u.getNetworkStats();case 2:return e.abrupt("return",null==(t=e.sent)?void 0:t.stats);case 4:case"end":return e.stop()}}),e)}))),[u]),quality:l,threshold:s,topology:c}},exports.useParticipant=m,exports.useParticipantIds=F,exports.useReceiveSettings=function(e){var t=void 0===e?{}:e,r=t.id,a=void 0===r?"base":r,o=t.onReceiveSettingsUpdated,c=i.useRecoilValue(q("base")),l=i.useRecoilValue(q(a)),s=f();v("receive-settings-updated",i.useRecoilCallback((function(e){var t=e.reset,n=e.set;return function(e){for(var r=u({},e.receiveSettings),i=0,c=Object.entries(r);i<c.length;i++){var l=c[i],s=l[1];n(q(l[0]),s)}a in r||t(q(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?c:l,updateReceiveSettings:d}},exports.useRecording=function(e){var t=void 0===e?{}:e,r=t.onRecordingStarted,a=t.onRecordingStopped,o=t.onRecordingError,c=t.onRecordingData,l=f(),s=i.useRecoilValue(G),d=i.useSetRecoilState(G),p=O(),h=F({filter:"record"});return n.useEffect((function(){var e,t=h.length>0,n=h.includes(null!=(e=null==p?void 0:p.session_id)?e:"local");d((function(e){return u({},e,{isLocalParticipantRecorded:"local"!==(null==e?void 0:e.type)&&null!=e&&e.type?e.isLocalParticipantRecorded:t,isRecording:"local"!==(null==e?void 0:e.type)&&null!=e&&e.type?e.isRecording:t,local:"local"!==(null==e?void 0:e.type)&&null!=e&&e.type||!t?null==e?void 0:e.local:n,type:t?"local":null==e?void 0:e.type})}))}),[null==p?void 0:p.session_id,h,d]),v("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 i;p&&"single-participant"===(null==(i=e.layout)?void 0:i.preset)&&e.layout.session_id!==(null==p?void 0:p.session_id)&&(n=!1)}t(G,{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}),null==r||r(e)}}),[p,r])),v("recording-stopped",i.useRecoilCallback((function(e){var t=e.set;return function(e){t(G,(function(e){return u({},e,{isLocalParticipantRecorded:!1,isRecording:!1})})),null==a||a(e)}}),[a])),v("recording-error",i.useRecoilCallback((function(e){var t=e.set;return function(e){t(G,(function(e){return u({},e,{error:!0,isLocalParticipantRecorded:!1,isRecording:!1})})),null==o||o(e)}}),[o])),v("recording-data",n.useCallback((function(e){null==c||c(e)}),[c])),u({},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(e){var t=i.useRecoilValue(U),r=f(),a=i.useRecoilCallback((function(t){var n=t.set;return o(g.mark((function t(){return g.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r){t.next=2;break}return t.abrupt("return");case 2:return t.t0=n,t.t1=U,t.next=6,r.room(e);case 6:t.t2=t.sent,(0,t.t0)(t.t1,t.t2);case 8:case"end":return t.stop()}}),t)})))}),[r,e]);return n.useEffect((function(){r&&a()}),[r,a]),v("loaded",a),v("access-state-updated",a),v("started-camera",a),v("joining-meeting",a),v("joined-meeting",a),t},exports.useScreenAudioTrack=function(e){return w(e,"screenAudio")},exports.useScreenShare=function(e){var t=void 0===e?{}:e,r=t.onLocalScreenShareStarted,i=t.onLocalScreenShareStopped,a=f(),o=n.useCallback((function(e){null==a||a.startScreenShare(e)}),[a]),u=n.useCallback((function(){null==a||a.stopScreenShare()}),[a]);v("local-screen-share-started",n.useCallback((function(){return null==r?void 0:r()}),[r])),v("local-screen-share-stopped",n.useCallback((function(){return null==i?void 0:i()}),[i]));var c=F({filter:function(e){return e.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:o,stopScreenShare:u}},exports.useScreenVideoTrack=function(e){return w(e,"screenVideo")},exports.useThrottledDailyEvent=M,exports.useVideoTrack=function(e){return w(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(z),l=i.useRecoilCallback((function(e){var t=e.set;return function(e){t(B,(function(t){return t.includes(e.participant.id)?t:[].concat(t,[e.participant.id])})),t(W(e.participant.id),e.participant),null==r||r(e)}}),[r]),s=i.useRecoilCallback((function(e){var t=e.reset,n=e.set;return function(e){n(B,(function(t){return t.filter((function(t){return t!==e.participant.id}))})),t(W(e.participant.id)),null==a||a(e)}}),[a]),d=i.useRecoilCallback((function(e){var t=e.set;return function(e){t(W(e.participant.id),e.participant),null==o||o(e)}}),[o]);v("waiting-participant-added",l),v("waiting-participant-removed",s),v("waiting-participant-updated",d);var p=n.useCallback((function(e,t){"*"!==e?null==u||u.updateWaitingParticipant(e,{grantRequestedAccess:t}):null==u||u.updateWaitingParticipants({"*":{grantRequestedAccess:t}})}),[u]);return{waitingParticipants:c,grantAccess:n.useCallback((function(e){p(e,!0)}),[p]),denyAccess:n.useCallback((function(e){p(e,!1)}),[p])}}; | ||
"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"),o=e(require("lodash.throttle"));function a(e,t,n,r,i,o,a){try{var u=e[o](a),c=u.value}catch(e){return void n(e)}u.done?t(c):Promise.resolve(c).then(r,i)}function u(e){return function(){var t=this,n=arguments;return new Promise((function(r,i){var o=e.apply(t,n);function u(e){a(o,r,i,u,c,"next",e)}function c(e){a(o,r,i,u,c,"throw",e)}u(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 s(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 l=n.createContext(null),f=n.createContext({on:function(){},off:function(){}});function d(e,t){return e(t={exports:{}},t.exports),t.exports}var p=d((function(e){var t=function(e){var t=Object.prototype,n=t.hasOwnProperty,r="function"==typeof Symbol?Symbol:{},i=r.iterator||"@@iterator",o=r.asyncIterator||"@@asyncIterator",a=r.toStringTag||"@@toStringTag";function u(e,t,n,r){var i=Object.create((t&&t.prototype instanceof l?t:l).prototype),o=new x(r||[]);return i._invoke=function(e,t,n){var r="suspendedStart";return function(i,o){if("executing"===r)throw new Error("Generator is already running");if("completed"===r){if("throw"===i)throw o;return{value:void 0,done:!0}}for(n.method=i,n.arg=o;;){var a=n.delegate;if(a){var u=k(a,n);if(u){if(u===s)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if("suspendedStart"===r)throw r="completed",n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r="executing";var l=c(e,t,n);if("normal"===l.type){if(r=n.done?"completed":"suspendedYield",l.arg===s)continue;return{value:l.arg,done:n.done}}"throw"===l.type&&(r="completed",n.method="throw",n.arg=l.arg)}}}(e,n,o),i}function c(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}e.wrap=u;var s={};function l(){}function f(){}function d(){}var p={};p[i]=function(){return this};var v=Object.getPrototypeOf,h=v&&v(v(R([])));h&&h!==t&&n.call(h,i)&&(p=h);var g=d.prototype=l.prototype=Object.create(p);function m(e){["next","throw","return"].forEach((function(t){e[t]=function(e){return this._invoke(t,e)}}))}function y(e,t){var r;this._invoke=function(i,o){function a(){return new t((function(r,a){!function r(i,o,a,u){var s=c(e[i],e,o);if("throw"!==s.type){var l=s.arg,f=l.value;return f&&"object"==typeof f&&n.call(f,"__await")?t.resolve(f.__await).then((function(e){r("next",e,a,u)}),(function(e){r("throw",e,a,u)})):t.resolve(f).then((function(e){l.value=e,a(l)}),(function(e){return r("throw",e,a,u)}))}u(s.arg)}(i,o,r,a)}))}return r=r?r.then(a,a):a()}}function k(e,t){var n=e.iterator[t.method];if(void 0===n){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=void 0,k(e,t),"throw"===t.method))return s;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return s}var r=c(n,e.iterator,t.arg);if("throw"===r.type)return t.method="throw",t.arg=r.arg,t.delegate=null,s;var i=r.arg;return i?i.done?(t[e.resultName]=i.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,s):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,s)}function b(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function w(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function x(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(b,this),this.reset(!0)}function R(e){if(e){var t=e[i];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,o=function t(){for(;++r<e.length;)if(n.call(e,r))return t.value=e[r],t.done=!1,t;return t.value=void 0,t.done=!0,t};return o.next=o}}return{next:S}}function S(){return{value:void 0,done:!0}}return f.prototype=g.constructor=d,d.constructor=f,d[a]=f.displayName="GeneratorFunction",e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===f||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,d):(e.__proto__=d,a in e||(e[a]="GeneratorFunction")),e.prototype=Object.create(g),e},e.awrap=function(e){return{__await:e}},m(y.prototype),y.prototype[o]=function(){return this},e.AsyncIterator=y,e.async=function(t,n,r,i,o){void 0===o&&(o=Promise);var a=new y(u(t,n,r,i),o);return e.isGeneratorFunction(n)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},m(g),g[a]="Generator",g[i]=function(){return this},g.toString=function(){return"[object Generator]"},e.keys=function(e){var t=[];for(var n in e)t.push(n);return t.reverse(),function n(){for(;t.length;){var r=t.pop();if(r in e)return n.value=r,n.done=!1,n}return n.done=!0,n}},e.values=R,x.prototype={constructor:x,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(w),!e)for(var t in this)"t"===t.charAt(0)&&n.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function r(n,r){return a.type="throw",a.arg=e,t.next=n,r&&(t.method="next",t.arg=void 0),!!r}for(var i=this.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],a=o.completion;if("root"===o.tryLoc)return r("end");if(o.tryLoc<=this.prev){var u=n.call(o,"catchLoc"),c=n.call(o,"finallyLoc");if(u&&c){if(this.prev<o.catchLoc)return r(o.catchLoc,!0);if(this.prev<o.finallyLoc)return r(o.finallyLoc)}else if(u){if(this.prev<o.catchLoc)return r(o.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return r(o.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===e||"continue"===e)&&o.tryLoc<=t&&t<=o.finallyLoc&&(o=null);var a=o?o.completion:{};return a.type=e,a.arg=t,o?(this.method="next",this.next=o.finallyLoc,s):this.complete(a)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),s},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),w(n),s}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var i=r.arg;w(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:R(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),s}},e}(e.exports);try{regeneratorRuntime=t}catch(e){Function("r","regeneratorRuntime = r")(t)}})),v=function(){return n.useContext(l)},h=0,g=function(){return h++},m=function(e,t){var r=n.useContext(f),i=r.on,o=r.off,a=n.useState(!1),u=a[0],c=a[1],s=n.useRef(0),l=n.useMemo((function(){return g()}),[]);n.useEffect((function(){if(e&&!u){if(s.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);s.current++;var n=setTimeout((function(){s.current=0}),50);return i(e,t,l),function(){clearTimeout(n),o(e,l)}}}),[t,e,l,u,o,i])},y=function(e,t,r){void 0===r&&(r=100);var i=n.useContext(f),a=i.on,u=i.off,c=n.useMemo((function(){return g()}),[]),s=n.useRef([]),l=n.useMemo((function(){return o((function(){0!==s.current.length&&(t(s.current),s.current=[])}),r,{trailing:!0})}),[t,r]);n.useEffect((function(){if(e)return a(e,(function(e){s.current.push(e),setTimeout(l,0)}),c),function(){u(e,c)}}),[l,e,c,u,a])},k=i.atom({key:"participants-objects",default:[]}),b=i.selectorFamily({key:"participant",get:function(e){return function(t){var n;return null!=(n=(0,t.get)(k).find((function(t){return t.session_id===e})))?n:null}}}),w=function(e){var t=e.children,o=v();m("active-speaker-change",i.useRecoilCallback((function(e){var t=e.set,n=e.snapshot;return function(){var e=u(p.mark((function e(r){var i,a;return p.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=r.activeSpeaker.peerId,e.next=3,n.getPromise(b(i));case 3:if(!(a=e.sent)&&o&&(a=o.participants()[i]),a){e.next=7;break}return e.abrupt("return");case 7:t(k,(function(e){return[].concat(e).map((function(e){return e.session_id===i?c({},e,{last_active:new Date}):e}))}));case 8:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()}),[o]));var a=i.useRecoilCallback((function(e){var t=e.set;return function(){var e=u(p.mark((function e(n){return p.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t(k,(function(e){return[].concat(e,Object.values(n)).filter((function(e,t,n){return n.findIndex((function(t){return t.session_id===e.session_id}))==t}))}));case 1:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()}),[]);return n.useEffect((function(){if(o){var e=setInterval((function(){var t=o.participants();"local"in t&&(a(t),clearInterval(e))}),100);return function(){clearInterval(e)}}}),[o,a]),m("joined-meeting",i.useRecoilCallback((function(e){var t=e.set;return function(e){t(k,(function(t){return t.some((function(e){return e.local}))?[].concat(t).map((function(t){return t.local?e.participants.local:t})):[].concat(t,[e.participants.local])}))}}))),y("participant-joined",i.useRecoilCallback((function(e){var t=e.set;return function(){var e=u(p.mark((function e(n){return p.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n.length){e.next=2;break}return e.abrupt("return");case 2:t(k,(function(e){return[].concat(e,n.map((function(e){return e.participant}))).filter((function(e,t,n){return n.findIndex((function(t){return t.session_id===e.session_id}))==t}))}));case 3:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()}),[])),y("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(k,(function(e){return[].concat(e).map((function(e){return e.session_id===t.session_id?t:e}))}))}))}))}}),[])),y("participant-left",i.useRecoilCallback((function(e){var t=e.set;return function(e){t(k,(function(t){return[].concat(t).filter((function(t){return!e.some((function(e){return e.participant.session_id===t.session_id}))}))}))}}),[])),r.createElement(r.Fragment,null,t)},x=i.atom({key:"room",default:null}),R=function(e){var t=e.children,o=v(),a=i.useRecoilCallback((function(e){var t=e.set;return u(p.mark((function e(){var n;return p.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(o){e.next=2;break}return e.abrupt("return");case 2:return e.next=4,o.room();case 4:return t(x,n=e.sent),e.abrupt("return",n);case 7:case"end":return e.stop()}}),e)})))}),[o]);return n.useEffect((function(){if(o){var e,t,n=function(){e=setInterval(u(p.mark((function t(){var n;return p.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,a();case 2:(n=t.sent)&&"config"in n&&clearInterval(e);case 4:case"end":return t.stop()}}),t)}))),250)},r=function(){clearInterval(e),t=setInterval(u(p.mark((function e(){var n;return p.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,a();case 2:(n=e.sent)&&"config"in n&&clearInterval(t);case 4:case"end":return e.stop()}}),e)}))),250)},i=setTimeout((function(){a()}),0);return o.on("access-state-updated",n),o.on("joining-meeting",r),function(){o.off("access-state-updated",n),o.off("joining-meeting",r),clearTimeout(i)}}}),[o,a]),r.createElement(r.Fragment,null,t)},S=["children"],C=function(e,t){var r=void 0===t?{}:t,o=r.onParticipantLeft,a=r.onParticipantUpdated,u=i.useRecoilValue(b(e));return y("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==a?void 0:a(e)}),0)}))}),[a,e])),y("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==o?void 0:o(n)}),0)}}),[o,e])),u},E=i.atom({key:"active-id",default:""}),L=i.atomFamily({key:"media-track",default:{state:"loading",subscribed:!1}}),_=function(e,t){void 0===t&&(t="video");var r=v(),o=n.useMemo((function(){return e+"-"+t}),[e,t]),a=i.useRecoilValue(L(o)),u=i.useRecoilCallback((function(n){var r=n.transact_UNSTABLE;return function(n){var i=n.filter((function(t){return t.participant.session_id===e}));i.length&&r((function(e){var n=e.set,r=e.reset;i.forEach((function(e){switch(e.action){case"participant-joined":case"participant-updated":n(L(o),e.participant.tracks[t]);break;case"participant-left":r(L(o))}}))}))}}),[o,e,t]);y("participant-joined",u),y("participant-updated",u),y("participant-left",u),m("joined-meeting",i.useRecoilCallback((function(e){var n=e.set;return function(e){n(L(o),e.participants.local.tracks[t])}}),[o,t]));var s=i.useRecoilCallback((function(e){var t=e.set;return function(e){e&&t(L(o),e)}}),[o]);return n.useEffect((function(){if(r){var n=null==r?void 0:r.participants();if(n){var i=Object.values(n).find((function(t){return t.session_id===e}));i&&s(i.tracks[t])}}}),[r,e,s,t]),c({},a,{isOff:"blocked"===a.state||"off"===a.state})},T=i.atom({key:"general-camera-state",default:"pending"}),I=i.atom({key:"general-microphone-state",default:"pending"}),j=i.atom({key:"camera-devices",default:[]}),P=i.atom({key:"microphone-devices",default:[]}),A=i.atom({key:"speaker-devices",default:[]}),O=i.atom({key:"input-settings",default:null}),M=i.atom({key:"input-settings-error",default:null}),D=i.atom({key:"live-streaming",default:{errorMsg:void 0,isLiveStreaming:!1,layout:void 0}}),V=i.atom({key:"local-id",default:""}),N=function(){var e=v(),t=i.useRecoilValue(V),r=i.useRecoilCallback((function(e){var t=e.set;return function(e){e&&t(V,e)}}),[]);return n.useEffect((function(){var n;if(e&&!t){if(null==(n=e.participants())||!n.local){var i=function(e){var t,n;null!=e&&null!=(t=e.participant)&&t.local&&r(null==e||null==(n=e.participant)?void 0:n.session_id)};return e.on("participant-updated",i),function(){e.off("participant-updated",i)}}r(e.participants().local.session_id)}}),[e,r,t]),C(t)},U=i.atom({key:"topology",default:"peer"}),B=i.atom({key:"networkQuality",default:100}),F=i.atom({key:"networkThreshold",default:"good"}),q=Boolean,G=function(){return 0},W=function(e){var t=void 0===e?{filter:q,sort:G}:e,r=t.filter,o=void 0===r?q:r,a=t.onActiveSpeakerChange,c=t.onParticipantJoined,s=t.onParticipantLeft,l=t.onParticipantUpdated,f=t.sort,d=void 0===f?G:f,v=i.useRecoilValue(k),h=n.useMemo((function(){var e,t=q;switch(o){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=o}switch(d){case"joined_at":case"session_id":case"user_id":case"user_name":e=function(e,t){return e[d]<t[d]?-1:e[d]>t[d]?1:0};break;default:e=d}return v.filter(t).sort(e).map((function(e){return e.session_id})).filter(Boolean)}),[v,o,d]);return y("participant-joined",n.useCallback((function(e){e.length&&e.forEach((function(e){return setTimeout((function(){return null==c?void 0:c(e)}),0)}))}),[c])),y("participant-updated",n.useCallback((function(e){e.length&&e.forEach((function(e){return setTimeout((function(){return null==l?void 0:l(e)}),0)}))}),[l])),y("active-speaker-change",n.useCallback(function(){var e=u(p.mark((function e(t){return p.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t.length){e.next=2;break}return e.abrupt("return");case 2:t.forEach((function(e){return setTimeout((function(){return null==a?void 0:a(e)}),0)}));case 3:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),[a])),y("participant-left",n.useCallback((function(e){e.length&&e.forEach((function(e){return setTimeout((function(){return null==s?void 0:s(e)}),0)}))}),[s])),h},z=i.atomFamily({key:"participant-receive-settings",default:{}}),Q=i.atom({key:"recording",default:{isLocalParticipantRecorded:!1,isRecording:!1}}),Y=i.atom({key:"waiting-participants",default:[]}),J=i.atomFamily({key:"waiting-participant",default:{awaitingAccess:{level:"full"},id:"",name:""}}),$=i.selector({key:"waitingParticipantsSelector",get:function(e){var t=e.get;return t(Y).map((function(e){return t(J(e))}))}});exports.DailyProvider=function(e){var o=e.children,a=function(e,t){if(null==e)return{};var n,r,i={},o=Object.keys(e);for(r=0;r<o.length;r++)t.indexOf(n=o[r])>=0||(i[n]=e[n]);return i}(e,S),u=n.useState("callObject"in a?a.callObject:null),c=u[0],d=u[1],p=n.useRef({}),v=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 s(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)?s(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=p.current)||null==(o=i[e.action])?void 0:o.values())?r:[]);!(t=n()).done;){var r,i,o;(0,t.value)(e)}}),[]),h=n.useCallback((function(e){e&&Object.keys(p.current).forEach((function(t){e.off(t,v).on(t,v)}))}),[v]);n.useEffect((function(){if(!c){if("callObject"in a)return d(a.callObject),void h(a.callObject);var e=t.createCallObject(a);d(e),h(e)}}),[c,h,a]);var g=n.useCallback((function(e,t,n){var r,i;p.current[e]||(p.current[e]=new Map,c&&c.off(e,v).on(e,v)),null!=(r=p.current[e])&&r.has(n)||null==(i=p.current[e])||i.set(n,t)}),[c,v]),m=n.useCallback((function(e,t){var n,r;null==(n=p.current[e])||n.delete(t),0===(null==(r=p.current[e])?void 0:r.size)&&(null==c||c.off(e,v),delete p.current[e])}),[c,v]);return r.createElement(i.RecoilRoot,null,r.createElement(l.Provider,{value:c},r.createElement(f.Provider,{value:{on:g,off:m}},r.createElement(R,null,r.createElement(w,null,o)))))},exports.useActiveParticipant=function(e){var t=void 0===e?{}:e,r=t.ignoreLocal,o=void 0!==r&&r,a=t.onActiveSpeakerChange,u=v(),c=i.useRecoilValue(E),s=n.useState(""),l=s[1],f=C(s[0]);return n.useEffect((function(){var e;if(u){var t=null==u||null==(e=u.participants())?void 0:e.local;o&&c===(null==t?void 0:t.session_id)||l(c)}}),[u,o,c]),m("active-speaker-change",i.useRecoilCallback((function(e){var t=e.set;return function(e){t(E,e.activeSpeaker.peerId),setTimeout((function(){return null==a?void 0:a(e)}),0)}}),[a])),f},exports.useAppMessage=function(e){var t=(void 0===e?{}:e).onAppMessage,r=v(),i=n.useCallback((function(e,t){void 0===t&&(t="*"),r&&r.sendAppMessage(e,t)}),[r]),o=n.useCallback((function(e){null==t||t(e,i)}),[t,i]);return m("app-message",o),i},exports.useAudioTrack=function(e){return _(e,"audio")},exports.useDaily=v,exports.useDailyEvent=m,exports.useDevices=function(){var e=v(),t=i.useRecoilValue(T),r=i.useRecoilValue(I),o=i.useRecoilValue(j),a=i.useRecoilValue(P),s=i.useRecoilValue(A),l=i.useRecoilCallback((function(t){var n=t.transact_UNSTABLE;return u(p.mark((function t(){var r,i,o,a,u,c,s,l,f,d,v,h,g,m;return p.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(void 0!==(null==(r=navigator)||null==(i=r.mediaDevices)?void 0:i.getUserMedia)&&void 0!==(null==(o=navigator)||null==(a=o.mediaDevices)?void 0:a.enumerateDevices)){t.next=3;break}return n((function(e){var t=e.set;t(T,"not-supported"),t(I,"not-supported")})),t.abrupt("return");case 3:if(e){t.next=5;break}return t.abrupt("return");case 5:return t.prev=5,t.next=8,e.enumerateDevices();case 8:return c=(u=t.sent.devices).filter((function(e){return"videoinput"===e.kind&&""!==e.deviceId})),s=u.filter((function(e){return"audioinput"===e.kind&&""!==e.deviceId})),l=u.filter((function(e){return"audiooutput"===e.kind&&""!==e.deviceId})),t.next=15,e.getInputDevices();case 15:d=(f=t.sent).camera,v=f.mic,h=f.speaker,g=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"}},m=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(j,(function(e){return c.filter(Boolean).map((function(t){return g(d,t,e)})).sort(m)})),t(P,(function(e){return s.filter(Boolean).map((function(t){return g(v,t,e)})).sort(m)})),t(A,(function(e){return l.filter(Boolean).map((function(t){return g(h,t,e)})).sort(m)}))})),t.next=27;break;case 24:t.prev=24,t.t0=t.catch(5),n((function(e){var t=e.set;t(T,"not-supported"),t(I,"not-supported")}));case 27:case"end":return t.stop()}}),t,null,[[5,24]])})))}),[e]),f=i.useRecoilCallback((function(t){var n=t.set,r=t.snapshot,i=t.transact_UNSTABLE;return u(p.mark((function t(){var o,a,u,s,f,d,v,h,g,m,y,k,b,w,x,R,S;return p.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(e){t.next=2;break}return t.abrupt("return");case 2:return t.next=4,r.getPromise(T);case 4:return b=t.sent,t.next=7,r.getPromise(I);case 7:w=t.sent,x=e.participants().local.tracks,R="pending"===b&&"interrupted"===x.video.state,S="pending"===w&&"interrupted"===x.audio.state,null!=(o=x.audio)&&null!=(a=o.blocked)&&a.byDeviceInUse?i((function(e){var t=e.set;t(I,"in-use"),t(P,(function(e){return e.map((function(e){return e.selected?c({},e,{state:"in-use"}):e}))}))})):null!=(u=x.audio)&&null!=(s=u.blocked)&&s.byDeviceMissing?n(I,"not-found"):null!=(f=x.audio)&&null!=(d=f.blocked)&&d.byPermissions?n(I,"blocked"):S||i((function(e){var t=e.set;t(I,"granted"),t(P,(function(e){return e.map((function(e){return e.selected?c({},e,{state:"granted"}):e}))}))})),null!=(v=x.video)&&null!=(h=v.blocked)&&h.byDeviceInUse?i((function(e){var t=e.set;t(T,"in-use"),t(j,(function(e){return e.map((function(e){return e.selected?c({},e,{state:"in-use"}):e}))}))})):null!=(g=x.video)&&null!=(m=g.blocked)&&m.byDeviceMissing?n(T,"not-found"):null!=(y=x.video)&&null!=(k=y.blocked)&&k.byPermissions?n(T,"blocked"):R||i((function(e){var t=e.set;t(T,"granted"),t(j,(function(e){return e.map((function(e){return e.selected?c({},e,{state:"granted"}):e}))}))})),l();case 14:case"end":return t.stop()}}),t)})))}),[e,l]);m("participant-updated",n.useCallback((function(e){e.participant.local&&f()}),[f])),m("camera-error",i.useRecoilCallback((function(e){var t=e.set,n=e.transact_UNSTABLE;return function(e){var r=e.errorMsg,i=r.errorMsg,o=r.audioOk,a=r.videoOk,u=e.error;switch(null==u?void 0:u.type){case"cam-in-use":t(T,"in-use");break;case"mic-in-use":t(I,"in-use");break;case"cam-mic-in-use":n((function(e){var t=e.set;t(T,"in-use"),t(I,"in-use")}));break;default:switch(i){case"devices error":n((function(e){var t=e.set;a||t(T,"not-found"),o||t(I,"not-found")}));break;case"not allowed":n((function(e){var t=e.set;t(T,"blocked"),t(I,"blocked")})),f()}}}}),[f])),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(T,"blocked"),t(I,"blocked")})),f()}}}),[f])),m("started-camera",i.useRecoilCallback((function(e){var t=e.transact_UNSTABLE;return function(){t((function(e){var t=e.set;t(T,"granted"),t(I,"granted")})),f()}}),[f]));var d=n.useCallback(function(){var t=u(p.mark((function t(n){return p.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,null==e?void 0:e.setInputDevicesAsync({videoDeviceId:n});case 2:l();case 3:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),[e,l]),h=n.useCallback(function(){var t=u(p.mark((function t(n){return p.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,null==e?void 0:e.setInputDevicesAsync({audioDeviceId:n});case 2:l();case 3:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),[e,l]),g=n.useCallback(function(){var t=u(p.mark((function t(n){return p.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:null==e||e.setOutputDevice({outputDeviceId:n}),l();case 2:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),[e,l]);return{cameras:o,camState:t,hasCamError:["blocked","in-use","not-found"].includes(t),hasMicError:["blocked","in-use","not-found"].includes(r),microphones:a,micState:r,refreshDevices:l,setCamera:d,setMicrophone:h,setSpeaker:g,speakers:s}},exports.useInputSettings=function(e){var t=void 0===e?{}:e,r=t.onError,o=t.onInputSettingsUpdated,a=i.useRecoilValue(O),u=i.useRecoilValue(M),c=v(),s=i.useRecoilCallback((function(e){var t=e.set;return function(e){t(O,e)}}),[]);return n.useEffect((function(){c&&c.getInputSettings().then(s)}),[c,s]),m("input-settings-updated",n.useCallback((function(e){s(e.inputSettings),setTimeout((function(){return null==o?void 0:o(e)}),0)}),[o,s])),m("nonfatal-error",i.useRecoilCallback((function(e){var t=e.set;return function(e){"input-settings-error"===e.type&&(t(M,e.errorMsg),setTimeout((function(){return null==r?void 0:r(e)}),0))}}),[r])),{errorMsg:u,inputSettings:a,updateInputSettings:n.useCallback((function(e){null==c||c.updateInputSettings(e)}),[c])}},exports.useLiveStreaming=function(e){var t=void 0===e?{}:e,r=t.onLiveStreamingStarted,o=t.onLiveStreamingStopped,a=t.onLiveStreamingError,u=v(),s=i.useRecoilValue(D);return m("live-streaming-started",i.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==r?void 0:r(e)}),0)}}),[r])),m("live-streaming-stopped",i.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==o?void 0:o(e)}),0)}}),[o])),m("live-streaming-error",i.useRecoilCallback((function(e){var t=e.set;return function(e){t(D,(function(t){return c({},t,{errorMsg:e.errorMsg})})),setTimeout((function(){return null==a?void 0:a(e)}),0)}}),[a])),c({},s,{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=N,exports.useMediaTrack=_,exports.useNetwork=function(e){var t=void 0===e?{}:e,r=t.onNetworkConnection,o=t.onNetworkQualityChange,a=v(),c=i.useRecoilValue(U),s=i.useRecoilValue(B),l=i.useRecoilValue(F),f=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(U,"peer"),"sfu"===e.type&&n(U,"sfu")}})),setTimeout((function(){return null==r?void 0:r(e)}),0)}}),[r]),d=i.useRecoilCallback((function(e){var t=e.transact_UNSTABLE;return function(e){t((function(t){var n=t.set;n(B,(function(t){return t!==e.quality?e.quality:t})),n(F,(function(t){return t!==e.threshold?e.threshold:t}))})),setTimeout((function(){return null==o?void 0:o(e)}),0)}}),[o]);return m("network-connection",f),m("network-quality-change",d),{getStats:n.useCallback(u(p.mark((function e(){var t;return p.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,null==a?void 0:a.getNetworkStats();case 2:return e.abrupt("return",null==(t=e.sent)?void 0:t.stats);case 4:case"end":return e.stop()}}),e)}))),[a]),quality:s,threshold:l,topology:c}},exports.useParticipant=C,exports.useParticipantIds=W,exports.useReceiveSettings=function(e){var t=void 0===e?{}:e,r=t.id,o=void 0===r?"base":r,a=t.onReceiveSettingsUpdated,u=i.useRecoilValue(z("base")),s=i.useRecoilValue(z(o)),l=v();m("receive-settings-updated",i.useRecoilCallback((function(e){var t=e.transact_UNSTABLE;return function(e){t((function(t){for(var n=t.set,r=t.reset,i=c({},e.receiveSettings),a=0,u=Object.entries(i);a<u.length;a++){var s=u[a],l=s[1];n(z(s[0]),l)}o in i||r(z(o))})),setTimeout((function(){return null==a?void 0:a(e)}),0)}}),[o,a]));var f=n.useCallback((function(e){l&&"joined-meeting"===l.meetingState()&&(null==l||null==l.updateReceiveSettings||l.updateReceiveSettings(e))}),[l]);return{receiveSettings:"base"===o||0===Object.keys(s).length?u:s,updateReceiveSettings:f}},exports.useRecording=function(e){var t=void 0===e?{}:e,r=t.onRecordingStarted,o=t.onRecordingStopped,a=t.onRecordingError,u=t.onRecordingData,s=v(),l=i.useRecoilValue(Q),f=i.useSetRecoilState(Q),d=N(),p=W({filter:"record"});return n.useEffect((function(){var e,t=p.length>0,n=p.includes(null!=(e=null==d?void 0:d.session_id)?e:"local");f((function(e){return c({},e,{isLocalParticipantRecorded:"local"!==(null==e?void 0:e.type)&&null!=e&&e.type?e.isLocalParticipantRecorded:t,isRecording:"local"!==(null==e?void 0:e.type)&&null!=e&&e.type?e.isRecording:t,local:"local"!==(null==e?void 0:e.type)&&null!=e&&e.type||!t?null==e?void 0:e.local:n,type:t?"local":null==e?void 0:e.type})}))}),[null==d?void 0:d.session_id,p,f]),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 i;d&&"single-participant"===(null==(i=e.layout)?void 0:i.preset)&&e.layout.session_id!==(null==d?void 0:d.session_id)&&(n=!1)}t(Q,{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==r?void 0:r(e)}),0)}}),[d,r])),m("recording-stopped",i.useRecoilCallback((function(e){var t=e.set;return function(e){t(Q,(function(e){return c({},e,{isLocalParticipantRecorded:!1,isRecording:!1})})),setTimeout((function(){return null==o?void 0:o(e)}),0)}}),[o])),m("recording-error",i.useRecoilCallback((function(e){var t=e.set;return function(e){t(Q,(function(e){return c({},e,{error:!0,isLocalParticipantRecorded:!1,isRecording:!1})})),setTimeout((function(){return null==a?void 0:a(e)}),0)}}),[a])),m("recording-data",n.useCallback((function(e){null==u||u(e)}),[u])),c({},l,{startRecording:n.useCallback((function(e){s&&s.startRecording(e)}),[s]),stopRecording:n.useCallback((function(){s&&s.stopRecording()}),[s]),updateRecording:n.useCallback((function(e){s&&s.updateRecording(e)}),[s])})},exports.useRoom=function(){return i.useRecoilValue(x)},exports.useScreenAudioTrack=function(e){return _(e,"screenAudio")},exports.useScreenShare=function(e){var t=void 0===e?{}:e,r=t.onLocalScreenShareStarted,i=t.onLocalScreenShareStopped,o=v(),a=n.useCallback((function(e){null==o||o.startScreenShare(e)}),[o]),u=n.useCallback((function(){null==o||o.stopScreenShare()}),[o]);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=W({filter:"screen"}),s=n.useMemo((function(){return c.map((function(e){var t,n=Object.values(null!=(t=null==o||null==o.participants?void 0:o.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}))}),[o,c]);return{isSharingScreen:s.some((function(e){return e.local})),screens:s,startScreenShare:a,stopScreenShare:u}},exports.useScreenVideoTrack=function(e){return _(e,"screenVideo")},exports.useThrottledDailyEvent=y,exports.useVideoTrack=function(e){return _(e,"video")},exports.useWaitingParticipants=function(e){var t=void 0===e?{}:e,r=t.onWaitingParticipantAdded,o=t.onWaitingParticipantRemoved,a=t.onWaitingParticipantUpdated,u=v(),c=i.useRecoilValue($),s=i.useRecoilCallback((function(e){var t=e.transact_UNSTABLE;return function(e){t((function(t){var n=t.set;n(Y,(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==r?void 0:r(e)}),0)}}),[r]),l=i.useRecoilCallback((function(e){var t=e.transact_UNSTABLE;return function(e){t((function(t){var n=t.reset;(0,t.set)(Y,(function(t){return t.filter((function(t){return t!==e.participant.id}))})),n(J(e.participant.id))})),setTimeout((function(){return null==o?void 0:o(e)}),0)}}),[o]),f=i.useRecoilCallback((function(e){var t=e.set;return function(e){t(J(e.participant.id),e.participant),setTimeout((function(){return null==a?void 0:a(e)}),0)}}),[a]);m("waiting-participant-added",s),m("waiting-participant-removed",l),m("waiting-participant-updated",f);var d=n.useCallback((function(e,t){"*"!==e?null==u||u.updateWaitingParticipant(e,{grantRequestedAccess:t}):null==u||u.updateWaitingParticipants({"*":{grantRequestedAccess:t}})}),[u]);return{waitingParticipants:c,grantAccess:n.useCallback((function(e){d(e,!0)}),[d]),denyAccess:n.useCallback((function(e){d(e,!1)}),[d])}}; | ||
//# sourceMappingURL=daily-react-hooks.cjs.production.min.js.map |
@@ -1,2 +0,2 @@ | ||
import { DailyCall, DailyCallOptions, DailyEvent } from '@daily-co/daily-js'; | ||
import { DailyCall, DailyCallOptions } from '@daily-co/daily-js'; | ||
import React from 'react'; | ||
@@ -7,9 +7,3 @@ declare type DailyProperties = Pick<DailyCallOptions, 'audioSource' | 'dailyConfig' | 'receiveSettings' | 'subscribeToTracksAutomatically' | 'token' | 'url' | 'userName' | 'videoSource'>; | ||
}; | ||
export declare const DailyContext: React.Context<DailyCall | null>; | ||
interface EventContextValue { | ||
on(ev: DailyEvent, callback: Function, key: number): void; | ||
off(ev: DailyEvent, key: number): void; | ||
} | ||
export declare const DailyEventContext: React.Context<EventContextValue>; | ||
export declare const DailyProvider: React.FC<Props>; | ||
export {}; |
@@ -15,3 +15,3 @@ import { DailyEventObjectActiveSpeakerChange } from '@daily-co/daily-js'; | ||
*/ | ||
export declare const useActiveParticipant: ({ ignoreLocal, onActiveSpeakerChange, }?: UseActiveParticipantArgs) => import("./useParticipant").ExtendedDailyParticipant | null; | ||
export declare const useActiveParticipant: ({ ignoreLocal, onActiveSpeakerChange, }?: UseActiveParticipantArgs) => import("../DailyParticipants").ExtendedDailyParticipant | null; | ||
export {}; |
@@ -1,8 +0,2 @@ | ||
import { DailyEventObjectParticipant, DailyParticipant } from '@daily-co/daily-js'; | ||
/** | ||
* Extends DailyParticipant with convenient additional properties. | ||
*/ | ||
export interface ExtendedDailyParticipant extends DailyParticipant { | ||
last_active?: Date; | ||
} | ||
import { DailyEventObjectParticipant } from '@daily-co/daily-js'; | ||
interface UseParticipantArgs { | ||
@@ -16,3 +10,3 @@ onParticipantLeft?(ev: DailyEventObjectParticipant): void; | ||
*/ | ||
export declare const useParticipant: (sessionId: string, { onParticipantLeft, onParticipantUpdated }?: UseParticipantArgs) => ExtendedDailyParticipant | null; | ||
export declare const useParticipant: (sessionId: string, { onParticipantLeft, onParticipantUpdated }?: UseParticipantArgs) => import("../DailyParticipants").ExtendedDailyParticipant | null; | ||
export {}; |
import { DailyEventObjectActiveSpeakerChange, DailyEventObjectParticipant, DailyParticipant } from '@daily-co/daily-js'; | ||
declare type FilterParticipantsFunction = (p: DailyParticipant, index: number, arr: DailyParticipant[]) => boolean; | ||
declare type FilterParticipants = 'local' | 'remote' | 'owner' | 'record' | FilterParticipantsFunction; | ||
declare type FilterParticipants = 'local' | 'remote' | 'owner' | 'record' | 'screen' | FilterParticipantsFunction; | ||
declare type SortParticipantsFunction = (a: DailyParticipant, b: DailyParticipant) => 1 | -1 | 0; | ||
@@ -5,0 +5,0 @@ declare type SortParticipants = 'joined_at' | 'session_id' | 'user_id' | 'user_name' | SortParticipantsFunction; |
@@ -1,10 +0,5 @@ | ||
import { DailyPendingRoomInfo, DailyRoomInfo } from '@daily-co/daily-js'; | ||
interface UseRoomArgs { | ||
includeRoomConfigDefaults: boolean; | ||
} | ||
/** | ||
* Stateful hook to work with room, domain and token configuration for a daily room. | ||
* Accepts same arguments as [room()](https://docs.daily.co/reference/daily-js/instance-methods/room). | ||
* Includes room default values. | ||
*/ | ||
export declare const useRoom: (options?: UseRoomArgs | undefined) => DailyPendingRoomInfo | DailyRoomInfo | null; | ||
export {}; | ||
export declare const useRoom: () => import("@daily-co/daily-js").DailyPendingRoomInfo | import("@daily-co/daily-js").DailyRoomInfo | null; |
@@ -0,1 +1,2 @@ | ||
export { ExtendedDailyParticipant } from './DailyParticipants'; | ||
export { DailyProvider } from './DailyProvider'; | ||
@@ -13,3 +14,3 @@ export { useActiveParticipant } from './hooks/useActiveParticipant'; | ||
export { useNetwork } from './hooks/useNetwork'; | ||
export { ExtendedDailyParticipant, useParticipant, } from './hooks/useParticipant'; | ||
export { useParticipant } from './hooks/useParticipant'; | ||
export { useParticipantIds } from './hooks/useParticipantIds'; | ||
@@ -16,0 +17,0 @@ export { useReceiveSettings } from './hooks/useReceiveSettings'; |
{ | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"license": "BSD-2-Clause", | ||
@@ -25,3 +25,3 @@ "main": "dist/index.js", | ||
"react": ">=16", | ||
"recoil": "^0.5.2" | ||
"recoil": "^0.7.0" | ||
}, | ||
@@ -65,2 +65,3 @@ "husky": { | ||
"@types/jest": "^27.0.1", | ||
"@types/lodash.throttle": "^4.1.6", | ||
"@types/react": "^17.0.20", | ||
@@ -91,4 +92,5 @@ "@types/react-dom": "^17.0.9", | ||
"dependencies": { | ||
"fast-deep-equal": "^3.1.3" | ||
"fast-deep-equal": "^3.1.3", | ||
"lodash.throttle": "^4.1.1" | ||
} | ||
} |
@@ -53,3 +53,3 @@ import { DailyEventObjectActiveSpeakerChange } from '@daily-co/daily-js'; | ||
set(activeIdState, ev.activeSpeaker.peerId); | ||
onActiveSpeakerChange?.(ev); | ||
setTimeout(() => onActiveSpeakerChange?.(ev), 0); | ||
}, | ||
@@ -56,0 +56,0 @@ [onActiveSpeakerChange] |
import { useContext } from 'react'; | ||
import { DailyContext } from '../DailyProvider'; | ||
import { DailyContext } from '../DailyContext'; | ||
@@ -5,0 +5,0 @@ /** |
import { DailyEvent, DailyEventObject } from '@daily-co/daily-js'; | ||
import { useContext, useEffect, useMemo, useRef, useState } from 'react'; | ||
import { DailyEventContext } from '../DailyProvider'; | ||
import { DailyEventContext } from '../DailyEventContext'; | ||
@@ -33,3 +33,3 @@ type EventCallback = (event?: DailyEventObject) => void; | ||
*/ | ||
if (reassignCount.current > 1000) { | ||
if (reassignCount.current > 100000) { | ||
console.error( | ||
@@ -36,0 +36,0 @@ `useDailyEvent called with potentially non-memoized event callback or due to too many re-renders. |
@@ -65,3 +65,3 @@ import { | ||
const refreshDevices = useRecoilCallback( | ||
({ set }) => | ||
({ transact_UNSTABLE }) => | ||
async () => { | ||
@@ -75,4 +75,6 @@ /** | ||
) { | ||
set(generalCameraState, 'not-supported'); | ||
set(generalMicrophoneState, 'not-supported'); | ||
transact_UNSTABLE(({ set }) => { | ||
set(generalCameraState, 'not-supported'); | ||
set(generalMicrophoneState, 'not-supported'); | ||
}); | ||
return; | ||
@@ -118,23 +120,27 @@ } | ||
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) | ||
); | ||
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) { | ||
set(generalCameraState, 'not-supported'); | ||
set(generalMicrophoneState, 'not-supported'); | ||
transact_UNSTABLE(({ set }) => { | ||
set(generalCameraState, 'not-supported'); | ||
set(generalMicrophoneState, 'not-supported'); | ||
}); | ||
} | ||
@@ -149,3 +155,3 @@ }, | ||
const updateDeviceStates = useRecoilCallback( | ||
({ set, snapshot }) => | ||
({ set, snapshot, transact_UNSTABLE }) => | ||
async () => { | ||
@@ -167,8 +173,10 @@ if (!daily) return; | ||
if (tracks.audio?.blocked?.byDeviceInUse) { | ||
set(generalMicrophoneState, 'in-use'); | ||
set(microphoneDevicesState, (mics) => | ||
mics.map<StatefulDevice>((m) => | ||
m.selected ? { ...m, state: 'in-use' } : m | ||
) | ||
); | ||
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) { | ||
@@ -179,17 +187,21 @@ set(generalMicrophoneState, 'not-found'); | ||
} else if (!awaitingMicAccess) { | ||
set(generalMicrophoneState, 'granted'); | ||
set(microphoneDevicesState, (mics) => | ||
mics.map<StatefulDevice>((m) => | ||
m.selected ? { ...m, state: 'granted' } : m | ||
) | ||
); | ||
transact_UNSTABLE(({ set }) => { | ||
set(generalMicrophoneState, 'granted'); | ||
set(microphoneDevicesState, (mics) => | ||
mics.map<StatefulDevice>((m) => | ||
m.selected ? { ...m, state: 'granted' } : m | ||
) | ||
); | ||
}); | ||
} | ||
if (tracks.video?.blocked?.byDeviceInUse) { | ||
set(generalCameraState, 'in-use'); | ||
set(cameraDevicesState, (cams) => | ||
cams.map<StatefulDevice>((m) => | ||
m.selected ? { ...m, state: 'in-use' } : m | ||
) | ||
); | ||
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) { | ||
@@ -200,10 +212,11 @@ set(generalCameraState, 'not-found'); | ||
} else if (!awaitingCamAccess) { | ||
set(generalCameraState, 'granted'); | ||
set(cameraDevicesState, (cams) => | ||
cams.map<StatefulDevice>((m) => | ||
m.selected ? { ...m, state: 'granted' } : m | ||
) | ||
); | ||
transact_UNSTABLE(({ set }) => { | ||
set(generalCameraState, 'granted'); | ||
set(cameraDevicesState, (cams) => | ||
cams.map<StatefulDevice>((m) => | ||
m.selected ? { ...m, state: 'granted' } : m | ||
) | ||
); | ||
}); | ||
} | ||
refreshDevices(); | ||
@@ -228,3 +241,3 @@ }, | ||
useRecoilCallback( | ||
({ set }) => | ||
({ set, transact_UNSTABLE }) => | ||
({ | ||
@@ -242,4 +255,6 @@ errorMsg: { errorMsg, audioOk, videoOk }, | ||
case 'cam-mic-in-use': | ||
set(generalCameraState, 'in-use'); | ||
set(generalMicrophoneState, 'in-use'); | ||
transact_UNSTABLE(({ set }) => { | ||
set(generalCameraState, 'in-use'); | ||
set(generalMicrophoneState, 'in-use'); | ||
}); | ||
break; | ||
@@ -249,8 +264,12 @@ default: | ||
case 'devices error': | ||
if (!videoOk) set(generalCameraState, 'not-found'); | ||
if (!audioOk) set(generalMicrophoneState, 'not-found'); | ||
transact_UNSTABLE(({ set }) => { | ||
if (!videoOk) set(generalCameraState, 'not-found'); | ||
if (!audioOk) set(generalMicrophoneState, 'not-found'); | ||
}); | ||
break; | ||
case 'not allowed': { | ||
set(generalCameraState, 'blocked'); | ||
set(generalMicrophoneState, 'blocked'); | ||
transact_UNSTABLE(({ set }) => { | ||
set(generalCameraState, 'blocked'); | ||
set(generalMicrophoneState, 'blocked'); | ||
}); | ||
updateDeviceStates(); | ||
@@ -270,8 +289,10 @@ break; | ||
useRecoilCallback( | ||
({ set }) => | ||
({ transact_UNSTABLE }) => | ||
({ errorMsg }: DailyEventObjectFatalError) => { | ||
switch (errorMsg) { | ||
case 'not allowed': { | ||
set(generalCameraState, 'blocked'); | ||
set(generalMicrophoneState, 'blocked'); | ||
transact_UNSTABLE(({ set }) => { | ||
set(generalCameraState, 'blocked'); | ||
set(generalMicrophoneState, 'blocked'); | ||
}); | ||
updateDeviceStates(); | ||
@@ -292,6 +313,8 @@ break; | ||
useRecoilCallback( | ||
({ set }) => | ||
({ transact_UNSTABLE }) => | ||
() => { | ||
set(generalCameraState, 'granted'); | ||
set(generalMicrophoneState, 'granted'); | ||
transact_UNSTABLE(({ set }) => { | ||
set(generalCameraState, 'granted'); | ||
set(generalMicrophoneState, 'granted'); | ||
}); | ||
updateDeviceStates(); | ||
@@ -298,0 +321,0 @@ }, |
@@ -55,3 +55,3 @@ import { | ||
updateInputSettingsState(ev.inputSettings); | ||
onInputSettingsUpdated?.(ev); | ||
setTimeout(() => onInputSettingsUpdated?.(ev), 0); | ||
}, | ||
@@ -72,3 +72,3 @@ [onInputSettingsUpdated, updateInputSettingsState] | ||
set(errorState, ev.errorMsg); | ||
onError?.(ev); | ||
setTimeout(() => onError?.(ev), 0); | ||
}, | ||
@@ -75,0 +75,0 @@ [onError] |
@@ -58,3 +58,3 @@ import { | ||
}); | ||
onLiveStreamingStarted?.(ev); | ||
setTimeout(() => onLiveStreamingStarted?.(ev), 0); | ||
}, | ||
@@ -75,3 +75,3 @@ [onLiveStreamingStarted] | ||
})); | ||
onLiveStreamingStopped?.(ev); | ||
setTimeout(() => onLiveStreamingStopped?.(ev), 0); | ||
}, | ||
@@ -91,3 +91,3 @@ [onLiveStreamingStopped] | ||
})); | ||
onLiveStreamingError?.(ev); | ||
setTimeout(() => onLiveStreamingError?.(ev), 0); | ||
}, | ||
@@ -94,0 +94,0 @@ [onLiveStreamingError] |
@@ -12,2 +12,3 @@ import { | ||
import { useDailyEvent } from './useDailyEvent'; | ||
import { useThrottledDailyEvent } from './useThrottledDailyEvent'; | ||
@@ -41,14 +42,21 @@ type MediaType = keyof DailyParticipant['tracks']; | ||
const handleNewParticipantState = useRecoilCallback( | ||
({ set, reset }) => | ||
(ev: DailyEventObjectParticipant) => { | ||
if (ev.participant.session_id !== participantId) return; | ||
switch (ev.action) { | ||
case 'participant-joined': | ||
case 'participant-updated': | ||
set(mediaTrackState(key), ev.participant.tracks[type]); | ||
break; | ||
case 'participant-left': | ||
reset(mediaTrackState(key)); | ||
break; | ||
} | ||
({ transact_UNSTABLE }) => | ||
(evts: DailyEventObjectParticipant[]) => { | ||
const filteredEvts = evts.filter( | ||
(ev) => ev.participant.session_id === participantId | ||
); | ||
if (!filteredEvts.length) return; | ||
transact_UNSTABLE(({ set, reset }) => { | ||
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; | ||
} | ||
}); | ||
}); | ||
}, | ||
@@ -58,5 +66,5 @@ [key, participantId, type] | ||
useDailyEvent('participant-joined', handleNewParticipantState); | ||
useDailyEvent('participant-updated', handleNewParticipantState); | ||
useDailyEvent('participant-left', handleNewParticipantState); | ||
useThrottledDailyEvent('participant-joined', handleNewParticipantState); | ||
useThrottledDailyEvent('participant-updated', handleNewParticipantState); | ||
useThrottledDailyEvent('participant-left', handleNewParticipantState); | ||
@@ -63,0 +71,0 @@ useDailyEvent( |
@@ -46,11 +46,13 @@ import { | ||
const handleNetworkConnection = useRecoilCallback( | ||
({ set }) => | ||
({ transact_UNSTABLE }) => | ||
(ev: DailyEventObjectNetworkConnectionEvent) => { | ||
switch (ev.event) { | ||
case 'connected': | ||
if (ev.type === 'peer-to-peer') set(topologyState, 'peer'); | ||
if (ev.type === 'sfu') set(topologyState, 'sfu'); | ||
break; | ||
} | ||
onNetworkConnection?.(ev); | ||
transact_UNSTABLE(({ set }) => { | ||
switch (ev.event) { | ||
case 'connected': | ||
if (ev.type === 'peer-to-peer') set(topologyState, 'peer'); | ||
if (ev.type === 'sfu') set(topologyState, 'sfu'); | ||
break; | ||
} | ||
}); | ||
setTimeout(() => onNetworkConnection?.(ev), 0); | ||
}, | ||
@@ -61,11 +63,13 @@ [onNetworkConnection] | ||
const handleNetworkQualityChange = useRecoilCallback( | ||
({ set }) => | ||
({ transact_UNSTABLE }) => | ||
(ev: DailyEventObjectNetworkQualityEvent) => { | ||
set(networkQualityState, (prevQuality) => | ||
prevQuality !== ev.quality ? ev.quality : prevQuality | ||
); | ||
set(networkThresholdState, (prevThreshold) => | ||
prevThreshold !== ev.threshold ? ev.threshold : prevThreshold | ||
); | ||
onNetworkQualityChange?.(ev); | ||
transact_UNSTABLE(({ set }) => { | ||
set(networkQualityState, (prevQuality) => | ||
prevQuality !== ev.quality ? ev.quality : prevQuality | ||
); | ||
set(networkThresholdState, (prevThreshold) => | ||
prevThreshold !== ev.threshold ? ev.threshold : prevThreshold | ||
); | ||
}); | ||
setTimeout(() => onNetworkQualityChange?.(ev), 0); | ||
}, | ||
@@ -72,0 +76,0 @@ [onNetworkQualityChange] |
@@ -1,27 +0,8 @@ | ||
import { | ||
DailyEventObjectActiveSpeakerChange, | ||
DailyEventObjectParticipant, | ||
DailyParticipant, | ||
} from '@daily-co/daily-js'; | ||
import { useEffect } from 'react'; | ||
import { atomFamily, useRecoilCallback, useRecoilValue } from 'recoil'; | ||
import { DailyEventObjectParticipant } from '@daily-co/daily-js'; | ||
import { useCallback } from 'react'; | ||
import { useRecoilValue } from 'recoil'; | ||
import { useDaily } from './useDaily'; | ||
import { useDailyEvent } from './useDailyEvent'; | ||
import { participantState } from '../DailyParticipants'; | ||
import { useThrottledDailyEvent } from './useThrottledDailyEvent'; | ||
/** | ||
* Extends DailyParticipant with convenient additional properties. | ||
*/ | ||
export interface ExtendedDailyParticipant extends DailyParticipant { | ||
last_active?: Date; | ||
} | ||
/** | ||
* Holds each inidividual participant's state object. | ||
*/ | ||
const participantState = atomFamily<ExtendedDailyParticipant | null, string>({ | ||
key: 'participant', | ||
default: null, | ||
}); | ||
interface UseParticipantArgs { | ||
@@ -40,52 +21,16 @@ onParticipantLeft?(ev: DailyEventObjectParticipant): void; | ||
) => { | ||
const daily = useDaily(); | ||
const participant = useRecoilValue(participantState(sessionId)); | ||
const initState = useRecoilCallback( | ||
({ set }) => | ||
(p: DailyParticipant) => { | ||
set(participantState(sessionId), p); | ||
useThrottledDailyEvent( | ||
'participant-updated', | ||
useCallback( | ||
(evts: DailyEventObjectParticipant[]) => { | ||
const filteredEvts = evts.filter( | ||
(ev) => ev.participant.session_id === sessionId | ||
); | ||
if (!filteredEvts.length) return; | ||
filteredEvts.forEach((ev) => { | ||
setTimeout(() => onParticipantUpdated?.(ev), 0); | ||
}); | ||
}, | ||
[sessionId] | ||
); | ||
useEffect(() => { | ||
if (!daily) return; | ||
const participant = Object.values(daily.participants() ?? {}).find( | ||
(p) => p.session_id === sessionId | ||
); | ||
if (!participant) return; | ||
initState(participant); | ||
}, [daily, initState, sessionId]); | ||
useDailyEvent( | ||
'active-speaker-change', | ||
useRecoilCallback( | ||
({ set, snapshot }) => | ||
async (ev: DailyEventObjectActiveSpeakerChange) => { | ||
if (ev.activeSpeaker.peerId !== sessionId) return; | ||
let participant = await snapshot.getPromise( | ||
participantState(sessionId) | ||
); | ||
if (!participant && daily) { | ||
participant = daily.participants()[sessionId]; | ||
} | ||
if (!participant) return; | ||
set(participantState(sessionId), { | ||
...participant, | ||
last_active: new Date(), | ||
}); | ||
}, | ||
[daily, sessionId] | ||
) | ||
); | ||
useDailyEvent( | ||
'participant-updated', | ||
useRecoilCallback( | ||
({ set }) => | ||
(ev: DailyEventObjectParticipant) => { | ||
if (ev.participant.session_id !== sessionId) return; | ||
set(participantState(sessionId), ev.participant); | ||
onParticipantUpdated?.(ev); | ||
}, | ||
[onParticipantUpdated, sessionId] | ||
@@ -95,11 +40,14 @@ ) | ||
useDailyEvent( | ||
useThrottledDailyEvent( | ||
'participant-left', | ||
useRecoilCallback( | ||
({ reset }) => | ||
(ev: DailyEventObjectParticipant) => { | ||
if (ev.participant.session_id !== sessionId) return; | ||
reset(participantState(sessionId)); | ||
onParticipantLeft?.(ev); | ||
}, | ||
useCallback( | ||
(evts: DailyEventObjectParticipant[]) => { | ||
const filteredEvts = evts.filter( | ||
(ev) => ev.participant.session_id === sessionId | ||
); | ||
if (!filteredEvts.length) return; | ||
// Last event is sufficient to pass the information | ||
const ev = evts[evts.length - 1]; | ||
setTimeout(() => onParticipantLeft?.(ev), 0); | ||
}, | ||
[onParticipantLeft, sessionId] | ||
@@ -106,0 +54,0 @@ ) |
@@ -5,19 +5,9 @@ import { | ||
DailyParticipant, | ||
DailyParticipantsObject, | ||
} from '@daily-co/daily-js'; | ||
import { useCallback, useEffect, useState } from 'react'; | ||
import { atom, useRecoilCallback } from 'recoil'; | ||
import { useCallback, useMemo } from 'react'; | ||
import { useRecoilValue } from 'recoil'; | ||
import { useDaily } from './useDaily'; | ||
import { useDailyEvent } from './useDailyEvent'; | ||
import { participantsState } from '../DailyParticipants'; | ||
import { useThrottledDailyEvent } from './useThrottledDailyEvent'; | ||
/** | ||
* Holds all session ids of joined participants. | ||
*/ | ||
const participantsState = atom<string[]>({ | ||
key: 'participants', | ||
default: [], | ||
}); | ||
type FilterParticipantsFunction = ( | ||
@@ -33,2 +23,3 @@ p: DailyParticipant, | ||
| 'record' | ||
| 'screen' | ||
| FilterParticipantsFunction; | ||
@@ -76,117 +67,56 @@ | ||
) => { | ||
const daily = useDaily(); | ||
const [sortedIds, setSortedIds] = useState<string[]>([]); | ||
const allParticipants = useRecoilValue(participantsState); | ||
const updateSortedIds = useCallback( | ||
(participants: DailyParticipantsObject) => { | ||
let filterFn: FilterParticipantsFunction; | ||
switch (filter) { | ||
case 'local': | ||
filterFn = (p) => p.local; | ||
break; | ||
case 'owner': | ||
filterFn = (p) => p.owner; | ||
break; | ||
case 'record': | ||
filterFn = (p) => p.record; | ||
break; | ||
case 'remote': | ||
filterFn = (p) => !p.local; | ||
break; | ||
default: | ||
filterFn = filter; | ||
break; | ||
} | ||
let sortFn: SortParticipantsFunction; | ||
switch (sort) { | ||
case 'joined_at': | ||
case 'session_id': | ||
case 'user_id': | ||
case 'user_name': | ||
sortFn = (a, b) => { | ||
if (a[sort] < b[sort]) return -1; | ||
if (a[sort] > b[sort]) return 1; | ||
return 0; | ||
}; | ||
break; | ||
default: | ||
sortFn = sort; | ||
break; | ||
} | ||
const newSorted = Object.values(participants) | ||
.filter(filterFn) | ||
.sort(sortFn) | ||
.map((p) => p.session_id) | ||
.filter(Boolean); | ||
setSortedIds((ids) => { | ||
if ( | ||
ids.length === newSorted.length && | ||
ids.every((id, idx) => newSorted[idx] === id) | ||
) | ||
return ids; | ||
return newSorted; | ||
}); | ||
}, | ||
[filter, sort] | ||
); | ||
const sortedIds = useMemo(() => { | ||
let filterFn = defaultFilter; | ||
switch (filter) { | ||
case 'local': | ||
filterFn = (p) => p.local; | ||
break; | ||
case 'owner': | ||
filterFn = (p) => p.owner; | ||
break; | ||
case 'record': | ||
filterFn = (p) => p.record; | ||
break; | ||
case 'remote': | ||
filterFn = (p) => !p.local; | ||
break; | ||
case 'screen': | ||
filterFn = (p) => p.screen; | ||
break; | ||
default: | ||
filterFn = filter; | ||
} | ||
let sortFn: SortParticipantsFunction; | ||
switch (sort) { | ||
case 'joined_at': | ||
case 'session_id': | ||
case 'user_id': | ||
case 'user_name': | ||
sortFn = (a, b) => { | ||
if (a[sort] < b[sort]) return -1; | ||
if (a[sort] > b[sort]) return 1; | ||
return 0; | ||
}; | ||
break; | ||
default: | ||
sortFn = sort; | ||
break; | ||
} | ||
return allParticipants | ||
.filter(filterFn) | ||
.sort(sortFn) | ||
.map((p) => p.session_id) | ||
.filter(Boolean); | ||
}, [allParticipants, filter, sort]); | ||
/** | ||
* Initializes state based on passed DailyParticipantsObject. | ||
*/ | ||
const initState = useRecoilCallback( | ||
({ set }) => | ||
async (participants: DailyParticipantsObject) => { | ||
const sessionIds = Object.values(participants ?? {}).map( | ||
(p) => p.session_id | ||
); | ||
set(participantsState, (ids) => | ||
[...ids, ...sessionIds].filter( | ||
(id, idx, arr) => arr.indexOf(id) == idx | ||
) | ||
); | ||
updateSortedIds(participants ?? {}); | ||
}, | ||
[updateSortedIds] | ||
); | ||
useEffect(() => { | ||
if (!daily) return; | ||
initState(daily.participants()); | ||
}, [daily, initState]); | ||
useDailyEvent( | ||
'joined-meeting', | ||
useRecoilCallback( | ||
({ set }) => | ||
async () => { | ||
if (!daily) return; | ||
const participants = daily.participants(); | ||
const localParticipant = participants.local; | ||
set(participantsState, (ids) => | ||
[...ids, localParticipant.session_id].filter( | ||
(id, idx, arr) => arr.indexOf(id) == idx | ||
) | ||
); | ||
updateSortedIds(participants); | ||
}, | ||
[daily, updateSortedIds] | ||
) | ||
); | ||
useThrottledDailyEvent( | ||
'participant-joined', | ||
useRecoilCallback( | ||
({ set }) => | ||
async (evts: DailyEventObjectParticipant[]) => { | ||
if (!evts.length) return; | ||
set(participantsState, (ids) => | ||
[...ids, ...evts.map((ev) => ev.participant.session_id)].filter( | ||
(id, idx, arr) => arr.indexOf(id) == idx | ||
) | ||
); | ||
if (daily) { | ||
updateSortedIds(daily.participants()); | ||
} | ||
evts.forEach((ev) => onParticipantJoined?.(ev)); | ||
}, | ||
[daily, onParticipantJoined, updateSortedIds] | ||
useCallback( | ||
(evts: DailyEventObjectParticipant[]) => { | ||
if (!evts.length) return; | ||
evts.forEach((ev) => setTimeout(() => onParticipantJoined?.(ev), 0)); | ||
}, | ||
[onParticipantJoined] | ||
) | ||
@@ -197,11 +127,8 @@ ); | ||
'participant-updated', | ||
useRecoilCallback( | ||
() => (evts: DailyEventObjectParticipant[]) => { | ||
useCallback( | ||
(evts: DailyEventObjectParticipant[]) => { | ||
if (!evts.length) return; | ||
if (daily) { | ||
updateSortedIds(daily.participants()); | ||
} | ||
evts.forEach((ev) => onParticipantUpdated?.(ev)); | ||
evts.forEach((ev) => setTimeout(() => onParticipantUpdated?.(ev), 0)); | ||
}, | ||
[daily, onParticipantUpdated, updateSortedIds] | ||
[onParticipantUpdated] | ||
) | ||
@@ -212,11 +139,8 @@ ); | ||
'active-speaker-change', | ||
useRecoilCallback( | ||
() => async (evts: DailyEventObjectActiveSpeakerChange[]) => { | ||
useCallback( | ||
async (evts: DailyEventObjectActiveSpeakerChange[]) => { | ||
if (!evts.length) return; | ||
if (daily) { | ||
updateSortedIds(daily.participants()); | ||
} | ||
evts.forEach((ev) => onActiveSpeakerChange?.(ev)); | ||
evts.forEach((ev) => setTimeout(() => onActiveSpeakerChange?.(ev), 0)); | ||
}, | ||
[daily, onActiveSpeakerChange, updateSortedIds] | ||
[onActiveSpeakerChange] | ||
) | ||
@@ -227,17 +151,8 @@ ); | ||
'participant-left', | ||
useRecoilCallback( | ||
({ set }) => | ||
async (evts: DailyEventObjectParticipant[]) => { | ||
if (!evts.length) return; | ||
set(participantsState, (ids) => | ||
[...ids].filter( | ||
(id) => !evts.some((ev) => ev.participant.session_id === id) | ||
) | ||
); | ||
if (daily) { | ||
updateSortedIds(daily.participants()); | ||
} | ||
evts.forEach((ev) => onParticipantLeft?.(ev)); | ||
}, | ||
[daily, onParticipantLeft, updateSortedIds] | ||
useCallback( | ||
(evts: DailyEventObjectParticipant[]) => { | ||
if (!evts.length) return; | ||
evts.forEach((ev) => setTimeout(() => onParticipantLeft?.(ev), 0)); | ||
}, | ||
[onParticipantLeft] | ||
) | ||
@@ -244,0 +159,0 @@ ); |
@@ -42,12 +42,14 @@ import { | ||
useRecoilCallback( | ||
({ reset, set }) => | ||
({ transact_UNSTABLE }) => | ||
(ev: DailyEventObjectReceiveSettingsUpdated) => { | ||
const { ...ids } = ev.receiveSettings; | ||
for (let [id, settings] of Object.entries(ids)) { | ||
set(participantReceiveSettingsState(id), settings); | ||
} | ||
if (!(id in ids)) { | ||
reset(participantReceiveSettingsState(id)); | ||
} | ||
onReceiveSettingsUpdated?.(ev); | ||
transact_UNSTABLE(({ set, reset }) => { | ||
const { ...ids } = ev.receiveSettings; | ||
for (let [id, settings] of Object.entries(ids)) { | ||
set(participantReceiveSettingsState(id), settings); | ||
} | ||
if (!(id in ids)) { | ||
reset(participantReceiveSettingsState(id)); | ||
} | ||
}); | ||
setTimeout(() => onReceiveSettingsUpdated?.(ev), 0); | ||
}, | ||
@@ -54,0 +56,0 @@ [id, onReceiveSettingsUpdated] |
@@ -154,3 +154,3 @@ import { | ||
}); | ||
onRecordingStarted?.(ev); | ||
setTimeout(() => onRecordingStarted?.(ev), 0); | ||
}, | ||
@@ -170,3 +170,3 @@ [localParticipant, onRecordingStarted] | ||
})); | ||
onRecordingStopped?.(ev); | ||
setTimeout(() => onRecordingStopped?.(ev), 0); | ||
}, | ||
@@ -187,3 +187,3 @@ [onRecordingStopped] | ||
})); | ||
onRecordingError?.(ev); | ||
setTimeout(() => onRecordingError?.(ev), 0); | ||
}, | ||
@@ -190,0 +190,0 @@ [onRecordingError] |
@@ -1,48 +0,12 @@ | ||
import { DailyPendingRoomInfo, DailyRoomInfo } from '@daily-co/daily-js'; | ||
import { useEffect } from 'react'; | ||
import { atom, useRecoilCallback, useRecoilValue } from 'recoil'; | ||
import { useRecoilValue } from 'recoil'; | ||
import { useDaily } from './useDaily'; | ||
import { useDailyEvent } from './useDailyEvent'; | ||
import { roomState } from '../DailyRoom'; | ||
const roomState = atom<DailyPendingRoomInfo | DailyRoomInfo | null>({ | ||
key: 'room', | ||
default: null, | ||
}); | ||
interface UseRoomArgs { | ||
includeRoomConfigDefaults: boolean; | ||
} | ||
/** | ||
* Stateful hook to work with room, domain and token configuration for a daily room. | ||
* Accepts same arguments as [room()](https://docs.daily.co/reference/daily-js/instance-methods/room). | ||
* Includes room default values. | ||
*/ | ||
export const useRoom = (options?: UseRoomArgs) => { | ||
export const useRoom = () => { | ||
const room = useRecoilValue(roomState); | ||
const daily = useDaily(); | ||
const updateRoom = useRecoilCallback( | ||
({ set }) => | ||
async () => { | ||
if (!daily) return; | ||
set(roomState, await daily.room(options)); | ||
}, | ||
[daily, options] | ||
); | ||
/** | ||
* Load room as soon as daily is available. | ||
*/ | ||
useEffect(() => { | ||
if (!daily) return; | ||
updateRoom(); | ||
}, [daily, updateRoom]); | ||
useDailyEvent('loaded', updateRoom); | ||
useDailyEvent('access-state-updated', updateRoom); | ||
useDailyEvent('started-camera', updateRoom); | ||
useDailyEvent('joining-meeting', updateRoom); | ||
useDailyEvent('joined-meeting', updateRoom); | ||
return room; | ||
}; |
@@ -57,3 +57,3 @@ import { DailyScreenCaptureOptions, DailyTrackState } from '@daily-co/daily-js'; | ||
const screenIds = useParticipantIds({ | ||
filter: (p) => p.screen, | ||
filter: 'screen', | ||
}); | ||
@@ -60,0 +60,0 @@ const screens = useMemo( |
import { DailyEvent, DailyEventObject } from '@daily-co/daily-js'; | ||
import throttle from 'lodash.throttle'; | ||
import { useContext, useEffect, useMemo, useRef } from 'react'; | ||
import { DailyEventContext } from '../DailyProvider'; | ||
import { DailyEventContext } from '../DailyEventContext'; | ||
import { getUnique } from './useDailyEvent'; | ||
@@ -29,21 +30,33 @@ | ||
const emitEvents = useMemo( | ||
() => | ||
throttle( | ||
() => { | ||
if (throttledEvents.current.length === 0) return; | ||
callback(throttledEvents.current); | ||
throttledEvents.current = []; | ||
}, | ||
throttleTimeout, | ||
{ | ||
trailing: true, | ||
} | ||
), | ||
[callback, throttleTimeout] | ||
); | ||
useEffect(() => { | ||
if (!ev) return; | ||
const emitEvents = () => { | ||
if (throttledEvents.current.length === 0) return; | ||
callback(throttledEvents.current); | ||
throttledEvents.current = []; | ||
}; | ||
const interval = setInterval(emitEvents, throttleTimeout); | ||
const addEvent = (ev: DailyEventObject) => { | ||
throttledEvents.current.push(ev); | ||
/** | ||
* A 0ms timeout allows the event loop to process additional incoming events, | ||
* while the throttle is active. Otherwise every event would be delayed. | ||
*/ | ||
setTimeout(emitEvents, 0); | ||
}; | ||
on(ev, addEvent, eventId); | ||
return () => { | ||
clearInterval(interval); | ||
// Clear throttled queue | ||
emitEvents(); | ||
off(ev, eventId); | ||
}; | ||
}, [callback, ev, eventId, off, on, throttleTimeout]); | ||
}, [emitEvents, ev, eventId, off, on]); | ||
}; |
@@ -63,12 +63,14 @@ import { | ||
const handleAdded = useRecoilCallback( | ||
({ set }) => | ||
({ transact_UNSTABLE }) => | ||
(ev: DailyEventObjectWaitingParticipant) => { | ||
set(waitingParticipantsState, (wps) => { | ||
if (!wps.includes(ev.participant.id)) { | ||
return [...wps, ev.participant.id]; | ||
} | ||
return wps; | ||
transact_UNSTABLE(({ set }) => { | ||
set(waitingParticipantsState, (wps) => { | ||
if (!wps.includes(ev.participant.id)) { | ||
return [...wps, ev.participant.id]; | ||
} | ||
return wps; | ||
}); | ||
set(waitingParticipantState(ev.participant.id), ev.participant); | ||
}); | ||
set(waitingParticipantState(ev.participant.id), ev.participant); | ||
onWaitingParticipantAdded?.(ev); | ||
setTimeout(() => onWaitingParticipantAdded?.(ev), 0); | ||
}, | ||
@@ -79,9 +81,11 @@ [onWaitingParticipantAdded] | ||
const handleRemoved = useRecoilCallback( | ||
({ reset, set }) => | ||
({ transact_UNSTABLE }) => | ||
(ev: DailyEventObjectWaitingParticipant) => { | ||
set(waitingParticipantsState, (wps) => | ||
wps.filter((wp) => wp !== ev.participant.id) | ||
); | ||
reset(waitingParticipantState(ev.participant.id)); | ||
onWaitingParticipantRemoved?.(ev); | ||
transact_UNSTABLE(({ set, reset }) => { | ||
set(waitingParticipantsState, (wps) => | ||
wps.filter((wp) => wp !== ev.participant.id) | ||
); | ||
reset(waitingParticipantState(ev.participant.id)); | ||
}); | ||
setTimeout(() => onWaitingParticipantRemoved?.(ev), 0); | ||
}, | ||
@@ -95,3 +99,3 @@ [onWaitingParticipantRemoved] | ||
set(waitingParticipantState(ev.participant.id), ev.participant); | ||
onWaitingParticipantUpdated?.(ev); | ||
setTimeout(() => onWaitingParticipantUpdated?.(ev), 0); | ||
}, | ||
@@ -98,0 +102,0 @@ [onWaitingParticipantUpdated] |
@@ -0,1 +1,2 @@ | ||
export { ExtendedDailyParticipant } from './DailyParticipants'; | ||
export { DailyProvider } from './DailyProvider'; | ||
@@ -13,6 +14,3 @@ export { useActiveParticipant } from './hooks/useActiveParticipant'; | ||
export { useNetwork } from './hooks/useNetwork'; | ||
export { | ||
ExtendedDailyParticipant, | ||
useParticipant, | ||
} from './hooks/useParticipant'; | ||
export { useParticipant } from './hooks/useParticipant'; | ||
export { useParticipantIds } from './hooks/useParticipantIds'; | ||
@@ -19,0 +17,0 @@ export { useReceiveSettings } from './hooks/useReceiveSettings'; |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
790963
66
7829
5
28
+ Addedlodash.throttle@^4.1.1
+ Addedlodash.throttle@4.1.1(transitive)
+ Addedrecoil@0.7.7(transitive)
- Removedrecoil@0.5.2(transitive)