@100mslive/react-sdk 0.0.8-alpha.0 → 0.0.8-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.
@@ -0,0 +1,31 @@
1
+ import { hooksErrHandler } from './types';
2
+ export interface useCustomEventInput<T> {
3
+ /**
4
+ * type of the event, e.g. MODERATOR_EVENT, EMOJI_REACTIONS etc.
5
+ */
6
+ type: string;
7
+ /**
8
+ * the handler function for when the custom event comes. It's recommended
9
+ * to use `useCallback` for the function passed in here for performance
10
+ * reasons.
11
+ * The callback is optional in case you want to decouple sending event and
12
+ * handling event in the UI.
13
+ */
14
+ onEvent?: (data: T) => void;
15
+ /**
16
+ * function to handle errors happening during sending the event
17
+ */
18
+ handleError?: hooksErrHandler;
19
+ }
20
+ export interface useCustomEventResult<T> {
21
+ /**
22
+ * sends the event data to others in the room who will receive it in onEvent
23
+ */
24
+ sendEvent: (data: T) => void;
25
+ }
26
+ /**
27
+ * A generic function to implement [custom events](https://www.100ms.live/docs/javascript/v2/features/chat#custom-events) in your UI.
28
+ * The data to be sent to remote is expected to be a serializable JSON. The serialization
29
+ * and deserialization is taken care of by the hook.
30
+ */
31
+ export declare const useCustomEvent: <T>({ type, onEvent, handleError, }: useCustomEventInput<T>) => useCustomEventResult<T>;
@@ -39,6 +39,10 @@ export interface useVideoListInput {
39
39
  * will be filtered. If you wish to show all peers, pass false for this.
40
40
  */
41
41
  filterNonPublishingPeers?: boolean;
42
+ /**
43
+ * Height that would be subtracted from the parent's height to give the available height, use case: if your pagination is inside the parent component then offsetY would be the height of pagination
44
+ */
45
+ offsetY?: number;
42
46
  }
43
47
  export interface useVideoListTile extends TrackWithPeer {
44
48
  width: number;
@@ -61,4 +65,4 @@ export interface useVideoResult {
61
65
  * a list of pages with every page having a list of video tiles.
62
66
  * Please check the documentation of input and output types for more details.
63
67
  */
64
- export declare const useVideoList: ({ peers, maxTileCount, maxColCount, maxRowCount, includeScreenShareForPeer, aspectRatio, filterNonPublishingPeers, }: useVideoListInput) => useVideoResult;
68
+ export declare const useVideoList: ({ peers, maxTileCount, maxColCount, maxRowCount, includeScreenShareForPeer, aspectRatio, filterNonPublishingPeers, offsetY, }: useVideoListInput) => useVideoResult;
package/dist/index.cjs.js CHANGED
@@ -1 +1 @@
1
- var Fe=Object.create;var q=Object.defineProperty,Be=Object.defineProperties,ze=Object.getOwnPropertyDescriptor,qe=Object.getOwnPropertyDescriptors,Ge=Object.getOwnPropertyNames,oe=Object.getOwnPropertySymbols,je=Object.getPrototypeOf,re=Object.prototype.hasOwnProperty,Ue=Object.prototype.propertyIsEnumerable;var se=(o,e,t)=>e in o?q(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t,G=(o,e)=>{for(var t in e||(e={}))re.call(e,t)&&se(o,t,e[t]);if(oe)for(var t of oe(e))Ue.call(e,t)&&se(o,t,e[t]);return o},j=(o,e)=>Be(o,qe(e)),ie=o=>q(o,"__esModule",{value:!0});var Je=(o,e)=>{ie(o);for(var t in e)q(o,t,{get:e[t],enumerable:!0})},H=(o,e,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Ge(e))!re.call(o,s)&&s!=="default"&&q(o,s,{get:()=>e[s],enumerable:!(t=ze(e,s))||t.enumerable});return o},f=o=>H(ie(q(o!=null?Fe(je(o)):{},"default",o&&o.__esModule&&"default"in o?{get:()=>o.default,enumerable:!0}:{value:o,enumerable:!0})),o);var p=(o,e,t)=>new Promise((s,r)=>{var i=c=>{try{a(t.next(c))}catch(u){r(u)}},n=c=>{try{a(t.throw(c))}catch(u){r(u)}},a=c=>c.done?s(c.value):Promise.resolve(c.value).then(i,n);a((t=t.apply(o,e)).next())});Je(exports,{DeviceType:()=>k,HMSRoomProvider:()=>le,throwErrorHandler:()=>me,useAVToggle:()=>fe,useAudioLevelStyles:()=>Ae,useAutoplayError:()=>We,useDevices:()=>De,useHMSActions:()=>M,useHMSNotifications:()=>K,useHMSStatsStore:()=>de,useHMSStore:()=>d,useHMSVanillaStore:()=>L,useParticipantList:()=>Le,usePreviewJoin:()=>Se,useRecordingStreaming:()=>Ne,useRemoteAVToggle:()=>be,useScreenShare:()=>Me,useVideo:()=>pe,useVideoList:()=>Te});var P=f(require("react")),ue=f(require("@100mslive/hms-video-store")),U=f(require("zustand"));var Y=f(require("react")),Z=f(require("zustand/shallow"));var b;(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"})(b||(b={}));var w=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}}}};w.level=0;var C="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 ne(o){return(t,s=Z.default)=>{t||w.w("fetching full store without passing any selector may have a heavy performance impact on your website.");let r=(0,Y.useContext)(o);if(!r)throw new Error(C);return r.store(t,s)}}function ae(o){return(t,s=Z.default)=>{t||w.w("fetching full store without passing any selector may have a heavy performance impact on your website.");let r=(0,Y.useContext)(o);if(!r)throw new Error(C);let i=r.statsStore;return i==null?void 0:i(t,s)}}var ce=typeof window!="undefined";var O=(0,P.createContext)(null),y,le=({children:o,actions:e,store:t,notifications:s,stats:r,isHMSStatsOn:i=!1})=>{if(!y){let n=()=>{throw new Error("modifying store is not allowed")};if(e&&t)y={actions:e,store:(0,U.default)(j(G({},t),{setState:n,destroy:n}))},s&&(y.notifications=s),r&&(y.statsStore=(0,U.default)({getState:r.getState,subscribe:r.subscribe,setState:n,destroy:n}));else{let a=new ue.HMSReactiveStore;if(y={actions:a.getActions(),store:(0,U.default)(j(G({},a.getStore()),{setState:n,destroy:n})),notifications:a.getNotifications()},i){let c=a.getStats();y.statsStore=(0,U.default)({getState:c.getState,subscribe:c.subscribe,setState:n,destroy:n})}}}return(0,P.useEffect)(()=>{ce&&(window.addEventListener("beforeunload",()=>y.actions.leave()),window.addEventListener("onunload",()=>y.actions.leave()))},[]),P.default.createElement(O.Provider,{value:y},o)},d=ne(O),de=ae(O),L=()=>{let o=(0,P.useContext)(O);if(!o)throw new Error(C);return o.store},M=()=>{let o=(0,P.useContext)(O);if(!o)throw new Error(C);return o.actions},K=()=>{let o=(0,P.useContext)(O),[e,t]=(0,P.useState)(null);if(!o)throw new Error(C);return(0,P.useEffect)(()=>o.notifications?o.notifications.onNotification(r=>t(r)):void 0,[o.notifications]),e};var E=f(require("@100mslive/hms-video-store")),J=f(require("react"));var Ke="react-sdk",T=(o,e)=>w.e(Ke,e,o),me=o=>{throw o};var Se=({name:o="",token:e,metadata:t,handleError:s=T,initEndpoint:r,initialSettings:i})=>{let n=M(),a=d(E.selectRoomState),c=d(E.selectIsConnectedToRoom)||!1,u=a===E.HMSRoomState.Preview,S=(0,J.useMemo)(()=>({userName:o,authToken:e,metaData:t,rememberDeviceSelection:!0,settings:i,initEndpoint:r}),[o,e,t,r,i]),m=(0,J.useCallback)(()=>{(()=>p(void 0,null,function*(){if(!!e){a!==E.HMSRoomState.Disconnected&&(yield n.leave());try{yield n.preview(S)}catch(h){s(h,"preview")}}}))()},[n,s,e,a,S]),l=(0,J.useCallback)(()=>{if(!!e)try{n.join(S)}catch(h){s(h,"join")}},[n,S,s,e]);return{enableJoin:u,join:l,isConnected:c,preview:m}};var N=f(require("@100mslive/hms-video-store")),_=f(require("react"));var fe=(o=T)=>{let e=d(N.selectIsLocalAudioEnabled),t=d(N.selectIsLocalVideoEnabled),s=d(N.selectIsAllowedToPublish),r=M(),i=(0,_.useCallback)(()=>p(void 0,null,function*(){try{yield r.setLocalAudioEnabled(!e)}catch(a){o(a,"toggleAudio")}}),[r,e,o]),n=(0,_.useCallback)(()=>p(void 0,null,function*(){try{yield r.setLocalVideoEnabled(!t)}catch(a){o(a,"toggleVideo")}}),[r,t,o]);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}};var he=f(require("@100mslive/hms-video-store")),A=f(require("react")),ge=f(require("react-intersection-observer"));var pe=({trackId:o,attach:e})=>{let t=M(),s=(0,A.useRef)(null),r=d((0,he.selectTrackByID)(o)),{ref:i,inView:n}=(0,ge.useInView)({threshold:.5}),a=(0,A.useCallback)(c=>{s.current=c,i(c)},[i]);return(0,A.useEffect)(()=>{(()=>p(void 0,null,function*(){s.current&&(r==null?void 0:r.id)&&(n&&r.enabled&&e!==!1?yield t.attachVideo(r.id,s.current):yield t.detachVideo(r.id,s.current))}))()},[t,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,A.useEffect)(()=>()=>{(()=>p(void 0,null,function*(){if(s.current&&r)try{yield t.detachVideo(r.id,s.current)}catch(c){w.w("detach video error for track",r.id,c)}}))()},[]),{videoRef:a}};var W=f(require("@100mslive/hms-video-store"));var He=f(require("react")),Qe=o=>console.log("Error: ",o),Me=(o=Qe)=>{var n,a;let e=M(),t=d(W.selectIsLocalScreenShared),s=d(W.selectPeerScreenSharing),r=d((0,W.selectScreenSharesByPeerId)(s==null?void 0:s.id)),i=(0,He.useCallback)((c=!1)=>p(void 0,null,function*(){try{yield e.setScreenShareEnabled(!t,c)}catch(u){o(u)}}),[e,t,o]);return{amIScreenSharing:t,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 V=f(require("@100mslive/hms-video-store"));var Q=f(require("react"));var ve=(o,e,t)=>p(void 0,null,function*(){if(e)try{yield o.setRemoteTrackEnabled(e.id,!e.enabled)}catch(s){t(s,"remoteToggle")}}),be=(o,e,t=T)=>{let s=M(),r=d((0,V.selectTrackByID)(o)),i=d((0,V.selectTrackByID)(e)),n=d((0,V.selectAudioTrackVolume)(r==null?void 0:r.id)),a=d(V.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,S=(0,Q.useCallback)(()=>p(void 0,null,function*(){yield ve(s,r,t)}),[s,r,t]),m=(0,Q.useCallback)(()=>p(void 0,null,function*(){yield ve(s,i,t)}),[s,t,i]),l=(0,Q.useCallback)(h=>{r&&s.setVolume(h,r.id)},[s,r]);return{isAudioEnabled:!!(r==null?void 0:r.enabled),isVideoEnabled:!!(i==null?void 0:i.enabled),volume:n,toggleAudio:r&&u?S:void 0,toggleVideo:(i==null?void 0:i.source)==="regular"&&c?m:void 0,setVolume:r?l:void 0}};var xe=f(require("@100mslive/hms-video-store")),X=f(require("react"));var Xe=(o,e,t)=>o.reduce((s,r,i)=>{let n=Math.floor(i/e);return n>0&&t||(s[n]||(s[n]=[]),s[n].push(r)),s},[]),Pe=({elements:o,tilesInFirstPage:e,onlyOnePage:t,isLastPageDifferentFromFirstPage:s,defaultWidth:r,defaultHeight:i,lastPageWidth:n,lastPageHeight:a})=>{let c=Xe(o,e,t);return c.map((u,S)=>u.map(m=>{let l=S===c.length-1,h=s&&l?n:r,g=s&&l?a:i;return j(G({},m),{height:g,width:h})}))};function Ye(o){if(o.length===0)return null;let e={},t=o[0],s=1;for(let r=0;r<o.length;r++){let i=o[r];e[i]===null?e[i]=1:e[i]++,e[i]>s&&(t=i,s=e[i])}return t}var ke=o=>Ye(o.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 r,i;let t=(r=e.track)==null?void 0:r.width,s=(i=e.track)==null?void 0:i.height;return(t||1)/(s||1)})),$=(o,e,t,s,r)=>{if(o<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&&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=t,c=-1;if(i!==void 0)for(let u=a;u>0;u+=c){let S=Math.ceil(t/u),m=o/(u*i),l=e/S,h,g;m<=l?(h=o/u,g=h/i):(g=e/S,h=g*i);let v=h*g;v>n.area&&(n={area:v,width:h,height:g,rows:S,cols:u})}return n},Ze=({parentWidth:o,parentHeight:e,count:t,maxCount:s,aspectRatio:r})=>{let i=0,n=0,a=0,c=0,u=!1,S=0,m=0,l=Math.min(Math.ceil(Math.sqrt(t*(o/e)/(r.width/r.height))),s),h=o/l,g=h/(r.width/r.height);g>e&&(g=e,h=g/(r.height/r.width));let v=Math.floor(e/g);if(n=g,i=h,S=Math.min(t,v*l),m=t%(v*l),u=m>0&&t>v*l,u){let D=Math.min(Math.ceil(Math.sqrt(m*(o/e)/(r.width/r.height))),s),R=o/D,x=R/(r.width/r.height);x>e&&(x=e,R=x/(r.height/r.width)),c=x,a=R}return{tilesInFirstPage:S,defaultWidth:i,defaultHeight:n,lastPageWidth:a,lastPageHeight:c,isLastPageDifferentFromFirstPage:u}},_e=({parentWidth:o,parentHeight:e,count:t,maxCount:s,aspectRatio:r})=>{let i=0,n=0,a=0,c=0,u=!1,S=0,m=0,{width:l,height:h}=$(o,e,Math.min(t,s),r.width,r.height);if(i=l,n=h,S=Math.min(t,s),m=t%s,u=m>0&&t>s,u){let{width:g,height:v}=$(o,e,m,r.width,r.height);a=g,c=v}return{tilesInFirstPage:S,defaultWidth:i,defaultHeight:n,lastPageWidth:a,lastPageHeight:c,isLastPageDifferentFromFirstPage:u}},$e=({parentWidth:o,parentHeight:e,count:t,maxCount:s,aspectRatio:r})=>{let i=0,n=0,a=0,c=0,u=!1,S=0,m=0,l=Math.min(Math.ceil(Math.sqrt(t*(r.width/r.height)/(o/e))),s),h=e/l,g=h*(r.width/r.height),v=Math.floor(o/g);if(i=g,n=h,S=Math.min(t,l*v),m=t%(l*v),u=m>0&&t>l*v,u){let D=Math.min(Math.ceil(Math.sqrt(m*(r.width/r.height)/(o/e))),s),R=e/D,x=R*(r.width/r.height);c=R,a=x}return{tilesInFirstPage:S,defaultWidth:i,defaultHeight:n,lastPageWidth:a,lastPageHeight:c,isLastPageDifferentFromFirstPage:u}};function we({count:o,parentWidth:e,parentHeight:t,maxTileCount:s,maxRowCount:r,maxColCount:i,aspectRatio:n}){let a=0,c=0,u=0,S=0,m=!1,l=0;if(o===0)return{tilesInFirstPage:l,defaultWidth:a,defaultHeight:c,lastPageWidth:u,lastPageHeight:S,isLastPageDifferentFromFirstPage:m};if(s)({tilesInFirstPage:l,defaultWidth:a,defaultHeight:c,lastPageWidth:u,lastPageHeight:S,isLastPageDifferentFromFirstPage:m}=_e({parentWidth:e,parentHeight:t,count:o,maxCount:s,aspectRatio:n}));else if(r)({tilesInFirstPage:l,defaultWidth:a,defaultHeight:c,lastPageWidth:u,lastPageHeight:S,isLastPageDifferentFromFirstPage:m}=$e({parentWidth:e,parentHeight:t,count:o,maxCount:r,aspectRatio:n}));else if(i)({tilesInFirstPage:l,defaultWidth:a,defaultHeight:c,lastPageWidth:u,lastPageHeight:S,isLastPageDifferentFromFirstPage:m}=Ze({parentWidth:e,parentHeight:t,count:o,maxCount:i,aspectRatio:n}));else{let{width:h,height:g}=$(e,t,o,n.width,n.height);a=h,c=g,l=o}return{tilesInFirstPage:l,defaultWidth:a,defaultHeight:c,lastPageWidth:u,lastPageHeight:S,isLastPageDifferentFromFirstPage:m}}var Re=(o,e,t,s=!0)=>{if(!o||!e||!t)return[];let r=[];for(let i of o)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}),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&&r.push({track:e[a],peer:i})}return r};var ye=f(require("react-resize-detector")),et={aspectRatio:{width:1,height:1}},Te=({peers:o,maxTileCount:e,maxColCount:t,maxRowCount:s,includeScreenShareForPeer:r=()=>!1,aspectRatio:i=et.aspectRatio,filterNonPublishingPeers:n=!0})=>{let{width:a=0,height:c=0,ref:u}=(0,ye.useResizeDetector)(),m=L().getState(xe.selectTracksMap),l=Re(o,m,r,n),h=(0,X.useMemo)(()=>i||{width:ke(l)||1,height:1},[i,l]),g=l.length,{tilesInFirstPage:v,defaultWidth:D,defaultHeight:R,lastPageWidth:x,lastPageHeight:ee,isLastPageDifferentFromFirstPage:te}=(0,X.useMemo)(()=>we({count:g,parentWidth:Math.floor(a),parentHeight:Math.floor(c),maxTileCount:e,maxRowCount:s,maxColCount:t,aspectRatio:h}),[g,a,c,e,s,t,h]);return{pagesWithTiles:(0,X.useMemo)(()=>Pe({elements:l,tilesInFirstPage:v,onlyOnePage:!1,isLastPageDifferentFromFirstPage:te,defaultWidth:D,defaultHeight:R,lastPageWidth:x,lastPageHeight:ee}),[l,v,te,D,R,x,ee]),ref:u}};var Ie=f(require("react")),Ee=f(require("@100mslive/hms-video-store"));function Ae({trackId:o,getStyle:e,ref:t}){let s=L();(0,Ie.useEffect)(()=>s.subscribe(r=>{if(!t.current)return;let i=e(r);for(let n in i)t.current.style[n]=i[n]},(0,Ee.selectTrackAudioByID)(o)),[e,t,s,o])}var F=f(require("@100mslive/hms-video-store")),Ve=f(require("react"));var k;(function(s){s.videoInput="videoInput",s.audioInput="audioInput",s.audioOutput="audioOutput"})(k||(k={}));var De=(o=T)=>{let e=M(),t=d(F.selectDevices),s=d(F.selectLocalMediaSettings),r=d(F.selectIsAllowedToPublish),i={[k.audioOutput]:s.audioOutputDeviceId},n={[k.audioOutput]:t.audioOutput};r.video&&(n[k.videoInput]=t.videoInput,i[k.videoInput]=s.videoInputDeviceId),r.audio&&(n[k.audioInput]=t.audioInput,i[k.audioInput]=s.audioInputDeviceId);let a=(0,Ve.useCallback)(S=>p(void 0,[S],function*({deviceType:c,deviceId:u}){try{switch(c){case k.audioInput:yield e.setAudioSettings({deviceId:u});break;case k.videoInput:yield e.setVideoSettings({deviceId:u});break;case k.audioOutput:e.setAudioOutputDevice(u);break}}catch(m){o(m,"updateDevices")}}),[o,e]);return{allDevices:n,selectedDeviceIDs:i,updateDevice:a}};var Oe=f(require("react")),I=f(require("@100mslive/hms-video-store"));var Ce=o=>!o||!Array.isArray(o)||o.length===0?{}:o.reduce((e,t)=>(t.roleName&&(e[t.roleName]||(e[t.roleName]=[]),e[t.roleName].push(t)),e),{});var Le=()=>{let o=d(I.selectIsConnectedToRoom),e=d(o?I.selectPeers:I.selectRemotePeers),t=d(I.selectPeerCount),s=(0,Oe.useMemo)(()=>Ce(e),[e]);return{roles:Object.keys(s),participantsByRoles:s,peerCount:t,isConnected:o}};var B=f(require("@100mslive/hms-video-store"));var Ne=()=>{let o=d(B.selectRecordingState),e=d(B.selectRTMPState),t=d(B.selectHLSState),s=o.server.running,r=o.browser.running,i=o.hls.running,n=t.running||e.running,a=s||r||i;return{isServerRecordingOn:s,isBrowserRecordingOn:r,isHLSRecordingOn:i,isStreamingOn:n,isHLSRunning:t.running,isRTMPRunning:e.running,isRecordingOn:a}};var z=f(require("react"));var We=()=>{let o=K(),[e,t]=(0,z.useState)(""),s=M(),r=(0,z.useCallback)(()=>p(void 0,null,function*(){yield s.unblockAudio()}),[s]);return(0,z.useEffect)(()=>{var i,n;((i=o==null?void 0:o.data)==null?void 0:i.code)===3008&&t((n=o==null?void 0:o.data)==null?void 0:n.message)},[o]),{error:e,unblockAudio:r,resetError:()=>t("")}};H(exports,f(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},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 P=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}}}};P.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||P.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||P.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",w=(t,e)=>P.e($e,e,t),he=t=>{throw t};var pe=({name:t="",token:e,metadata:o,handleError:s=w,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=w)=>{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){P.w("detach video error for track",r.id,u)}}))()},[]),{videoRef:a}};var W=m(require("@100mslive/hms-video-store"));var be=m(require("react")),et=t=>console.log("Error: ",t),ke=(t=et)=>{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)}}),[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=w)=>{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 tt=(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=tt(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 ot(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=>ot(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},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,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}},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,{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}},it=({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}=st({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}=it({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}=rt({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")),nt={aspectRatio:{width:1,height:1}},Ae=({peers:t,maxTileCount:e,maxColCount:o,maxRowCount:s,includeScreenShareForPeer:r=()=>!1,aspectRatio:i=nt.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=w)=>{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=w})=>{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")));
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { HMSRoomProvider, useHMSStore, useHMSActions, useHMSNotifications, useHMSVanillaStore, useHMSStatsStore, } from './primitives/HmsRoomProvider';
1
+ export { HMSRoomProvider, useHMSStore, useHMSActions, useHMSNotifications, useHMSVanillaStore, useHMSVanillaNotifications, useHMSStatsStore, } from './primitives/HmsRoomProvider';
2
2
  export { usePreviewJoin } from './hooks/usePreviewJoin';
3
3
  export { useAVToggle } from './hooks/useAVToggle';
4
4
  export { useVideo } from './hooks/useVideo';
@@ -10,6 +10,7 @@ export { useDevices, DeviceType } from './hooks/useDevices';
10
10
  export { useParticipantList } from './hooks/useParticipantList';
11
11
  export { useRecordingStreaming } from './hooks/useRecordingStreaming';
12
12
  export { useAutoplayError } from './hooks/useAutoplayError';
13
+ export { useCustomEvent } from './hooks/useCustomEvent';
13
14
  export type { hooksErrHandler } from './hooks/types';
14
15
  export type { usePreviewInput, usePreviewResult } from './hooks/usePreviewJoin';
15
16
  export type { useVideoListInput, useVideoResult, useVideoListTile } from './hooks/useVideoList';
@@ -21,5 +22,6 @@ export type { useRecordingStreamingResult } from './hooks/useRecordingStreaming'
21
22
  export type { useParticipantListResult } from './hooks/useParticipantList';
22
23
  export type { useVideoInput, useVideoOutput } from './hooks/useVideo';
23
24
  export type { useAutoplayErrorResult } from './hooks/useAutoplayError';
25
+ export type { useCustomEventInput, useCustomEventResult } from './hooks/useCustomEvent';
24
26
  export { throwErrorHandler } from './utils/commons';
25
27
  export * from '@100mslive/hms-video-store';
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- var ie=Object.defineProperty,ne=Object.defineProperties;var ae=Object.getOwnPropertyDescriptors;var B=Object.getOwnPropertySymbols;var ce=Object.prototype.hasOwnProperty,ue=Object.prototype.propertyIsEnumerable;var z=(r,e,o)=>e in r?ie(r,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):r[e]=o,I=(r,e)=>{for(var o in e||(e={}))ce.call(e,o)&&z(r,o,e[o]);if(B)for(var o of B(e))ue.call(e,o)&&z(r,o,e[o]);return r},E=(r,e)=>ne(r,ae(e));var g=(r,e,o)=>new Promise((s,t)=>{var i=c=>{try{a(o.next(c))}catch(u){t(u)}},n=c=>{try{a(o.throw(c))}catch(u){t(u)}},a=c=>c.done?s(c.value):Promise.resolve(c.value).then(i,n);a((o=o.apply(r,e)).next())});import le,{createContext as de,useContext as D,useEffect as K,useState as me}from"react";import{HMSReactiveStore as Se}from"@100mslive/hms-video-store";import V from"zustand";import{useContext as q}from"react";import G 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 b=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}}}};b.level=0;var y="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 j(r){return(o,s=G)=>{o||b.w("fetching full store without passing any selector may have a heavy performance impact on your website.");let t=q(r);if(!t)throw new Error(y);return t.store(o,s)}}function U(r){return(o,s=G)=>{o||b.w("fetching full store without passing any selector may have a heavy performance impact on your website.");let t=q(r);if(!t)throw new Error(y);let i=t.statsStore;return i==null?void 0:i(o,s)}}var J=typeof window!="undefined";var T=de(null),w,fe=({children:r,actions:e,store:o,notifications:s,stats:t,isHMSStatsOn:i=!1})=>{if(!w){let n=()=>{throw new Error("modifying store is not allowed")};if(e&&o)w={actions:e,store:V(E(I({},o),{setState:n,destroy:n}))},s&&(w.notifications=s),t&&(w.statsStore=V({getState:t.getState,subscribe:t.subscribe,setState:n,destroy:n}));else{let a=new Se;if(w={actions:a.getActions(),store:V(E(I({},a.getStore()),{setState:n,destroy:n})),notifications:a.getNotifications()},i){let c=a.getStats();w.statsStore=V({getState:c.getState,subscribe:c.subscribe,setState:n,destroy:n})}}}return K(()=>{J&&(window.addEventListener("beforeunload",()=>w.actions.leave()),window.addEventListener("onunload",()=>w.actions.leave()))},[]),le.createElement(T.Provider,{value:w},r)},d=j(T),he=U(T),A=()=>{let r=D(T);if(!r)throw new Error(y);return r.store},H=()=>{let r=D(T);if(!r)throw new Error(y);return r.actions},C=()=>{let r=D(T),[e,o]=me(null);if(!r)throw new Error(y);return K(()=>r.notifications?r.notifications.onNotification(t=>o(t)):void 0,[r.notifications]),e};import{HMSRoomState as Q,selectIsConnectedToRoom as He,selectRoomState as Me}from"@100mslive/hms-video-store";import{useCallback as X,useMemo as ve}from"react";var ge="react-sdk",R=(r,e)=>b.e(ge,e,r),pe=r=>{throw r};var be=({name:r="",token:e,metadata:o,handleError:s=R,initEndpoint:t,initialSettings:i})=>{let n=H(),a=d(Me),c=d(He)||!1,u=a===Q.Preview,S=ve(()=>({userName:r,authToken:e,metaData:o,rememberDeviceSelection:!0,settings:i,initEndpoint:t}),[r,e,o,t,i]),m=X(()=>{(()=>g(void 0,null,function*(){if(!!e){a!==Q.Disconnected&&(yield n.leave());try{yield n.preview(S)}catch(f){s(f,"preview")}}}))()},[n,s,e,a,S]),l=X(()=>{if(!!e)try{n.join(S)}catch(f){s(f,"join")}},[n,S,s,e]);return{enableJoin:u,join:l,isConnected:c,preview:m}};import{selectIsAllowedToPublish as Pe,selectIsLocalAudioEnabled as ke,selectIsLocalVideoEnabled as we}from"@100mslive/hms-video-store";import{useCallback as Y}from"react";var Re=(r=R)=>{let e=d(ke),o=d(we),s=d(Pe),t=H(),i=Y(()=>g(void 0,null,function*(){try{yield t.setLocalAudioEnabled(!e)}catch(a){r(a,"toggleAudio")}}),[t,e,r]),n=Y(()=>g(void 0,null,function*(){try{yield t.setLocalVideoEnabled(!o)}catch(a){r(a,"toggleVideo")}}),[t,o,r]);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}};import{selectTrackByID as xe}from"@100mslive/hms-video-store";import{useCallback as ye,useEffect as Z,useRef as Te}from"react";import{useInView as Ie}from"react-intersection-observer";var Ee=({trackId:r,attach:e})=>{let o=H(),s=Te(null),t=d(xe(r)),{ref:i,inView:n}=Ie({threshold:.5}),a=ye(c=>{s.current=c,i(c)},[i]);return Z(()=>{(()=>g(void 0,null,function*(){s.current&&(t==null?void 0:t.id)&&(n&&t.enabled&&e!==!1?yield o.attachVideo(t.id,s.current):yield o.detachVideo(t.id,s.current))}))()},[o,n,s,t==null?void 0:t.id,t==null?void 0:t.enabled,t==null?void 0:t.deviceID,t==null?void 0:t.plugins,e]),Z(()=>()=>{(()=>g(void 0,null,function*(){if(s.current&&t)try{yield o.detachVideo(t.id,s.current)}catch(c){b.w("detach video error for track",t.id,c)}}))()},[]),{videoRef:a}};import{selectIsLocalScreenShared as Ae,selectPeerScreenSharing as Ve,selectScreenSharesByPeerId as De}from"@100mslive/hms-video-store";import{useCallback as Ce}from"react";var Oe=r=>console.log("Error: ",r),Le=(r=Oe)=>{var n,a;let e=H(),o=d(Ae),s=d(Ve),t=d(De(s==null?void 0:s.id)),i=Ce((c=!1)=>g(void 0,null,function*(){try{yield e.setScreenShareEnabled(!o,c)}catch(u){r(u)}}),[e,o,r]);return{amIScreenSharing:o,screenSharingPeerId:s==null?void 0:s.id,screenShareVideoTrackId:(n=t==null?void 0:t.video)==null?void 0:n.id,screenShareAudioTrackId:(a=t==null?void 0:t.audio)==null?void 0:a.id,toggleScreenShare:i}};import{selectAudioTrackVolume as Ne,selectPermissions as We,selectTrackByID as _}from"@100mslive/hms-video-store";import{useCallback as O}from"react";var $=(r,e,o)=>g(void 0,null,function*(){if(e)try{yield r.setRemoteTrackEnabled(e.id,!e.enabled)}catch(s){o(s,"remoteToggle")}}),Fe=(r,e,o=R)=>{let s=H(),t=d(_(r)),i=d(_(e)),n=d(Ne(t==null?void 0:t.id)),a=d(We),c=(i==null?void 0:i.enabled)?a==null?void 0:a.mute:a==null?void 0:a.unmute,u=(t==null?void 0:t.enabled)?a==null?void 0:a.mute:a==null?void 0:a.unmute,S=O(()=>g(void 0,null,function*(){yield $(s,t,o)}),[s,t,o]),m=O(()=>g(void 0,null,function*(){yield $(s,i,o)}),[s,o,i]),l=O(f=>{t&&s.setVolume(f,t.id)},[s,t]);return{isAudioEnabled:!!(t==null?void 0:t.enabled),isVideoEnabled:!!(i==null?void 0:i.enabled),volume:n,toggleAudio:t&&u?S:void 0,toggleVideo:(i==null?void 0:i.source)==="regular"&&c?m:void 0,setVolume:t?l:void 0}};import{selectTracksMap as Ue}from"@100mslive/hms-video-store";import{useMemo as N}from"react";var Be=(r,e,o)=>r.reduce((s,t,i)=>{let n=Math.floor(i/e);return n>0&&o||(s[n]||(s[n]=[]),s[n].push(t)),s},[]),ee=({elements:r,tilesInFirstPage:e,onlyOnePage:o,isLastPageDifferentFromFirstPage:s,defaultWidth:t,defaultHeight:i,lastPageWidth:n,lastPageHeight:a})=>{let c=Be(r,e,o);return c.map((u,S)=>u.map(m=>{let l=S===c.length-1,f=s&&l?n:t,h=s&&l?a:i;return E(I({},m),{height:h,width:f})}))};function ze(r){if(r.length===0)return null;let e={},o=r[0],s=1;for(let t=0;t<r.length;t++){let i=r[t];e[i]===null?e[i]=1:e[i]++,e[i]>s&&(o=i,s=e[i])}return o}var te=r=>ze(r.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 t,i;let o=(t=e.track)==null?void 0:t.width,s=(i=e.track)==null?void 0:i.height;return(o||1)/(s||1)})),L=(r,e,o,s,t)=>{if(r<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&&t&&s/t;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 S=Math.ceil(o/u),m=r/(u*i),l=e/S,f,h;m<=l?(f=r/u,h=f/i):(h=e/S,f=h*i);let p=f*h;p>n.area&&(n={area:p,width:f,height:h,rows:S,cols:u})}return n},qe=({parentWidth:r,parentHeight:e,count:o,maxCount:s,aspectRatio:t})=>{let i=0,n=0,a=0,c=0,u=!1,S=0,m=0,l=Math.min(Math.ceil(Math.sqrt(o*(r/e)/(t.width/t.height))),s),f=r/l,h=f/(t.width/t.height);h>e&&(h=e,f=h/(t.height/t.width));let p=Math.floor(e/h);if(n=h,i=f,S=Math.min(o,p*l),m=o%(p*l),u=m>0&&o>p*l,u){let x=Math.min(Math.ceil(Math.sqrt(m*(r/e)/(t.width/t.height))),s),P=r/x,k=P/(t.width/t.height);k>e&&(k=e,P=k/(t.height/t.width)),c=k,a=P}return{tilesInFirstPage:S,defaultWidth:i,defaultHeight:n,lastPageWidth:a,lastPageHeight:c,isLastPageDifferentFromFirstPage:u}},Ge=({parentWidth:r,parentHeight:e,count:o,maxCount:s,aspectRatio:t})=>{let i=0,n=0,a=0,c=0,u=!1,S=0,m=0,{width:l,height:f}=L(r,e,Math.min(o,s),t.width,t.height);if(i=l,n=f,S=Math.min(o,s),m=o%s,u=m>0&&o>s,u){let{width:h,height:p}=L(r,e,m,t.width,t.height);a=h,c=p}return{tilesInFirstPage:S,defaultWidth:i,defaultHeight:n,lastPageWidth:a,lastPageHeight:c,isLastPageDifferentFromFirstPage:u}},je=({parentWidth:r,parentHeight:e,count:o,maxCount:s,aspectRatio:t})=>{let i=0,n=0,a=0,c=0,u=!1,S=0,m=0,l=Math.min(Math.ceil(Math.sqrt(o*(t.width/t.height)/(r/e))),s),f=e/l,h=f*(t.width/t.height),p=Math.floor(r/h);if(i=h,n=f,S=Math.min(o,l*p),m=o%(l*p),u=m>0&&o>l*p,u){let x=Math.min(Math.ceil(Math.sqrt(m*(t.width/t.height)/(r/e))),s),P=e/x,k=P*(t.width/t.height);c=P,a=k}return{tilesInFirstPage:S,defaultWidth:i,defaultHeight:n,lastPageWidth:a,lastPageHeight:c,isLastPageDifferentFromFirstPage:u}};function oe({count:r,parentWidth:e,parentHeight:o,maxTileCount:s,maxRowCount:t,maxColCount:i,aspectRatio:n}){let a=0,c=0,u=0,S=0,m=!1,l=0;if(r===0)return{tilesInFirstPage:l,defaultWidth:a,defaultHeight:c,lastPageWidth:u,lastPageHeight:S,isLastPageDifferentFromFirstPage:m};if(s)({tilesInFirstPage:l,defaultWidth:a,defaultHeight:c,lastPageWidth:u,lastPageHeight:S,isLastPageDifferentFromFirstPage:m}=Ge({parentWidth:e,parentHeight:o,count:r,maxCount:s,aspectRatio:n}));else if(t)({tilesInFirstPage:l,defaultWidth:a,defaultHeight:c,lastPageWidth:u,lastPageHeight:S,isLastPageDifferentFromFirstPage:m}=je({parentWidth:e,parentHeight:o,count:r,maxCount:t,aspectRatio:n}));else if(i)({tilesInFirstPage:l,defaultWidth:a,defaultHeight:c,lastPageWidth:u,lastPageHeight:S,isLastPageDifferentFromFirstPage:m}=qe({parentWidth:e,parentHeight:o,count:r,maxCount:i,aspectRatio:n}));else{let{width:f,height:h}=L(e,o,r,n.width,n.height);a=f,c=h,l=r}return{tilesInFirstPage:l,defaultWidth:a,defaultHeight:c,lastPageWidth:u,lastPageHeight:S,isLastPageDifferentFromFirstPage:m}}var re=(r,e,o,s=!0)=>{if(!r||!e||!o)return[];let t=[];for(let i of r)if(i.videoTrack===void 0&&i.audioTrack&&e[i.audioTrack]?t.push({peer:i}):i.videoTrack&&e[i.videoTrack]?t.push({track:e[i.videoTrack],peer:i}):s||t.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&&t.push({track:e[a],peer:i})}return t};import{useResizeDetector as Je}from"react-resize-detector";var Ke={aspectRatio:{width:1,height:1}},Qe=({peers:r,maxTileCount:e,maxColCount:o,maxRowCount:s,includeScreenShareForPeer:t=()=>!1,aspectRatio:i=Ke.aspectRatio,filterNonPublishingPeers:n=!0})=>{let{width:a=0,height:c=0,ref:u}=Je(),m=A().getState(Ue),l=re(r,m,t,n),f=N(()=>i||{width:te(l)||1,height:1},[i,l]),h=l.length,{tilesInFirstPage:p,defaultWidth:x,defaultHeight:P,lastPageWidth:k,lastPageHeight:W,isLastPageDifferentFromFirstPage:F}=N(()=>oe({count:h,parentWidth:Math.floor(a),parentHeight:Math.floor(c),maxTileCount:e,maxRowCount:s,maxColCount:o,aspectRatio:f}),[h,a,c,e,s,o,f]);return{pagesWithTiles:N(()=>ee({elements:l,tilesInFirstPage:p,onlyOnePage:!1,isLastPageDifferentFromFirstPage:F,defaultWidth:x,defaultHeight:P,lastPageWidth:k,lastPageHeight:W}),[l,p,F,x,P,k,W]),ref:u}};import{useEffect as Xe}from"react";import{selectTrackAudioByID as Ye}from"@100mslive/hms-video-store";function Ze({trackId:r,getStyle:e,ref:o}){let s=A();Xe(()=>s.subscribe(t=>{if(!o.current)return;let i=e(t);for(let n in i)o.current.style[n]=i[n]},Ye(r)),[e,o,s,r])}import{selectDevices as _e,selectIsAllowedToPublish as $e,selectLocalMediaSettings as et}from"@100mslive/hms-video-store";import{useCallback as tt}from"react";var v;(function(s){s.videoInput="videoInput",s.audioInput="audioInput",s.audioOutput="audioOutput"})(v||(v={}));var ot=(r=R)=>{let e=H(),o=d(_e),s=d(et),t=d($e),i={[v.audioOutput]:s.audioOutputDeviceId},n={[v.audioOutput]:o.audioOutput};t.video&&(n[v.videoInput]=o.videoInput,i[v.videoInput]=s.videoInputDeviceId),t.audio&&(n[v.audioInput]=o.audioInput,i[v.audioInput]=s.audioInputDeviceId);let a=tt(S=>g(void 0,[S],function*({deviceType:c,deviceId:u}){try{switch(c){case v.audioInput:yield e.setAudioSettings({deviceId:u});break;case v.videoInput:yield e.setVideoSettings({deviceId:u});break;case v.audioOutput:e.setAudioOutputDevice(u);break}}catch(m){r(m,"updateDevices")}}),[r,e]);return{allDevices:n,selectedDeviceIDs:i,updateDevice:a}};import{useMemo as rt}from"react";import{selectIsConnectedToRoom as st,selectPeerCount as it,selectPeers as nt,selectRemotePeers as at}from"@100mslive/hms-video-store";var se=r=>!r||!Array.isArray(r)||r.length===0?{}:r.reduce((e,o)=>(o.roleName&&(e[o.roleName]||(e[o.roleName]=[]),e[o.roleName].push(o)),e),{});var ct=()=>{let r=d(st),e=d(r?nt:at),o=d(it),s=rt(()=>se(e),[e]);return{roles:Object.keys(s),participantsByRoles:s,peerCount:o,isConnected:r}};import{selectHLSState as ut,selectRecordingState as lt,selectRTMPState as dt}from"@100mslive/hms-video-store";var mt=()=>{let r=d(lt),e=d(dt),o=d(ut),s=r.server.running,t=r.browser.running,i=r.hls.running,n=o.running||e.running,a=s||t||i;return{isServerRecordingOn:s,isBrowserRecordingOn:t,isHLSRecordingOn:i,isStreamingOn:n,isHLSRunning:o.running,isRTMPRunning:e.running,isRecordingOn:a}};import{useCallback as St,useEffect as ft,useState as ht}from"react";var gt=()=>{let r=C(),[e,o]=ht(""),s=H(),t=St(()=>g(void 0,null,function*(){yield s.unblockAudio()}),[s]);return ft(()=>{var i,n;((i=r==null?void 0:r.data)==null?void 0:i.code)===3008&&o((n=r==null?void 0:r.data)==null?void 0:n.message)},[r]),{error:e,unblockAudio:t,resetError:()=>o("")}};export*from"@100mslive/hms-video-store";export{v as DeviceType,fe as HMSRoomProvider,pe as throwErrorHandler,Re as useAVToggle,Ze as useAudioLevelStyles,gt as useAutoplayError,ot as useDevices,H as useHMSActions,C as useHMSNotifications,he as useHMSStatsStore,d as useHMSStore,A as useHMSVanillaStore,ct as useParticipantList,be as usePreviewJoin,mt as useRecordingStreaming,Fe as useRemoteAVToggle,Le as useScreenShare,Ee as useVideo,Qe 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=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 b=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}}}};b.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||b.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||b.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",k=(r,e)=>b.e(Me,e,r),ve=r=>{throw r};var Pe=({name:r="",token:e,metadata:t,handleError:s=k,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=k)=>{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){b.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=>console.log("Error: ",r),Fe=(r=We)=>{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)}}),[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 Be,selectPermissions as ze,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")}}),Ge=(r,e,t=k)=>{let s=g(),o=l(ee(r)),i=l(ee(e)),n=l(Be(o==null?void 0:o.id)),a=l(ze),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 Ke}from"@100mslive/hms-video-store";import{useMemo as W}from"react";var qe=(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=qe(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 je(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=>je(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}},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,{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}},_e=({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}=Ue({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}=_e({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 Qe}from"react-resize-detector";var Xe={aspectRatio:{width:1,height:1}},Ye=({peers:r,maxTileCount:e,maxColCount:t,maxRowCount:s,includeScreenShareForPeer:o=()=>!1,aspectRatio:i=Xe.aspectRatio,filterNonPublishingPeers:n=!0,offsetY:a=0})=>{let{width:u=0,height:c=0,ref:d}=Qe(),S=A().getState(Ke),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 Ze}from"react";import{selectTrackAudioByID as $e}from"@100mslive/hms-video-store";function et({trackId:r,getStyle:e,ref:t}){let s=A();Ze(()=>s.subscribe(o=>{if(!t.current)return;let i=e(o);for(let n in i)t.current.style[n]=i[n]},$e(r)),[e,t,s,r])}import{selectDevices as tt,selectIsAllowedToPublish as ot,selectLocalMediaSettings as rt}from"@100mslive/hms-video-store";import{useCallback as st}from"react";var v;(function(s){s.videoInput="videoInput",s.audioInput="audioInput",s.audioOutput="audioOutput"})(v||(v={}));var it=(r=k)=>{let e=g(),t=l(tt),s=l(rt),o=l(ot),i={[v.audioOutput]:s.audioOutputDeviceId},n={[v.audioOutput]:t.audioOutput};o.video&&(n[v.videoInput]=t.videoInput,i[v.videoInput]=s.videoInputDeviceId),o.audio&&(n[v.audioInput]=t.audioInput,i[v.audioInput]=s.audioInputDeviceId);let a=st(d=>p(void 0,[d],function*({deviceType:u,deviceId:c}){try{switch(u){case v.audioInput:yield e.setAudioSettings({deviceId:c});break;case v.videoInput:yield e.setVideoSettings({deviceId:c});break;case v.audioOutput:e.setAudioOutputDevice(c);break}}catch(f){r(f,"updateDevices")}}),[r,e]);return{allDevices:n,selectedDeviceIDs:i,updateDevice:a}};import{useMemo as nt}from"react";import{selectIsConnectedToRoom as at,selectPeerCount as ct,selectPeers as ut,selectRemotePeers as lt}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 mt=()=>{let r=l(at),e=l(r?ut:lt),t=l(ct),s=nt(()=>ne(e),[e]);return{roles:Object.keys(s),participantsByRoles:s,peerCount:t,isConnected:r}};import{selectHLSState as dt,selectRecordingState as St,selectRTMPState as ft}from"@100mslive/hms-video-store";var ht=()=>{let r=l(St),e=l(ft),t=l(dt),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 pt,useEffect as gt,useState as Ht}from"react";import{HMSNotificationTypes as Mt}from"@100mslive/hms-video-store";var vt=()=>{let r=O(Mt.ERROR),[e,t]=Ht(""),s=g(),o=pt(()=>p(void 0,null,function*(){yield s.unblockAudio()}),[s]);return gt(()=>{(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 bt,useEffect as ae}from"react";import{HMSNotificationTypes as kt}from"@100mslive/hms-video-store";var Rt=({type:r,onEvent:e,handleError:t=k})=>{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")}},kt.NEW_MESSAGE):void 0,[o,r,e,t]),{sendEvent:bt(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{v as DeviceType,ge as HMSRoomProvider,ve as throwErrorHandler,ye as useAVToggle,et as useAudioLevelStyles,vt as useAutoplayError,Rt as useCustomEvent,it as useDevices,g as useHMSActions,O as useHMSNotifications,He as useHMSStatsStore,l as useHMSStore,D as useHMSVanillaNotifications,A as useHMSVanillaStore,mt as useParticipantList,Pe as usePreviewJoin,ht as useRecordingStreaming,Ge as useRemoteAVToggle,Fe as useScreenShare,Ce as useVideo,Ye as useVideoList};
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { HMSStore, HMSActions, HMSNotification, HMSNotifications, HMSStatsStore, HMSStats, HMSStoreWrapper } from '@100mslive/hms-video-store';
2
+ import { HMSStore, HMSActions, HMSNotification, HMSNotifications, HMSStatsStore, HMSStats, HMSStoreWrapper, HMSNotificationTypes } from '@100mslive/hms-video-store';
3
3
  export interface HMSRoomProviderProps {
4
4
  actions?: HMSActions;
5
5
  store?: HMSStoreWrapper;
@@ -36,9 +36,13 @@ export declare const useHMSStatsStore: <StateSlice>(selector: import("zustand").
36
36
  * For almost every case, `useHMSStore` would get the job done.
37
37
  */
38
38
  export declare const useHMSVanillaStore: () => import("./store").IHMSReactStore<HMSStore>;
39
+ export declare const useHMSVanillaNotifications: () => HMSNotifications | undefined;
39
40
  export declare const useHMSActions: () => HMSActions;
40
41
  /**
41
42
  * `useHMSNotifications` is a read only hook which gives the latest notification(HMSNotification) received.
43
+ * @param type can be a string or an array of string for the types of notifications to listen to. If an array is passed
44
+ * either declare it outside the functional component or use a useMemo to make sure its reference stays same across
45
+ * rerenders for performance reasons.
42
46
  */
43
- export declare const useHMSNotifications: () => HMSNotification | null;
47
+ export declare const useHMSNotifications: (type?: HMSNotificationTypes | HMSNotificationTypes[] | undefined) => HMSNotification | null;
44
48
  export declare const useIsHMSStatsOn: () => boolean;
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.8-alpha.0",
7
+ "version": "0.0.8-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.91-alpha.0",
35
+ "@100mslive/hms-video-store": "0.2.91-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": "f1a8532577823a660faf599badb0697ec4d498b2"
40
+ "gitHead": "831204de58a9f92fa9376592bddd3ea1ee47f1cb"
41
41
  }