@daily-co/daily-react-hooks
Advanced tools
Comparing version 0.2.6 to 0.3.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"),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 l(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var s=n.createContext(null),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 s?t:s).prototype),o=new S(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===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,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 l={};function s(){}function f(){}function d(){}var p={};p[i]=function(){return this};var v=Object.getPrototypeOf,h=v&&v(v(x([])));h&&h!==t&&n.call(h,i)&&(p=h);var g=d.prototype=s.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 l=c(e[i],e,o);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,a,u)}),(function(e){r("throw",e,a,u)})):t.resolve(f).then((function(e){s.value=e,a(s)}),(function(e){return r("throw",e,a,u)}))}u(l.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 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 S(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(b,this),this.reset(!0)}function x(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:R}}function R(){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=x,S.prototype={constructor:S,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,l):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),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:x(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)}})),v=function(){return n.useContext(s)},h=0,g=function(){return h++},m=function(e,t){var r=n.useContext(f),i=r.off,o=r.on,a=n.useState(!1),u=a[0],c=a[1],l=n.useRef(0),s=n.useMemo((function(){return g()}),[]);n.useEffect((function(){if(e&&!u){if(l.current>1e5)return console.error("useDailyEvent called with potentially non-memoized event callback or due to too many re-renders.\n Memoize using useCallback to avoid re-render loop or reduce the amount of state transitions the callback depends on.\n Passed callback for '"+e+"' event is NOT registered.",t),void c(!0);l.current++;var n=setTimeout((function(){l.current=0}),50);return o(e,t,s),function(){clearTimeout(n),i(e,s)}}}),[t,e,s,u,i,o])},y=function(e,t,r){void 0===r&&(r=100);var i=n.useContext(f),a=i.off,u=i.on,c=n.useMemo((function(){return g()}),[]),l=n.useRef([]),s=n.useMemo((function(){return o((function(){0!==l.current.length&&(t(l.current),l.current=[])}),r,{trailing:!0})}),[t,r]);n.useEffect((function(){if(e)return u(e,(function(e){l.current.push(e),setTimeout(s,0)}),c),function(){a(e,c)}}),[s,e,c,a,u])},k=i.atom({key:"local-id",default:""}),b=i.atom({key:"participants-objects",default:[]}),w=i.selectorFamily({key:"participant",get:function(e){return function(t){var n;return null!=(n=(0,t.get)(b).find((function(t){return t.session_id===e})))?n:null}}}),S=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(w(i));case 3:if(!(a=e.sent)&&o&&(a=o.participants()[i]),a){e.next=7;break}return e.abrupt("return");case 7:t(b,(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,n.local.session_id),t(b,Object.values(n));case 2:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()}),[]);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]);var l=n.useCallback((function(){if(o){var e=null==o?void 0:o.participants();e.local&&a(e)}}),[o,a]);return m("started-camera",l),m("access-state-updated",l),m("joining-meeting",l),m("joined-meeting",n.useCallback((function(e){a(e.participants)}),[a])),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(b,(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(b,(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(b,(function(t){return[].concat(t).filter((function(t){return!e.some((function(e){return e.participant.session_id===t.session_id}))}))}))}}),[])),m("left-meeting",i.useRecoilCallback((function(e){var t=e.reset;return function(){t(k),t(b)}}),[])),r.createElement(r.Fragment,null,t)},x=i.atom({key:"room",default:null}),R=function(e){var t=e.children,n=v(),o=i.useRecoilCallback((function(e){var t=e.set;return u(p.mark((function e(){var r;return p.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n&&"left-meeting"!==n.meetingState()){e.next=2;break}return e.abrupt("return");case 2:return e.next=4,n.room();case 4:return(r=e.sent)&&"id"in r&&t(x,r),e.abrupt("return",r);case 7:case"end":return e.stop()}}),e)})))}),[n]);return m("access-state-updated",o),r.createElement(r.Fragment,null,t)},C=["children"],E=function(e,t){var r=void 0===t?{}:t,o=r.onParticipantLeft,a=r.onParticipantUpdated,u=i.useRecoilValue(w(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},L=i.atom({key:"active-id",default:""}),_=i.atomFamily({key:"media-track",default:{state:"loading",subscribed:!1}}),T=function(e,t){void 0===t&&(t="video");var r=v(),o=n.useMemo((function(){return e+"-"+t}),[e,t]),a=i.useRecoilValue(_(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.reset,r=e.set;i.forEach((function(e){switch(e.action){case"participant-joined":case"participant-updated":r(_(o),e.participant.tracks[t]);break;case"participant-left":n(_(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(_(o),e.participants.local.tracks[t])}}),[o,t]));var l=i.useRecoilCallback((function(e){var t=e.set;return function(e){e&&t(_(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&&l(i.tracks[t])}}}),[r,e,l,t]),c({},a,{isOff:"blocked"===a.state||"off"===a.state})},j=i.atom({key:"general-camera-state",default:"pending"}),I=i.atom({key:"general-microphone-state",default:"pending"}),P=i.atom({key:"camera-devices",default:[]}),A=i.atom({key:"microphone-devices",default:[]}),O=i.atom({key:"speaker-devices",default:[]}),D=i.atom({key:"input-settings",default:null}),M=i.atom({key:"input-settings-error",default:null}),V=i.atom({key:"live-streaming",default:{errorMsg:void 0,isLiveStreaming:!1,layout:void 0}}),N=function(){var e=i.useRecoilValue(k);return E(e)},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,l=t.onParticipantLeft,s=t.onParticipantUpdated,f=t.sort,d=void 0===f?G:f,v=i.useRecoilValue(b),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==s?void 0:s(e)}),0)}))}),[s])),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==l?void 0:l(e)}),0)}))}),[l])),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,C),u=n.useState("callObject"in a?a.callObject:null),c=u[0],d=u[1],p=n.useRef({});n.useEffect((function(){var e;"callObject"in a&&c&&a.callObject&&(null==c?void 0:c._callFrameId)!==(null==a||null==(e=a.callObject)?void 0:e._callFrameId)&&d(a.callObject)}),[c,a]);var 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 l(e,void 0);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?l(e,void 0):void 0}}(e))){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(null!=(r=null==(i=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(s.Provider,{value:c},r.createElement(f.Provider,{value:{on:g,off:m}},r.createElement(R,null,r.createElement(S,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(L),l=n.useState(""),s=l[1],f=E(l[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)||s(c)}}),[u,o,c]),m("active-speaker-change",i.useRecoilCallback((function(e){var t=e.set;return function(e){t(L,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 T(e,"audio")},exports.useDaily=v,exports.useDailyEvent=m,exports.useDevices=function(){var e=v(),t=i.useRecoilValue(j),r=i.useRecoilValue(I),o=i.useRecoilValue(P),a=i.useRecoilValue(A),l=i.useRecoilValue(O),s=i.useRecoilCallback((function(t){var n=t.transact_UNSTABLE;return u(p.mark((function t(){var r,i,o,a,u,c,l,s,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(j,"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})),l=u.filter((function(e){return"audioinput"===e.kind&&""!==e.deviceId})),s=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(P,(function(e){return c.filter(Boolean).map((function(t){return g(d,t,e)})).sort(m)})),t(A,(function(e){return l.filter(Boolean).map((function(t){return g(v,t,e)})).sort(m)})),t(O,(function(e){return s.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(j,"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,l,f,d,v,h,g,m,y,k,b,w,S,x,R;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(j);case 4:return b=t.sent,t.next=7,r.getPromise(I);case 7:w=t.sent,S=e.participants().local.tracks,x="pending"===b&&"interrupted"===S.video.state,R="pending"===w&&"interrupted"===S.audio.state,null!=(o=S.audio)&&null!=(a=o.blocked)&&a.byDeviceInUse?i((function(e){var t=e.set;t(I,"in-use"),t(A,(function(e){return e.map((function(e){return e.selected?c({},e,{state:"in-use"}):e}))}))})):null!=(u=S.audio)&&null!=(l=u.blocked)&&l.byDeviceMissing?n(I,"not-found"):null!=(f=S.audio)&&null!=(d=f.blocked)&&d.byPermissions?n(I,"blocked"):R||i((function(e){var t=e.set;t(I,"granted"),t(A,(function(e){return e.map((function(e){return e.selected?c({},e,{state:"granted"}):e}))}))})),null!=(v=S.video)&&null!=(h=v.blocked)&&h.byDeviceInUse?i((function(e){var t=e.set;t(j,"in-use"),t(P,(function(e){return e.map((function(e){return e.selected?c({},e,{state:"in-use"}):e}))}))})):null!=(g=S.video)&&null!=(m=g.blocked)&&m.byDeviceMissing?n(j,"not-found"):null!=(y=S.video)&&null!=(k=y.blocked)&&k.byPermissions?n(j,"blocked"):x||i((function(e){var t=e.set;t(j,"granted"),t(P,(function(e){return e.map((function(e){return e.selected?c({},e,{state:"granted"}):e}))}))})),s();case 14:case"end":return t.stop()}}),t)})))}),[e,s]);m("participant-updated",n.useCallback((function(e){e.participant.local&&f()}),[f])),m("available-devices-updated",s),m("camera-error",i.useRecoilCallback((function(e){var t=e.set,n=e.transact_UNSTABLE;return function(e){var r=e.error,i=e.errorMsg,o=i.audioOk,a=i.errorMsg,u=i.videoOk;switch(null==r?void 0:r.type){case"cam-in-use":t(j,"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(j,"in-use"),t(I,"in-use")}));break;default:switch(a){case"devices error":n((function(e){var t=e.set;u||t(j,"not-found"),o||t(I,"not-found")}));break;case"not allowed":n((function(e){var t=e.set;t(j,"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(j,"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(j,"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({audioDeviceId:null,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=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,videoDeviceId:null});case 2:s();case 3:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),[e,s]),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:return t.next=2,null==e?void 0:e.setOutputDeviceAsync({outputDeviceId:n});case 2:s();case 3:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),[e,s]);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:s,setCamera:d,setMicrophone:h,setSpeaker:g,speakers:l}},exports.useInputSettings=function(e){var t=void 0===e?{}:e,r=t.onError,o=t.onInputSettingsUpdated,a=i.useRecoilValue(D),u=i.useRecoilValue(M),c=v(),l=i.useRecoilCallback((function(e){var t=e.set;return function(e){t(D,e)}}),[]);return n.useEffect((function(){c&&c.getInputSettings().then(l)}),[c,l]),m("input-settings-updated",n.useCallback((function(e){l(e.inputSettings),setTimeout((function(){return null==o?void 0:o(e)}),0)}),[o,l])),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.onLiveStreamingError,o=t.onLiveStreamingStarted,a=t.onLiveStreamingStopped,u=v(),l=i.useRecoilValue(V);return m("live-streaming-started",i.useRecoilCallback((function(e){var t=e.set;return function(e){t(V,{isLiveStreaming:!0,layout:null==e?void 0:e.layout}),setTimeout((function(){return null==o?void 0:o(e)}),0)}}),[o])),m("live-streaming-stopped",i.useRecoilCallback((function(e){var t=e.set;return function(e){t(V,(function(e){return c({},e,{isLiveStreaming:!1,layout:void 0})})),setTimeout((function(){return null==a?void 0:a(e)}),0)}}),[a])),m("live-streaming-error",i.useRecoilCallback((function(e){var t=e.set;return function(e){t(V,(function(t){return c({},t,{errorMsg:e.errorMsg})})),setTimeout((function(){return null==r?void 0:r(e)}),0)}}),[r])),c({},l,{startLiveStreaming:n.useCallback((function(e){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=T,exports.useNetwork=function(e){var t=void 0===e?{}:e,r=t.onNetworkConnection,o=t.onNetworkQualityChange,a=v(),c=i.useRecoilValue(U),l=i.useRecoilValue(B),s=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:l,threshold:s,topology:c}},exports.useParticipant=E,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")),l=i.useRecoilValue(z(o)),s=v();m("receive-settings-updated",i.useRecoilCallback((function(e){var t=e.transact_UNSTABLE;return function(e){t((function(t){for(var n=t.reset,r=t.set,i=c({},e.receiveSettings),a=0,u=Object.entries(i);a<u.length;a++){var l=u[a],s=l[1];r(z(l[0]),s)}o in i||n(z(o))})),setTimeout((function(){return null==a?void 0:a(e)}),0)}}),[o,a]));var f=n.useCallback((function(e){s&&"joined-meeting"===s.meetingState()&&(null==s||null==s.updateReceiveSettings||s.updateReceiveSettings(e))}),[s]);return{receiveSettings:"base"===o||0===Object.keys(l).length?u:l,updateReceiveSettings:f}},exports.useRecording=function(e){var t=void 0===e?{}:e,r=t.onRecordingData,o=t.onRecordingError,a=t.onRecordingStarted,u=t.onRecordingStopped,l=v(),s=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 r;d&&"single-participant"===(null==(r=e.layout)?void 0:r.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==a?void 0:a(e)}),0)}}),[d,a])),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==u?void 0:u(e)}),0)}}),[u])),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==o?void 0:o(e)}),0)}}),[o])),m("recording-data",n.useCallback((function(e){null==r||r(e)}),[r])),c({},s,{startRecording:n.useCallback((function(e){l&&l.startRecording(e)}),[l]),stopRecording:n.useCallback((function(){l&&l.stopRecording()}),[l]),updateRecording:n.useCallback((function(e){l&&l.updateRecording(e)}),[l])})},exports.useRoom=function(){return i.useRecoilValue(x)},exports.useScreenAudioTrack=function(e){return T(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"}),l=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:l.some((function(e){return e.local})),screens:l,startScreenShare:a,stopScreenShare:u}},exports.useScreenVideoTrack=function(e){return T(e,"screenVideo")},exports.useThrottledDailyEvent=y,exports.useVideoTrack=function(e){return T(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($),l=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]),s=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",l),m("waiting-participant-removed",s),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])}}; | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=e(require("@daily-co/daily-js")),n=require("react"),i=e(n),r=require("recoil"),a=e(require("lodash.throttle"));function u(e,t,n,i,r,a,u){try{var o=e[a](u),c=o.value}catch(e){return void n(e)}o.done?t(c):Promise.resolve(c).then(i,r)}function o(e){return function(){var t=this,n=arguments;return new Promise((function(i,r){var a=e.apply(t,n);function o(e){u(a,i,r,o,c,"next",e)}function c(e){u(a,i,r,o,c,"throw",e)}o(void 0)}))}}function c(){return(c=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e}).apply(this,arguments)}function l(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,i=new Array(t);n<t;n++)i[n]=e[n];return i}var s=n.createContext(null),d=n.createContext({on:function(){},off:function(){}}),f=function(){return n.useContext(s)},v=0,p=function(){return v++},g=function(e,t){var i=n.useContext(d),r=i.off,a=i.on,u=n.useState(!1),o=u[0],c=u[1],l=n.useRef(0),s=n.useMemo((function(){return p()}),[]);n.useEffect((function(){if(e&&!o){if(l.current>1e5)return console.error("useDailyEvent called with potentially non-memoized event callback or due to too many re-renders.\n Memoize using useCallback to avoid re-render loop or reduce the amount of state transitions the callback depends on.\n Passed callback for '"+e+"' event is NOT registered.",t),void c(!0);l.current++;var n=setTimeout((function(){l.current=0}),50);return a(e,t,s),function(){clearTimeout(n),r(e,s)}}}),[t,e,s,o,r,a])},m=function(e,t,i){void 0===i&&(i=100);var r=n.useContext(d),u=r.off,o=r.on,c=n.useMemo((function(){return p()}),[]),l=n.useRef([]),s=n.useMemo((function(){return a((function(){0!==l.current.length&&(t(l.current),l.current=[])}),i,{trailing:!0})}),[t,i]);n.useEffect((function(){if(e)return o(e,(function(e){l.current.push(e),setTimeout(s,0)}),c),function(){u(e,c)}}),[s,e,c,u,o])},k=r.atom({key:"local-id",default:""}),b=r.atom({key:"participants-objects",default:[]}),y=r.selectorFamily({key:"participant",get:function(e){return function(t){var n;return null!=(n=(0,t.get)(b).find((function(t){return t.session_id===e})))?n:null}}}),h=r.selectorFamily({key:"participant-property",get:function(e){var t=e.id,n=e.property;return function(e){var i,r=null!=(i=(0,e.get)(b).find((function(e){return e.session_id===t})))?i:null;return r?function(e,t){return t.split(".").reduce((function(e,t){return null==e?void 0:e[t]}),e)}(r,n):null}}}),R=function(e){var t=e.children,a=f();g("active-speaker-change",r.useRecoilCallback((function(e){var t=e.set,n=e.snapshot;return function(){var e=o((function*(e){var i=e.activeSpeaker.peerId,r=yield n.getPromise(y(i));!r&&a&&(r=a.participants()[i]),r&&t(b,(function(e){return[].concat(e).map((function(e){return e.session_id===i?c({},e,{last_active:new Date}):e}))}))}));return function(t){return e.apply(this,arguments)}}()}),[a]));var u=r.useRecoilCallback((function(e){var t=e.set;return function(){var e=o((function*(e){t(k,e.local.session_id),t(b,Object.values(e))}));return function(t){return e.apply(this,arguments)}}()}),[]);n.useEffect((function(){if(a){var e=setInterval((function(){var t=a.participants();"local"in t&&(u(t),clearInterval(e))}),100);return function(){clearInterval(e)}}}),[a,u]);var l=n.useCallback((function(){if(a){var e=null==a?void 0:a.participants();e.local&&u(e)}}),[a,u]);return g("started-camera",l),g("access-state-updated",l),g("joining-meeting",l),g("joined-meeting",n.useCallback((function(e){u(e.participants)}),[u])),m("participant-joined",r.useRecoilCallback((function(e){var t=e.set;return function(){var e=o((function*(e){e.length&&t(b,(function(t){return[].concat(t,e.map((function(e){return e.participant}))).filter((function(e,t,n){return n.findIndex((function(t){return t.session_id===e.session_id}))==t}))}))}));return function(t){return e.apply(this,arguments)}}()}),[])),m("participant-updated",r.useRecoilCallback((function(e){var t=e.transact_UNSTABLE;return function(e){t((function(t){var n=t.set;e.forEach((function(e){var t=e.participant;n(b,(function(e){return[].concat(e).map((function(e){return e.session_id===t.session_id?t:e}))}))}))}))}}),[])),m("participant-left",r.useRecoilCallback((function(e){var t=e.set;return function(e){t(b,(function(t){return[].concat(t).filter((function(t){return!e.some((function(e){return e.participant.session_id===t.session_id}))}))}))}}),[])),g("left-meeting",r.useRecoilCallback((function(e){var t=e.reset;return function(){t(k),t(b)}}),[])),i.createElement(i.Fragment,null,t)},S=r.atom({key:"room",default:null}),C=function(e){var t=e.children,n=f(),a=r.useRecoilCallback((function(e){var t=e.set;return o((function*(){if(n&&"left-meeting"!==n.meetingState()){var e=yield n.room();return e&&"id"in e&&t(S,e),e}}))}),[n]);return g("access-state-updated",a),i.createElement(i.Fragment,null,t)},T=function(e,t){var i=void 0===t?{}:t,a=i.onParticipantLeft,u=i.onParticipantUpdated,o=r.useRecoilValue(y(e));return m("participant-updated",n.useCallback((function(t){var n=t.filter((function(t){return t.participant.session_id===e}));n.length&&n.forEach((function(e){setTimeout((function(){return null==u?void 0:u(e)}),0)}))}),[u,e])),m("participant-left",n.useCallback((function(t){if(t.filter((function(t){return t.participant.session_id===e})).length){var n=t[t.length-1];setTimeout((function(){return null==a?void 0:a(n)}),0)}}),[a,e])),o},E=r.atom({key:"active-id",default:""}),I=r.atomFamily({key:"media-track",default:{state:"loading",subscribed:!1}}),_=function(e,t){void 0===t&&(t="video");var i=f(),a=n.useMemo((function(){return e+"-"+t}),[e,t]),u=r.useRecoilValue(I(a)),o=r.useRecoilCallback((function(n){var i=n.transact_UNSTABLE;return function(n){var r=n.filter((function(t){return t.participant.session_id===e}));r.length&&i((function(e){var n=e.reset,i=e.set;r.forEach((function(e){switch(e.action){case"participant-joined":case"participant-updated":i(I(a),e.participant.tracks[t]);break;case"participant-left":n(I(a))}}))}))}}),[a,e,t]);m("participant-joined",o),m("participant-updated",o),m("participant-left",o),g("joined-meeting",r.useRecoilCallback((function(e){var n=e.set;return function(e){n(I(a),e.participants.local.tracks[t])}}),[a,t]));var l=r.useRecoilCallback((function(e){var t=e.set;return function(e){e&&t(I(a),e)}}),[a]);return n.useEffect((function(){var n,r;if(i){var a=null==i?void 0:i.participants();if(a){var u=Object.values(a).find((function(t){return t.session_id===e}));u&&l(null!=(n=null==(r=u.tracks)?void 0:r[t])?n:null)}}}),[i,e,l,t]),u?c({},u,{isOff:"blocked"===u.state||"off"===u.state}):{isOff:!0,persistentTrack:void 0,state:"off",subscribed:!1}},w=r.atom({key:"general-camera-state",default:"pending"}),A=r.atom({key:"general-microphone-state",default:"pending"}),L=r.atom({key:"camera-devices",default:[]}),P=r.atom({key:"microphone-devices",default:[]}),j=r.atom({key:"speaker-devices",default:[]}),x=r.atom({key:"input-settings",default:null}),O=r.atom({key:"input-settings-error",default:null}),D=r.atom({key:"live-streaming",default:{errorMsg:void 0,isLiveStreaming:!1,layout:void 0}}),V=function(){return r.useRecoilValue(k)||null},M=r.atom({key:"topology",default:"peer"}),U=r.atom({key:"networkQuality",default:100}),B=r.atom({key:"networkThreshold",default:"good"}),N=Boolean,q=function(){return 0},F=function(e){var t=void 0===e?{filter:N,sort:q}:e,i=t.filter,a=void 0===i?N:i,u=t.onActiveSpeakerChange,c=t.onParticipantJoined,l=t.onParticipantLeft,s=t.onParticipantUpdated,d=t.sort,f=void 0===d?q:d,v=r.useRecoilValue(b),p=n.useMemo((function(){var e,t=N;switch(a){case"local":t=function(e){return e.local};break;case"owner":t=function(e){return e.owner};break;case"record":t=function(e){return e.record};break;case"remote":t=function(e){return!e.local};break;case"screen":t=function(e){return e.screen};break;default:t=a}switch(f){case"joined_at":case"session_id":case"user_id":case"user_name":e=function(e,t){return e[f]<t[f]?-1:e[f]>t[f]?1:0};break;default:e=f}return v.filter(t).sort(e).map((function(e){return e.session_id})).filter(Boolean)}),[v,a,f]);return m("participant-joined",n.useCallback((function(e){e.length&&e.forEach((function(e){return setTimeout((function(){return null==c?void 0:c(e)}),0)}))}),[c])),m("participant-updated",n.useCallback((function(e){e.length&&e.forEach((function(e){return setTimeout((function(){return null==s?void 0:s(e)}),0)}))}),[s])),m("active-speaker-change",n.useCallback(function(){var e=o((function*(e){e.length&&e.forEach((function(e){return setTimeout((function(){return null==u?void 0:u(e)}),0)}))}));return function(t){return e.apply(this,arguments)}}(),[u])),m("participant-left",n.useCallback((function(e){e.length&&e.forEach((function(e){return setTimeout((function(){return null==l?void 0:l(e)}),0)}))}),[l])),p},W=r.atomFamily({key:"participant-receive-settings",default:{}}),z=r.atom({key:"recording",default:{isLocalParticipantRecorded:!1,isRecording:!1}}),Q=r.atom({key:"waiting-participants",default:[]}),J=r.atomFamily({key:"waiting-participant",default:{awaitingAccess:{level:"full"},id:"",name:""}}),$=r.selector({key:"waitingParticipantsSelector",get:function(e){var t=e.get;return t(Q).map((function(e){return t(J(e))}))}});exports.DailyProvider=function(e){var a=e.children,u=function(e,t){if(null==e)return{};var n,i,r={},a=Object.keys(e);for(i=0;i<a.length;i++)t.indexOf(n=a[i])>=0||(r[n]=e[n]);return r}(e,["children"]),o=n.useState("callObject"in u?u.callObject:null),c=o[0],f=o[1],v=n.useRef({});n.useEffect((function(){var e;"callObject"in u&&c&&u.callObject&&(null==c?void 0:c._callFrameId)!==(null==u||null==(e=u.callObject)?void 0:e._callFrameId)&&f(u.callObject)}),[c,u]);var p=n.useCallback((function(e){if("action"in e)for(var t,n=function(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return l(e,void 0);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?l(e,void 0):void 0}}(e))){n&&(e=n);var i=0;return function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(null!=(i=null==(r=v.current)||null==(a=r[e.action])?void 0:a.values())?i:[]);!(t=n()).done;){var i,r,a;(0,t.value)(e)}}),[]),g=n.useCallback((function(e){e&&Object.keys(v.current).forEach((function(t){e.off(t,p).on(t,p)}))}),[p]);n.useEffect((function(){if(!c){if("callObject"in u)return f(u.callObject),void g(u.callObject);var e=t.createCallObject(u);f(e),g(e)}}),[c,g,u]);var m=n.useCallback((function(e,t,n){var i,r;v.current[e]||(v.current[e]=new Map,c&&c.off(e,p).on(e,p)),(null==(i=v.current[e])?void 0:i.has(n))||null==(r=v.current[e])||r.set(n,t)}),[c,p]),k=n.useCallback((function(e,t){var n,i;null==(n=v.current[e])||n.delete(t),0===(null==(i=v.current[e])?void 0:i.size)&&(null==c||c.off(e,p),delete v.current[e])}),[c,p]);return i.createElement(r.RecoilRoot,null,i.createElement(s.Provider,{value:c},i.createElement(d.Provider,{value:{on:m,off:k}},i.createElement(C,null,i.createElement(R,null,a)))))},exports.useActiveParticipant=function(e){var t=void 0===e?{}:e,i=t.ignoreLocal,a=void 0!==i&&i,u=t.onActiveSpeakerChange,o=f(),c=r.useRecoilValue(E),l=n.useState(""),s=l[1],d=T(l[0]);return n.useEffect((function(){var e;if(o){var t=null==o||null==(e=o.participants())?void 0:e.local;a&&c===(null==t?void 0:t.session_id)||s(c)}}),[o,a,c]),g("active-speaker-change",r.useRecoilCallback((function(e){var t=e.set;return function(e){t(E,e.activeSpeaker.peerId),setTimeout((function(){return null==u?void 0:u(e)}),0)}}),[u])),d},exports.useAppMessage=function(e){var t=(void 0===e?{}:e).onAppMessage,i=f(),r=n.useCallback((function(e,t){void 0===t&&(t="*"),i&&i.sendAppMessage(e,t)}),[i]),a=n.useCallback((function(e){null==t||t(e,r)}),[t,r]);return g("app-message",a),r},exports.useAudioTrack=function(e){return _(e,"audio")},exports.useDaily=f,exports.useDailyEvent=g,exports.useDevices=function(){var e=f(),t=r.useRecoilValue(w),i=r.useRecoilValue(A),a=r.useRecoilValue(L),u=r.useRecoilValue(P),l=r.useRecoilValue(j),s=r.useRecoilCallback((function(t){var n=t.transact_UNSTABLE;return o((function*(){var t,i,r,a;if(void 0!==(null==(t=navigator)||null==(i=t.mediaDevices)?void 0:i.getUserMedia)&&void 0!==(null==(r=navigator)||null==(a=r.mediaDevices)?void 0:a.enumerateDevices)){if(e)try{var u=(yield e.enumerateDevices()).devices,o=u.filter((function(e){return"videoinput"===e.kind&&""!==e.deviceId})),c=u.filter((function(e){return"audioinput"===e.kind&&""!==e.deviceId})),l=u.filter((function(e){return"audiooutput"===e.kind&&""!==e.deviceId})),s=yield e.getInputDevices(),d=s.camera,f=s.mic,v=s.speaker,p=function(e,t,n){var i,r;return{device:t,selected:"deviceId"in e&&t.deviceId===e.deviceId,state:null!=(i=null==(r=n.find((function(e){return e.device.deviceId===t.deviceId})))?void 0:r.state)?i:"granted"}},g=function(e,t){return"default"===e.device.deviceId?-1:"default"===t.device.deviceId?1:e.device.label<t.device.label?-1:e.device.label>t.device.label?1:0};n((function(e){var t=e.set;t(L,(function(e){return o.filter(Boolean).map((function(t){return p(d,t,e)})).sort(g)})),t(P,(function(e){return c.filter(Boolean).map((function(t){return p(f,t,e)})).sort(g)})),t(j,(function(e){return l.filter(Boolean).map((function(t){return p(v,t,e)})).sort(g)}))}))}catch(e){n((function(e){var t=e.set;t(w,"not-supported"),t(A,"not-supported")}))}}else n((function(e){var t=e.set;t(w,"not-supported"),t(A,"not-supported")}))}))}),[e]),d=r.useRecoilCallback((function(t){var n=t.set,i=t.snapshot,r=t.transact_UNSTABLE;return o((function*(){var t,a,u,o,l,d,f,v,p,g,m,k;if(e){var b=yield i.getPromise(w),y=yield i.getPromise(A),h=e.participants().local.tracks,R="pending"===b&&"interrupted"===h.video.state,S="pending"===y&&"interrupted"===h.audio.state;(null==(t=h.audio)||null==(a=t.blocked)?void 0:a.byDeviceInUse)?r((function(e){var t=e.set;t(A,"in-use"),t(P,(function(e){return e.map((function(e){return e.selected?c({},e,{state:"in-use"}):e}))}))})):(null==(u=h.audio)||null==(o=u.blocked)?void 0:o.byDeviceMissing)?n(A,"not-found"):(null==(l=h.audio)||null==(d=l.blocked)?void 0:d.byPermissions)?n(A,"blocked"):S||r((function(e){var t=e.set;t(A,"granted"),t(P,(function(e){return e.map((function(e){return e.selected?c({},e,{state:"granted"}):e}))}))})),(null==(f=h.video)||null==(v=f.blocked)?void 0:v.byDeviceInUse)?r((function(e){var t=e.set;t(w,"in-use"),t(L,(function(e){return e.map((function(e){return e.selected?c({},e,{state:"in-use"}):e}))}))})):(null==(p=h.video)||null==(g=p.blocked)?void 0:g.byDeviceMissing)?n(w,"not-found"):(null==(m=h.video)||null==(k=m.blocked)?void 0:k.byPermissions)?n(w,"blocked"):R||r((function(e){var t=e.set;t(w,"granted"),t(L,(function(e){return e.map((function(e){return e.selected?c({},e,{state:"granted"}):e}))}))})),s()}}))}),[e,s]);g("participant-updated",n.useCallback((function(e){e.participant.local&&d()}),[d])),g("available-devices-updated",s),g("camera-error",r.useRecoilCallback((function(e){var t=e.set,n=e.transact_UNSTABLE;return function(e){var i=e.error,r=e.errorMsg,a=r.audioOk,u=r.errorMsg,o=r.videoOk;switch(null==i?void 0:i.type){case"cam-in-use":t(w,"in-use");break;case"mic-in-use":t(A,"in-use");break;case"cam-mic-in-use":n((function(e){var t=e.set;t(w,"in-use"),t(A,"in-use")}));break;default:switch(u){case"devices error":n((function(e){var t=e.set;o||t(w,"not-found"),a||t(A,"not-found")}));break;case"not allowed":n((function(e){var t=e.set;t(w,"blocked"),t(A,"blocked")})),d()}}}}),[d])),g("error",r.useRecoilCallback((function(e){var t=e.transact_UNSTABLE;return function(e){switch(e.errorMsg){case"not allowed":t((function(e){var t=e.set;t(w,"blocked"),t(A,"blocked")})),d()}}}),[d])),g("started-camera",r.useRecoilCallback((function(e){var t=e.transact_UNSTABLE;return function(){t((function(e){var t=e.set;t(w,"granted"),t(A,"granted")})),d()}}),[d]));var v=n.useCallback(function(){var t=o((function*(t){yield null==e?void 0:e.setInputDevicesAsync({audioDeviceId:null,videoDeviceId:t}),s()}));return function(e){return t.apply(this,arguments)}}(),[e,s]),p=n.useCallback(function(){var t=o((function*(t){yield null==e?void 0:e.setInputDevicesAsync({audioDeviceId:t,videoDeviceId:null}),s()}));return function(e){return t.apply(this,arguments)}}(),[e,s]),m=n.useCallback(function(){var t=o((function*(t){yield null==e?void 0:e.setOutputDeviceAsync({outputDeviceId:t}),s()}));return function(e){return t.apply(this,arguments)}}(),[e,s]);return{cameras:a,camState:t,hasCamError:["blocked","in-use","not-found"].includes(t),hasMicError:["blocked","in-use","not-found"].includes(i),microphones:u,micState:i,refreshDevices:s,setCamera:v,setMicrophone:p,setSpeaker:m,speakers:l}},exports.useInputSettings=function(e){var t=void 0===e?{}:e,i=t.onError,a=t.onInputSettingsUpdated,u=r.useRecoilValue(x),o=r.useRecoilValue(O),c=f(),l=r.useRecoilCallback((function(e){var t=e.set;return function(e){t(x,e)}}),[]);return n.useEffect((function(){c&&c.getInputSettings().then(l)}),[c,l]),g("input-settings-updated",n.useCallback((function(e){l(e.inputSettings),setTimeout((function(){return null==a?void 0:a(e)}),0)}),[a,l])),g("nonfatal-error",r.useRecoilCallback((function(e){var t=e.set;return function(e){"input-settings-error"===e.type&&(t(O,e.errorMsg),setTimeout((function(){return null==i?void 0:i(e)}),0))}}),[i])),{errorMsg:o,inputSettings:u,updateInputSettings:n.useCallback((function(e){null==c||c.updateInputSettings(e)}),[c])}},exports.useLiveStreaming=function(e){var t=void 0===e?{}:e,i=t.onLiveStreamingError,a=t.onLiveStreamingStarted,u=t.onLiveStreamingStopped,o=f(),l=r.useRecoilValue(D);return g("live-streaming-started",r.useRecoilCallback((function(e){var t=e.set;return function(e){t(D,{isLiveStreaming:!0,layout:null==e?void 0:e.layout}),setTimeout((function(){return null==a?void 0:a(e)}),0)}}),[a])),g("live-streaming-stopped",r.useRecoilCallback((function(e){var t=e.set;return function(e){t(D,(function(e){return c({},e,{isLiveStreaming:!1,layout:void 0})})),setTimeout((function(){return null==u?void 0:u(e)}),0)}}),[u])),g("live-streaming-error",r.useRecoilCallback((function(e){var t=e.set;return function(e){t(D,(function(t){return c({},t,{errorMsg:e.errorMsg})})),setTimeout((function(){return null==i?void 0:i(e)}),0)}}),[i])),c({},l,{startLiveStreaming:n.useCallback((function(e){o&&o.startLiveStreaming(e)}),[o]),stopLiveStreaming:n.useCallback((function(){o&&o.stopLiveStreaming()}),[o]),updateLiveStreaming:n.useCallback((function(e){o&&o.updateLiveStreaming({layout:e.layout})}),[o])})},exports.useLocalParticipant=function(){var e=r.useRecoilValue(k);return T(e)},exports.useLocalSessionId=V,exports.useMediaTrack=_,exports.useNetwork=function(e){var t=void 0===e?{}:e,i=t.onNetworkConnection,a=t.onNetworkQualityChange,u=f(),c=r.useRecoilValue(M),l=r.useRecoilValue(U),s=r.useRecoilValue(B),d=r.useRecoilCallback((function(e){var t=e.transact_UNSTABLE;return function(e){t((function(t){var n=t.set;switch(e.event){case"connected":"peer-to-peer"===e.type&&n(M,"peer"),"sfu"===e.type&&n(M,"sfu")}})),setTimeout((function(){return null==i?void 0:i(e)}),0)}}),[i]),v=r.useRecoilCallback((function(e){var t=e.transact_UNSTABLE;return function(e){t((function(t){var n=t.set;n(U,(function(t){return t!==e.quality?e.quality:t})),n(B,(function(t){return t!==e.threshold?e.threshold:t}))})),setTimeout((function(){return null==a?void 0:a(e)}),0)}}),[a]);return g("network-connection",d),g("network-quality-change",v),{getStats:n.useCallback(o((function*(){var e=yield null==u?void 0:u.getNetworkStats();return null==e?void 0:e.stats})),[u]),quality:l,threshold:s,topology:c}},exports.useParticipant=T,exports.useParticipantIds=F,exports.useParticipantProperty=function(e,t){return r.useRecoilValue(h({id:e,property:t}))},exports.useReceiveSettings=function(e){var t=void 0===e?{}:e,i=t.id,a=void 0===i?"base":i,u=t.onReceiveSettingsUpdated,o=r.useRecoilValue(W("base")),l=r.useRecoilValue(W(a)),s=f();g("receive-settings-updated",r.useRecoilCallback((function(e){var t=e.transact_UNSTABLE;return function(e){t((function(t){for(var n=t.reset,i=t.set,r=c({},e.receiveSettings),u=0,o=Object.entries(r);u<o.length;u++){var l=o[u],s=l[1];i(W(l[0]),s)}a in r||n(W(a))})),setTimeout((function(){return null==u?void 0:u(e)}),0)}}),[a,u]));var d=n.useCallback((function(e){s&&"joined-meeting"===s.meetingState()&&(null==s||null==s.updateReceiveSettings||s.updateReceiveSettings(e))}),[s]);return{receiveSettings:"base"===a||0===Object.keys(l).length?o:l,updateReceiveSettings:d}},exports.useRecording=function(e){var t=void 0===e?{}:e,i=t.onRecordingData,a=t.onRecordingError,u=t.onRecordingStarted,o=t.onRecordingStopped,l=f(),s=r.useRecoilValue(z),d=r.useSetRecoilState(z),v=V(),p=F({filter:"record"});return n.useEffect((function(){var e=p.length>0,t=p.includes(null!=v?v:"local");d((function(n){return c({},n,{isLocalParticipantRecorded:"local"!==(null==n?void 0:n.type)&&(null==n?void 0:n.type)?n.isLocalParticipantRecorded:e,isRecording:"local"!==(null==n?void 0:n.type)&&(null==n?void 0:n.type)?n.isRecording:e,local:"local"!==(null==n?void 0:n.type)&&(null==n?void 0:n.type)||!e?null==n?void 0:n.local:t,type:e?"local":null==n?void 0:n.type})}))}),[v,p,d]),g("recording-started",r.useRecoilCallback((function(e){var t=e.set;return function(e){var n=!0;switch(e.type){case"cloud-beta":case"cloud":var i;v&&"single-participant"===(null==(i=e.layout)?void 0:i.preset)&&e.layout.session_id!==v&&(n=!1)}t(z,{error:!1,isLocalParticipantRecorded:n,isRecording:!0,layout:null==e?void 0:e.layout,local:null==e?void 0:e.local,recordingId:null==e?void 0:e.recordingId,recordingStartedDate:new Date,startedBy:null==e?void 0:e.startedBy,type:null==e?void 0:e.type}),setTimeout((function(){return null==u?void 0:u(e)}),0)}}),[v,u])),g("recording-stopped",r.useRecoilCallback((function(e){var t=e.set;return function(e){t(z,(function(e){return c({},e,{isLocalParticipantRecorded:!1,isRecording:!1})})),setTimeout((function(){return null==o?void 0:o(e)}),0)}}),[o])),g("recording-error",r.useRecoilCallback((function(e){var t=e.set;return function(e){t(z,(function(e){return c({},e,{error:!0,isLocalParticipantRecorded:!1,isRecording:!1})})),setTimeout((function(){return null==a?void 0:a(e)}),0)}}),[a])),g("recording-data",n.useCallback((function(e){null==i||i(e)}),[i])),c({},s,{startRecording:n.useCallback((function(e){l&&l.startRecording(e)}),[l]),stopRecording:n.useCallback((function(){l&&l.stopRecording()}),[l]),updateRecording:n.useCallback((function(e){l&&l.updateRecording(e)}),[l])})},exports.useRoom=function(){return r.useRecoilValue(S)},exports.useScreenAudioTrack=function(e){return _(e,"screenAudio")},exports.useScreenShare=function(e){var t=void 0===e?{}:e,i=t.onLocalScreenShareStarted,r=t.onLocalScreenShareStopped,a=f(),u=n.useCallback((function(e){null==a||a.startScreenShare(e)}),[a]),o=n.useCallback((function(){null==a||a.stopScreenShare()}),[a]);g("local-screen-share-started",n.useCallback((function(){return null==i?void 0:i()}),[i])),g("local-screen-share-stopped",n.useCallback((function(){return null==r?void 0:r()}),[r]));var c=F({filter:"screen"}),l=n.useMemo((function(){return c.map((function(e){var t,n=Object.values(null!=(t=null==a||null==a.participants?void 0:a.participants())?t:{}).find((function(t){return t.session_id===e}));if(n)return{local:n.local,screenAudio:n.tracks.screenAudio,screenVideo:n.tracks.screenVideo,screenId:e+"-screen",session_id:e}})).filter((function(e){return!!e}))}),[a,c]);return{isSharingScreen:l.some((function(e){return e.local})),screens:l,startScreenShare:u,stopScreenShare:o}},exports.useScreenVideoTrack=function(e){return _(e,"screenVideo")},exports.useThrottledDailyEvent=m,exports.useVideoTrack=function(e){return _(e,"video")},exports.useWaitingParticipants=function(e){var t=void 0===e?{}:e,i=t.onWaitingParticipantAdded,a=t.onWaitingParticipantRemoved,u=t.onWaitingParticipantUpdated,o=f(),c=r.useRecoilValue($),l=r.useRecoilCallback((function(e){var t=e.transact_UNSTABLE;return function(e){t((function(t){var n=t.set;n(Q,(function(t){return t.includes(e.participant.id)?t:[].concat(t,[e.participant.id])})),n(J(e.participant.id),e.participant)})),setTimeout((function(){return null==i?void 0:i(e)}),0)}}),[i]),s=r.useRecoilCallback((function(e){var t=e.transact_UNSTABLE;return function(e){t((function(t){var n=t.reset;(0,t.set)(Q,(function(t){return t.filter((function(t){return t!==e.participant.id}))})),n(J(e.participant.id))})),setTimeout((function(){return null==a?void 0:a(e)}),0)}}),[a]),d=r.useRecoilCallback((function(e){var t=e.set;return function(e){t(J(e.participant.id),e.participant),setTimeout((function(){return null==u?void 0:u(e)}),0)}}),[u]);g("waiting-participant-added",l),g("waiting-participant-removed",s),g("waiting-participant-updated",d);var v=n.useCallback((function(e,t){"*"!==e?null==o||o.updateWaitingParticipant(e,{grantRequestedAccess:t}):null==o||o.updateWaitingParticipants({"*":{grantRequestedAccess:t}})}),[o]);return{waitingParticipants:c,grantAccess:n.useCallback((function(e){v(e,!0)}),[v]),denyAccess:n.useCallback((function(e){v(e,!1)}),[v])}}; | ||
//# sourceMappingURL=daily-react-hooks.cjs.production.min.js.map |
import { DailyParticipant } from '@daily-co/daily-js'; | ||
import React from 'react'; | ||
import type { Paths } from '../types/paths'; | ||
/** | ||
@@ -9,8 +10,17 @@ * Extends DailyParticipant with convenient additional properties. | ||
} | ||
declare type PropertyType = { | ||
id: string; | ||
property: Paths<ExtendedDailyParticipant>; | ||
}; | ||
export declare const localIdState: import("recoil").RecoilState<string>; | ||
export declare const participantsState: import("recoil").RecoilState<ExtendedDailyParticipant[]>; | ||
/** | ||
* Holds each inidividual participant's state object. | ||
* Holds each individual participant's state object. | ||
*/ | ||
export declare const participantState: (param: string) => import("recoil").RecoilValueReadOnly<ExtendedDailyParticipant | null>; | ||
/** | ||
* Holds each individual participant's property. | ||
*/ | ||
export declare const participantPropertyState: (param: PropertyType) => import("recoil").RecoilValueReadOnly<any>; | ||
export declare const DailyParticipants: React.FC<React.PropsWithChildren<{}>>; | ||
export {}; |
@@ -5,18 +5,2 @@ /** | ||
*/ | ||
export declare const useAudioTrack: (participantId: string) => { | ||
isOff: boolean; | ||
subscribed: import("@daily-co/daily-js").DailyTrackSubscriptionState; | ||
state: "blocked" | "off" | "sendable" | "loading" | "interrupted" | "playable"; | ||
blocked?: { | ||
byDeviceMissing?: boolean | undefined; | ||
byDeviceInUse?: boolean | undefined; | ||
byPermissions?: boolean | undefined; | ||
} | undefined; | ||
off?: { | ||
byUser?: boolean | undefined; | ||
byRemoteRequest?: boolean | undefined; | ||
byBandwidth?: boolean | undefined; | ||
} | undefined; | ||
track?: MediaStreamTrack | undefined; | ||
persistentTrack?: MediaStreamTrack | undefined; | ||
}; | ||
export declare const useAudioTrack: (participantId: string) => import("./useMediaTrack").MediaTrackState; |
@@ -1,3 +0,6 @@ | ||
import { DailyParticipant } from '@daily-co/daily-js'; | ||
import { DailyParticipant, DailyTrackState } from '@daily-co/daily-js'; | ||
declare type MediaType = keyof DailyParticipant['tracks']; | ||
export interface MediaTrackState extends DailyTrackState { | ||
isOff: boolean; | ||
} | ||
/** | ||
@@ -11,19 +14,3 @@ * Returns a participant's track and state, based on the given MediaType. | ||
*/ | ||
export declare const useMediaTrack: (participantId: string, type?: MediaType) => { | ||
isOff: boolean; | ||
subscribed: import("@daily-co/daily-js").DailyTrackSubscriptionState; | ||
state: "blocked" | "off" | "sendable" | "loading" | "interrupted" | "playable"; | ||
blocked?: { | ||
byDeviceMissing?: boolean | undefined; | ||
byDeviceInUse?: boolean | undefined; | ||
byPermissions?: boolean | undefined; | ||
} | undefined; | ||
off?: { | ||
byUser?: boolean | undefined; | ||
byRemoteRequest?: boolean | undefined; | ||
byBandwidth?: boolean | undefined; | ||
} | undefined; | ||
track?: MediaStreamTrack | undefined; | ||
persistentTrack?: MediaStreamTrack | undefined; | ||
}; | ||
export declare const useMediaTrack: (participantId: string, type?: MediaType) => MediaTrackState; | ||
export {}; |
@@ -5,18 +5,2 @@ /** | ||
*/ | ||
export declare const useScreenAudioTrack: (participantId: string) => { | ||
isOff: boolean; | ||
subscribed: import("@daily-co/daily-js").DailyTrackSubscriptionState; | ||
state: "blocked" | "off" | "sendable" | "loading" | "interrupted" | "playable"; | ||
blocked?: { | ||
byDeviceMissing?: boolean | undefined; | ||
byDeviceInUse?: boolean | undefined; | ||
byPermissions?: boolean | undefined; | ||
} | undefined; | ||
off?: { | ||
byUser?: boolean | undefined; | ||
byRemoteRequest?: boolean | undefined; | ||
byBandwidth?: boolean | undefined; | ||
} | undefined; | ||
track?: MediaStreamTrack | undefined; | ||
persistentTrack?: MediaStreamTrack | undefined; | ||
}; | ||
export declare const useScreenAudioTrack: (participantId: string) => import("./useMediaTrack").MediaTrackState; |
@@ -5,18 +5,2 @@ /** | ||
*/ | ||
export declare const useScreenVideoTrack: (participantId: string) => { | ||
isOff: boolean; | ||
subscribed: import("@daily-co/daily-js").DailyTrackSubscriptionState; | ||
state: "blocked" | "off" | "sendable" | "loading" | "interrupted" | "playable"; | ||
blocked?: { | ||
byDeviceMissing?: boolean | undefined; | ||
byDeviceInUse?: boolean | undefined; | ||
byPermissions?: boolean | undefined; | ||
} | undefined; | ||
off?: { | ||
byUser?: boolean | undefined; | ||
byRemoteRequest?: boolean | undefined; | ||
byBandwidth?: boolean | undefined; | ||
} | undefined; | ||
track?: MediaStreamTrack | undefined; | ||
persistentTrack?: MediaStreamTrack | undefined; | ||
}; | ||
export declare const useScreenVideoTrack: (participantId: string) => import("./useMediaTrack").MediaTrackState; |
@@ -5,18 +5,2 @@ /** | ||
*/ | ||
export declare const useVideoTrack: (participantId: string) => { | ||
isOff: boolean; | ||
subscribed: import("@daily-co/daily-js").DailyTrackSubscriptionState; | ||
state: "blocked" | "off" | "sendable" | "loading" | "interrupted" | "playable"; | ||
blocked?: { | ||
byDeviceMissing?: boolean | undefined; | ||
byDeviceInUse?: boolean | undefined; | ||
byPermissions?: boolean | undefined; | ||
} | undefined; | ||
off?: { | ||
byUser?: boolean | undefined; | ||
byRemoteRequest?: boolean | undefined; | ||
byBandwidth?: boolean | undefined; | ||
} | undefined; | ||
track?: MediaStreamTrack | undefined; | ||
persistentTrack?: MediaStreamTrack | undefined; | ||
}; | ||
export declare const useVideoTrack: (participantId: string) => import("./useMediaTrack").MediaTrackState; |
@@ -12,2 +12,3 @@ export { ExtendedDailyParticipant } from './DailyParticipants'; | ||
export { useLocalParticipant } from './hooks/useLocalParticipant'; | ||
export { useLocalSessionId } from './hooks/useLocalSessionId'; | ||
export { useMediaTrack } from './hooks/useMediaTrack'; | ||
@@ -17,2 +18,3 @@ export { useNetwork } from './hooks/useNetwork'; | ||
export { useParticipantIds } from './hooks/useParticipantIds'; | ||
export { useParticipantProperty } from './hooks/useParticipantProperty'; | ||
export { useReceiveSettings } from './hooks/useReceiveSettings'; | ||
@@ -19,0 +21,0 @@ export { useRecording } from './hooks/useRecording'; |
{ | ||
"version": "0.2.6", | ||
"version": "0.3.0", | ||
"license": "BSD-2-Clause", | ||
@@ -35,3 +35,3 @@ "keywords": [ | ||
"peerDependencies": { | ||
"@daily-co/daily-js": ">=0.28.0 <1", | ||
"@daily-co/daily-js": ">=0.29.0 <1", | ||
"react": ">=16.13.1", | ||
@@ -97,2 +97,3 @@ "recoil": "^0.7.0" | ||
"react-dom": "^17.0.2", | ||
"recoil": "^0.7.0", | ||
"size-limit": "^5.0.3", | ||
@@ -99,0 +100,0 @@ "ts-jest": "^27.0.5", |
@@ -16,3 +16,4 @@ import { | ||
const mediaTrackState = atomFamily<DailyTrackState, string>({ | ||
// TODO: Handle optional tracks better | ||
const mediaTrackState = atomFamily<DailyTrackState | undefined, string>({ | ||
key: 'media-track', | ||
@@ -25,2 +26,6 @@ default: { | ||
export interface MediaTrackState extends DailyTrackState { | ||
isOff: boolean; | ||
} | ||
/** | ||
@@ -37,3 +42,3 @@ * Returns a participant's track and state, based on the given MediaType. | ||
type: MediaType = 'video' | ||
) => { | ||
): MediaTrackState => { | ||
const daily = useDaily(); | ||
@@ -84,3 +89,3 @@ const key = useMemo(() => `${participantId}-${type}`, [participantId, type]); | ||
({ set }) => | ||
(initialState: DailyTrackState) => { | ||
(initialState: DailyTrackState | null) => { | ||
if (!initialState) return; | ||
@@ -99,5 +104,13 @@ set(mediaTrackState(key), initialState); | ||
if (!participant) return; | ||
setInitialState(participant.tracks[type]); | ||
setInitialState(participant.tracks?.[type] ?? null); | ||
}, [daily, participantId, setInitialState, type]); | ||
if (!trackState) | ||
return { | ||
isOff: true, | ||
persistentTrack: undefined, | ||
state: 'off', | ||
subscribed: false, | ||
}; | ||
return { | ||
@@ -104,0 +117,0 @@ ...trackState, |
@@ -18,3 +18,3 @@ import { | ||
import { useDailyEvent } from './useDailyEvent'; | ||
import { useLocalParticipant } from './useLocalParticipant'; | ||
import { useLocalSessionId } from './useLocalSessionId'; | ||
import { useParticipantIds } from './useParticipantIds'; | ||
@@ -89,3 +89,3 @@ | ||
const localParticipant = useLocalParticipant(); | ||
const localSessionId = useLocalSessionId(); | ||
@@ -101,3 +101,3 @@ const recordingParticipantIds = useParticipantIds({ | ||
const isLocalParticipantRecording = recordingParticipantIds.includes( | ||
localParticipant?.session_id ?? 'local' | ||
localSessionId ?? 'local' | ||
); | ||
@@ -125,3 +125,3 @@ setState((s) => ({ | ||
})); | ||
}, [localParticipant?.session_id, recordingParticipantIds, setState]); | ||
}, [localSessionId, recordingParticipantIds, setState]); | ||
@@ -138,5 +138,5 @@ useDailyEvent( | ||
if ( | ||
localParticipant && | ||
localSessionId && | ||
ev.layout?.preset === 'single-participant' && | ||
ev.layout.session_id !== localParticipant?.session_id | ||
ev.layout.session_id !== localSessionId | ||
) { | ||
@@ -161,3 +161,3 @@ isLocalParticipantRecorded = false; | ||
}, | ||
[localParticipant, onRecordingStarted] | ||
[localSessionId, onRecordingStarted] | ||
) | ||
@@ -164,0 +164,0 @@ ); |
@@ -12,2 +12,3 @@ export { ExtendedDailyParticipant } from './DailyParticipants'; | ||
export { useLocalParticipant } from './hooks/useLocalParticipant'; | ||
export { useLocalSessionId } from './hooks/useLocalSessionId'; | ||
export { useMediaTrack } from './hooks/useMediaTrack'; | ||
@@ -17,2 +18,3 @@ export { useNetwork } from './hooks/useNetwork'; | ||
export { useParticipantIds } from './hooks/useParticipantIds'; | ||
export { useParticipantProperty } from './hooks/useParticipantProperty'; | ||
export { useReceiveSettings } from './hooks/useReceiveSettings'; | ||
@@ -19,0 +21,0 @@ export { useRecording } from './hooks/useRecording'; |
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
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
72
0
600041
30
6293