@100mslive/react-sdk 0.0.15 → 0.0.16

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.
@@ -1 +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};
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){y&&(yield w.leave());try{yield w.preview(b)}catch(e){l(e,"preview")}}}))}),[w,l,d,j,b,y]);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};
package/dist/index.cjs.js CHANGED
@@ -13,4 +13,4 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13
13
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14
14
  PERFORMANCE OF THIS SOFTWARE.
15
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]}})}));
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),k=(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")}})),R=({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 I=(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}=I(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}=I(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}=I(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){d&&(yield l.leave());try{yield l.preview(g)}catch(e){r(e,"preview")}}}))}),[l,r,o,c,g,d]);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 k(r,a,n)}))),[r,a,n]),g=e.useCallback((()=>E(void 0,void 0,void 0,(function*(){yield k(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}),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})(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((()=>R({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]}})}));
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import React, { PropsWithChildren } from 'react';
2
2
  import { HMSStore, HMSActions, HMSNotification, HMSNotifications, HMSStatsStore, HMSStats, HMSStoreWrapper, HMSNotificationTypes } from '@100mslive/hms-video-store';
3
3
  export interface HMSRoomProviderProps {
4
4
  actions?: HMSActions;
@@ -16,7 +16,7 @@ export interface HMSRoomProviderProps {
16
16
  * react part of your code.
17
17
  * @constructor
18
18
  */
19
- export declare const HMSRoomProvider: React.FC<HMSRoomProviderProps>;
19
+ export declare const HMSRoomProvider: React.FC<PropsWithChildren<HMSRoomProviderProps>>;
20
20
  /**
21
21
  * `useHMSStore` is a read only hook which can be passed a selector to read data.
22
22
  * The hook can only be used in a component if HMSRoomProvider is present in its ancestors.
@@ -1 +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};
1
+ const t=(t,e,i)=>t.reduce(((t,a,r)=>{const h=Math.floor(r/e);return h>0&&i||(t[h]||(t[h]=[]),t[h].push(a)),t}),[]),e=({elements:e,tilesInFirstPage:i,onlyOnePage:a,isLastPageDifferentFromFirstPage:r,defaultWidth:h,defaultHeight:n,lastPageWidth:s,lastPageHeight:o})=>{const l=t(e,i,a);return l.map(((t,e)=>t.map((t=>{const i=e===l.length-1,a=r&&i?s:h,g=r&&i?o:n;return Object.assign(Object.assign({},t),{height:g,width:a})}))))};function i(t){if(0===t.length)return null;const e={};let i=t[0],a=1;for(let r=0;r<t.length;r++){const h=t[r];null===e[h]?e[h]=1:e[h]++,e[h]>a&&(i=h,a=e[h])}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)}))),r=(t,e,i,a,r)=>{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 h=a&&r&&a/r;if(void 0!==h&&isNaN(h))throw new Error("Aspect ratio must be a number");let n={area:0,cols:0,rows:0,width:0,height:0};if(void 0!==h)for(let a=i;a>0;a+=-1){const r=Math.ceil(i/a);let s,o;t/(a*h)<=e/r?(s=t/a,o=s/h):(o=e/r,s=o*h);const l=s*o;l>n.area&&(n={area:l,width:s,height:o,rows:r,cols:a})}return n},h=({parentWidth:t,parentHeight:e,count:i,maxCount:a,aspectRatio:r})=>{let h=0,n=0,s=0,o=0,l=!1,g=0,d=0;const u=Math.min(Math.ceil(Math.sqrt(i*(t/e)/(r.width/r.height))),a);let c=t/u,f=c/(r.width/r.height);f>e&&(f=e,c=f/(r.height/r.width));const P=Math.floor(e/f);if(n=f,h=c,g=Math.min(i,P*u),d=i%(P*u),l=d>0&&i>P*u,l){let i=t/Math.min(Math.ceil(Math.sqrt(d*(t/e)/(r.width/r.height))),a),h=i/(r.width/r.height);h>e&&(h=e,i=h/(r.height/r.width)),o=h,s=i}return{tilesInFirstPage:g,defaultWidth:h,defaultHeight:n,lastPageWidth:s,lastPageHeight:o,isLastPageDifferentFromFirstPage:l}},n=({parentWidth:t,parentHeight:e,count:i,maxCount:a,aspectRatio:h})=>{let n=0,s=0,o=0,l=0,g=!1,d=0,u=0;const{width:c,height:f}=r(t,e,Math.min(i,a),h.width,h.height);if(n=c,s=f,d=Math.min(i,a),u=i%a,g=u>0&&i>a,g){const{width:i,height:a}=r(t,e,u,h.width,h.height);o=i,l=a}return{tilesInFirstPage:d,defaultWidth:n,defaultHeight:s,lastPageWidth:o,lastPageHeight:l,isLastPageDifferentFromFirstPage:g}},s=({parentWidth:t,parentHeight:e,count:i,maxCount:a,aspectRatio:r})=>{let h=0,n=0,s=0,o=0,l=!1,g=0,d=0;const u=Math.min(Math.ceil(Math.sqrt(i*(r.width/r.height)/(t/e))),a),c=e/u,f=c*(r.width/r.height),P=Math.floor(t/f);if(h=f,n=c,g=Math.min(i,u*P),d=i%(u*P),l=d>0&&i>u*P,l){const i=e/Math.min(Math.ceil(Math.sqrt(d*(r.width/r.height)/(t/e))),a);o=i,s=i*(r.width/r.height)}return{tilesInFirstPage:g,defaultWidth:h,defaultHeight:n,lastPageWidth:s,lastPageHeight:o,isLastPageDifferentFromFirstPage:l}};function o({count:t,parentWidth:e,parentHeight:i,maxTileCount:a,maxRowCount:o,maxColCount:l,aspectRatio:g}){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:g}));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:g}));else if(l)({tilesInFirstPage:p,defaultWidth:d,defaultHeight:u,lastPageWidth:c,lastPageHeight:f,isLastPageDifferentFromFirstPage:P}=h({parentWidth:e,parentHeight:i,count:t,maxCount:l,aspectRatio:g}));else{const{width:a,height:h}=r(e,i,t,g.width,g.height);d=a,u=h,p=t}return{tilesInFirstPage:p,defaultWidth:d,defaultHeight:u,lastPageWidth:c,lastPageHeight:f,isLastPageDifferentFromFirstPage:P}}const l=(t,e,i,a=!0)=>{if(!t||!e||!i)return[];const r=[];for(const h of t){if(void 0===h.videoTrack&&h.audioTrack&&e[h.audioTrack]?r.push({peer:h}):h.videoTrack&&e[h.videoTrack]?r.push({track:e[h.videoTrack],peer:h}):a||r.push({peer:h}),h.auxiliaryTracks.length>0&&h.auxiliaryTracks.forEach((t=>{const i=e[t];"video"===(null==i?void 0:i.type)&&"regular"===(null==i?void 0:i.source)&&r.push({track:i,peer:h})})),i(h)&&h.auxiliaryTracks.length>0){const t=h.auxiliaryTracks.find((t=>{const i=e[t];return"video"===(null==i?void 0:i.type)&&"screen"===(null==i?void 0:i.source)}));t&&r.push({track:e[t],peer:h})}}return r};export{o as calculateLayoutSizes,t as chunk,e as chunkElements,a as getModeAspectRatio,h as getTileSizesWithColConstraint,n as getTileSizesWithPageConstraint,s as getTileSizesWithRowConstraint,l as getVideoTracksFromPeers,r as largestRect,i as mode};
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.15",
7
+ "version": "0.0.16",
8
8
  "author": "100ms",
9
9
  "license": "MIT",
10
10
  "files": [
@@ -24,20 +24,20 @@
24
24
  "@rollup/plugin-commonjs": "^21.0.3",
25
25
  "@rollup/plugin-node-resolve": "^13.1.3",
26
26
  "@rollup/plugin-typescript": "^8.3.1",
27
- "@types/react": "^17.0.38",
28
- "react": "^17.0.2",
27
+ "@types/react": "^18.0.8",
28
+ "react": "^18.1.0",
29
29
  "rollup": "^2.70.1",
30
30
  "rollup-plugin-esbuild": "^4.9.1",
31
31
  "rollup-plugin-terser": "^7.0.2"
32
32
  },
33
33
  "peerDependencies": {
34
- "react": "^17.0.2"
34
+ "react": "^18.1.0"
35
35
  },
36
36
  "dependencies": {
37
- "@100mslive/hms-video-store": "0.2.98",
37
+ "@100mslive/hms-video-store": "0.2.99",
38
38
  "react-intersection-observer": "^8.33.1",
39
39
  "react-resize-detector": "^7.0.0",
40
40
  "zustand": "^3.6.2"
41
41
  },
42
- "gitHead": "80757dd8d2a0fc195746bd158f7238e81b4ae1ca"
42
+ "gitHead": "c6c340a9f18b78da0b3ca8b8ba0c6f5c0bc36ff2"
43
43
  }