@100mslive/react-sdk 0.11.2-alpha.5 → 0.11.2-alpha.6

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"),i=require("@100mslive/hms-video-store"),o=require("react-resize-detector");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n,s,a=r(e),c=r(t);function l(e,t){if(Object.is(e,t))return!0;if("object"!=typeof e||null===e||"object"!=typeof t||null===t)return!1;const i=Object.keys(e);if(i.length!==Object.keys(t).length)return!1;for(let o=0;o<i.length;o++)if(!Object.prototype.hasOwnProperty.call(t,i[o])||!Object.is(e[i[o]],t[i[o]]))return!1;return!0}(s=n||(n={}))[s.VERBOSE=0]="VERBOSE",s[s.DEBUG=1]="DEBUG",s[s.INFO=2]="INFO",s[s.WARN=3]="WARN",s[s.ERROR=4]="ERROR",s[s.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,...i){if(!(this.level.valueOf()>e.valueOf()))switch(e){case n.VERBOSE:console.log("HMSui-components: ",t,...i);break;case n.DEBUG:console.debug("HMSui-components: ",t,...i);break;case n.INFO:console.info("HMSui-components: ",t,...i);break;case n.WARN:console.warn("HMSui-components: ",t,...i);break;case n.ERROR:console.error("HMSui-components: ",t,...i)}}}u.level=n.VERBOSE;var d=u;const h="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 f="undefined"!=typeof window,v=e.createContext(null),g=(p=v,(t,i=l)=>{t||d.w("fetching full store without passing any selector may have a heavy performance impact on your website.");const o=e.useContext(p);if(!o)throw new Error(h);return(0,o.store)(t,i)});var p;const m=function(t){return(i,o=l)=>{i||d.w("fetching full store without passing any selector may have a heavy performance impact on your website.");const r=e.useContext(t);if(!r)throw new Error(h);const n=r.statsStore;return null==n?void 0:n(i,o)}}(v),w=()=>{const t=e.useContext(v);if(!t)throw new Error(h);return t.store},S=()=>{const t=e.useContext(v);if(!t)throw new Error(h);return t.notifications},y=()=>{const t=e.useContext(v);if(!t)throw new Error(h);return t.actions},b=t=>{const i=e.useContext(v),[o,r]=e.useState(null);if(!i)throw new Error(h);return e.useEffect((()=>{if(!i.notifications)return;return i.notifications.onNotification((e=>{r(e)}),t)}),[i.notifications,t]),o};function P(e,t,i,o){return new(i||(i=Promise))((function(r,n){function s(e){try{c(o.next(e))}catch(e){n(e)}}function a(e){try{c(o.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(s,a)}c((o=o.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const E=(e,t)=>d.e("react-sdk",t,e);function k(t){const i=e.useRef();return e.useEffect((()=>{i.current=t})),i.current}const M=["blink"].some((e=>{var t,o;return(null===(o=null===(t=i.parsedUserAgent.getEngine())||void 0===t?void 0:t.name)||void 0===o?void 0:o.toLowerCase())===e})),R=(t=E)=>{var o,r;const n=y(),s=g(i.selectIsLocalScreenShared),a=g(i.selectPeerScreenSharing),c=g(i.selectScreenSharesByPeerId(null==a?void 0:a.id)),l=e.useCallback((e=>P(void 0,void 0,void 0,(function*(){try{yield n.setScreenShareEnabled(!s,e)}catch(e){t(e,"toggleScreenShare")}}))),[n,s,t]);return{amIScreenSharing:s,screenSharingPeerId:null==a?void 0:a.id,screenSharingPeerName:null==a?void 0:a.name,screenShareVideoTrackId:null===(o=null==c?void 0:c.video)||void 0===o?void 0:o.id,screenShareAudioTrackId:null===(r=null==c?void 0:c.audio)||void 0===r?void 0:r.id,toggleScreenShare:l}},C=(e,t,i)=>P(void 0,void 0,void 0,(function*(){if(t)try{yield e.setRemoteTrackEnabled(t.id,!t.enabled)}catch(e){i(e,"remoteToggle")}})),I=({elements:e,tilesInFirstPage:t,onlyOnePage:i,isLastPageDifferentFromFirstPage:o,defaultWidth:r,defaultHeight:n,lastPageWidth:s,lastPageHeight:a})=>{const c=((e,t,i)=>e.reduce(((e,o,r)=>{const n=Math.floor(r/t);return n>0&&i||(e[n]||(e[n]=[]),e[n].push(o)),e}),[]))(e,t,i);return c.map(((e,t)=>e.map((e=>{const i=t===c.length-1,l=o&&i?s:r,u=o&&i?a:n;return Object.assign(Object.assign({},e),{height:u,width:l})}))))};const N=(e,t,i,o,r)=>{if(e<0||t<0)throw new Error("Container must have a non-negative area");if(i<1||!Number.isInteger(i))throw new Error("Number of shapes to place must be a positive integer");const n=o&&r&&o/r;if(void 0!==n&&isNaN(n))throw new Error("Aspect ratio must be a number");let s={area:0,cols:0,rows:0,width:0,height:0};if(void 0!==n)for(let o=i;o>0;o+=-1){const r=Math.ceil(i/o);let a,c;e/(o*n)<=t/r?(a=e/o,c=a/n):(c=t/r,a=c*n);const l=a*c;l>s.area&&(s={area:l,width:a,height:c,rows:r,cols:o})}return s};function x({count:e,parentWidth:t,parentHeight:i,maxTileCount:o,maxRowCount:r,maxColCount:n,aspectRatio:s}){let a=0,c=0,l=0,u=0,d=!1,h=0;if(0===e)return{tilesInFirstPage:h,defaultWidth:a,defaultHeight:c,lastPageWidth:l,lastPageHeight:u,isLastPageDifferentFromFirstPage:d};if(o)({tilesInFirstPage:h,defaultWidth:a,defaultHeight:c,lastPageWidth:l,lastPageHeight:u,isLastPageDifferentFromFirstPage:d}=(({parentWidth:e,parentHeight:t,count:i,maxCount:o,aspectRatio:r})=>{let n=0,s=0,a=0,c=0,l=!1,u=0,d=0;const{width:h,height:f}=N(e,t,Math.min(i,o),r.width,r.height);if(n=h,s=f,u=Math.min(i,o),d=i%o,l=d>0&&i>o,l){const{width:i,height:o}=N(e,t,d,r.width,r.height);a=i,c=o}return{tilesInFirstPage:u,defaultWidth:n,defaultHeight:s,lastPageWidth:a,lastPageHeight:c,isLastPageDifferentFromFirstPage:l}})({parentWidth:t,parentHeight:i,count:e,maxCount:o,aspectRatio:s}));else if(r)({tilesInFirstPage:h,defaultWidth:a,defaultHeight:c,lastPageWidth:l,lastPageHeight:u,isLastPageDifferentFromFirstPage:d}=(({parentWidth:e,parentHeight:t,count:i,maxCount:o,aspectRatio:r})=>{let n=0,s=0,a=0,c=0,l=!1,u=0,d=0;const h=Math.min(Math.ceil(Math.sqrt(i*(r.width/r.height)/(e/t))),o),f=t/h,v=f*(r.width/r.height),g=Math.floor(e/v);if(n=v,s=f,u=Math.min(i,h*g),d=i%(h*g),l=d>0&&i>h*g,l){const i=t/Math.min(Math.ceil(Math.sqrt(d*(r.width/r.height)/(e/t))),o);c=i,a=i*(r.width/r.height)}return{tilesInFirstPage:u,defaultWidth:n,defaultHeight:s,lastPageWidth:a,lastPageHeight:c,isLastPageDifferentFromFirstPage:l}})({parentWidth:t,parentHeight:i,count:e,maxCount:r,aspectRatio:s}));else if(n)({tilesInFirstPage:h,defaultWidth:a,defaultHeight:c,lastPageWidth:l,lastPageHeight:u,isLastPageDifferentFromFirstPage:d}=(({parentWidth:e,parentHeight:t,count:i,maxCount:o,aspectRatio:r})=>{let n=0,s=0,a=0,c=0,l=!1,u=0,d=0;const h=Math.min(Math.ceil(Math.sqrt(i*(e/t)/(r.width/r.height))),o);let f=e/h,v=f/(r.width/r.height);v>t&&(v=t,f=v/(r.height/r.width));const g=Math.floor(t/v);if(s=v,n=f,u=Math.min(i,g*h),d=i%(g*h),l=d>0&&i>g*h,l){let i=e/Math.min(Math.ceil(Math.sqrt(d*(e/t)/(r.width/r.height))),o),n=i/(r.width/r.height);n>t&&(n=t,i=n/(r.height/r.width)),c=n,a=i}return{tilesInFirstPage:u,defaultWidth:n,defaultHeight:s,lastPageWidth:a,lastPageHeight:c,isLastPageDifferentFromFirstPage:l}})({parentWidth:t,parentHeight:i,count:e,maxCount:n,aspectRatio:s}));else{const{width:o,height:r}=N(t,i,e,s.width,s.height);a=o,c=r,h=e}return{tilesInFirstPage:h,defaultWidth:a,defaultHeight:c,lastPageWidth:l,lastPageHeight:u,isLastPageDifferentFromFirstPage:d}}const T=(e,t,i,o=!0)=>{if(!e||!t||!i)return[];const r=[];for(const n of e){if(void 0===n.videoTrack&&n.audioTrack&&t[n.audioTrack]?r.push({peer:n}):n.videoTrack&&t[n.videoTrack]?r.push({track:t[n.videoTrack],peer:n}):o||r.push({peer:n}),n.auxiliaryTracks.length>0&&n.auxiliaryTracks.forEach((e=>{const i=t[e];"video"===(null==i?void 0:i.type)&&"regular"===(null==i?void 0:i.source)&&r.push({track:i,peer:n})})),i(n)&&n.auxiliaryTracks.length>0){const e=n.auxiliaryTracks.find((e=>{const i=t[e];return"video"===(null==i?void 0:i.type)&&"screen"===(null==i?void 0:i.source)}));e&&r.push({track:t[e],peer:n})}}return r},H={width:1,height:1};const O=e=>e.reduce(((e,t)=>(e[t.id]=t,e)),{});exports.HMSRoomProvider=({children:t,actions:o,store:r,notifications:n,stats:s,isHMSStatsOn:l=!1,leaveOnUnload:u=!0})=>{const d=e.useMemo((()=>{let e;const t=()=>{throw new Error("modifying store is not allowed")};if(o&&r)e={actions:o,store:c.default(Object.assign(Object.assign({},r),{setState:t,destroy:t}))},n&&(e.notifications=n),s&&(e.statsStore=c.default({getState:s.getState,subscribe:s.subscribe,setState:t,destroy:t}));else{const o=new i.HMSReactiveStore;if(e={actions:o.getActions(),store:c.default(Object.assign(Object.assign({},o.getStore()),{setState:t,destroy:t})),notifications:o.getNotifications()},l){const i=o.getStats();e.statsStore=c.default({getState:i.getState,subscribe:i.subscribe,setState:t,destroy:t})}}return e.actions.setFrameworkInfo({type:"react-web",version:a.default.version,sdkVersion:"0.11.2-alpha.5"}),e}),[o,r,n,s,l]);return e.useEffect((()=>{if(f&&u){const e=()=>d.actions.leave();return window.addEventListener("unload",e),()=>{window.removeEventListener("unload",e)}}return()=>{}}),[u,d]),a.default.createElement(v.Provider,{value:d},t)},exports.getPeersWithTiles=T,exports.throwErrorHandler=e=>{throw e},exports.useAVToggle=(t=E)=>{const o=g(i.selectIsLocalAudioEnabled),r=g(i.selectIsLocalVideoEnabled),n=g(i.selectIsInPreview)?i.selectIsAllowedToPreviewMedia:i.selectIsAllowedToPublish,s=g(n),a=y(),c=e.useCallback((()=>P(void 0,void 0,void 0,(function*(){try{yield a.setLocalAudioEnabled(!o)}catch(e){t(e,"toggleAudio")}}))),[a,o,t]),l=e.useCallback((()=>P(void 0,void 0,void 0,(function*(){try{yield a.setLocalVideoEnabled(!r)}catch(e){t(e,"toggleVideo")}}))),[a,r,t]);return{isLocalAudioEnabled:o,isLocalVideoEnabled:r,toggleAudio:(null==s?void 0:s.audio)?c:void 0,toggleVideo:(null==s?void 0:s.video)?l:void 0}},exports.useAudioLevelStyles=function({trackId:t,getStyle:o,ref:r}){const n=w();e.useEffect((()=>n.subscribe((e=>{if(!r.current)return;const t=o(e);for(const e in t)r.current.style[e]=t[e]}),i.selectTrackAudioByID(t))),[o,r,n,t])},exports.useAudioMode=()=>{const e=y(),{audioMode:t}=g(i.selectLocalMediaSettings),o=t===i.HMSAudioMode.MUSIC;return{toggleMusicMode:()=>P(void 0,void 0,void 0,(function*(){return yield e.setAudioSettings({audioMode:o?i.HMSAudioMode.VOICE:i.HMSAudioMode.MUSIC})})),isMusicModeEnabled:o}},exports.useAutoplayError=()=>{const t=b(i.HMSNotificationTypes.ERROR),[o,r]=e.useState(""),n=y(),s=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)&&r(null==t?void 0:t.data.message)}),[t]),{error:o,unblockAudio:s,resetError:()=>r("")}},exports.useAwayNotifications=()=>{const t=w();return{requestPermission:e.useCallback((()=>P(void 0,void 0,void 0,(function*(){if(!("Notification"in window)||navigator.webdriver)return void console.debug("Request Permsissions : Notifications not supported or headless browser");if("granted"===(null===Notification||void 0===Notification?void 0:Notification.permission)||"denied"===(null===Notification||void 0===Notification?void 0:Notification.permission))return;const e=t.subscribe((t=>P(void 0,void 0,void 0,(function*(){t&&"__internal_recorder"!==t&&(yield Notification.requestPermission(),null==e||e())}))),i.selectLocalPeerRoleName)}))),[t]),showNotification:e.useCallback(((e,t)=>{if(!("Notification"in window))return void console.debug("Show Notifications: Notifications not supported or headless browser");if("denied"===(null===Notification||void 0===Notification?void 0:Notification.permission)||"visible"===document.visibilityState&&document.hasFocus())return;const i=new Notification(e,t),o=()=>{"visible"===document.visibilityState&&document.hasFocus()&&(null==i||i.close(),document.removeEventListener("visibilitychange",o))};document.addEventListener("visibilitychange",o)}),[])}},exports.useCustomEvent=({type:t,json:o=!0,onEvent:r,handleError:n=E})=>{const s=y(),a=S();e.useEffect((()=>{s.ignoreMessageTypes([t])}),[s,t]),e.useEffect((()=>{if(!a)return;return a.onNotification((e=>{const i=e.data;if(i&&i.type===t)try{const e=o?JSON.parse(i.message):i.message;null==r||r(e)}catch(e){n(e,"handleCustomEvent")}}),i.HMSNotificationTypes.NEW_MESSAGE)}),[a,t,o,r,n]);return{sendEvent:e.useCallback(((e,i)=>P(void 0,void 0,void 0,(function*(){try{const n=((e,t)=>t?JSON.stringify(e||""):e)(e,o);i&&Array.isArray(null==i?void 0:i.roleNames)?yield s.sendGroupMessage(n,i.roleNames,t):"string"==typeof(null==i?void 0:i.peerId)?yield s.sendDirectMessage(n,i.peerId,t):yield s.sendBroadcastMessage(n,t),null==r||r(e)}catch(e){n(e,"sendCustomEvent")}}))),[s,n,r,t,o])}},exports.useDevices=(t=E)=>{const o=y(),r=g(i.selectDevices),n=g(i.selectLocalMediaSettings),s=g(i.selectIsInPreview)?i.selectIsAllowedToPreviewMedia:i.selectIsAllowedToPublish,a=g(s),c={[i.DeviceType.audioOutput]:n.audioOutputDeviceId},l={[i.DeviceType.audioOutput]:r.audioOutput};a.video&&(l[i.DeviceType.videoInput]=r.videoInput,c[i.DeviceType.videoInput]=n.videoInputDeviceId),a.audio&&(l[i.DeviceType.audioInput]=r.audioInput,c[i.DeviceType.audioInput]=n.audioInputDeviceId);return{allDevices:l,selectedDeviceIDs:c,updateDevice:e.useCallback((e=>P(void 0,[e],void 0,(function*({deviceType:e,deviceId:r}){try{switch(e){case i.DeviceType.audioInput:yield o.setAudioSettings({deviceId:r});break;case i.DeviceType.videoInput:yield o.setVideoSettings({deviceId:r});break;case i.DeviceType.audioOutput:yield o.setAudioOutputDevice(r)}}catch(e){t(e,"updateDevices")}}))),[t,o])}},exports.useEmbedShare=t=>{const i=e.useRef(null),[o,r]=e.useState(!1),n=e.useCallback((()=>{throw new Error("unable to start screen share")}),[]),s=e.useRef(!1),{amIScreenSharing:a,toggleScreenShare:c}=R(n),l=k(a),u=e.useCallback((()=>P(void 0,void 0,void 0,(function*(){a&&(yield null==c?void 0:c(),i.current=null)}))),[a,c]),d=e.useCallback((e=>P(void 0,void 0,void 0,(function*(){if(!s.current){if(!e)throw new Error("URL not found");if(a)throw new Error("You are already sharing");if(!i.current)throw new Error("Attach a reference `iframeRef` to iframe for sharing");i.current.src=e,s.current=!0,r(!0),yield null==c?void 0:c({forceCurrentTab:M,cropElement:i.current,preferCurrentTab:M})}}))),[a,c]);return e.useEffect((()=>{l&&!a&&(null==t||t(),i.current&&(i.current.src=""),s.current=!1,r(!1))}),[a,l,t]),{startEmbedShare:d,stopEmbedShare:u,iframeRef:i,isEmbedShareInProgress:o}},exports.useHMSActions=y,exports.useHMSNotifications=b,exports.useHMSStatsStore=m,exports.useHMSStore=g,exports.useHMSVanillaNotifications=S,exports.useHMSVanillaStore=w,exports.usePDFShare=t=>{const i=e.useRef(null),[o,r]=e.useState(!1),n=e.useCallback((()=>{throw new Error("unable to start screen share")}),[]),s=e.useRef(!1),{amIScreenSharing:a,toggleScreenShare:c}=R(n),l=k(a),u=e.useCallback((e=>{var t;i.current&&(null===(t=i.current.contentWindow)||void 0===t||t.postMessage({theme:2,file:e},"*"))}),[]),d=e.useCallback((()=>P(void 0,void 0,void 0,(function*(){a&&(yield null==c?void 0:c())}))),[a,c]),h=e.useCallback((e=>P(void 0,void 0,void 0,(function*(){if(s.current)return;if(!e)throw new Error("File or url not found");if(a)throw new Error("You are already sharing");if(!i.current)throw new Error("Attach a reference `iframeRef` to iframe for sharing");i.current.src="https://pdf-annotation.100ms.live/generic/web/viewer.html"+("string"==typeof e?`?file=${e}`:""),i.current.onload=()=>{requestAnimationFrame((()=>{e instanceof File&&u(e)}))},s.current=!0,r(!0);const t=window.self!==window.top;yield null==c?void 0:c({forceCurrentTab:M&&!t,cropElement:i.current,preferCurrentTab:M&&!t})}))),[a,u,c]);return e.useEffect((()=>{l&&!a&&(null==t||t(),i.current&&i.current.removeAttribute("src"),s.current=!1,r(!1))}),[a,l,t]),{startPDFShare:h,stopPDFShare:d,iframeRef:i,isPDFShareInProgress:o}},exports.usePaginatedParticipants=t=>{const i=y(),o=e.useRef(i.getPeerListIterator(t)),[r,n]=e.useState({}),[s,a]=e.useState(0);return{loadPeers:()=>o.current.findPeers().then((e=>{n(O(e)),a(o.current.getTotal())})),loadMorePeers:()=>o.current.next().then((e=>{n((t=>Object.assign(Object.assign({},t),O(e)))),a(o.current.getTotal())})),hasNext:()=>o.current.hasNext(),total:s,peers:Object.values(r)}},exports.useParticipantList=()=>{const t=g(i.selectIsConnectedToRoom),o=g(t?i.selectPeers:i.selectRemotePeers),r=g(i.selectPeerCount),n=e.useMemo((()=>{return(e=o)&&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}),[o]);return{roles:Object.keys(n),participantsByRoles:n,peerCount:r,isConnected:t}},exports.useParticipants=e=>{var t;const o=g(i.selectIsConnectedToRoom),r=g(i.selectPeerCount),n=g(i.selectAvailableRoleNames);let s=g(o?i.selectPeers:i.selectRemotePeers);const a=Array.from(new Set(s.map((e=>e.roleName)))),c=w();if((null===(t=null==e?void 0:e.metadata)||void 0===t?void 0:t.isHandRaised)&&(s=s.filter((e=>c.getState(i.selectPeerMetadata(e.id)).isHandRaised))),(null==e?void 0:e.role)&&n.includes(e.role)&&(s=s.filter((t=>t.roleName===e.role))),null==e?void 0:e.search){const t=e.search.toLowerCase();s=s.filter((e=>{var i;return(null===(i=e.roleName)||void 0===i?void 0:i.toLowerCase().includes(t))||e.name.toLowerCase().includes(t)}))}return{participants:s,isConnected:o,peerCount:r,rolesWithParticipants:a}},exports.usePreviewJoin=({name:t="",token:o,metadata:r,handleError:n=E,initEndpoint:s,initialSettings:a,captureNetworkQualityInPreview:c,asRole:l,autoManageVideo:u,autoManageWakeLock:d,iceServers:h})=>{const f=y(),v=g(i.selectRoomState),p=g(i.selectIsConnectedToRoom)||!1,m=v===i.HMSRoomState.Preview,w=e.useMemo((()=>({userName:t,authToken:o,metaData:r,rememberDeviceSelection:!0,settings:a,initEndpoint:s,asRole:l,captureNetworkQualityInPreview:c,autoManageVideo:u,autoManageWakeLock:d,iceServers:h})),[t,o,r,s,a,c,l,u,d,h]),S=e.useCallback((()=>P(void 0,void 0,void 0,(function*(){if(o)try{(p||v!==i.HMSRoomState.Disconnected)&&(yield f.leave().catch((()=>{}))),yield f.preview(w)}catch(e){n(e,"preview")}}))),[o,p,v,f,w,n]);return{enableJoin:m,join:e.useCallback((()=>P(void 0,void 0,void 0,(function*(){if(o)try{yield f.join(w)}catch(e){n(e,"join")}}))),[f,w,n,o]),isConnected:p,preview:S}},exports.useRecordingStreaming=()=>{const e=g(i.selectRecordingState),t=g(i.selectRTMPState),o=g(i.selectHLSState),r=e.server.running,n=e.browser.running,s=e.hls.running,a=r||n||s;return{isServerRecordingOn:r,isBrowserRecordingOn:n,isHLSRecordingOn:s,isStreamingOn:o.running||t.running,isHLSRunning:o.running,isRTMPRunning:t.running,isRecordingOn:a}},exports.useRemoteAVToggle=(t,o,r=E)=>{const n=y(),s=g(i.selectAudioTrackByID(t)),a=g(i.selectVideoTrackByID(o)),c=g(i.selectAudioTrackVolume(null==s?void 0:s.id)),l=g(i.selectPermissions),u=(null==a?void 0:a.enabled)?null==l?void 0:l.mute:null==l?void 0:l.unmute,d=(null==s?void 0:s.enabled)?null==l?void 0:l.mute:null==l?void 0:l.unmute,h=e.useCallback((()=>P(void 0,void 0,void 0,(function*(){yield C(n,s,r)}))),[n,s,r]),f=e.useCallback((()=>P(void 0,void 0,void 0,(function*(){yield C(n,a,r)}))),[n,r,a]),v=e.useCallback((e=>{s&&n.setVolume(e,s.id)}),[n,s]);return{isAudioEnabled:!!(null==s?void 0:s.enabled),isVideoEnabled:!!(null==a?void 0:a.enabled),volume:c,toggleAudio:s&&d?h:void 0,toggleVideo:"regular"===(null==a?void 0:a.source)&&u?f:void 0,setVolume:s?v:void 0}},exports.useScreenShare=R,exports.useTranscript=({onTranscript:t,handleError:o=E})=>{const r="hms_transcript",n=S();e.useEffect((()=>{if(!n)return;return n.onNotification((e=>{const i=e.data;if(i&&i.type===r)try{const e=JSON.parse(i.message).results;null==t||t(e)}catch(e){o(e,"handleCaptionEvent")}}),i.HMSNotificationTypes.NEW_MESSAGE)}),[n,r,o,t])},exports.useVideo=({trackId:t,attach:o})=>{const r=y(),n=e.useRef(null),s=g(i.selectVideoTrackByID(t)),a=e.useRef(),c=e.useCallback((e=>{e&&(n.current=e)}),[]);return e.useEffect((()=>{a.current?(null==s?void 0:s.id)&&a.current!==(null==s?void 0:s.id)&&P(void 0,void 0,void 0,(function*(){if(n.current)try{d.d("detaching because different track is passed"),yield r.detachVideo(a.current,n.current)}catch(e){d.w("detach video error for track",a.current,e)}a.current=null==s?void 0:s.id})):a.current=null==s?void 0:s.id}),[null==s?void 0:s.id,r]),e.useEffect((()=>{P(void 0,void 0,void 0,(function*(){(null==s?void 0:s.id)&&n.current&&(!1!==o?yield r.attachVideo(s.id,n.current):yield r.detachVideo(s.id,n.current))}))}),[s,o,r]),e.useEffect((()=>()=>{P(void 0,void 0,void 0,(function*(){if(n.current&&s)try{yield r.detachVideo(s.id,n.current)}catch(e){d.w("detach video error for track",s.id,e)}}))}),[]),{videoRef:c}},exports.useVideoList=({peers:t,maxTileCount:r,maxColCount:n,maxRowCount:s,includeScreenShareForPeer:a=(()=>!1),aspectRatio:c=H,filterNonPublishingPeers:l=!0,offsetY:u=0})=>{const{width:d=0,height:h=0,ref:f}=o.useResizeDetector(),v=w().getState(i.selectTracksMap),g=T(t,v,a,l),p=e.useMemo((()=>{if(c)return c;return{width:function(e){if(0===e.length)return null;const t={};let i=e[0],o=1;for(let r=0;r<e.length;r++){const n=e[r];null===t[n]?t[n]=1:t[n]++,t[n]>o&&(i=n,o=t[n])}return i}(g.filter((e=>{var t,i;return(null===(t=e.track)||void 0===t?void 0:t.width)&&(null===(i=e.track)||void 0===i?void 0:i.height)})).map((e=>{var t,i;return((null===(t=e.track)||void 0===t?void 0:t.width)||1)/((null===(i=e.track)||void 0===i?void 0:i.height)||1)})))||1,height:1}}),[c,g]),m=g.length,{tilesInFirstPage:S,defaultWidth:y,defaultHeight:b,lastPageWidth:P,lastPageHeight:E,isLastPageDifferentFromFirstPage:k}=e.useMemo((()=>x({count:m,parentWidth:Math.floor(d),parentHeight:Math.floor(h)-Math.min(h,u),maxTileCount:r,maxRowCount:s,maxColCount:n,aspectRatio:p})),[m,d,h,r,s,n,p,u]);return{pagesWithTiles:e.useMemo((()=>I({elements:g,tilesInFirstPage:S,onlyOnePage:!1,isLastPageDifferentFromFirstPage:k,defaultWidth:y,defaultHeight:b,lastPageWidth:P,lastPageHeight:E})),[g,S,k,y,b,P,E]),ref:f}},exports.useWhiteboard=(t=!1)=>{var o,r;const n=g(i.selectIsConnectedToRoom),s=null===(o=g(i.selectLocalPeer))||void 0===o?void 0:o.customerUserId,a=g(i.selectWhiteboard),c=g(i.selectAppData("disableNotifications")),l=!!(null==a?void 0:a.open),u=(null==a?void 0:a.owner)===s,d=y(),[h,f]=e.useState(!1),v=null===(r=g(i.selectPermissions))||void 0===r?void 0:r.whiteboard,p=!!(null==v?void 0:v.includes("admin"));e.useEffect((()=>{n&&f(d.interactivityCenter.whiteboard.isEnabled)}),[n,d]);const m=e.useCallback((()=>P(void 0,void 0,void 0,(function*(){n&&p&&(l?u&&(yield d.interactivityCenter.whiteboard.close()):yield d.interactivityCenter.whiteboard.open())}))),[d,u,p,l,n]);return{open:l,token:null==a?void 0:a.token,endpoint:null==a?void 0:a.addr,isOwner:u,isAdmin:p,zoomToContent:c||t,toggle:h&&p?m:void 0}},Object.keys(i).forEach((function(e){"default"===e||exports.hasOwnProperty(e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return i[e]}})}));
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("zustand"),i=require("@100mslive/hms-video-store"),o=require("react-resize-detector");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n,s,a=r(e),c=r(t);function l(e,t){if(Object.is(e,t))return!0;if("object"!=typeof e||null===e||"object"!=typeof t||null===t)return!1;const i=Object.keys(e);if(i.length!==Object.keys(t).length)return!1;for(let o=0;o<i.length;o++)if(!Object.prototype.hasOwnProperty.call(t,i[o])||!Object.is(e[i[o]],t[i[o]]))return!1;return!0}(s=n||(n={}))[s.VERBOSE=0]="VERBOSE",s[s.DEBUG=1]="DEBUG",s[s.INFO=2]="INFO",s[s.WARN=3]="WARN",s[s.ERROR=4]="ERROR",s[s.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,...i){if(!(this.level.valueOf()>e.valueOf()))switch(e){case n.VERBOSE:console.log("HMSui-components: ",t,...i);break;case n.DEBUG:console.debug("HMSui-components: ",t,...i);break;case n.INFO:console.info("HMSui-components: ",t,...i);break;case n.WARN:console.warn("HMSui-components: ",t,...i);break;case n.ERROR:console.error("HMSui-components: ",t,...i)}}}u.level=n.VERBOSE;var d=u;const h="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 f="undefined"!=typeof window,v=e.createContext(null),g=(p=v,(t,i=l)=>{t||d.w("fetching full store without passing any selector may have a heavy performance impact on your website.");const o=e.useContext(p);if(!o)throw new Error(h);return(0,o.store)(t,i)});var p;const m=function(t){return(i,o=l)=>{i||d.w("fetching full store without passing any selector may have a heavy performance impact on your website.");const r=e.useContext(t);if(!r)throw new Error(h);const n=r.statsStore;return null==n?void 0:n(i,o)}}(v),w=()=>{const t=e.useContext(v);if(!t)throw new Error(h);return t.store},S=()=>{const t=e.useContext(v);if(!t)throw new Error(h);return t.notifications},y=()=>{const t=e.useContext(v);if(!t)throw new Error(h);return t.actions},b=t=>{const i=e.useContext(v),[o,r]=e.useState(null);if(!i)throw new Error(h);return e.useEffect((()=>{if(!i.notifications)return;return i.notifications.onNotification((e=>{r(e)}),t)}),[i.notifications,t]),o};function P(e,t,i,o){return new(i||(i=Promise))((function(r,n){function s(e){try{c(o.next(e))}catch(e){n(e)}}function a(e){try{c(o.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(s,a)}c((o=o.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const E=(e,t)=>d.e("react-sdk",t,e);function k(t){const i=e.useRef();return e.useEffect((()=>{i.current=t})),i.current}const M=["blink"].some((e=>{var t,o;return(null===(o=null===(t=i.parsedUserAgent.getEngine())||void 0===t?void 0:t.name)||void 0===o?void 0:o.toLowerCase())===e})),R=(t=E)=>{var o,r;const n=y(),s=g(i.selectIsLocalScreenShared),a=g(i.selectPeerScreenSharing),c=g(i.selectScreenSharesByPeerId(null==a?void 0:a.id)),l=e.useCallback((e=>P(void 0,void 0,void 0,(function*(){try{yield n.setScreenShareEnabled(!s,e)}catch(e){t(e,"toggleScreenShare")}}))),[n,s,t]);return{amIScreenSharing:s,screenSharingPeerId:null==a?void 0:a.id,screenSharingPeerName:null==a?void 0:a.name,screenShareVideoTrackId:null===(o=null==c?void 0:c.video)||void 0===o?void 0:o.id,screenShareAudioTrackId:null===(r=null==c?void 0:c.audio)||void 0===r?void 0:r.id,toggleScreenShare:l}},C=(e,t,i)=>P(void 0,void 0,void 0,(function*(){if(t)try{yield e.setRemoteTrackEnabled(t.id,!t.enabled)}catch(e){i(e,"remoteToggle")}})),I=({elements:e,tilesInFirstPage:t,onlyOnePage:i,isLastPageDifferentFromFirstPage:o,defaultWidth:r,defaultHeight:n,lastPageWidth:s,lastPageHeight:a})=>{const c=((e,t,i)=>e.reduce(((e,o,r)=>{const n=Math.floor(r/t);return n>0&&i||(e[n]||(e[n]=[]),e[n].push(o)),e}),[]))(e,t,i);return c.map(((e,t)=>e.map((e=>{const i=t===c.length-1,l=o&&i?s:r,u=o&&i?a:n;return Object.assign(Object.assign({},e),{height:u,width:l})}))))};const N=(e,t,i,o,r)=>{if(e<0||t<0)throw new Error("Container must have a non-negative area");if(i<1||!Number.isInteger(i))throw new Error("Number of shapes to place must be a positive integer");const n=o&&r&&o/r;if(void 0!==n&&isNaN(n))throw new Error("Aspect ratio must be a number");let s={area:0,cols:0,rows:0,width:0,height:0};if(void 0!==n)for(let o=i;o>0;o+=-1){const r=Math.ceil(i/o);let a,c;e/(o*n)<=t/r?(a=e/o,c=a/n):(c=t/r,a=c*n);const l=a*c;l>s.area&&(s={area:l,width:a,height:c,rows:r,cols:o})}return s};function x({count:e,parentWidth:t,parentHeight:i,maxTileCount:o,maxRowCount:r,maxColCount:n,aspectRatio:s}){let a=0,c=0,l=0,u=0,d=!1,h=0;if(0===e)return{tilesInFirstPage:h,defaultWidth:a,defaultHeight:c,lastPageWidth:l,lastPageHeight:u,isLastPageDifferentFromFirstPage:d};if(o)({tilesInFirstPage:h,defaultWidth:a,defaultHeight:c,lastPageWidth:l,lastPageHeight:u,isLastPageDifferentFromFirstPage:d}=(({parentWidth:e,parentHeight:t,count:i,maxCount:o,aspectRatio:r})=>{let n=0,s=0,a=0,c=0,l=!1,u=0,d=0;const{width:h,height:f}=N(e,t,Math.min(i,o),r.width,r.height);if(n=h,s=f,u=Math.min(i,o),d=i%o,l=d>0&&i>o,l){const{width:i,height:o}=N(e,t,d,r.width,r.height);a=i,c=o}return{tilesInFirstPage:u,defaultWidth:n,defaultHeight:s,lastPageWidth:a,lastPageHeight:c,isLastPageDifferentFromFirstPage:l}})({parentWidth:t,parentHeight:i,count:e,maxCount:o,aspectRatio:s}));else if(r)({tilesInFirstPage:h,defaultWidth:a,defaultHeight:c,lastPageWidth:l,lastPageHeight:u,isLastPageDifferentFromFirstPage:d}=(({parentWidth:e,parentHeight:t,count:i,maxCount:o,aspectRatio:r})=>{let n=0,s=0,a=0,c=0,l=!1,u=0,d=0;const h=Math.min(Math.ceil(Math.sqrt(i*(r.width/r.height)/(e/t))),o),f=t/h,v=f*(r.width/r.height),g=Math.floor(e/v);if(n=v,s=f,u=Math.min(i,h*g),d=i%(h*g),l=d>0&&i>h*g,l){const i=t/Math.min(Math.ceil(Math.sqrt(d*(r.width/r.height)/(e/t))),o);c=i,a=i*(r.width/r.height)}return{tilesInFirstPage:u,defaultWidth:n,defaultHeight:s,lastPageWidth:a,lastPageHeight:c,isLastPageDifferentFromFirstPage:l}})({parentWidth:t,parentHeight:i,count:e,maxCount:r,aspectRatio:s}));else if(n)({tilesInFirstPage:h,defaultWidth:a,defaultHeight:c,lastPageWidth:l,lastPageHeight:u,isLastPageDifferentFromFirstPage:d}=(({parentWidth:e,parentHeight:t,count:i,maxCount:o,aspectRatio:r})=>{let n=0,s=0,a=0,c=0,l=!1,u=0,d=0;const h=Math.min(Math.ceil(Math.sqrt(i*(e/t)/(r.width/r.height))),o);let f=e/h,v=f/(r.width/r.height);v>t&&(v=t,f=v/(r.height/r.width));const g=Math.floor(t/v);if(s=v,n=f,u=Math.min(i,g*h),d=i%(g*h),l=d>0&&i>g*h,l){let i=e/Math.min(Math.ceil(Math.sqrt(d*(e/t)/(r.width/r.height))),o),n=i/(r.width/r.height);n>t&&(n=t,i=n/(r.height/r.width)),c=n,a=i}return{tilesInFirstPage:u,defaultWidth:n,defaultHeight:s,lastPageWidth:a,lastPageHeight:c,isLastPageDifferentFromFirstPage:l}})({parentWidth:t,parentHeight:i,count:e,maxCount:n,aspectRatio:s}));else{const{width:o,height:r}=N(t,i,e,s.width,s.height);a=o,c=r,h=e}return{tilesInFirstPage:h,defaultWidth:a,defaultHeight:c,lastPageWidth:l,lastPageHeight:u,isLastPageDifferentFromFirstPage:d}}const T=(e,t,i,o=!0)=>{if(!e||!t||!i)return[];const r=[];for(const n of e){if(void 0===n.videoTrack&&n.audioTrack&&t[n.audioTrack]?r.push({peer:n}):n.videoTrack&&t[n.videoTrack]?r.push({track:t[n.videoTrack],peer:n}):o||r.push({peer:n}),n.auxiliaryTracks.length>0&&n.auxiliaryTracks.forEach((e=>{const i=t[e];"video"===(null==i?void 0:i.type)&&"regular"===(null==i?void 0:i.source)&&r.push({track:i,peer:n})})),i(n)&&n.auxiliaryTracks.length>0){const e=n.auxiliaryTracks.find((e=>{const i=t[e];return"video"===(null==i?void 0:i.type)&&"screen"===(null==i?void 0:i.source)}));e&&r.push({track:t[e],peer:n})}}return r},H={width:1,height:1};const O=e=>e.reduce(((e,t)=>(e[t.id]=t,e)),{});exports.HMSRoomProvider=({children:t,actions:o,store:r,notifications:n,stats:s,isHMSStatsOn:l=!1,leaveOnUnload:u=!0})=>{const d=e.useMemo((()=>{let e;const t=()=>{throw new Error("modifying store is not allowed")};if(o&&r)e={actions:o,store:c.default(Object.assign(Object.assign({},r),{setState:t,destroy:t}))},n&&(e.notifications=n),s&&(e.statsStore=c.default({getState:s.getState,subscribe:s.subscribe,setState:t,destroy:t}));else{const o=new i.HMSReactiveStore;if(e={actions:o.getActions(),store:c.default(Object.assign(Object.assign({},o.getStore()),{setState:t,destroy:t})),notifications:o.getNotifications()},l){const i=o.getStats();e.statsStore=c.default({getState:i.getState,subscribe:i.subscribe,setState:t,destroy:t})}}return e.actions.setFrameworkInfo({type:"react-web",version:a.default.version,sdkVersion:"0.11.2-alpha.6"}),e}),[o,r,n,s,l]);return e.useEffect((()=>{if(f&&u){const e=()=>d.actions.leave();return window.addEventListener("unload",e),()=>{window.removeEventListener("unload",e)}}return()=>{}}),[u,d]),a.default.createElement(v.Provider,{value:d},t)},exports.getPeersWithTiles=T,exports.throwErrorHandler=e=>{throw e},exports.useAVToggle=(t=E)=>{const o=g(i.selectIsLocalAudioEnabled),r=g(i.selectIsLocalVideoEnabled),n=g(i.selectIsInPreview)?i.selectIsAllowedToPreviewMedia:i.selectIsAllowedToPublish,s=g(n),a=y(),c=e.useCallback((()=>P(void 0,void 0,void 0,(function*(){try{yield a.setLocalAudioEnabled(!o)}catch(e){t(e,"toggleAudio")}}))),[a,o,t]),l=e.useCallback((()=>P(void 0,void 0,void 0,(function*(){try{yield a.setLocalVideoEnabled(!r)}catch(e){t(e,"toggleVideo")}}))),[a,r,t]);return{isLocalAudioEnabled:o,isLocalVideoEnabled:r,toggleAudio:(null==s?void 0:s.audio)?c:void 0,toggleVideo:(null==s?void 0:s.video)?l:void 0}},exports.useAudioLevelStyles=function({trackId:t,getStyle:o,ref:r}){const n=w();e.useEffect((()=>n.subscribe((e=>{if(!r.current)return;const t=o(e);for(const e in t)r.current.style[e]=t[e]}),i.selectTrackAudioByID(t))),[o,r,n,t])},exports.useAudioMode=()=>{const e=y(),{audioMode:t}=g(i.selectLocalMediaSettings),o=t===i.HMSAudioMode.MUSIC;return{toggleMusicMode:()=>P(void 0,void 0,void 0,(function*(){return yield e.setAudioSettings({audioMode:o?i.HMSAudioMode.VOICE:i.HMSAudioMode.MUSIC})})),isMusicModeEnabled:o}},exports.useAutoplayError=()=>{const t=b(i.HMSNotificationTypes.ERROR),[o,r]=e.useState(""),n=y(),s=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)&&r(null==t?void 0:t.data.message)}),[t]),{error:o,unblockAudio:s,resetError:()=>r("")}},exports.useAwayNotifications=()=>{const t=w();return{requestPermission:e.useCallback((()=>P(void 0,void 0,void 0,(function*(){if(!("Notification"in window)||navigator.webdriver)return void console.debug("Request Permsissions : Notifications not supported or headless browser");if("granted"===(null===Notification||void 0===Notification?void 0:Notification.permission)||"denied"===(null===Notification||void 0===Notification?void 0:Notification.permission))return;const e=t.subscribe((t=>P(void 0,void 0,void 0,(function*(){t&&"__internal_recorder"!==t&&(yield Notification.requestPermission(),null==e||e())}))),i.selectLocalPeerRoleName)}))),[t]),showNotification:e.useCallback(((e,t)=>{if(!("Notification"in window))return void console.debug("Show Notifications: Notifications not supported or headless browser");if("denied"===(null===Notification||void 0===Notification?void 0:Notification.permission)||"visible"===document.visibilityState&&document.hasFocus())return;const i=new Notification(e,t),o=()=>{"visible"===document.visibilityState&&document.hasFocus()&&(null==i||i.close(),document.removeEventListener("visibilitychange",o))};document.addEventListener("visibilitychange",o)}),[])}},exports.useCustomEvent=({type:t,json:o=!0,onEvent:r,handleError:n=E})=>{const s=y(),a=S();e.useEffect((()=>{s.ignoreMessageTypes([t])}),[s,t]),e.useEffect((()=>{if(!a)return;return a.onNotification((e=>{const i=e.data;if(i&&i.type===t)try{const e=o?JSON.parse(i.message):i.message;null==r||r(e)}catch(e){n(e,"handleCustomEvent")}}),i.HMSNotificationTypes.NEW_MESSAGE)}),[a,t,o,r,n]);return{sendEvent:e.useCallback(((e,i)=>P(void 0,void 0,void 0,(function*(){try{const n=((e,t)=>t?JSON.stringify(e||""):e)(e,o);i&&Array.isArray(null==i?void 0:i.roleNames)?yield s.sendGroupMessage(n,i.roleNames,t):"string"==typeof(null==i?void 0:i.peerId)?yield s.sendDirectMessage(n,i.peerId,t):yield s.sendBroadcastMessage(n,t),null==r||r(e)}catch(e){n(e,"sendCustomEvent")}}))),[s,n,r,t,o])}},exports.useDevices=(t=E)=>{const o=y(),r=g(i.selectDevices),n=g(i.selectLocalMediaSettings),s=g(i.selectIsInPreview)?i.selectIsAllowedToPreviewMedia:i.selectIsAllowedToPublish,a=g(s),c={[i.DeviceType.audioOutput]:n.audioOutputDeviceId},l={[i.DeviceType.audioOutput]:r.audioOutput};a.video&&(l[i.DeviceType.videoInput]=r.videoInput,c[i.DeviceType.videoInput]=n.videoInputDeviceId),a.audio&&(l[i.DeviceType.audioInput]=r.audioInput,c[i.DeviceType.audioInput]=n.audioInputDeviceId);return{allDevices:l,selectedDeviceIDs:c,updateDevice:e.useCallback((e=>P(void 0,[e],void 0,(function*({deviceType:e,deviceId:r}){try{switch(e){case i.DeviceType.audioInput:yield o.setAudioSettings({deviceId:r});break;case i.DeviceType.videoInput:yield o.setVideoSettings({deviceId:r});break;case i.DeviceType.audioOutput:yield o.setAudioOutputDevice(r)}}catch(e){t(e,"updateDevices")}}))),[t,o])}},exports.useEmbedShare=t=>{const i=e.useRef(null),[o,r]=e.useState(!1),n=e.useCallback((()=>{throw new Error("unable to start screen share")}),[]),s=e.useRef(!1),{amIScreenSharing:a,toggleScreenShare:c}=R(n),l=k(a),u=e.useCallback((()=>P(void 0,void 0,void 0,(function*(){a&&(yield null==c?void 0:c(),i.current=null)}))),[a,c]),d=e.useCallback((e=>P(void 0,void 0,void 0,(function*(){if(!s.current){if(!e)throw new Error("URL not found");if(a)throw new Error("You are already sharing");if(!i.current)throw new Error("Attach a reference `iframeRef` to iframe for sharing");i.current.src=e,s.current=!0,r(!0),yield null==c?void 0:c({forceCurrentTab:M,cropElement:i.current,preferCurrentTab:M})}}))),[a,c]);return e.useEffect((()=>{l&&!a&&(null==t||t(),i.current&&(i.current.src=""),s.current=!1,r(!1))}),[a,l,t]),{startEmbedShare:d,stopEmbedShare:u,iframeRef:i,isEmbedShareInProgress:o}},exports.useHMSActions=y,exports.useHMSNotifications=b,exports.useHMSStatsStore=m,exports.useHMSStore=g,exports.useHMSVanillaNotifications=S,exports.useHMSVanillaStore=w,exports.usePDFShare=t=>{const i=e.useRef(null),[o,r]=e.useState(!1),n=e.useCallback((()=>{throw new Error("unable to start screen share")}),[]),s=e.useRef(!1),{amIScreenSharing:a,toggleScreenShare:c}=R(n),l=k(a),u=e.useCallback((e=>{var t;i.current&&(null===(t=i.current.contentWindow)||void 0===t||t.postMessage({theme:2,file:e},"*"))}),[]),d=e.useCallback((()=>P(void 0,void 0,void 0,(function*(){a&&(yield null==c?void 0:c())}))),[a,c]),h=e.useCallback((e=>P(void 0,void 0,void 0,(function*(){if(s.current)return;if(!e)throw new Error("File or url not found");if(a)throw new Error("You are already sharing");if(!i.current)throw new Error("Attach a reference `iframeRef` to iframe for sharing");i.current.src="https://pdf-annotation.100ms.live/generic/web/viewer.html"+("string"==typeof e?`?file=${e}`:""),i.current.onload=()=>{requestAnimationFrame((()=>{e instanceof File&&u(e)}))},s.current=!0,r(!0);const t=window.self!==window.top;yield null==c?void 0:c({forceCurrentTab:M&&!t,cropElement:i.current,preferCurrentTab:M&&!t})}))),[a,u,c]);return e.useEffect((()=>{l&&!a&&(null==t||t(),i.current&&i.current.removeAttribute("src"),s.current=!1,r(!1))}),[a,l,t]),{startPDFShare:h,stopPDFShare:d,iframeRef:i,isPDFShareInProgress:o}},exports.usePaginatedParticipants=t=>{const i=y(),o=e.useRef(i.getPeerListIterator(t)),[r,n]=e.useState({}),[s,a]=e.useState(0);return{loadPeers:()=>o.current.findPeers().then((e=>{n(O(e)),a(o.current.getTotal())})),loadMorePeers:()=>o.current.next().then((e=>{n((t=>Object.assign(Object.assign({},t),O(e)))),a(o.current.getTotal())})),hasNext:()=>o.current.hasNext(),total:s,peers:Object.values(r)}},exports.useParticipantList=()=>{const t=g(i.selectIsConnectedToRoom),o=g(t?i.selectPeers:i.selectRemotePeers),r=g(i.selectPeerCount),n=e.useMemo((()=>{return(e=o)&&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}),[o]);return{roles:Object.keys(n),participantsByRoles:n,peerCount:r,isConnected:t}},exports.useParticipants=e=>{var t;const o=g(i.selectIsConnectedToRoom),r=g(i.selectPeerCount),n=g(i.selectAvailableRoleNames);let s=g(o?i.selectPeers:i.selectRemotePeers);const a=Array.from(new Set(s.map((e=>e.roleName)))),c=w();if((null===(t=null==e?void 0:e.metadata)||void 0===t?void 0:t.isHandRaised)&&(s=s.filter((e=>c.getState(i.selectPeerMetadata(e.id)).isHandRaised))),(null==e?void 0:e.role)&&n.includes(e.role)&&(s=s.filter((t=>t.roleName===e.role))),null==e?void 0:e.search){const t=e.search.toLowerCase();s=s.filter((e=>{var i;return(null===(i=e.roleName)||void 0===i?void 0:i.toLowerCase().includes(t))||e.name.toLowerCase().includes(t)}))}return{participants:s,isConnected:o,peerCount:r,rolesWithParticipants:a}},exports.usePreviewJoin=({name:t="",token:o,metadata:r,handleError:n=E,initEndpoint:s,initialSettings:a,captureNetworkQualityInPreview:c,asRole:l,autoManageVideo:u,autoManageWakeLock:d,iceServers:h})=>{const f=y(),v=g(i.selectRoomState),p=g(i.selectIsConnectedToRoom)||!1,m=v===i.HMSRoomState.Preview,w=e.useMemo((()=>({userName:t,authToken:o,metaData:r,rememberDeviceSelection:!0,settings:a,initEndpoint:s,asRole:l,captureNetworkQualityInPreview:c,autoManageVideo:u,autoManageWakeLock:d,iceServers:h})),[t,o,r,s,a,c,l,u,d,h]),S=e.useCallback((()=>P(void 0,void 0,void 0,(function*(){if(o)try{(p||v!==i.HMSRoomState.Disconnected)&&(yield f.leave().catch((()=>{}))),yield f.preview(w)}catch(e){n(e,"preview")}}))),[o,p,v,f,w,n]);return{enableJoin:m,join:e.useCallback((()=>P(void 0,void 0,void 0,(function*(){if(o)try{yield f.join(w)}catch(e){n(e,"join")}}))),[f,w,n,o]),isConnected:p,preview:S}},exports.useRecordingStreaming=()=>{const e=g(i.selectRecordingState),t=g(i.selectRTMPState),o=g(i.selectHLSState),r=e.server.running,n=e.browser.running,s=e.hls.running,a=r||n||s;return{isServerRecordingOn:r,isBrowserRecordingOn:n,isHLSRecordingOn:s,isStreamingOn:o.running||t.running,isHLSRunning:o.running,isRTMPRunning:t.running,isRecordingOn:a}},exports.useRemoteAVToggle=(t,o,r=E)=>{const n=y(),s=g(i.selectAudioTrackByID(t)),a=g(i.selectVideoTrackByID(o)),c=g(i.selectAudioTrackVolume(null==s?void 0:s.id)),l=g(i.selectPermissions),u=(null==a?void 0:a.enabled)?null==l?void 0:l.mute:null==l?void 0:l.unmute,d=(null==s?void 0:s.enabled)?null==l?void 0:l.mute:null==l?void 0:l.unmute,h=e.useCallback((()=>P(void 0,void 0,void 0,(function*(){yield C(n,s,r)}))),[n,s,r]),f=e.useCallback((()=>P(void 0,void 0,void 0,(function*(){yield C(n,a,r)}))),[n,r,a]),v=e.useCallback((e=>{s&&n.setVolume(e,s.id)}),[n,s]);return{isAudioEnabled:!!(null==s?void 0:s.enabled),isVideoEnabled:!!(null==a?void 0:a.enabled),volume:c,toggleAudio:s&&d?h:void 0,toggleVideo:"regular"===(null==a?void 0:a.source)&&u?f:void 0,setVolume:s?v:void 0}},exports.useScreenShare=R,exports.useTranscript=({onTranscript:t,handleError:o=E})=>{const r="hms_transcript",n=S();e.useEffect((()=>{if(!n)return;return n.onNotification((e=>{const i=e.data;if(i&&i.type===r)try{const e=JSON.parse(i.message).results;null==t||t(e)}catch(e){o(e,"handleCaptionEvent")}}),i.HMSNotificationTypes.NEW_MESSAGE)}),[n,r,o,t])},exports.useVideo=({trackId:t,attach:o})=>{const r=y(),n=e.useRef(null),s=g(i.selectVideoTrackByID(t)),a=e.useRef(),c=e.useCallback((e=>{e&&(n.current=e)}),[]);return e.useEffect((()=>{a.current?(null==s?void 0:s.id)&&a.current!==(null==s?void 0:s.id)&&P(void 0,void 0,void 0,(function*(){if(n.current)try{d.d("detaching because different track is passed"),yield r.detachVideo(a.current,n.current)}catch(e){d.w("detach video error for track",a.current,e)}a.current=null==s?void 0:s.id})):a.current=null==s?void 0:s.id}),[null==s?void 0:s.id,r]),e.useEffect((()=>{P(void 0,void 0,void 0,(function*(){(null==s?void 0:s.id)&&n.current&&(!1!==o?yield r.attachVideo(s.id,n.current):yield r.detachVideo(s.id,n.current))}))}),[s,o,r]),e.useEffect((()=>()=>{P(void 0,void 0,void 0,(function*(){if(n.current&&s)try{yield r.detachVideo(s.id,n.current)}catch(e){d.w("detach video error for track",s.id,e)}}))}),[]),{videoRef:c}},exports.useVideoList=({peers:t,maxTileCount:r,maxColCount:n,maxRowCount:s,includeScreenShareForPeer:a=(()=>!1),aspectRatio:c=H,filterNonPublishingPeers:l=!0,offsetY:u=0})=>{const{width:d=0,height:h=0,ref:f}=o.useResizeDetector(),v=w().getState(i.selectTracksMap),g=T(t,v,a,l),p=e.useMemo((()=>{if(c)return c;return{width:function(e){if(0===e.length)return null;const t={};let i=e[0],o=1;for(let r=0;r<e.length;r++){const n=e[r];null===t[n]?t[n]=1:t[n]++,t[n]>o&&(i=n,o=t[n])}return i}(g.filter((e=>{var t,i;return(null===(t=e.track)||void 0===t?void 0:t.width)&&(null===(i=e.track)||void 0===i?void 0:i.height)})).map((e=>{var t,i;return((null===(t=e.track)||void 0===t?void 0:t.width)||1)/((null===(i=e.track)||void 0===i?void 0:i.height)||1)})))||1,height:1}}),[c,g]),m=g.length,{tilesInFirstPage:S,defaultWidth:y,defaultHeight:b,lastPageWidth:P,lastPageHeight:E,isLastPageDifferentFromFirstPage:k}=e.useMemo((()=>x({count:m,parentWidth:Math.floor(d),parentHeight:Math.floor(h)-Math.min(h,u),maxTileCount:r,maxRowCount:s,maxColCount:n,aspectRatio:p})),[m,d,h,r,s,n,p,u]);return{pagesWithTiles:e.useMemo((()=>I({elements:g,tilesInFirstPage:S,onlyOnePage:!1,isLastPageDifferentFromFirstPage:k,defaultWidth:y,defaultHeight:b,lastPageWidth:P,lastPageHeight:E})),[g,S,k,y,b,P,E]),ref:f}},exports.useWhiteboard=(t=!1)=>{var o,r;const n=g(i.selectIsConnectedToRoom),s=null===(o=g(i.selectLocalPeer))||void 0===o?void 0:o.customerUserId,a=g(i.selectWhiteboard),c=g(i.selectAppData("disableNotifications")),l=!!(null==a?void 0:a.open),u=(null==a?void 0:a.owner)===s,d=y(),[h,f]=e.useState(!1),v=null===(r=g(i.selectPermissions))||void 0===r?void 0:r.whiteboard,p=!!(null==v?void 0:v.includes("admin"));e.useEffect((()=>{n&&f(d.interactivityCenter.whiteboard.isEnabled)}),[n,d]);const m=e.useCallback((()=>P(void 0,void 0,void 0,(function*(){n&&p&&(l?u&&(yield d.interactivityCenter.whiteboard.close()):yield d.interactivityCenter.whiteboard.open())}))),[d,u,p,l,n]);return{open:l,token:null==a?void 0:a.token,endpoint:null==a?void 0:a.addr,isOwner:u,isAdmin:p,zoomToContent:c||t,toggle:h&&p?m:void 0}},Object.keys(i).forEach((function(e){"default"===e||exports.hasOwnProperty(e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return i[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.11.2-alpha.5"}),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.11.2-alpha.6"}),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.11.2-alpha.5",
7
+ "version": "0.11.2-alpha.6",
8
8
  "author": "100ms",
9
9
  "license": "MIT",
10
10
  "repository": {
@@ -48,9 +48,9 @@
48
48
  "react": ">=16.8 <19.0.0"
49
49
  },
50
50
  "dependencies": {
51
- "@100mslive/hms-video-store": "0.13.2-alpha.5",
51
+ "@100mslive/hms-video-store": "0.13.2-alpha.6",
52
52
  "react-resize-detector": "^7.0.0",
53
53
  "zustand": "^3.6.2"
54
54
  },
55
- "gitHead": "077201f60b82e89785c3147532fceff458d888f2"
55
+ "gitHead": "b68f0630c63c6de29580cc131feed91934825cfb"
56
56
  }