@100mslive/react-sdk 0.0.11-alpha.2 → 0.0.12-alpha.1

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.
@@ -22,6 +22,13 @@ export interface usePreviewInput {
22
22
  * initial settings for audio/video and device to be used.
23
23
  */
24
24
  initialSettings?: HMSConfigInitialSettings;
25
+ /**
26
+ * Enable to get a network quality score while in preview. The score ranges from -1 to 5.
27
+ * -1 when we are not able to connect to 100ms servers within an expected time limit
28
+ * 0 when there is a timeout/failure when measuring the quality
29
+ * 1-5 ranges from poor to good quality.
30
+ */
31
+ captureNetworkQualityInPreview?: boolean;
25
32
  }
26
33
  export interface usePreviewResult {
27
34
  /**
@@ -48,4 +55,4 @@ export interface usePreviewResult {
48
55
  * muting/unmuting and useAudioLevelStyles for showing mic audio level to the user.
49
56
  * Any device change or mute/unmute will be carried across to join.
50
57
  */
51
- export declare const usePreviewJoin: ({ name, token, metadata, handleError, initEndpoint, initialSettings, }: usePreviewInput) => usePreviewResult;
58
+ export declare const usePreviewJoin: ({ name, token, metadata, handleError, initEndpoint, initialSettings, captureNetworkQualityInPreview, }: usePreviewInput) => usePreviewResult;
@@ -14,6 +14,11 @@ export interface useScreenShareResult {
14
14
  * In case of multiple screenshares, the behaviour of which one is picked is not defined.
15
15
  */
16
16
  screenSharingPeerId?: HMSPeerID;
17
+ /**
18
+ * the name of the peer who is currently screensharing. Will be undefined if no one is sharing the screen.
19
+ * In case of multiple screenshares, the behavior of which one is picked is not defined.
20
+ */
21
+ screenSharingPeerName?: string;
17
22
  /**
18
23
  * screenShare audio track id, will only be present if there is a screenshare with video track
19
24
  */
package/dist/index.cjs.js CHANGED
@@ -1 +1 @@
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},m=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=u=>{try{a(o.next(u))}catch(c){r(c)}},n=u=>{try{a(o.throw(u))}catch(c){r(c)}},a=u=>u.done?s(u.value):Promise.resolve(u.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:()=>Ne,useHMSActions:()=>M,useHMSNotifications:()=>Q,useHMSStatsStore:()=>fe,useHMSStore:()=>l,useHMSVanillaNotifications:()=>K,useHMSVanillaStore:()=>N,useParticipantList:()=>Fe,usePreviewJoin:()=>pe,useRecordingStreaming:()=>Be,useRemoteAVToggle:()=>Pe,useScreenShare:()=>ke,useVideo:()=>ve,useVideoList:()=>Ae});var b=m(require("react")),de=m(require("@100mslive/hms-video-store")),J=m(require("zustand"));var Z=m(require("react")),$=m(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 u=a.getStats();y.statsStore=(0,J.default)({getState:u.getState,subscribe:u.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),N=()=>{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=m(require("@100mslive/hms-video-store")),U=m(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})=>{let n=M(),a=l(V.selectRoomState),u=l(V.selectIsConnectedToRoom)||!1,c=a===V.HMSRoomState.Preview,S=(0,U.useMemo)(()=>({userName:t,authToken:e,metaData:o,rememberDeviceSelection:!0,settings:i,initEndpoint:r}),[t,e,o,r,i]),h=(0,U.useCallback)(()=>{(()=>g(void 0,null,function*(){if(!!e){a!==V.HMSRoomState.Disconnected&&(yield n.leave());try{yield n.preview(S)}catch(d){s(d,"preview")}}}))()},[n,s,e,a,S]),f=(0,U.useCallback)(()=>{if(!!e)try{n.join(S)}catch(d){s(d,"join")}},[n,S,s,e]);return{enableJoin:c,join:f,isConnected:u,preview:h}};var L=m(require("@100mslive/hms-video-store")),ee=m(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=m(require("@100mslive/hms-video-store")),C=m(require("react")),Me=m(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)(u=>{s.current=u,i(u)},[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(u){w.w("detach video error for track",r.id,u)}}))()},[]),{videoRef:a}};var W=m(require("@100mslive/hms-video-store"));var be=m(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)((u=!1)=>g(void 0,null,function*(){try{yield e.setScreenShareEnabled(!o,u)}catch(c){t(c,"toggleScreenShare")}}),[e,o,t]);return{amIScreenSharing:o,screenSharingPeerId:s==null?void 0:s.id,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=m(require("@100mslive/hms-video-store"));var X=m(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),u=(i==null?void 0:i.enabled)?a==null?void 0:a.mute:a==null?void 0:a.unmute,c=(r==null?void 0:r.enabled)?a==null?void 0:a.mute:a==null?void 0:a.unmute,S=(0,X.useCallback)(()=>g(void 0,null,function*(){yield Re(s,r,o)}),[s,r,o]),h=(0,X.useCallback)(()=>g(void 0,null,function*(){yield Re(s,i,o)}),[s,o,i]),f=(0,X.useCallback)(d=>{r&&s.setVolume(d,r.id)},[s,r]);return{isAudioEnabled:!!(r==null?void 0:r.enabled),isVideoEnabled:!!(i==null?void 0:i.enabled),volume:n,toggleAudio:r&&c?S:void 0,toggleVideo:(i==null?void 0:i.source)==="regular"&&u?h:void 0,setVolume:r?f:void 0}};var Ee=m(require("@100mslive/hms-video-store")),Y=m(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 u=et(t,e,o);return u.map((c,S)=>c.map(h=>{let f=S===u.length-1,d=s&&f?n:r,p=s&&f?a:i;return j(q({},h),{height:p,width:d})}))};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,u=-1;if(i!==void 0)for(let c=a;c>0;c+=u){let S=Math.ceil(o/c),h=t/(c*i),f=e/S,d,p;h<=f?(d=t/c,p=d/i):(p=e/S,d=p*i);let v=d*p;v>n.area&&(n={area:v,width:d,height:p,rows:S,cols:c})}return n},ot=({parentWidth:t,parentHeight:e,count:o,maxCount:s,aspectRatio:r})=>{let i=0,n=0,a=0,u=0,c=!1,S=0,h=0,f=Math.min(Math.ceil(Math.sqrt(o*(t/e)/(r.width/r.height))),s),d=t/f,p=d/(r.width/r.height);p>e&&(p=e,d=p/(r.height/r.width));let v=Math.floor(e/p);if(n=p,i=d,S=Math.min(o,v*f),h=o%(v*f),c=h>0&&o>v*f,c){let O=Math.min(Math.ceil(Math.sqrt(h*(t/e)/(r.width/r.height))),s),T=t/O,x=T/(r.width/r.height);x>e&&(x=e,T=x/(r.height/r.width)),u=x,a=T}return{tilesInFirstPage:S,defaultWidth:i,defaultHeight:n,lastPageWidth:a,lastPageHeight:u,isLastPageDifferentFromFirstPage:c}},rt=({parentWidth:t,parentHeight:e,count:o,maxCount:s,aspectRatio:r})=>{let i=0,n=0,a=0,u=0,c=!1,S=0,h=0,{width:f,height:d}=te(t,e,Math.min(o,s),r.width,r.height);if(i=f,n=d,S=Math.min(o,s),h=o%s,c=h>0&&o>s,c){let{width:p,height:v}=te(t,e,h,r.width,r.height);a=p,u=v}return{tilesInFirstPage:S,defaultWidth:i,defaultHeight:n,lastPageWidth:a,lastPageHeight:u,isLastPageDifferentFromFirstPage:c}},st=({parentWidth:t,parentHeight:e,count:o,maxCount:s,aspectRatio:r})=>{let i=0,n=0,a=0,u=0,c=!1,S=0,h=0,f=Math.min(Math.ceil(Math.sqrt(o*(r.width/r.height)/(t/e))),s),d=e/f,p=d*(r.width/r.height),v=Math.floor(t/p);if(i=p,n=d,S=Math.min(o,f*v),h=o%(f*v),c=h>0&&o>f*v,c){let O=Math.min(Math.ceil(Math.sqrt(h*(r.width/r.height)/(t/e))),s),T=e/O,x=T*(r.width/r.height);u=T,a=x}return{tilesInFirstPage:S,defaultWidth:i,defaultHeight:n,lastPageWidth:a,lastPageHeight:u,isLastPageDifferentFromFirstPage:c}};function xe({count:t,parentWidth:e,parentHeight:o,maxTileCount:s,maxRowCount:r,maxColCount:i,aspectRatio:n}){let a=0,u=0,c=0,S=0,h=!1,f=0;if(t===0)return{tilesInFirstPage:f,defaultWidth:a,defaultHeight:u,lastPageWidth:c,lastPageHeight:S,isLastPageDifferentFromFirstPage:h};if(s)({tilesInFirstPage:f,defaultWidth:a,defaultHeight:u,lastPageWidth:c,lastPageHeight:S,isLastPageDifferentFromFirstPage:h}=rt({parentWidth:e,parentHeight:o,count:t,maxCount:s,aspectRatio:n}));else if(r)({tilesInFirstPage:f,defaultWidth:a,defaultHeight:u,lastPageWidth:c,lastPageHeight:S,isLastPageDifferentFromFirstPage:h}=st({parentWidth:e,parentHeight:o,count:t,maxCount:r,aspectRatio:n}));else if(i)({tilesInFirstPage:f,defaultWidth:a,defaultHeight:u,lastPageWidth:c,lastPageHeight:S,isLastPageDifferentFromFirstPage:h}=ot({parentWidth:e,parentHeight:o,count:t,maxCount:i,aspectRatio:n}));else{let{width:d,height:p}=te(e,o,t,n.width,n.height);a=d,u=p,f=t}return{tilesInFirstPage:f,defaultWidth:a,defaultHeight:u,lastPageWidth:c,lastPageHeight:S,isLastPageDifferentFromFirstPage:h}}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(u=>{let c=e[u];return(c==null?void 0:c.type)==="video"&&(c==null?void 0:c.source)==="screen"});a&&r.push({track:e[a],peer:i})}return r};var Ie=m(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:u=0,height:c=0,ref:S}=(0,Ie.useResizeDetector)(),f=N().getState(Ee.selectTracksMap),d=ye(t,f,r,n),p=(0,Y.useMemo)(()=>i||{width:Te(d)||1,height:1},[i,d]),v=d.length,{tilesInFirstPage:O,defaultWidth:T,defaultHeight:x,lastPageWidth:oe,lastPageHeight:re,isLastPageDifferentFromFirstPage:se}=(0,Y.useMemo)(()=>xe({count:v,parentWidth:Math.floor(u),parentHeight:Math.floor(c)-Math.min(c,a),maxTileCount:e,maxRowCount:s,maxColCount:o,aspectRatio:p}),[v,u,c,e,s,o,p,a]);return{pagesWithTiles:(0,Y.useMemo)(()=>we({elements:d,tilesInFirstPage:O,onlyOnePage:!1,isLastPageDifferentFromFirstPage:se,defaultWidth:T,defaultHeight:x,lastPageWidth:oe,lastPageHeight:re}),[d,O,se,T,x,oe,re]),ref:S}};var Ve=m(require("react")),Ce=m(require("@100mslive/hms-video-store"));function De({trackId:t,getStyle:e,ref:o}){let s=N();(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=m(require("@100mslive/hms-video-store")),Oe=m(require("react"));var R;(function(s){s.videoInput="videoInput",s.audioInput="audioInput",s.audioOutput="audioOutput"})(R||(R={}));var Ne=(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,Oe.useCallback)(S=>g(void 0,[S],function*({deviceType:u,deviceId:c}){try{switch(u){case R.audioInput:yield e.setAudioSettings({deviceId:c});break;case R.videoInput:yield e.setVideoSettings({deviceId:c});break;case R.audioOutput:e.setAudioOutputDevice(c);break}}catch(h){t(h,"updateDevices")}}),[t,e]);return{allDevices:n,selectedDeviceIDs:i,updateDevice:a}};var We=m(require("react")),E=m(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=m(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=m(require("react")),ze=m(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 _=m(require("react")),qe=m(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 u=a.data;if(u&&u.type===t)try{let c=JSON.parse(u.message);e==null||e(c)}catch(c){o(c,"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,m(require("@100mslive/hms-video-store")));
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")));
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=u=>{try{a(t.next(u))}catch(c){o(c)}},n=u=>{try{a(t.throw(u))}catch(c){o(c)}},a=u=>u.done?s(u.value):Promise.resolve(u.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 u=a.getStats();w.statsStore=C({getState:u.getState,subscribe:u.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)},l=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},O=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})=>{let n=g(),a=l(ke),u=l(be)||!1,c=a===X.Preview,d=Re(()=>({userName:r,authToken:e,metaData:t,rememberDeviceSelection:!0,settings:i,initEndpoint:o}),[r,e,t,o,i]),f=Y(()=>{(()=>p(void 0,null,function*(){if(!!e){a!==X.Disconnected&&(yield n.leave());try{yield n.preview(d)}catch(m){s(m,"preview")}}}))()},[n,s,e,a,d]),S=Y(()=>{if(!!e)try{n.join(d)}catch(m){s(m,"join")}},[n,d,s,e]);return{enableJoin:c,join:S,isConnected:u,preview:f}};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=l(Te),t=l(xe),s=l(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=l(Ee(r)),{ref:i,inView:n}=Ve({threshold:.5}),a=Ie(u=>{s.current=u,i(u)},[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(u){k.w("detach video error for track",o.id,u)}}))()},[]),{videoRef:a}};import{selectIsLocalScreenShared as De,selectPeerScreenSharing as Oe,selectScreenSharesByPeerId as Ne}from"@100mslive/hms-video-store";import{useCallback as Le}from"react";var We=(r=v)=>{var n,a;let e=g(),t=l(De),s=l(Oe),o=l(Ne(s==null?void 0:s.id)),i=Le((u=!1)=>p(void 0,null,function*(){try{yield e.setScreenShareEnabled(!t,u)}catch(c){r(c,"toggleScreenShare")}}),[e,t,r]);return{amIScreenSharing:t,screenSharingPeerId:s==null?void 0:s.id,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 N}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=l(ee(r)),i=l(ee(e)),n=l(Fe(o==null?void 0:o.id)),a=l(Be),u=(i==null?void 0:i.enabled)?a==null?void 0:a.mute:a==null?void 0:a.unmute,c=(o==null?void 0:o.enabled)?a==null?void 0:a.mute:a==null?void 0:a.unmute,d=N(()=>p(void 0,null,function*(){yield te(s,o,t)}),[s,o,t]),f=N(()=>p(void 0,null,function*(){yield te(s,i,t)}),[s,t,i]),S=N(m=>{o&&s.setVolume(m,o.id)},[s,o]);return{isAudioEnabled:!!(o==null?void 0:o.enabled),isVideoEnabled:!!(i==null?void 0:i.enabled),volume:n,toggleAudio:o&&c?d:void 0,toggleVideo:(i==null?void 0:i.source)==="regular"&&u?f:void 0,setVolume:o?S: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 u=Ge(r,e,t);return u.map((c,d)=>c.map(f=>{let S=d===u.length-1,m=s&&S?n:o,h=s&&S?a:i;return I(E({},f),{height:h,width:m})}))};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,u=-1;if(i!==void 0)for(let c=a;c>0;c+=u){let d=Math.ceil(t/c),f=r/(c*i),S=e/d,m,h;f<=S?(m=r/c,h=m/i):(h=e/d,m=h*i);let H=m*h;H>n.area&&(n={area:H,width:m,height:h,rows:d,cols:c})}return n},je=({parentWidth:r,parentHeight:e,count:t,maxCount:s,aspectRatio:o})=>{let i=0,n=0,a=0,u=0,c=!1,d=0,f=0,S=Math.min(Math.ceil(Math.sqrt(t*(r/e)/(o.width/o.height))),s),m=r/S,h=m/(o.width/o.height);h>e&&(h=e,m=h/(o.height/o.width));let H=Math.floor(e/h);if(n=h,i=m,d=Math.min(t,H*S),f=t%(H*S),c=f>0&&t>H*S,c){let y=Math.min(Math.ceil(Math.sqrt(f*(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)),u=P,a=R}return{tilesInFirstPage:d,defaultWidth:i,defaultHeight:n,lastPageWidth:a,lastPageHeight:u,isLastPageDifferentFromFirstPage:c}},Je=({parentWidth:r,parentHeight:e,count:t,maxCount:s,aspectRatio:o})=>{let i=0,n=0,a=0,u=0,c=!1,d=0,f=0,{width:S,height:m}=L(r,e,Math.min(t,s),o.width,o.height);if(i=S,n=m,d=Math.min(t,s),f=t%s,c=f>0&&t>s,c){let{width:h,height:H}=L(r,e,f,o.width,o.height);a=h,u=H}return{tilesInFirstPage:d,defaultWidth:i,defaultHeight:n,lastPageWidth:a,lastPageHeight:u,isLastPageDifferentFromFirstPage:c}},Ue=({parentWidth:r,parentHeight:e,count:t,maxCount:s,aspectRatio:o})=>{let i=0,n=0,a=0,u=0,c=!1,d=0,f=0,S=Math.min(Math.ceil(Math.sqrt(t*(o.width/o.height)/(r/e))),s),m=e/S,h=m*(o.width/o.height),H=Math.floor(r/h);if(i=h,n=m,d=Math.min(t,S*H),f=t%(S*H),c=f>0&&t>S*H,c){let y=Math.min(Math.ceil(Math.sqrt(f*(o.width/o.height)/(r/e))),s),R=e/y,P=R*(o.width/o.height);u=R,a=P}return{tilesInFirstPage:d,defaultWidth:i,defaultHeight:n,lastPageWidth:a,lastPageHeight:u,isLastPageDifferentFromFirstPage:c}};function se({count:r,parentWidth:e,parentHeight:t,maxTileCount:s,maxRowCount:o,maxColCount:i,aspectRatio:n}){let a=0,u=0,c=0,d=0,f=!1,S=0;if(r===0)return{tilesInFirstPage:S,defaultWidth:a,defaultHeight:u,lastPageWidth:c,lastPageHeight:d,isLastPageDifferentFromFirstPage:f};if(s)({tilesInFirstPage:S,defaultWidth:a,defaultHeight:u,lastPageWidth:c,lastPageHeight:d,isLastPageDifferentFromFirstPage:f}=Je({parentWidth:e,parentHeight:t,count:r,maxCount:s,aspectRatio:n}));else if(o)({tilesInFirstPage:S,defaultWidth:a,defaultHeight:u,lastPageWidth:c,lastPageHeight:d,isLastPageDifferentFromFirstPage:f}=Ue({parentWidth:e,parentHeight:t,count:r,maxCount:o,aspectRatio:n}));else if(i)({tilesInFirstPage:S,defaultWidth:a,defaultHeight:u,lastPageWidth:c,lastPageHeight:d,isLastPageDifferentFromFirstPage:f}=je({parentWidth:e,parentHeight:t,count:r,maxCount:i,aspectRatio:n}));else{let{width:m,height:h}=L(e,t,r,n.width,n.height);a=m,u=h,S=r}return{tilesInFirstPage:S,defaultWidth:a,defaultHeight:u,lastPageWidth:c,lastPageHeight:d,isLastPageDifferentFromFirstPage:f}}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(u=>{let c=e[u];return(c==null?void 0:c.type)==="video"&&(c==null?void 0:c.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:u=0,height:c=0,ref:d}=Ke(),S=A().getState(_e),m=ie(r,S,o,n),h=W(()=>i||{width:re(m)||1,height:1},[i,m]),H=m.length,{tilesInFirstPage:y,defaultWidth:R,defaultHeight:P,lastPageWidth:F,lastPageHeight:B,isLastPageDifferentFromFirstPage:z}=W(()=>se({count:H,parentWidth:Math.floor(u),parentHeight:Math.floor(c)-Math.min(c,a),maxTileCount:e,maxRowCount:s,maxColCount:t,aspectRatio:h}),[H,u,c,e,s,t,h,a]);return{pagesWithTiles:W(()=>oe({elements:m,tilesInFirstPage:y,onlyOnePage:!1,isLastPageDifferentFromFirstPage:z,defaultWidth:R,defaultHeight:P,lastPageWidth:F,lastPageHeight:B}),[m,y,z,R,P,F,B]),ref:d}};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=l(et),s=l(ot),o=l(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(d=>p(void 0,[d],function*({deviceType:u,deviceId:c}){try{switch(u){case b.audioInput:yield e.setAudioSettings({deviceId:c});break;case b.videoInput:yield e.setVideoSettings({deviceId:c});break;case b.audioOutput:e.setAudioOutputDevice(c);break}}catch(f){r(f,"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=l(nt),e=l(r?ct:ut),t=l(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=l(dt),e=l(St),t=l(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=O(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 u=a.data;if(u&&u.type===r)try{let c=JSON.parse(u.message);e==null||e(c)}catch(c){t(c,"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,O as useHMSNotifications,He as useHMSStatsStore,l 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
+ 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};
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.11-alpha.2",
7
+ "version": "0.0.12-alpha.1",
8
8
  "author": "100ms",
9
9
  "license": "MIT",
10
10
  "files": [
@@ -32,10 +32,10 @@
32
32
  "react": "^17.0.1"
33
33
  },
34
34
  "dependencies": {
35
- "@100mslive/hms-video-store": "0.2.94-alpha.2",
35
+ "@100mslive/hms-video-store": "0.2.95-alpha.1",
36
36
  "react-intersection-observer": "^8.33.1",
37
37
  "react-resize-detector": "^7.0.0",
38
38
  "zustand": "^3.6.2"
39
39
  },
40
- "gitHead": "a50567c36b48097760a7afb32769ae716330bca6"
40
+ "gitHead": "493b64c9e8e81f8db39837af309689c01bc70109"
41
41
  }