@100mslive/react-sdk 0.4.3-alpha.2 → 0.4.3

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.
Files changed (67) hide show
  1. package/dist/hooks/useAVToggle.js +1 -1
  2. package/dist/hooks/useAVToggle.js.map +1 -1
  3. package/dist/hooks/useAudioLevelStyles.js.map +1 -1
  4. package/dist/hooks/useAutoplayError.js +1 -1
  5. package/dist/hooks/useAutoplayError.js.map +1 -1
  6. package/dist/hooks/useCustomEvent.js +1 -1
  7. package/dist/hooks/useCustomEvent.js.map +1 -1
  8. package/dist/hooks/useDevices.js +1 -1
  9. package/dist/hooks/useDevices.js.map +1 -1
  10. package/dist/hooks/useParticipantList.js.map +1 -1
  11. package/dist/hooks/useParticipants.js +1 -1
  12. package/dist/hooks/useParticipants.js.map +1 -1
  13. package/dist/hooks/usePreviewJoin.js +1 -1
  14. package/dist/hooks/usePreviewJoin.js.map +1 -1
  15. package/dist/hooks/useRecordingStreaming.js.map +1 -1
  16. package/dist/hooks/useRemoteAVToggle.js +1 -1
  17. package/dist/hooks/useRemoteAVToggle.js.map +1 -1
  18. package/dist/hooks/useScreenShare.js +1 -1
  19. package/dist/hooks/useScreenShare.js.map +1 -1
  20. package/dist/hooks/useVideo.js +1 -1
  21. package/dist/hooks/useVideo.js.map +1 -1
  22. package/dist/hooks/useVideoList.js.map +1 -1
  23. package/dist/index.cjs.js +1 -1
  24. package/dist/index.cjs.js.map +1 -1
  25. package/dist/{packages/react-sdk/node_modules → node_modules}/zustand/esm/shallow.js +0 -0
  26. package/dist/node_modules/zustand/esm/shallow.js.map +1 -0
  27. package/dist/package.json.js +2 -0
  28. package/dist/package.json.js.map +1 -0
  29. package/dist/primitives/HmsRoomProvider.js +1 -1
  30. package/dist/primitives/HmsRoomProvider.js.map +1 -1
  31. package/dist/primitives/store.js +1 -1
  32. package/dist/primitives/store.js.map +1 -1
  33. package/dist/utils/commons.js.map +1 -1
  34. package/dist/utils/groupBy.js.map +1 -1
  35. package/dist/utils/isBrowser.js.map +1 -1
  36. package/dist/utils/layout.js +1 -1
  37. package/dist/utils/layout.js.map +1 -1
  38. package/dist/utils/logger.js +1 -1
  39. package/dist/utils/logger.js.map +1 -1
  40. package/package.json +4 -3
  41. package/src/primitives/HmsRoomProvider.ts +2 -1
  42. package/dist/hooks/types.d.ts +0 -6
  43. package/dist/hooks/useAVToggle.d.ts +0 -24
  44. package/dist/hooks/useAudioLevelStyles.d.ts +0 -15
  45. package/dist/hooks/useAutoplayError.d.ts +0 -17
  46. package/dist/hooks/useCustomEvent.d.ts +0 -58
  47. package/dist/hooks/useDevices.d.ts +0 -40
  48. package/dist/hooks/useParticipantList.d.ts +0 -13
  49. package/dist/hooks/useParticipants.d.ts +0 -42
  50. package/dist/hooks/usePreviewJoin.d.ts +0 -58
  51. package/dist/hooks/useRecordingStreaming.d.ts +0 -10
  52. package/dist/hooks/useRemoteAVToggle.d.ts +0 -36
  53. package/dist/hooks/useScreenShare.d.ts +0 -40
  54. package/dist/hooks/useVideo.d.ts +0 -27
  55. package/dist/hooks/useVideoList.d.ts +0 -68
  56. package/dist/index.d.ts +0 -29
  57. package/dist/node_modules/tslib/tslib.es6.js +0 -2
  58. package/dist/node_modules/tslib/tslib.es6.js.map +0 -1
  59. package/dist/packages/react-sdk/node_modules/zustand/esm/shallow.js.map +0 -1
  60. package/dist/primitives/HmsRoomProvider.d.ts +0 -49
  61. package/dist/primitives/store.d.ts +0 -15
  62. package/dist/primitives/types.d.ts +0 -5
  63. package/dist/utils/commons.d.ts +0 -7
  64. package/dist/utils/groupBy.d.ts +0 -15
  65. package/dist/utils/isBrowser.d.ts +0 -1
  66. package/dist/utils/layout.d.ts +0 -116
  67. package/dist/utils/logger.d.ts +0 -17
@@ -1,2 +1,2 @@
1
- import{__awaiter as o}from"../node_modules/tslib/tslib.es6.js";import{selectIsLocalAudioEnabled as i,selectIsLocalVideoEnabled as d,selectIsAllowedToPublish as e}from"@100mslive/hms-video-store";import{useCallback as t}from"react";import{useHMSStore as l,useHMSActions as r}from"../primitives/HmsRoomProvider.js";import{logErrorHandler as s}from"../utils/commons.js";const m=(m=s)=>{const n=l(i),v=l(d),c=l(e),a=r(),u=t((()=>o(void 0,void 0,void 0,(function*(){try{yield a.setLocalAudioEnabled(!n)}catch(o){m(o,"toggleAudio")}}))),[a,n,m]),g=t((()=>o(void 0,void 0,void 0,(function*(){try{yield a.setLocalVideoEnabled(!v)}catch(o){m(o,"toggleVideo")}}))),[a,v,m]);return{isLocalAudioEnabled:n,isLocalVideoEnabled:v,toggleAudio:(null==c?void 0:c.audio)?u:void 0,toggleVideo:(null==c?void 0:c.video)?g:void 0}};export{m as useAVToggle};
1
+ import{selectIsLocalAudioEnabled as o,selectIsLocalVideoEnabled as i,selectIsAllowedToPublish as t}from"@100mslive/hms-video-store";import{useCallback as e}from"react";import{useHMSStore as d,useHMSActions as a}from"../primitives/HmsRoomProvider.js";import{logErrorHandler as l}from"../utils/commons.js";const r=(r=l)=>{const s=d(o),m=d(i),c=d(t),n=a(),u=e((async()=>{try{await n.setLocalAudioEnabled(!s)}catch(o){r(o,"toggleAudio")}}),[n,s,r]),v=e((async()=>{try{await n.setLocalVideoEnabled(!m)}catch(o){r(o,"toggleVideo")}}),[n,m,r]);return{isLocalAudioEnabled:s,isLocalVideoEnabled:m,toggleAudio:(null==c?void 0:c.audio)?u:void 0,toggleVideo:(null==c?void 0:c.video)?v:void 0}};export{r as useAVToggle};
2
2
  //# sourceMappingURL=useAVToggle.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useAVToggle.js","sources":["../../src/hooks/useAVToggle.ts"],"sourcesContent":[null],"names":["useAVToggle","handleError","logErrorHandler","isLocalAudioEnabled","useHMSStore","selectIsLocalAudioEnabled","isLocalVideoEnabled","selectIsLocalVideoEnabled","isAllowedToPublish","selectIsAllowedToPublish","actions","useHMSActions","toggleAudio","useCallback","__awaiter","setLocalAudioEnabled","err","toggleVideo","setLocalVideoEnabled","audio","video"],"mappings":"+WAiCa,MAAAA,EAAc,CAACC,EAA+BC,KACzD,MAAMC,EAAsBC,EAAYC,GAClCC,EAAsBF,EAAYG,GAClCC,EAAqBJ,EAAYK,GACjCC,EAAUC,IAEVC,EAAcC,GAAY,IAAWC,OAAA,OAAA,OAAA,GAAA,YACrC,UACIJ,EAAQK,sBAAsBZ,EAEV,CAFU,MAC7Ba,GACPf,EAAYe,EAAc,cAAA,CAE3B,KAAA,CAACN,EAASP,EAAqBF,IAE5BgB,EAAcJ,GAAY,IAAWC,OAAA,OAAA,OAAA,GAAA,YACrC,UACIJ,EAAQQ,sBAAsBZ,EAEV,CAFU,MAC7BU,GACPf,EAAYe,EAAc,cAAA,CAE3B,KAAA,CAACN,EAASJ,EAAqBL,IAE3B,MAAA,CACLE,sBACAG,sBACAM,4BAAaJ,EAAoBW,OAAQP,OAAc,EACvDK,4BAAaT,EAAoBY,OAAQH,OAAc,EAAA"}
1
+ {"version":3,"file":"useAVToggle.js","sources":["../../src/hooks/useAVToggle.ts"],"sourcesContent":["import {\n selectIsAllowedToPublish,\n selectIsLocalAudioEnabled,\n selectIsLocalVideoEnabled,\n} from '@100mslive/hms-video-store';\nimport { useCallback } from 'react';\nimport { useHMSActions, useHMSStore } from '../primitives/HmsRoomProvider';\nimport { logErrorHandler } from '../utils/commons';\nimport { hooksErrHandler } from '../hooks/types';\n\nexport interface useAVToggleResult {\n /**\n * true if unmuted and vice versa\n */\n isLocalAudioEnabled: boolean;\n isLocalVideoEnabled: boolean;\n /**\n * use this function to toggle audio state, the function will only be present if the user\n * has permission to unmute audio\n */\n toggleAudio?: () => void;\n /**\n * use this function to toggle video state, the function will only be present if the user\n * has permission to unmute video\n */\n toggleVideo?: () => void;\n}\n\n/**\n * Use this hook to implement mute/unmute for audio and video.\n * isAllowedToPublish can be used to decide whether to show the toggle buttons in the UI.\n * @param handleError to handle any error during toggle of audio/video\n */\nexport const useAVToggle = (handleError: hooksErrHandler = logErrorHandler): useAVToggleResult => {\n const isLocalAudioEnabled = useHMSStore(selectIsLocalAudioEnabled);\n const isLocalVideoEnabled = useHMSStore(selectIsLocalVideoEnabled);\n const isAllowedToPublish = useHMSStore(selectIsAllowedToPublish);\n const actions = useHMSActions();\n\n const toggleAudio = useCallback(async () => {\n try {\n await actions.setLocalAudioEnabled(!isLocalAudioEnabled);\n } catch (err) {\n handleError(err as Error, 'toggleAudio');\n }\n }, [actions, isLocalAudioEnabled, handleError]);\n\n const toggleVideo = useCallback(async () => {\n try {\n await actions.setLocalVideoEnabled(!isLocalVideoEnabled);\n } catch (err) {\n handleError(err as Error, 'toggleVideo');\n }\n }, [actions, isLocalVideoEnabled, handleError]);\n\n return {\n isLocalAudioEnabled,\n isLocalVideoEnabled,\n toggleAudio: isAllowedToPublish?.audio ? toggleAudio : undefined,\n toggleVideo: isAllowedToPublish?.video ? toggleVideo : undefined,\n };\n};\n"],"names":["useAVToggle","handleError","logErrorHandler","isLocalAudioEnabled","useHMSStore","selectIsLocalAudioEnabled","isLocalVideoEnabled","selectIsLocalVideoEnabled","isAllowedToPublish","selectIsAllowedToPublish","actions","useHMSActions","toggleAudio","useCallback","async","setLocalAudioEnabled","err","toggleVideo","setLocalVideoEnabled","audio","video"],"mappings":"gTAiCa,MAAAA,EAAc,CAACC,EAA+BC,KACzD,MAAMC,EAAsBC,EAAYC,GAClCC,EAAsBF,EAAYG,GAClCC,EAAqBJ,EAAYK,GACjCC,EAAUC,IAEVC,EAAcC,GAAYC,UAC1B,UACIJ,EAAQK,sBAAsBZ,EAEV,CAFU,MAC7Ba,GACPf,EAAYe,EAAc,cAAA,IAE3B,CAACN,EAASP,EAAqBF,IAE5BgB,EAAcJ,GAAYC,UAC1B,UACIJ,EAAQQ,sBAAsBZ,EAEV,CAFU,MAC7BU,GACPf,EAAYe,EAAc,cAAA,IAE3B,CAACN,EAASJ,EAAqBL,IAE3B,MAAA,CACLE,sBACAG,sBACAM,aAAiC,MAAAJ,OAAA,EAAAA,EAAAW,OAAQP,OAAc,EACvDK,aAAiC,MAAAT,OAAA,EAAAA,EAAAY,OAAQH,OAAc,EAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"useAudioLevelStyles.js","sources":["../../src/hooks/useAudioLevelStyles.ts"],"sourcesContent":[null],"names":["useAudioLevelStyles","trackId","getStyle","ref","store","useHMSVanillaStore","useEffect","subscribe","level","current","styles","key","style","selectTrackAudioByID"],"mappings":"0KAaM,SAA8BA,GAAAC,QAClCA,EACAC,SAAAA,EAAAC,IACAA,IAMA,MAAMC,EAAQC,IAEZC,GAAA,IACEF,EAAMG,WAAkBC,IAClB,IAACL,EAAIM,QACP,OAEF,MAAMC,EAASR,EAASM,GACxB,IAAA,MAAWG,KAAOD,EACZP,EAAAM,QAAQG,MAAMD,GAAOD,EAAOC,EAAA,GAEjCE,EAAqBZ,KAC1B,CAACC,EAAUC,EAAKC,EAAOH,GAAA"}
1
+ {"version":3,"file":"useAudioLevelStyles.js","sources":["../../src/hooks/useAudioLevelStyles.ts"],"sourcesContent":["import React, { useEffect } from 'react';\nimport { selectTrackAudioByID } from '@100mslive/hms-video-store';\nimport { useHMSVanillaStore } from '../primitives/HmsRoomProvider';\n\n/**\n * This hook can be used to apply css properties on an element based on the current audio level for the passed in track.\n * It doesn't return the audio level as it's optimised for performance. As audio level could be changing frequently we\n * want to minimise the number of components an audio level change causes to re render.\n * An e.g. use of this hook will be to apply box-shadow on parent tile based on audio level.\n * @param trackId is the audio track id for which audio level needs to be used\n * @param getStyle is a function which can take in current audio level and return the style to apply for the ref\n * @param ref is the ref of the element on which you want the css to apply\n */\nexport function useAudioLevelStyles({\n trackId,\n getStyle,\n ref,\n}: {\n trackId?: string;\n getStyle: (level: number) => Record<string, string>;\n ref: React.RefObject<any>;\n}) {\n const store = useHMSVanillaStore();\n useEffect(\n () =>\n store.subscribe(level => {\n if (!ref.current) {\n return;\n }\n const styles = getStyle(level);\n for (const key in styles) {\n ref.current.style[key] = styles[key];\n }\n }, selectTrackAudioByID(trackId)),\n [getStyle, ref, store, trackId],\n );\n}\n"],"names":["useAudioLevelStyles","trackId","getStyle","ref","store","useHMSVanillaStore","useEffect","subscribe","level","current","styles","key","style","selectTrackAudioByID"],"mappings":"0KAaO,SAA6BA,GAAAC,QAClCA,EAAAC,SACAA,EAAAC,IACAA,IAMA,MAAMC,EAAQC,IAEZC,GAAA,IACEF,EAAMG,WAAmBC,IACnB,IAACL,EAAIM,QACP,OAEF,MAAMC,EAASR,EAASM,GACxB,IAAA,MAAWG,KAAOD,EACZP,EAAAM,QAAQG,MAAMD,GAAOD,EAAOC,EAAA,GAEjCE,EAAqBZ,KAC1B,CAACC,EAAUC,EAAKC,EAAOH,GAAA"}
@@ -1,2 +1,2 @@
1
- import{__awaiter as o}from"../node_modules/tslib/tslib.es6.js";import{useState as r,useCallback as i,useEffect as e}from"react";import{HMSNotificationTypes as t}from"@100mslive/hms-video-store";import{useHMSNotifications as s,useHMSActions as d}from"../primitives/HmsRoomProvider.js";const m=()=>{const m=s(t.ERROR),[l,n]=r(""),u=d(),v=i((()=>o(void 0,void 0,void 0,(function*(){yield u.unblockAudio()}))),[u]);return e((()=>{3008===(null==m?void 0:m.data.code)&&n(null==m?void 0:m.data.message)}),[m]),{error:l,unblockAudio:v,resetError:()=>n("")}};export{m as useAutoplayError};
1
+ import{useState as o,useCallback as r,useEffect as e}from"react";import{HMSNotificationTypes as i}from"@100mslive/hms-video-store";import{useHMSNotifications as t,useHMSActions as m}from"../primitives/HmsRoomProvider.js";const s=()=>{const s=t(i.ERROR),[a,d]=o(""),n=m(),c=r((async()=>{await n.unblockAudio()}),[n]);return e((()=>{3008===(null==s?void 0:s.data.code)&&d(null==s?void 0:s.data.message)}),[s]),{error:a,unblockAudio:c,resetError:()=>d("")}};export{s as useAutoplayError};
2
2
  //# sourceMappingURL=useAutoplayError.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useAutoplayError.js","sources":["../../src/hooks/useAutoplayError.ts"],"sourcesContent":[null],"names":["useAutoplayError","notification","useHMSNotifications","HMSNotificationTypes","ERROR","error","setError","useState","actions","useHMSActions","unblockAudio","useCallback","__awaiter","useEffect","data","code","message","resetError"],"mappings":"4RAwBO,MAAMA,EAAmB,KACxB,MAAAC,EAAeC,EAAoBC,EAAqBC,QACvDC,EAAOC,GAAYC,EAAS,IAC7BC,EAAUC,IAEVC,EAAeC,GAAY,IAAWC,OAAA,OAAA,OAAA,GAAA,kBACpCJ,EAAQE,cAAA,KACb,CAACF,IAQJ,OANAK,GAAU,KACwB,QAA5BZ,aAAA,EAAAA,EAAca,KAAKC,OACrBT,EAASL,aAAY,EAAZA,EAAca,KAAKE,QAAA,GAE7B,CAACf,IAEG,CAAEI,QAAOK,eAAcO,WAAY,IAAMX,EAAS,IAAA"}
1
+ {"version":3,"file":"useAutoplayError.js","sources":["../../src/hooks/useAutoplayError.ts"],"sourcesContent":["import { useCallback, useEffect, useState } from 'react';\nimport { HMSNotificationTypes } from '@100mslive/hms-video-store';\nimport { useHMSActions, useHMSNotifications } from '../primitives/HmsRoomProvider';\n\nexport interface useAutoplayErrorResult {\n /*\n * Autoplay error message\n */\n error: string;\n /**\n * call this method on a UI element click to unblock the blocked audio autoplay.\n */\n unblockAudio: () => Promise<void>;\n /**\n * Call this method to reset(hide) the UI that is rendered when there was an error\n */\n resetError: () => void;\n}\n\n/**\n * Use this hook to show a UI(modal or a toast) when autoplay is blocked by browser and allow the user to\n * unblock the browser autoplay block\n * @returns {useAutoplayErrorResult}\n */\nexport const useAutoplayError = (): useAutoplayErrorResult => {\n const notification = useHMSNotifications(HMSNotificationTypes.ERROR);\n const [error, setError] = useState('');\n const actions = useHMSActions();\n\n const unblockAudio = useCallback(async () => {\n await actions.unblockAudio();\n }, [actions]);\n\n useEffect(() => {\n if (notification?.data.code === 3008) {\n setError(notification?.data.message);\n }\n }, [notification]);\n\n return { error, unblockAudio, resetError: () => setError('') };\n};\n"],"names":["useAutoplayError","notification","useHMSNotifications","HMSNotificationTypes","ERROR","error","setError","useState","actions","useHMSActions","unblockAudio","useCallback","async","useEffect","data","code","message","resetError"],"mappings":"6NAwBO,MAAMA,EAAmB,KACxB,MAAAC,EAAeC,EAAoBC,EAAqBC,QACvDC,EAAOC,GAAYC,EAAS,IAC7BC,EAAUC,IAEVC,EAAeC,GAAYC,gBACzBJ,EAAQE,cAAA,GACb,CAACF,IAQJ,OANAK,GAAU,KACwB,QAA5B,MAAAZ,OAAA,EAAAA,EAAca,KAAKC,OACrBT,QAASL,WAAca,KAAKE,QAAA,GAE7B,CAACf,IAEG,CAAEI,QAAOK,eAAcO,WAAY,IAAMX,EAAS,IAAA"}
@@ -1,2 +1,2 @@
1
- import{__awaiter as e}from"../node_modules/tslib/tslib.es6.js";import{useHMSActions as s,useHMSVanillaNotifications as o}from"../primitives/HmsRoomProvider.js";import{useEffect as r,useCallback as t}from"react";import{HMSNotificationTypes as i}from"@100mslive/hms-video-store";import{logErrorHandler as n}from"../utils/commons.js";const m=({type:m,json:d=!0,onEvent:a,handleError:l=n})=>{const c=s(),p=o();r((()=>{c.ignoreMessageTypes([m])}),[c,m]),r((()=>{if(!p)return;return p.onNotification((e=>{const s=e.data;if(s&&s.type===m)try{const e=d?JSON.parse(s.message):s.message;null==a||a(e)}catch(e){l(e,"handleCustomEvent")}}),i.NEW_MESSAGE)}),[p,m,d,a,l]);return{sendEvent:t(((s,o)=>e(void 0,void 0,void 0,(function*(){try{const e=((e,s)=>s?JSON.stringify(e||""):e)(s,d);o&&Array.isArray(null==o?void 0:o.roleNames)?yield c.sendGroupMessage(e,o.roleNames,m):"string"==typeof(null==o?void 0:o.peerId)?yield c.sendDirectMessage(e,o.peerId,m):yield c.sendBroadcastMessage(e,m),null==a||a(s)}catch(e){l(e,"sendCustomEvent")}}))),[c,l,a,m,d])}};export{m as useCustomEvent};
1
+ import{useHMSActions as e,useHMSVanillaNotifications as s}from"../primitives/HmsRoomProvider.js";import{useEffect as r,useCallback as t}from"react";import{HMSNotificationTypes as o}from"@100mslive/hms-video-store";import{logErrorHandler as n}from"../utils/commons.js";const a=({type:a,json:i=!0,onEvent:m,handleError:c=n})=>{const d=e(),l=s();r((()=>{d.ignoreMessageTypes([a])}),[d,a]),r((()=>{if(!l)return;return l.onNotification((e=>{const s=e.data;if(s&&s.type===a)try{const e=i?JSON.parse(s.message):s.message;null==m||m(e)}catch(e){c(e,"handleCustomEvent")}}),o.NEW_MESSAGE)}),[l,a,i,m,c]);return{sendEvent:t((async(e,s)=>{try{const r=((e,s)=>s?JSON.stringify(e||""):e)(e,i);s&&Array.isArray(null==s?void 0:s.roleNames)?await d.sendGroupMessage(r,s.roleNames,a):"string"==typeof(null==s?void 0:s.peerId)?await d.sendDirectMessage(r,s.peerId,a):await d.sendBroadcastMessage(r,a),null==m||m(e)}catch(e){c(e,"sendCustomEvent")}}),[d,c,m,a,i])}};export{a as useCustomEvent};
2
2
  //# sourceMappingURL=useCustomEvent.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useCustomEvent.js","sources":["../../src/hooks/useCustomEvent.ts"],"sourcesContent":[null],"names":["useCustomEvent","type","json","onEvent","handleError","logErrorHandler","actions","useHMSActions","notifications","useHMSVanillaNotifications","useEffect","ignoreMessageTypes","onNotification","notification","msg","data","JSON","parse","message","err","HMSNotificationTypes","NEW_MESSAGE","sendEvent","useCallback","receiver","__awaiter","dataStr","stringify","stringifyData","Array","isArray","roleNames","sendGroupMessage","peerId","sendDirectMessage","sendBroadcastMessage"],"mappings":"2UA2DA,MAOaA,EAAiB,EAC5BC,OACAC,QAAO,EACPC,UACAC,cAAcC,MAEd,MAAMC,EAAUC,IACVC,EAAgBC,IAEtBC,GAAU,KAERJ,EAAQK,mBAAmB,CAACV,GAAA,GAC3B,CAACK,EAASL,IAGbS,GAAU,KACR,IAAKF,EACH,OAaK,OAXaA,EAAcI,gBAA8BC,IAC9D,MAAMC,EAAMD,EAAaE,KACrB,GAAAD,GAAOA,EAAIb,OAASA,EAClB,IACF,MAAMc,EAAOb,EAAOc,KAAKC,MAAMH,EAAII,SAAWJ,EAAII,QAClDf,SAAAA,EAAUY,EAEgB,CAFhB,MACHI,GACPf,EAAYe,EAAc,oBAAA,CAAA,GAG7BC,EAAqBC,YACjB,GACN,CAACb,EAAeP,EAAMC,EAAMC,EAASC,IAsBxC,MAAO,CAAEkB,UAnBSC,GAChB,CAAOR,EAASS,IAA4BC,OAAA,OAAA,OAAA,GAAA,YACtC,IACI,MAAAC,EA5CQ,EAAIX,EAASb,IAAmBA,EAAOc,KAAKW,UAAUZ,GAAQ,IAAOA,EA4CnEa,CAAiBb,EAAMb,GACnCsB,GAAYK,MAAMC,QAAQN,aAAA,EAAAA,EAAUO,iBAChCzB,EAAQ0B,iBAAiBN,EAASF,EAASO,UAAW9B,GACvB,8BAAb,EAARuB,EAAUS,cACpB3B,EAAQ4B,kBAAkBR,EAASF,EAASS,OAAQhC,SAEpDK,EAAQ6B,qBAAqBT,EAASzB,GAE9CE,SAAAA,EAAUY,EAEgB,CAFhB,MACHI,GACPf,EAAYe,EAAc,kBAAA,CAAA,KAG9B,CAACb,EAASF,EAAaD,EAASF,EAAMC,IAG/B"}
1
+ {"version":3,"file":"useCustomEvent.js","sources":["../../src/hooks/useCustomEvent.ts"],"sourcesContent":["import { useHMSActions, useHMSVanillaNotifications } from '../primitives/HmsRoomProvider';\nimport { useCallback, useEffect } from 'react';\nimport { HMSNotificationTypes, HMSPeerID, HMSRoleName } from '@100mslive/hms-video-store';\nimport { hooksErrHandler } from './types';\nimport { logErrorHandler } from '../utils/commons';\n\nexport interface useCustomEventInput<T> {\n /**\n * type of the event, e.g. MODERATOR_EVENT, EMOJI_REACTIONS etc.\n */\n type: string;\n /**\n * the handler function for when the custom event comes. It's recommended\n * to use `useCallback` for the function passed in here for performance\n * reasons.\n * The callback is optional in case you want to decouple sending event and\n * handling event in the UI.\n */\n onEvent?: (data: T) => void;\n /**\n * flag to treat event payload as json.\n * If true, the payload will be stringified before sending and\n * parsed before calling the onEvent handler function.\n *\n * Set it to `false` if you want to send/receive only string messages\n *\n * Set it to `true` if you want to send/receive objects\n *\n * default value is true\n */\n json?: boolean;\n /**\n * function to handle errors happening during sending the event\n */\n handleError?: hooksErrHandler;\n}\n\nexport interface EventReceiver {\n peerId?: HMSPeerID;\n roleNames?: HMSRoleName[];\n}\n\nexport interface useCustomEventResult<T> {\n /**\n * sends the event data to others in the room who will receive it in onEvent\n *\n * @example to send message to peers of specific roles\n * ```js\n * sendEvent(data, {roleNames: ['host','guest']})\n * ```\n *\n * @example to send message to single peer\n * ```js\n * sendEvent(data, {peerId})\n * ```\n */\n sendEvent: (data: T, receiver?: EventReceiver) => void;\n}\n\nconst stringifyData = <T>(data: T, json: boolean) => (json ? JSON.stringify(data || '') : (data as unknown as string));\n\n/**\n * A generic function to implement [custom events](https://www.100ms.live/docs/javascript/v2/features/chat#custom-events) in your UI.\n * The data to be sent to remote is expected to be a serializable JSON. The serialization\n * and deserialization is taken care of by the hook.\n */\nexport const useCustomEvent = <T>({\n type,\n json = true,\n onEvent,\n handleError = logErrorHandler,\n}: useCustomEventInput<T>): useCustomEventResult<T> => {\n const actions = useHMSActions();\n const notifications = useHMSVanillaNotifications();\n\n useEffect(() => {\n // we don't want these messages to be stored in store reserving that for chat messages\n actions.ignoreMessageTypes([type]);\n }, [actions, type]);\n\n // this is to handle messages from remote peers\n useEffect(() => {\n if (!notifications) {\n return;\n }\n const unsubscribe = notifications.onNotification(notification => {\n const msg = notification.data;\n if (msg && msg.type === type) {\n try {\n const data = json ? JSON.parse(msg.message) : msg.message;\n onEvent?.(data as T);\n } catch (err) {\n handleError(err as Error, 'handleCustomEvent');\n }\n }\n }, HMSNotificationTypes.NEW_MESSAGE);\n return unsubscribe;\n }, [notifications, type, json, onEvent, handleError]);\n\n // this is to send message to remote peers, peers of specific role or single peer, and call onEvent\n const sendEvent = useCallback(\n async (data: T, receiver?: EventReceiver) => {\n try {\n const dataStr = stringifyData<T>(data, json);\n if (receiver && Array.isArray(receiver?.roleNames)) {\n await actions.sendGroupMessage(dataStr, receiver.roleNames, type);\n } else if (typeof receiver?.peerId === 'string') {\n await actions.sendDirectMessage(dataStr, receiver.peerId, type);\n } else {\n await actions.sendBroadcastMessage(dataStr, type);\n }\n onEvent?.(data);\n } catch (err) {\n handleError(err as Error, 'sendCustomEvent');\n }\n },\n [actions, handleError, onEvent, type, json],\n );\n\n return { sendEvent };\n};\n"],"names":["useCustomEvent","type","json","onEvent","handleError","logErrorHandler","actions","useHMSActions","notifications","useHMSVanillaNotifications","useEffect","ignoreMessageTypes","onNotification","notification","msg","data","JSON","parse","message","err","HMSNotificationTypes","NEW_MESSAGE","sendEvent","useCallback","async","receiver","dataStr","stringify","stringifyData","Array","isArray","roleNames","sendGroupMessage","peerId","sendDirectMessage","sendBroadcastMessage"],"mappings":"4QA2DA,MAOaA,EAAiB,EAC5BC,OACAC,QAAO,EACPC,UACAC,cAAcC,MAEd,MAAMC,EAAUC,IACVC,EAAgBC,IAEtBC,GAAU,KAERJ,EAAQK,mBAAmB,CAACV,GAAA,GAC3B,CAACK,EAASL,IAGbS,GAAU,KACR,IAAKF,EACH,OAaK,OAXaA,EAAcI,gBAA+BC,IAC/D,MAAMC,EAAMD,EAAaE,KACrB,GAAAD,GAAOA,EAAIb,OAASA,EAClB,IACF,MAAMc,EAAOb,EAAOc,KAAKC,MAAMH,EAAII,SAAWJ,EAAII,QACxC,MAAAf,GAAAA,EAAAY,EAEgB,CAFhB,MACHI,GACPf,EAAYe,EAAc,oBAAA,CAAA,GAG7BC,EAAqBC,YACjB,GACN,CAACb,EAAeP,EAAMC,EAAMC,EAASC,IAsBxC,MAAO,CAAEkB,UAnBSC,GAChBC,MAAOT,EAASU,KACV,IACI,MAAAC,EA5CQ,EAAIX,EAASb,IAAmBA,EAAOc,KAAKW,UAAUZ,GAAQ,IAAOA,EA4CnEa,CAAiBb,EAAMb,GACnCuB,GAAYI,MAAMC,QAAQ,MAAAL,OAAA,EAAAA,EAAUM,iBAChCzB,EAAQ0B,iBAAiBN,EAASD,EAASM,UAAW9B,GACvB,iBAAX,MAAAwB,OAAA,EAAAA,EAAAQ,cACpB3B,EAAQ4B,kBAAkBR,EAASD,EAASQ,OAAQhC,SAEpDK,EAAQ6B,qBAAqBT,EAASzB,GAEpC,MAAAE,GAAAA,EAAAY,EAEgB,CAFhB,MACHI,GACPf,EAAYe,EAAc,kBAAA,IAG9B,CAACb,EAASF,EAAaD,EAASF,EAAMC,IAG/B"}
@@ -1,2 +1,2 @@
1
- import{__awaiter as e}from"../node_modules/tslib/tslib.es6.js";import{selectDevices as i,selectLocalMediaSettings as t,selectIsAllowedToPublish as u}from"@100mslive/hms-video-store";import{useCallback as o}from"react";import{useHMSActions as d,useHMSStore as p}from"../primitives/HmsRoomProvider.js";import{logErrorHandler as s}from"../utils/commons.js";var v,a;(a=v||(v={})).videoInput="videoInput",a.audioInput="audioInput",a.audioOutput="audioOutput";const c=(a=s)=>{const c=d(),n=p(i),r=p(t),I=p(u),m={[v.audioOutput]:r.audioOutputDeviceId},l={[v.audioOutput]:n.audioOutput};I.video&&(l[v.videoInput]=n.videoInput,m[v.videoInput]=r.videoInputDeviceId),I.audio&&(l[v.audioInput]=n.audioInput,m[v.audioInput]=r.audioInputDeviceId);return{allDevices:l,selectedDeviceIDs:m,updateDevice:o((({deviceType:i,deviceId:t})=>e(void 0,void 0,void 0,(function*(){try{switch(i){case v.audioInput:yield c.setAudioSettings({deviceId:t});break;case v.videoInput:yield c.setVideoSettings({deviceId:t});break;case v.audioOutput:yield c.setAudioOutputDevice(t)}}catch(e){a(e,"updateDevices")}}))),[a,c])}};export{v as DeviceType,c as useDevices};
1
+ import{selectDevices as t,selectLocalMediaSettings as e,selectIsAllowedToPublish as i}from"@100mslive/hms-video-store";import{useCallback as u}from"react";import{useHMSActions as o,useHMSStore as d}from"../primitives/HmsRoomProvider.js";import{logErrorHandler as a}from"../utils/commons.js";var p,s;(s=p||(p={})).videoInput="videoInput",s.audioInput="audioInput",s.audioOutput="audioOutput";const v=(s=a)=>{const v=o(),c=d(t),n=d(e),I=d(i),r={[p.audioOutput]:n.audioOutputDeviceId},m={[p.audioOutput]:c.audioOutput};I.video&&(m[p.videoInput]=c.videoInput,r[p.videoInput]=n.videoInputDeviceId),I.audio&&(m[p.audioInput]=c.audioInput,r[p.audioInput]=n.audioInputDeviceId);return{allDevices:m,selectedDeviceIDs:r,updateDevice:u((async({deviceType:t,deviceId:e})=>{try{switch(t){case p.audioInput:await v.setAudioSettings({deviceId:e});break;case p.videoInput:await v.setVideoSettings({deviceId:e});break;case p.audioOutput:await v.setAudioOutputDevice(e)}}catch(t){s(t,"updateDevices")}}),[s,v])}};export{p as DeviceType,v as useDevices};
2
2
  //# sourceMappingURL=useDevices.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useDevices.js","sources":["../../src/hooks/useDevices.ts"],"sourcesContent":[null],"names":["DeviceType","DeviceType2","useDevices","handleError","logErrorHandler","actions","useHMSActions","sdkAllDevices","useHMSStore","selectDevices","sdkSelectedDevices","selectLocalMediaSettings","isAllowedToPublish","selectIsAllowedToPublish","selectedDeviceIDs","audioOutput","audioOutputDeviceId","allDevices","video","videoInput","videoInputDeviceId","audio","audioInput","audioInputDeviceId","updateDevice","useCallback","deviceType","deviceId","__awaiter","setAudioSettings","setVideoSettings","setAudioOutputDevice","err"],"mappings":"kWAMY,IAAAA,EAAAC,KAAAD,IAIXA,EAAA,CAAA,IAHC,WAAA,aACAC,EAAA,WAAA,aACAA,EAAA,YAAA,cAmCW,MAAAC,EAAa,CAACC,EAA+BC,KACxD,MAAMC,EAAUC,IACVC,EAAsDC,EAAYC,GAClEC,EAAqBF,EAAYG,GACjCC,EAAqBJ,EAAYK,GAEjCC,EAA+C,CAClD,CAAAd,EAAWe,aAAcL,EAAmBM,qBAEzCC,EAAmD,CACtD,CAAAjB,EAAWe,aAAcR,EAAcQ,aAGtCH,EAAmBM,QACVD,EAAAjB,EAAWmB,YAAcZ,EAAcY,WAChCL,EAAAd,EAAWmB,YAAcT,EAAmBU,oBAE5DR,EAAmBS,QACVJ,EAAAjB,EAAWsB,YAAcf,EAAce,WAChCR,EAAAd,EAAWsB,YAAcZ,EAAmBa,oBAwBzD,MAAA,CACLN,aACAH,oBACAU,aAxBmBC,GACnB,EAASC,aAAYC,cAA4DC,OAAA,OAAA,OAAA,GAAA,YAC3E,IACM,OAAAF,GAAA,KACD1B,EAAWsB,iBACRjB,EAAQwB,iBAAiB,CAAEF,aACjC,MAAA,KACG3B,EAAWmB,iBACRd,EAAQyB,iBAAiB,CAAEH,aACjC,MAAA,KACG3B,EAAWe,kBACRV,EAAQ0B,qBAAqBJ,GAIb,CAHtB,MAEGK,GACP7B,EAAY6B,EAAc,gBAAA,CAAA,KAG9B,CAAC7B,EAAaE,IAMd"}
1
+ {"version":3,"file":"useDevices.js","sources":["../../src/hooks/useDevices.ts"],"sourcesContent":["import { selectDevices, selectIsAllowedToPublish, selectLocalMediaSettings } from '@100mslive/hms-video-store';\nimport { useCallback } from 'react';\nimport { useHMSActions, useHMSStore } from '../primitives/HmsRoomProvider';\nimport { logErrorHandler } from '../utils/commons';\nimport { hooksErrHandler } from '../hooks/types';\n\nexport enum DeviceType {\n videoInput = 'videoInput',\n audioInput = 'audioInput',\n audioOutput = 'audioOutput',\n}\n\nexport type DeviceTypeAndInfo<T> = {\n [key in DeviceType]?: T;\n};\n\nexport interface useDevicesResult {\n /**\n * list of all devices by type\n */\n allDevices: DeviceTypeAndInfo<MediaDeviceInfo[]>;\n /**\n * selected device ids for all types\n */\n selectedDeviceIDs: DeviceTypeAndInfo<string>;\n /**\n * function to call to update device\n */\n updateDevice: ({ deviceType, deviceId }: { deviceType: DeviceType; deviceId: string }) => Promise<void>;\n}\n\n/**\n * This hook can be used to implement a UI component which allows the user to manually change their\n * audio/video device. It returns the list of all devices as well as the currently selected one. The input\n * devices will be returned based on what the user is allowed to publish, so a audio only user won't get\n * the audioInput field. This can be used to show the UI dropdowns properly.\n *\n * Note:\n * - Browsers give access to the list of devices only if the user has given permission to access them\n * - Changing devices manually work best in combination with remembering the user's selection for the next time, do\n * pass the rememberDeviceSelection flag at time of join for this to happen.\n *\n * @param handleError error handler for any errors during device change\n */\nexport const useDevices = (handleError: hooksErrHandler = logErrorHandler): useDevicesResult => {\n const actions = useHMSActions();\n const sdkAllDevices: DeviceTypeAndInfo<MediaDeviceInfo[]> = useHMSStore(selectDevices);\n const sdkSelectedDevices = useHMSStore(selectLocalMediaSettings);\n const isAllowedToPublish = useHMSStore(selectIsAllowedToPublish);\n\n const selectedDeviceIDs: DeviceTypeAndInfo<string> = {\n [DeviceType.audioOutput]: sdkSelectedDevices.audioOutputDeviceId,\n };\n const allDevices: DeviceTypeAndInfo<MediaDeviceInfo[]> = {\n [DeviceType.audioOutput]: sdkAllDevices.audioOutput,\n };\n\n if (isAllowedToPublish.video) {\n allDevices[DeviceType.videoInput] = sdkAllDevices.videoInput;\n selectedDeviceIDs[DeviceType.videoInput] = sdkSelectedDevices.videoInputDeviceId;\n }\n if (isAllowedToPublish.audio) {\n allDevices[DeviceType.audioInput] = sdkAllDevices.audioInput;\n selectedDeviceIDs[DeviceType.audioInput] = sdkSelectedDevices.audioInputDeviceId;\n }\n\n const updateDevice = useCallback(\n async ({ deviceType, deviceId }: { deviceType: DeviceType; deviceId: string }) => {\n try {\n switch (deviceType) {\n case DeviceType.audioInput:\n await actions.setAudioSettings({ deviceId });\n break;\n case DeviceType.videoInput:\n await actions.setVideoSettings({ deviceId });\n break;\n case DeviceType.audioOutput:\n await actions.setAudioOutputDevice(deviceId);\n break;\n }\n } catch (err) {\n handleError(err as Error, 'updateDevices');\n }\n },\n [handleError, actions],\n );\n\n return {\n allDevices,\n selectedDeviceIDs,\n updateDevice,\n };\n};\n"],"names":["DeviceType","DeviceType2","useDevices","handleError","logErrorHandler","actions","useHMSActions","sdkAllDevices","useHMSStore","selectDevices","sdkSelectedDevices","selectLocalMediaSettings","isAllowedToPublish","selectIsAllowedToPublish","selectedDeviceIDs","audioOutput","audioOutputDeviceId","allDevices","video","videoInput","videoInputDeviceId","audio","audioInput","audioInputDeviceId","updateDevice","useCallback","async","deviceType","deviceId","setAudioSettings","setVideoSettings","setAudioOutputDevice","err"],"mappings":"mSAMY,IAAAA,EAAAC,KAAAD,IAAAA,EAAA,CAAA,IACG,WAAA,aACAC,EAAA,WAAA,aACCA,EAAA,YAAA,cAmCH,MAAAC,EAAa,CAACC,EAA+BC,KACxD,MAAMC,EAAUC,IACVC,EAAsDC,EAAYC,GAClEC,EAAqBF,EAAYG,GACjCC,EAAqBJ,EAAYK,GAEjCC,EAA+C,CAClD,CAAAd,EAAWe,aAAcL,EAAmBM,qBAEzCC,EAAmD,CACtD,CAAAjB,EAAWe,aAAcR,EAAcQ,aAGtCH,EAAmBM,QACVD,EAAAjB,EAAWmB,YAAcZ,EAAcY,WAChCL,EAAAd,EAAWmB,YAAcT,EAAmBU,oBAE5DR,EAAmBS,QACVJ,EAAAjB,EAAWsB,YAAcf,EAAce,WAChCR,EAAAd,EAAWsB,YAAcZ,EAAmBa,oBAwBzD,MAAA,CACLN,aACAH,oBACAU,aAxBmBC,GACnBC,OAASC,aAAYC,eACf,IACM,OAAAD,GAAA,KACD3B,EAAWsB,iBACRjB,EAAQwB,iBAAiB,CAAED,aACjC,MAAA,KACG5B,EAAWmB,iBACRd,EAAQyB,iBAAiB,CAAEF,aACjC,MAAA,KACG5B,EAAWe,kBACRV,EAAQ0B,qBAAqBH,GAIb,CAHtB,MAEGI,GACP7B,EAAY6B,EAAc,gBAAA,IAG9B,CAAC7B,EAAaE,IAMd"}
@@ -1 +1 @@
1
- {"version":3,"file":"useParticipantList.js","sources":["../../src/hooks/useParticipantList.ts"],"sourcesContent":[null],"names":["useParticipantList","isConnected","useHMSStore","selectIsConnectedToRoom","participantList","selectPeers","selectRemotePeers","peerCount","selectPeerCount","participantsByRoles","useMemo","groupByRoles","roles","Object","keys"],"mappings":"oRAmBO,MAAMA,EAAqB,KAChC,MAAMC,EAAcC,EAAYC,GAC1BC,EAAkBF,EAAYD,EAAcI,EAAcC,GAC1DC,EAAYL,EAAYM,GACxBC,EAAsBC,GAAQ,IAAMC,EAAaP,IAAkB,CAACA,IAEnE,MAAA,CAAEQ,MADKC,OAAOC,KAAKL,GACVA,sBAAqBF,YAAWN,cAAA"}
1
+ {"version":3,"file":"useParticipantList.js","sources":["../../src/hooks/useParticipantList.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport {\n HMSPeer,\n HMSRoleName,\n selectIsConnectedToRoom,\n selectPeerCount,\n selectPeers,\n selectRemotePeers,\n} from '@100mslive/hms-video-store';\nimport { useHMSStore } from '../primitives/HmsRoomProvider';\nimport { groupByRoles } from '../utils/groupBy';\n\nexport interface useParticipantListResult {\n roles: HMSRoleName[];\n participantsByRoles: Record<string, HMSPeer[]>;\n peerCount: number;\n isConnected: boolean;\n}\n\nexport const useParticipantList = () => {\n const isConnected = useHMSStore(selectIsConnectedToRoom);\n const participantList = useHMSStore(isConnected ? selectPeers : selectRemotePeers);\n const peerCount = useHMSStore(selectPeerCount);\n const participantsByRoles = useMemo(() => groupByRoles(participantList), [participantList]);\n const roles = Object.keys(participantsByRoles);\n return { roles, participantsByRoles, peerCount, isConnected };\n};\n"],"names":["useParticipantList","isConnected","useHMSStore","selectIsConnectedToRoom","participantList","selectPeers","selectRemotePeers","peerCount","selectPeerCount","participantsByRoles","useMemo","groupByRoles","roles","Object","keys"],"mappings":"oRAmBO,MAAMA,EAAqB,KAChC,MAAMC,EAAcC,EAAYC,GAC1BC,EAAkBF,EAAYD,EAAcI,EAAcC,GAC1DC,EAAYL,EAAYM,GACxBC,EAAsBC,GAAQ,IAAMC,EAAaP,IAAkB,CAACA,IAEnE,MAAA,CAAEQ,MADKC,OAAOC,KAAKL,GACVA,sBAAqBF,YAAWN,cAAA"}
@@ -1,2 +1,2 @@
1
- import{selectIsConnectedToRoom as e,selectPeerCount as o,selectAvailableRoleNames as r,selectPeers as i,selectRemotePeers as t,selectPeerMetadata as s}from"@100mslive/hms-video-store";import{useHMSStore as a,useHMSVanillaStore as l}from"../primitives/HmsRoomProvider.js";const n=n=>{var d;const m=a(e),v=a(o),c=a(r);let u=a(m?i:t);const p=Array.from(new Set(u.map((e=>e.roleName)))),f=l();if((null===(d=null==n?void 0:n.metadata)||void 0===d?void 0:d.isHandRaised)&&(u=u.filter((e=>f.getState(s(e.id)).isHandRaised))),(null==n?void 0:n.role)&&c.includes(n.role)&&(u=u.filter((e=>e.roleName===n.role))),null==n?void 0:n.search){const e=n.search.toLowerCase();u=u.filter((o=>{var r;return(null===(r=o.roleName)||void 0===r?void 0:r.toLowerCase().includes(e))||o.name.toLowerCase().includes(e)}))}return{participants:u,isConnected:m,peerCount:v,rolesWithParticipants:p}};export{n as useParticipants};
1
+ import{selectIsConnectedToRoom as e,selectPeerCount as r,selectAvailableRoleNames as o,selectPeers as i,selectRemotePeers as t,selectPeerMetadata as s}from"@100mslive/hms-video-store";import{useHMSStore as a,useHMSVanillaStore as l}from"../primitives/HmsRoomProvider.js";const n=n=>{var d;const m=a(e),c=a(r),u=a(o);let v=a(m?i:t);const p=Array.from(new Set(v.map((e=>e.roleName)))),f=l();if((null==(d=null==n?void 0:n.metadata)?void 0:d.isHandRaised)&&(v=v.filter((e=>f.getState(s(e.id)).isHandRaised))),(null==n?void 0:n.role)&&u.includes(n.role)&&(v=v.filter((e=>e.roleName===n.role))),null==n?void 0:n.search){const e=n.search.toLowerCase();v=v.filter((r=>{var o;return(null==(o=r.roleName)?void 0:o.toLowerCase().includes(e))||r.name.toLowerCase().includes(e)}))}return{participants:v,isConnected:m,peerCount:c,rolesWithParticipants:p}};export{n as useParticipants};
2
2
  //# sourceMappingURL=useParticipants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useParticipants.js","sources":["../../src/hooks/useParticipants.ts"],"sourcesContent":[null],"names":["useParticipants","params","isConnected","useHMSStore","selectIsConnectedToRoom","peerCount","selectPeerCount","availableRoles","selectAvailableRoleNames","participantList","selectPeers","selectRemotePeers","rolesWithParticipants","Array","from","Set","map","peer","roleName","vanillaStore","useHMSVanillaStore","_a","metadata","isHandRaised","filter","getState","selectPeerMetadata","id","role","includes","search","toLowerCase","_a2","name","participants"],"mappings":"+QAiDa,MAAAA,EAAmBC,UAC9B,MAAMC,EAAcC,EAAYC,GAC1BC,EAAYF,EAAYG,GACxBC,EAAiBJ,EAAYK,GAC/B,IAAAC,EAAkBN,EAAYD,EAAcQ,EAAcC,GACxD,MAAAC,EAAwBC,MAAMC,KAAK,IAAIC,IAAIN,EAAgBO,QAAYC,EAAKC,aAC5EC,EAAeC,IASrB,IARsB,QAAlBC,EAAApB,aAAM,EAANA,EAAQqB,gBAAU,IAAAD,OAAA,EAAAA,EAAAE,gBACFd,EAAAA,EAAgBe,QAAcP,GACvCE,EAAaM,SAASC,EAAmBT,EAAKU,KAAKJ,iBAG1DtB,aAAM,EAANA,EAAQ2B,OAAQrB,EAAesB,SAAS5B,EAAO2B,QACjDnB,EAAkBA,EAAgBe,QAAeP,GAAAA,EAAKC,WAAajB,EAAO2B,QAExE3B,eAAAA,EAAQ6B,OAAQ,CACZ,MAAAA,EAAS7B,EAAO6B,OAAOC,cACXtB,EAAAA,EAAgBe,QACxBP,IAAA,IAAAe,EAAA,eAAAA,EAAAf,EAAKC,+BAAUa,cAAcF,SAASC,KAAWb,EAAKgB,KAAKF,cAAcF,SAASC,EAAA,GAAA,CAG9F,MAAO,CAAEI,aAAczB,EAAiBP,cAAaG,YAAWO,wBAAA"}
1
+ {"version":3,"file":"useParticipants.js","sources":["../../src/hooks/useParticipants.ts"],"sourcesContent":["import {\n HMSPeer,\n HMSRoleName,\n selectAvailableRoleNames,\n selectIsConnectedToRoom,\n selectPeerCount,\n selectPeerMetadata,\n selectPeers,\n selectRemotePeers,\n} from '@100mslive/hms-video-store';\nimport { useHMSStore, useHMSVanillaStore } from '../primitives/HmsRoomProvider';\n\nexport interface useParticipantsResult {\n /**\n * list of participants that match the given filters\n */\n participants: HMSPeer[];\n /**\n * Total number of participants in the room\n */\n peerCount: number;\n /**\n * is joined in the room\n */\n isConnected: boolean;\n /**\n * role names with atleast one participant present with that role\n */\n rolesWithParticipants: HMSRoleName[];\n}\n\nexport type useParticipantsParams = {\n /** To filter by particular role */\n role: HMSRoleName;\n /**\n * To filter by particular by metadata. only supports { isHandRaised: true } for now\n * @beta\n */\n metadata: Record<string, any>;\n /** To filter by name/role (partial match) */\n search: string;\n};\n\n/**\n * This can be used to get the total count of participants in the room, participants\n * filtered by role or metadata with isHandRaised or the entire participants if no params are passed\n * @param {useParticipantsParams} params\n * @returns {useParticipantsResult}\n */\nexport const useParticipants = (params?: useParticipantsParams) => {\n const isConnected = useHMSStore(selectIsConnectedToRoom);\n const peerCount = useHMSStore(selectPeerCount);\n const availableRoles = useHMSStore(selectAvailableRoleNames);\n let participantList = useHMSStore(isConnected ? selectPeers : selectRemotePeers);\n const rolesWithParticipants = Array.from(new Set(participantList.map(peer => peer.roleName)));\n const vanillaStore = useHMSVanillaStore();\n if (params?.metadata?.isHandRaised) {\n participantList = participantList.filter(peer => {\n return vanillaStore.getState(selectPeerMetadata(peer.id)).isHandRaised;\n });\n }\n if (params?.role && availableRoles.includes(params.role)) {\n participantList = participantList.filter(peer => peer.roleName === params.role);\n }\n if (params?.search) {\n const search = params.search.toLowerCase();\n participantList = participantList.filter(\n peer => peer.roleName?.toLowerCase().includes(search) || peer.name.toLowerCase().includes(search),\n );\n }\n return { participants: participantList, isConnected, peerCount, rolesWithParticipants };\n};\n"],"names":["useParticipants","params","_a","isConnected","useHMSStore","selectIsConnectedToRoom","peerCount","selectPeerCount","availableRoles","selectAvailableRoleNames","participantList","selectPeers","selectRemotePeers","rolesWithParticipants","Array","from","Set","map","peer","roleName","vanillaStore","useHMSVanillaStore","metadata","isHandRaised","filter","getState","selectPeerMetadata","id","role","includes","search","toLowerCase","_a2","name","participants"],"mappings":"+QAiDa,MAAAA,EAAmBC,IAjDhC,IAAAC,EAkDE,MAAMC,EAAcC,EAAYC,GAC1BC,EAAYF,EAAYG,GACxBC,EAAiBJ,EAAYK,GAC/B,IAAAC,EAAkBN,EAAYD,EAAcQ,EAAcC,GACxD,MAAAC,EAAwBC,MAAMC,KAAK,IAAIC,IAAIN,EAAgBO,QAAYC,EAAKC,aAC5EC,EAAeC,IASrB,IARI,OAAAnB,EAAA,MAAAD,OAAA,EAAAA,EAAQqB,eAAR,EAAApB,EAAkBqB,gBACFb,EAAAA,EAAgBc,QAAeN,GACxCE,EAAaK,SAASC,EAAmBR,EAAKS,KAAKJ,iBAGlD,MAAAtB,OAAA,EAAAA,EAAA2B,OAAQpB,EAAeqB,SAAS5B,EAAO2B,QACjDlB,EAAkBA,EAAgBc,QAAeN,GAAAA,EAAKC,WAAalB,EAAO2B,cAExE3B,WAAQ6B,OAAQ,CACZ,MAAAA,EAAS7B,EAAO6B,OAAOC,cACXrB,EAAAA,EAAgBc,QAC3BN,IAnEX,IAAAc,EAmEmB,OAAL,OAAKA,EAAAd,EAAAC,mBAAUY,cAAcF,SAASC,KAAWZ,EAAKe,KAAKF,cAAcF,SAASC,EAAA,GAAA,CAG9F,MAAO,CAAEI,aAAcxB,EAAiBP,cAAaG,YAAWO,wBAAA"}
@@ -1,2 +1,2 @@
1
- import{__awaiter as e}from"../node_modules/tslib/tslib.es6.js";import{selectRoomState as i,selectIsConnectedToRoom as t,HMSRoomState as o}from"@100mslive/hms-video-store";import{useMemo as r,useCallback as n}from"react";import{useHMSActions as m,useHMSStore as s}from"../primitives/HmsRoomProvider.js";import{logErrorHandler as a}from"../utils/commons.js";const d=({name:d="",token:v,metadata:c,handleError:l=a,initEndpoint:p,initialSettings:u,captureNetworkQualityInPreview:f})=>{const w=m(),y=s(i),j=s(t)||!1,h=y===o.Preview,b=r((()=>({userName:d,authToken:v,metaData:c,rememberDeviceSelection:!0,settings:u,initEndpoint:p,captureNetworkQualityInPreview:f})),[d,v,c,p,u,f]),k=n((()=>e(void 0,void 0,void 0,(function*(){if(v&&y===o.Disconnected){j&&(yield w.leave());try{yield w.preview(b)}catch(e){l(e,"preview")}}}))),[w,l,v,y,b,j]);return{enableJoin:h,join:n((()=>e(void 0,void 0,void 0,(function*(){if(v)try{yield w.join(b)}catch(e){l(e,"join")}}))),[w,b,l,v]),isConnected:j,preview:k}};export{d as usePreviewJoin};
1
+ import{selectRoomState as e,selectIsConnectedToRoom as i,HMSRoomState as t}from"@100mslive/hms-video-store";import{useMemo as r,useCallback as o}from"react";import{useHMSActions as n,useHMSStore as a}from"../primitives/HmsRoomProvider.js";import{logErrorHandler as m}from"../utils/commons.js";const s=({name:s="",token:c,metadata:p,handleError:v=m,initEndpoint:w,initialSettings:l,captureNetworkQualityInPreview:d})=>{const u=n(),f=a(e),y=a(i)||!1,h=f===t.Preview,j=r((()=>({userName:s,authToken:c,metaData:p,rememberDeviceSelection:!0,settings:l,initEndpoint:w,captureNetworkQualityInPreview:d})),[s,c,p,w,l,d]),k=o((async()=>{if(c&&f===t.Disconnected){y&&await u.leave();try{await u.preview(j)}catch(e){v(e,"preview")}}}),[u,v,c,f,j,y]);return{enableJoin:h,join:o((async()=>{if(c)try{await u.join(j)}catch(e){v(e,"join")}}),[u,j,v,c]),isConnected:y,preview:k}};export{s as usePreviewJoin};
2
2
  //# sourceMappingURL=usePreviewJoin.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"usePreviewJoin.js","sources":["../../src/hooks/usePreviewJoin.ts"],"sourcesContent":[null],"names":["usePreviewJoin","name","token","metadata","handleError","logErrorHandler","initEndpoint","initialSettings","captureNetworkQualityInPreview","actions","useHMSActions","roomState","useHMSStore","selectRoomState","isConnected","selectIsConnectedToRoom","enableJoin","HMSRoomState","Preview","config","useMemo","userName","authToken","metaData","rememberDeviceSelection","settings","preview","useCallback","__awaiter","Disconnected","leave","err","join"],"mappings":"oWAqEa,MAAAA,EAAiB,EAC5BC,OAAO,GACPC,QACAC,WACAC,cAAcC,EACdC,eACAC,kBACAC,qCAEA,MAAMC,EAAUC,IACVC,EAAYC,EAAYC,GACxBC,EAAcF,EAAYG,KAA4B,EACtDC,EAAaL,IAAcM,EAAaC,QAExCC,EAAoBC,GAAQ,KACzB,CACLC,SAAUpB,EACVqB,UAAWpB,EACXqB,SAAUpB,EACVqB,yBAAyB,EACzBC,SAAUlB,EACVD,eACAE,oCAED,CAACP,EAAMC,EAAOC,EAAUG,EAAcC,EAAiBC,IAEpDkB,EAAUC,GAAY,IAAWC,OAAA,OAAA,OAAA,GAAA,YACrC,GAAK1B,GAGDS,IAAcM,EAAaY,aAA3B,CAGAf,UACIL,EAAQqB,SAEZ,UACIrB,EAAQiB,QAAQP,EAEI,CAFJ,MACfY,GACP3B,EAAY2B,EAAc,UAAA,CAR1B,CAQ0B,KAE3B,CAACtB,EAASL,EAAaF,EAAOS,EAAWQ,EAAQL,IAa7C,MAAA,CACLE,aACAgB,KAbWL,GAAY,IAAWC,OAAA,OAAA,OAAA,GAAA,YAClC,GAAK1B,EAGD,UACIO,EAAQuB,KAAKb,EAEO,CAFP,MACZY,GACP3B,EAAY2B,EAAc,OAAA,CAAA,KAE3B,CAACtB,EAASU,EAAQf,EAAaF,IAKhCY,cACAY,UAAA"}
1
+ {"version":3,"file":"usePreviewJoin.js","sources":["../../src/hooks/usePreviewJoin.ts"],"sourcesContent":["import {\n HMSRoomState,\n selectIsConnectedToRoom,\n selectRoomState,\n HMSConfigInitialSettings,\n} from '@100mslive/hms-video-store';\nimport { useCallback, useMemo } from 'react';\nimport { useHMSActions, useHMSStore } from '../primitives/HmsRoomProvider';\nimport { hooksErrHandler } from './types';\nimport { logErrorHandler } from '../utils/commons';\nimport { HMSConfig } from '@100mslive/hms-video';\n\nexport interface usePreviewInput {\n /**\n * name of user who is joining, this is only required if join is called\n */\n name?: string;\n /**\n * app side authentication token\n */\n token: string;\n /**\n * any extra metadata info for the peer\n */\n metadata?: string;\n /**\n * function to handle errors happening during preview\n */\n handleError?: hooksErrHandler;\n initEndpoint?: string;\n /**\n * initial settings for audio/video and device to be used.\n */\n initialSettings?: HMSConfigInitialSettings;\n /**\n * Enable to get a network quality score while in preview. The score ranges from -1 to 5.\n * -1 when we are not able to connect to 100ms servers within an expected time limit\n * 0 when there is a timeout/failure when measuring the quality\n * 1-5 ranges from poor to good quality.\n */\n captureNetworkQualityInPreview?: boolean;\n}\n\nexport interface usePreviewResult {\n /**\n * enable the join button for the user only when this is true\n */\n enableJoin: boolean;\n /**\n * call this function to join the room\n */\n join: () => Promise<void>;\n /**\n * once the user has joined the room, till leave happens this flag will be true. It can be used\n * to decide to show between preview form and conferencing component/video tiles.\n */\n isConnected: boolean;\n /**\n * call this function to join the room\n */\n preview: () => Promise<void>;\n}\n\n/**\n * This hook can be used to build a preview UI component, this lets you call preview everytime the passed in\n * token changes. This hook is best used in combination with useDevices for changing devices, useAVToggle for\n * muting/unmuting and useAudioLevelStyles for showing mic audio level to the user.\n * Any device change or mute/unmute will be carried across to join.\n */\nexport const usePreviewJoin = ({\n name = '',\n token,\n metadata,\n handleError = logErrorHandler,\n initEndpoint,\n initialSettings,\n captureNetworkQualityInPreview,\n}: usePreviewInput): usePreviewResult => {\n const actions = useHMSActions();\n const roomState = useHMSStore(selectRoomState);\n const isConnected = useHMSStore(selectIsConnectedToRoom) || false;\n const enableJoin = roomState === HMSRoomState.Preview;\n\n const config: HMSConfig = useMemo(() => {\n return {\n userName: name,\n authToken: token,\n metaData: metadata,\n rememberDeviceSelection: true,\n settings: initialSettings,\n initEndpoint: initEndpoint,\n captureNetworkQualityInPreview,\n };\n }, [name, token, metadata, initEndpoint, initialSettings, captureNetworkQualityInPreview]);\n\n const preview = useCallback(async () => {\n if (!token) {\n return;\n }\n if (roomState !== HMSRoomState.Disconnected) {\n return;\n }\n if (isConnected) {\n await actions.leave();\n }\n try {\n await actions.preview(config);\n } catch (err) {\n handleError(err as Error, 'preview');\n }\n }, [actions, handleError, token, roomState, config, isConnected]);\n\n const join = useCallback(async () => {\n if (!token) {\n return;\n }\n try {\n await actions.join(config);\n } catch (err) {\n handleError(err as Error, 'join');\n }\n }, [actions, config, handleError, token]);\n\n return {\n enableJoin,\n join,\n isConnected,\n preview,\n };\n};\n"],"names":["usePreviewJoin","name","token","metadata","handleError","logErrorHandler","initEndpoint","initialSettings","captureNetworkQualityInPreview","actions","useHMSActions","roomState","useHMSStore","selectRoomState","isConnected","selectIsConnectedToRoom","enableJoin","HMSRoomState","Preview","config","useMemo","userName","authToken","metaData","rememberDeviceSelection","settings","preview","useCallback","async","Disconnected","leave","err","join"],"mappings":"qSAqEO,MAAMA,EAAiB,EAC5BC,OAAO,GACPC,QACAC,WACAC,cAAcC,EACdC,eACAC,kBACAC,qCAEA,MAAMC,EAAUC,IACVC,EAAYC,EAAYC,GACxBC,EAAcF,EAAYG,KAA4B,EACtDC,EAAaL,IAAcM,EAAaC,QAExCC,EAAoBC,GAAQ,KACzB,CACLC,SAAUpB,EACVqB,UAAWpB,EACXqB,SAAUpB,EACVqB,yBAAyB,EACzBC,SAAUlB,EACVD,eACAE,oCAED,CAACP,EAAMC,EAAOC,EAAUG,EAAcC,EAAiBC,IAEpDkB,EAAUC,GAAYC,UAC1B,GAAK1B,GAGDS,IAAcM,EAAaY,aAA3B,CAGAf,SACIL,EAAQqB,QAEZ,UACIrB,EAAQiB,QAAQP,EAEI,CAFJ,MACfY,GACP3B,EAAY2B,EAAc,UAAA,CAR1B,CAQ0B,GAE3B,CAACtB,EAASL,EAAaF,EAAOS,EAAWQ,EAAQL,IAa7C,MAAA,CACLE,aACAgB,KAbWL,GAAYC,UACvB,GAAK1B,EAGD,UACIO,EAAQuB,KAAKb,EAEO,CAFP,MACZY,GACP3B,EAAY2B,EAAc,OAAA,IAE3B,CAACtB,EAASU,EAAQf,EAAaF,IAKhCY,cACAY,UAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"useRecordingStreaming.js","sources":["../../src/hooks/useRecordingStreaming.ts"],"sourcesContent":[null],"names":["useRecordingStreaming","recording","useHMSStore","selectRecordingState","rtmp","selectRTMPState","hls","selectHLSState","isServerRecordingOn","server","running","isBrowserRecordingOn","browser","isHLSRecordingOn","isRecordingOn","isStreamingOn","isHLSRunning","isRTMPRunning"],"mappings":"0KAaO,MAAMA,EAAwB,KACnC,MAAMC,EAAYC,EAAYC,GACxBC,EAAOF,EAAYG,GACnBC,EAAMJ,EAAYK,GAElBC,EAAsBP,EAAUQ,OAAOC,QACvCC,EAAuBV,EAAUW,QAAQF,QACzCG,EAAmBZ,EAAUK,IAAII,QAEjCI,EAAgBN,GAAuBG,GAAwBE,EAE9D,MAAA,CACLL,sBACAG,uBACAE,mBACAE,cAPoBT,EAAII,SAAWN,EAAKM,QAQxCM,aAAcV,EAAII,QAClBO,cAAeb,EAAKM,QACpBI,gBAAA"}
1
+ {"version":3,"file":"useRecordingStreaming.js","sources":["../../src/hooks/useRecordingStreaming.ts"],"sourcesContent":["import { selectHLSState, selectRecordingState, selectRTMPState } from '@100mslive/hms-video-store';\nimport { useHMSStore } from '../primitives/HmsRoomProvider';\n\nexport interface useRecordingStreamingResult {\n isServerRecordingOn: boolean;\n isBrowserRecordingOn: boolean;\n isHLSRecordingOn: boolean;\n isStreamingOn: boolean;\n isHLSRunning: boolean;\n isRTMPRunning: boolean;\n isRecordingOn: boolean;\n}\n\nexport const useRecordingStreaming = (): useRecordingStreamingResult => {\n const recording = useHMSStore(selectRecordingState);\n const rtmp = useHMSStore(selectRTMPState);\n const hls = useHMSStore(selectHLSState);\n\n const isServerRecordingOn = recording.server.running;\n const isBrowserRecordingOn = recording.browser.running;\n const isHLSRecordingOn = recording.hls.running;\n const isStreamingOn = hls.running || rtmp.running;\n const isRecordingOn = isServerRecordingOn || isBrowserRecordingOn || isHLSRecordingOn;\n\n return {\n isServerRecordingOn,\n isBrowserRecordingOn,\n isHLSRecordingOn,\n isStreamingOn,\n isHLSRunning: hls.running,\n isRTMPRunning: rtmp.running,\n isRecordingOn,\n };\n};\n"],"names":["useRecordingStreaming","recording","useHMSStore","selectRecordingState","rtmp","selectRTMPState","hls","selectHLSState","isServerRecordingOn","server","running","isBrowserRecordingOn","browser","isHLSRecordingOn","isRecordingOn","isStreamingOn","isHLSRunning","isRTMPRunning"],"mappings":"0KAaO,MAAMA,EAAwB,KACnC,MAAMC,EAAYC,EAAYC,GACxBC,EAAOF,EAAYG,GACnBC,EAAMJ,EAAYK,GAElBC,EAAsBP,EAAUQ,OAAOC,QACvCC,EAAuBV,EAAUW,QAAQF,QACzCG,EAAmBZ,EAAUK,IAAII,QAEjCI,EAAgBN,GAAuBG,GAAwBE,EAE9D,MAAA,CACLL,sBACAG,uBACAE,mBACAE,cAPoBT,EAAII,SAAWN,EAAKM,QAQxCM,aAAcV,EAAII,QAClBO,cAAeb,EAAKM,QACpBI,gBAAA"}
@@ -1,2 +1,2 @@
1
- import{__awaiter as o}from"../node_modules/tslib/tslib.es6.js";import{selectAudioTrackByID as i,selectVideoTrackByID as e,selectAudioTrackVolume as d,selectPermissions as l}from"@100mslive/hms-video-store";import{useHMSActions as n,useHMSStore as t}from"../primitives/HmsRoomProvider.js";import{useCallback as u}from"react";import{logErrorHandler as m}from"../utils/commons.js";const v=(i,e,d)=>o(void 0,void 0,void 0,(function*(){if(e)try{yield i.setRemoteTrackEnabled(e.id,!e.enabled)}catch(o){d(o,"remoteToggle")}})),r=(r,s,a=m)=>{const c=n(),b=t(i(r)),f=t(e(s)),g=t(d(null==b?void 0:b.id)),p=t(l),y=(null==f?void 0:f.enabled)?null==p?void 0:p.mute:null==p?void 0:p.unmute,V=(null==b?void 0:b.enabled)?null==p?void 0:p.mute:null==p?void 0:p.unmute,j=u((()=>o(void 0,void 0,void 0,(function*(){yield v(c,b,a)}))),[c,b,a]),E=u((()=>o(void 0,void 0,void 0,(function*(){yield v(c,f,a)}))),[c,a,f]),h=u((o=>{b&&c.setVolume(o,b.id)}),[c,b]);return{isAudioEnabled:!!(null==b?void 0:b.enabled),isVideoEnabled:!!(null==f?void 0:f.enabled),volume:g,toggleAudio:b&&V?j:void 0,toggleVideo:"regular"===(null==f?void 0:f.source)&&y?E:void 0,setVolume:b?h:void 0}};export{r as useRemoteAVToggle};
1
+ import{selectAudioTrackByID as o,selectVideoTrackByID as e,selectAudioTrackVolume as i,selectPermissions as l}from"@100mslive/hms-video-store";import{useHMSActions as d,useHMSStore as t}from"../primitives/HmsRoomProvider.js";import{useCallback as n}from"react";import{logErrorHandler as u}from"../utils/commons.js";const m=async(o,e,i)=>{if(e)try{await o.setRemoteTrackEnabled(e.id,!e.enabled)}catch(o){i(o,"remoteToggle")}},r=(r,a,s=u)=>{const v=d(),c=t(o(r)),b=t(e(a)),g=t(i(null==c?void 0:c.id)),p=t(l),f=(null==b?void 0:b.enabled)?null==p?void 0:p.mute:null==p?void 0:p.unmute,y=(null==c?void 0:c.enabled)?null==p?void 0:p.mute:null==p?void 0:p.unmute,V=n((async()=>{await m(v,c,s)}),[v,c,s]),w=n((async()=>{await m(v,b,s)}),[v,s,b]),E=n((o=>{c&&v.setVolume(o,c.id)}),[v,c]);return{isAudioEnabled:!!(null==c?void 0:c.enabled),isVideoEnabled:!!(null==b?void 0:b.enabled),volume:g,toggleAudio:c&&y?V:void 0,toggleVideo:"regular"===(null==b?void 0:b.source)&&f?w:void 0,setVolume:c?E:void 0}};export{r as useRemoteAVToggle};
2
2
  //# sourceMappingURL=useRemoteAVToggle.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useRemoteAVToggle.js","sources":["../../src/hooks/useRemoteAVToggle.ts"],"sourcesContent":[null],"names":["toggleTrackEnabled","actions","track","handleError","__awaiter","setRemoteTrackEnabled","id","enabled","err","useRemoteAVToggle","audioTrackId","videoTrackId","logErrorHandler","useHMSActions","audioTrack","useHMSStore","selectAudioTrackByID","videoTrack","selectVideoTrackByID","volume","selectAudioTrackVolume","permissions","selectPermissions","canToggleVideo","mute","unmute","canToggleAudio","toggleAudio","useCallback","toggleVideo","setVolume","volume2","isAudioEnabled","isVideoEnabled","source"],"mappings":"0XA0CA,MAAMA,EAAqB,CACzBC,EACAC,EACAC,IACEC,OAAA,OAAA,OAAA,GAAA,YACF,GAAIF,EACE,UACID,EAAQI,sBAAsBH,EAAMI,IAAKJ,EAAMK,QAE3B,CAF2B,MAC9CC,GACPL,EAAYK,EAAc,eAAA,CAAA,IAYnBC,EAAoB,CAC/BC,EACAC,EACAR,EAA+BS,KAE/B,MAAMX,EAAUY,IACVC,EAAaC,EAAYC,EAAqBN,IAC9CO,EAAaF,EAAYG,EAAqBP,IAC9CQ,EAASJ,EAAYK,EAAuBN,eAAAA,EAAYR,KACxDe,EAAcN,EAAYO,GAC1BC,gBAAiB,EAAAN,EAAYV,SAAUc,aAAW,EAAXA,EAAaG,KAAOH,aAAW,EAAXA,EAAaI,OACxEC,gBAAiB,EAAAZ,EAAYP,SAAUc,aAAW,EAAXA,EAAaG,KAAOH,aAAW,EAAXA,EAAaI,OAExEE,EAAcC,GAAY,IAAWxB,OAAA,OAAA,OAAA,GAAA,kBACnCJ,EAAmBC,EAASa,EAAYX,EAC7C,KAAA,CAACF,EAASa,EAAYX,IAEnB0B,EAAcD,GAAY,IAAWxB,OAAA,OAAA,OAAA,GAAA,kBACnCJ,EAAmBC,EAASgB,EAAYd,EAC7C,KAAA,CAACF,EAASE,EAAac,IAEpBa,EAAYF,GACfG,IACKjB,GACMb,EAAA6B,UAAUC,EAAQjB,EAAWR,GAAA,GAGzC,CAACL,EAASa,IAGL,MAAA,CACLkB,kBAAkBlB,aAAA,EAAAA,EAAYP,SAC9B0B,kBAAkBhB,aAAA,EAAAA,EAAYV,SAC9BY,SACAQ,YAAab,GAAcY,EAAiBC,OAAc,EAC1DE,YAAoC,aAAbZ,aAAV,EAAAA,EAAYiB,SAAwBX,EAAiBM,OAAc,EAChFC,UAAWhB,EAAagB,OAAY,EAAA"}
1
+ {"version":3,"file":"useRemoteAVToggle.js","sources":["../../src/hooks/useRemoteAVToggle.ts"],"sourcesContent":["/* eslint-disable complexity */\nimport {\n HMSActions,\n HMSTrack,\n HMSTrackID,\n selectAudioTrackVolume,\n selectPermissions,\n selectAudioTrackByID,\n selectVideoTrackByID,\n} from '@100mslive/hms-video-store';\nimport { useHMSActions, useHMSStore } from '../primitives/HmsRoomProvider';\nimport { useCallback } from 'react';\nimport { hooksErrHandler } from './types';\nimport { logErrorHandler } from '../utils/commons';\n\nexport interface useRemoteAVToggleResult {\n /**\n * true if unmuted and vice versa\n */\n isAudioEnabled: boolean;\n isVideoEnabled: boolean;\n /**\n * current volume of the audio track\n */\n volume?: number;\n /**\n * use this function to toggle audio state, the function will only be present if the user\n * has permission to mute/unmute remote audio\n */\n toggleAudio?: () => void;\n /**\n * use this function to toggle video state, the function will only be present if the user\n * has permission to mute/unmute remote video\n */\n toggleVideo?: () => void;\n /**\n * use this function to set the volume of peer's audio track for the local user, the function will\n * only be present if the remote peer has an audio track to change volume for\n */\n setVolume?: (volume: number) => void;\n}\n\nconst toggleTrackEnabled = async (\n actions: HMSActions,\n track: HMSTrack | undefined | null,\n handleError: hooksErrHandler,\n) => {\n if (track) {\n try {\n await actions.setRemoteTrackEnabled(track.id, !track.enabled);\n } catch (err) {\n handleError(err as Error, 'remoteToggle');\n }\n }\n};\n\n/**\n * This hook can be used to implement remote mute/unmute + audio volume changer on tile level.\n * @param peerId of the peer whose tracks need to be managed\n * @param audioTrackId of the peer whose tracks need to be managed\n * @param videoTrackId of the peer whose tracks need to be managed\n * @param handleError to handle any error during toggle of audio/video\n */\nexport const useRemoteAVToggle = (\n audioTrackId: HMSTrackID,\n videoTrackId: HMSTrackID,\n handleError: hooksErrHandler = logErrorHandler,\n): useRemoteAVToggleResult => {\n const actions = useHMSActions();\n const audioTrack = useHMSStore(selectAudioTrackByID(audioTrackId));\n const videoTrack = useHMSStore(selectVideoTrackByID(videoTrackId));\n const volume = useHMSStore(selectAudioTrackVolume(audioTrack?.id));\n const permissions = useHMSStore(selectPermissions);\n const canToggleVideo = videoTrack?.enabled ? permissions?.mute : permissions?.unmute;\n const canToggleAudio = audioTrack?.enabled ? permissions?.mute : permissions?.unmute;\n\n const toggleAudio = useCallback(async () => {\n await toggleTrackEnabled(actions, audioTrack, handleError);\n }, [actions, audioTrack, handleError]);\n\n const toggleVideo = useCallback(async () => {\n await toggleTrackEnabled(actions, videoTrack, handleError);\n }, [actions, handleError, videoTrack]);\n\n const setVolume = useCallback(\n (volume: number) => {\n if (audioTrack) {\n actions.setVolume(volume, audioTrack.id);\n }\n },\n [actions, audioTrack],\n );\n\n return {\n isAudioEnabled: !!audioTrack?.enabled,\n isVideoEnabled: !!videoTrack?.enabled,\n volume,\n toggleAudio: audioTrack && canToggleAudio ? toggleAudio : undefined,\n toggleVideo: videoTrack?.source === 'regular' && canToggleVideo ? toggleVideo : undefined,\n setVolume: audioTrack ? setVolume : undefined,\n };\n};\n"],"names":["toggleTrackEnabled","async","actions","track","handleError","setRemoteTrackEnabled","id","enabled","err","useRemoteAVToggle","audioTrackId","videoTrackId","logErrorHandler","useHMSActions","audioTrack","useHMSStore","selectAudioTrackByID","videoTrack","selectVideoTrackByID","volume","selectAudioTrackVolume","permissions","selectPermissions","canToggleVideo","mute","unmute","canToggleAudio","toggleAudio","useCallback","toggleVideo","setVolume","volume2","isAudioEnabled","isVideoEnabled","source"],"mappings":"2TA0CA,MAAMA,EAAqBC,MACzBC,EACAC,EACAC,KAEA,GAAID,EACE,UACID,EAAQG,sBAAsBF,EAAMG,IAAKH,EAAMI,QAE3B,CAF2B,MAC9CC,GACPJ,EAAYI,EAAc,eAAA,CAAA,EAYnBC,EAAoB,CAC/BC,EACAC,EACAP,EAA+BQ,KAE/B,MAAMV,EAAUW,IACVC,EAAaC,EAAYC,EAAqBN,IAC9CO,EAAaF,EAAYG,EAAqBP,IAC9CQ,EAASJ,EAAYK,EAAmC,MAAZN,OAAY,EAAAA,EAAAR,KACxDe,EAAcN,EAAYO,GAC1BC,GAAiB,MAAAN,OAAA,EAAAA,EAAYV,SAAU,MAAAc,OAAA,EAAAA,EAAaG,KAAoB,MAAbH,OAAa,EAAAA,EAAAI,OACxEC,GAAiB,MAAAZ,OAAA,EAAAA,EAAYP,SAAU,MAAAc,OAAA,EAAAA,EAAaG,KAAoB,MAAbH,OAAa,EAAAA,EAAAI,OAExEE,EAAcC,GAAY3B,gBACxBD,EAAmBE,EAASY,EAAYV,EAAA,GAC7C,CAACF,EAASY,EAAYV,IAEnByB,EAAcD,GAAY3B,gBACxBD,EAAmBE,EAASe,EAAYb,EAAA,GAC7C,CAACF,EAASE,EAAaa,IAEpBa,EAAYF,GACfG,IACKjB,GACMZ,EAAA4B,UAAUC,EAAQjB,EAAWR,GAAA,GAGzC,CAACJ,EAASY,IAGL,MAAA,CACLkB,kBAA8B,MAAAlB,OAAA,EAAAA,EAAAP,SAC9B0B,kBAA8B,MAAAhB,OAAA,EAAAA,EAAAV,SAC9BY,SACAQ,YAAab,GAAcY,EAAiBC,OAAc,EAC1DE,YAAoC,aAAvB,MAAAZ,OAAA,EAAAA,EAAYiB,SAAwBX,EAAiBM,OAAc,EAChFC,UAAWhB,EAAagB,OAAY,EAAA"}
@@ -1,2 +1,2 @@
1
- import{__awaiter as e}from"../node_modules/tslib/tslib.es6.js";import{selectIsLocalScreenShared as o,selectPeerScreenSharing as r,selectScreenSharesByPeerId as i}from"@100mslive/hms-video-store";import{useHMSActions as d,useHMSStore as n}from"../primitives/HmsRoomProvider.js";import{useCallback as l}from"react";import{logErrorHandler as m}from"../utils/commons.js";const s=(s=m)=>{var t,a;const v=d(),c=n(o),u=n(r),S=n(i(null==u?void 0:u.id)),h=l(((o=!1)=>e(void 0,void 0,void 0,(function*(){try{yield v.setScreenShareEnabled(!c,o)}catch(e){s(e,"toggleScreenShare")}}))),[v,c,s]);return{amIScreenSharing:c,screenSharingPeerId:null==u?void 0:u.id,screenSharingPeerName:null==u?void 0:u.name,screenShareVideoTrackId:null===(t=null==S?void 0:S.video)||void 0===t?void 0:t.id,screenShareAudioTrackId:null===(a=null==S?void 0:S.audio)||void 0===a?void 0:a.id,toggleScreenShare:h}};export{s as useScreenShare};
1
+ import{selectIsLocalScreenShared as e,selectPeerScreenSharing as r,selectScreenSharesByPeerId as o}from"@100mslive/hms-video-store";import{useHMSActions as i,useHMSStore as n}from"../primitives/HmsRoomProvider.js";import{useCallback as a}from"react";import{logErrorHandler as d}from"../utils/commons.js";const l=(l=d)=>{var m,t;const c=i(),s=n(e),v=n(r),S=n(o(null==v?void 0:v.id)),u=a((async(e=!1)=>{try{await c.setScreenShareEnabled(!s,e)}catch(e){l(e,"toggleScreenShare")}}),[c,s,l]);return{amIScreenSharing:s,screenSharingPeerId:null==v?void 0:v.id,screenSharingPeerName:null==v?void 0:v.name,screenShareVideoTrackId:null==(m=null==S?void 0:S.video)?void 0:m.id,screenShareAudioTrackId:null==(t=null==S?void 0:S.audio)?void 0:t.id,toggleScreenShare:u}};export{l as useScreenShare};
2
2
  //# sourceMappingURL=useScreenShare.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useScreenShare.js","sources":["../../src/hooks/useScreenShare.ts"],"sourcesContent":[null],"names":["useScreenShare","handleError","logErrorHandler","actions","useHMSActions","amIScreenSharing","useHMSStore","selectIsLocalScreenShared","screenSharePeer","selectPeerScreenSharing","screenShare","selectScreenSharesByPeerId","id","toggleScreenShare","useCallback","audioOnly","__awaiter","setScreenShareEnabled","err","screenSharingPeerId","screenSharingPeerName","name","screenShareVideoTrackId","_a","video","screenShareAudioTrackId","_b","audio"],"mappings":"+WAkDa,MAAAA,EAAiB,CAACC,EAA+BC,aAC5D,MAAMC,EAAUC,IACVC,EAAmBC,EAAYC,GAC/BC,EAAkBF,EAAYG,GAC9BC,EAAcJ,EAAYK,EAA2BH,eAAAA,EAAiBI,KAEtEC,EAAoBC,GACxB,CAAOC,GAAY,IAASC,OAAA,OAAA,OAAA,GAAA,YACtB,UACIb,EAAQc,uBAAuBZ,EAAkBU,EAE7B,CAF6B,MAChDG,GACPjB,EAAYiB,EAAc,oBAAA,CAG9B,KAAA,CAACf,EAASE,EAAkBJ,IAGvB,MAAA,CACLI,mBACAc,oBAAqBX,aAAA,EAAAA,EAAiBI,GACtCQ,sBAAuBZ,aAAA,EAAAA,EAAiBa,KACxCC,wBAA2C,QAAlBC,EAAAb,eAAAA,EAAac,aAAK,IAAAD,OAAA,EAAAA,EAAEX,GAC7Ca,wBAA2C,QAAlBC,EAAAhB,eAAAA,EAAaiB,aAAK,IAAAD,OAAA,EAAAA,EAAEd,GAC7CC,oBAAA"}
1
+ {"version":3,"file":"useScreenShare.js","sources":["../../src/hooks/useScreenShare.ts"],"sourcesContent":["import { hooksErrHandler } from '../hooks/types';\nimport {\n HMSPeerID,\n HMSTrackID,\n selectIsLocalScreenShared,\n selectPeerScreenSharing,\n selectScreenSharesByPeerId,\n} from '@100mslive/hms-video-store';\nimport { useHMSActions, useHMSStore } from '../primitives/HmsRoomProvider';\nimport { useCallback } from 'react';\nimport { logErrorHandler } from '../utils/commons';\n\nexport interface useScreenShareResult {\n /**\n * true if the local user is screensharing, false otherwise\n */\n amIScreenSharing: boolean;\n /**\n * toggle screenshare for the local user, will only be present if the user has the permission to toggle\n */\n toggleScreenShare?: () => void;\n /**\n * the id of the peer who is currently screensharing, will only be present if there is a screenshare in the room.\n * In case of multiple screenshares, the behaviour of which one is picked is not defined.\n */\n screenSharingPeerId?: HMSPeerID;\n /**\n * the name of the peer who is currently screensharing. Will be undefined if no one is sharing the screen.\n * In case of multiple screenshares, the behavior of which one is picked is not defined.\n */\n screenSharingPeerName?: string;\n /**\n * screenShare audio track id, will only be present if there is a screenshare with video track\n */\n screenShareVideoTrackId?: HMSTrackID;\n /**\n * screenShare audio track id, will only be present if there is a screenshare with audio track\n */\n screenShareAudioTrackId?: HMSTrackID;\n}\n\n/**\n * This hook can be used to implement a screenshare toggle button as well as know about the screenshare in the room.\n * This works best if your application only needs to show one screenshare in large view at a time with other screenshares\n * similar to normal user tiles.\n * For any complicated requirement with multiple screenshares it's best to use the store directly.\n * For viewing the screenshare this hook is best used in combination with useVideo.\n * For implementing control bar for local peer, this is used based with useAVToggle.\n * @param handleError to handle any errors during screenshare toggle\n */\nexport const useScreenShare = (handleError: hooksErrHandler = logErrorHandler): useScreenShareResult => {\n const actions = useHMSActions();\n const amIScreenSharing = useHMSStore(selectIsLocalScreenShared);\n const screenSharePeer = useHMSStore(selectPeerScreenSharing);\n const screenShare = useHMSStore(selectScreenSharesByPeerId(screenSharePeer?.id));\n\n const toggleScreenShare = useCallback(\n async (audioOnly = false) => {\n try {\n await actions.setScreenShareEnabled(!amIScreenSharing, audioOnly);\n } catch (err) {\n handleError(err as Error, 'toggleScreenShare');\n }\n },\n [actions, amIScreenSharing, handleError],\n );\n\n return {\n amIScreenSharing,\n screenSharingPeerId: screenSharePeer?.id,\n screenSharingPeerName: screenSharePeer?.name,\n screenShareVideoTrackId: screenShare?.video?.id,\n screenShareAudioTrackId: screenShare?.audio?.id,\n toggleScreenShare,\n };\n};\n"],"names":["useScreenShare","handleError","logErrorHandler","_a","_b","actions","useHMSActions","amIScreenSharing","useHMSStore","selectIsLocalScreenShared","screenSharePeer","selectPeerScreenSharing","screenShare","selectScreenSharesByPeerId","id","toggleScreenShare","useCallback","async","audioOnly","setScreenShareEnabled","err","screenSharingPeerId","screenSharingPeerName","name","screenShareVideoTrackId","video","screenShareAudioTrackId","audio"],"mappings":"gTAkDa,MAAAA,EAAiB,CAACC,EAA+BC,KAlD9D,IAAAC,EAAAC,EAmDE,MAAMC,EAAUC,IACVC,EAAmBC,EAAYC,GAC/BC,EAAkBF,EAAYG,GAC9BC,EAAcJ,EAAYK,EAA4C,MAAjBH,OAAiB,EAAAA,EAAAI,KAEtEC,EAAoBC,GACxBC,MAAOC,GAAY,KACb,UACIb,EAAQc,uBAAuBZ,EAAkBW,EAE7B,CAF6B,MAChDE,GACPnB,EAAYmB,EAAc,oBAAA,IAG9B,CAACf,EAASE,EAAkBN,IAGvB,MAAA,CACLM,mBACAc,oBAAsC,MAAjBX,OAAiB,EAAAA,EAAAI,GACtCQ,sBAAwC,MAAjBZ,OAAiB,EAAAA,EAAAa,KACxCC,wBAAyB,OAAarB,EAAA,MAAAS,OAAA,EAAAA,EAAAa,YAAO,EAAAtB,EAAAW,GAC7CY,wBAAyB,OAAatB,EAAA,MAAAQ,OAAA,EAAAA,EAAAe,YAAO,EAAAvB,EAAAU,GAC7CC,oBAAA"}
@@ -1,2 +1,2 @@
1
- import{__awaiter as i}from"../node_modules/tslib/tslib.es6.js";import{selectVideoTrackByID as o}from"@100mslive/hms-video-store";import{useRef as r,useCallback as e,useEffect as t}from"react";import{useInView as d}from"react-intersection-observer";import{useHMSActions as l,useHMSStore as n}from"../primitives/HmsRoomProvider.js";import c from"../utils/logger.js";const s=({trackId:s,attach:v,threshold:m=.5})=>{const u=l(),a=r(null),f=n(o(s)),{ref:h,inView:p}=d({threshold:m}),b=e((i=>{i&&(a.current=i,h(i))}),[h]);return t((()=>{i(void 0,void 0,void 0,(function*(){a.current&&(null==f?void 0:f.id)&&(p&&f.enabled&&!1!==v?yield u.attachVideo(f.id,a.current):yield u.detachVideo(f.id,a.current))}))}),[u,p,a,null==f?void 0:f.id,null==f?void 0:f.enabled,null==f?void 0:f.deviceID,null==f?void 0:f.plugins,v]),t((()=>()=>{i(void 0,void 0,void 0,(function*(){if(a.current&&f)try{yield u.detachVideo(f.id,a.current)}catch(i){c.w("detach video error for track",f.id,i)}}))}),[]),{videoRef:b}};export{s as useVideo};
1
+ import{selectVideoTrackByID as r}from"@100mslive/hms-video-store";import{useRef as e,useCallback as i,useEffect as t}from"react";import{useInView as o}from"react-intersection-observer";import{useHMSActions as d,useHMSStore as c}from"../primitives/HmsRoomProvider.js";import n from"../utils/logger.js";const a=({trackId:a,attach:l,threshold:s=.5})=>{const m=d(),u=e(null),v=c(r(a)),{ref:h,inView:f}=o({threshold:s}),p=i((r=>{r&&(u.current=r,h(r))}),[h]);return t((()=>{(async()=>{u.current&&(null==v?void 0:v.id)&&(f&&v.enabled&&!1!==l?await m.attachVideo(v.id,u.current):await m.detachVideo(v.id,u.current))})()}),[m,f,u,null==v?void 0:v.id,null==v?void 0:v.enabled,null==v?void 0:v.deviceID,null==v?void 0:v.plugins,l]),t((()=>()=>{(async()=>{if(u.current&&v)try{await m.detachVideo(v.id,u.current)}catch(r){n.w("detach video error for track",v.id,r)}})()}),[]),{videoRef:p}};export{a as useVideo};
2
2
  //# sourceMappingURL=useVideo.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useVideo.js","sources":["../../src/hooks/useVideo.ts"],"sourcesContent":[null],"names":["useVideo","trackId","attach","threshold","actions","useHMSActions","videoRef","useRef","track","useHMSStore","selectVideoTrackByID","ref","inViewRef","inView","useInView","setRefs","useCallback","node","current","useEffect","__awaiter","id","enabled","attachVideo","detachVideo","deviceID","plugins","err","HMSLogger","w"],"mappings":"4WA+BO,MAAMA,EAAW,EAAGC,UAASC,SAAQC,YAAY,OACtD,MAAMC,EAAUC,IACVC,EAAWC,EAAgC,MAC3CC,EAAQC,EAAYC,EAAqBT,KAEvCU,IAAKC,EAAWC,OAAAA,GAAWC,EAAU,CAAEX,cAEzCY,EAAUC,GACbC,IACKA,IACFX,EAASY,QAAUD,EACTL,EAAAK,GAAA,GAGd,CAACL,IAkCH,OA/BAO,GAAU,KACIC,OAAA,OAAA,OAAA,GAAA,YACNd,EAASY,UAAgBV,aAAA,EAALA,EAAOa,MACzBR,GAAUL,EAAMc,UAAsB,IAAXpB,QAEvBE,EAAQmB,YAAYf,EAAMa,GAAIf,EAASY,eAGvCd,EAAQoB,YAAYhB,EAAMa,GAAIf,EAASY,SAAA,GAAA,GAIlD,CAACd,EAASS,EAAQP,EAAUE,aAAK,EAALA,EAAOa,GAAIb,aAAA,EAAAA,EAAOc,QAASd,eAAAA,EAAOiB,SAAUjB,aAAK,EAALA,EAAOkB,QAASxB,IAG3FiB,GAAU,IACD,KACOC,OAAA,OAAA,OAAA,GAAA,YACN,GAAAd,EAASY,SAAWV,EAClB,UAEIJ,EAAQoB,YAAYhB,EAAMa,GAAIf,EAASY,QAES,CAFT,MACtCS,GACGC,EAAAC,EAAE,+BAAgCrB,EAAMa,GAAIM,EAAA,CAAA,GAAA,GAM7D,IAEI,CAAErB,SAAUS,EAAA"}
1
+ {"version":3,"file":"useVideo.js","sources":["../../src/hooks/useVideo.ts"],"sourcesContent":["import { selectVideoTrackByID, HMSTrackID } from '@100mslive/hms-video-store';\nimport React, { useCallback, useEffect, useRef } from 'react';\nimport { useInView } from 'react-intersection-observer';\nimport { useHMSActions, useHMSStore } from '../primitives/HmsRoomProvider';\nimport HMSLogger from '../utils/logger';\n\nexport interface useVideoInput {\n /**\n * TrackId that is to be rendered\n */\n trackId?: HMSTrackID;\n /**\n * Boolean stating whether to override the internal behaviour.\n * when attach is false, even if tile is inView or enabled, it won't be rendered\n */\n attach?: boolean;\n /**\n * Number between 0 and 1 indication when the element is considered inView\n */\n threshold?: number;\n}\n\nexport interface useVideoOutput {\n videoRef: React.RefCallback<HTMLVideoElement>;\n}\n/**\n * This hooks can be used to implement a video tile component. Given a track id it will return a ref.\n * The returned ref can be used to set on a video element meant to display the video.\n * The hook will take care of attaching and detaching video, and will automatically detach when the video\n * goes out of view to save on bandwidth.\n */\nexport const useVideo = ({ trackId, attach, threshold = 0.5 }: useVideoInput): useVideoOutput => {\n const actions = useHMSActions();\n const videoRef = useRef<HTMLVideoElement | null>(null);\n const track = useHMSStore(selectVideoTrackByID(trackId));\n\n const { ref: inViewRef, inView } = useInView({ threshold });\n\n const setRefs = useCallback(\n (node: HTMLVideoElement) => {\n if (node) {\n videoRef.current = node;\n inViewRef(node);\n }\n },\n [inViewRef],\n );\n\n useEffect(() => {\n (async () => {\n if (videoRef.current && track?.id) {\n if (inView && track.enabled && attach !== false) {\n // attach when in view and enabled\n await actions.attachVideo(track.id, videoRef.current);\n } else {\n // detach when not in view\n await actions.detachVideo(track.id, videoRef.current);\n }\n }\n })();\n }, [actions, inView, videoRef, track?.id, track?.enabled, track?.deviceID, track?.plugins, attach]);\n\n // detach on unmount\n useEffect(() => {\n return () => {\n (async () => {\n if (videoRef.current && track) {\n try {\n // detach on unmount\n await actions.detachVideo(track.id, videoRef.current);\n } catch (err) {\n HMSLogger.w('detach video error for track', track.id, err);\n }\n }\n })();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n return { videoRef: setRefs };\n};\n"],"names":["useVideo","trackId","attach","threshold","actions","useHMSActions","videoRef","useRef","track","useHMSStore","selectVideoTrackByID","ref","inViewRef","inView","useInView","setRefs","useCallback","node","current","useEffect","id","enabled","attachVideo","detachVideo","deviceID","plugins","err","HMSLogger","w"],"mappings":"6SA+BO,MAAMA,EAAW,EAAGC,UAASC,SAAQC,YAAY,OACtD,MAAMC,EAAUC,IACVC,EAAWC,EAAgC,MAC3CC,EAAQC,EAAYC,EAAqBT,KAEvCU,IAAKC,EAAWC,OAAAA,GAAWC,EAAU,CAAEX,cAEzCY,EAAUC,GACbC,IACKA,IACFX,EAASY,QAAUD,EACTL,EAAAK,GAAA,GAGd,CAACL,IAkCH,OA/BAO,GAAU,KACP,WACKb,EAASY,UAAW,MAAAV,OAAA,EAAAA,EAAOY,MACzBP,GAAUL,EAAMa,UAAsB,IAAXnB,QAEvBE,EAAQkB,YAAYd,EAAMY,GAAId,EAASY,eAGvCd,EAAQmB,YAAYf,EAAMY,GAAId,EAASY,SAAA,EAPlD,EAOkD,GAIlD,CAACd,EAASS,EAAQP,EAAU,MAAAE,OAAA,EAAAA,EAAOY,GAAI,MAAAZ,OAAA,EAAAA,EAAOa,QAAS,MAAAb,OAAA,EAAAA,EAAOgB,SAAU,MAAAhB,OAAA,EAAAA,EAAOiB,QAASvB,IAG3FiB,GAAU,IACD,KACJ,WACK,GAAAb,EAASY,SAAWV,EAClB,UAEIJ,EAAQmB,YAAYf,EAAMY,GAAId,EAASY,QAES,CAFT,MACtCQ,GACGC,EAAAC,EAAE,+BAAgCpB,EAAMY,GAAIM,EAAA,CAAA,EAN3D,EAM2D,GAM7D,IAEI,CAAEpB,SAAUS,EAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"useVideoList.js","sources":["../../src/hooks/useVideoList.ts"],"sourcesContent":[null],"names":["DEFAULTS","width","height","useVideoList","peers","maxTileCount","maxColCount","maxRowCount","includeScreenShareForPeer","aspectRatio","filterNonPublishingPeers","offsetY","ref","useResizeDetector","tracksMap","useHMSVanillaStore","getState","selectTracksMap","tracksWithPeer","getVideoTracksFromPeers","finalAspectRatio","useMemo","getModeAspectRatio","count","length","tilesInFirstPage","defaultWidth","defaultHeight","lastPageWidth","lastPageHeight","isLastPageDifferentFromFirstPage","calculateLayoutSizes","parentWidth","Math","floor","parentHeight","min","pagesWithTiles","chunkElements","elements","onlyOnePage"],"mappings":"+VAsEA,MAAMA,EACS,CACXC,MAAO,EACPC,OAAQ,GAUCC,EAAe,EAC1BC,QACAC,eACAC,cACAC,cACAC,4BAA4B,MAAM,GAClCC,cAAcT,EACdU,4BAA2B,EAC3BC,UAAU,MAEV,MAAMV,MAAEA,EAAQ,EAAGC,OAAAA,EAAS,MAAGU,GAAQC,IAGjCC,EAFQC,IAEwCC,SAASC,GACzDC,EAAkCC,EACtCf,EACAU,EACAN,EACAE,GAEIU,EAAmBC,GAAQ,KAC/B,GAAIZ,EACK,OAAAA,EAIF,MAAA,CACLR,MAHsBqB,EAAmBJ,IAGf,EAC1BhB,OAAQ,EAAA,GAET,CAACO,EAAaS,IACXK,EAAQL,EAAeM,QACvBC,iBACJA,eACAC,EACAC,cAAAA,EAAAC,cACAA,iBACAC,EACAC,iCAAAA,GACET,GACF,IACEU,EAAqB,CACnBR,QACAS,YAAaC,KAAKC,MAAMjC,GACxBkC,aAAcF,KAAKC,MAAMhC,GAAU+B,KAAKG,IAAIlC,EAAQS,GACpDN,eACAE,cACAD,cACAG,YAAaW,KAEjB,CAACG,EAAOtB,EAAOC,EAAQG,EAAcE,EAAaD,EAAac,EAAkBT,IAwB5E,MAAA,CACL0B,eAvB4BhB,GAC5B,IACEiB,EAA6B,CAC3BC,SAAUrB,EACVO,mBACAe,aAAa,EACbV,mCACAJ,eACAC,gBACAC,gBACAC,oBAEJ,CACEX,EACAO,EACAK,EACAJ,EACAC,EACAC,EACAC,IAKFjB,MAAA"}
1
+ {"version":3,"file":"useVideoList.js","sources":["../../src/hooks/useVideoList.ts"],"sourcesContent":["import { HMSPeer, HMSTrack, HMSTrackID, selectTracksMap } from '@100mslive/hms-video-store';\nimport React, { useMemo } from 'react';\nimport {\n calculateLayoutSizes,\n chunkElements,\n getModeAspectRatio,\n getVideoTracksFromPeers,\n TrackWithPeer,\n} from '../utils/layout';\nimport { useHMSVanillaStore } from '../primitives/HmsRoomProvider';\nimport { useResizeDetector } from 'react-resize-detector';\n\nexport interface useVideoListInput {\n /**\n * peers is the list of all peers you need to display\n */\n peers: HMSPeer[];\n /**\n * Max tiles in a page. Overrides maxRowCount and maxColCount\n */\n maxTileCount?: number;\n /**\n * Max rows in a page. Only applied if maxTileCount is not present\n */\n maxRowCount?: number;\n /**\n * Max columns in a page. Only applied if maxTileCount and maxRowCount are not present\n */\n maxColCount?: number;\n /**\n * A function which tells whether to show the screenShare for a peer who is screensharing. A peer is passed\n * and a boolean value is expected.\n * This can be useful if there are multiple screenShares in the room where you may want to show the main one in the\n * center view and others in video list along side other tiles. No screenShare is included by default.\n * e.g. includeScreenShare = (peer) => return peer.id !== mainScreenSharingPeer.id\n */\n includeScreenShareForPeer?: (peer: HMSPeer) => boolean;\n /**\n * Aspect ratio of VideoTiles, ideally this should be the same as the aspect ratio selected for\n * capture in the dashboard template.\n */\n aspectRatio?: { width: number; height: number };\n /**\n * By default this will be true. Only publishing(audio/video/screen) peers in the passed in peer list\n * will be filtered. If you wish to show all peers, pass false for this.\n */\n filterNonPublishingPeers?: boolean;\n /**\n * 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\n */\n offsetY?: number;\n}\n\nexport interface useVideoListTile extends TrackWithPeer {\n width: number;\n height: number;\n}\n\nexport interface useVideoResult {\n /**\n * This returns a list of all pages with every page containing the list of all tiles on it.\n */\n pagesWithTiles: useVideoListTile[][];\n /**\n * add the ref to the element going to render the video list, this is used to measure the available\n * space/dimensions in order to calculate the best fit\n */\n ref: React.MutableRefObject<any>;\n}\n\nconst DEFAULTS = {\n aspectRatio: {\n width: 1,\n height: 1,\n },\n};\n\n/**\n * This hook can be used to build a paginated gallery view of video tiles. You can give the hook\n * a list of all the peers which need to be shown and it tells you how to structure the UI by giving\n * a list of pages with every page having a list of video tiles.\n * Please check the documentation of input and output types for more details.\n */\nexport const useVideoList = ({\n peers,\n maxTileCount,\n maxColCount,\n maxRowCount,\n includeScreenShareForPeer = () => false,\n aspectRatio = DEFAULTS.aspectRatio,\n filterNonPublishingPeers = true,\n offsetY = 0,\n}: useVideoListInput): useVideoResult => {\n const { width = 0, height = 0, ref } = useResizeDetector();\n const store = useHMSVanillaStore();\n // using vanilla store as we don't need re-rendering everytime something in a track changes\n const tracksMap: Record<HMSTrackID, HMSTrack> = store.getState(selectTracksMap);\n const tracksWithPeer: TrackWithPeer[] = getVideoTracksFromPeers(\n peers,\n tracksMap,\n includeScreenShareForPeer,\n filterNonPublishingPeers,\n );\n const finalAspectRatio = useMemo(() => {\n if (aspectRatio) {\n return aspectRatio;\n }\n const modeAspectRatio = getModeAspectRatio(tracksWithPeer);\n // Default to 1 if there are no video tracks\n return {\n width: modeAspectRatio || 1,\n height: 1,\n };\n }, [aspectRatio, tracksWithPeer]);\n const count = tracksWithPeer.length;\n const {\n tilesInFirstPage,\n defaultWidth,\n defaultHeight,\n lastPageWidth,\n lastPageHeight,\n isLastPageDifferentFromFirstPage,\n } = useMemo(\n () =>\n calculateLayoutSizes({\n count,\n parentWidth: Math.floor(width),\n parentHeight: Math.floor(height) - Math.min(height, offsetY),\n maxTileCount,\n maxRowCount,\n maxColCount,\n aspectRatio: finalAspectRatio,\n }),\n [count, width, height, maxTileCount, maxRowCount, maxColCount, finalAspectRatio, offsetY],\n );\n const chunkedTracksWithPeer = useMemo(\n () =>\n chunkElements<TrackWithPeer>({\n elements: tracksWithPeer,\n tilesInFirstPage,\n onlyOnePage: false,\n isLastPageDifferentFromFirstPage,\n defaultWidth,\n defaultHeight,\n lastPageWidth,\n lastPageHeight,\n }),\n [\n tracksWithPeer,\n tilesInFirstPage,\n isLastPageDifferentFromFirstPage,\n defaultWidth,\n defaultHeight,\n lastPageWidth,\n lastPageHeight,\n ],\n );\n return {\n pagesWithTiles: chunkedTracksWithPeer,\n ref,\n };\n};\n"],"names":["DEFAULTS","width","height","useVideoList","peers","maxTileCount","maxColCount","maxRowCount","includeScreenShareForPeer","aspectRatio","filterNonPublishingPeers","offsetY","ref","useResizeDetector","tracksMap","useHMSVanillaStore","getState","selectTracksMap","tracksWithPeer","getVideoTracksFromPeers","finalAspectRatio","useMemo","getModeAspectRatio","count","length","tilesInFirstPage","defaultWidth","defaultHeight","lastPageWidth","lastPageHeight","isLastPageDifferentFromFirstPage","calculateLayoutSizes","parentWidth","Math","floor","parentHeight","min","pagesWithTiles","chunkElements","elements","onlyOnePage"],"mappings":"+VAsEA,MAAMA,EACS,CACXC,MAAO,EACPC,OAAQ,GAUCC,EAAe,EAC1BC,QACAC,eACAC,cACAC,cACAC,4BAA4B,MAAM,GAClCC,cAAcT,EACdU,4BAA2B,EAC3BC,UAAU,MAEV,MAAMV,MAAEA,EAAQ,EAAGC,OAAAA,EAAS,MAAGU,GAAQC,IAGjCC,EAFQC,IAEwCC,SAASC,GACzDC,EAAkCC,EACtCf,EACAU,EACAN,EACAE,GAEIU,EAAmBC,GAAQ,KAC/B,GAAIZ,EACK,OAAAA,EAIF,MAAA,CACLR,MAHsBqB,EAAmBJ,IAGf,EAC1BhB,OAAQ,EAAA,GAET,CAACO,EAAaS,IACXK,EAAQL,EAAeM,QACvBC,iBACJA,EAAAC,aACAA,EAAAC,cACAA,EAAAC,cACAA,EAAAC,eACAA,EAAAC,iCACAA,GACET,GACF,IACEU,EAAqB,CACnBR,QACAS,YAAaC,KAAKC,MAAMjC,GACxBkC,aAAcF,KAAKC,MAAMhC,GAAU+B,KAAKG,IAAIlC,EAAQS,GACpDN,eACAE,cACAD,cACAG,YAAaW,KAEjB,CAACG,EAAOtB,EAAOC,EAAQG,EAAcE,EAAaD,EAAac,EAAkBT,IAwB5E,MAAA,CACL0B,eAvB4BhB,GAC5B,IACEiB,EAA6B,CAC3BC,SAAUrB,EACVO,mBACAe,aAAa,EACbV,mCACAJ,eACAC,gBACAC,gBACAC,oBAEJ,CACEX,EACAO,EACAK,EACAJ,EACAC,EACAC,EACAC,IAKFjB,MAAA"}
package/dist/index.cjs.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("@100mslive/hms-video-store"),i=require("zustand"),o=require("react-intersection-observer"),r=require("react-resize-detector");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a,s,l=n(e),c=n(i);function u(e,t){if(Object.is(e,t))return!0;if("object"!=typeof e||null===e||"object"!=typeof t||null===t)return!1;const i=Object.keys(e);if(i.length!==Object.keys(t).length)return!1;for(let o=0;o<i.length;o++)if(!Object.prototype.hasOwnProperty.call(t,i[o])||!Object.is(e[i[o]],t[i[o]]))return!1;return!0}(s=a||(a={}))[s.VERBOSE=0]="VERBOSE",s[s.DEBUG=1]="DEBUG",s[s.INFO=2]="INFO",s[s.WARN=3]="WARN",s[s.ERROR=4]="ERROR",s[s.NONE=5]="NONE";class d{static v(e,...t){this.log(a.VERBOSE,e,...t)}static d(e,...t){this.log(a.DEBUG,e,...t)}static i(e,...t){this.log(a.INFO,e,...t)}static w(e,...t){this.log(a.WARN,e,...t)}static e(e,...t){this.log(a.ERROR,e,...t)}static log(e,t,...i){if(!(this.level.valueOf()>e.valueOf()))switch(e){case a.VERBOSE:console.log("HMSui-components: ",t,...i);break;case a.DEBUG:console.debug("HMSui-components: ",t,...i);break;case a.INFO:console.info("HMSui-components: ",t,...i);break;case a.WARN:console.warn("HMSui-components: ",t,...i);break;case a.ERROR:console.error("HMSui-components: ",t,...i)}}}d.level=a.VERBOSE;const h="It seems like you forgot to add your component within a top level HMSRoomProvider, please refer to 100ms react docs(https://docs.100ms.live/javascript/v2/features/integration#react-hooks) to check on the required steps for using this hook.";const g="undefined"!=typeof window,v=e.createContext(null);let f;const p=(m=v,(t,i=u)=>{t||d.w("fetching full store without passing any selector may have a heavy performance impact on your website.");const o=e.useContext(m);if(!o)throw new Error(h);return(0,o.store)(t,i)});var m;const y=function(t){return(i,o=u)=>{i||d.w("fetching full store without passing any selector may have a heavy performance impact on your website.");const r=e.useContext(t);if(!r)throw new Error(h);const n=r.statsStore;return null==n?void 0:n(i,o)}}(v),w=()=>{const t=e.useContext(v);if(!t)throw new Error(h);return t.store},S=()=>{const t=e.useContext(v);if(!t)throw new Error(h);return t.notifications},P=()=>{const t=e.useContext(v);if(!t)throw new Error(h);return t.actions},b=t=>{const i=e.useContext(v),[o,r]=e.useState(null);if(!i)throw new Error(h);return e.useEffect((()=>{if(!i.notifications)return;return i.notifications.onNotification((e=>{r(e)}),t)}),[i.notifications,t]),o};function E(e,t,i,o){return new(i||(i=Promise))((function(r,n){function a(e){try{l(o.next(e))}catch(e){n(e)}}function s(e){try{l(o.throw(e))}catch(e){n(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,s)}l((o=o.apply(e,t||[])).next())}))}const R=(e,t)=>d.e("react-sdk",t,e),k=(e,t,i)=>E(void 0,void 0,void 0,(function*(){if(t)try{yield e.setRemoteTrackEnabled(t.id,!t.enabled)}catch(e){i(e,"remoteToggle")}})),x=({elements:e,tilesInFirstPage:t,onlyOnePage:i,isLastPageDifferentFromFirstPage:o,defaultWidth:r,defaultHeight:n,lastPageWidth:a,lastPageHeight:s})=>{const l=((e,t,i)=>e.reduce(((e,o,r)=>{const n=Math.floor(r/t);return n>0&&i||(e[n]||(e[n]=[]),e[n].push(o)),e}),[]))(e,t,i);return l.map(((e,t)=>e.map((e=>{const i=t===l.length-1,c=o&&i?a:r,u=o&&i?s:n;return Object.assign(Object.assign({},e),{height:u,width:c})}))))};const I=(e,t,i,o,r)=>{if(e<0||t<0)throw new Error("Container must have a non-negative area");if(i<1||!Number.isInteger(i))throw new Error("Number of shapes to place must be a positive integer");const n=o&&r&&o/r;if(void 0!==n&&isNaN(n))throw new Error("Aspect ratio must be a number");let a={area:0,cols:0,rows:0,width:0,height:0};if(void 0!==n)for(let o=i;o>0;o+=-1){const r=Math.ceil(i/o);let s,l;e/(o*n)<=t/r?(s=e/o,l=s/n):(l=t/r,s=l*n);const c=s*l;c>a.area&&(a={area:c,width:s,height:l,rows:r,cols:o})}return a};function M({count:e,parentWidth:t,parentHeight:i,maxTileCount:o,maxRowCount:r,maxColCount:n,aspectRatio:a}){let s=0,l=0,c=0,u=0,d=!1,h=0;if(0===e)return{tilesInFirstPage:h,defaultWidth:s,defaultHeight:l,lastPageWidth:c,lastPageHeight:u,isLastPageDifferentFromFirstPage:d};if(o)({tilesInFirstPage:h,defaultWidth:s,defaultHeight:l,lastPageWidth:c,lastPageHeight:u,isLastPageDifferentFromFirstPage:d}=(({parentWidth:e,parentHeight:t,count:i,maxCount:o,aspectRatio:r})=>{let n=0,a=0,s=0,l=0,c=!1,u=0,d=0;const{width:h,height:g}=I(e,t,Math.min(i,o),r.width,r.height);if(n=h,a=g,u=Math.min(i,o),d=i%o,c=d>0&&i>o,c){const{width:i,height:o}=I(e,t,d,r.width,r.height);s=i,l=o}return{tilesInFirstPage:u,defaultWidth:n,defaultHeight:a,lastPageWidth:s,lastPageHeight:l,isLastPageDifferentFromFirstPage:c}})({parentWidth:t,parentHeight:i,count:e,maxCount:o,aspectRatio:a}));else if(r)({tilesInFirstPage:h,defaultWidth:s,defaultHeight:l,lastPageWidth:c,lastPageHeight:u,isLastPageDifferentFromFirstPage:d}=(({parentWidth:e,parentHeight:t,count:i,maxCount:o,aspectRatio:r})=>{let n=0,a=0,s=0,l=0,c=!1,u=0,d=0;const h=Math.min(Math.ceil(Math.sqrt(i*(r.width/r.height)/(e/t))),o),g=t/h,v=g*(r.width/r.height),f=Math.floor(e/v);if(n=v,a=g,u=Math.min(i,h*f),d=i%(h*f),c=d>0&&i>h*f,c){const i=t/Math.min(Math.ceil(Math.sqrt(d*(r.width/r.height)/(e/t))),o);l=i,s=i*(r.width/r.height)}return{tilesInFirstPage:u,defaultWidth:n,defaultHeight:a,lastPageWidth:s,lastPageHeight:l,isLastPageDifferentFromFirstPage:c}})({parentWidth:t,parentHeight:i,count:e,maxCount:r,aspectRatio:a}));else if(n)({tilesInFirstPage:h,defaultWidth:s,defaultHeight:l,lastPageWidth:c,lastPageHeight:u,isLastPageDifferentFromFirstPage:d}=(({parentWidth:e,parentHeight:t,count:i,maxCount:o,aspectRatio:r})=>{let n=0,a=0,s=0,l=0,c=!1,u=0,d=0;const h=Math.min(Math.ceil(Math.sqrt(i*(e/t)/(r.width/r.height))),o);let g=e/h,v=g/(r.width/r.height);v>t&&(v=t,g=v/(r.height/r.width));const f=Math.floor(t/v);if(a=v,n=g,u=Math.min(i,f*h),d=i%(f*h),c=d>0&&i>f*h,c){let i=e/Math.min(Math.ceil(Math.sqrt(d*(e/t)/(r.width/r.height))),o),n=i/(r.width/r.height);n>t&&(n=t,i=n/(r.height/r.width)),l=n,s=i}return{tilesInFirstPage:u,defaultWidth:n,defaultHeight:a,lastPageWidth:s,lastPageHeight:l,isLastPageDifferentFromFirstPage:c}})({parentWidth:t,parentHeight:i,count:e,maxCount:n,aspectRatio:a}));else{const{width:o,height:r}=I(t,i,e,a.width,a.height);s=o,l=r,h=e}return{tilesInFirstPage:h,defaultWidth:s,defaultHeight:l,lastPageWidth:c,lastPageHeight:u,isLastPageDifferentFromFirstPage:d}}const H={width:1,height:1};var C;exports.DeviceType=void 0,(C=exports.DeviceType||(exports.DeviceType={})).videoInput="videoInput",C.audioInput="audioInput",C.audioOutput="audioOutput";exports.HMSRoomProvider=({children:i,actions:o,store:r,notifications:n,stats:a,isHMSStatsOn:s=!1,leaveOnUnload:u=!0})=>{if(!f){const e=()=>{throw new Error("modifying store is not allowed")};if(o&&r)f={actions:o,store:c.default(Object.assign(Object.assign({},r),{setState:e,destroy:e}))},n&&(f.notifications=n),a&&(f.statsStore=c.default({getState:a.getState,subscribe:a.subscribe,setState:e,destroy:e}));else{const i=new t.HMSReactiveStore;if(f={actions:i.getActions(),store:c.default(Object.assign(Object.assign({},i.getStore()),{setState:e,destroy:e})),notifications:i.getNotifications()},s){const t=i.getStats();f.statsStore=c.default({getState:t.getState,subscribe:t.subscribe,setState:e,destroy:e})}}f.actions.setFrameworkInfo({type:"react-web",version:l.default.version,sdkVersion:require("../../package.json").version})}return e.useEffect((()=>{g&&u&&(window.addEventListener("beforeunload",(()=>f.actions.leave())),window.addEventListener("onunload",(()=>f.actions.leave())))}),[u]),l.default.createElement(v.Provider,{value:f},i)},exports.throwErrorHandler=e=>{throw e},exports.useAVToggle=(i=R)=>{const o=p(t.selectIsLocalAudioEnabled),r=p(t.selectIsLocalVideoEnabled),n=p(t.selectIsAllowedToPublish),a=P(),s=e.useCallback((()=>E(void 0,void 0,void 0,(function*(){try{yield a.setLocalAudioEnabled(!o)}catch(e){i(e,"toggleAudio")}}))),[a,o,i]),l=e.useCallback((()=>E(void 0,void 0,void 0,(function*(){try{yield a.setLocalVideoEnabled(!r)}catch(e){i(e,"toggleVideo")}}))),[a,r,i]);return{isLocalAudioEnabled:o,isLocalVideoEnabled:r,toggleAudio:(null==n?void 0:n.audio)?s:void 0,toggleVideo:(null==n?void 0:n.video)?l:void 0}},exports.useAudioLevelStyles=function({trackId:i,getStyle:o,ref:r}){const n=w();e.useEffect((()=>n.subscribe((e=>{if(!r.current)return;const t=o(e);for(const e in t)r.current.style[e]=t[e]}),t.selectTrackAudioByID(i))),[o,r,n,i])},exports.useAutoplayError=()=>{const i=b(t.HMSNotificationTypes.ERROR),[o,r]=e.useState(""),n=P(),a=e.useCallback((()=>E(void 0,void 0,void 0,(function*(){yield n.unblockAudio()}))),[n]);return e.useEffect((()=>{3008===(null==i?void 0:i.data.code)&&r(null==i?void 0:i.data.message)}),[i]),{error:o,unblockAudio:a,resetError:()=>r("")}},exports.useCustomEvent=({type:i,json:o=!0,onEvent:r,handleError:n=R})=>{const a=P(),s=S();e.useEffect((()=>{a.ignoreMessageTypes([i])}),[a,i]),e.useEffect((()=>{if(!s)return;return s.onNotification((e=>{const t=e.data;if(t&&t.type===i)try{const e=o?JSON.parse(t.message):t.message;null==r||r(e)}catch(e){n(e,"handleCustomEvent")}}),t.HMSNotificationTypes.NEW_MESSAGE)}),[s,i,o,r,n]);return{sendEvent:e.useCallback(((e,t)=>E(void 0,void 0,void 0,(function*(){try{const n=((e,t)=>t?JSON.stringify(e||""):e)(e,o);t&&Array.isArray(null==t?void 0:t.roleNames)?yield a.sendGroupMessage(n,t.roleNames,i):"string"==typeof(null==t?void 0:t.peerId)?yield a.sendDirectMessage(n,t.peerId,i):yield a.sendBroadcastMessage(n,i),null==r||r(e)}catch(e){n(e,"sendCustomEvent")}}))),[a,n,r,i,o])}},exports.useDevices=(i=R)=>{const o=P(),r=p(t.selectDevices),n=p(t.selectLocalMediaSettings),a=p(t.selectIsAllowedToPublish),s={[exports.DeviceType.audioOutput]:n.audioOutputDeviceId},l={[exports.DeviceType.audioOutput]:r.audioOutput};a.video&&(l[exports.DeviceType.videoInput]=r.videoInput,s[exports.DeviceType.videoInput]=n.videoInputDeviceId),a.audio&&(l[exports.DeviceType.audioInput]=r.audioInput,s[exports.DeviceType.audioInput]=n.audioInputDeviceId);return{allDevices:l,selectedDeviceIDs:s,updateDevice:e.useCallback((({deviceType:e,deviceId:t})=>E(void 0,void 0,void 0,(function*(){try{switch(e){case exports.DeviceType.audioInput:yield o.setAudioSettings({deviceId:t});break;case exports.DeviceType.videoInput:yield o.setVideoSettings({deviceId:t});break;case exports.DeviceType.audioOutput:yield o.setAudioOutputDevice(t)}}catch(e){i(e,"updateDevices")}}))),[i,o])}},exports.useHMSActions=P,exports.useHMSNotifications=b,exports.useHMSStatsStore=y,exports.useHMSStore=p,exports.useHMSVanillaNotifications=S,exports.useHMSVanillaStore=w,exports.useParticipantList=()=>{const i=p(t.selectIsConnectedToRoom),o=p(i?t.selectPeers:t.selectRemotePeers),r=p(t.selectPeerCount),n=e.useMemo((()=>{return(e=o)&&Array.isArray(e)&&0!==e.length?e.reduce(((e,t)=>t.roleName?(e[t.roleName]||(e[t.roleName]=[]),e[t.roleName].push(t),e):e),{}):{};var e}),[o]);return{roles:Object.keys(n),participantsByRoles:n,peerCount:r,isConnected:i}},exports.useParticipants=e=>{var i;const o=p(t.selectIsConnectedToRoom),r=p(t.selectPeerCount),n=p(t.selectAvailableRoleNames);let a=p(o?t.selectPeers:t.selectRemotePeers);const s=Array.from(new Set(a.map((e=>e.roleName)))),l=w();if((null===(i=null==e?void 0:e.metadata)||void 0===i?void 0:i.isHandRaised)&&(a=a.filter((e=>l.getState(t.selectPeerMetadata(e.id)).isHandRaised))),(null==e?void 0:e.role)&&n.includes(e.role)&&(a=a.filter((t=>t.roleName===e.role))),null==e?void 0:e.search){const t=e.search.toLowerCase();a=a.filter((e=>{var i;return(null===(i=e.roleName)||void 0===i?void 0:i.toLowerCase().includes(t))||e.name.toLowerCase().includes(t)}))}return{participants:a,isConnected:o,peerCount:r,rolesWithParticipants:s}},exports.usePreviewJoin=({name:i="",token:o,metadata:r,handleError:n=R,initEndpoint:a,initialSettings:s,captureNetworkQualityInPreview:l})=>{const c=P(),u=p(t.selectRoomState),d=p(t.selectIsConnectedToRoom)||!1,h=u===t.HMSRoomState.Preview,g=e.useMemo((()=>({userName:i,authToken:o,metaData:r,rememberDeviceSelection:!0,settings:s,initEndpoint:a,captureNetworkQualityInPreview:l})),[i,o,r,a,s,l]),v=e.useCallback((()=>E(void 0,void 0,void 0,(function*(){if(o&&u===t.HMSRoomState.Disconnected){d&&(yield c.leave());try{yield c.preview(g)}catch(e){n(e,"preview")}}}))),[c,n,o,u,g,d]);return{enableJoin:h,join:e.useCallback((()=>E(void 0,void 0,void 0,(function*(){if(o)try{yield c.join(g)}catch(e){n(e,"join")}}))),[c,g,n,o]),isConnected:d,preview:v}},exports.useRecordingStreaming=()=>{const e=p(t.selectRecordingState),i=p(t.selectRTMPState),o=p(t.selectHLSState),r=e.server.running,n=e.browser.running,a=e.hls.running,s=r||n||a;return{isServerRecordingOn:r,isBrowserRecordingOn:n,isHLSRecordingOn:a,isStreamingOn:o.running||i.running,isHLSRunning:o.running,isRTMPRunning:i.running,isRecordingOn:s}},exports.useRemoteAVToggle=(i,o,r=R)=>{const n=P(),a=p(t.selectAudioTrackByID(i)),s=p(t.selectVideoTrackByID(o)),l=p(t.selectAudioTrackVolume(null==a?void 0:a.id)),c=p(t.selectPermissions),u=(null==s?void 0:s.enabled)?null==c?void 0:c.mute:null==c?void 0:c.unmute,d=(null==a?void 0:a.enabled)?null==c?void 0:c.mute:null==c?void 0:c.unmute,h=e.useCallback((()=>E(void 0,void 0,void 0,(function*(){yield k(n,a,r)}))),[n,a,r]),g=e.useCallback((()=>E(void 0,void 0,void 0,(function*(){yield k(n,s,r)}))),[n,r,s]),v=e.useCallback((e=>{a&&n.setVolume(e,a.id)}),[n,a]);return{isAudioEnabled:!!(null==a?void 0:a.enabled),isVideoEnabled:!!(null==s?void 0:s.enabled),volume:l,toggleAudio:a&&d?h:void 0,toggleVideo:"regular"===(null==s?void 0:s.source)&&u?g:void 0,setVolume:a?v:void 0}},exports.useScreenShare=(i=R)=>{var o,r;const n=P(),a=p(t.selectIsLocalScreenShared),s=p(t.selectPeerScreenSharing),l=p(t.selectScreenSharesByPeerId(null==s?void 0:s.id)),c=e.useCallback(((e=!1)=>E(void 0,void 0,void 0,(function*(){try{yield n.setScreenShareEnabled(!a,e)}catch(e){i(e,"toggleScreenShare")}}))),[n,a,i]);return{amIScreenSharing:a,screenSharingPeerId:null==s?void 0:s.id,screenSharingPeerName:null==s?void 0:s.name,screenShareVideoTrackId:null===(o=null==l?void 0:l.video)||void 0===o?void 0:o.id,screenShareAudioTrackId:null===(r=null==l?void 0:l.audio)||void 0===r?void 0:r.id,toggleScreenShare:c}},exports.useVideo=({trackId:i,attach:r,threshold:n=.5})=>{const a=P(),s=e.useRef(null),l=p(t.selectVideoTrackByID(i)),{ref:c,inView:u}=o.useInView({threshold:n}),h=e.useCallback((e=>{e&&(s.current=e,c(e))}),[c]);return e.useEffect((()=>{E(void 0,void 0,void 0,(function*(){s.current&&(null==l?void 0:l.id)&&(u&&l.enabled&&!1!==r?yield a.attachVideo(l.id,s.current):yield a.detachVideo(l.id,s.current))}))}),[a,u,s,null==l?void 0:l.id,null==l?void 0:l.enabled,null==l?void 0:l.deviceID,null==l?void 0:l.plugins,r]),e.useEffect((()=>()=>{E(void 0,void 0,void 0,(function*(){if(s.current&&l)try{yield a.detachVideo(l.id,s.current)}catch(e){d.w("detach video error for track",l.id,e)}}))}),[]),{videoRef:h}},exports.useVideoList=({peers:i,maxTileCount:o,maxColCount:n,maxRowCount:a,includeScreenShareForPeer:s=(()=>!1),aspectRatio:l=H,filterNonPublishingPeers:c=!0,offsetY:u=0})=>{const{width:d=0,height:h=0,ref:g}=r.useResizeDetector(),v=((e,t,i,o=!0)=>{if(!e||!t||!i)return[];const r=[];for(const n of e)if(void 0===n.videoTrack&&n.audioTrack&&t[n.audioTrack]?r.push({peer:n}):n.videoTrack&&t[n.videoTrack]?r.push({track:t[n.videoTrack],peer:n}):o||r.push({peer:n}),n.auxiliaryTracks.length>0&&n.auxiliaryTracks.forEach((e=>{const i=t[e];"video"===(null==i?void 0:i.type)&&"regular"===(null==i?void 0:i.source)&&r.push({track:i,peer:n})})),i(n)&&n.auxiliaryTracks.length>0){const e=n.auxiliaryTracks.find((e=>{const i=t[e];return"video"===(null==i?void 0:i.type)&&"screen"===(null==i?void 0:i.source)}));e&&r.push({track:t[e],peer:n})}return r})(i,w().getState(t.selectTracksMap),s,c),f=e.useMemo((()=>{if(l)return l;return{width:function(e){if(0===e.length)return null;const t={};let i=e[0],o=1;for(let r=0;r<e.length;r++){const n=e[r];null===t[n]?t[n]=1:t[n]++,t[n]>o&&(i=n,o=t[n])}return i}(v.filter((e=>{var t,i;return(null===(t=e.track)||void 0===t?void 0:t.width)&&(null===(i=e.track)||void 0===i?void 0:i.height)})).map((e=>{var t,i;return((null===(t=e.track)||void 0===t?void 0:t.width)||1)/((null===(i=e.track)||void 0===i?void 0:i.height)||1)})))||1,height:1}}),[l,v]),p=v.length,{tilesInFirstPage:m,defaultWidth:y,defaultHeight:S,lastPageWidth:P,lastPageHeight:b,isLastPageDifferentFromFirstPage:E}=e.useMemo((()=>M({count:p,parentWidth:Math.floor(d),parentHeight:Math.floor(h)-Math.min(h,u),maxTileCount:o,maxRowCount:a,maxColCount:n,aspectRatio:f})),[p,d,h,o,a,n,f,u]);return{pagesWithTiles:e.useMemo((()=>x({elements:v,tilesInFirstPage:m,onlyOnePage:!1,isLastPageDifferentFromFirstPage:E,defaultWidth:y,defaultHeight:S,lastPageWidth:P,lastPageHeight:b})),[v,m,E,y,S,P,b]),ref:g}},Object.keys(t).forEach((function(e){"default"===e||exports.hasOwnProperty(e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return t[e]}})}));
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("@100mslive/hms-video-store"),i=require("zustand"),r=require("react-intersection-observer"),o=require("react-resize-detector");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n,s,l=a(e),c=a(i);function u(e,t){if(Object.is(e,t))return!0;if("object"!=typeof e||null===e||"object"!=typeof t||null===t)return!1;const i=Object.keys(e);if(i.length!==Object.keys(t).length)return!1;for(let r=0;r<i.length;r++)if(!Object.prototype.hasOwnProperty.call(t,i[r])||!Object.is(e[i[r]],t[i[r]]))return!1;return!0}(s=n||(n={}))[s.VERBOSE=0]="VERBOSE",s[s.DEBUG=1]="DEBUG",s[s.INFO=2]="INFO",s[s.WARN=3]="WARN",s[s.ERROR=4]="ERROR",s[s.NONE=5]="NONE";class d{static v(e,...t){this.log(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,...i){if(!(this.level.valueOf()>e.valueOf()))switch(e){case 0:console.log("HMSui-components: ",t,...i);break;case 1:console.debug("HMSui-components: ",t,...i);break;case 2:console.info("HMSui-components: ",t,...i);break;case 3:console.warn("HMSui-components: ",t,...i);break;case 4:console.error("HMSui-components: ",t,...i)}}}d.level=0;const h="It seems like you forgot to add your component within a top level HMSRoomProvider, please refer to 100ms react docs(https://docs.100ms.live/javascript/v2/features/integration#react-hooks) to check on the required steps for using this hook.";const g="undefined"!=typeof window;var p=Object.defineProperty,f=Object.defineProperties,v=Object.getOwnPropertyDescriptors,m=Object.getOwnPropertySymbols,w=Object.prototype.hasOwnProperty,y=Object.prototype.propertyIsEnumerable,b=(e,t,i)=>t in e?p(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,P=(e,t)=>{for(var i in t||(t={}))w.call(t,i)&&b(e,i,t[i]);if(m)for(var i of m(t))y.call(t,i)&&b(e,i,t[i]);return e},S=(e,t)=>f(e,v(t));const k=e.createContext(null);let I;const x=(E=k,(t,i=u)=>{t||d.w("fetching full store without passing any selector may have a heavy performance impact on your website.");const r=e.useContext(E);if(!r)throw new Error(h);return(0,r.store)(t,i)});var E;const O=function(t){return(i,r=u)=>{i||d.w("fetching full store without passing any selector may have a heavy performance impact on your website.");const o=e.useContext(t);if(!o)throw new Error(h);const a=o.statsStore;return null==a?void 0:a(i,r)}}(k),M=()=>{const t=e.useContext(k);if(!t)throw new Error(h);return t.store},H=()=>{const t=e.useContext(k);if(!t)throw new Error(h);return t.notifications},R=()=>{const t=e.useContext(k);if(!t)throw new Error(h);return t.actions},C=t=>{const i=e.useContext(k),[r,o]=e.useState(null);if(!i)throw new Error(h);return e.useEffect((()=>{if(!i.notifications)return;return i.notifications.onNotification((e=>{o(e)}),t)}),[i.notifications,t]),r},T=(e,t)=>d.e("react-sdk",t,e),D=async(e,t,i)=>{if(t)try{await e.setRemoteTrackEnabled(t.id,!t.enabled)}catch(e){i(e,"remoteToggle")}};var F=Object.defineProperty,N=Object.defineProperties,W=Object.getOwnPropertyDescriptors,A=Object.getOwnPropertySymbols,L=Object.prototype.hasOwnProperty,j=Object.prototype.propertyIsEnumerable,V=(e,t,i)=>t in e?F(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i;const B=({elements:e,tilesInFirstPage:t,onlyOnePage:i,isLastPageDifferentFromFirstPage:r,defaultWidth:o,defaultHeight:a,lastPageWidth:n,lastPageHeight:s})=>{const l=((e,t,i)=>e.reduce(((e,r,o)=>{const a=Math.floor(o/t);return a>0&&i||(e[a]||(e[a]=[]),e[a].push(r)),e}),[]))(e,t,i);return l.map(((e,t)=>e.map((e=>{const i=t===l.length-1,c=r&&i?n:o,u=r&&i?s:a;return d=((e,t)=>{for(var i in t||(t={}))L.call(t,i)&&V(e,i,t[i]);if(A)for(var i of A(t))j.call(t,i)&&V(e,i,t[i]);return e})({},e),N(d,W({height:u,width:c}));var d}))))};const q=(e,t,i,r,o)=>{if(e<0||t<0)throw new Error("Container must have a non-negative area");if(i<1||!Number.isInteger(i))throw new Error("Number of shapes to place must be a positive integer");const a=r&&o&&r/o;if(void 0!==a&&isNaN(a))throw new Error("Aspect ratio must be a number");let n={area:0,cols:0,rows:0,width:0,height:0};if(void 0!==a)for(let r=i;r>0;r+=-1){const o=Math.ceil(i/r);let s,l;e/(r*a)<=t/o?(s=e/r,l=s/a):(l=t/o,s=l*a);const c=s*l;c>n.area&&(n={area:c,width:s,height:l,rows:o,cols:r})}return n};function G({count:e,parentWidth:t,parentHeight:i,maxTileCount:r,maxRowCount:o,maxColCount:a,aspectRatio:n}){let s=0,l=0,c=0,u=0,d=!1,h=0;if(0===e)return{tilesInFirstPage:h,defaultWidth:s,defaultHeight:l,lastPageWidth:c,lastPageHeight:u,isLastPageDifferentFromFirstPage:d};if(r)({tilesInFirstPage:h,defaultWidth:s,defaultHeight:l,lastPageWidth:c,lastPageHeight:u,isLastPageDifferentFromFirstPage:d}=(({parentWidth:e,parentHeight:t,count:i,maxCount:r,aspectRatio:o})=>{let a=0,n=0,s=0,l=0,c=!1,u=0,d=0;const{width:h,height:g}=q(e,t,Math.min(i,r),o.width,o.height);if(a=h,n=g,u=Math.min(i,r),d=i%r,c=d>0&&i>r,c){const{width:i,height:r}=q(e,t,d,o.width,o.height);s=i,l=r}return{tilesInFirstPage:u,defaultWidth:a,defaultHeight:n,lastPageWidth:s,lastPageHeight:l,isLastPageDifferentFromFirstPage:c}})({parentWidth:t,parentHeight:i,count:e,maxCount:r,aspectRatio:n}));else if(o)({tilesInFirstPage:h,defaultWidth:s,defaultHeight:l,lastPageWidth:c,lastPageHeight:u,isLastPageDifferentFromFirstPage:d}=(({parentWidth:e,parentHeight:t,count:i,maxCount:r,aspectRatio:o})=>{let a=0,n=0,s=0,l=0,c=!1,u=0,d=0;const h=Math.min(Math.ceil(Math.sqrt(i*(o.width/o.height)/(e/t))),r),g=t/h,p=g*(o.width/o.height),f=Math.floor(e/p);if(a=p,n=g,u=Math.min(i,h*f),d=i%(h*f),c=d>0&&i>h*f,c){const i=t/Math.min(Math.ceil(Math.sqrt(d*(o.width/o.height)/(e/t))),r);l=i,s=i*(o.width/o.height)}return{tilesInFirstPage:u,defaultWidth:a,defaultHeight:n,lastPageWidth:s,lastPageHeight:l,isLastPageDifferentFromFirstPage:c}})({parentWidth:t,parentHeight:i,count:e,maxCount:o,aspectRatio:n}));else if(a)({tilesInFirstPage:h,defaultWidth:s,defaultHeight:l,lastPageWidth:c,lastPageHeight:u,isLastPageDifferentFromFirstPage:d}=(({parentWidth:e,parentHeight:t,count:i,maxCount:r,aspectRatio:o})=>{let a=0,n=0,s=0,l=0,c=!1,u=0,d=0;const h=Math.min(Math.ceil(Math.sqrt(i*(e/t)/(o.width/o.height))),r);let g=e/h,p=g/(o.width/o.height);p>t&&(p=t,g=p/(o.height/o.width));const f=Math.floor(t/p);if(n=p,a=g,u=Math.min(i,f*h),d=i%(f*h),c=d>0&&i>f*h,c){let i=e/Math.min(Math.ceil(Math.sqrt(d*(e/t)/(o.width/o.height))),r),a=i/(o.width/o.height);a>t&&(a=t,i=a/(o.height/o.width)),l=a,s=i}return{tilesInFirstPage:u,defaultWidth:a,defaultHeight:n,lastPageWidth:s,lastPageHeight:l,isLastPageDifferentFromFirstPage:c}})({parentWidth:t,parentHeight:i,count:e,maxCount:a,aspectRatio:n}));else{const{width:r,height:o}=q(t,i,e,n.width,n.height);s=r,l=o,h=e}return{tilesInFirstPage:h,defaultWidth:s,defaultHeight:l,lastPageWidth:c,lastPageHeight:u,isLastPageDifferentFromFirstPage:d}}const J={width:1,height:1};var z;exports.DeviceType=void 0,(z=exports.DeviceType||(exports.DeviceType={})).videoInput="videoInput",z.audioInput="audioInput",z.audioOutput="audioOutput";exports.HMSRoomProvider=({children:i,actions:r,store:o,notifications:a,stats:n,isHMSStatsOn:s=!1,leaveOnUnload:u=!0})=>{if(!I){const e=()=>{throw new Error("modifying store is not allowed")};if(r&&o)I={actions:r,store:c.default(S(P({},o),{setState:e,destroy:e}))},a&&(I.notifications=a),n&&(I.statsStore=c.default({getState:n.getState,subscribe:n.subscribe,setState:e,destroy:e}));else{const i=new t.HMSReactiveStore;if(I={actions:i.getActions(),store:c.default(S(P({},i.getStore()),{setState:e,destroy:e})),notifications:i.getNotifications()},s){const t=i.getStats();I.statsStore=c.default({getState:t.getState,subscribe:t.subscribe,setState:e,destroy:e})}}I.actions.setFrameworkInfo({type:"react-web",version:l.default.version,sdkVersion:"0.4.3"})}return e.useEffect((()=>{g&&u&&(window.addEventListener("beforeunload",(()=>I.actions.leave())),window.addEventListener("onunload",(()=>I.actions.leave())))}),[u]),l.default.createElement(k.Provider,{value:I},i)},exports.throwErrorHandler=e=>{throw e},exports.useAVToggle=(i=T)=>{const r=x(t.selectIsLocalAudioEnabled),o=x(t.selectIsLocalVideoEnabled),a=x(t.selectIsAllowedToPublish),n=R(),s=e.useCallback((async()=>{try{await n.setLocalAudioEnabled(!r)}catch(e){i(e,"toggleAudio")}}),[n,r,i]),l=e.useCallback((async()=>{try{await n.setLocalVideoEnabled(!o)}catch(e){i(e,"toggleVideo")}}),[n,o,i]);return{isLocalAudioEnabled:r,isLocalVideoEnabled:o,toggleAudio:(null==a?void 0:a.audio)?s:void 0,toggleVideo:(null==a?void 0:a.video)?l:void 0}},exports.useAudioLevelStyles=function({trackId:i,getStyle:r,ref:o}){const a=M();e.useEffect((()=>a.subscribe((e=>{if(!o.current)return;const t=r(e);for(const e in t)o.current.style[e]=t[e]}),t.selectTrackAudioByID(i))),[r,o,a,i])},exports.useAutoplayError=()=>{const i=C(t.HMSNotificationTypes.ERROR),[r,o]=e.useState(""),a=R(),n=e.useCallback((async()=>{await a.unblockAudio()}),[a]);return e.useEffect((()=>{3008===(null==i?void 0:i.data.code)&&o(null==i?void 0:i.data.message)}),[i]),{error:r,unblockAudio:n,resetError:()=>o("")}},exports.useCustomEvent=({type:i,json:r=!0,onEvent:o,handleError:a=T})=>{const n=R(),s=H();e.useEffect((()=>{n.ignoreMessageTypes([i])}),[n,i]),e.useEffect((()=>{if(!s)return;return s.onNotification((e=>{const t=e.data;if(t&&t.type===i)try{const e=r?JSON.parse(t.message):t.message;null==o||o(e)}catch(e){a(e,"handleCustomEvent")}}),t.HMSNotificationTypes.NEW_MESSAGE)}),[s,i,r,o,a]);return{sendEvent:e.useCallback((async(e,t)=>{try{const a=((e,t)=>t?JSON.stringify(e||""):e)(e,r);t&&Array.isArray(null==t?void 0:t.roleNames)?await n.sendGroupMessage(a,t.roleNames,i):"string"==typeof(null==t?void 0:t.peerId)?await n.sendDirectMessage(a,t.peerId,i):await n.sendBroadcastMessage(a,i),null==o||o(e)}catch(e){a(e,"sendCustomEvent")}}),[n,a,o,i,r])}},exports.useDevices=(i=T)=>{const r=R(),o=x(t.selectDevices),a=x(t.selectLocalMediaSettings),n=x(t.selectIsAllowedToPublish),s={[exports.DeviceType.audioOutput]:a.audioOutputDeviceId},l={[exports.DeviceType.audioOutput]:o.audioOutput};n.video&&(l[exports.DeviceType.videoInput]=o.videoInput,s[exports.DeviceType.videoInput]=a.videoInputDeviceId),n.audio&&(l[exports.DeviceType.audioInput]=o.audioInput,s[exports.DeviceType.audioInput]=a.audioInputDeviceId);return{allDevices:l,selectedDeviceIDs:s,updateDevice:e.useCallback((async({deviceType:e,deviceId:t})=>{try{switch(e){case exports.DeviceType.audioInput:await r.setAudioSettings({deviceId:t});break;case exports.DeviceType.videoInput:await r.setVideoSettings({deviceId:t});break;case exports.DeviceType.audioOutput:await r.setAudioOutputDevice(t)}}catch(e){i(e,"updateDevices")}}),[i,r])}},exports.useHMSActions=R,exports.useHMSNotifications=C,exports.useHMSStatsStore=O,exports.useHMSStore=x,exports.useHMSVanillaNotifications=H,exports.useHMSVanillaStore=M,exports.useParticipantList=()=>{const i=x(t.selectIsConnectedToRoom),r=x(i?t.selectPeers:t.selectRemotePeers),o=x(t.selectPeerCount),a=e.useMemo((()=>{return(e=r)&&Array.isArray(e)&&0!==e.length?e.reduce(((e,t)=>t.roleName?(e[t.roleName]||(e[t.roleName]=[]),e[t.roleName].push(t),e):e),{}):{};var e}),[r]);return{roles:Object.keys(a),participantsByRoles:a,peerCount:o,isConnected:i}},exports.useParticipants=e=>{var i;const r=x(t.selectIsConnectedToRoom),o=x(t.selectPeerCount),a=x(t.selectAvailableRoleNames);let n=x(r?t.selectPeers:t.selectRemotePeers);const s=Array.from(new Set(n.map((e=>e.roleName)))),l=M();if((null==(i=null==e?void 0:e.metadata)?void 0:i.isHandRaised)&&(n=n.filter((e=>l.getState(t.selectPeerMetadata(e.id)).isHandRaised))),(null==e?void 0:e.role)&&a.includes(e.role)&&(n=n.filter((t=>t.roleName===e.role))),null==e?void 0:e.search){const t=e.search.toLowerCase();n=n.filter((e=>{var i;return(null==(i=e.roleName)?void 0:i.toLowerCase().includes(t))||e.name.toLowerCase().includes(t)}))}return{participants:n,isConnected:r,peerCount:o,rolesWithParticipants:s}},exports.usePreviewJoin=({name:i="",token:r,metadata:o,handleError:a=T,initEndpoint:n,initialSettings:s,captureNetworkQualityInPreview:l})=>{const c=R(),u=x(t.selectRoomState),d=x(t.selectIsConnectedToRoom)||!1,h=u===t.HMSRoomState.Preview,g=e.useMemo((()=>({userName:i,authToken:r,metaData:o,rememberDeviceSelection:!0,settings:s,initEndpoint:n,captureNetworkQualityInPreview:l})),[i,r,o,n,s,l]),p=e.useCallback((async()=>{if(r&&u===t.HMSRoomState.Disconnected){d&&await c.leave();try{await c.preview(g)}catch(e){a(e,"preview")}}}),[c,a,r,u,g,d]);return{enableJoin:h,join:e.useCallback((async()=>{if(r)try{await c.join(g)}catch(e){a(e,"join")}}),[c,g,a,r]),isConnected:d,preview:p}},exports.useRecordingStreaming=()=>{const e=x(t.selectRecordingState),i=x(t.selectRTMPState),r=x(t.selectHLSState),o=e.server.running,a=e.browser.running,n=e.hls.running,s=o||a||n;return{isServerRecordingOn:o,isBrowserRecordingOn:a,isHLSRecordingOn:n,isStreamingOn:r.running||i.running,isHLSRunning:r.running,isRTMPRunning:i.running,isRecordingOn:s}},exports.useRemoteAVToggle=(i,r,o=T)=>{const a=R(),n=x(t.selectAudioTrackByID(i)),s=x(t.selectVideoTrackByID(r)),l=x(t.selectAudioTrackVolume(null==n?void 0:n.id)),c=x(t.selectPermissions),u=(null==s?void 0:s.enabled)?null==c?void 0:c.mute:null==c?void 0:c.unmute,d=(null==n?void 0:n.enabled)?null==c?void 0:c.mute:null==c?void 0:c.unmute,h=e.useCallback((async()=>{await D(a,n,o)}),[a,n,o]),g=e.useCallback((async()=>{await D(a,s,o)}),[a,o,s]),p=e.useCallback((e=>{n&&a.setVolume(e,n.id)}),[a,n]);return{isAudioEnabled:!!(null==n?void 0:n.enabled),isVideoEnabled:!!(null==s?void 0:s.enabled),volume:l,toggleAudio:n&&d?h:void 0,toggleVideo:"regular"===(null==s?void 0:s.source)&&u?g:void 0,setVolume:n?p:void 0}},exports.useScreenShare=(i=T)=>{var r,o;const a=R(),n=x(t.selectIsLocalScreenShared),s=x(t.selectPeerScreenSharing),l=x(t.selectScreenSharesByPeerId(null==s?void 0:s.id)),c=e.useCallback((async(e=!1)=>{try{await a.setScreenShareEnabled(!n,e)}catch(e){i(e,"toggleScreenShare")}}),[a,n,i]);return{amIScreenSharing:n,screenSharingPeerId:null==s?void 0:s.id,screenSharingPeerName:null==s?void 0:s.name,screenShareVideoTrackId:null==(r=null==l?void 0:l.video)?void 0:r.id,screenShareAudioTrackId:null==(o=null==l?void 0:l.audio)?void 0:o.id,toggleScreenShare:c}},exports.useVideo=({trackId:i,attach:o,threshold:a=.5})=>{const n=R(),s=e.useRef(null),l=x(t.selectVideoTrackByID(i)),{ref:c,inView:u}=r.useInView({threshold:a}),h=e.useCallback((e=>{e&&(s.current=e,c(e))}),[c]);return e.useEffect((()=>{(async()=>{s.current&&(null==l?void 0:l.id)&&(u&&l.enabled&&!1!==o?await n.attachVideo(l.id,s.current):await n.detachVideo(l.id,s.current))})()}),[n,u,s,null==l?void 0:l.id,null==l?void 0:l.enabled,null==l?void 0:l.deviceID,null==l?void 0:l.plugins,o]),e.useEffect((()=>()=>{(async()=>{if(s.current&&l)try{await n.detachVideo(l.id,s.current)}catch(e){d.w("detach video error for track",l.id,e)}})()}),[]),{videoRef:h}},exports.useVideoList=({peers:i,maxTileCount:r,maxColCount:a,maxRowCount:n,includeScreenShareForPeer:s=(()=>!1),aspectRatio:l=J,filterNonPublishingPeers:c=!0,offsetY:u=0})=>{const{width:d=0,height:h=0,ref:g}=o.useResizeDetector(),p=((e,t,i,r=!0)=>{if(!e||!t||!i)return[];const o=[];for(const a of e)if(void 0===a.videoTrack&&a.audioTrack&&t[a.audioTrack]?o.push({peer:a}):a.videoTrack&&t[a.videoTrack]?o.push({track:t[a.videoTrack],peer:a}):r||o.push({peer:a}),a.auxiliaryTracks.length>0&&a.auxiliaryTracks.forEach((e=>{const i=t[e];"video"===(null==i?void 0:i.type)&&"regular"===(null==i?void 0:i.source)&&o.push({track:i,peer:a})})),i(a)&&a.auxiliaryTracks.length>0){const e=a.auxiliaryTracks.find((e=>{const i=t[e];return"video"===(null==i?void 0:i.type)&&"screen"===(null==i?void 0:i.source)}));e&&o.push({track:t[e],peer:a})}return o})(i,M().getState(t.selectTracksMap),s,c),f=e.useMemo((()=>{if(l)return l;return{width:function(e){if(0===e.length)return null;const t={};let i=e[0],r=1;for(let o=0;o<e.length;o++){const a=e[o];null===t[a]?t[a]=1:t[a]++,t[a]>r&&(i=a,r=t[a])}return i}(p.filter((e=>{var t,i;return(null==(t=e.track)?void 0:t.width)&&(null==(i=e.track)?void 0:i.height)})).map((e=>{var t,i;return((null==(t=e.track)?void 0:t.width)||1)/((null==(i=e.track)?void 0:i.height)||1)})))||1,height:1}}),[l,p]),v=p.length,{tilesInFirstPage:m,defaultWidth:w,defaultHeight:y,lastPageWidth:b,lastPageHeight:P,isLastPageDifferentFromFirstPage:S}=e.useMemo((()=>G({count:v,parentWidth:Math.floor(d),parentHeight:Math.floor(h)-Math.min(h,u),maxTileCount:r,maxRowCount:n,maxColCount:a,aspectRatio:f})),[v,d,h,r,n,a,f,u]);return{pagesWithTiles:e.useMemo((()=>B({elements:p,tilesInFirstPage:m,onlyOnePage:!1,isLastPageDifferentFromFirstPage:S,defaultWidth:w,defaultHeight:y,lastPageWidth:b,lastPageHeight:P})),[p,m,S,w,y,b,P]),ref:g}},Object.keys(t).forEach((function(e){"default"===e||exports.hasOwnProperty(e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return t[e]}})}));
2
2
  //# sourceMappingURL=index.cjs.js.map