@100mslive/react-sdk 0.6.4-alpha.1 → 0.6.4-alpha.3

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-intersection-observer"),n=require("react-resize-detector");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a,s,l=r(e),d=r(t);function u(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=a||(a={}))[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 c{static v(e,...t){this.log(a.VERBOSE,e,...t)}static d(e,...t){this.log(a.DEBUG,e,...t)}static i(e,...t){this.log(a.INFO,e,...t)}static w(e,...t){this.log(a.WARN,e,...t)}static e(e,...t){this.log(a.ERROR,e,...t)}static log(e,t,...i){if(!(this.level.valueOf()>e.valueOf()))switch(e){case a.VERBOSE:console.log("HMSui-components: ",t,...i);break;case a.DEBUG:console.debug("HMSui-components: ",t,...i);break;case a.INFO:console.info("HMSui-components: ",t,...i);break;case a.WARN:console.warn("HMSui-components: ",t,...i);break;case a.ERROR:console.error("HMSui-components: ",t,...i)}}}c.level=a.VERBOSE;const h="It seems like you forgot to add your component within a top level HMSRoomProvider, please refer to 100ms react docs(https://docs.100ms.live/javascript/v2/features/integration#react-hooks) to check on the required steps for using this hook.";const g="undefined"!=typeof window,v=e.createContext(null),f=(p=v,(t,i=u)=>{t||c.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=u)=>{i||c.w("fetching full store without passing any selector may have a heavy performance impact on your website.");const n=e.useContext(t);if(!n)throw new Error(h);const r=n.statsStore;return null==r?void 0:r(i,o)}}(v),y=()=>{const t=e.useContext(v);if(!t)throw new Error(h);return t.store},w=()=>{const t=e.useContext(v);if(!t)throw new Error(h);return t.notifications},b=()=>{const t=e.useContext(v);if(!t)throw new Error(h);return t.actions},S=t=>{const i=e.useContext(v),[o,n]=e.useState(null);if(!i)throw new Error(h);return e.useEffect((()=>{if(!i.notifications)return;return i.notifications.onNotification((e=>{n(e)}),t)}),[i.notifications,t]),o};function P(e,t,i,o){return new(i||(i=Promise))((function(n,r){function a(e){try{l(o.next(e))}catch(e){r(e)}}function s(e){try{l(o.throw(e))}catch(e){r(e)}}function l(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,s)}l((o=o.apply(e,t||[])).next())}))}const E=(e,t)=>c.e("react-sdk",t,e),R=({elements:e,tilesInFirstPage:t,onlyOnePage:i,isLastPageDifferentFromFirstPage:o,defaultWidth:n,defaultHeight:r,lastPageWidth:a,lastPageHeight:s})=>{const l=((e,t,i)=>e.reduce(((e,o,n)=>{const r=Math.floor(n/t);return r>0&&i||(e[r]||(e[r]=[]),e[r].push(o)),e}),[]))(e,t,i);return l.map(((e,t)=>e.map((e=>{const i=t===l.length-1,d=o&&i?a:n,u=o&&i?s:r;return Object.assign(Object.assign({},e),{height:u,width:d})}))))};const k=(e,t,i,o,n)=>{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 r=o&&n&&o/n;if(void 0!==r&&isNaN(r))throw new Error("Aspect ratio must be a number");let a={area:0,cols:0,rows:0,width:0,height:0};if(void 0!==r)for(let o=i;o>0;o+=-1){const n=Math.ceil(i/o);let s,l;e/(o*r)<=t/n?(s=e/o,l=s/r):(l=t/n,s=l*r);const d=s*l;d>a.area&&(a={area:d,width:s,height:l,rows:n,cols:o})}return a};function M({count:e,parentWidth:t,parentHeight:i,maxTileCount:o,maxRowCount:n,maxColCount:r,aspectRatio:a}){let s=0,l=0,d=0,u=0,c=!1,h=0;if(0===e)return{tilesInFirstPage:h,defaultWidth:s,defaultHeight:l,lastPageWidth:d,lastPageHeight:u,isLastPageDifferentFromFirstPage:c};if(o)({tilesInFirstPage:h,defaultWidth:s,defaultHeight:l,lastPageWidth:d,lastPageHeight:u,isLastPageDifferentFromFirstPage:c}=(({parentWidth:e,parentHeight:t,count:i,maxCount:o,aspectRatio:n})=>{let r=0,a=0,s=0,l=0,d=!1,u=0,c=0;const{width:h,height:g}=k(e,t,Math.min(i,o),n.width,n.height);if(r=h,a=g,u=Math.min(i,o),c=i%o,d=c>0&&i>o,d){const{width:i,height:o}=k(e,t,c,n.width,n.height);s=i,l=o}return{tilesInFirstPage:u,defaultWidth:r,defaultHeight:a,lastPageWidth:s,lastPageHeight:l,isLastPageDifferentFromFirstPage:d}})({parentWidth:t,parentHeight:i,count:e,maxCount:o,aspectRatio:a}));else if(n)({tilesInFirstPage:h,defaultWidth:s,defaultHeight:l,lastPageWidth:d,lastPageHeight:u,isLastPageDifferentFromFirstPage:c}=(({parentWidth:e,parentHeight:t,count:i,maxCount:o,aspectRatio:n})=>{let r=0,a=0,s=0,l=0,d=!1,u=0,c=0;const h=Math.min(Math.ceil(Math.sqrt(i*(n.width/n.height)/(e/t))),o),g=t/h,v=g*(n.width/n.height),f=Math.floor(e/v);if(r=v,a=g,u=Math.min(i,h*f),c=i%(h*f),d=c>0&&i>h*f,d){const i=t/Math.min(Math.ceil(Math.sqrt(c*(n.width/n.height)/(e/t))),o);l=i,s=i*(n.width/n.height)}return{tilesInFirstPage:u,defaultWidth:r,defaultHeight:a,lastPageWidth:s,lastPageHeight:l,isLastPageDifferentFromFirstPage:d}})({parentWidth:t,parentHeight:i,count:e,maxCount:n,aspectRatio:a}));else if(r)({tilesInFirstPage:h,defaultWidth:s,defaultHeight:l,lastPageWidth:d,lastPageHeight:u,isLastPageDifferentFromFirstPage:c}=(({parentWidth:e,parentHeight:t,count:i,maxCount:o,aspectRatio:n})=>{let r=0,a=0,s=0,l=0,d=!1,u=0,c=0;const h=Math.min(Math.ceil(Math.sqrt(i*(e/t)/(n.width/n.height))),o);let g=e/h,v=g/(n.width/n.height);v>t&&(v=t,g=v/(n.height/n.width));const f=Math.floor(t/v);if(a=v,r=g,u=Math.min(i,f*h),c=i%(f*h),d=c>0&&i>f*h,d){let i=e/Math.min(Math.ceil(Math.sqrt(c*(e/t)/(n.width/n.height))),o),r=i/(n.width/n.height);r>t&&(r=t,i=r/(n.height/n.width)),l=r,s=i}return{tilesInFirstPage:u,defaultWidth:r,defaultHeight:a,lastPageWidth:s,lastPageHeight:l,isLastPageDifferentFromFirstPage:d}})({parentWidth:t,parentHeight:i,count:e,maxCount:r,aspectRatio:a}));else{const{width:o,height:n}=k(t,i,e,a.width,a.height);s=o,l=n,h=e}return{tilesInFirstPage:h,defaultWidth:s,defaultHeight:l,lastPageWidth:d,lastPageHeight:u,isLastPageDifferentFromFirstPage:c}}const I=(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")}})),C={width:1,height:1};exports.HMSRoomProvider=({children:t,actions:o,store:n,notifications:r,stats:a,isHMSStatsOn:s=!1,leaveOnUnload:u=!0})=>{const c=e.useMemo((()=>{let e;const t=()=>{throw new Error("modifying store is not allowed")};if(o&&n)e={actions:o,store:d.default(Object.assign(Object.assign({},n),{setState:t,destroy:t}))},r&&(e.notifications=r),a&&(e.statsStore=d.default({getState:a.getState,subscribe:a.subscribe,setState:t,destroy:t}));else{const o=new i.HMSReactiveStore;if(e={actions:o.getActions(),store:d.default(Object.assign(Object.assign({},o.getStore()),{setState:t,destroy:t})),notifications:o.getNotifications()},s){const i=o.getStats();e.statsStore=d.default({getState:i.getState,subscribe:i.subscribe,setState:t,destroy:t})}}return e.actions.setFrameworkInfo({type:"react-web",version:l.default.version,sdkVersion:"0.6.4-alpha.1"}),e}),[o,n,r,a,s]);return e.useEffect((()=>{if(g&&u){const e=()=>c.actions.leave();return window.addEventListener("beforeunload",e),()=>{window.removeEventListener("beforeunload",e)}}return()=>{}}),[u,c]),l.default.createElement(v.Provider,{value:c},t)},exports.throwErrorHandler=e=>{throw e},exports.useAVToggle=(t=E)=>{const o=f(i.selectIsLocalAudioEnabled),n=f(i.selectIsLocalVideoEnabled),r=f(i.selectIsAllowedToPublish),a=b(),s=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(!n)}catch(e){t(e,"toggleVideo")}}))),[a,n,t]);return{isLocalAudioEnabled:o,isLocalVideoEnabled:n,toggleAudio:(null==r?void 0:r.audio)?s:void 0,toggleVideo:(null==r?void 0:r.video)?l:void 0}},exports.useAudioLevelStyles=function({trackId:t,getStyle:o,ref:n}){const r=y();e.useEffect((()=>r.subscribe((e=>{if(!n.current)return;const t=o(e);for(const e in t)n.current.style[e]=t[e]}),i.selectTrackAudioByID(t))),[o,n,r,t])},exports.useAutoplayError=()=>{const t=S(i.HMSNotificationTypes.ERROR),[o,n]=e.useState(""),r=b(),a=e.useCallback((()=>P(void 0,void 0,void 0,(function*(){yield r.unblockAudio()}))),[r]);return e.useEffect((()=>{3008===(null==t?void 0:t.data.code)&&n(null==t?void 0:t.data.message)}),[t]),{error:o,unblockAudio:a,resetError:()=>n("")}},exports.useCustomEvent=({type:t,json:o=!0,onEvent:n,handleError:r=E})=>{const a=b(),s=w();e.useEffect((()=>{a.ignoreMessageTypes([t])}),[a,t]),e.useEffect((()=>{if(!s)return;return s.onNotification((e=>{const i=e.data;if(i&&i.type===t)try{const e=o?JSON.parse(i.message):i.message;null==n||n(e)}catch(e){r(e,"handleCustomEvent")}}),i.HMSNotificationTypes.NEW_MESSAGE)}),[s,t,o,n,r]);return{sendEvent:e.useCallback(((e,i)=>P(void 0,void 0,void 0,(function*(){try{const r=((e,t)=>t?JSON.stringify(e||""):e)(e,o);i&&Array.isArray(null==i?void 0:i.roleNames)?yield a.sendGroupMessage(r,i.roleNames,t):"string"==typeof(null==i?void 0:i.peerId)?yield a.sendDirectMessage(r,i.peerId,t):yield a.sendBroadcastMessage(r,t),null==n||n(e)}catch(e){r(e,"sendCustomEvent")}}))),[a,r,n,t,o])}},exports.useDevices=(t=E)=>{const o=b(),n=f(i.selectDevices),r=f(i.selectLocalMediaSettings),a=f(i.selectIsAllowedToPublish),s={[i.DeviceType.audioOutput]:r.audioOutputDeviceId},l={[i.DeviceType.audioOutput]:n.audioOutput};a.video&&(l[i.DeviceType.videoInput]=n.videoInput,s[i.DeviceType.videoInput]=r.videoInputDeviceId),a.audio&&(l[i.DeviceType.audioInput]=n.audioInput,s[i.DeviceType.audioInput]=r.audioInputDeviceId);return{allDevices:l,selectedDeviceIDs:s,updateDevice:e.useCallback((({deviceType:e,deviceId:n})=>P(void 0,void 0,void 0,(function*(){try{switch(e){case i.DeviceType.audioInput:yield o.setAudioSettings({deviceId:n});break;case i.DeviceType.videoInput:yield o.setVideoSettings({deviceId:n});break;case i.DeviceType.audioOutput:yield o.setAudioOutputDevice(n)}}catch(e){t(e,"updateDevices")}}))),[t,o])}},exports.useHMSActions=b,exports.useHMSNotifications=S,exports.useHMSStatsStore=m,exports.useHMSStore=f,exports.useHMSVanillaNotifications=w,exports.useHMSVanillaStore=y,exports.useParticipantList=()=>{const t=f(i.selectIsConnectedToRoom),o=f(t?i.selectPeers:i.selectRemotePeers),n=f(i.selectPeerCount),r=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(r),participantsByRoles:r,peerCount:n,isConnected:t}},exports.useParticipants=e=>{var t;const o=f(i.selectIsConnectedToRoom),n=f(i.selectPeerCount),r=f(i.selectAvailableRoleNames);let a=f(o?i.selectPeers:i.selectRemotePeers);const s=Array.from(new Set(a.map((e=>e.roleName)))),l=y();if((null===(t=null==e?void 0:e.metadata)||void 0===t?void 0:t.isHandRaised)&&(a=a.filter((e=>l.getState(i.selectPeerMetadata(e.id)).isHandRaised))),(null==e?void 0:e.role)&&r.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 i;return(null===(i=e.roleName)||void 0===i?void 0:i.toLowerCase().includes(t))||e.name.toLowerCase().includes(t)}))}return{participants:a,isConnected:o,peerCount:n,rolesWithParticipants:s}},exports.usePreviewJoin=({name:t="",token:o,metadata:n,handleError:r=E,initEndpoint:a,initialSettings:s,captureNetworkQualityInPreview:l,asRole:d})=>{const u=b(),c=f(i.selectRoomState),h=f(i.selectIsConnectedToRoom)||!1,g=c===i.HMSRoomState.Preview,v=e.useMemo((()=>({userName:t,authToken:o,metaData:n,rememberDeviceSelection:!0,settings:s,initEndpoint:a,asRole:d,captureNetworkQualityInPreview:l})),[t,o,n,a,s,l,d]),p=e.useCallback((()=>P(void 0,void 0,void 0,(function*(){if(o&&c===i.HMSRoomState.Disconnected){h&&(yield u.leave());try{yield u.preview(v)}catch(e){r(e,"preview")}}}))),[u,r,o,c,v,h]);return{enableJoin:g,join:e.useCallback((()=>P(void 0,void 0,void 0,(function*(){if(o)try{yield u.join(v)}catch(e){r(e,"join")}}))),[u,v,r,o]),isConnected:h,preview:p}},exports.useRecordingStreaming=()=>{const e=f(i.selectRecordingState),t=f(i.selectRTMPState),o=f(i.selectHLSState),n=e.server.running,r=e.browser.running,a=e.hls.running,s=n||r||a;return{isServerRecordingOn:n,isBrowserRecordingOn:r,isHLSRecordingOn:a,isStreamingOn:o.running||t.running,isHLSRunning:o.running,isRTMPRunning:t.running,isRecordingOn:s}},exports.useRemoteAVToggle=(t,o,n=E)=>{const r=b(),a=f(i.selectAudioTrackByID(t)),s=f(i.selectVideoTrackByID(o)),l=f(i.selectAudioTrackVolume(null==a?void 0:a.id)),d=f(i.selectPermissions),u=(null==s?void 0:s.enabled)?null==d?void 0:d.mute:null==d?void 0:d.unmute,c=(null==a?void 0:a.enabled)?null==d?void 0:d.mute:null==d?void 0:d.unmute,h=e.useCallback((()=>P(void 0,void 0,void 0,(function*(){yield I(r,a,n)}))),[r,a,n]),g=e.useCallback((()=>P(void 0,void 0,void 0,(function*(){yield I(r,s,n)}))),[r,n,s]),v=e.useCallback((e=>{a&&r.setVolume(e,a.id)}),[r,a]);return{isAudioEnabled:!!(null==a?void 0:a.enabled),isVideoEnabled:!!(null==s?void 0:s.enabled),volume:l,toggleAudio:a&&c?h:void 0,toggleVideo:"regular"===(null==s?void 0:s.source)&&u?g:void 0,setVolume:a?v:void 0}},exports.useScreenShare=(t=E)=>{var o,n;const r=b(),a=f(i.selectIsLocalScreenShared),s=f(i.selectPeerScreenSharing),l=f(i.selectScreenSharesByPeerId(null==s?void 0:s.id)),d=e.useCallback((e=>P(void 0,void 0,void 0,(function*(){try{yield r.setScreenShareEnabled(!a,e)}catch(e){t(e,"toggleScreenShare")}}))),[r,a,t]);return{amIScreenSharing:a,screenSharingPeerId:null==s?void 0:s.id,screenSharingPeerName:null==s?void 0:s.name,screenShareVideoTrackId:null===(o=null==l?void 0:l.video)||void 0===o?void 0:o.id,screenShareAudioTrackId:null===(n=null==l?void 0:l.audio)||void 0===n?void 0:n.id,toggleScreenShare:d}},exports.useVideo=({trackId:t,attach:r,threshold:a=.5})=>{var s;const l=b(),d=e.useRef(null),u=f(i.selectVideoTrackByID(t)),{ref:h,inView:v}=o.useInView({threshold:a}),{width:p=0,height:m=0,ref:y}=n.useResizeDetector({refreshMode:"debounce",refreshRate:300}),w=e.useCallback((()=>P(void 0,void 0,void 0,(function*(){var e;if(p>0&&m>0&&v&&(null===(e=null==u?void 0:u.layerDefinitions)||void 0===e?void 0:e.length)&&y.current&&(null==u?void 0:u.enabled)&&!(null==u?void 0:u.degraded)){const e=(({layerDefinitions:e,width:t,height:i})=>{let o,n=Number.MAX_VALUE;for(const{resolution:r,layer:a}of e){const e=Math.abs(t-(r.width||0))+Math.abs(i-(r.height||0));e<n&&(n=e,o=a)}return o})({layerDefinitions:u.layerDefinitions,width:p,height:m});yield l.setPreferredLayer(null==u?void 0:u.id,e)}}))),[p,m,null==u?void 0:u.id,l,null==u?void 0:u.enabled,null==u?void 0:u.degraded,y,v]),S=e.useCallback((e=>{var t;e&&(d.current=e,h(e),(null===(t=null==u?void 0:u.layerDefinitions)||void 0===t?void 0:t.length)&&(y.current=e))}),[h,null===(s=null==u?void 0:u.layerDefinitions)||void 0===s?void 0:s.length,y]);return e.useEffect((()=>{w()}),[w]),e.useEffect((()=>{P(void 0,void 0,void 0,(function*(){if(d.current&&(null==u?void 0:u.id)){let e=!0;g&&(e="visible"===window.getComputedStyle(d.current).visibility),v&&u.enabled&&e&&!1!==r?yield l.attachVideo(u.id,d.current):yield l.detachVideo(u.id,d.current)}}))}),[l,v,d,null==u?void 0:u.id,null==u?void 0:u.enabled,null==u?void 0:u.deviceID,null==u?void 0:u.plugins,r]),e.useEffect((()=>()=>{P(void 0,void 0,void 0,(function*(){if(d.current&&u)try{yield l.detachVideo(u.id,d.current)}catch(e){c.w("detach video error for track",u.id,e)}}))}),[]),{videoRef:S}},exports.useVideoList=({peers:t,maxTileCount:o,maxColCount:r,maxRowCount:a,includeScreenShareForPeer:s=(()=>!1),aspectRatio:l=C,filterNonPublishingPeers:d=!0,offsetY:u=0})=>{const{width:c=0,height:h=0,ref:g}=n.useResizeDetector(),v=((e,t,i,o=!0)=>{if(!e||!t||!i)return[];const n=[];for(const r of e)if(void 0===r.videoTrack&&r.audioTrack&&t[r.audioTrack]?n.push({peer:r}):r.videoTrack&&t[r.videoTrack]?n.push({track:t[r.videoTrack],peer:r}):o||n.push({peer:r}),r.auxiliaryTracks.length>0&&r.auxiliaryTracks.forEach((e=>{const i=t[e];"video"===(null==i?void 0:i.type)&&"regular"===(null==i?void 0:i.source)&&n.push({track:i,peer:r})})),i(r)&&r.auxiliaryTracks.length>0){const e=r.auxiliaryTracks.find((e=>{const i=t[e];return"video"===(null==i?void 0:i.type)&&"screen"===(null==i?void 0:i.source)}));e&&n.push({track:t[e],peer:r})}return n})(t,y().getState(i.selectTracksMap),s,d),f=e.useMemo((()=>{if(l)return l;return{width:function(e){if(0===e.length)return null;const t={};let i=e[0],o=1;for(let n=0;n<e.length;n++){const r=e[n];null===t[r]?t[r]=1:t[r]++,t[r]>o&&(i=r,o=t[r])}return i}(v.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}}),[l,v]),p=v.length,{tilesInFirstPage:m,defaultWidth:w,defaultHeight:b,lastPageWidth:S,lastPageHeight:P,isLastPageDifferentFromFirstPage:E}=e.useMemo((()=>M({count:p,parentWidth:Math.floor(c),parentHeight:Math.floor(h)-Math.min(h,u),maxTileCount:o,maxRowCount:a,maxColCount:r,aspectRatio:f})),[p,c,h,o,a,r,f,u]);return{pagesWithTiles:e.useMemo((()=>R({elements:v,tilesInFirstPage:m,onlyOnePage:!1,isLastPageDifferentFromFirstPage:E,defaultWidth:w,defaultHeight:b,lastPageWidth:S,lastPageHeight:P})),[v,m,E,w,b,S,P]),ref:g}},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-intersection-observer"),n=require("react-resize-detector");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a,s,l=r(e),d=r(t);function u(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=a||(a={}))[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 c{static v(e,...t){this.log(a.VERBOSE,e,...t)}static d(e,...t){this.log(a.DEBUG,e,...t)}static i(e,...t){this.log(a.INFO,e,...t)}static w(e,...t){this.log(a.WARN,e,...t)}static e(e,...t){this.log(a.ERROR,e,...t)}static log(e,t,...i){if(!(this.level.valueOf()>e.valueOf()))switch(e){case a.VERBOSE:console.log("HMSui-components: ",t,...i);break;case a.DEBUG:console.debug("HMSui-components: ",t,...i);break;case a.INFO:console.info("HMSui-components: ",t,...i);break;case a.WARN:console.warn("HMSui-components: ",t,...i);break;case a.ERROR:console.error("HMSui-components: ",t,...i)}}}c.level=a.VERBOSE;const h="It seems like you forgot to add your component within a top level HMSRoomProvider, please refer to 100ms react docs(https://docs.100ms.live/javascript/v2/features/integration#react-hooks) to check on the required steps for using this hook.";const g="undefined"!=typeof window,v=e.createContext(null),f=(p=v,(t,i=u)=>{t||c.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=u)=>{i||c.w("fetching full store without passing any selector may have a heavy performance impact on your website.");const n=e.useContext(t);if(!n)throw new Error(h);const r=n.statsStore;return null==r?void 0:r(i,o)}}(v),y=()=>{const t=e.useContext(v);if(!t)throw new Error(h);return t.store},w=()=>{const t=e.useContext(v);if(!t)throw new Error(h);return t.notifications},b=()=>{const t=e.useContext(v);if(!t)throw new Error(h);return t.actions},S=t=>{const i=e.useContext(v),[o,n]=e.useState(null);if(!i)throw new Error(h);return e.useEffect((()=>{if(!i.notifications)return;return i.notifications.onNotification((e=>{n(e)}),t)}),[i.notifications,t]),o};function P(e,t,i,o){return new(i||(i=Promise))((function(n,r){function a(e){try{l(o.next(e))}catch(e){r(e)}}function s(e){try{l(o.throw(e))}catch(e){r(e)}}function l(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,s)}l((o=o.apply(e,t||[])).next())}))}const E=(e,t)=>c.e("react-sdk",t,e),R=({elements:e,tilesInFirstPage:t,onlyOnePage:i,isLastPageDifferentFromFirstPage:o,defaultWidth:n,defaultHeight:r,lastPageWidth:a,lastPageHeight:s})=>{const l=((e,t,i)=>e.reduce(((e,o,n)=>{const r=Math.floor(n/t);return r>0&&i||(e[r]||(e[r]=[]),e[r].push(o)),e}),[]))(e,t,i);return l.map(((e,t)=>e.map((e=>{const i=t===l.length-1,d=o&&i?a:n,u=o&&i?s:r;return Object.assign(Object.assign({},e),{height:u,width:d})}))))};const k=(e,t,i,o,n)=>{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 r=o&&n&&o/n;if(void 0!==r&&isNaN(r))throw new Error("Aspect ratio must be a number");let a={area:0,cols:0,rows:0,width:0,height:0};if(void 0!==r)for(let o=i;o>0;o+=-1){const n=Math.ceil(i/o);let s,l;e/(o*r)<=t/n?(s=e/o,l=s/r):(l=t/n,s=l*r);const d=s*l;d>a.area&&(a={area:d,width:s,height:l,rows:n,cols:o})}return a};function M({count:e,parentWidth:t,parentHeight:i,maxTileCount:o,maxRowCount:n,maxColCount:r,aspectRatio:a}){let s=0,l=0,d=0,u=0,c=!1,h=0;if(0===e)return{tilesInFirstPage:h,defaultWidth:s,defaultHeight:l,lastPageWidth:d,lastPageHeight:u,isLastPageDifferentFromFirstPage:c};if(o)({tilesInFirstPage:h,defaultWidth:s,defaultHeight:l,lastPageWidth:d,lastPageHeight:u,isLastPageDifferentFromFirstPage:c}=(({parentWidth:e,parentHeight:t,count:i,maxCount:o,aspectRatio:n})=>{let r=0,a=0,s=0,l=0,d=!1,u=0,c=0;const{width:h,height:g}=k(e,t,Math.min(i,o),n.width,n.height);if(r=h,a=g,u=Math.min(i,o),c=i%o,d=c>0&&i>o,d){const{width:i,height:o}=k(e,t,c,n.width,n.height);s=i,l=o}return{tilesInFirstPage:u,defaultWidth:r,defaultHeight:a,lastPageWidth:s,lastPageHeight:l,isLastPageDifferentFromFirstPage:d}})({parentWidth:t,parentHeight:i,count:e,maxCount:o,aspectRatio:a}));else if(n)({tilesInFirstPage:h,defaultWidth:s,defaultHeight:l,lastPageWidth:d,lastPageHeight:u,isLastPageDifferentFromFirstPage:c}=(({parentWidth:e,parentHeight:t,count:i,maxCount:o,aspectRatio:n})=>{let r=0,a=0,s=0,l=0,d=!1,u=0,c=0;const h=Math.min(Math.ceil(Math.sqrt(i*(n.width/n.height)/(e/t))),o),g=t/h,v=g*(n.width/n.height),f=Math.floor(e/v);if(r=v,a=g,u=Math.min(i,h*f),c=i%(h*f),d=c>0&&i>h*f,d){const i=t/Math.min(Math.ceil(Math.sqrt(c*(n.width/n.height)/(e/t))),o);l=i,s=i*(n.width/n.height)}return{tilesInFirstPage:u,defaultWidth:r,defaultHeight:a,lastPageWidth:s,lastPageHeight:l,isLastPageDifferentFromFirstPage:d}})({parentWidth:t,parentHeight:i,count:e,maxCount:n,aspectRatio:a}));else if(r)({tilesInFirstPage:h,defaultWidth:s,defaultHeight:l,lastPageWidth:d,lastPageHeight:u,isLastPageDifferentFromFirstPage:c}=(({parentWidth:e,parentHeight:t,count:i,maxCount:o,aspectRatio:n})=>{let r=0,a=0,s=0,l=0,d=!1,u=0,c=0;const h=Math.min(Math.ceil(Math.sqrt(i*(e/t)/(n.width/n.height))),o);let g=e/h,v=g/(n.width/n.height);v>t&&(v=t,g=v/(n.height/n.width));const f=Math.floor(t/v);if(a=v,r=g,u=Math.min(i,f*h),c=i%(f*h),d=c>0&&i>f*h,d){let i=e/Math.min(Math.ceil(Math.sqrt(c*(e/t)/(n.width/n.height))),o),r=i/(n.width/n.height);r>t&&(r=t,i=r/(n.height/n.width)),l=r,s=i}return{tilesInFirstPage:u,defaultWidth:r,defaultHeight:a,lastPageWidth:s,lastPageHeight:l,isLastPageDifferentFromFirstPage:d}})({parentWidth:t,parentHeight:i,count:e,maxCount:r,aspectRatio:a}));else{const{width:o,height:n}=k(t,i,e,a.width,a.height);s=o,l=n,h=e}return{tilesInFirstPage:h,defaultWidth:s,defaultHeight:l,lastPageWidth:d,lastPageHeight:u,isLastPageDifferentFromFirstPage:c}}const I=(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")}})),C={width:1,height:1};exports.HMSRoomProvider=({children:t,actions:o,store:n,notifications:r,stats:a,isHMSStatsOn:s=!1,leaveOnUnload:u=!0})=>{const c=e.useMemo((()=>{let e;const t=()=>{throw new Error("modifying store is not allowed")};if(o&&n)e={actions:o,store:d.default(Object.assign(Object.assign({},n),{setState:t,destroy:t}))},r&&(e.notifications=r),a&&(e.statsStore=d.default({getState:a.getState,subscribe:a.subscribe,setState:t,destroy:t}));else{const o=new i.HMSReactiveStore;if(e={actions:o.getActions(),store:d.default(Object.assign(Object.assign({},o.getStore()),{setState:t,destroy:t})),notifications:o.getNotifications()},s){const i=o.getStats();e.statsStore=d.default({getState:i.getState,subscribe:i.subscribe,setState:t,destroy:t})}}return e.actions.setFrameworkInfo({type:"react-web",version:l.default.version,sdkVersion:"0.6.4-alpha.3"}),e}),[o,n,r,a,s]);return e.useEffect((()=>{if(g&&u){const e=()=>c.actions.leave();return window.addEventListener("beforeunload",e),()=>{window.removeEventListener("beforeunload",e)}}return()=>{}}),[u,c]),l.default.createElement(v.Provider,{value:c},t)},exports.throwErrorHandler=e=>{throw e},exports.useAVToggle=(t=E)=>{const o=f(i.selectIsLocalAudioEnabled),n=f(i.selectIsLocalVideoEnabled),r=f(i.selectIsAllowedToPublish),a=b(),s=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(!n)}catch(e){t(e,"toggleVideo")}}))),[a,n,t]);return{isLocalAudioEnabled:o,isLocalVideoEnabled:n,toggleAudio:(null==r?void 0:r.audio)?s:void 0,toggleVideo:(null==r?void 0:r.video)?l:void 0}},exports.useAudioLevelStyles=function({trackId:t,getStyle:o,ref:n}){const r=y();e.useEffect((()=>r.subscribe((e=>{if(!n.current)return;const t=o(e);for(const e in t)n.current.style[e]=t[e]}),i.selectTrackAudioByID(t))),[o,n,r,t])},exports.useAutoplayError=()=>{const t=S(i.HMSNotificationTypes.ERROR),[o,n]=e.useState(""),r=b(),a=e.useCallback((()=>P(void 0,void 0,void 0,(function*(){yield r.unblockAudio()}))),[r]);return e.useEffect((()=>{3008===(null==t?void 0:t.data.code)&&n(null==t?void 0:t.data.message)}),[t]),{error:o,unblockAudio:a,resetError:()=>n("")}},exports.useCustomEvent=({type:t,json:o=!0,onEvent:n,handleError:r=E})=>{const a=b(),s=w();e.useEffect((()=>{a.ignoreMessageTypes([t])}),[a,t]),e.useEffect((()=>{if(!s)return;return s.onNotification((e=>{const i=e.data;if(i&&i.type===t)try{const e=o?JSON.parse(i.message):i.message;null==n||n(e)}catch(e){r(e,"handleCustomEvent")}}),i.HMSNotificationTypes.NEW_MESSAGE)}),[s,t,o,n,r]);return{sendEvent:e.useCallback(((e,i)=>P(void 0,void 0,void 0,(function*(){try{const r=((e,t)=>t?JSON.stringify(e||""):e)(e,o);i&&Array.isArray(null==i?void 0:i.roleNames)?yield a.sendGroupMessage(r,i.roleNames,t):"string"==typeof(null==i?void 0:i.peerId)?yield a.sendDirectMessage(r,i.peerId,t):yield a.sendBroadcastMessage(r,t),null==n||n(e)}catch(e){r(e,"sendCustomEvent")}}))),[a,r,n,t,o])}},exports.useDevices=(t=E)=>{const o=b(),n=f(i.selectDevices),r=f(i.selectLocalMediaSettings),a=f(i.selectIsAllowedToPublish),s={[i.DeviceType.audioOutput]:r.audioOutputDeviceId},l={[i.DeviceType.audioOutput]:n.audioOutput};a.video&&(l[i.DeviceType.videoInput]=n.videoInput,s[i.DeviceType.videoInput]=r.videoInputDeviceId),a.audio&&(l[i.DeviceType.audioInput]=n.audioInput,s[i.DeviceType.audioInput]=r.audioInputDeviceId);return{allDevices:l,selectedDeviceIDs:s,updateDevice:e.useCallback((({deviceType:e,deviceId:n})=>P(void 0,void 0,void 0,(function*(){try{switch(e){case i.DeviceType.audioInput:yield o.setAudioSettings({deviceId:n});break;case i.DeviceType.videoInput:yield o.setVideoSettings({deviceId:n});break;case i.DeviceType.audioOutput:yield o.setAudioOutputDevice(n)}}catch(e){t(e,"updateDevices")}}))),[t,o])}},exports.useHMSActions=b,exports.useHMSNotifications=S,exports.useHMSStatsStore=m,exports.useHMSStore=f,exports.useHMSVanillaNotifications=w,exports.useHMSVanillaStore=y,exports.useParticipantList=()=>{const t=f(i.selectIsConnectedToRoom),o=f(t?i.selectPeers:i.selectRemotePeers),n=f(i.selectPeerCount),r=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(r),participantsByRoles:r,peerCount:n,isConnected:t}},exports.useParticipants=e=>{var t;const o=f(i.selectIsConnectedToRoom),n=f(i.selectPeerCount),r=f(i.selectAvailableRoleNames);let a=f(o?i.selectPeers:i.selectRemotePeers);const s=Array.from(new Set(a.map((e=>e.roleName)))),l=y();if((null===(t=null==e?void 0:e.metadata)||void 0===t?void 0:t.isHandRaised)&&(a=a.filter((e=>l.getState(i.selectPeerMetadata(e.id)).isHandRaised))),(null==e?void 0:e.role)&&r.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 i;return(null===(i=e.roleName)||void 0===i?void 0:i.toLowerCase().includes(t))||e.name.toLowerCase().includes(t)}))}return{participants:a,isConnected:o,peerCount:n,rolesWithParticipants:s}},exports.usePreviewJoin=({name:t="",token:o,metadata:n,handleError:r=E,initEndpoint:a,initialSettings:s,captureNetworkQualityInPreview:l,asRole:d})=>{const u=b(),c=f(i.selectRoomState),h=f(i.selectIsConnectedToRoom)||!1,g=c===i.HMSRoomState.Preview,v=e.useMemo((()=>({userName:t,authToken:o,metaData:n,rememberDeviceSelection:!0,settings:s,initEndpoint:a,asRole:d,captureNetworkQualityInPreview:l})),[t,o,n,a,s,l,d]),p=e.useCallback((()=>P(void 0,void 0,void 0,(function*(){if(o&&c===i.HMSRoomState.Disconnected){h&&(yield u.leave());try{yield u.preview(v)}catch(e){r(e,"preview")}}}))),[u,r,o,c,v,h]);return{enableJoin:g,join:e.useCallback((()=>P(void 0,void 0,void 0,(function*(){if(o)try{yield u.join(v)}catch(e){r(e,"join")}}))),[u,v,r,o]),isConnected:h,preview:p}},exports.useRecordingStreaming=()=>{const e=f(i.selectRecordingState),t=f(i.selectRTMPState),o=f(i.selectHLSState),n=e.server.running,r=e.browser.running,a=e.hls.running,s=n||r||a;return{isServerRecordingOn:n,isBrowserRecordingOn:r,isHLSRecordingOn:a,isStreamingOn:o.running||t.running,isHLSRunning:o.running,isRTMPRunning:t.running,isRecordingOn:s}},exports.useRemoteAVToggle=(t,o,n=E)=>{const r=b(),a=f(i.selectAudioTrackByID(t)),s=f(i.selectVideoTrackByID(o)),l=f(i.selectAudioTrackVolume(null==a?void 0:a.id)),d=f(i.selectPermissions),u=(null==s?void 0:s.enabled)?null==d?void 0:d.mute:null==d?void 0:d.unmute,c=(null==a?void 0:a.enabled)?null==d?void 0:d.mute:null==d?void 0:d.unmute,h=e.useCallback((()=>P(void 0,void 0,void 0,(function*(){yield I(r,a,n)}))),[r,a,n]),g=e.useCallback((()=>P(void 0,void 0,void 0,(function*(){yield I(r,s,n)}))),[r,n,s]),v=e.useCallback((e=>{a&&r.setVolume(e,a.id)}),[r,a]);return{isAudioEnabled:!!(null==a?void 0:a.enabled),isVideoEnabled:!!(null==s?void 0:s.enabled),volume:l,toggleAudio:a&&c?h:void 0,toggleVideo:"regular"===(null==s?void 0:s.source)&&u?g:void 0,setVolume:a?v:void 0}},exports.useScreenShare=(t=E)=>{var o,n;const r=b(),a=f(i.selectIsLocalScreenShared),s=f(i.selectPeerScreenSharing),l=f(i.selectScreenSharesByPeerId(null==s?void 0:s.id)),d=e.useCallback((e=>P(void 0,void 0,void 0,(function*(){try{yield r.setScreenShareEnabled(!a,e)}catch(e){t(e,"toggleScreenShare")}}))),[r,a,t]);return{amIScreenSharing:a,screenSharingPeerId:null==s?void 0:s.id,screenSharingPeerName:null==s?void 0:s.name,screenShareVideoTrackId:null===(o=null==l?void 0:l.video)||void 0===o?void 0:o.id,screenShareAudioTrackId:null===(n=null==l?void 0:l.audio)||void 0===n?void 0:n.id,toggleScreenShare:d}},exports.useVideo=({trackId:t,attach:r,threshold:a=.5})=>{var s;const l=b(),d=e.useRef(null),u=f(i.selectVideoTrackByID(t)),{ref:h,inView:v}=o.useInView({threshold:a}),{width:p=0,height:m=0,ref:y}=n.useResizeDetector({refreshMode:"debounce",refreshRate:300}),w=e.useCallback((()=>P(void 0,void 0,void 0,(function*(){var e;if(p>0&&m>0&&v&&(null===(e=null==u?void 0:u.layerDefinitions)||void 0===e?void 0:e.length)&&y.current&&(null==u?void 0:u.enabled)&&!(null==u?void 0:u.degraded)){const e=(({layerDefinitions:e,width:t,height:i})=>{let o,n=Number.MAX_VALUE;for(const{resolution:r,layer:a}of e){const e=Math.abs(t-(r.width||0))+Math.abs(i-(r.height||0));e<n&&(n=e,o=a)}return o})({layerDefinitions:u.layerDefinitions,width:p,height:m});yield l.setPreferredLayer(null==u?void 0:u.id,e)}}))),[p,m,null==u?void 0:u.id,l,null==u?void 0:u.enabled,null==u?void 0:u.degraded,y,v]),S=e.useCallback((e=>{var t;e&&(d.current=e,h(e),(null===(t=null==u?void 0:u.layerDefinitions)||void 0===t?void 0:t.length)&&(y.current=e))}),[h,null===(s=null==u?void 0:u.layerDefinitions)||void 0===s?void 0:s.length,y]);return e.useEffect((()=>{w()}),[w]),e.useEffect((()=>{P(void 0,void 0,void 0,(function*(){if(d.current&&(null==u?void 0:u.id)){let e=!0;g&&(e="visible"===window.getComputedStyle(d.current).visibility),v&&u.enabled&&e&&!1!==r?yield l.attachVideo(u.id,d.current):yield l.detachVideo(u.id,d.current)}}))}),[l,v,d,null==u?void 0:u.id,null==u?void 0:u.enabled,null==u?void 0:u.deviceID,null==u?void 0:u.plugins,r]),e.useEffect((()=>()=>{P(void 0,void 0,void 0,(function*(){if(d.current&&u)try{yield l.detachVideo(u.id,d.current)}catch(e){c.w("detach video error for track",u.id,e)}}))}),[]),{videoRef:S}},exports.useVideoList=({peers:t,maxTileCount:o,maxColCount:r,maxRowCount:a,includeScreenShareForPeer:s=(()=>!1),aspectRatio:l=C,filterNonPublishingPeers:d=!0,offsetY:u=0})=>{const{width:c=0,height:h=0,ref:g}=n.useResizeDetector(),v=((e,t,i,o=!0)=>{if(!e||!t||!i)return[];const n=[];for(const r of e)if(void 0===r.videoTrack&&r.audioTrack&&t[r.audioTrack]?n.push({peer:r}):r.videoTrack&&t[r.videoTrack]?n.push({track:t[r.videoTrack],peer:r}):o||n.push({peer:r}),r.auxiliaryTracks.length>0&&r.auxiliaryTracks.forEach((e=>{const i=t[e];"video"===(null==i?void 0:i.type)&&"regular"===(null==i?void 0:i.source)&&n.push({track:i,peer:r})})),i(r)&&r.auxiliaryTracks.length>0){const e=r.auxiliaryTracks.find((e=>{const i=t[e];return"video"===(null==i?void 0:i.type)&&"screen"===(null==i?void 0:i.source)}));e&&n.push({track:t[e],peer:r})}return n})(t,y().getState(i.selectTracksMap),s,d),f=e.useMemo((()=>{if(l)return l;return{width:function(e){if(0===e.length)return null;const t={};let i=e[0],o=1;for(let n=0;n<e.length;n++){const r=e[n];null===t[r]?t[r]=1:t[r]++,t[r]>o&&(i=r,o=t[r])}return i}(v.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}}),[l,v]),p=v.length,{tilesInFirstPage:m,defaultWidth:w,defaultHeight:b,lastPageWidth:S,lastPageHeight:P,isLastPageDifferentFromFirstPage:E}=e.useMemo((()=>M({count:p,parentWidth:Math.floor(c),parentHeight:Math.floor(h)-Math.min(h,u),maxTileCount:o,maxRowCount:a,maxColCount:r,aspectRatio:f})),[p,c,h,o,a,r,f,u]);return{pagesWithTiles:e.useMemo((()=>R({elements:v,tilesInFirstPage:m,onlyOnePage:!1,isLastPageDifferentFromFirstPage:E,defaultWidth:w,defaultHeight:b,lastPageWidth:S,lastPageHeight:P})),[v,m,E,w,b,S,P]),ref:g}},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.6.4-alpha.1"}),e}),[s,n,c,f,u]);return r((()=>{if(l&&d){const t=()=>m.actions.leave();return window.addEventListener("beforeunload",t),()=>{window.removeEventListener("beforeunload",t)}}return()=>{}}),[d,m]),t.createElement(w.Provider,{value:m},e)},m=c(w),b=f(w),S=()=>{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,b as useHMSStatsStore,m as useHMSStore,g as useHMSVanillaNotifications,S 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.6.4-alpha.3"}),e}),[s,n,c,f,u]);return r((()=>{if(l&&d){const t=()=>m.actions.leave();return window.addEventListener("beforeunload",t),()=>{window.removeEventListener("beforeunload",t)}}return()=>{}}),[d,m]),t.createElement(w.Provider,{value:m},e)},m=c(w),b=f(w),S=()=>{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,b as useHMSStatsStore,m as useHMSStore,g as useHMSVanillaNotifications,S 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.6.4-alpha.1",
7
+ "version": "0.6.4-alpha.3",
8
8
  "author": "100ms",
9
9
  "license": "MIT",
10
10
  "files": [
@@ -37,10 +37,10 @@
37
37
  "react": ">=16.8 <19.0.0"
38
38
  },
39
39
  "dependencies": {
40
- "@100mslive/hms-video-store": "0.8.4-alpha.1",
40
+ "@100mslive/hms-video-store": "0.8.4-alpha.3",
41
41
  "react-intersection-observer": "^8.33.1",
42
42
  "react-resize-detector": "^7.0.0",
43
43
  "zustand": "^3.6.2"
44
44
  },
45
- "gitHead": "e8efa0dcf72a288750a4ed2c9fca0942aa74081f"
45
+ "gitHead": "8648086eadbc385870d427b992221372e5c029b0"
46
46
  }