@100mslive/react-sdk 0.8.23-alpha.0 → 0.8.23-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("zustand"),r=require("@100mslive/hms-video-store"),i=require("react-resize-detector");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n,a,s=o(e),l=o(t);function c(e,t){if(Object.is(e,t))return!0;if("object"!=typeof e||null===e||"object"!=typeof t||null===t)return!1;const r=Object.keys(e);if(r.length!==Object.keys(t).length)return!1;for(let i=0;i<r.length;i++)if(!Object.prototype.hasOwnProperty.call(t,r[i])||!Object.is(e[r[i]],t[r[i]]))return!1;return!0}(a=n||(n={}))[a.VERBOSE=0]="VERBOSE",a[a.DEBUG=1]="DEBUG",a[a.INFO=2]="INFO",a[a.WARN=3]="WARN",a[a.ERROR=4]="ERROR",a[a.NONE=5]="NONE";class u{static v(e,...t){this.log(n.VERBOSE,e,...t)}static d(e,...t){this.log(n.DEBUG,e,...t)}static i(e,...t){this.log(n.INFO,e,...t)}static w(e,...t){this.log(n.WARN,e,...t)}static e(e,...t){this.log(n.ERROR,e,...t)}static log(e,t,...r){if(!(this.level.valueOf()>e.valueOf()))switch(e){case n.VERBOSE:console.log("HMSui-components: ",t,...r);break;case n.DEBUG:console.debug("HMSui-components: ",t,...r);break;case n.INFO:console.info("HMSui-components: ",t,...r);break;case n.WARN:console.warn("HMSui-components: ",t,...r);break;case n.ERROR:console.error("HMSui-components: ",t,...r)}}}u.level=n.VERBOSE;const d="It seems like you forgot to add your component within a top level HMSRoomProvider, please refer to 100ms react docs(https://www.100ms.live/docs/javascript/v2/how-to-guides/install-the-sdk/integration#react-hooks) to check on the required steps for using this hook. If the provider is present\n at the top level, check the yarn.lock/package-lock.json, if there are multiple versions of @100mslive/react-sdk. Please ensure the versions of @100mslive/react-sdk and @100mslive/roomkit-react are the same versions from the release notes(https://www.100ms.live/docs/javascript/v2/changelog/release-notes) that you are trying to update to.";const h="undefined"!=typeof window,f=e.createContext(null),g=(v=f,(t,r=c)=>{t||u.w("fetching full store without passing any selector may have a heavy performance impact on your website.");const i=e.useContext(v);if(!i)throw new Error(d);return(0,i.store)(t,r)});var v;const p=function(t){return(r,i=c)=>{r||u.w("fetching full store without passing any selector may have a heavy performance impact on your website.");const o=e.useContext(t);if(!o)throw new Error(d);const n=o.statsStore;return null==n?void 0:n(r,i)}}(f),m=()=>{const t=e.useContext(f);if(!t)throw new Error(d);return t.store},w=()=>{const t=e.useContext(f);if(!t)throw new Error(d);return t.notifications},y=()=>{const t=e.useContext(f);if(!t)throw new Error(d);return t.actions},S=t=>{const r=e.useContext(f),[i,o]=e.useState(null);if(!r)throw new Error(d);return e.useEffect((()=>{if(!r.notifications)return;return r.notifications.onNotification((e=>{o(e)}),t)}),[r.notifications,t]),i};function P(e,t,r,i){return new(r||(r=Promise))((function(o,n){function a(e){try{l(i.next(e))}catch(e){n(e)}}function s(e){try{l(i.throw(e))}catch(e){n(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}l((i=i.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const b=(e,t)=>u.e("react-sdk",t,e);function E(t){const r=e.useRef();return e.useEffect((()=>{r.current=t})),r.current}const k=["blink"].some((e=>{var t,i;return(null===(i=null===(t=r.parsedUserAgent.getEngine())||void 0===t?void 0:t.name)||void 0===i?void 0:i.toLowerCase())===e})),R=(t=b)=>{var i,o;const n=y(),a=g(r.selectIsLocalScreenShared),s=g(r.selectPeerScreenSharing),l=g(r.selectScreenSharesByPeerId(null==s?void 0:s.id)),c=e.useCallback((e=>P(void 0,void 0,void 0,(function*(){try{yield n.setScreenShareEnabled(!a,e)}catch(e){t(e,"toggleScreenShare")}}))),[n,a,t]);return{amIScreenSharing:a,screenSharingPeerId:null==s?void 0:s.id,screenSharingPeerName:null==s?void 0:s.name,screenShareVideoTrackId:null===(i=null==l?void 0:l.video)||void 0===i?void 0:i.id,screenShareAudioTrackId:null===(o=null==l?void 0:l.audio)||void 0===o?void 0:o.id,toggleScreenShare:c}},I=(e,t,r)=>P(void 0,void 0,void 0,(function*(){if(t)try{yield e.setRemoteTrackEnabled(t.id,!t.enabled)}catch(e){r(e,"remoteToggle")}})),M=({elements:e,tilesInFirstPage:t,onlyOnePage:r,isLastPageDifferentFromFirstPage:i,defaultWidth:o,defaultHeight:n,lastPageWidth:a,lastPageHeight:s})=>{const l=((e,t,r)=>e.reduce(((e,i,o)=>{const n=Math.floor(o/t);return n>0&&r||(e[n]||(e[n]=[]),e[n].push(i)),e}),[]))(e,t,r);return l.map(((e,t)=>e.map((e=>{const r=t===l.length-1,c=i&&r?a:o,u=i&&r?s:n;return Object.assign(Object.assign({},e),{height:u,width:c})}))))};const C=(e,t,r,i,o)=>{if(e<0||t<0)throw new Error("Container must have a non-negative area");if(r<1||!Number.isInteger(r))throw new Error("Number of shapes to place must be a positive integer");const n=i&&o&&i/o;if(void 0!==n&&isNaN(n))throw new Error("Aspect ratio must be a number");let a={area:0,cols:0,rows:0,width:0,height:0};if(void 0!==n)for(let i=r;i>0;i+=-1){const o=Math.ceil(r/i);let s,l;e/(i*n)<=t/o?(s=e/i,l=s/n):(l=t/o,s=l*n);const c=s*l;c>a.area&&(a={area:c,width:s,height:l,rows:o,cols:i})}return a};function x({count:e,parentWidth:t,parentHeight:r,maxTileCount:i,maxRowCount:o,maxColCount:n,aspectRatio:a}){let s=0,l=0,c=0,u=0,d=!1,h=0;if(0===e)return{tilesInFirstPage:h,defaultWidth:s,defaultHeight:l,lastPageWidth:c,lastPageHeight:u,isLastPageDifferentFromFirstPage:d};if(i)({tilesInFirstPage:h,defaultWidth:s,defaultHeight:l,lastPageWidth:c,lastPageHeight:u,isLastPageDifferentFromFirstPage:d}=(({parentWidth:e,parentHeight:t,count:r,maxCount:i,aspectRatio:o})=>{let n=0,a=0,s=0,l=0,c=!1,u=0,d=0;const{width:h,height:f}=C(e,t,Math.min(r,i),o.width,o.height);if(n=h,a=f,u=Math.min(r,i),d=r%i,c=d>0&&r>i,c){const{width:r,height:i}=C(e,t,d,o.width,o.height);s=r,l=i}return{tilesInFirstPage:u,defaultWidth:n,defaultHeight:a,lastPageWidth:s,lastPageHeight:l,isLastPageDifferentFromFirstPage:c}})({parentWidth:t,parentHeight:r,count:e,maxCount:i,aspectRatio:a}));else if(o)({tilesInFirstPage:h,defaultWidth:s,defaultHeight:l,lastPageWidth:c,lastPageHeight:u,isLastPageDifferentFromFirstPage:d}=(({parentWidth:e,parentHeight:t,count:r,maxCount:i,aspectRatio:o})=>{let n=0,a=0,s=0,l=0,c=!1,u=0,d=0;const h=Math.min(Math.ceil(Math.sqrt(r*(o.width/o.height)/(e/t))),i),f=t/h,g=f*(o.width/o.height),v=Math.floor(e/g);if(n=g,a=f,u=Math.min(r,h*v),d=r%(h*v),c=d>0&&r>h*v,c){const r=t/Math.min(Math.ceil(Math.sqrt(d*(o.width/o.height)/(e/t))),i);l=r,s=r*(o.width/o.height)}return{tilesInFirstPage:u,defaultWidth:n,defaultHeight:a,lastPageWidth:s,lastPageHeight:l,isLastPageDifferentFromFirstPage:c}})({parentWidth:t,parentHeight:r,count:e,maxCount:o,aspectRatio:a}));else if(n)({tilesInFirstPage:h,defaultWidth:s,defaultHeight:l,lastPageWidth:c,lastPageHeight:u,isLastPageDifferentFromFirstPage:d}=(({parentWidth:e,parentHeight:t,count:r,maxCount:i,aspectRatio:o})=>{let n=0,a=0,s=0,l=0,c=!1,u=0,d=0;const h=Math.min(Math.ceil(Math.sqrt(r*(e/t)/(o.width/o.height))),i);let f=e/h,g=f/(o.width/o.height);g>t&&(g=t,f=g/(o.height/o.width));const v=Math.floor(t/g);if(a=g,n=f,u=Math.min(r,v*h),d=r%(v*h),c=d>0&&r>v*h,c){let r=e/Math.min(Math.ceil(Math.sqrt(d*(e/t)/(o.width/o.height))),i),n=r/(o.width/o.height);n>t&&(n=t,r=n/(o.height/o.width)),l=n,s=r}return{tilesInFirstPage:u,defaultWidth:n,defaultHeight:a,lastPageWidth:s,lastPageHeight:l,isLastPageDifferentFromFirstPage:c}})({parentWidth:t,parentHeight:r,count:e,maxCount:n,aspectRatio:a}));else{const{width:i,height:o}=C(t,r,e,a.width,a.height);s=i,l=o,h=e}return{tilesInFirstPage:h,defaultWidth:s,defaultHeight:l,lastPageWidth:c,lastPageHeight:u,isLastPageDifferentFromFirstPage:d}}const T=(e,t,r,i=!0)=>{if(!e||!t||!r)return[];const o=[];for(const n of e){if(void 0===n.videoTrack&&n.audioTrack&&t[n.audioTrack]?o.push({peer:n}):n.videoTrack&&t[n.videoTrack]?o.push({track:t[n.videoTrack],peer:n}):i||o.push({peer:n}),n.auxiliaryTracks.length>0&&n.auxiliaryTracks.forEach((e=>{const r=t[e];"video"===(null==r?void 0:r.type)&&"regular"===(null==r?void 0:r.source)&&o.push({track:r,peer:n})})),r(n)&&n.auxiliaryTracks.length>0){const e=n.auxiliaryTracks.find((e=>{const r=t[e];return"video"===(null==r?void 0:r.type)&&"screen"===(null==r?void 0:r.source)}));e&&o.push({track:t[e],peer:n})}}return o},H={width:1,height:1};const O=e=>e.reduce(((e,t)=>(e[t.id]=t,e)),{});exports.HMSRoomProvider=({children:t,actions:i,store:o,notifications:n,stats:a,isHMSStatsOn:c=!1,leaveOnUnload:u=!0})=>{const d=e.useMemo((()=>{let e;const t=()=>{throw new Error("modifying store is not allowed")};if(i&&o)e={actions:i,store:l.default(Object.assign(Object.assign({},o),{setState:t,destroy:t}))},n&&(e.notifications=n),a&&(e.statsStore=l.default({getState:a.getState,subscribe:a.subscribe,setState:t,destroy:t}));else{const i=new r.HMSReactiveStore;if(e={actions:i.getActions(),store:l.default(Object.assign(Object.assign({},i.getStore()),{setState:t,destroy:t})),notifications:i.getNotifications()},c){const r=i.getStats();e.statsStore=l.default({getState:r.getState,subscribe:r.subscribe,setState:t,destroy:t})}}return e.actions.setFrameworkInfo({type:"react-web",version:s.default.version,sdkVersion:"0.8.23-alpha.0"}),e}),[i,o,n,a,c]);return e.useEffect((()=>{if(h&&u){const e=()=>d.actions.leave();return window.addEventListener("unload",e),()=>{window.removeEventListener("unload",e)}}return()=>{}}),[u,d]),s.default.createElement(f.Provider,{value:d},t)},exports.getPeersWithTiles=T,exports.throwErrorHandler=e=>{throw e},exports.useAVToggle=(t=b)=>{const i=g(r.selectIsLocalAudioEnabled),o=g(r.selectIsLocalVideoEnabled),n=g(r.selectIsInPreview)?r.selectIsAllowedToPreviewMedia:r.selectIsAllowedToPublish,a=g(n),s=y(),l=e.useCallback((()=>P(void 0,void 0,void 0,(function*(){try{yield s.setLocalAudioEnabled(!i)}catch(e){t(e,"toggleAudio")}}))),[s,i,t]),c=e.useCallback((()=>P(void 0,void 0,void 0,(function*(){try{yield s.setLocalVideoEnabled(!o)}catch(e){t(e,"toggleVideo")}}))),[s,o,t]);return{isLocalAudioEnabled:i,isLocalVideoEnabled:o,toggleAudio:(null==a?void 0:a.audio)?l:void 0,toggleVideo:(null==a?void 0:a.video)?c:void 0}},exports.useAudioLevelStyles=function({trackId:t,getStyle:i,ref:o}){const n=m();e.useEffect((()=>n.subscribe((e=>{if(!o.current)return;const t=i(e);for(const e in t)o.current.style[e]=t[e]}),r.selectTrackAudioByID(t))),[i,o,n,t])},exports.useAutoplayError=()=>{const t=S(r.HMSNotificationTypes.ERROR),[i,o]=e.useState(""),n=y(),a=e.useCallback((()=>P(void 0,void 0,void 0,(function*(){yield n.unblockAudio()}))),[n]);return e.useEffect((()=>{3008===(null==t?void 0:t.data.code)&&o(null==t?void 0:t.data.message)}),[t]),{error:i,unblockAudio:a,resetError:()=>o("")}},exports.useCustomEvent=({type:t,json:i=!0,onEvent:o,handleError:n=b})=>{const a=y(),s=w();e.useEffect((()=>{a.ignoreMessageTypes([t])}),[a,t]),e.useEffect((()=>{if(!s)return;return s.onNotification((e=>{const r=e.data;if(r&&r.type===t)try{const e=i?JSON.parse(r.message):r.message;null==o||o(e)}catch(e){n(e,"handleCustomEvent")}}),r.HMSNotificationTypes.NEW_MESSAGE)}),[s,t,i,o,n]);return{sendEvent:e.useCallback(((e,r)=>P(void 0,void 0,void 0,(function*(){try{const n=((e,t)=>t?JSON.stringify(e||""):e)(e,i);r&&Array.isArray(null==r?void 0:r.roleNames)?yield a.sendGroupMessage(n,r.roleNames,t):"string"==typeof(null==r?void 0:r.peerId)?yield a.sendDirectMessage(n,r.peerId,t):yield a.sendBroadcastMessage(n,t),null==o||o(e)}catch(e){n(e,"sendCustomEvent")}}))),[a,n,o,t,i])}},exports.useDevices=(t=b)=>{const i=y(),o=g(r.selectDevices),n=g(r.selectLocalMediaSettings),a=g(r.selectIsInPreview)?r.selectIsAllowedToPreviewMedia:r.selectIsAllowedToPublish,s=g(a),l={[r.DeviceType.audioOutput]:n.audioOutputDeviceId},c={[r.DeviceType.audioOutput]:o.audioOutput};s.video&&(c[r.DeviceType.videoInput]=o.videoInput,l[r.DeviceType.videoInput]=n.videoInputDeviceId),s.audio&&(c[r.DeviceType.audioInput]=o.audioInput,l[r.DeviceType.audioInput]=n.audioInputDeviceId);return{allDevices:c,selectedDeviceIDs:l,updateDevice:e.useCallback((({deviceType:e,deviceId:o})=>P(void 0,void 0,void 0,(function*(){try{switch(e){case r.DeviceType.audioInput:yield i.setAudioSettings({deviceId:o});break;case r.DeviceType.videoInput:yield i.setVideoSettings({deviceId:o});break;case r.DeviceType.audioOutput:yield i.setAudioOutputDevice(o)}}catch(e){t(e,"updateDevices")}}))),[t,i])}},exports.useEmbedShare=t=>{const r=e.useRef(null),[i,o]=e.useState(!1),n=e.useCallback((()=>{throw new Error("unable to start screen share")}),[]),a=e.useRef(!1),{amIScreenSharing:s,toggleScreenShare:l}=R(n),c=E(s),u=e.useCallback((()=>P(void 0,void 0,void 0,(function*(){s&&(yield null==l?void 0:l(),r.current=null)}))),[s,l]),d=e.useCallback((e=>P(void 0,void 0,void 0,(function*(){if(!a.current){if(!e)throw new Error("URL not found");if(s)throw new Error("You are already sharing");if(!r.current)throw new Error("Attach a reference `iframeRef` to iframe for sharing");r.current.src=e,a.current=!0,o(!0),yield null==l?void 0:l({forceCurrentTab:k,cropElement:r.current,preferCurrentTab:k})}}))),[s,l]);return e.useEffect((()=>{c&&!s&&(null==t||t(),r.current&&(r.current.src=""),a.current=!1,o(!1))}),[s,c,t]),{startEmbedShare:d,stopEmbedShare:u,iframeRef:r,isEmbedShareInProgress:i}},exports.useHMSActions=y,exports.useHMSNotifications=S,exports.useHMSStatsStore=p,exports.useHMSStore=g,exports.useHMSVanillaNotifications=w,exports.useHMSVanillaStore=m,exports.usePDFShare=t=>{const r=e.useRef(null),[i,o]=e.useState(!1),n=e.useCallback((()=>{throw new Error("unable to start screen share")}),[]),a=e.useRef(!1),{amIScreenSharing:s,toggleScreenShare:l}=R(n),c=E(s),u=e.useCallback((e=>{var t;r.current&&(null===(t=r.current.contentWindow)||void 0===t||t.postMessage({theme:2,file:e},"*"))}),[]),d=e.useCallback((()=>P(void 0,void 0,void 0,(function*(){s&&(yield null==l?void 0:l())}))),[s,l]),h=e.useCallback((e=>P(void 0,void 0,void 0,(function*(){if(!a.current){if(!e)throw new Error("File or url not found");if(s)throw new Error("You are already sharing");if(!r.current)throw new Error("Attach a reference `iframeRef` to iframe for sharing");r.current.src="https://pdf-annotation.100ms.live/generic/web/viewer.html"+("string"==typeof e?`?file=${e}`:""),r.current.onload=()=>{requestAnimationFrame((()=>{e instanceof File&&u(e)}))},a.current=!0,o(!0),yield null==l?void 0:l({forceCurrentTab:k,cropElement:r.current,preferCurrentTab:k})}}))),[s,u,l]);return e.useEffect((()=>{c&&!s&&(null==t||t(),r.current&&r.current.removeAttribute("src"),a.current=!1,o(!1))}),[s,c,t]),{startPDFShare:h,stopPDFShare:d,iframeRef:r,isPDFShareInProgress:i}},exports.usePaginatedParticipants=t=>{const r=y(),i=e.useRef(r.getPeerListIterator(t)),[o,n]=e.useState({}),[a,s]=e.useState(0);return{loadPeers:()=>i.current.findPeers().then((e=>{n(O(e)),s(i.current.getTotal())})),loadMorePeers:()=>i.current.next().then((e=>{n((t=>Object.assign(Object.assign({},t),O(e)))),s(i.current.getTotal())})),hasNext:()=>i.current.hasNext(),total:a,peers:Object.values(o)}},exports.useParticipantList=()=>{const t=g(r.selectIsConnectedToRoom),i=g(t?r.selectPeers:r.selectRemotePeers),o=g(r.selectPeerCount),n=e.useMemo((()=>{return(e=i)&&Array.isArray(e)&&0!==e.length?e.reduce(((e,t)=>t.roleName?(e[t.roleName]||(e[t.roleName]=[]),e[t.roleName].push(t),e):e),{}):{};var e}),[i]);return{roles:Object.keys(n),participantsByRoles:n,peerCount:o,isConnected:t}},exports.useParticipants=e=>{var t;const i=g(r.selectIsConnectedToRoom),o=g(r.selectPeerCount),n=g(r.selectAvailableRoleNames);let a=g(i?r.selectPeers:r.selectRemotePeers);const s=Array.from(new Set(a.map((e=>e.roleName)))),l=m();if((null===(t=null==e?void 0:e.metadata)||void 0===t?void 0:t.isHandRaised)&&(a=a.filter((e=>l.getState(r.selectPeerMetadata(e.id)).isHandRaised))),(null==e?void 0:e.role)&&n.includes(e.role)&&(a=a.filter((t=>t.roleName===e.role))),null==e?void 0:e.search){const t=e.search.toLowerCase();a=a.filter((e=>{var r;return(null===(r=e.roleName)||void 0===r?void 0:r.toLowerCase().includes(t))||e.name.toLowerCase().includes(t)}))}return{participants:a,isConnected:i,peerCount:o,rolesWithParticipants:s}},exports.usePreviewJoin=({name:t="",token:i,metadata:o,handleError:n=b,initEndpoint:a,initialSettings:s,captureNetworkQualityInPreview:l,asRole:c,autoManageVideo:u,autoManageWakeLock:d})=>{const h=y(),f=g(r.selectRoomState),v=g(r.selectIsConnectedToRoom)||!1,p=f===r.HMSRoomState.Preview,m=e.useMemo((()=>({userName:t,authToken:i,metaData:o,rememberDeviceSelection:!0,settings:s,initEndpoint:a,asRole:c,captureNetworkQualityInPreview:l,autoManageVideo:u,autoManageWakeLock:d})),[t,i,o,a,s,l,c,u,d]),w=e.useCallback((()=>P(void 0,void 0,void 0,(function*(){if(i)try{(v||f!==r.HMSRoomState.Disconnected)&&(yield h.leave().catch((()=>{}))),yield h.preview(m)}catch(e){n(e,"preview")}}))),[i,v,f,h,m,n]);return{enableJoin:p,join:e.useCallback((()=>P(void 0,void 0,void 0,(function*(){if(i)try{yield h.join(m)}catch(e){n(e,"join")}}))),[h,m,n,i]),isConnected:v,preview:w}},exports.useRecordingStreaming=()=>{const e=g(r.selectRecordingState),t=g(r.selectRTMPState),i=g(r.selectHLSState),o=e.server.running,n=e.browser.running,a=e.hls.running,s=o||n||a;return{isServerRecordingOn:o,isBrowserRecordingOn:n,isHLSRecordingOn:a,isStreamingOn:i.running||t.running,isHLSRunning:i.running,isRTMPRunning:t.running,isRecordingOn:s}},exports.useRemoteAVToggle=(t,i,o=b)=>{const n=y(),a=g(r.selectAudioTrackByID(t)),s=g(r.selectVideoTrackByID(i)),l=g(r.selectAudioTrackVolume(null==a?void 0:a.id)),c=g(r.selectPermissions),u=(null==s?void 0:s.enabled)?null==c?void 0:c.mute:null==c?void 0:c.unmute,d=(null==a?void 0:a.enabled)?null==c?void 0:c.mute:null==c?void 0:c.unmute,h=e.useCallback((()=>P(void 0,void 0,void 0,(function*(){yield I(n,a,o)}))),[n,a,o]),f=e.useCallback((()=>P(void 0,void 0,void 0,(function*(){yield I(n,s,o)}))),[n,o,s]),v=e.useCallback((e=>{a&&n.setVolume(e,a.id)}),[n,a]);return{isAudioEnabled:!!(null==a?void 0:a.enabled),isVideoEnabled:!!(null==s?void 0:s.enabled),volume:l,toggleAudio:a&&d?h:void 0,toggleVideo:"regular"===(null==s?void 0:s.source)&&u?f:void 0,setVolume:a?v:void 0}},exports.useScreenShare=R,exports.useVideo=({trackId:t,attach:i})=>{const o=y(),n=e.useRef(null),a=g(r.selectVideoTrackByID(t)),s=e.useRef(),l=e.useCallback((e=>{e&&(n.current=e)}),[]);return e.useEffect((()=>{s.current?(null==a?void 0:a.id)&&s.current!==(null==a?void 0:a.id)&&P(void 0,void 0,void 0,(function*(){if(n.current)try{u.d("detaching because different track is passed"),yield o.detachVideo(s.current,n.current)}catch(e){u.w("detach video error for track",s.current,e)}s.current=null==a?void 0:a.id})):s.current=null==a?void 0:a.id}),[null==a?void 0:a.id,o]),e.useEffect((()=>{P(void 0,void 0,void 0,(function*(){(null==a?void 0:a.id)&&n.current&&(!1!==i?yield o.attachVideo(a.id,n.current):yield o.detachVideo(a.id,n.current))}))}),[a,i,o]),e.useEffect((()=>()=>{P(void 0,void 0,void 0,(function*(){if(n.current&&a)try{yield o.detachVideo(a.id,n.current)}catch(e){u.w("detach video error for track",a.id,e)}}))}),[]),{videoRef:l}},exports.useVideoList=({peers:t,maxTileCount:o,maxColCount:n,maxRowCount:a,includeScreenShareForPeer:s=(()=>!1),aspectRatio:l=H,filterNonPublishingPeers:c=!0,offsetY:u=0})=>{const{width:d=0,height:h=0,ref:f}=i.useResizeDetector(),g=m().getState(r.selectTracksMap),v=T(t,g,s,c),p=e.useMemo((()=>{if(l)return l;return{width:function(e){if(0===e.length)return null;const t={};let r=e[0],i=1;for(let o=0;o<e.length;o++){const n=e[o];null===t[n]?t[n]=1:t[n]++,t[n]>i&&(r=n,i=t[n])}return r}(v.filter((e=>{var t,r;return(null===(t=e.track)||void 0===t?void 0:t.width)&&(null===(r=e.track)||void 0===r?void 0:r.height)})).map((e=>{var t,r;return((null===(t=e.track)||void 0===t?void 0:t.width)||1)/((null===(r=e.track)||void 0===r?void 0:r.height)||1)})))||1,height:1}}),[l,v]),w=v.length,{tilesInFirstPage:y,defaultWidth:S,defaultHeight:P,lastPageWidth:b,lastPageHeight:E,isLastPageDifferentFromFirstPage:k}=e.useMemo((()=>x({count:w,parentWidth:Math.floor(d),parentHeight:Math.floor(h)-Math.min(h,u),maxTileCount:o,maxRowCount:a,maxColCount:n,aspectRatio:p})),[w,d,h,o,a,n,p,u]);return{pagesWithTiles:e.useMemo((()=>M({elements:v,tilesInFirstPage:y,onlyOnePage:!1,isLastPageDifferentFromFirstPage:k,defaultWidth:S,defaultHeight:P,lastPageWidth:b,lastPageHeight:E})),[v,y,k,S,P,b,E]),ref:f}},Object.keys(r).forEach((function(e){"default"===e||exports.hasOwnProperty(e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return r[e]}})}));
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("zustand"),r=require("@100mslive/hms-video-store"),i=require("react-resize-detector");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n,a,s=o(e),l=o(t);function c(e,t){if(Object.is(e,t))return!0;if("object"!=typeof e||null===e||"object"!=typeof t||null===t)return!1;const r=Object.keys(e);if(r.length!==Object.keys(t).length)return!1;for(let i=0;i<r.length;i++)if(!Object.prototype.hasOwnProperty.call(t,r[i])||!Object.is(e[r[i]],t[r[i]]))return!1;return!0}(a=n||(n={}))[a.VERBOSE=0]="VERBOSE",a[a.DEBUG=1]="DEBUG",a[a.INFO=2]="INFO",a[a.WARN=3]="WARN",a[a.ERROR=4]="ERROR",a[a.NONE=5]="NONE";class u{static v(e,...t){this.log(n.VERBOSE,e,...t)}static d(e,...t){this.log(n.DEBUG,e,...t)}static i(e,...t){this.log(n.INFO,e,...t)}static w(e,...t){this.log(n.WARN,e,...t)}static e(e,...t){this.log(n.ERROR,e,...t)}static log(e,t,...r){if(!(this.level.valueOf()>e.valueOf()))switch(e){case n.VERBOSE:console.log("HMSui-components: ",t,...r);break;case n.DEBUG:console.debug("HMSui-components: ",t,...r);break;case n.INFO:console.info("HMSui-components: ",t,...r);break;case n.WARN:console.warn("HMSui-components: ",t,...r);break;case n.ERROR:console.error("HMSui-components: ",t,...r)}}}u.level=n.VERBOSE;const d="It seems like you forgot to add your component within a top level HMSRoomProvider, please refer to 100ms react docs(https://www.100ms.live/docs/javascript/v2/how-to-guides/install-the-sdk/integration#react-hooks) to check on the required steps for using this hook. If the provider is present\n at the top level, check the yarn.lock/package-lock.json, if there are multiple versions of @100mslive/react-sdk. Please ensure the versions of @100mslive/react-sdk and @100mslive/roomkit-react are the same versions from the release notes(https://www.100ms.live/docs/javascript/v2/changelog/release-notes) that you are trying to update to.";const h="undefined"!=typeof window,f=e.createContext(null),g=(v=f,(t,r=c)=>{t||u.w("fetching full store without passing any selector may have a heavy performance impact on your website.");const i=e.useContext(v);if(!i)throw new Error(d);return(0,i.store)(t,r)});var v;const p=function(t){return(r,i=c)=>{r||u.w("fetching full store without passing any selector may have a heavy performance impact on your website.");const o=e.useContext(t);if(!o)throw new Error(d);const n=o.statsStore;return null==n?void 0:n(r,i)}}(f),m=()=>{const t=e.useContext(f);if(!t)throw new Error(d);return t.store},w=()=>{const t=e.useContext(f);if(!t)throw new Error(d);return t.notifications},y=()=>{const t=e.useContext(f);if(!t)throw new Error(d);return t.actions},S=t=>{const r=e.useContext(f),[i,o]=e.useState(null);if(!r)throw new Error(d);return e.useEffect((()=>{if(!r.notifications)return;return r.notifications.onNotification((e=>{o(e)}),t)}),[r.notifications,t]),i};function P(e,t,r,i){return new(r||(r=Promise))((function(o,n){function a(e){try{l(i.next(e))}catch(e){n(e)}}function s(e){try{l(i.throw(e))}catch(e){n(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}l((i=i.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const b=(e,t)=>u.e("react-sdk",t,e);function E(t){const r=e.useRef();return e.useEffect((()=>{r.current=t})),r.current}const k=["blink"].some((e=>{var t,i;return(null===(i=null===(t=r.parsedUserAgent.getEngine())||void 0===t?void 0:t.name)||void 0===i?void 0:i.toLowerCase())===e})),R=(t=b)=>{var i,o;const n=y(),a=g(r.selectIsLocalScreenShared),s=g(r.selectPeerScreenSharing),l=g(r.selectScreenSharesByPeerId(null==s?void 0:s.id)),c=e.useCallback((e=>P(void 0,void 0,void 0,(function*(){try{yield n.setScreenShareEnabled(!a,e)}catch(e){t(e,"toggleScreenShare")}}))),[n,a,t]);return{amIScreenSharing:a,screenSharingPeerId:null==s?void 0:s.id,screenSharingPeerName:null==s?void 0:s.name,screenShareVideoTrackId:null===(i=null==l?void 0:l.video)||void 0===i?void 0:i.id,screenShareAudioTrackId:null===(o=null==l?void 0:l.audio)||void 0===o?void 0:o.id,toggleScreenShare:c}},I=(e,t,r)=>P(void 0,void 0,void 0,(function*(){if(t)try{yield e.setRemoteTrackEnabled(t.id,!t.enabled)}catch(e){r(e,"remoteToggle")}})),M=({elements:e,tilesInFirstPage:t,onlyOnePage:r,isLastPageDifferentFromFirstPage:i,defaultWidth:o,defaultHeight:n,lastPageWidth:a,lastPageHeight:s})=>{const l=((e,t,r)=>e.reduce(((e,i,o)=>{const n=Math.floor(o/t);return n>0&&r||(e[n]||(e[n]=[]),e[n].push(i)),e}),[]))(e,t,r);return l.map(((e,t)=>e.map((e=>{const r=t===l.length-1,c=i&&r?a:o,u=i&&r?s:n;return Object.assign(Object.assign({},e),{height:u,width:c})}))))};const C=(e,t,r,i,o)=>{if(e<0||t<0)throw new Error("Container must have a non-negative area");if(r<1||!Number.isInteger(r))throw new Error("Number of shapes to place must be a positive integer");const n=i&&o&&i/o;if(void 0!==n&&isNaN(n))throw new Error("Aspect ratio must be a number");let a={area:0,cols:0,rows:0,width:0,height:0};if(void 0!==n)for(let i=r;i>0;i+=-1){const o=Math.ceil(r/i);let s,l;e/(i*n)<=t/o?(s=e/i,l=s/n):(l=t/o,s=l*n);const c=s*l;c>a.area&&(a={area:c,width:s,height:l,rows:o,cols:i})}return a};function x({count:e,parentWidth:t,parentHeight:r,maxTileCount:i,maxRowCount:o,maxColCount:n,aspectRatio:a}){let s=0,l=0,c=0,u=0,d=!1,h=0;if(0===e)return{tilesInFirstPage:h,defaultWidth:s,defaultHeight:l,lastPageWidth:c,lastPageHeight:u,isLastPageDifferentFromFirstPage:d};if(i)({tilesInFirstPage:h,defaultWidth:s,defaultHeight:l,lastPageWidth:c,lastPageHeight:u,isLastPageDifferentFromFirstPage:d}=(({parentWidth:e,parentHeight:t,count:r,maxCount:i,aspectRatio:o})=>{let n=0,a=0,s=0,l=0,c=!1,u=0,d=0;const{width:h,height:f}=C(e,t,Math.min(r,i),o.width,o.height);if(n=h,a=f,u=Math.min(r,i),d=r%i,c=d>0&&r>i,c){const{width:r,height:i}=C(e,t,d,o.width,o.height);s=r,l=i}return{tilesInFirstPage:u,defaultWidth:n,defaultHeight:a,lastPageWidth:s,lastPageHeight:l,isLastPageDifferentFromFirstPage:c}})({parentWidth:t,parentHeight:r,count:e,maxCount:i,aspectRatio:a}));else if(o)({tilesInFirstPage:h,defaultWidth:s,defaultHeight:l,lastPageWidth:c,lastPageHeight:u,isLastPageDifferentFromFirstPage:d}=(({parentWidth:e,parentHeight:t,count:r,maxCount:i,aspectRatio:o})=>{let n=0,a=0,s=0,l=0,c=!1,u=0,d=0;const h=Math.min(Math.ceil(Math.sqrt(r*(o.width/o.height)/(e/t))),i),f=t/h,g=f*(o.width/o.height),v=Math.floor(e/g);if(n=g,a=f,u=Math.min(r,h*v),d=r%(h*v),c=d>0&&r>h*v,c){const r=t/Math.min(Math.ceil(Math.sqrt(d*(o.width/o.height)/(e/t))),i);l=r,s=r*(o.width/o.height)}return{tilesInFirstPage:u,defaultWidth:n,defaultHeight:a,lastPageWidth:s,lastPageHeight:l,isLastPageDifferentFromFirstPage:c}})({parentWidth:t,parentHeight:r,count:e,maxCount:o,aspectRatio:a}));else if(n)({tilesInFirstPage:h,defaultWidth:s,defaultHeight:l,lastPageWidth:c,lastPageHeight:u,isLastPageDifferentFromFirstPage:d}=(({parentWidth:e,parentHeight:t,count:r,maxCount:i,aspectRatio:o})=>{let n=0,a=0,s=0,l=0,c=!1,u=0,d=0;const h=Math.min(Math.ceil(Math.sqrt(r*(e/t)/(o.width/o.height))),i);let f=e/h,g=f/(o.width/o.height);g>t&&(g=t,f=g/(o.height/o.width));const v=Math.floor(t/g);if(a=g,n=f,u=Math.min(r,v*h),d=r%(v*h),c=d>0&&r>v*h,c){let r=e/Math.min(Math.ceil(Math.sqrt(d*(e/t)/(o.width/o.height))),i),n=r/(o.width/o.height);n>t&&(n=t,r=n/(o.height/o.width)),l=n,s=r}return{tilesInFirstPage:u,defaultWidth:n,defaultHeight:a,lastPageWidth:s,lastPageHeight:l,isLastPageDifferentFromFirstPage:c}})({parentWidth:t,parentHeight:r,count:e,maxCount:n,aspectRatio:a}));else{const{width:i,height:o}=C(t,r,e,a.width,a.height);s=i,l=o,h=e}return{tilesInFirstPage:h,defaultWidth:s,defaultHeight:l,lastPageWidth:c,lastPageHeight:u,isLastPageDifferentFromFirstPage:d}}const T=(e,t,r,i=!0)=>{if(!e||!t||!r)return[];const o=[];for(const n of e){if(void 0===n.videoTrack&&n.audioTrack&&t[n.audioTrack]?o.push({peer:n}):n.videoTrack&&t[n.videoTrack]?o.push({track:t[n.videoTrack],peer:n}):i||o.push({peer:n}),n.auxiliaryTracks.length>0&&n.auxiliaryTracks.forEach((e=>{const r=t[e];"video"===(null==r?void 0:r.type)&&"regular"===(null==r?void 0:r.source)&&o.push({track:r,peer:n})})),r(n)&&n.auxiliaryTracks.length>0){const e=n.auxiliaryTracks.find((e=>{const r=t[e];return"video"===(null==r?void 0:r.type)&&"screen"===(null==r?void 0:r.source)}));e&&o.push({track:t[e],peer:n})}}return o},H={width:1,height:1};const O=e=>e.reduce(((e,t)=>(e[t.id]=t,e)),{});exports.HMSRoomProvider=({children:t,actions:i,store:o,notifications:n,stats:a,isHMSStatsOn:c=!1,leaveOnUnload:u=!0})=>{const d=e.useMemo((()=>{let e;const t=()=>{throw new Error("modifying store is not allowed")};if(i&&o)e={actions:i,store:l.default(Object.assign(Object.assign({},o),{setState:t,destroy:t}))},n&&(e.notifications=n),a&&(e.statsStore=l.default({getState:a.getState,subscribe:a.subscribe,setState:t,destroy:t}));else{const i=new r.HMSReactiveStore;if(e={actions:i.getActions(),store:l.default(Object.assign(Object.assign({},i.getStore()),{setState:t,destroy:t})),notifications:i.getNotifications()},c){const r=i.getStats();e.statsStore=l.default({getState:r.getState,subscribe:r.subscribe,setState:t,destroy:t})}}return e.actions.setFrameworkInfo({type:"react-web",version:s.default.version,sdkVersion:"0.8.23-alpha.2"}),e}),[i,o,n,a,c]);return e.useEffect((()=>{if(h&&u){const e=()=>d.actions.leave();return window.addEventListener("unload",e),()=>{window.removeEventListener("unload",e)}}return()=>{}}),[u,d]),s.default.createElement(f.Provider,{value:d},t)},exports.getPeersWithTiles=T,exports.throwErrorHandler=e=>{throw e},exports.useAVToggle=(t=b)=>{const i=g(r.selectIsLocalAudioEnabled),o=g(r.selectIsLocalVideoEnabled),n=g(r.selectIsInPreview)?r.selectIsAllowedToPreviewMedia:r.selectIsAllowedToPublish,a=g(n),s=y(),l=e.useCallback((()=>P(void 0,void 0,void 0,(function*(){try{yield s.setLocalAudioEnabled(!i)}catch(e){t(e,"toggleAudio")}}))),[s,i,t]),c=e.useCallback((()=>P(void 0,void 0,void 0,(function*(){try{yield s.setLocalVideoEnabled(!o)}catch(e){t(e,"toggleVideo")}}))),[s,o,t]);return{isLocalAudioEnabled:i,isLocalVideoEnabled:o,toggleAudio:(null==a?void 0:a.audio)?l:void 0,toggleVideo:(null==a?void 0:a.video)?c:void 0}},exports.useAudioLevelStyles=function({trackId:t,getStyle:i,ref:o}){const n=m();e.useEffect((()=>n.subscribe((e=>{if(!o.current)return;const t=i(e);for(const e in t)o.current.style[e]=t[e]}),r.selectTrackAudioByID(t))),[i,o,n,t])},exports.useAutoplayError=()=>{const t=S(r.HMSNotificationTypes.ERROR),[i,o]=e.useState(""),n=y(),a=e.useCallback((()=>P(void 0,void 0,void 0,(function*(){yield n.unblockAudio()}))),[n]);return e.useEffect((()=>{3008===(null==t?void 0:t.data.code)&&o(null==t?void 0:t.data.message)}),[t]),{error:i,unblockAudio:a,resetError:()=>o("")}},exports.useCustomEvent=({type:t,json:i=!0,onEvent:o,handleError:n=b})=>{const a=y(),s=w();e.useEffect((()=>{a.ignoreMessageTypes([t])}),[a,t]),e.useEffect((()=>{if(!s)return;return s.onNotification((e=>{const r=e.data;if(r&&r.type===t)try{const e=i?JSON.parse(r.message):r.message;null==o||o(e)}catch(e){n(e,"handleCustomEvent")}}),r.HMSNotificationTypes.NEW_MESSAGE)}),[s,t,i,o,n]);return{sendEvent:e.useCallback(((e,r)=>P(void 0,void 0,void 0,(function*(){try{const n=((e,t)=>t?JSON.stringify(e||""):e)(e,i);r&&Array.isArray(null==r?void 0:r.roleNames)?yield a.sendGroupMessage(n,r.roleNames,t):"string"==typeof(null==r?void 0:r.peerId)?yield a.sendDirectMessage(n,r.peerId,t):yield a.sendBroadcastMessage(n,t),null==o||o(e)}catch(e){n(e,"sendCustomEvent")}}))),[a,n,o,t,i])}},exports.useDevices=(t=b)=>{const i=y(),o=g(r.selectDevices),n=g(r.selectLocalMediaSettings),a=g(r.selectIsInPreview)?r.selectIsAllowedToPreviewMedia:r.selectIsAllowedToPublish,s=g(a),l={[r.DeviceType.audioOutput]:n.audioOutputDeviceId},c={[r.DeviceType.audioOutput]:o.audioOutput};s.video&&(c[r.DeviceType.videoInput]=o.videoInput,l[r.DeviceType.videoInput]=n.videoInputDeviceId),s.audio&&(c[r.DeviceType.audioInput]=o.audioInput,l[r.DeviceType.audioInput]=n.audioInputDeviceId);return{allDevices:c,selectedDeviceIDs:l,updateDevice:e.useCallback((({deviceType:e,deviceId:o})=>P(void 0,void 0,void 0,(function*(){try{switch(e){case r.DeviceType.audioInput:yield i.setAudioSettings({deviceId:o});break;case r.DeviceType.videoInput:yield i.setVideoSettings({deviceId:o});break;case r.DeviceType.audioOutput:yield i.setAudioOutputDevice(o)}}catch(e){t(e,"updateDevices")}}))),[t,i])}},exports.useEmbedShare=t=>{const r=e.useRef(null),[i,o]=e.useState(!1),n=e.useCallback((()=>{throw new Error("unable to start screen share")}),[]),a=e.useRef(!1),{amIScreenSharing:s,toggleScreenShare:l}=R(n),c=E(s),u=e.useCallback((()=>P(void 0,void 0,void 0,(function*(){s&&(yield null==l?void 0:l(),r.current=null)}))),[s,l]),d=e.useCallback((e=>P(void 0,void 0,void 0,(function*(){if(!a.current){if(!e)throw new Error("URL not found");if(s)throw new Error("You are already sharing");if(!r.current)throw new Error("Attach a reference `iframeRef` to iframe for sharing");r.current.src=e,a.current=!0,o(!0),yield null==l?void 0:l({forceCurrentTab:k,cropElement:r.current,preferCurrentTab:k})}}))),[s,l]);return e.useEffect((()=>{c&&!s&&(null==t||t(),r.current&&(r.current.src=""),a.current=!1,o(!1))}),[s,c,t]),{startEmbedShare:d,stopEmbedShare:u,iframeRef:r,isEmbedShareInProgress:i}},exports.useHMSActions=y,exports.useHMSNotifications=S,exports.useHMSStatsStore=p,exports.useHMSStore=g,exports.useHMSVanillaNotifications=w,exports.useHMSVanillaStore=m,exports.usePDFShare=t=>{const r=e.useRef(null),[i,o]=e.useState(!1),n=e.useCallback((()=>{throw new Error("unable to start screen share")}),[]),a=e.useRef(!1),{amIScreenSharing:s,toggleScreenShare:l}=R(n),c=E(s),u=e.useCallback((e=>{var t;r.current&&(null===(t=r.current.contentWindow)||void 0===t||t.postMessage({theme:2,file:e},"*"))}),[]),d=e.useCallback((()=>P(void 0,void 0,void 0,(function*(){s&&(yield null==l?void 0:l())}))),[s,l]),h=e.useCallback((e=>P(void 0,void 0,void 0,(function*(){if(!a.current){if(!e)throw new Error("File or url not found");if(s)throw new Error("You are already sharing");if(!r.current)throw new Error("Attach a reference `iframeRef` to iframe for sharing");r.current.src="https://pdf-annotation.100ms.live/generic/web/viewer.html"+("string"==typeof e?`?file=${e}`:""),r.current.onload=()=>{requestAnimationFrame((()=>{e instanceof File&&u(e)}))},a.current=!0,o(!0),yield null==l?void 0:l({forceCurrentTab:k,cropElement:r.current,preferCurrentTab:k})}}))),[s,u,l]);return e.useEffect((()=>{c&&!s&&(null==t||t(),r.current&&r.current.removeAttribute("src"),a.current=!1,o(!1))}),[s,c,t]),{startPDFShare:h,stopPDFShare:d,iframeRef:r,isPDFShareInProgress:i}},exports.usePaginatedParticipants=t=>{const r=y(),i=e.useRef(r.getPeerListIterator(t)),[o,n]=e.useState({}),[a,s]=e.useState(0);return{loadPeers:()=>i.current.findPeers().then((e=>{n(O(e)),s(i.current.getTotal())})),loadMorePeers:()=>i.current.next().then((e=>{n((t=>Object.assign(Object.assign({},t),O(e)))),s(i.current.getTotal())})),hasNext:()=>i.current.hasNext(),total:a,peers:Object.values(o)}},exports.useParticipantList=()=>{const t=g(r.selectIsConnectedToRoom),i=g(t?r.selectPeers:r.selectRemotePeers),o=g(r.selectPeerCount),n=e.useMemo((()=>{return(e=i)&&Array.isArray(e)&&0!==e.length?e.reduce(((e,t)=>t.roleName?(e[t.roleName]||(e[t.roleName]=[]),e[t.roleName].push(t),e):e),{}):{};var e}),[i]);return{roles:Object.keys(n),participantsByRoles:n,peerCount:o,isConnected:t}},exports.useParticipants=e=>{var t;const i=g(r.selectIsConnectedToRoom),o=g(r.selectPeerCount),n=g(r.selectAvailableRoleNames);let a=g(i?r.selectPeers:r.selectRemotePeers);const s=Array.from(new Set(a.map((e=>e.roleName)))),l=m();if((null===(t=null==e?void 0:e.metadata)||void 0===t?void 0:t.isHandRaised)&&(a=a.filter((e=>l.getState(r.selectPeerMetadata(e.id)).isHandRaised))),(null==e?void 0:e.role)&&n.includes(e.role)&&(a=a.filter((t=>t.roleName===e.role))),null==e?void 0:e.search){const t=e.search.toLowerCase();a=a.filter((e=>{var r;return(null===(r=e.roleName)||void 0===r?void 0:r.toLowerCase().includes(t))||e.name.toLowerCase().includes(t)}))}return{participants:a,isConnected:i,peerCount:o,rolesWithParticipants:s}},exports.usePreviewJoin=({name:t="",token:i,metadata:o,handleError:n=b,initEndpoint:a,initialSettings:s,captureNetworkQualityInPreview:l,asRole:c,autoManageVideo:u,autoManageWakeLock:d})=>{const h=y(),f=g(r.selectRoomState),v=g(r.selectIsConnectedToRoom)||!1,p=f===r.HMSRoomState.Preview,m=e.useMemo((()=>({userName:t,authToken:i,metaData:o,rememberDeviceSelection:!0,settings:s,initEndpoint:a,asRole:c,captureNetworkQualityInPreview:l,autoManageVideo:u,autoManageWakeLock:d})),[t,i,o,a,s,l,c,u,d]),w=e.useCallback((()=>P(void 0,void 0,void 0,(function*(){if(i)try{(v||f!==r.HMSRoomState.Disconnected)&&(yield h.leave().catch((()=>{}))),yield h.preview(m)}catch(e){n(e,"preview")}}))),[i,v,f,h,m,n]);return{enableJoin:p,join:e.useCallback((()=>P(void 0,void 0,void 0,(function*(){if(i)try{yield h.join(m)}catch(e){n(e,"join")}}))),[h,m,n,i]),isConnected:v,preview:w}},exports.useRecordingStreaming=()=>{const e=g(r.selectRecordingState),t=g(r.selectRTMPState),i=g(r.selectHLSState),o=e.server.running,n=e.browser.running,a=e.hls.running,s=o||n||a;return{isServerRecordingOn:o,isBrowserRecordingOn:n,isHLSRecordingOn:a,isStreamingOn:i.running||t.running,isHLSRunning:i.running,isRTMPRunning:t.running,isRecordingOn:s}},exports.useRemoteAVToggle=(t,i,o=b)=>{const n=y(),a=g(r.selectAudioTrackByID(t)),s=g(r.selectVideoTrackByID(i)),l=g(r.selectAudioTrackVolume(null==a?void 0:a.id)),c=g(r.selectPermissions),u=(null==s?void 0:s.enabled)?null==c?void 0:c.mute:null==c?void 0:c.unmute,d=(null==a?void 0:a.enabled)?null==c?void 0:c.mute:null==c?void 0:c.unmute,h=e.useCallback((()=>P(void 0,void 0,void 0,(function*(){yield I(n,a,o)}))),[n,a,o]),f=e.useCallback((()=>P(void 0,void 0,void 0,(function*(){yield I(n,s,o)}))),[n,o,s]),v=e.useCallback((e=>{a&&n.setVolume(e,a.id)}),[n,a]);return{isAudioEnabled:!!(null==a?void 0:a.enabled),isVideoEnabled:!!(null==s?void 0:s.enabled),volume:l,toggleAudio:a&&d?h:void 0,toggleVideo:"regular"===(null==s?void 0:s.source)&&u?f:void 0,setVolume:a?v:void 0}},exports.useScreenShare=R,exports.useVideo=({trackId:t,attach:i})=>{const o=y(),n=e.useRef(null),a=g(r.selectVideoTrackByID(t)),s=e.useRef(),l=e.useCallback((e=>{e&&(n.current=e)}),[]);return e.useEffect((()=>{s.current?(null==a?void 0:a.id)&&s.current!==(null==a?void 0:a.id)&&P(void 0,void 0,void 0,(function*(){if(n.current)try{u.d("detaching because different track is passed"),yield o.detachVideo(s.current,n.current)}catch(e){u.w("detach video error for track",s.current,e)}s.current=null==a?void 0:a.id})):s.current=null==a?void 0:a.id}),[null==a?void 0:a.id,o]),e.useEffect((()=>{P(void 0,void 0,void 0,(function*(){(null==a?void 0:a.id)&&n.current&&(!1!==i?yield o.attachVideo(a.id,n.current):yield o.detachVideo(a.id,n.current))}))}),[a,i,o]),e.useEffect((()=>()=>{P(void 0,void 0,void 0,(function*(){if(n.current&&a)try{yield o.detachVideo(a.id,n.current)}catch(e){u.w("detach video error for track",a.id,e)}}))}),[]),{videoRef:l}},exports.useVideoList=({peers:t,maxTileCount:o,maxColCount:n,maxRowCount:a,includeScreenShareForPeer:s=(()=>!1),aspectRatio:l=H,filterNonPublishingPeers:c=!0,offsetY:u=0})=>{const{width:d=0,height:h=0,ref:f}=i.useResizeDetector(),g=m().getState(r.selectTracksMap),v=T(t,g,s,c),p=e.useMemo((()=>{if(l)return l;return{width:function(e){if(0===e.length)return null;const t={};let r=e[0],i=1;for(let o=0;o<e.length;o++){const n=e[o];null===t[n]?t[n]=1:t[n]++,t[n]>i&&(r=n,i=t[n])}return r}(v.filter((e=>{var t,r;return(null===(t=e.track)||void 0===t?void 0:t.width)&&(null===(r=e.track)||void 0===r?void 0:r.height)})).map((e=>{var t,r;return((null===(t=e.track)||void 0===t?void 0:t.width)||1)/((null===(r=e.track)||void 0===r?void 0:r.height)||1)})))||1,height:1}}),[l,v]),w=v.length,{tilesInFirstPage:y,defaultWidth:S,defaultHeight:P,lastPageWidth:b,lastPageHeight:E,isLastPageDifferentFromFirstPage:k}=e.useMemo((()=>x({count:w,parentWidth:Math.floor(d),parentHeight:Math.floor(h)-Math.min(h,u),maxTileCount:o,maxRowCount:a,maxColCount:n,aspectRatio:p})),[w,d,h,o,a,n,p,u]);return{pagesWithTiles:e.useMemo((()=>M({elements:v,tilesInFirstPage:y,onlyOnePage:!1,isLastPageDifferentFromFirstPage:k,defaultWidth:S,defaultHeight:P,lastPageWidth:b,lastPageHeight:E})),[v,y,k,S,P,b,E]),ref:f}},Object.keys(r).forEach((function(e){"default"===e||exports.hasOwnProperty(e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return r[e]}})}));
2
2
  //# sourceMappingURL=index.cjs.js.map
@@ -1,2 +1,2 @@
1
- import t,{createContext as e,useMemo as o,useEffect as r,useContext as s,useState as n}from"react";import i from"zustand";import{HMSReactiveStore as a}from"@100mslive/hms-video-store";import{makeHMSStoreHook as c,makeHMSStatsStoreHook as f,hooksErrorMessage as u}from"./store.js";import{isBrowser as l}from"../utils/isBrowser.js";const w=e(null),d=({children:e,actions:s,store:n,notifications:c,stats:f,isHMSStatsOn:u=!1,leaveOnUnload:d=!0})=>{const m=o((()=>{let e;const o=()=>{throw new Error("modifying store is not allowed")};if(s&&n)e={actions:s,store:i(Object.assign(Object.assign({},n),{setState:o,destroy:o}))},c&&(e.notifications=c),f&&(e.statsStore=i({getState:f.getState,subscribe:f.subscribe,setState:o,destroy:o}));else{const t=new a;if(e={actions:t.getActions(),store:i(Object.assign(Object.assign({},t.getStore()),{setState:o,destroy:o})),notifications:t.getNotifications()},u){const r=t.getStats();e.statsStore=i({getState:r.getState,subscribe:r.subscribe,setState:o,destroy:o})}}return e.actions.setFrameworkInfo({type:"react-web",version:t.version,sdkVersion:"0.8.23-alpha.0"}),e}),[s,n,c,f,u]);return r((()=>{if(l&&d){const t=()=>m.actions.leave();return window.addEventListener("unload",t),()=>{window.removeEventListener("unload",t)}}return()=>{}}),[d,m]),t.createElement(w.Provider,{value:m},e)},m=c(w),S=f(w),b=()=>{const t=s(w);if(!t)throw new Error(u);return t.store},g=()=>{const t=s(w);if(!t)throw new Error(u);return t.notifications},v=()=>{const t=s(w);if(!t)throw new Error(u);return t.actions},h=t=>{const e=s(w),[o,i]=n(null);if(!e)throw new Error(u);return r((()=>{if(!e.notifications)return;return e.notifications.onNotification((t=>{i(t)}),t)}),[e.notifications,t]),o};export{d as HMSRoomProvider,v as useHMSActions,h as useHMSNotifications,S as useHMSStatsStore,m as useHMSStore,g as useHMSVanillaNotifications,b as useHMSVanillaStore};
1
+ import t,{createContext as e,useMemo as o,useEffect as r,useContext as s,useState as n}from"react";import i from"zustand";import{HMSReactiveStore as a}from"@100mslive/hms-video-store";import{makeHMSStoreHook as c,makeHMSStatsStoreHook as f,hooksErrorMessage as u}from"./store.js";import{isBrowser as l}from"../utils/isBrowser.js";const w=e(null),d=({children:e,actions:s,store:n,notifications:c,stats:f,isHMSStatsOn:u=!1,leaveOnUnload:d=!0})=>{const m=o((()=>{let e;const o=()=>{throw new Error("modifying store is not allowed")};if(s&&n)e={actions:s,store:i(Object.assign(Object.assign({},n),{setState:o,destroy:o}))},c&&(e.notifications=c),f&&(e.statsStore=i({getState:f.getState,subscribe:f.subscribe,setState:o,destroy:o}));else{const t=new a;if(e={actions:t.getActions(),store:i(Object.assign(Object.assign({},t.getStore()),{setState:o,destroy:o})),notifications:t.getNotifications()},u){const r=t.getStats();e.statsStore=i({getState:r.getState,subscribe:r.subscribe,setState:o,destroy:o})}}return e.actions.setFrameworkInfo({type:"react-web",version:t.version,sdkVersion:"0.8.23-alpha.2"}),e}),[s,n,c,f,u]);return r((()=>{if(l&&d){const t=()=>m.actions.leave();return window.addEventListener("unload",t),()=>{window.removeEventListener("unload",t)}}return()=>{}}),[d,m]),t.createElement(w.Provider,{value:m},e)},m=c(w),S=f(w),b=()=>{const t=s(w);if(!t)throw new Error(u);return t.store},g=()=>{const t=s(w);if(!t)throw new Error(u);return t.notifications},v=()=>{const t=s(w);if(!t)throw new Error(u);return t.actions},h=t=>{const e=s(w),[o,i]=n(null);if(!e)throw new Error(u);return r((()=>{if(!e.notifications)return;return e.notifications.onNotification((t=>{i(t)}),t)}),[e.notifications,t]),o};export{d as HMSRoomProvider,v as useHMSActions,h as useHMSNotifications,S as useHMSStatsStore,m as useHMSStore,g as useHMSVanillaNotifications,b as useHMSVanillaStore};
2
2
  //# sourceMappingURL=HmsRoomProvider.js.map
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "main": "dist/index.cjs.js",
5
5
  "module": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
7
- "version": "0.8.23-alpha.0",
7
+ "version": "0.8.23-alpha.2",
8
8
  "author": "100ms",
9
9
  "license": "MIT",
10
10
  "files": [
@@ -43,9 +43,9 @@
43
43
  "react": ">=16.8 <19.0.0"
44
44
  },
45
45
  "dependencies": {
46
- "@100mslive/hms-video-store": "0.10.23-alpha.0",
46
+ "@100mslive/hms-video-store": "0.10.23-alpha.2",
47
47
  "react-resize-detector": "^7.0.0",
48
48
  "zustand": "^3.6.2"
49
49
  },
50
- "gitHead": "47c92f0479d2c2066f78d66333d669a33e5e38e6"
50
+ "gitHead": "1b964f1d356fe098de341574a63a6c3b5332e418"
51
51
  }