@100mslive/react-sdk 0.6.2-alpha.4 → 0.6.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-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);let f;const p=(m=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(m);if(!o)throw new Error(h);return(0,o.store)(t,i)});var m;const y=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),w=()=>{const t=e.useContext(v);if(!t)throw new Error(h);return t.store},b=()=>{const t=e.useContext(v);if(!t)throw new Error(h);return t.notifications},S=()=>{const t=e.useContext(v);if(!t)throw new Error(h);return t.actions},P=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 E(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 R=(e,t)=>c.e("react-sdk",t,e),k=({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 x=(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 I({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}=x(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}=x(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}=x(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 M=(e,t,i)=>E(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};var D;exports.DeviceType=void 0,(D=exports.DeviceType||(exports.DeviceType={})).videoInput="videoInput",D.audioInput="audioInput",D.audioOutput="audioOutput";exports.HMSRoomProvider=({children:t,actions:o,store:n,notifications:r,stats:a,isHMSStatsOn:s=!1,leaveOnUnload:u=!0})=>{if(!f){const e=()=>{throw new Error("modifying store is not allowed")};if(o&&n)f={actions:o,store:d.default(Object.assign(Object.assign({},n),{setState:e,destroy:e}))},r&&(f.notifications=r),a&&(f.statsStore=d.default({getState:a.getState,subscribe:a.subscribe,setState:e,destroy:e}));else{const t=new i.HMSReactiveStore;if(f={actions:t.getActions(),store:d.default(Object.assign(Object.assign({},t.getStore()),{setState:e,destroy:e})),notifications:t.getNotifications()},s){const i=t.getStats();f.statsStore=d.default({getState:i.getState,subscribe:i.subscribe,setState:e,destroy:e})}}f.actions.setFrameworkInfo({type:"react-web",version:l.default.version,sdkVersion:"0.6.2-alpha.4"})}return e.useEffect((()=>{if(g&&u){const e=()=>f.actions.leave();return window.addEventListener("beforeunload",e),()=>{window.removeEventListener("beforeunload",e)}}return()=>{}}),[u]),l.default.createElement(v.Provider,{value:f},t)},exports.throwErrorHandler=e=>{throw e},exports.useAVToggle=(t=R)=>{const o=p(i.selectIsLocalAudioEnabled),n=p(i.selectIsLocalVideoEnabled),r=p(i.selectIsAllowedToPublish),a=S(),s=e.useCallback((()=>E(void 0,void 0,void 0,(function*(){try{yield a.setLocalAudioEnabled(!o)}catch(e){t(e,"toggleAudio")}}))),[a,o,t]),l=e.useCallback((()=>E(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=w();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=P(i.HMSNotificationTypes.ERROR),[o,n]=e.useState(""),r=S(),a=e.useCallback((()=>E(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=R})=>{const a=S(),s=b();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)=>E(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=R)=>{const o=S(),n=p(i.selectDevices),r=p(i.selectLocalMediaSettings),a=p(i.selectIsAllowedToPublish),s={[exports.DeviceType.audioOutput]:r.audioOutputDeviceId},l={[exports.DeviceType.audioOutput]:n.audioOutput};a.video&&(l[exports.DeviceType.videoInput]=n.videoInput,s[exports.DeviceType.videoInput]=r.videoInputDeviceId),a.audio&&(l[exports.DeviceType.audioInput]=n.audioInput,s[exports.DeviceType.audioInput]=r.audioInputDeviceId);return{allDevices:l,selectedDeviceIDs:s,updateDevice:e.useCallback((({deviceType:e,deviceId:i})=>E(void 0,void 0,void 0,(function*(){try{switch(e){case exports.DeviceType.audioInput:yield o.setAudioSettings({deviceId:i});break;case exports.DeviceType.videoInput:yield o.setVideoSettings({deviceId:i});break;case exports.DeviceType.audioOutput:yield o.setAudioOutputDevice(i)}}catch(e){t(e,"updateDevices")}}))),[t,o])}},exports.useHMSActions=S,exports.useHMSNotifications=P,exports.useHMSStatsStore=y,exports.useHMSStore=p,exports.useHMSVanillaNotifications=b,exports.useHMSVanillaStore=w,exports.useParticipantList=()=>{const t=p(i.selectIsConnectedToRoom),o=p(t?i.selectPeers:i.selectRemotePeers),n=p(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=p(i.selectIsConnectedToRoom),n=p(i.selectPeerCount),r=p(i.selectAvailableRoleNames);let a=p(o?i.selectPeers:i.selectRemotePeers);const s=Array.from(new Set(a.map((e=>e.roleName)))),l=w();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=R,initEndpoint:a,initialSettings:s,captureNetworkQualityInPreview:l})=>{const d=S(),u=p(i.selectRoomState),c=p(i.selectIsConnectedToRoom)||!1,h=u===i.HMSRoomState.Preview,g=e.useMemo((()=>({userName:t,authToken:o,metaData:n,rememberDeviceSelection:!0,settings:s,initEndpoint:a,captureNetworkQualityInPreview:l})),[t,o,n,a,s,l]),v=e.useCallback((()=>E(void 0,void 0,void 0,(function*(){if(o&&u===i.HMSRoomState.Disconnected){c&&(yield d.leave());try{yield d.preview(g)}catch(e){r(e,"preview")}}}))),[d,r,o,u,g,c]);return{enableJoin:h,join:e.useCallback((()=>E(void 0,void 0,void 0,(function*(){if(o)try{yield d.join(g)}catch(e){r(e,"join")}}))),[d,g,r,o]),isConnected:c,preview:v}},exports.useRecordingStreaming=()=>{const e=p(i.selectRecordingState),t=p(i.selectRTMPState),o=p(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=R)=>{const r=S(),a=p(i.selectAudioTrackByID(t)),s=p(i.selectVideoTrackByID(o)),l=p(i.selectAudioTrackVolume(null==a?void 0:a.id)),d=p(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((()=>E(void 0,void 0,void 0,(function*(){yield M(r,a,n)}))),[r,a,n]),g=e.useCallback((()=>E(void 0,void 0,void 0,(function*(){yield M(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=R)=>{var o,n;const r=S(),a=p(i.selectIsLocalScreenShared),s=p(i.selectPeerScreenSharing),l=p(i.selectScreenSharesByPeerId(null==s?void 0:s.id)),d=e.useCallback((e=>E(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=S(),d=e.useRef(null),u=p(i.selectVideoTrackByID(t)),{ref:h,inView:v}=o.useInView({threshold:a}),{width:f=0,height:m=0,ref:y}=n.useResizeDetector({refreshMode:"debounce",refreshRate:300}),w=e.useCallback((()=>E(void 0,void 0,void 0,(function*(){var e;if(f>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:f,height:m});yield l.setPreferredLayer(null==u?void 0:u.id,e)}}))),[f,m,null==u?void 0:u.id,l,null==u?void 0:u.enabled,null==u?void 0:u.degraded,y,v]),b=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((()=>{E(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((()=>()=>{E(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:b}},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,w().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:y,defaultHeight:b,lastPageWidth:S,lastPageHeight:P,isLastPageDifferentFromFirstPage:E}=e.useMemo((()=>I({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((()=>k({elements:v,tilesInFirstPage:m,onlyOnePage:!1,isLastPageDifferentFromFirstPage:E,defaultWidth:y,defaultHeight:b,lastPageWidth:S,lastPageHeight:P})),[v,m,E,y,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);let f;const p=(m=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(m);if(!o)throw new Error(h);return(0,o.store)(t,i)});var m;const y=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),w=()=>{const t=e.useContext(v);if(!t)throw new Error(h);return t.store},b=()=>{const t=e.useContext(v);if(!t)throw new Error(h);return t.notifications},S=()=>{const t=e.useContext(v);if(!t)throw new Error(h);return t.actions},P=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 E(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 R=(e,t)=>c.e("react-sdk",t,e),k=({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 x=(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 I({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}=x(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}=x(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}=x(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 M=(e,t,i)=>E(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};var D;exports.DeviceType=void 0,(D=exports.DeviceType||(exports.DeviceType={})).videoInput="videoInput",D.audioInput="audioInput",D.audioOutput="audioOutput";exports.HMSRoomProvider=({children:t,actions:o,store:n,notifications:r,stats:a,isHMSStatsOn:s=!1,leaveOnUnload:u=!0})=>{if(!f){const e=()=>{throw new Error("modifying store is not allowed")};if(o&&n)f={actions:o,store:d.default(Object.assign(Object.assign({},n),{setState:e,destroy:e}))},r&&(f.notifications=r),a&&(f.statsStore=d.default({getState:a.getState,subscribe:a.subscribe,setState:e,destroy:e}));else{const t=new i.HMSReactiveStore;if(f={actions:t.getActions(),store:d.default(Object.assign(Object.assign({},t.getStore()),{setState:e,destroy:e})),notifications:t.getNotifications()},s){const i=t.getStats();f.statsStore=d.default({getState:i.getState,subscribe:i.subscribe,setState:e,destroy:e})}}f.actions.setFrameworkInfo({type:"react-web",version:l.default.version,sdkVersion:"0.6.2-alpha.6"})}return e.useEffect((()=>{if(g&&u){const e=()=>f.actions.leave();return window.addEventListener("beforeunload",e),()=>{window.removeEventListener("beforeunload",e)}}return()=>{}}),[u]),l.default.createElement(v.Provider,{value:f},t)},exports.throwErrorHandler=e=>{throw e},exports.useAVToggle=(t=R)=>{const o=p(i.selectIsLocalAudioEnabled),n=p(i.selectIsLocalVideoEnabled),r=p(i.selectIsAllowedToPublish),a=S(),s=e.useCallback((()=>E(void 0,void 0,void 0,(function*(){try{yield a.setLocalAudioEnabled(!o)}catch(e){t(e,"toggleAudio")}}))),[a,o,t]),l=e.useCallback((()=>E(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=w();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=P(i.HMSNotificationTypes.ERROR),[o,n]=e.useState(""),r=S(),a=e.useCallback((()=>E(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=R})=>{const a=S(),s=b();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)=>E(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=R)=>{const o=S(),n=p(i.selectDevices),r=p(i.selectLocalMediaSettings),a=p(i.selectIsAllowedToPublish),s={[exports.DeviceType.audioOutput]:r.audioOutputDeviceId},l={[exports.DeviceType.audioOutput]:n.audioOutput};a.video&&(l[exports.DeviceType.videoInput]=n.videoInput,s[exports.DeviceType.videoInput]=r.videoInputDeviceId),a.audio&&(l[exports.DeviceType.audioInput]=n.audioInput,s[exports.DeviceType.audioInput]=r.audioInputDeviceId);return{allDevices:l,selectedDeviceIDs:s,updateDevice:e.useCallback((({deviceType:e,deviceId:i})=>E(void 0,void 0,void 0,(function*(){try{switch(e){case exports.DeviceType.audioInput:yield o.setAudioSettings({deviceId:i});break;case exports.DeviceType.videoInput:yield o.setVideoSettings({deviceId:i});break;case exports.DeviceType.audioOutput:yield o.setAudioOutputDevice(i)}}catch(e){t(e,"updateDevices")}}))),[t,o])}},exports.useHMSActions=S,exports.useHMSNotifications=P,exports.useHMSStatsStore=y,exports.useHMSStore=p,exports.useHMSVanillaNotifications=b,exports.useHMSVanillaStore=w,exports.useParticipantList=()=>{const t=p(i.selectIsConnectedToRoom),o=p(t?i.selectPeers:i.selectRemotePeers),n=p(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=p(i.selectIsConnectedToRoom),n=p(i.selectPeerCount),r=p(i.selectAvailableRoleNames);let a=p(o?i.selectPeers:i.selectRemotePeers);const s=Array.from(new Set(a.map((e=>e.roleName)))),l=w();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=R,initEndpoint:a,initialSettings:s,captureNetworkQualityInPreview:l})=>{const d=S(),u=p(i.selectRoomState),c=p(i.selectIsConnectedToRoom)||!1,h=u===i.HMSRoomState.Preview,g=e.useMemo((()=>({userName:t,authToken:o,metaData:n,rememberDeviceSelection:!0,settings:s,initEndpoint:a,captureNetworkQualityInPreview:l})),[t,o,n,a,s,l]),v=e.useCallback((()=>E(void 0,void 0,void 0,(function*(){if(o&&u===i.HMSRoomState.Disconnected){c&&(yield d.leave());try{yield d.preview(g)}catch(e){r(e,"preview")}}}))),[d,r,o,u,g,c]);return{enableJoin:h,join:e.useCallback((()=>E(void 0,void 0,void 0,(function*(){if(o)try{yield d.join(g)}catch(e){r(e,"join")}}))),[d,g,r,o]),isConnected:c,preview:v}},exports.useRecordingStreaming=()=>{const e=p(i.selectRecordingState),t=p(i.selectRTMPState),o=p(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=R)=>{const r=S(),a=p(i.selectAudioTrackByID(t)),s=p(i.selectVideoTrackByID(o)),l=p(i.selectAudioTrackVolume(null==a?void 0:a.id)),d=p(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((()=>E(void 0,void 0,void 0,(function*(){yield M(r,a,n)}))),[r,a,n]),g=e.useCallback((()=>E(void 0,void 0,void 0,(function*(){yield M(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=R)=>{var o,n;const r=S(),a=p(i.selectIsLocalScreenShared),s=p(i.selectPeerScreenSharing),l=p(i.selectScreenSharesByPeerId(null==s?void 0:s.id)),d=e.useCallback((e=>E(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=S(),d=e.useRef(null),u=p(i.selectVideoTrackByID(t)),{ref:h,inView:v}=o.useInView({threshold:a}),{width:f=0,height:m=0,ref:y}=n.useResizeDetector({refreshMode:"debounce",refreshRate:300}),w=e.useCallback((()=>E(void 0,void 0,void 0,(function*(){var e;if(f>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:f,height:m});yield l.setPreferredLayer(null==u?void 0:u.id,e)}}))),[f,m,null==u?void 0:u.id,l,null==u?void 0:u.enabled,null==u?void 0:u.degraded,y,v]),b=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((()=>{E(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((()=>()=>{E(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:b}},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,w().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:y,defaultHeight:b,lastPageWidth:S,lastPageHeight:P,isLastPageDifferentFromFirstPage:E}=e.useMemo((()=>I({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((()=>k({elements:v,tilesInFirstPage:m,onlyOnePage:!1,isLastPageDifferentFromFirstPage:E,defaultWidth:y,defaultHeight:b,lastPageWidth:S,lastPageHeight:P})),[v,m,E,y,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,useEffect as o,useContext as r,useState as s}from"react";import n from"zustand";import{HMSReactiveStore as i}from"@100mslive/hms-video-store";import{makeHMSStoreHook as a,makeHMSStatsStoreHook as c,hooksErrorMessage as f}from"./store.js";import{isBrowser as u}from"../utils/isBrowser.js";const l=e(null);let w;const d=({children:e,actions:r,store:s,notifications:a,stats:c,isHMSStatsOn:f=!1,leaveOnUnload:d=!0})=>{if(!w){const e=()=>{throw new Error("modifying store is not allowed")};if(r&&s)w={actions:r,store:n(Object.assign(Object.assign({},s),{setState:e,destroy:e}))},a&&(w.notifications=a),c&&(w.statsStore=n({getState:c.getState,subscribe:c.subscribe,setState:e,destroy:e}));else{const t=new i;if(w={actions:t.getActions(),store:n(Object.assign(Object.assign({},t.getStore()),{setState:e,destroy:e})),notifications:t.getNotifications()},f){const o=t.getStats();w.statsStore=n({getState:o.getState,subscribe:o.subscribe,setState:e,destroy:e})}}w.actions.setFrameworkInfo({type:"react-web",version:t.version,sdkVersion:"0.6.2-alpha.
|
|
1
|
+
import t,{createContext as e,useEffect as o,useContext as r,useState as s}from"react";import n from"zustand";import{HMSReactiveStore as i}from"@100mslive/hms-video-store";import{makeHMSStoreHook as a,makeHMSStatsStoreHook as c,hooksErrorMessage as f}from"./store.js";import{isBrowser as u}from"../utils/isBrowser.js";const l=e(null);let w;const d=({children:e,actions:r,store:s,notifications:a,stats:c,isHMSStatsOn:f=!1,leaveOnUnload:d=!0})=>{if(!w){const e=()=>{throw new Error("modifying store is not allowed")};if(r&&s)w={actions:r,store:n(Object.assign(Object.assign({},s),{setState:e,destroy:e}))},a&&(w.notifications=a),c&&(w.statsStore=n({getState:c.getState,subscribe:c.subscribe,setState:e,destroy:e}));else{const t=new i;if(w={actions:t.getActions(),store:n(Object.assign(Object.assign({},t.getStore()),{setState:e,destroy:e})),notifications:t.getNotifications()},f){const o=t.getStats();w.statsStore=n({getState:o.getState,subscribe:o.subscribe,setState:e,destroy:e})}}w.actions.setFrameworkInfo({type:"react-web",version:t.version,sdkVersion:"0.6.2-alpha.6"})}return o((()=>{if(u&&d){const t=()=>w.actions.leave();return window.addEventListener("beforeunload",t),()=>{window.removeEventListener("beforeunload",t)}}return()=>{}}),[d]),t.createElement(l.Provider,{value:w},e)},m=a(l),b=c(l),S=()=>{const t=r(l);if(!t)throw new Error(f);return t.store},g=()=>{const t=r(l);if(!t)throw new Error(f);return t.notifications},v=()=>{const t=r(l);if(!t)throw new Error(f);return t.actions},h=t=>{const e=r(l),[n,i]=s(null);if(!e)throw new Error(f);return o((()=>{if(!e.notifications)return;return e.notifications.onNotification((t=>{i(t)}),t)}),[e.notifications,t]),n};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.2-alpha.
|
|
7
|
+
"version": "0.6.2-alpha.6",
|
|
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.2-alpha.
|
|
40
|
+
"@100mslive/hms-video-store": "0.8.2-alpha.6",
|
|
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": "
|
|
45
|
+
"gitHead": "a4b47fc3830edaccc8d10f07d7ac7b062e0578e6"
|
|
46
46
|
}
|