@100mslive/react-sdk 0.0.12-alpha.3 → 0.0.13

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.
@@ -0,0 +1 @@
1
+ import{__awaiter as o}from"../node_modules/tslib/tslib.es6.js";import{selectIsLocalAudioEnabled as i,selectIsLocalVideoEnabled as d,selectIsAllowedToPublish as e}from"@100mslive/hms-video-store";import{useCallback as t}from"react";import{useHMSStore as l,useHMSActions as r}from"../primitives/HmsRoomProvider.js";import{logErrorHandler as s}from"../utils/commons.js";const m=(m=s)=>{const n=l(i),v=l(d),c=l(e),a=r(),u=t((()=>o(void 0,void 0,void 0,(function*(){try{yield a.setLocalAudioEnabled(!n)}catch(o){m(o,"toggleAudio")}}))),[a,n,m]),g=t((()=>o(void 0,void 0,void 0,(function*(){try{yield a.setLocalVideoEnabled(!v)}catch(o){m(o,"toggleVideo")}}))),[a,v,m]);return{isLocalAudioEnabled:n,isLocalVideoEnabled:v,toggleAudio:(null==c?void 0:c.audio)?u:void 0,toggleVideo:(null==c?void 0:c.video)?g:void 0}};export{m as useAVToggle};
@@ -0,0 +1 @@
1
+ import{useEffect as r}from"react";import{selectTrackAudioByID as t}from"@100mslive/hms-video-store";import{useHMSVanillaStore as o}from"../primitives/HmsRoomProvider.js";function e({trackId:e,getStyle:i,ref:s}){const m=o();r((()=>m.subscribe((r=>{if(!s.current)return;const t=i(r);for(const r in t)s.current.style[r]=t[r]}),t(e))),[i,s,m,e])}export{e as useAudioLevelStyles};
@@ -0,0 +1 @@
1
+ import{__awaiter as o}from"../node_modules/tslib/tslib.es6.js";import{useState as r,useCallback as i,useEffect as e}from"react";import{HMSNotificationTypes as t}from"@100mslive/hms-video-store";import{useHMSNotifications as s,useHMSActions as d}from"../primitives/HmsRoomProvider.js";const m=()=>{const m=s(t.ERROR),[l,n]=r(""),u=d(),v=i((()=>o(void 0,void 0,void 0,(function*(){yield u.unblockAudio()}))),[u]);return e((()=>{3008===(null==m?void 0:m.data.code)&&n(null==m?void 0:m.data.message)}),[m]),{error:l,unblockAudio:v,resetError:()=>n("")}};export{m as useAutoplayError};
@@ -0,0 +1 @@
1
+ import{__awaiter as o}from"../node_modules/tslib/tslib.es6.js";import{useHMSActions as t,useHMSVanillaNotifications as e}from"../primitives/HmsRoomProvider.js";import{useEffect as s,useCallback as r}from"react";import{HMSNotificationTypes as n}from"@100mslive/hms-video-store";import{logErrorHandler as i}from"../utils/commons.js";const m=({type:m,onEvent:d,handleError:a=i})=>{const c=t(),l=e();s((()=>{c.ignoreMessageTypes([m])}),[c,m]),s((()=>{if(!l)return;return l.onNotification((o=>{const t=o.data;if(t&&t.type===m)try{const o=JSON.parse(t.message);null==d||d(o)}catch(o){a(o,"handleCustomEvent")}}),n.NEW_MESSAGE)}),[l,m,d,a]);return{sendEvent:r((t=>o(void 0,void 0,void 0,(function*(){try{const o=JSON.stringify(t||"");yield c.sendBroadcastMessage(o,m),null==d||d(t)}catch(o){a(o,"sendCustomEvent")}}))),[c,a,d,m])}};export{m as useCustomEvent};
@@ -0,0 +1 @@
1
+ import{__awaiter as e}from"../node_modules/tslib/tslib.es6.js";import{selectDevices as i,selectLocalMediaSettings as t,selectIsAllowedToPublish as u}from"@100mslive/hms-video-store";import{useCallback as o}from"react";import{useHMSActions as d,useHMSStore as p}from"../primitives/HmsRoomProvider.js";import{logErrorHandler as s}from"../utils/commons.js";var v,a;(a=v||(v={})).videoInput="videoInput",a.audioInput="audioInput",a.audioOutput="audioOutput";const c=(a=s)=>{const c=d(),n=p(i),r=p(t),I=p(u),m={[v.audioOutput]:r.audioOutputDeviceId},l={[v.audioOutput]:n.audioOutput};I.video&&(l[v.videoInput]=n.videoInput,m[v.videoInput]=r.videoInputDeviceId),I.audio&&(l[v.audioInput]=n.audioInput,m[v.audioInput]=r.audioInputDeviceId);return{allDevices:l,selectedDeviceIDs:m,updateDevice:o((({deviceType:i,deviceId:t})=>e(void 0,void 0,void 0,(function*(){try{switch(i){case v.audioInput:yield c.setAudioSettings({deviceId:t});break;case v.videoInput:yield c.setVideoSettings({deviceId:t});break;case v.audioOutput:c.setAudioOutputDevice(t)}}catch(e){a(e,"updateDevices")}}))),[a,c])}};export{v as DeviceType,c as useDevices};
@@ -0,0 +1 @@
1
+ import{useMemo as o}from"react";import{selectIsConnectedToRoom as r,selectPeers as t,selectRemotePeers as e,selectPeerCount as s}from"@100mslive/hms-video-store";import{useHMSStore as i}from"../primitives/HmsRoomProvider.js";import{groupByRoles as m}from"../utils/groupBy.js";const p=()=>{const p=i(r),n=i(p?t:e),c=i(s),f=o((()=>m(n)),[n]);return{roles:Object.keys(f),participantsByRoles:f,peerCount:c,isConnected:p}};export{p as useParticipantList};
@@ -0,0 +1 @@
1
+ import{__awaiter as e}from"../node_modules/tslib/tslib.es6.js";import{selectRoomState as i,selectIsConnectedToRoom as t,HMSRoomState as o}from"@100mslive/hms-video-store";import{useMemo as r,useCallback as n}from"react";import{useHMSActions as m,useHMSStore as s}from"../primitives/HmsRoomProvider.js";import{logErrorHandler as a}from"../utils/commons.js";const c=({name:c="",token:d,metadata:v,handleError:l=a,initEndpoint:p,initialSettings:u,captureNetworkQualityInPreview:f})=>{const w=m(),j=s(i),y=s(t)||!1,h=j===o.Preview,b=r((()=>({userName:c,authToken:d,metaData:v,rememberDeviceSelection:!0,settings:u,initEndpoint:p,captureNetworkQualityInPreview:f})),[c,d,v,p,u,f]),k=n((()=>{e(void 0,void 0,void 0,(function*(){if(d){j!==o.Disconnected&&(yield w.leave());try{yield w.preview(b)}catch(e){l(e,"preview")}}}))}),[w,l,d,j,b]);return{enableJoin:h,join:n((()=>{if(d)try{w.join(b)}catch(e){l(e,"join")}}),[w,b,l,d]),isConnected:y,preview:k}};export{c as usePreviewJoin};
@@ -0,0 +1 @@
1
+ import{selectRecordingState as n,selectRTMPState as r,selectHLSState as i}from"@100mslive/hms-video-store";import{useHMSStore as s}from"../primitives/HmsRoomProvider.js";const e=()=>{const e=s(n),o=s(r),g=s(i),m=e.server.running,u=e.browser.running,t=e.hls.running,R=m||u||t;return{isServerRecordingOn:m,isBrowserRecordingOn:u,isHLSRecordingOn:t,isStreamingOn:g.running||o.running,isHLSRunning:g.running,isRTMPRunning:o.running,isRecordingOn:R}};export{e as useRecordingStreaming};
@@ -0,0 +1 @@
1
+ import{__awaiter as o}from"../node_modules/tslib/tslib.es6.js";import{selectTrackByID as i,selectAudioTrackVolume as e,selectPermissions as d}from"@100mslive/hms-video-store";import{useHMSActions as l,useHMSStore as n}from"../primitives/HmsRoomProvider.js";import{useCallback as t}from"react";import{logErrorHandler as u}from"../utils/commons.js";const m=(i,e,d)=>o(void 0,void 0,void 0,(function*(){if(e)try{yield i.setRemoteTrackEnabled(e.id,!e.enabled)}catch(o){d(o,"remoteToggle")}})),v=(v,r,s=u)=>{const a=l(),c=n(i(v)),b=n(i(r)),f=n(e(null==c?void 0:c.id)),g=n(d),p=(null==b?void 0:b.enabled)?null==g?void 0:g.mute:null==g?void 0:g.unmute,y=(null==c?void 0:c.enabled)?null==g?void 0:g.mute:null==g?void 0:g.unmute,V=t((()=>o(void 0,void 0,void 0,(function*(){yield m(a,c,s)}))),[a,c,s]),j=t((()=>o(void 0,void 0,void 0,(function*(){yield m(a,b,s)}))),[a,s,b]),E=t((o=>{c&&a.setVolume(o,c.id)}),[a,c]);return{isAudioEnabled:!!(null==c?void 0:c.enabled),isVideoEnabled:!!(null==b?void 0:b.enabled),volume:f,toggleAudio:c&&y?V:void 0,toggleVideo:"regular"===(null==b?void 0:b.source)&&p?j:void 0,setVolume:c?E:void 0}};export{v as useRemoteAVToggle};
@@ -0,0 +1 @@
1
+ import{__awaiter as e}from"../node_modules/tslib/tslib.es6.js";import{selectIsLocalScreenShared as o,selectPeerScreenSharing as r,selectScreenSharesByPeerId as i}from"@100mslive/hms-video-store";import{useHMSActions as d,useHMSStore as n}from"../primitives/HmsRoomProvider.js";import{useCallback as l}from"react";import{logErrorHandler as m}from"../utils/commons.js";const s=(s=m)=>{var t,a;const v=d(),c=n(o),u=n(r),S=n(i(null==u?void 0:u.id)),h=l(((o=!1)=>e(void 0,void 0,void 0,(function*(){try{yield v.setScreenShareEnabled(!c,o)}catch(e){s(e,"toggleScreenShare")}}))),[v,c,s]);return{amIScreenSharing:c,screenSharingPeerId:null==u?void 0:u.id,screenSharingPeerName:null==u?void 0:u.name,screenShareVideoTrackId:null===(t=null==S?void 0:S.video)||void 0===t?void 0:t.id,screenShareAudioTrackId:null===(a=null==S?void 0:S.audio)||void 0===a?void 0:a.id,toggleScreenShare:h}};export{s as useScreenShare};
@@ -0,0 +1 @@
1
+ import{__awaiter as i}from"../node_modules/tslib/tslib.es6.js";import{selectTrackByID as o}from"@100mslive/hms-video-store";import{useRef as r,useCallback as e,useEffect as t}from"react";import{useInView as d}from"react-intersection-observer";import{useHMSActions as n,useHMSStore as l}from"../primitives/HmsRoomProvider.js";import c from"../utils/logger.js";const s=({trackId:s,attach:v})=>{const m=n(),u=r(null),a=l(o(s)),{ref:f,inView:h}=d({threshold:.5}),p=e((i=>{i&&(u.current=i,f(i))}),[f]);return t((()=>{i(void 0,void 0,void 0,(function*(){u.current&&(null==a?void 0:a.id)&&(h&&a.enabled&&!1!==v?yield m.attachVideo(a.id,u.current):yield m.detachVideo(a.id,u.current))}))}),[m,h,u,null==a?void 0:a.id,null==a?void 0:a.enabled,null==a?void 0:a.deviceID,null==a?void 0:a.plugins,v]),t((()=>()=>{i(void 0,void 0,void 0,(function*(){if(u.current&&a)try{yield m.detachVideo(a.id,u.current)}catch(i){c.w("detach video error for track",a.id,i)}}))}),[]),{videoRef:p}};export{s as useVideo};
@@ -0,0 +1 @@
1
+ import{selectTracksMap as t}from"@100mslive/hms-video-store";import{useMemo as e}from"react";import{getVideoTracksFromPeers as i,getModeAspectRatio as r,calculateLayoutSizes as o,chunkElements as a}from"../utils/layout.js";import{useHMSVanillaStore as s}from"../primitives/HmsRoomProvider.js";import{useResizeDetector as h}from"react-resize-detector";const n={width:1,height:1},l=({peers:l,maxTileCount:m,maxColCount:g,maxRowCount:f,includeScreenShareForPeer:u=(()=>!1),aspectRatio:d=n,filterNonPublishingPeers:P=!0,offsetY:p=0})=>{const{width:c=0,height:C=0,ref:x}=h(),F=s().getState(t),H=i(l,F,u,P),W=e((()=>{if(d)return d;return{width:r(H)||1,height:1}}),[d,H]),w=H.length,{tilesInFirstPage:R,defaultWidth:v,defaultHeight:M,lastPageWidth:S,lastPageHeight:T,isLastPageDifferentFromFirstPage:j}=e((()=>o({count:w,parentWidth:Math.floor(c),parentHeight:Math.floor(C)-Math.min(C,p),maxTileCount:m,maxRowCount:f,maxColCount:g,aspectRatio:W})),[w,c,C,m,f,g,W,p]);return{pagesWithTiles:e((()=>a({elements:H,tilesInFirstPage:R,onlyOnePage:!1,isLastPageDifferentFromFirstPage:j,defaultWidth:v,defaultHeight:M,lastPageWidth:S,lastPageHeight:T})),[H,R,j,v,M,S,T]),ref:x}};export{l as useVideoList};
package/dist/index.cjs.js CHANGED
@@ -1 +1,16 @@
1
- var Je=Object.create;var G=Object.defineProperty,Ue=Object.defineProperties,_e=Object.getOwnPropertyDescriptor,Ke=Object.getOwnPropertyDescriptors,Qe=Object.getOwnPropertyNames,ie=Object.getOwnPropertySymbols,Xe=Object.getPrototypeOf,ne=Object.prototype.hasOwnProperty,Ye=Object.prototype.propertyIsEnumerable;var ae=(t,e,o)=>e in t?G(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o,q=(t,e)=>{for(var o in e||(e={}))ne.call(e,o)&&ae(t,o,e[o]);if(ie)for(var o of ie(e))Ye.call(e,o)&&ae(t,o,e[o]);return t},j=(t,e)=>Ue(t,Ke(e)),ce=t=>G(t,"__esModule",{value:!0});var Ze=(t,e)=>{ce(t);for(var o in e)G(t,o,{get:e[o],enumerable:!0})},H=(t,e,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Qe(e))!ne.call(t,s)&&s!=="default"&&G(t,s,{get:()=>e[s],enumerable:!(o=_e(e,s))||o.enumerable});return t},d=t=>H(ce(G(t!=null?Je(Xe(t)):{},"default",t&&t.__esModule&&"default"in t?{get:()=>t.default,enumerable:!0}:{value:t,enumerable:!0})),t);var g=(t,e,o)=>new Promise((s,r)=>{var i=c=>{try{a(o.next(c))}catch(u){r(u)}},n=c=>{try{a(o.throw(c))}catch(u){r(u)}},a=c=>c.done?s(c.value):Promise.resolve(c.value).then(i,n);a((o=o.apply(t,e)).next())});Ze(exports,{DeviceType:()=>R,HMSRoomProvider:()=>Se,throwErrorHandler:()=>he,useAVToggle:()=>ge,useAudioLevelStyles:()=>De,useAutoplayError:()=>Ge,useCustomEvent:()=>je,useDevices:()=>Oe,useHMSActions:()=>M,useHMSNotifications:()=>Q,useHMSStatsStore:()=>fe,useHMSStore:()=>l,useHMSVanillaNotifications:()=>K,useHMSVanillaStore:()=>O,useParticipantList:()=>Fe,usePreviewJoin:()=>pe,useRecordingStreaming:()=>Be,useRemoteAVToggle:()=>Pe,useScreenShare:()=>ke,useVideo:()=>ve,useVideoList:()=>Ae});var b=d(require("react")),de=d(require("@100mslive/hms-video-store")),J=d(require("zustand"));var Z=d(require("react")),$=d(require("zustand/shallow"));var k;(function(n){n[n.VERBOSE=0]="VERBOSE",n[n.DEBUG=1]="DEBUG",n[n.INFO=2]="INFO",n[n.WARN=3]="WARN",n[n.ERROR=4]="ERROR",n[n.NONE=5]="NONE"})(k||(k={}));var w=class{static v(e,...o){this.log(0,e,...o)}static d(e,...o){this.log(1,e,...o)}static i(e,...o){this.log(2,e,...o)}static w(e,...o){this.log(3,e,...o)}static e(e,...o){this.log(4,e,...o)}static log(e,o,...s){if(!(this.level.valueOf()>e.valueOf()))switch(e){case 0:{console.log("HMSui-components: ",o,...s);break}case 1:{console.debug("HMSui-components: ",o,...s);break}case 2:{console.info("HMSui-components: ",o,...s);break}case 3:{console.warn("HMSui-components: ",o,...s);break}case 4:{console.error("HMSui-components: ",o,...s);break}}}};w.level=0;var I="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.";function ue(t){return(o,s=$.default)=>{o||w.w("fetching full store without passing any selector may have a heavy performance impact on your website.");let r=(0,Z.useContext)(t);if(!r)throw new Error(I);return r.store(o,s)}}function le(t){return(o,s=$.default)=>{o||w.w("fetching full store without passing any selector may have a heavy performance impact on your website.");let r=(0,Z.useContext)(t);if(!r)throw new Error(I);let i=r.statsStore;return i==null?void 0:i(o,s)}}var me=typeof window!="undefined";var A=(0,b.createContext)(null),y,Se=({children:t,actions:e,store:o,notifications:s,stats:r,isHMSStatsOn:i=!1})=>{if(!y){let n=()=>{throw new Error("modifying store is not allowed")};if(e&&o)y={actions:e,store:(0,J.default)(j(q({},o),{setState:n,destroy:n}))},s&&(y.notifications=s),r&&(y.statsStore=(0,J.default)({getState:r.getState,subscribe:r.subscribe,setState:n,destroy:n}));else{let a=new de.HMSReactiveStore;if(y={actions:a.getActions(),store:(0,J.default)(j(q({},a.getStore()),{setState:n,destroy:n})),notifications:a.getNotifications()},i){let c=a.getStats();y.statsStore=(0,J.default)({getState:c.getState,subscribe:c.subscribe,setState:n,destroy:n})}}}return(0,b.useEffect)(()=>{me&&(window.addEventListener("beforeunload",()=>y.actions.leave()),window.addEventListener("onunload",()=>y.actions.leave()))},[]),b.default.createElement(A.Provider,{value:y},t)},l=ue(A),fe=le(A),O=()=>{let t=(0,b.useContext)(A);if(!t)throw new Error(I);return t.store},K=()=>{let t=(0,b.useContext)(A);if(!t)throw new Error(I);return t.notifications},M=()=>{let t=(0,b.useContext)(A);if(!t)throw new Error(I);return t.actions},Q=t=>{let e=(0,b.useContext)(A),[o,s]=(0,b.useState)(null);if(!e)throw new Error(I);return(0,b.useEffect)(()=>e.notifications?e.notifications.onNotification(i=>s(i),t):void 0,[e.notifications,t]),o};var V=d(require("@100mslive/hms-video-store")),U=d(require("react"));var $e="react-sdk",P=(t,e)=>w.e($e,e,t),he=t=>{throw t};var pe=({name:t="",token:e,metadata:o,handleError:s=P,initEndpoint:r,initialSettings:i,captureNetworkQualityInPreview:n})=>{let a=M(),c=l(V.selectRoomState),u=l(V.selectIsConnectedToRoom)||!1,p=c===V.HMSRoomState.Preview,m=(0,U.useMemo)(()=>({userName:t,authToken:e,metaData:o,rememberDeviceSelection:!0,settings:i,initEndpoint:r,captureNetworkQualityInPreview:n}),[t,e,o,r,i,n]),S=(0,U.useCallback)(()=>{(()=>g(void 0,null,function*(){if(!!e){c!==V.HMSRoomState.Disconnected&&(yield a.leave());try{yield a.preview(m)}catch(h){s(h,"preview")}}}))()},[a,s,e,c,m]),f=(0,U.useCallback)(()=>{if(!!e)try{a.join(m)}catch(h){s(h,"join")}},[a,m,s,e]);return{enableJoin:p,join:f,isConnected:u,preview:S}};var L=d(require("@100mslive/hms-video-store")),ee=d(require("react"));var ge=(t=P)=>{let e=l(L.selectIsLocalAudioEnabled),o=l(L.selectIsLocalVideoEnabled),s=l(L.selectIsAllowedToPublish),r=M(),i=(0,ee.useCallback)(()=>g(void 0,null,function*(){try{yield r.setLocalAudioEnabled(!e)}catch(a){t(a,"toggleAudio")}}),[r,e,t]),n=(0,ee.useCallback)(()=>g(void 0,null,function*(){try{yield r.setLocalVideoEnabled(!o)}catch(a){t(a,"toggleVideo")}}),[r,o,t]);return{isLocalAudioEnabled:e,isLocalVideoEnabled:o,toggleAudio:(s==null?void 0:s.audio)?i:void 0,toggleVideo:(s==null?void 0:s.video)?n:void 0}};var He=d(require("@100mslive/hms-video-store")),C=d(require("react")),Me=d(require("react-intersection-observer"));var ve=({trackId:t,attach:e})=>{let o=M(),s=(0,C.useRef)(null),r=l((0,He.selectTrackByID)(t)),{ref:i,inView:n}=(0,Me.useInView)({threshold:.5}),a=(0,C.useCallback)(c=>{c&&(s.current=c,i(c))},[i]);return(0,C.useEffect)(()=>{(()=>g(void 0,null,function*(){s.current&&(r==null?void 0:r.id)&&(n&&r.enabled&&e!==!1?yield o.attachVideo(r.id,s.current):yield o.detachVideo(r.id,s.current))}))()},[o,n,s,r==null?void 0:r.id,r==null?void 0:r.enabled,r==null?void 0:r.deviceID,r==null?void 0:r.plugins,e]),(0,C.useEffect)(()=>()=>{(()=>g(void 0,null,function*(){if(s.current&&r)try{yield o.detachVideo(r.id,s.current)}catch(c){w.w("detach video error for track",r.id,c)}}))()},[]),{videoRef:a}};var W=d(require("@100mslive/hms-video-store"));var be=d(require("react"));var ke=(t=P)=>{var n,a;let e=M(),o=l(W.selectIsLocalScreenShared),s=l(W.selectPeerScreenSharing),r=l((0,W.selectScreenSharesByPeerId)(s==null?void 0:s.id)),i=(0,be.useCallback)((c=!1)=>g(void 0,null,function*(){try{yield e.setScreenShareEnabled(!o,c)}catch(u){t(u,"toggleScreenShare")}}),[e,o,t]);return{amIScreenSharing:o,screenSharingPeerId:s==null?void 0:s.id,screenSharingPeerName:s==null?void 0:s.name,screenShareVideoTrackId:(n=r==null?void 0:r.video)==null?void 0:n.id,screenShareAudioTrackId:(a=r==null?void 0:r.audio)==null?void 0:a.id,toggleScreenShare:i}};var D=d(require("@100mslive/hms-video-store"));var X=d(require("react"));var Re=(t,e,o)=>g(void 0,null,function*(){if(e)try{yield t.setRemoteTrackEnabled(e.id,!e.enabled)}catch(s){o(s,"remoteToggle")}}),Pe=(t,e,o=P)=>{let s=M(),r=l((0,D.selectTrackByID)(t)),i=l((0,D.selectTrackByID)(e)),n=l((0,D.selectAudioTrackVolume)(r==null?void 0:r.id)),a=l(D.selectPermissions),c=(i==null?void 0:i.enabled)?a==null?void 0:a.mute:a==null?void 0:a.unmute,u=(r==null?void 0:r.enabled)?a==null?void 0:a.mute:a==null?void 0:a.unmute,p=(0,X.useCallback)(()=>g(void 0,null,function*(){yield Re(s,r,o)}),[s,r,o]),m=(0,X.useCallback)(()=>g(void 0,null,function*(){yield Re(s,i,o)}),[s,o,i]),S=(0,X.useCallback)(f=>{r&&s.setVolume(f,r.id)},[s,r]);return{isAudioEnabled:!!(r==null?void 0:r.enabled),isVideoEnabled:!!(i==null?void 0:i.enabled),volume:n,toggleAudio:r&&u?p:void 0,toggleVideo:(i==null?void 0:i.source)==="regular"&&c?m:void 0,setVolume:r?S:void 0}};var Ee=d(require("@100mslive/hms-video-store")),Y=d(require("react"));var et=(t,e,o)=>t.reduce((s,r,i)=>{let n=Math.floor(i/e);return n>0&&o||(s[n]||(s[n]=[]),s[n].push(r)),s},[]),we=({elements:t,tilesInFirstPage:e,onlyOnePage:o,isLastPageDifferentFromFirstPage:s,defaultWidth:r,defaultHeight:i,lastPageWidth:n,lastPageHeight:a})=>{let c=et(t,e,o);return c.map((u,p)=>u.map(m=>{let S=p===c.length-1,f=s&&S?n:r,h=s&&S?a:i;return j(q({},m),{height:h,width:f})}))};function tt(t){if(t.length===0)return null;let e={},o=t[0],s=1;for(let r=0;r<t.length;r++){let i=t[r];e[i]===null?e[i]=1:e[i]++,e[i]>s&&(o=i,s=e[i])}return o}var Te=t=>tt(t.filter(e=>{var o,s;return((o=e.track)==null?void 0:o.width)&&((s=e.track)==null?void 0:s.height)}).map(e=>{var r,i;let o=(r=e.track)==null?void 0:r.width,s=(i=e.track)==null?void 0:i.height;return(o||1)/(s||1)})),te=(t,e,o,s,r)=>{if(t<0||e<0)throw new Error("Container must have a non-negative area");if(o<1||!Number.isInteger(o))throw new Error("Number of shapes to place must be a positive integer");let i=s&&r&&s/r;if(i!==void 0&&isNaN(i))throw new Error("Aspect ratio must be a number");let n={area:0,cols:0,rows:0,width:0,height:0},a=o,c=-1;if(i!==void 0)for(let u=a;u>0;u+=c){let p=Math.ceil(o/u),m=t/(u*i),S=e/p,f,h;m<=S?(f=t/u,h=f/i):(h=e/p,f=h*i);let v=f*h;v>n.area&&(n={area:v,width:f,height:h,rows:p,cols:u})}return n},ot=({parentWidth:t,parentHeight:e,count:o,maxCount:s,aspectRatio:r})=>{let i=0,n=0,a=0,c=0,u=!1,p=0,m=0,S=Math.min(Math.ceil(Math.sqrt(o*(t/e)/(r.width/r.height))),s),f=t/S,h=f/(r.width/r.height);h>e&&(h=e,f=h/(r.height/r.width));let v=Math.floor(e/h);if(n=h,i=f,p=Math.min(o,v*S),m=o%(v*S),u=m>0&&o>v*S,u){let N=Math.min(Math.ceil(Math.sqrt(m*(t/e)/(r.width/r.height))),s),T=t/N,x=T/(r.width/r.height);x>e&&(x=e,T=x/(r.height/r.width)),c=x,a=T}return{tilesInFirstPage:p,defaultWidth:i,defaultHeight:n,lastPageWidth:a,lastPageHeight:c,isLastPageDifferentFromFirstPage:u}},rt=({parentWidth:t,parentHeight:e,count:o,maxCount:s,aspectRatio:r})=>{let i=0,n=0,a=0,c=0,u=!1,p=0,m=0,{width:S,height:f}=te(t,e,Math.min(o,s),r.width,r.height);if(i=S,n=f,p=Math.min(o,s),m=o%s,u=m>0&&o>s,u){let{width:h,height:v}=te(t,e,m,r.width,r.height);a=h,c=v}return{tilesInFirstPage:p,defaultWidth:i,defaultHeight:n,lastPageWidth:a,lastPageHeight:c,isLastPageDifferentFromFirstPage:u}},st=({parentWidth:t,parentHeight:e,count:o,maxCount:s,aspectRatio:r})=>{let i=0,n=0,a=0,c=0,u=!1,p=0,m=0,S=Math.min(Math.ceil(Math.sqrt(o*(r.width/r.height)/(t/e))),s),f=e/S,h=f*(r.width/r.height),v=Math.floor(t/h);if(i=h,n=f,p=Math.min(o,S*v),m=o%(S*v),u=m>0&&o>S*v,u){let N=Math.min(Math.ceil(Math.sqrt(m*(r.width/r.height)/(t/e))),s),T=e/N,x=T*(r.width/r.height);c=T,a=x}return{tilesInFirstPage:p,defaultWidth:i,defaultHeight:n,lastPageWidth:a,lastPageHeight:c,isLastPageDifferentFromFirstPage:u}};function xe({count:t,parentWidth:e,parentHeight:o,maxTileCount:s,maxRowCount:r,maxColCount:i,aspectRatio:n}){let a=0,c=0,u=0,p=0,m=!1,S=0;if(t===0)return{tilesInFirstPage:S,defaultWidth:a,defaultHeight:c,lastPageWidth:u,lastPageHeight:p,isLastPageDifferentFromFirstPage:m};if(s)({tilesInFirstPage:S,defaultWidth:a,defaultHeight:c,lastPageWidth:u,lastPageHeight:p,isLastPageDifferentFromFirstPage:m}=rt({parentWidth:e,parentHeight:o,count:t,maxCount:s,aspectRatio:n}));else if(r)({tilesInFirstPage:S,defaultWidth:a,defaultHeight:c,lastPageWidth:u,lastPageHeight:p,isLastPageDifferentFromFirstPage:m}=st({parentWidth:e,parentHeight:o,count:t,maxCount:r,aspectRatio:n}));else if(i)({tilesInFirstPage:S,defaultWidth:a,defaultHeight:c,lastPageWidth:u,lastPageHeight:p,isLastPageDifferentFromFirstPage:m}=ot({parentWidth:e,parentHeight:o,count:t,maxCount:i,aspectRatio:n}));else{let{width:f,height:h}=te(e,o,t,n.width,n.height);a=f,c=h,S=t}return{tilesInFirstPage:S,defaultWidth:a,defaultHeight:c,lastPageWidth:u,lastPageHeight:p,isLastPageDifferentFromFirstPage:m}}var ye=(t,e,o,s=!0)=>{if(!t||!e||!o)return[];let r=[];for(let i of t)if(i.videoTrack===void 0&&i.audioTrack&&e[i.audioTrack]?r.push({peer:i}):i.videoTrack&&e[i.videoTrack]?r.push({track:e[i.videoTrack],peer:i}):s||r.push({peer:i}),o(i)&&i.auxiliaryTracks.length>0){let a=i.auxiliaryTracks.find(c=>{let u=e[c];return(u==null?void 0:u.type)==="video"&&(u==null?void 0:u.source)==="screen"});a&&r.push({track:e[a],peer:i})}return r};var Ie=d(require("react-resize-detector")),it={aspectRatio:{width:1,height:1}},Ae=({peers:t,maxTileCount:e,maxColCount:o,maxRowCount:s,includeScreenShareForPeer:r=()=>!1,aspectRatio:i=it.aspectRatio,filterNonPublishingPeers:n=!0,offsetY:a=0})=>{let{width:c=0,height:u=0,ref:p}=(0,Ie.useResizeDetector)(),S=O().getState(Ee.selectTracksMap),f=ye(t,S,r,n),h=(0,Y.useMemo)(()=>i||{width:Te(f)||1,height:1},[i,f]),v=f.length,{tilesInFirstPage:N,defaultWidth:T,defaultHeight:x,lastPageWidth:oe,lastPageHeight:re,isLastPageDifferentFromFirstPage:se}=(0,Y.useMemo)(()=>xe({count:v,parentWidth:Math.floor(c),parentHeight:Math.floor(u)-Math.min(u,a),maxTileCount:e,maxRowCount:s,maxColCount:o,aspectRatio:h}),[v,c,u,e,s,o,h,a]);return{pagesWithTiles:(0,Y.useMemo)(()=>we({elements:f,tilesInFirstPage:N,onlyOnePage:!1,isLastPageDifferentFromFirstPage:se,defaultWidth:T,defaultHeight:x,lastPageWidth:oe,lastPageHeight:re}),[f,N,se,T,x,oe,re]),ref:p}};var Ve=d(require("react")),Ce=d(require("@100mslive/hms-video-store"));function De({trackId:t,getStyle:e,ref:o}){let s=O();(0,Ve.useEffect)(()=>s.subscribe(r=>{if(!o.current)return;let i=e(r);for(let n in i)o.current.style[n]=i[n]},(0,Ce.selectTrackAudioByID)(t)),[e,o,s,t])}var F=d(require("@100mslive/hms-video-store")),Ne=d(require("react"));var R;(function(s){s.videoInput="videoInput",s.audioInput="audioInput",s.audioOutput="audioOutput"})(R||(R={}));var Oe=(t=P)=>{let e=M(),o=l(F.selectDevices),s=l(F.selectLocalMediaSettings),r=l(F.selectIsAllowedToPublish),i={[R.audioOutput]:s.audioOutputDeviceId},n={[R.audioOutput]:o.audioOutput};r.video&&(n[R.videoInput]=o.videoInput,i[R.videoInput]=s.videoInputDeviceId),r.audio&&(n[R.audioInput]=o.audioInput,i[R.audioInput]=s.audioInputDeviceId);let a=(0,Ne.useCallback)(p=>g(void 0,[p],function*({deviceType:c,deviceId:u}){try{switch(c){case R.audioInput:yield e.setAudioSettings({deviceId:u});break;case R.videoInput:yield e.setVideoSettings({deviceId:u});break;case R.audioOutput:e.setAudioOutputDevice(u);break}}catch(m){t(m,"updateDevices")}}),[t,e]);return{allDevices:n,selectedDeviceIDs:i,updateDevice:a}};var We=d(require("react")),E=d(require("@100mslive/hms-video-store"));var Le=t=>!t||!Array.isArray(t)||t.length===0?{}:t.reduce((e,o)=>(o.roleName&&(e[o.roleName]||(e[o.roleName]=[]),e[o.roleName].push(o)),e),{});var Fe=()=>{let t=l(E.selectIsConnectedToRoom),e=l(t?E.selectPeers:E.selectRemotePeers),o=l(E.selectPeerCount),s=(0,We.useMemo)(()=>Le(e),[e]);return{roles:Object.keys(s),participantsByRoles:s,peerCount:o,isConnected:t}};var B=d(require("@100mslive/hms-video-store"));var Be=()=>{let t=l(B.selectRecordingState),e=l(B.selectRTMPState),o=l(B.selectHLSState),s=t.server.running,r=t.browser.running,i=t.hls.running,n=o.running||e.running,a=s||r||i;return{isServerRecordingOn:s,isBrowserRecordingOn:r,isHLSRecordingOn:i,isStreamingOn:n,isHLSRunning:o.running,isRTMPRunning:e.running,isRecordingOn:a}};var z=d(require("react")),ze=d(require("@100mslive/hms-video-store"));var Ge=()=>{let t=Q(ze.HMSNotificationTypes.ERROR),[e,o]=(0,z.useState)(""),s=M(),r=(0,z.useCallback)(()=>g(void 0,null,function*(){yield s.unblockAudio()}),[s]);return(0,z.useEffect)(()=>{(t==null?void 0:t.data.code)===3008&&o(t==null?void 0:t.data.message)},[t]),{error:e,unblockAudio:r,resetError:()=>o("")}};var _=d(require("react")),qe=d(require("@100mslive/hms-video-store"));var je=({type:t,onEvent:e,handleError:o=P})=>{let s=M(),r=K();return(0,_.useEffect)(()=>{s.ignoreMessageTypes([t])},[s,t]),(0,_.useEffect)(()=>r?r.onNotification(a=>{let c=a.data;if(c&&c.type===t)try{let u=JSON.parse(c.message);e==null||e(u)}catch(u){o(u,"handleCustomEvent")}},qe.HMSNotificationTypes.NEW_MESSAGE):void 0,[r,t,e,o]),{sendEvent:(0,_.useCallback)(n=>g(void 0,null,function*(){try{let a=JSON.stringify(n||"");yield s.sendBroadcastMessage(a,t),e==null||e(n)}catch(a){o(a,"sendCustomEvent")}}),[s,o,e,t])}};H(exports,d(require("@100mslive/hms-video-store")));
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("@100mslive/hms-video-store"),i=require("zustand"),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,u=r(e),l=r(i);function c(e,t){if(Object.is(e,t))return!0;if("object"!=typeof e||null===e||"object"!=typeof t||null===t)return!1;const 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 d{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)}}}d.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,f=e.createContext(null);let v;const p=(m=f,(t,i=c)=>{t||d.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=c)=>{i||d.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)}}(f),w=()=>{const t=e.useContext(f);if(!t)throw new Error(h);return t.store},S=()=>{const t=e.useContext(f);if(!t)throw new Error(h);return t.notifications},P=()=>{const t=e.useContext(f);if(!t)throw new Error(h);return t.actions},b=t=>{const i=e.useContext(f),[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};
2
+ /*! *****************************************************************************
3
+ Copyright (c) Microsoft Corporation.
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
9
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
11
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14
+ PERFORMANCE OF THIS SOFTWARE.
15
+ ***************************************************************************** */
16
+ function E(e,t,i,o){return new(i||(i=Promise))((function(n,r){function a(e){try{u(o.next(e))}catch(e){r(e)}}function s(e){try{u(o.throw(e))}catch(e){r(e)}}function u(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,s)}u((o=o.apply(e,t||[])).next())}))}const x=(e,t)=>d.e("react-sdk",t,e),R=(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")}})),I=({elements:e,tilesInFirstPage:t,onlyOnePage:i,isLastPageDifferentFromFirstPage:o,defaultWidth:n,defaultHeight:r,lastPageWidth:a,lastPageHeight:s})=>{const u=((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 u.map(((e,t)=>e.map((e=>{const i=t===u.length-1,l=o&&i?a:n,c=o&&i?s:r;return Object.assign(Object.assign({},e),{height:c,width:l})}))))};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,u;e/(o*r)<=t/n?(s=e/o,u=s/r):(u=t/n,s=u*r);const l=s*u;l>a.area&&(a={area:l,width:s,height:u,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,u=0,l=0,c=0,d=!1,h=0;if(0===e)return{tilesInFirstPage:h,defaultWidth:s,defaultHeight:u,lastPageWidth:l,lastPageHeight:c,isLastPageDifferentFromFirstPage:d};if(o)({tilesInFirstPage:h,defaultWidth:s,defaultHeight:u,lastPageWidth:l,lastPageHeight:c,isLastPageDifferentFromFirstPage:d}=(({parentWidth:e,parentHeight:t,count:i,maxCount:o,aspectRatio:n})=>{let r=0,a=0,s=0,u=0,l=!1,c=0,d=0;const{width:h,height:g}=k(e,t,Math.min(i,o),n.width,n.height);if(r=h,a=g,c=Math.min(i,o),d=i%o,l=d>0&&i>o,l){const{width:i,height:o}=k(e,t,d,n.width,n.height);s=i,u=o}return{tilesInFirstPage:c,defaultWidth:r,defaultHeight:a,lastPageWidth:s,lastPageHeight:u,isLastPageDifferentFromFirstPage:l}})({parentWidth:t,parentHeight:i,count:e,maxCount:o,aspectRatio:a}));else if(n)({tilesInFirstPage:h,defaultWidth:s,defaultHeight:u,lastPageWidth:l,lastPageHeight:c,isLastPageDifferentFromFirstPage:d}=(({parentWidth:e,parentHeight:t,count:i,maxCount:o,aspectRatio:n})=>{let r=0,a=0,s=0,u=0,l=!1,c=0,d=0;const h=Math.min(Math.ceil(Math.sqrt(i*(n.width/n.height)/(e/t))),o),g=t/h,f=g*(n.width/n.height),v=Math.floor(e/f);if(r=f,a=g,c=Math.min(i,h*v),d=i%(h*v),l=d>0&&i>h*v,l){const i=t/Math.min(Math.ceil(Math.sqrt(d*(n.width/n.height)/(e/t))),o);u=i,s=i*(n.width/n.height)}return{tilesInFirstPage:c,defaultWidth:r,defaultHeight:a,lastPageWidth:s,lastPageHeight:u,isLastPageDifferentFromFirstPage:l}})({parentWidth:t,parentHeight:i,count:e,maxCount:n,aspectRatio:a}));else if(r)({tilesInFirstPage:h,defaultWidth:s,defaultHeight:u,lastPageWidth:l,lastPageHeight:c,isLastPageDifferentFromFirstPage:d}=(({parentWidth:e,parentHeight:t,count:i,maxCount:o,aspectRatio:n})=>{let r=0,a=0,s=0,u=0,l=!1,c=0,d=0;const h=Math.min(Math.ceil(Math.sqrt(i*(e/t)/(n.width/n.height))),o);let g=e/h,f=g/(n.width/n.height);f>t&&(f=t,g=f/(n.height/n.width));const v=Math.floor(t/f);if(a=f,r=g,c=Math.min(i,v*h),d=i%(v*h),l=d>0&&i>v*h,l){let i=e/Math.min(Math.ceil(Math.sqrt(d*(e/t)/(n.width/n.height))),o),r=i/(n.width/n.height);r>t&&(r=t,i=r/(n.height/n.width)),u=r,s=i}return{tilesInFirstPage:c,defaultWidth:r,defaultHeight:a,lastPageWidth:s,lastPageHeight:u,isLastPageDifferentFromFirstPage:l}})({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,u=n,h=e}return{tilesInFirstPage:h,defaultWidth:s,defaultHeight:u,lastPageWidth:l,lastPageHeight:c,isLastPageDifferentFromFirstPage:d}}const H={width:1,height:1};var O;exports.DeviceType=void 0,(O=exports.DeviceType||(exports.DeviceType={})).videoInput="videoInput",O.audioInput="audioInput",O.audioOutput="audioOutput";exports.HMSRoomProvider=({children:i,actions:o,store:n,notifications:r,stats:a,isHMSStatsOn:s=!1})=>{if(!v){const e=()=>{throw new Error("modifying store is not allowed")};if(o&&n)v={actions:o,store:l.default(Object.assign(Object.assign({},n),{setState:e,destroy:e}))},r&&(v.notifications=r),a&&(v.statsStore=l.default({getState:a.getState,subscribe:a.subscribe,setState:e,destroy:e}));else{const i=new t.HMSReactiveStore;if(v={actions:i.getActions(),store:l.default(Object.assign(Object.assign({},i.getStore()),{setState:e,destroy:e})),notifications:i.getNotifications()},s){const t=i.getStats();v.statsStore=l.default({getState:t.getState,subscribe:t.subscribe,setState:e,destroy:e})}}}return e.useEffect((()=>{g&&(window.addEventListener("beforeunload",(()=>v.actions.leave())),window.addEventListener("onunload",(()=>v.actions.leave())))}),[]),u.default.createElement(f.Provider,{value:v},i)},exports.throwErrorHandler=e=>{throw e},exports.useAVToggle=(i=x)=>{const o=p(t.selectIsLocalAudioEnabled),n=p(t.selectIsLocalVideoEnabled),r=p(t.selectIsAllowedToPublish),a=P(),s=e.useCallback((()=>E(void 0,void 0,void 0,(function*(){try{yield a.setLocalAudioEnabled(!o)}catch(e){i(e,"toggleAudio")}}))),[a,o,i]),u=e.useCallback((()=>E(void 0,void 0,void 0,(function*(){try{yield a.setLocalVideoEnabled(!n)}catch(e){i(e,"toggleVideo")}}))),[a,n,i]);return{isLocalAudioEnabled:o,isLocalVideoEnabled:n,toggleAudio:(null==r?void 0:r.audio)?s:void 0,toggleVideo:(null==r?void 0:r.video)?u:void 0}},exports.useAudioLevelStyles=function({trackId:i,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]}),t.selectTrackAudioByID(i))),[o,n,r,i])},exports.useAutoplayError=()=>{const i=b(t.HMSNotificationTypes.ERROR),[o,n]=e.useState(""),r=P(),a=e.useCallback((()=>E(void 0,void 0,void 0,(function*(){yield r.unblockAudio()}))),[r]);return e.useEffect((()=>{3008===(null==i?void 0:i.data.code)&&n(null==i?void 0:i.data.message)}),[i]),{error:o,unblockAudio:a,resetError:()=>n("")}},exports.useCustomEvent=({type:i,onEvent:o,handleError:n=x})=>{const r=P(),a=S();e.useEffect((()=>{r.ignoreMessageTypes([i])}),[r,i]),e.useEffect((()=>{if(!a)return;return a.onNotification((e=>{const t=e.data;if(t&&t.type===i)try{const e=JSON.parse(t.message);null==o||o(e)}catch(e){n(e,"handleCustomEvent")}}),t.HMSNotificationTypes.NEW_MESSAGE)}),[a,i,o,n]);return{sendEvent:e.useCallback((e=>E(void 0,void 0,void 0,(function*(){try{const t=JSON.stringify(e||"");yield r.sendBroadcastMessage(t,i),null==o||o(e)}catch(e){n(e,"sendCustomEvent")}}))),[r,n,o,i])}},exports.useDevices=(i=x)=>{const o=P(),n=p(t.selectDevices),r=p(t.selectLocalMediaSettings),a=p(t.selectIsAllowedToPublish),s={[exports.DeviceType.audioOutput]:r.audioOutputDeviceId},u={[exports.DeviceType.audioOutput]:n.audioOutput};a.video&&(u[exports.DeviceType.videoInput]=n.videoInput,s[exports.DeviceType.videoInput]=r.videoInputDeviceId),a.audio&&(u[exports.DeviceType.audioInput]=n.audioInput,s[exports.DeviceType.audioInput]=r.audioInputDeviceId);return{allDevices:u,selectedDeviceIDs:s,updateDevice:e.useCallback((({deviceType:e,deviceId:t})=>E(void 0,void 0,void 0,(function*(){try{switch(e){case exports.DeviceType.audioInput:yield o.setAudioSettings({deviceId:t});break;case exports.DeviceType.videoInput:yield o.setVideoSettings({deviceId:t});break;case exports.DeviceType.audioOutput:o.setAudioOutputDevice(t)}}catch(e){i(e,"updateDevices")}}))),[i,o])}},exports.useHMSActions=P,exports.useHMSNotifications=b,exports.useHMSStatsStore=y,exports.useHMSStore=p,exports.useHMSVanillaNotifications=S,exports.useHMSVanillaStore=w,exports.useParticipantList=()=>{const i=p(t.selectIsConnectedToRoom),o=p(i?t.selectPeers:t.selectRemotePeers),n=p(t.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:i}},exports.usePreviewJoin=({name:i="",token:o,metadata:n,handleError:r=x,initEndpoint:a,initialSettings:s,captureNetworkQualityInPreview:u})=>{const l=P(),c=p(t.selectRoomState),d=p(t.selectIsConnectedToRoom)||!1,h=c===t.HMSRoomState.Preview,g=e.useMemo((()=>({userName:i,authToken:o,metaData:n,rememberDeviceSelection:!0,settings:s,initEndpoint:a,captureNetworkQualityInPreview:u})),[i,o,n,a,s,u]),f=e.useCallback((()=>{E(void 0,void 0,void 0,(function*(){if(o){c!==t.HMSRoomState.Disconnected&&(yield l.leave());try{yield l.preview(g)}catch(e){r(e,"preview")}}}))}),[l,r,o,c,g]);return{enableJoin:h,join:e.useCallback((()=>{if(o)try{l.join(g)}catch(e){r(e,"join")}}),[l,g,r,o]),isConnected:d,preview:f}},exports.useRecordingStreaming=()=>{const e=p(t.selectRecordingState),i=p(t.selectRTMPState),o=p(t.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||i.running,isHLSRunning:o.running,isRTMPRunning:i.running,isRecordingOn:s}},exports.useRemoteAVToggle=(i,o,n=x)=>{const r=P(),a=p(t.selectTrackByID(i)),s=p(t.selectTrackByID(o)),u=p(t.selectAudioTrackVolume(null==a?void 0:a.id)),l=p(t.selectPermissions),c=(null==s?void 0:s.enabled)?null==l?void 0:l.mute:null==l?void 0:l.unmute,d=(null==a?void 0:a.enabled)?null==l?void 0:l.mute:null==l?void 0:l.unmute,h=e.useCallback((()=>E(void 0,void 0,void 0,(function*(){yield R(r,a,n)}))),[r,a,n]),g=e.useCallback((()=>E(void 0,void 0,void 0,(function*(){yield R(r,s,n)}))),[r,n,s]),f=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:u,toggleAudio:a&&d?h:void 0,toggleVideo:"regular"===(null==s?void 0:s.source)&&c?g:void 0,setVolume:a?f:void 0}},exports.useScreenShare=(i=x)=>{var o,n;const r=P(),a=p(t.selectIsLocalScreenShared),s=p(t.selectPeerScreenSharing),u=p(t.selectScreenSharesByPeerId(null==s?void 0:s.id)),l=e.useCallback(((e=!1)=>E(void 0,void 0,void 0,(function*(){try{yield r.setScreenShareEnabled(!a,e)}catch(e){i(e,"toggleScreenShare")}}))),[r,a,i]);return{amIScreenSharing:a,screenSharingPeerId:null==s?void 0:s.id,screenSharingPeerName:null==s?void 0:s.name,screenShareVideoTrackId:null===(o=null==u?void 0:u.video)||void 0===o?void 0:o.id,screenShareAudioTrackId:null===(n=null==u?void 0:u.audio)||void 0===n?void 0:n.id,toggleScreenShare:l}},exports.useVideo=({trackId:i,attach:n})=>{const r=P(),a=e.useRef(null),s=p(t.selectTrackByID(i)),{ref:u,inView:l}=o.useInView({threshold:.5}),c=e.useCallback((e=>{e&&(a.current=e,u(e))}),[u]);return e.useEffect((()=>{E(void 0,void 0,void 0,(function*(){a.current&&(null==s?void 0:s.id)&&(l&&s.enabled&&!1!==n?yield r.attachVideo(s.id,a.current):yield r.detachVideo(s.id,a.current))}))}),[r,l,a,null==s?void 0:s.id,null==s?void 0:s.enabled,null==s?void 0:s.deviceID,null==s?void 0:s.plugins,n]),e.useEffect((()=>()=>{E(void 0,void 0,void 0,(function*(){if(a.current&&s)try{yield r.detachVideo(s.id,a.current)}catch(e){d.w("detach video error for track",s.id,e)}}))}),[]),{videoRef:c}},exports.useVideoList=({peers:i,maxTileCount:o,maxColCount:r,maxRowCount:a,includeScreenShareForPeer:s=(()=>!1),aspectRatio:u=H,filterNonPublishingPeers:l=!0,offsetY:c=0})=>{const{width:d=0,height:h=0,ref:g}=n.useResizeDetector(),f=((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}),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})(i,w().getState(t.selectTracksMap),s,l),v=e.useMemo((()=>{if(u)return u;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}(f.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}}),[u,f]),p=f.length,{tilesInFirstPage:m,defaultWidth:y,defaultHeight:S,lastPageWidth:P,lastPageHeight:b,isLastPageDifferentFromFirstPage:E}=e.useMemo((()=>M({count:p,parentWidth:Math.floor(d),parentHeight:Math.floor(h)-Math.min(h,c),maxTileCount:o,maxRowCount:a,maxColCount:r,aspectRatio:v})),[p,d,h,o,a,r,v,c]);return{pagesWithTiles:e.useMemo((()=>I({elements:f,tilesInFirstPage:m,onlyOnePage:!1,isLastPageDifferentFromFirstPage:E,defaultWidth:y,defaultHeight:S,lastPageWidth:P,lastPageHeight:b})),[f,m,E,y,S,P,b]),ref:g}},Object.keys(t).forEach((function(e){"default"===e||exports.hasOwnProperty(e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return t[e]}})}));
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- var ce=Object.defineProperty,ue=Object.defineProperties;var le=Object.getOwnPropertyDescriptors;var G=Object.getOwnPropertySymbols;var me=Object.prototype.hasOwnProperty,de=Object.prototype.propertyIsEnumerable;var q=(r,e,t)=>e in r?ce(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,E=(r,e)=>{for(var t in e||(e={}))me.call(e,t)&&q(r,t,e[t]);if(G)for(var t of G(e))de.call(e,t)&&q(r,t,e[t]);return r},I=(r,e)=>ue(r,le(e));var p=(r,e,t)=>new Promise((s,o)=>{var i=c=>{try{a(t.next(c))}catch(u){o(u)}},n=c=>{try{a(t.throw(c))}catch(u){o(u)}},a=c=>c.done?s(c.value):Promise.resolve(c.value).then(i,n);a((t=t.apply(r,e)).next())});import Se,{createContext as fe,useContext as V,useEffect as Q,useState as he}from"react";import{HMSReactiveStore as pe}from"@100mslive/hms-video-store";import C from"zustand";import{useContext as j}from"react";import J from"zustand/shallow";var M;(function(n){n[n.VERBOSE=0]="VERBOSE",n[n.DEBUG=1]="DEBUG",n[n.INFO=2]="INFO",n[n.WARN=3]="WARN",n[n.ERROR=4]="ERROR",n[n.NONE=5]="NONE"})(M||(M={}));var k=class{static v(e,...t){this.log(0,e,...t)}static d(e,...t){this.log(1,e,...t)}static i(e,...t){this.log(2,e,...t)}static w(e,...t){this.log(3,e,...t)}static e(e,...t){this.log(4,e,...t)}static log(e,t,...s){if(!(this.level.valueOf()>e.valueOf()))switch(e){case 0:{console.log("HMSui-components: ",t,...s);break}case 1:{console.debug("HMSui-components: ",t,...s);break}case 2:{console.info("HMSui-components: ",t,...s);break}case 3:{console.warn("HMSui-components: ",t,...s);break}case 4:{console.error("HMSui-components: ",t,...s);break}}}};k.level=0;var T="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.";function U(r){return(t,s=J)=>{t||k.w("fetching full store without passing any selector may have a heavy performance impact on your website.");let o=j(r);if(!o)throw new Error(T);return o.store(t,s)}}function _(r){return(t,s=J)=>{t||k.w("fetching full store without passing any selector may have a heavy performance impact on your website.");let o=j(r);if(!o)throw new Error(T);let i=o.statsStore;return i==null?void 0:i(t,s)}}var K=typeof window!="undefined";var x=fe(null),w,ge=({children:r,actions:e,store:t,notifications:s,stats:o,isHMSStatsOn:i=!1})=>{if(!w){let n=()=>{throw new Error("modifying store is not allowed")};if(e&&t)w={actions:e,store:C(I(E({},t),{setState:n,destroy:n}))},s&&(w.notifications=s),o&&(w.statsStore=C({getState:o.getState,subscribe:o.subscribe,setState:n,destroy:n}));else{let a=new pe;if(w={actions:a.getActions(),store:C(I(E({},a.getStore()),{setState:n,destroy:n})),notifications:a.getNotifications()},i){let c=a.getStats();w.statsStore=C({getState:c.getState,subscribe:c.subscribe,setState:n,destroy:n})}}}return Q(()=>{K&&(window.addEventListener("beforeunload",()=>w.actions.leave()),window.addEventListener("onunload",()=>w.actions.leave()))},[]),Se.createElement(x.Provider,{value:w},r)},m=U(x),He=_(x),A=()=>{let r=V(x);if(!r)throw new Error(T);return r.store},D=()=>{let r=V(x);if(!r)throw new Error(T);return r.notifications},g=()=>{let r=V(x);if(!r)throw new Error(T);return r.actions},N=r=>{let e=V(x),[t,s]=he(null);if(!e)throw new Error(T);return Q(()=>e.notifications?e.notifications.onNotification(i=>s(i),r):void 0,[e.notifications,r]),t};import{HMSRoomState as X,selectIsConnectedToRoom as be,selectRoomState as ke}from"@100mslive/hms-video-store";import{useCallback as Y,useMemo as Re}from"react";var Me="react-sdk",v=(r,e)=>k.e(Me,e,r),ve=r=>{throw r};var Pe=({name:r="",token:e,metadata:t,handleError:s=v,initEndpoint:o,initialSettings:i,captureNetworkQualityInPreview:n})=>{let a=g(),c=m(ke),u=m(be)||!1,h=c===X.Preview,l=Re(()=>({userName:r,authToken:e,metaData:t,rememberDeviceSelection:!0,settings:i,initEndpoint:o,captureNetworkQualityInPreview:n}),[r,e,t,o,i,n]),d=Y(()=>{(()=>p(void 0,null,function*(){if(!!e){c!==X.Disconnected&&(yield a.leave());try{yield a.preview(l)}catch(f){s(f,"preview")}}}))()},[a,s,e,c,l]),S=Y(()=>{if(!!e)try{a.join(l)}catch(f){s(f,"join")}},[a,l,s,e]);return{enableJoin:h,join:S,isConnected:u,preview:d}};import{selectIsAllowedToPublish as we,selectIsLocalAudioEnabled as Te,selectIsLocalVideoEnabled as xe}from"@100mslive/hms-video-store";import{useCallback as Z}from"react";var ye=(r=v)=>{let e=m(Te),t=m(xe),s=m(we),o=g(),i=Z(()=>p(void 0,null,function*(){try{yield o.setLocalAudioEnabled(!e)}catch(a){r(a,"toggleAudio")}}),[o,e,r]),n=Z(()=>p(void 0,null,function*(){try{yield o.setLocalVideoEnabled(!t)}catch(a){r(a,"toggleVideo")}}),[o,t,r]);return{isLocalAudioEnabled:e,isLocalVideoEnabled:t,toggleAudio:(s==null?void 0:s.audio)?i:void 0,toggleVideo:(s==null?void 0:s.video)?n:void 0}};import{selectTrackByID as Ee}from"@100mslive/hms-video-store";import{useCallback as Ie,useEffect as $,useRef as Ae}from"react";import{useInView as Ve}from"react-intersection-observer";var Ce=({trackId:r,attach:e})=>{let t=g(),s=Ae(null),o=m(Ee(r)),{ref:i,inView:n}=Ve({threshold:.5}),a=Ie(c=>{c&&(s.current=c,i(c))},[i]);return $(()=>{(()=>p(void 0,null,function*(){s.current&&(o==null?void 0:o.id)&&(n&&o.enabled&&e!==!1?yield t.attachVideo(o.id,s.current):yield t.detachVideo(o.id,s.current))}))()},[t,n,s,o==null?void 0:o.id,o==null?void 0:o.enabled,o==null?void 0:o.deviceID,o==null?void 0:o.plugins,e]),$(()=>()=>{(()=>p(void 0,null,function*(){if(s.current&&o)try{yield t.detachVideo(o.id,s.current)}catch(c){k.w("detach video error for track",o.id,c)}}))()},[]),{videoRef:a}};import{selectIsLocalScreenShared as De,selectPeerScreenSharing as Ne,selectScreenSharesByPeerId as Oe}from"@100mslive/hms-video-store";import{useCallback as Le}from"react";var We=(r=v)=>{var n,a;let e=g(),t=m(De),s=m(Ne),o=m(Oe(s==null?void 0:s.id)),i=Le((c=!1)=>p(void 0,null,function*(){try{yield e.setScreenShareEnabled(!t,c)}catch(u){r(u,"toggleScreenShare")}}),[e,t,r]);return{amIScreenSharing:t,screenSharingPeerId:s==null?void 0:s.id,screenSharingPeerName:s==null?void 0:s.name,screenShareVideoTrackId:(n=o==null?void 0:o.video)==null?void 0:n.id,screenShareAudioTrackId:(a=o==null?void 0:o.audio)==null?void 0:a.id,toggleScreenShare:i}};import{selectAudioTrackVolume as Fe,selectPermissions as Be,selectTrackByID as ee}from"@100mslive/hms-video-store";import{useCallback as O}from"react";var te=(r,e,t)=>p(void 0,null,function*(){if(e)try{yield r.setRemoteTrackEnabled(e.id,!e.enabled)}catch(s){t(s,"remoteToggle")}}),ze=(r,e,t=v)=>{let s=g(),o=m(ee(r)),i=m(ee(e)),n=m(Fe(o==null?void 0:o.id)),a=m(Be),c=(i==null?void 0:i.enabled)?a==null?void 0:a.mute:a==null?void 0:a.unmute,u=(o==null?void 0:o.enabled)?a==null?void 0:a.mute:a==null?void 0:a.unmute,h=O(()=>p(void 0,null,function*(){yield te(s,o,t)}),[s,o,t]),l=O(()=>p(void 0,null,function*(){yield te(s,i,t)}),[s,t,i]),d=O(S=>{o&&s.setVolume(S,o.id)},[s,o]);return{isAudioEnabled:!!(o==null?void 0:o.enabled),isVideoEnabled:!!(i==null?void 0:i.enabled),volume:n,toggleAudio:o&&u?h:void 0,toggleVideo:(i==null?void 0:i.source)==="regular"&&c?l:void 0,setVolume:o?d:void 0}};import{selectTracksMap as _e}from"@100mslive/hms-video-store";import{useMemo as W}from"react";var Ge=(r,e,t)=>r.reduce((s,o,i)=>{let n=Math.floor(i/e);return n>0&&t||(s[n]||(s[n]=[]),s[n].push(o)),s},[]),oe=({elements:r,tilesInFirstPage:e,onlyOnePage:t,isLastPageDifferentFromFirstPage:s,defaultWidth:o,defaultHeight:i,lastPageWidth:n,lastPageHeight:a})=>{let c=Ge(r,e,t);return c.map((u,h)=>u.map(l=>{let d=h===c.length-1,S=s&&d?n:o,f=s&&d?a:i;return I(E({},l),{height:f,width:S})}))};function qe(r){if(r.length===0)return null;let e={},t=r[0],s=1;for(let o=0;o<r.length;o++){let i=r[o];e[i]===null?e[i]=1:e[i]++,e[i]>s&&(t=i,s=e[i])}return t}var re=r=>qe(r.filter(e=>{var t,s;return((t=e.track)==null?void 0:t.width)&&((s=e.track)==null?void 0:s.height)}).map(e=>{var o,i;let t=(o=e.track)==null?void 0:o.width,s=(i=e.track)==null?void 0:i.height;return(t||1)/(s||1)})),L=(r,e,t,s,o)=>{if(r<0||e<0)throw new Error("Container must have a non-negative area");if(t<1||!Number.isInteger(t))throw new Error("Number of shapes to place must be a positive integer");let i=s&&o&&s/o;if(i!==void 0&&isNaN(i))throw new Error("Aspect ratio must be a number");let n={area:0,cols:0,rows:0,width:0,height:0},a=t,c=-1;if(i!==void 0)for(let u=a;u>0;u+=c){let h=Math.ceil(t/u),l=r/(u*i),d=e/h,S,f;l<=d?(S=r/u,f=S/i):(f=e/h,S=f*i);let H=S*f;H>n.area&&(n={area:H,width:S,height:f,rows:h,cols:u})}return n},je=({parentWidth:r,parentHeight:e,count:t,maxCount:s,aspectRatio:o})=>{let i=0,n=0,a=0,c=0,u=!1,h=0,l=0,d=Math.min(Math.ceil(Math.sqrt(t*(r/e)/(o.width/o.height))),s),S=r/d,f=S/(o.width/o.height);f>e&&(f=e,S=f/(o.height/o.width));let H=Math.floor(e/f);if(n=f,i=S,h=Math.min(t,H*d),l=t%(H*d),u=l>0&&t>H*d,u){let y=Math.min(Math.ceil(Math.sqrt(l*(r/e)/(o.width/o.height))),s),R=r/y,P=R/(o.width/o.height);P>e&&(P=e,R=P/(o.height/o.width)),c=P,a=R}return{tilesInFirstPage:h,defaultWidth:i,defaultHeight:n,lastPageWidth:a,lastPageHeight:c,isLastPageDifferentFromFirstPage:u}},Je=({parentWidth:r,parentHeight:e,count:t,maxCount:s,aspectRatio:o})=>{let i=0,n=0,a=0,c=0,u=!1,h=0,l=0,{width:d,height:S}=L(r,e,Math.min(t,s),o.width,o.height);if(i=d,n=S,h=Math.min(t,s),l=t%s,u=l>0&&t>s,u){let{width:f,height:H}=L(r,e,l,o.width,o.height);a=f,c=H}return{tilesInFirstPage:h,defaultWidth:i,defaultHeight:n,lastPageWidth:a,lastPageHeight:c,isLastPageDifferentFromFirstPage:u}},Ue=({parentWidth:r,parentHeight:e,count:t,maxCount:s,aspectRatio:o})=>{let i=0,n=0,a=0,c=0,u=!1,h=0,l=0,d=Math.min(Math.ceil(Math.sqrt(t*(o.width/o.height)/(r/e))),s),S=e/d,f=S*(o.width/o.height),H=Math.floor(r/f);if(i=f,n=S,h=Math.min(t,d*H),l=t%(d*H),u=l>0&&t>d*H,u){let y=Math.min(Math.ceil(Math.sqrt(l*(o.width/o.height)/(r/e))),s),R=e/y,P=R*(o.width/o.height);c=R,a=P}return{tilesInFirstPage:h,defaultWidth:i,defaultHeight:n,lastPageWidth:a,lastPageHeight:c,isLastPageDifferentFromFirstPage:u}};function se({count:r,parentWidth:e,parentHeight:t,maxTileCount:s,maxRowCount:o,maxColCount:i,aspectRatio:n}){let a=0,c=0,u=0,h=0,l=!1,d=0;if(r===0)return{tilesInFirstPage:d,defaultWidth:a,defaultHeight:c,lastPageWidth:u,lastPageHeight:h,isLastPageDifferentFromFirstPage:l};if(s)({tilesInFirstPage:d,defaultWidth:a,defaultHeight:c,lastPageWidth:u,lastPageHeight:h,isLastPageDifferentFromFirstPage:l}=Je({parentWidth:e,parentHeight:t,count:r,maxCount:s,aspectRatio:n}));else if(o)({tilesInFirstPage:d,defaultWidth:a,defaultHeight:c,lastPageWidth:u,lastPageHeight:h,isLastPageDifferentFromFirstPage:l}=Ue({parentWidth:e,parentHeight:t,count:r,maxCount:o,aspectRatio:n}));else if(i)({tilesInFirstPage:d,defaultWidth:a,defaultHeight:c,lastPageWidth:u,lastPageHeight:h,isLastPageDifferentFromFirstPage:l}=je({parentWidth:e,parentHeight:t,count:r,maxCount:i,aspectRatio:n}));else{let{width:S,height:f}=L(e,t,r,n.width,n.height);a=S,c=f,d=r}return{tilesInFirstPage:d,defaultWidth:a,defaultHeight:c,lastPageWidth:u,lastPageHeight:h,isLastPageDifferentFromFirstPage:l}}var ie=(r,e,t,s=!0)=>{if(!r||!e||!t)return[];let o=[];for(let i of r)if(i.videoTrack===void 0&&i.audioTrack&&e[i.audioTrack]?o.push({peer:i}):i.videoTrack&&e[i.videoTrack]?o.push({track:e[i.videoTrack],peer:i}):s||o.push({peer:i}),t(i)&&i.auxiliaryTracks.length>0){let a=i.auxiliaryTracks.find(c=>{let u=e[c];return(u==null?void 0:u.type)==="video"&&(u==null?void 0:u.source)==="screen"});a&&o.push({track:e[a],peer:i})}return o};import{useResizeDetector as Ke}from"react-resize-detector";var Qe={aspectRatio:{width:1,height:1}},Xe=({peers:r,maxTileCount:e,maxColCount:t,maxRowCount:s,includeScreenShareForPeer:o=()=>!1,aspectRatio:i=Qe.aspectRatio,filterNonPublishingPeers:n=!0,offsetY:a=0})=>{let{width:c=0,height:u=0,ref:h}=Ke(),d=A().getState(_e),S=ie(r,d,o,n),f=W(()=>i||{width:re(S)||1,height:1},[i,S]),H=S.length,{tilesInFirstPage:y,defaultWidth:R,defaultHeight:P,lastPageWidth:F,lastPageHeight:B,isLastPageDifferentFromFirstPage:z}=W(()=>se({count:H,parentWidth:Math.floor(c),parentHeight:Math.floor(u)-Math.min(u,a),maxTileCount:e,maxRowCount:s,maxColCount:t,aspectRatio:f}),[H,c,u,e,s,t,f,a]);return{pagesWithTiles:W(()=>oe({elements:S,tilesInFirstPage:y,onlyOnePage:!1,isLastPageDifferentFromFirstPage:z,defaultWidth:R,defaultHeight:P,lastPageWidth:F,lastPageHeight:B}),[S,y,z,R,P,F,B]),ref:h}};import{useEffect as Ye}from"react";import{selectTrackAudioByID as Ze}from"@100mslive/hms-video-store";function $e({trackId:r,getStyle:e,ref:t}){let s=A();Ye(()=>s.subscribe(o=>{if(!t.current)return;let i=e(o);for(let n in i)t.current.style[n]=i[n]},Ze(r)),[e,t,s,r])}import{selectDevices as et,selectIsAllowedToPublish as tt,selectLocalMediaSettings as ot}from"@100mslive/hms-video-store";import{useCallback as rt}from"react";var b;(function(s){s.videoInput="videoInput",s.audioInput="audioInput",s.audioOutput="audioOutput"})(b||(b={}));var st=(r=v)=>{let e=g(),t=m(et),s=m(ot),o=m(tt),i={[b.audioOutput]:s.audioOutputDeviceId},n={[b.audioOutput]:t.audioOutput};o.video&&(n[b.videoInput]=t.videoInput,i[b.videoInput]=s.videoInputDeviceId),o.audio&&(n[b.audioInput]=t.audioInput,i[b.audioInput]=s.audioInputDeviceId);let a=rt(h=>p(void 0,[h],function*({deviceType:c,deviceId:u}){try{switch(c){case b.audioInput:yield e.setAudioSettings({deviceId:u});break;case b.videoInput:yield e.setVideoSettings({deviceId:u});break;case b.audioOutput:e.setAudioOutputDevice(u);break}}catch(l){r(l,"updateDevices")}}),[r,e]);return{allDevices:n,selectedDeviceIDs:i,updateDevice:a}};import{useMemo as it}from"react";import{selectIsConnectedToRoom as nt,selectPeerCount as at,selectPeers as ct,selectRemotePeers as ut}from"@100mslive/hms-video-store";var ne=r=>!r||!Array.isArray(r)||r.length===0?{}:r.reduce((e,t)=>(t.roleName&&(e[t.roleName]||(e[t.roleName]=[]),e[t.roleName].push(t)),e),{});var lt=()=>{let r=m(nt),e=m(r?ct:ut),t=m(at),s=it(()=>ne(e),[e]);return{roles:Object.keys(s),participantsByRoles:s,peerCount:t,isConnected:r}};import{selectHLSState as mt,selectRecordingState as dt,selectRTMPState as St}from"@100mslive/hms-video-store";var ft=()=>{let r=m(dt),e=m(St),t=m(mt),s=r.server.running,o=r.browser.running,i=r.hls.running,n=t.running||e.running,a=s||o||i;return{isServerRecordingOn:s,isBrowserRecordingOn:o,isHLSRecordingOn:i,isStreamingOn:n,isHLSRunning:t.running,isRTMPRunning:e.running,isRecordingOn:a}};import{useCallback as ht,useEffect as pt,useState as gt}from"react";import{HMSNotificationTypes as Ht}from"@100mslive/hms-video-store";var Mt=()=>{let r=N(Ht.ERROR),[e,t]=gt(""),s=g(),o=ht(()=>p(void 0,null,function*(){yield s.unblockAudio()}),[s]);return pt(()=>{(r==null?void 0:r.data.code)===3008&&t(r==null?void 0:r.data.message)},[r]),{error:e,unblockAudio:o,resetError:()=>t("")}};import{useCallback as vt,useEffect as ae}from"react";import{HMSNotificationTypes as bt}from"@100mslive/hms-video-store";var kt=({type:r,onEvent:e,handleError:t=v})=>{let s=g(),o=D();return ae(()=>{s.ignoreMessageTypes([r])},[s,r]),ae(()=>o?o.onNotification(a=>{let c=a.data;if(c&&c.type===r)try{let u=JSON.parse(c.message);e==null||e(u)}catch(u){t(u,"handleCustomEvent")}},bt.NEW_MESSAGE):void 0,[o,r,e,t]),{sendEvent:vt(n=>p(void 0,null,function*(){try{let a=JSON.stringify(n||"");yield s.sendBroadcastMessage(a,r),e==null||e(n)}catch(a){t(a,"sendCustomEvent")}}),[s,t,e,r])}};export*from"@100mslive/hms-video-store";export{b as DeviceType,ge as HMSRoomProvider,ve as throwErrorHandler,ye as useAVToggle,$e as useAudioLevelStyles,Mt as useAutoplayError,kt as useCustomEvent,st as useDevices,g as useHMSActions,N as useHMSNotifications,He as useHMSStatsStore,m as useHMSStore,D as useHMSVanillaNotifications,A as useHMSVanillaStore,lt as useParticipantList,Pe as usePreviewJoin,ft as useRecordingStreaming,ze as useRemoteAVToggle,We as useScreenShare,Ce as useVideo,Xe as useVideoList};
1
+ export{HMSRoomProvider,useHMSActions,useHMSNotifications,useHMSStatsStore,useHMSStore,useHMSVanillaNotifications,useHMSVanillaStore}from"./primitives/HmsRoomProvider.js";export{usePreviewJoin}from"./hooks/usePreviewJoin.js";export{useAVToggle}from"./hooks/useAVToggle.js";export{useVideo}from"./hooks/useVideo.js";export{useScreenShare}from"./hooks/useScreenShare.js";export{useRemoteAVToggle}from"./hooks/useRemoteAVToggle.js";export{useVideoList}from"./hooks/useVideoList.js";export{useAudioLevelStyles}from"./hooks/useAudioLevelStyles.js";export{DeviceType,useDevices}from"./hooks/useDevices.js";export{useParticipantList}from"./hooks/useParticipantList.js";export{useRecordingStreaming}from"./hooks/useRecordingStreaming.js";export{useAutoplayError}from"./hooks/useAutoplayError.js";export{useCustomEvent}from"./hooks/useCustomEvent.js";export{throwErrorHandler}from"./utils/commons.js";export*from"@100mslive/hms-video-store";
@@ -0,0 +1,15 @@
1
+ /*! *****************************************************************************
2
+ Copyright (c) Microsoft Corporation.
3
+
4
+ Permission to use, copy, modify, and/or distribute this software for any
5
+ purpose with or without fee is hereby granted.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
9
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
11
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
12
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13
+ PERFORMANCE OF THIS SOFTWARE.
14
+ ***************************************************************************** */
15
+ function n(n,t,e,c){return new(e||(e=Promise))((function(o,u){function i(n){try{a(c.next(n))}catch(n){u(n)}}function r(n){try{a(c.throw(n))}catch(n){u(n)}}function a(n){var t;n.done?o(n.value):(t=n.value,t instanceof e?t:new e((function(n){n(t)}))).then(i,r)}a((c=c.apply(n,t||[])).next())}))}export{n as __awaiter};
@@ -0,0 +1 @@
1
+ function t(t,e){if(Object.is(t,e))return!0;if("object"!=typeof t||null===t||"object"!=typeof e||null===e)return!1;const r=Object.keys(t);if(r.length!==Object.keys(e).length)return!1;for(let n=0;n<r.length;n++)if(!Object.prototype.hasOwnProperty.call(e,r[n])||!Object.is(t[r[n]],e[r[n]]))return!1;return!0}export{t as default};
@@ -0,0 +1 @@
1
+ import t,{createContext as e,useEffect as o,useContext as s,useState as r}from"react";import{HMSReactiveStore as i}from"@100mslive/hms-video-store";import n from"zustand";import{makeHMSStoreHook as a,makeHMSStatsStoreHook as c,hooksErrorMessage as f}from"./store.js";import{isBrowser as d}from"../utils/isBrowser.js";const u=e(null);let l;const w=({children:e,actions:s,store:r,notifications:a,stats:c,isHMSStatsOn:f=!1})=>{if(!l){const t=()=>{throw new Error("modifying store is not allowed")};if(s&&r)l={actions:s,store:n(Object.assign(Object.assign({},r),{setState:t,destroy:t}))},a&&(l.notifications=a),c&&(l.statsStore=n({getState:c.getState,subscribe:c.subscribe,setState:t,destroy:t}));else{const e=new i;if(l={actions:e.getActions(),store:n(Object.assign(Object.assign({},e.getStore()),{setState:t,destroy:t})),notifications:e.getNotifications()},f){const o=e.getStats();l.statsStore=n({getState:o.getState,subscribe:o.subscribe,setState:t,destroy:t})}}}return o((()=>{d&&(window.addEventListener("beforeunload",(()=>l.actions.leave())),window.addEventListener("onunload",(()=>l.actions.leave())))}),[]),t.createElement(u.Provider,{value:l},e)},m=a(u),S=c(u),b=()=>{const t=s(u);if(!t)throw new Error(f);return t.store},g=()=>{const t=s(u);if(!t)throw new Error(f);return t.notifications},v=()=>{const t=s(u);if(!t)throw new Error(f);return t.actions},E=t=>{const e=s(u),[i,n]=r(null);if(!e)throw new Error(f);return o((()=>{if(!e.notifications)return;return e.notifications.onNotification((t=>n(t)),t)}),[e.notifications,t]),i};export{w as HMSRoomProvider,v as useHMSActions,E as useHMSNotifications,S as useHMSStatsStore,m as useHMSStore,g as useHMSVanillaNotifications,b as useHMSVanillaStore};
@@ -0,0 +1 @@
1
+ import{useContext as o}from"react";import e from"../node_modules/zustand/esm/shallow.js";import t from"../utils/logger.js";const r="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.";function s(s){return(n,i=e)=>{n||t.w("fetching full store without passing any selector may have a heavy performance impact on your website.");const a=o(s);if(!a)throw new Error(r);return(0,a.store)(n,i)}}function n(s){return(n,i=e)=>{n||t.w("fetching full store without passing any selector may have a heavy performance impact on your website.");const a=o(s);if(!a)throw new Error(r);const c=a.statsStore;return null==c?void 0:c(n,i)}}export{r as hooksErrorMessage,n as makeHMSStatsStoreHook,s as makeHMSStoreHook};
@@ -0,0 +1 @@
1
+ import o from"./logger.js";const r=(r,t)=>o.e("react-sdk",t,r),t=o=>{throw o};export{r as logErrorHandler,t as throwErrorHandler};
@@ -0,0 +1 @@
1
+ const e=e=>e&&Array.isArray(e)&&0!==e.length?e.reduce(((e,r)=>r.roleName?(e[r.roleName]||(e[r.roleName]=[]),e[r.roleName].push(r),e):e),{}):{};export{e as groupByRoles};
@@ -0,0 +1 @@
1
+ const e="undefined"!=typeof window;export{e as isBrowser};
@@ -0,0 +1 @@
1
+ const t=(t,e,i)=>t.reduce(((t,a,h)=>{const r=Math.floor(h/e);return r>0&&i||(t[r]||(t[r]=[]),t[r].push(a)),t}),[]),e=({elements:e,tilesInFirstPage:i,onlyOnePage:a,isLastPageDifferentFromFirstPage:h,defaultWidth:r,defaultHeight:n,lastPageWidth:s,lastPageHeight:o})=>{const g=t(e,i,a);return g.map(((t,e)=>t.map((t=>{const i=e===g.length-1,a=h&&i?s:r,l=h&&i?o:n;return Object.assign(Object.assign({},t),{height:l,width:a})}))))};function i(t){if(0===t.length)return null;const e={};let i=t[0],a=1;for(let h=0;h<t.length;h++){const r=t[h];null===e[r]?e[r]=1:e[r]++,e[r]>a&&(i=r,a=e[r])}return i}const a=t=>i(t.filter((t=>{var e,i;return(null===(e=t.track)||void 0===e?void 0:e.width)&&(null===(i=t.track)||void 0===i?void 0:i.height)})).map((t=>{var e,i;return((null===(e=t.track)||void 0===e?void 0:e.width)||1)/((null===(i=t.track)||void 0===i?void 0:i.height)||1)}))),h=(t,e,i,a,h)=>{if(t<0||e<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=a&&h&&a/h;if(void 0!==r&&isNaN(r))throw new Error("Aspect ratio must be a number");let n={area:0,cols:0,rows:0,width:0,height:0};if(void 0!==r)for(let a=i;a>0;a+=-1){const h=Math.ceil(i/a);let s,o;t/(a*r)<=e/h?(s=t/a,o=s/r):(o=e/h,s=o*r);const g=s*o;g>n.area&&(n={area:g,width:s,height:o,rows:h,cols:a})}return n},r=({parentWidth:t,parentHeight:e,count:i,maxCount:a,aspectRatio:h})=>{let r=0,n=0,s=0,o=0,g=!1,l=0,d=0;const u=Math.min(Math.ceil(Math.sqrt(i*(t/e)/(h.width/h.height))),a);let c=t/u,f=c/(h.width/h.height);f>e&&(f=e,c=f/(h.height/h.width));const P=Math.floor(e/f);if(n=f,r=c,l=Math.min(i,P*u),d=i%(P*u),g=d>0&&i>P*u,g){let i=t/Math.min(Math.ceil(Math.sqrt(d*(t/e)/(h.width/h.height))),a),r=i/(h.width/h.height);r>e&&(r=e,i=r/(h.height/h.width)),o=r,s=i}return{tilesInFirstPage:l,defaultWidth:r,defaultHeight:n,lastPageWidth:s,lastPageHeight:o,isLastPageDifferentFromFirstPage:g}},n=({parentWidth:t,parentHeight:e,count:i,maxCount:a,aspectRatio:r})=>{let n=0,s=0,o=0,g=0,l=!1,d=0,u=0;const{width:c,height:f}=h(t,e,Math.min(i,a),r.width,r.height);if(n=c,s=f,d=Math.min(i,a),u=i%a,l=u>0&&i>a,l){const{width:i,height:a}=h(t,e,u,r.width,r.height);o=i,g=a}return{tilesInFirstPage:d,defaultWidth:n,defaultHeight:s,lastPageWidth:o,lastPageHeight:g,isLastPageDifferentFromFirstPage:l}},s=({parentWidth:t,parentHeight:e,count:i,maxCount:a,aspectRatio:h})=>{let r=0,n=0,s=0,o=0,g=!1,l=0,d=0;const u=Math.min(Math.ceil(Math.sqrt(i*(h.width/h.height)/(t/e))),a),c=e/u,f=c*(h.width/h.height),P=Math.floor(t/f);if(r=f,n=c,l=Math.min(i,u*P),d=i%(u*P),g=d>0&&i>u*P,g){const i=e/Math.min(Math.ceil(Math.sqrt(d*(h.width/h.height)/(t/e))),a);o=i,s=i*(h.width/h.height)}return{tilesInFirstPage:l,defaultWidth:r,defaultHeight:n,lastPageWidth:s,lastPageHeight:o,isLastPageDifferentFromFirstPage:g}};function o({count:t,parentWidth:e,parentHeight:i,maxTileCount:a,maxRowCount:o,maxColCount:g,aspectRatio:l}){let d=0,u=0,c=0,f=0,P=!1,p=0;if(0===t)return{tilesInFirstPage:p,defaultWidth:d,defaultHeight:u,lastPageWidth:c,lastPageHeight:f,isLastPageDifferentFromFirstPage:P};if(a)({tilesInFirstPage:p,defaultWidth:d,defaultHeight:u,lastPageWidth:c,lastPageHeight:f,isLastPageDifferentFromFirstPage:P}=n({parentWidth:e,parentHeight:i,count:t,maxCount:a,aspectRatio:l}));else if(o)({tilesInFirstPage:p,defaultWidth:d,defaultHeight:u,lastPageWidth:c,lastPageHeight:f,isLastPageDifferentFromFirstPage:P}=s({parentWidth:e,parentHeight:i,count:t,maxCount:o,aspectRatio:l}));else if(g)({tilesInFirstPage:p,defaultWidth:d,defaultHeight:u,lastPageWidth:c,lastPageHeight:f,isLastPageDifferentFromFirstPage:P}=r({parentWidth:e,parentHeight:i,count:t,maxCount:g,aspectRatio:l}));else{const{width:a,height:r}=h(e,i,t,l.width,l.height);d=a,u=r,p=t}return{tilesInFirstPage:p,defaultWidth:d,defaultHeight:u,lastPageWidth:c,lastPageHeight:f,isLastPageDifferentFromFirstPage:P}}const g=(t,e,i,a=!0)=>{if(!t||!e||!i)return[];const h=[];for(const r of t){if(void 0===r.videoTrack&&r.audioTrack&&e[r.audioTrack]?h.push({peer:r}):r.videoTrack&&e[r.videoTrack]?h.push({track:e[r.videoTrack],peer:r}):a||h.push({peer:r}),i(r)&&r.auxiliaryTracks.length>0){const t=r.auxiliaryTracks.find((t=>{const i=e[t];return"video"===(null==i?void 0:i.type)&&"screen"===(null==i?void 0:i.source)}));t&&h.push({track:e[t],peer:r})}}return h};export{o as calculateLayoutSizes,t as chunk,e as chunkElements,a as getModeAspectRatio,r as getTileSizesWithColConstraint,n as getTileSizesWithPageConstraint,s as getTileSizesWithRowConstraint,g as getVideoTracksFromPeers,h as largestRect,i as mode};
@@ -0,0 +1 @@
1
+ var s,e;(e=s||(s={}))[e.VERBOSE=0]="VERBOSE",e[e.DEBUG=1]="DEBUG",e[e.INFO=2]="INFO",e[e.WARN=3]="WARN",e[e.ERROR=4]="ERROR",e[e.NONE=5]="NONE";class o{static v(e,...o){this.log(s.VERBOSE,e,...o)}static d(e,...o){this.log(s.DEBUG,e,...o)}static i(e,...o){this.log(s.INFO,e,...o)}static w(e,...o){this.log(s.WARN,e,...o)}static e(e,...o){this.log(s.ERROR,e,...o)}static log(e,o,...t){if(!(this.level.valueOf()>e.valueOf()))switch(e){case s.VERBOSE:console.log("HMSui-components: ",o,...t);break;case s.DEBUG:console.debug("HMSui-components: ",o,...t);break;case s.INFO:console.info("HMSui-components: ",o,...t);break;case s.WARN:console.warn("HMSui-components: ",o,...t);break;case s.ERROR:console.error("HMSui-components: ",o,...t)}}}o.level=s.VERBOSE;export{s as HMSLogLevel,o as default};
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.0.12-alpha.3",
7
+ "version": "0.0.13",
8
8
  "author": "100ms",
9
9
  "license": "MIT",
10
10
  "files": [
@@ -12,30 +12,32 @@
12
12
  ],
13
13
  "sideEffects": false,
14
14
  "scripts": {
15
- "prestart": "rm -rf dist && yarn types:build",
16
- "start": "concurrently \"yarn dev\" \"yarn types\"",
17
- "dev": "node ../../scripts/dev",
18
- "build:only": "node ../../scripts/build",
19
- "build": "yarn build:only && yarn types:build",
20
- "types": "tsc -w",
21
- "types:build": "tsc -p tsconfig.build.json",
15
+ "prestart": "rm -rf dist",
16
+ "start": "rollup -c -w",
17
+ "build": "rm -rf dist && NODE_ENV=production rollup -c",
22
18
  "lint": "eslint src/**",
23
19
  "lint:fix": "eslint src/** --fix",
24
20
  "format": "prettier -w src/**",
25
21
  "docs": "typedoc src/index.ts --plugin none"
26
22
  },
27
23
  "devDependencies": {
24
+ "@rollup/plugin-commonjs": "^21.0.3",
25
+ "@rollup/plugin-node-resolve": "^13.1.3",
26
+ "@rollup/plugin-typescript": "^8.3.1",
28
27
  "@types/react": "^17.0.38",
29
- "react": "^17.0.2"
28
+ "react": "^17.0.2",
29
+ "rollup": "^2.70.1",
30
+ "rollup-plugin-esbuild": "^4.9.1",
31
+ "rollup-plugin-terser": "^7.0.2"
30
32
  },
31
33
  "peerDependencies": {
32
- "react": "^17.0.1"
34
+ "react": "^17.0.2"
33
35
  },
34
36
  "dependencies": {
35
- "@100mslive/hms-video-store": "0.2.95-alpha.3",
37
+ "@100mslive/hms-video-store": "0.2.96",
36
38
  "react-intersection-observer": "^8.33.1",
37
39
  "react-resize-detector": "^7.0.0",
38
40
  "zustand": "^3.6.2"
39
41
  },
40
- "gitHead": "6d5a273898cebf38c39592ecff3d84ad56a1ad16"
42
+ "gitHead": "371fada735453c1ac2aff1d2e46b76a7c4367e49"
41
43
  }