@100mslive/react-sdk 0.10.8-alpha.2 → 0.10.8-alpha.4
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.
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("zustand"),i=require("@100mslive/hms-video-store"),r=require("react-resize-detector");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n,s,a=o(e),l=o(t);function c(e,t){if(Object.is(e,t))return!0;if("object"!=typeof e||null===e||"object"!=typeof t||null===t)return!1;const i=Object.keys(e);if(i.length!==Object.keys(t).length)return!1;for(let 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 u{static v(e,...t){this.log(n.VERBOSE,e,...t)}static d(e,...t){this.log(n.DEBUG,e,...t)}static i(e,...t){this.log(n.INFO,e,...t)}static w(e,...t){this.log(n.WARN,e,...t)}static e(e,...t){this.log(n.ERROR,e,...t)}static log(e,t,...i){if(!(this.level.valueOf()>e.valueOf()))switch(e){case n.VERBOSE:console.log("HMSui-components: ",t,...i);break;case n.DEBUG:console.debug("HMSui-components: ",t,...i);break;case n.INFO:console.info("HMSui-components: ",t,...i);break;case n.WARN:console.warn("HMSui-components: ",t,...i);break;case n.ERROR:console.error("HMSui-components: ",t,...i)}}}u.level=n.VERBOSE;const d="It seems like you forgot to add your component within a top level HMSRoomProvider, please refer to 100ms react docs(https://www.100ms.live/docs/javascript/v2/how-to-guides/install-the-sdk/integration#react-hooks) to check on the required steps for using this hook. If the provider is present\n at the top level, check the yarn.lock/package-lock.json, if there are multiple versions of @100mslive/react-sdk. Please ensure the versions of @100mslive/react-sdk and @100mslive/roomkit-react are the same versions from the release notes(https://www.100ms.live/docs/javascript/v2/changelog/release-notes) that you are trying to update to.";const h="undefined"!=typeof window,f=e.createContext(null),v=(g=f,(t,i=c)=>{t||u.w("fetching full store without passing any selector may have a heavy performance impact on your website.");const r=e.useContext(g);if(!r)throw new Error(d);return(0,r.store)(t,i)});var g;const p=function(t){return(i,r=c)=>{i||u.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(d);const n=o.statsStore;return null==n?void 0:n(i,r)}}(f),m=()=>{const t=e.useContext(f);if(!t)throw new Error(d);return t.store},w=()=>{const t=e.useContext(f);if(!t)throw new Error(d);return t.notifications},y=()=>{const t=e.useContext(f);if(!t)throw new Error(d);return t.actions},S=t=>{const i=e.useContext(f),[r,o]=e.useState(null);if(!i)throw new Error(d);return e.useEffect((()=>{if(!i.notifications)return;return i.notifications.onNotification((e=>{o(e)}),t)}),[i.notifications,t]),r};function b(e,t,i,r){return new(i||(i=Promise))((function(o,n){function s(e){try{l(r.next(e))}catch(e){n(e)}}function a(e){try{l(r.throw(e))}catch(e){n(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(s,a)}l((r=r.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const P=(e,t)=>u.e("react-sdk",t,e);function E(t){const i=e.useRef();return e.useEffect((()=>{i.current=t})),i.current}const k=["blink"].some((e=>{var t,r;return(null===(r=null===(t=i.parsedUserAgent.getEngine())||void 0===t?void 0:t.name)||void 0===r?void 0:r.toLowerCase())===e})),R=(t=P)=>{var r,o;const n=y(),s=v(i.selectIsLocalScreenShared),a=v(i.selectPeerScreenSharing),l=v(i.selectScreenSharesByPeerId(null==a?void 0:a.id)),c=e.useCallback((e=>b(void 0,void 0,void 0,(function*(){try{yield n.setScreenShareEnabled(!s,e)}catch(e){t(e,"toggleScreenShare")}}))),[n,s,t]);return{amIScreenSharing:s,screenSharingPeerId:null==a?void 0:a.id,screenSharingPeerName:null==a?void 0:a.name,screenShareVideoTrackId:null===(r=null==l?void 0:l.video)||void 0===r?void 0:r.id,screenShareAudioTrackId:null===(o=null==l?void 0:l.audio)||void 0===o?void 0:o.id,toggleScreenShare:c}},C=(e,t,i)=>b(void 0,void 0,void 0,(function*(){if(t)try{yield e.setRemoteTrackEnabled(t.id,!t.enabled)}catch(e){i(e,"remoteToggle")}})),I=({elements:e,tilesInFirstPage:t,onlyOnePage:i,isLastPageDifferentFromFirstPage:r,defaultWidth:o,defaultHeight:n,lastPageWidth:s,lastPageHeight:a})=>{const l=((e,t,i)=>e.reduce(((e,r,o)=>{const n=Math.floor(o/t);return n>0&&i||(e[n]||(e[n]=[]),e[n].push(r)),e}),[]))(e,t,i);return l.map(((e,t)=>e.map((e=>{const i=t===l.length-1,c=r&&i?s:o,u=r&&i?a:n;return Object.assign(Object.assign({},e),{height:u,width:c})}))))};const M=(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 n=r&&o&&r/o;if(void 0!==n&&isNaN(n))throw new Error("Aspect ratio must be a number");let s={area:0,cols:0,rows:0,width:0,height:0};if(void 0!==n)for(let r=i;r>0;r+=-1){const o=Math.ceil(i/r);let a,l;e/(r*n)<=t/o?(a=e/r,l=a/n):(l=t/o,a=l*n);const c=a*l;c>s.area&&(s={area:c,width:a,height:l,rows:o,cols:r})}return s};function x({count:e,parentWidth:t,parentHeight:i,maxTileCount:r,maxRowCount:o,maxColCount:n,aspectRatio:s}){let a=0,l=0,c=0,u=0,d=!1,h=0;if(0===e)return{tilesInFirstPage:h,defaultWidth:a,defaultHeight:l,lastPageWidth:c,lastPageHeight:u,isLastPageDifferentFromFirstPage:d};if(r)({tilesInFirstPage:h,defaultWidth:a,defaultHeight:l,lastPageWidth:c,lastPageHeight:u,isLastPageDifferentFromFirstPage:d}=(({parentWidth:e,parentHeight:t,count:i,maxCount:r,aspectRatio:o})=>{let n=0,s=0,a=0,l=0,c=!1,u=0,d=0;const{width:h,height:f}=M(e,t,Math.min(i,r),o.width,o.height);if(n=h,s=f,u=Math.min(i,r),d=i%r,c=d>0&&i>r,c){const{width:i,height:r}=M(e,t,d,o.width,o.height);a=i,l=r}return{tilesInFirstPage:u,defaultWidth:n,defaultHeight:s,lastPageWidth:a,lastPageHeight:l,isLastPageDifferentFromFirstPage:c}})({parentWidth:t,parentHeight:i,count:e,maxCount:r,aspectRatio:s}));else if(o)({tilesInFirstPage:h,defaultWidth:a,defaultHeight:l,lastPageWidth:c,lastPageHeight:u,isLastPageDifferentFromFirstPage:d}=(({parentWidth:e,parentHeight:t,count:i,maxCount:r,aspectRatio:o})=>{let n=0,s=0,a=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),f=t/h,v=f*(o.width/o.height),g=Math.floor(e/v);if(n=v,s=f,u=Math.min(i,h*g),d=i%(h*g),c=d>0&&i>h*g,c){const i=t/Math.min(Math.ceil(Math.sqrt(d*(o.width/o.height)/(e/t))),r);l=i,a=i*(o.width/o.height)}return{tilesInFirstPage:u,defaultWidth:n,defaultHeight:s,lastPageWidth:a,lastPageHeight:l,isLastPageDifferentFromFirstPage:c}})({parentWidth:t,parentHeight:i,count:e,maxCount:o,aspectRatio:s}));else if(n)({tilesInFirstPage:h,defaultWidth:a,defaultHeight:l,lastPageWidth:c,lastPageHeight:u,isLastPageDifferentFromFirstPage:d}=(({parentWidth:e,parentHeight:t,count:i,maxCount:r,aspectRatio:o})=>{let n=0,s=0,a=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 f=e/h,v=f/(o.width/o.height);v>t&&(v=t,f=v/(o.height/o.width));const g=Math.floor(t/v);if(s=v,n=f,u=Math.min(i,g*h),d=i%(g*h),c=d>0&&i>g*h,c){let i=e/Math.min(Math.ceil(Math.sqrt(d*(e/t)/(o.width/o.height))),r),n=i/(o.width/o.height);n>t&&(n=t,i=n/(o.height/o.width)),l=n,a=i}return{tilesInFirstPage:u,defaultWidth:n,defaultHeight:s,lastPageWidth:a,lastPageHeight:l,isLastPageDifferentFromFirstPage:c}})({parentWidth:t,parentHeight:i,count:e,maxCount:n,aspectRatio:s}));else{const{width:r,height:o}=M(t,i,e,s.width,s.height);a=r,l=o,h=e}return{tilesInFirstPage:h,defaultWidth:a,defaultHeight:l,lastPageWidth:c,lastPageHeight:u,isLastPageDifferentFromFirstPage:d}}const N=(e,t,i,r=!0)=>{if(!e||!t||!i)return[];const o=[];for(const n of e){if(void 0===n.videoTrack&&n.audioTrack&&t[n.audioTrack]?o.push({peer:n}):n.videoTrack&&t[n.videoTrack]?o.push({track:t[n.videoTrack],peer:n}):r||o.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)&&o.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&&o.push({track:t[e],peer:n})}}return o},T={width:1,height:1};const O=e=>e.reduce(((e,t)=>(e[t.id]=t,e)),{});exports.HMSRoomProvider=({children:t,actions:r,store:o,notifications:n,stats:s,isHMSStatsOn:c=!1,leaveOnUnload:u=!0})=>{const d=e.useMemo((()=>{let e;const t=()=>{throw new Error("modifying store is not allowed")};if(r&&o)e={actions:r,store:l.default(Object.assign(Object.assign({},o),{setState:t,destroy:t}))},n&&(e.notifications=n),s&&(e.statsStore=l.default({getState:s.getState,subscribe:s.subscribe,setState:t,destroy:t}));else{const r=new i.HMSReactiveStore;if(e={actions:r.getActions(),store:l.default(Object.assign(Object.assign({},r.getStore()),{setState:t,destroy:t})),notifications:r.getNotifications()},c){const i=r.getStats();e.statsStore=l.default({getState:i.getState,subscribe:i.subscribe,setState:t,destroy:t})}}return e.actions.setFrameworkInfo({type:"react-web",version:a.default.version,sdkVersion:"0.10.8-alpha.2"}),e}),[r,o,n,s,c]);return e.useEffect((()=>{if(h&&u){const e=()=>d.actions.leave();return window.addEventListener("unload",e),()=>{window.removeEventListener("unload",e)}}return()=>{}}),[u,d]),a.default.createElement(f.Provider,{value:d},t)},exports.getPeersWithTiles=N,exports.throwErrorHandler=e=>{throw e},exports.useAVToggle=(t=P)=>{const r=v(i.selectIsLocalAudioEnabled),o=v(i.selectIsLocalVideoEnabled),n=v(i.selectIsInPreview)?i.selectIsAllowedToPreviewMedia:i.selectIsAllowedToPublish,s=v(n),a=y(),l=e.useCallback((()=>b(void 0,void 0,void 0,(function*(){try{yield a.setLocalAudioEnabled(!r)}catch(e){t(e,"toggleAudio")}}))),[a,r,t]),c=e.useCallback((()=>b(void 0,void 0,void 0,(function*(){try{yield a.setLocalVideoEnabled(!o)}catch(e){t(e,"toggleVideo")}}))),[a,o,t]);return{isLocalAudioEnabled:r,isLocalVideoEnabled:o,toggleAudio:(null==s?void 0:s.audio)?l:void 0,toggleVideo:(null==s?void 0:s.video)?c:void 0}},exports.useAudioLevelStyles=function({trackId:t,getStyle:r,ref:o}){const n=m();e.useEffect((()=>n.subscribe((e=>{if(!o.current)return;const t=r(e);for(const e in t)o.current.style[e]=t[e]}),i.selectTrackAudioByID(t))),[r,o,n,t])},exports.useAutoplayError=()=>{const t=S(i.HMSNotificationTypes.ERROR),[r,o]=e.useState(""),n=y(),s=e.useCallback((()=>b(void 0,void 0,void 0,(function*(){yield n.unblockAudio()}))),[n]);return e.useEffect((()=>{3008===(null==t?void 0:t.data.code)&&o(null==t?void 0:t.data.message)}),[t]),{error:r,unblockAudio:s,resetError:()=>o("")}},exports.useAwayNotifications=()=>({requestPermission:e.useCallback((()=>b(void 0,void 0,void 0,(function*(){Notification&&"granted"!==(null===Notification||void 0===Notification?void 0:Notification.permission)&&(yield Notification.requestPermission())}))),[]),showNotification:e.useCallback(((e,t)=>{if(!Notification||"denied"===(null===Notification||void 0===Notification?void 0:Notification.permission)||"visible"===document.visibilityState&&document.hasFocus())return;const i=new Notification(e,t),r=()=>{"visible"===document.visibilityState&&document.hasFocus()&&(null==i||i.close(),document.removeEventListener("visibilitychange",r))};document.addEventListener("visibilitychange",r)}),[])}),exports.useCustomEvent=({type:t,json:r=!0,onEvent:o,handleError:n=P})=>{const s=y(),a=w();e.useEffect((()=>{s.ignoreMessageTypes([t])}),[s,t]),e.useEffect((()=>{if(!a)return;return a.onNotification((e=>{const i=e.data;if(i&&i.type===t)try{const e=r?JSON.parse(i.message):i.message;null==o||o(e)}catch(e){n(e,"handleCustomEvent")}}),i.HMSNotificationTypes.NEW_MESSAGE)}),[a,t,r,o,n]);return{sendEvent:e.useCallback(((e,i)=>b(void 0,void 0,void 0,(function*(){try{const n=((e,t)=>t?JSON.stringify(e||""):e)(e,r);i&&Array.isArray(null==i?void 0:i.roleNames)?yield s.sendGroupMessage(n,i.roleNames,t):"string"==typeof(null==i?void 0:i.peerId)?yield s.sendDirectMessage(n,i.peerId,t):yield s.sendBroadcastMessage(n,t),null==o||o(e)}catch(e){n(e,"sendCustomEvent")}}))),[s,n,o,t,r])}},exports.useDevices=(t=P)=>{const r=y(),o=v(i.selectDevices),n=v(i.selectLocalMediaSettings),s=v(i.selectIsInPreview)?i.selectIsAllowedToPreviewMedia:i.selectIsAllowedToPublish,a=v(s),l={[i.DeviceType.audioOutput]:n.audioOutputDeviceId},c={[i.DeviceType.audioOutput]:o.audioOutput};a.video&&(c[i.DeviceType.videoInput]=o.videoInput,l[i.DeviceType.videoInput]=n.videoInputDeviceId),a.audio&&(c[i.DeviceType.audioInput]=o.audioInput,l[i.DeviceType.audioInput]=n.audioInputDeviceId);return{allDevices:c,selectedDeviceIDs:l,updateDevice:e.useCallback((({deviceType:e,deviceId:o})=>b(void 0,void 0,void 0,(function*(){try{switch(e){case i.DeviceType.audioInput:yield r.setAudioSettings({deviceId:o});break;case i.DeviceType.videoInput:yield r.setVideoSettings({deviceId:o});break;case i.DeviceType.audioOutput:yield r.setAudioOutputDevice(o)}}catch(e){t(e,"updateDevices")}}))),[t,r])}},exports.useEmbedShare=t=>{const i=e.useRef(null),[r,o]=e.useState(!1),n=e.useCallback((()=>{throw new Error("unable to start screen share")}),[]),s=e.useRef(!1),{amIScreenSharing:a,toggleScreenShare:l}=R(n),c=E(a),u=e.useCallback((()=>b(void 0,void 0,void 0,(function*(){a&&(yield null==l?void 0:l(),i.current=null)}))),[a,l]),d=e.useCallback((e=>b(void 0,void 0,void 0,(function*(){if(!s.current){if(!e)throw new Error("URL not found");if(a)throw new Error("You are already sharing");if(!i.current)throw new Error("Attach a reference `iframeRef` to iframe for sharing");i.current.src=e,s.current=!0,o(!0),yield null==l?void 0:l({forceCurrentTab:k,cropElement:i.current,preferCurrentTab:k})}}))),[a,l]);return e.useEffect((()=>{c&&!a&&(null==t||t(),i.current&&(i.current.src=""),s.current=!1,o(!1))}),[a,c,t]),{startEmbedShare:d,stopEmbedShare:u,iframeRef:i,isEmbedShareInProgress:r}},exports.useHMSActions=y,exports.useHMSNotifications=S,exports.useHMSStatsStore=p,exports.useHMSStore=v,exports.useHMSVanillaNotifications=w,exports.useHMSVanillaStore=m,exports.usePDFShare=t=>{const i=e.useRef(null),[r,o]=e.useState(!1),n=e.useCallback((()=>{throw new Error("unable to start screen share")}),[]),s=e.useRef(!1),{amIScreenSharing:a,toggleScreenShare:l}=R(n),c=E(a),u=e.useCallback((e=>{var t;i.current&&(null===(t=i.current.contentWindow)||void 0===t||t.postMessage({theme:2,file:e},"*"))}),[]),d=e.useCallback((()=>b(void 0,void 0,void 0,(function*(){a&&(yield null==l?void 0:l())}))),[a,l]),h=e.useCallback((e=>b(void 0,void 0,void 0,(function*(){if(s.current)return;if(!e)throw new Error("File or url not found");if(a)throw new Error("You are already sharing");if(!i.current)throw new Error("Attach a reference `iframeRef` to iframe for sharing");i.current.src="https://pdf-annotation.100ms.live/generic/web/viewer.html"+("string"==typeof e?`?file=${e}`:""),i.current.onload=()=>{requestAnimationFrame((()=>{e instanceof File&&u(e)}))},s.current=!0,o(!0);const t=window.self!==window.top;yield null==l?void 0:l({forceCurrentTab:k&&!t,cropElement:i.current,preferCurrentTab:k&&!t})}))),[a,u,l]);return e.useEffect((()=>{c&&!a&&(null==t||t(),i.current&&i.current.removeAttribute("src"),s.current=!1,o(!1))}),[a,c,t]),{startPDFShare:h,stopPDFShare:d,iframeRef:i,isPDFShareInProgress:r}},exports.usePaginatedParticipants=t=>{const i=y(),r=e.useRef(i.getPeerListIterator(t)),[o,n]=e.useState({}),[s,a]=e.useState(0);return{loadPeers:()=>r.current.findPeers().then((e=>{n(O(e)),a(r.current.getTotal())})),loadMorePeers:()=>r.current.next().then((e=>{n((t=>Object.assign(Object.assign({},t),O(e)))),a(r.current.getTotal())})),hasNext:()=>r.current.hasNext(),total:s,peers:Object.values(o)}},exports.useParticipantList=()=>{const t=v(i.selectIsConnectedToRoom),r=v(t?i.selectPeers:i.selectRemotePeers),o=v(i.selectPeerCount),n=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(n),participantsByRoles:n,peerCount:o,isConnected:t}},exports.useParticipants=e=>{var t;const r=v(i.selectIsConnectedToRoom),o=v(i.selectPeerCount),n=v(i.selectAvailableRoleNames);let s=v(r?i.selectPeers:i.selectRemotePeers);const a=Array.from(new Set(s.map((e=>e.roleName)))),l=m();if((null===(t=null==e?void 0:e.metadata)||void 0===t?void 0:t.isHandRaised)&&(s=s.filter((e=>l.getState(i.selectPeerMetadata(e.id)).isHandRaised))),(null==e?void 0:e.role)&&n.includes(e.role)&&(s=s.filter((t=>t.roleName===e.role))),null==e?void 0:e.search){const t=e.search.toLowerCase();s=s.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:s,isConnected:r,peerCount:o,rolesWithParticipants:a}},exports.usePreviewJoin=({name:t="",token:r,metadata:o,handleError:n=P,initEndpoint:s,initialSettings:a,captureNetworkQualityInPreview:l,asRole:c,autoManageVideo:u,autoManageWakeLock:d})=>{const h=y(),f=v(i.selectRoomState),g=v(i.selectIsConnectedToRoom)||!1,p=f===i.HMSRoomState.Preview,m=e.useMemo((()=>({userName:t,authToken:r,metaData:o,rememberDeviceSelection:!0,settings:a,initEndpoint:s,asRole:c,captureNetworkQualityInPreview:l,autoManageVideo:u,autoManageWakeLock:d})),[t,r,o,s,a,l,c,u,d]),w=e.useCallback((()=>b(void 0,void 0,void 0,(function*(){if(r)try{(g||f!==i.HMSRoomState.Disconnected)&&(yield h.leave().catch((()=>{}))),yield h.preview(m)}catch(e){n(e,"preview")}}))),[r,g,f,h,m,n]);return{enableJoin:p,join:e.useCallback((()=>b(void 0,void 0,void 0,(function*(){if(r)try{yield h.join(m)}catch(e){n(e,"join")}}))),[h,m,n,r]),isConnected:g,preview:w}},exports.useRecordingStreaming=()=>{const e=v(i.selectRecordingState),t=v(i.selectRTMPState),r=v(i.selectHLSState),o=e.server.running,n=e.browser.running,s=e.hls.running,a=o||n||s;return{isServerRecordingOn:o,isBrowserRecordingOn:n,isHLSRecordingOn:s,isStreamingOn:r.running||t.running,isHLSRunning:r.running,isRTMPRunning:t.running,isRecordingOn:a}},exports.useRemoteAVToggle=(t,r,o=P)=>{const n=y(),s=v(i.selectAudioTrackByID(t)),a=v(i.selectVideoTrackByID(r)),l=v(i.selectAudioTrackVolume(null==s?void 0:s.id)),c=v(i.selectPermissions),u=(null==a?void 0:a.enabled)?null==c?void 0:c.mute:null==c?void 0:c.unmute,d=(null==s?void 0:s.enabled)?null==c?void 0:c.mute:null==c?void 0:c.unmute,h=e.useCallback((()=>b(void 0,void 0,void 0,(function*(){yield C(n,s,o)}))),[n,s,o]),f=e.useCallback((()=>b(void 0,void 0,void 0,(function*(){yield C(n,a,o)}))),[n,o,a]),g=e.useCallback((e=>{s&&n.setVolume(e,s.id)}),[n,s]);return{isAudioEnabled:!!(null==s?void 0:s.enabled),isVideoEnabled:!!(null==a?void 0:a.enabled),volume:l,toggleAudio:s&&d?h:void 0,toggleVideo:"regular"===(null==a?void 0:a.source)&&u?f:void 0,setVolume:s?g:void 0}},exports.useScreenShare=R,exports.useTranscript=({onTranscript:t,handleError:r=P})=>{const o="hms_transcript",n=w();e.useEffect((()=>{if(!n)return;return n.onNotification((e=>{const i=e.data;if(i&&i.type===o)try{const e=JSON.parse(i.message).results;null==t||t(e)}catch(e){r(e,"handleCaptionEvent")}}),i.HMSNotificationTypes.NEW_MESSAGE)}),[n,o,r,t])},exports.useVideo=({trackId:t,attach:r})=>{const o=y(),n=e.useRef(null),s=v(i.selectVideoTrackByID(t)),a=e.useRef(),l=e.useCallback((e=>{e&&(n.current=e)}),[]);return e.useEffect((()=>{a.current?(null==s?void 0:s.id)&&a.current!==(null==s?void 0:s.id)&&b(void 0,void 0,void 0,(function*(){if(n.current)try{u.d("detaching because different track is passed"),yield o.detachVideo(a.current,n.current)}catch(e){u.w("detach video error for track",a.current,e)}a.current=null==s?void 0:s.id})):a.current=null==s?void 0:s.id}),[null==s?void 0:s.id,o]),e.useEffect((()=>{b(void 0,void 0,void 0,(function*(){(null==s?void 0:s.id)&&n.current&&(!1!==r?yield o.attachVideo(s.id,n.current):yield o.detachVideo(s.id,n.current))}))}),[s,r,o]),e.useEffect((()=>()=>{b(void 0,void 0,void 0,(function*(){if(n.current&&s)try{yield o.detachVideo(s.id,n.current)}catch(e){u.w("detach video error for track",s.id,e)}}))}),[]),{videoRef:l}},exports.useVideoList=({peers:t,maxTileCount:o,maxColCount:n,maxRowCount:s,includeScreenShareForPeer:a=(()=>!1),aspectRatio:l=T,filterNonPublishingPeers:c=!0,offsetY:u=0})=>{const{width:d=0,height:h=0,ref:f}=r.useResizeDetector(),v=m().getState(i.selectTracksMap),g=N(t,v,a,c),p=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 n=e[o];null===t[n]?t[n]=1:t[n]++,t[n]>r&&(i=n,r=t[n])}return i}(g.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,g]),w=g.length,{tilesInFirstPage:y,defaultWidth:S,defaultHeight:b,lastPageWidth:P,lastPageHeight:E,isLastPageDifferentFromFirstPage:k}=e.useMemo((()=>x({count:w,parentWidth:Math.floor(d),parentHeight:Math.floor(h)-Math.min(h,u),maxTileCount:o,maxRowCount:s,maxColCount:n,aspectRatio:p})),[w,d,h,o,s,n,p,u]);return{pagesWithTiles:e.useMemo((()=>I({elements:g,tilesInFirstPage:y,onlyOnePage:!1,isLastPageDifferentFromFirstPage:k,defaultWidth:S,defaultHeight:b,lastPageWidth:P,lastPageHeight:E})),[g,y,k,S,b,P,E]),ref:f}},exports.useWhiteboard=(t=!1)=>{var r,o;const n=v(i.selectIsConnectedToRoom),s=null===(r=v(i.selectLocalPeer))||void 0===r?void 0:r.customerUserId,a=v(i.selectWhiteboard),l=v(i.selectAppData("disableNotifications")),c=!!(null==a?void 0:a.open),u=(null==a?void 0:a.owner)===s,d=y(),[h,f]=e.useState(!1),g=null===(o=v(i.selectPermissions))||void 0===o?void 0:o.whiteboard,p=!!(null==g?void 0:g.includes("admin")),m=e.useRef(null);e.useEffect((()=>{if(!(null==a?void 0:a.url)||!m.current)return;const e=new URL(a.url);(l||t)&&e.searchParams.set("zoom_to_content","true"),m.current.src=e.toString()}),[null==a?void 0:a.url,l,t]),e.useEffect((()=>{n&&f(d.interactivityCenter.whiteboard.isEnabled)}),[n,d]);const w=e.useCallback((()=>b(void 0,void 0,void 0,(function*(){n&&p&&(c?u&&(yield d.interactivityCenter.whiteboard.close()):yield d.interactivityCenter.whiteboard.open())}))),[d,u,p,c,n]);return{open:c,isOwner:u,isAdmin:p,iframeRef:m,toggle:h&&p?w:void 0}},Object.keys(i).forEach((function(e){"default"===e||exports.hasOwnProperty(e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return i[e]}})}));
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("zustand"),i=require("@100mslive/hms-video-store"),r=require("react-resize-detector");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n,s,a=o(e),l=o(t);function c(e,t){if(Object.is(e,t))return!0;if("object"!=typeof e||null===e||"object"!=typeof t||null===t)return!1;const i=Object.keys(e);if(i.length!==Object.keys(t).length)return!1;for(let 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 u{static v(e,...t){this.log(n.VERBOSE,e,...t)}static d(e,...t){this.log(n.DEBUG,e,...t)}static i(e,...t){this.log(n.INFO,e,...t)}static w(e,...t){this.log(n.WARN,e,...t)}static e(e,...t){this.log(n.ERROR,e,...t)}static log(e,t,...i){if(!(this.level.valueOf()>e.valueOf()))switch(e){case n.VERBOSE:console.log("HMSui-components: ",t,...i);break;case n.DEBUG:console.debug("HMSui-components: ",t,...i);break;case n.INFO:console.info("HMSui-components: ",t,...i);break;case n.WARN:console.warn("HMSui-components: ",t,...i);break;case n.ERROR:console.error("HMSui-components: ",t,...i)}}}u.level=n.VERBOSE;const d="It seems like you forgot to add your component within a top level HMSRoomProvider, please refer to 100ms react docs(https://www.100ms.live/docs/javascript/v2/how-to-guides/install-the-sdk/integration#react-hooks) to check on the required steps for using this hook. If the provider is present\n at the top level, check the yarn.lock/package-lock.json, if there are multiple versions of @100mslive/react-sdk. Please ensure the versions of @100mslive/react-sdk and @100mslive/roomkit-react are the same versions from the release notes(https://www.100ms.live/docs/javascript/v2/changelog/release-notes) that you are trying to update to.";const h="undefined"!=typeof window,f=e.createContext(null),v=(g=f,(t,i=c)=>{t||u.w("fetching full store without passing any selector may have a heavy performance impact on your website.");const r=e.useContext(g);if(!r)throw new Error(d);return(0,r.store)(t,i)});var g;const p=function(t){return(i,r=c)=>{i||u.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(d);const n=o.statsStore;return null==n?void 0:n(i,r)}}(f),m=()=>{const t=e.useContext(f);if(!t)throw new Error(d);return t.store},w=()=>{const t=e.useContext(f);if(!t)throw new Error(d);return t.notifications},y=()=>{const t=e.useContext(f);if(!t)throw new Error(d);return t.actions},S=t=>{const i=e.useContext(f),[r,o]=e.useState(null);if(!i)throw new Error(d);return e.useEffect((()=>{if(!i.notifications)return;return i.notifications.onNotification((e=>{o(e)}),t)}),[i.notifications,t]),r};function b(e,t,i,r){return new(i||(i=Promise))((function(o,n){function s(e){try{l(r.next(e))}catch(e){n(e)}}function a(e){try{l(r.throw(e))}catch(e){n(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(s,a)}l((r=r.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const P=(e,t)=>u.e("react-sdk",t,e);function E(t){const i=e.useRef();return e.useEffect((()=>{i.current=t})),i.current}const k=["blink"].some((e=>{var t,r;return(null===(r=null===(t=i.parsedUserAgent.getEngine())||void 0===t?void 0:t.name)||void 0===r?void 0:r.toLowerCase())===e})),R=(t=P)=>{var r,o;const n=y(),s=v(i.selectIsLocalScreenShared),a=v(i.selectPeerScreenSharing),l=v(i.selectScreenSharesByPeerId(null==a?void 0:a.id)),c=e.useCallback((e=>b(void 0,void 0,void 0,(function*(){try{yield n.setScreenShareEnabled(!s,e)}catch(e){t(e,"toggleScreenShare")}}))),[n,s,t]);return{amIScreenSharing:s,screenSharingPeerId:null==a?void 0:a.id,screenSharingPeerName:null==a?void 0:a.name,screenShareVideoTrackId:null===(r=null==l?void 0:l.video)||void 0===r?void 0:r.id,screenShareAudioTrackId:null===(o=null==l?void 0:l.audio)||void 0===o?void 0:o.id,toggleScreenShare:c}},C=(e,t,i)=>b(void 0,void 0,void 0,(function*(){if(t)try{yield e.setRemoteTrackEnabled(t.id,!t.enabled)}catch(e){i(e,"remoteToggle")}})),I=({elements:e,tilesInFirstPage:t,onlyOnePage:i,isLastPageDifferentFromFirstPage:r,defaultWidth:o,defaultHeight:n,lastPageWidth:s,lastPageHeight:a})=>{const l=((e,t,i)=>e.reduce(((e,r,o)=>{const n=Math.floor(o/t);return n>0&&i||(e[n]||(e[n]=[]),e[n].push(r)),e}),[]))(e,t,i);return l.map(((e,t)=>e.map((e=>{const i=t===l.length-1,c=r&&i?s:o,u=r&&i?a:n;return Object.assign(Object.assign({},e),{height:u,width:c})}))))};const M=(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 n=r&&o&&r/o;if(void 0!==n&&isNaN(n))throw new Error("Aspect ratio must be a number");let s={area:0,cols:0,rows:0,width:0,height:0};if(void 0!==n)for(let r=i;r>0;r+=-1){const o=Math.ceil(i/r);let a,l;e/(r*n)<=t/o?(a=e/r,l=a/n):(l=t/o,a=l*n);const c=a*l;c>s.area&&(s={area:c,width:a,height:l,rows:o,cols:r})}return s};function x({count:e,parentWidth:t,parentHeight:i,maxTileCount:r,maxRowCount:o,maxColCount:n,aspectRatio:s}){let a=0,l=0,c=0,u=0,d=!1,h=0;if(0===e)return{tilesInFirstPage:h,defaultWidth:a,defaultHeight:l,lastPageWidth:c,lastPageHeight:u,isLastPageDifferentFromFirstPage:d};if(r)({tilesInFirstPage:h,defaultWidth:a,defaultHeight:l,lastPageWidth:c,lastPageHeight:u,isLastPageDifferentFromFirstPage:d}=(({parentWidth:e,parentHeight:t,count:i,maxCount:r,aspectRatio:o})=>{let n=0,s=0,a=0,l=0,c=!1,u=0,d=0;const{width:h,height:f}=M(e,t,Math.min(i,r),o.width,o.height);if(n=h,s=f,u=Math.min(i,r),d=i%r,c=d>0&&i>r,c){const{width:i,height:r}=M(e,t,d,o.width,o.height);a=i,l=r}return{tilesInFirstPage:u,defaultWidth:n,defaultHeight:s,lastPageWidth:a,lastPageHeight:l,isLastPageDifferentFromFirstPage:c}})({parentWidth:t,parentHeight:i,count:e,maxCount:r,aspectRatio:s}));else if(o)({tilesInFirstPage:h,defaultWidth:a,defaultHeight:l,lastPageWidth:c,lastPageHeight:u,isLastPageDifferentFromFirstPage:d}=(({parentWidth:e,parentHeight:t,count:i,maxCount:r,aspectRatio:o})=>{let n=0,s=0,a=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),f=t/h,v=f*(o.width/o.height),g=Math.floor(e/v);if(n=v,s=f,u=Math.min(i,h*g),d=i%(h*g),c=d>0&&i>h*g,c){const i=t/Math.min(Math.ceil(Math.sqrt(d*(o.width/o.height)/(e/t))),r);l=i,a=i*(o.width/o.height)}return{tilesInFirstPage:u,defaultWidth:n,defaultHeight:s,lastPageWidth:a,lastPageHeight:l,isLastPageDifferentFromFirstPage:c}})({parentWidth:t,parentHeight:i,count:e,maxCount:o,aspectRatio:s}));else if(n)({tilesInFirstPage:h,defaultWidth:a,defaultHeight:l,lastPageWidth:c,lastPageHeight:u,isLastPageDifferentFromFirstPage:d}=(({parentWidth:e,parentHeight:t,count:i,maxCount:r,aspectRatio:o})=>{let n=0,s=0,a=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 f=e/h,v=f/(o.width/o.height);v>t&&(v=t,f=v/(o.height/o.width));const g=Math.floor(t/v);if(s=v,n=f,u=Math.min(i,g*h),d=i%(g*h),c=d>0&&i>g*h,c){let i=e/Math.min(Math.ceil(Math.sqrt(d*(e/t)/(o.width/o.height))),r),n=i/(o.width/o.height);n>t&&(n=t,i=n/(o.height/o.width)),l=n,a=i}return{tilesInFirstPage:u,defaultWidth:n,defaultHeight:s,lastPageWidth:a,lastPageHeight:l,isLastPageDifferentFromFirstPage:c}})({parentWidth:t,parentHeight:i,count:e,maxCount:n,aspectRatio:s}));else{const{width:r,height:o}=M(t,i,e,s.width,s.height);a=r,l=o,h=e}return{tilesInFirstPage:h,defaultWidth:a,defaultHeight:l,lastPageWidth:c,lastPageHeight:u,isLastPageDifferentFromFirstPage:d}}const N=(e,t,i,r=!0)=>{if(!e||!t||!i)return[];const o=[];for(const n of e){if(void 0===n.videoTrack&&n.audioTrack&&t[n.audioTrack]?o.push({peer:n}):n.videoTrack&&t[n.videoTrack]?o.push({track:t[n.videoTrack],peer:n}):r||o.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)&&o.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&&o.push({track:t[e],peer:n})}}return o},T={width:1,height:1};const O=e=>e.reduce(((e,t)=>(e[t.id]=t,e)),{});exports.HMSRoomProvider=({children:t,actions:r,store:o,notifications:n,stats:s,isHMSStatsOn:c=!1,leaveOnUnload:u=!0})=>{const d=e.useMemo((()=>{let e;const t=()=>{throw new Error("modifying store is not allowed")};if(r&&o)e={actions:r,store:l.default(Object.assign(Object.assign({},o),{setState:t,destroy:t}))},n&&(e.notifications=n),s&&(e.statsStore=l.default({getState:s.getState,subscribe:s.subscribe,setState:t,destroy:t}));else{const r=new i.HMSReactiveStore;if(e={actions:r.getActions(),store:l.default(Object.assign(Object.assign({},r.getStore()),{setState:t,destroy:t})),notifications:r.getNotifications()},c){const i=r.getStats();e.statsStore=l.default({getState:i.getState,subscribe:i.subscribe,setState:t,destroy:t})}}return e.actions.setFrameworkInfo({type:"react-web",version:a.default.version,sdkVersion:"0.10.8-alpha.4"}),e}),[r,o,n,s,c]);return e.useEffect((()=>{if(h&&u){const e=()=>d.actions.leave();return window.addEventListener("unload",e),()=>{window.removeEventListener("unload",e)}}return()=>{}}),[u,d]),a.default.createElement(f.Provider,{value:d},t)},exports.getPeersWithTiles=N,exports.throwErrorHandler=e=>{throw e},exports.useAVToggle=(t=P)=>{const r=v(i.selectIsLocalAudioEnabled),o=v(i.selectIsLocalVideoEnabled),n=v(i.selectIsInPreview)?i.selectIsAllowedToPreviewMedia:i.selectIsAllowedToPublish,s=v(n),a=y(),l=e.useCallback((()=>b(void 0,void 0,void 0,(function*(){try{yield a.setLocalAudioEnabled(!r)}catch(e){t(e,"toggleAudio")}}))),[a,r,t]),c=e.useCallback((()=>b(void 0,void 0,void 0,(function*(){try{yield a.setLocalVideoEnabled(!o)}catch(e){t(e,"toggleVideo")}}))),[a,o,t]);return{isLocalAudioEnabled:r,isLocalVideoEnabled:o,toggleAudio:(null==s?void 0:s.audio)?l:void 0,toggleVideo:(null==s?void 0:s.video)?c:void 0}},exports.useAudioLevelStyles=function({trackId:t,getStyle:r,ref:o}){const n=m();e.useEffect((()=>n.subscribe((e=>{if(!o.current)return;const t=r(e);for(const e in t)o.current.style[e]=t[e]}),i.selectTrackAudioByID(t))),[r,o,n,t])},exports.useAutoplayError=()=>{const t=S(i.HMSNotificationTypes.ERROR),[r,o]=e.useState(""),n=y(),s=e.useCallback((()=>b(void 0,void 0,void 0,(function*(){yield n.unblockAudio()}))),[n]);return e.useEffect((()=>{3008===(null==t?void 0:t.data.code)&&o(null==t?void 0:t.data.message)}),[t]),{error:r,unblockAudio:s,resetError:()=>o("")}},exports.useAwayNotifications=()=>({requestPermission:e.useCallback((()=>b(void 0,void 0,void 0,(function*(){Notification&&"granted"!==(null===Notification||void 0===Notification?void 0:Notification.permission)&&(yield Notification.requestPermission())}))),[]),showNotification:e.useCallback(((e,t)=>{if(!Notification||"denied"===(null===Notification||void 0===Notification?void 0:Notification.permission)||"visible"===document.visibilityState&&document.hasFocus())return;const i=new Notification(e,t),r=()=>{"visible"===document.visibilityState&&document.hasFocus()&&(null==i||i.close(),document.removeEventListener("visibilitychange",r))};document.addEventListener("visibilitychange",r)}),[])}),exports.useCustomEvent=({type:t,json:r=!0,onEvent:o,handleError:n=P})=>{const s=y(),a=w();e.useEffect((()=>{s.ignoreMessageTypes([t])}),[s,t]),e.useEffect((()=>{if(!a)return;return a.onNotification((e=>{const i=e.data;if(i&&i.type===t)try{const e=r?JSON.parse(i.message):i.message;null==o||o(e)}catch(e){n(e,"handleCustomEvent")}}),i.HMSNotificationTypes.NEW_MESSAGE)}),[a,t,r,o,n]);return{sendEvent:e.useCallback(((e,i)=>b(void 0,void 0,void 0,(function*(){try{const n=((e,t)=>t?JSON.stringify(e||""):e)(e,r);i&&Array.isArray(null==i?void 0:i.roleNames)?yield s.sendGroupMessage(n,i.roleNames,t):"string"==typeof(null==i?void 0:i.peerId)?yield s.sendDirectMessage(n,i.peerId,t):yield s.sendBroadcastMessage(n,t),null==o||o(e)}catch(e){n(e,"sendCustomEvent")}}))),[s,n,o,t,r])}},exports.useDevices=(t=P)=>{const r=y(),o=v(i.selectDevices),n=v(i.selectLocalMediaSettings),s=v(i.selectIsInPreview)?i.selectIsAllowedToPreviewMedia:i.selectIsAllowedToPublish,a=v(s),l={[i.DeviceType.audioOutput]:n.audioOutputDeviceId},c={[i.DeviceType.audioOutput]:o.audioOutput};a.video&&(c[i.DeviceType.videoInput]=o.videoInput,l[i.DeviceType.videoInput]=n.videoInputDeviceId),a.audio&&(c[i.DeviceType.audioInput]=o.audioInput,l[i.DeviceType.audioInput]=n.audioInputDeviceId);return{allDevices:c,selectedDeviceIDs:l,updateDevice:e.useCallback((({deviceType:e,deviceId:o})=>b(void 0,void 0,void 0,(function*(){try{switch(e){case i.DeviceType.audioInput:yield r.setAudioSettings({deviceId:o});break;case i.DeviceType.videoInput:yield r.setVideoSettings({deviceId:o});break;case i.DeviceType.audioOutput:yield r.setAudioOutputDevice(o)}}catch(e){t(e,"updateDevices")}}))),[t,r])}},exports.useEmbedShare=t=>{const i=e.useRef(null),[r,o]=e.useState(!1),n=e.useCallback((()=>{throw new Error("unable to start screen share")}),[]),s=e.useRef(!1),{amIScreenSharing:a,toggleScreenShare:l}=R(n),c=E(a),u=e.useCallback((()=>b(void 0,void 0,void 0,(function*(){a&&(yield null==l?void 0:l(),i.current=null)}))),[a,l]),d=e.useCallback((e=>b(void 0,void 0,void 0,(function*(){if(!s.current){if(!e)throw new Error("URL not found");if(a)throw new Error("You are already sharing");if(!i.current)throw new Error("Attach a reference `iframeRef` to iframe for sharing");i.current.src=e,s.current=!0,o(!0),yield null==l?void 0:l({forceCurrentTab:k,cropElement:i.current,preferCurrentTab:k})}}))),[a,l]);return e.useEffect((()=>{c&&!a&&(null==t||t(),i.current&&(i.current.src=""),s.current=!1,o(!1))}),[a,c,t]),{startEmbedShare:d,stopEmbedShare:u,iframeRef:i,isEmbedShareInProgress:r}},exports.useHMSActions=y,exports.useHMSNotifications=S,exports.useHMSStatsStore=p,exports.useHMSStore=v,exports.useHMSVanillaNotifications=w,exports.useHMSVanillaStore=m,exports.usePDFShare=t=>{const i=e.useRef(null),[r,o]=e.useState(!1),n=e.useCallback((()=>{throw new Error("unable to start screen share")}),[]),s=e.useRef(!1),{amIScreenSharing:a,toggleScreenShare:l}=R(n),c=E(a),u=e.useCallback((e=>{var t;i.current&&(null===(t=i.current.contentWindow)||void 0===t||t.postMessage({theme:2,file:e},"*"))}),[]),d=e.useCallback((()=>b(void 0,void 0,void 0,(function*(){a&&(yield null==l?void 0:l())}))),[a,l]),h=e.useCallback((e=>b(void 0,void 0,void 0,(function*(){if(s.current)return;if(!e)throw new Error("File or url not found");if(a)throw new Error("You are already sharing");if(!i.current)throw new Error("Attach a reference `iframeRef` to iframe for sharing");i.current.src="https://pdf-annotation.100ms.live/generic/web/viewer.html"+("string"==typeof e?`?file=${e}`:""),i.current.onload=()=>{requestAnimationFrame((()=>{e instanceof File&&u(e)}))},s.current=!0,o(!0);const t=window.self!==window.top;yield null==l?void 0:l({forceCurrentTab:k&&!t,cropElement:i.current,preferCurrentTab:k&&!t})}))),[a,u,l]);return e.useEffect((()=>{c&&!a&&(null==t||t(),i.current&&i.current.removeAttribute("src"),s.current=!1,o(!1))}),[a,c,t]),{startPDFShare:h,stopPDFShare:d,iframeRef:i,isPDFShareInProgress:r}},exports.usePaginatedParticipants=t=>{const i=y(),r=e.useRef(i.getPeerListIterator(t)),[o,n]=e.useState({}),[s,a]=e.useState(0);return{loadPeers:()=>r.current.findPeers().then((e=>{n(O(e)),a(r.current.getTotal())})),loadMorePeers:()=>r.current.next().then((e=>{n((t=>Object.assign(Object.assign({},t),O(e)))),a(r.current.getTotal())})),hasNext:()=>r.current.hasNext(),total:s,peers:Object.values(o)}},exports.useParticipantList=()=>{const t=v(i.selectIsConnectedToRoom),r=v(t?i.selectPeers:i.selectRemotePeers),o=v(i.selectPeerCount),n=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(n),participantsByRoles:n,peerCount:o,isConnected:t}},exports.useParticipants=e=>{var t;const r=v(i.selectIsConnectedToRoom),o=v(i.selectPeerCount),n=v(i.selectAvailableRoleNames);let s=v(r?i.selectPeers:i.selectRemotePeers);const a=Array.from(new Set(s.map((e=>e.roleName)))),l=m();if((null===(t=null==e?void 0:e.metadata)||void 0===t?void 0:t.isHandRaised)&&(s=s.filter((e=>l.getState(i.selectPeerMetadata(e.id)).isHandRaised))),(null==e?void 0:e.role)&&n.includes(e.role)&&(s=s.filter((t=>t.roleName===e.role))),null==e?void 0:e.search){const t=e.search.toLowerCase();s=s.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:s,isConnected:r,peerCount:o,rolesWithParticipants:a}},exports.usePreviewJoin=({name:t="",token:r,metadata:o,handleError:n=P,initEndpoint:s,initialSettings:a,captureNetworkQualityInPreview:l,asRole:c,autoManageVideo:u,autoManageWakeLock:d})=>{const h=y(),f=v(i.selectRoomState),g=v(i.selectIsConnectedToRoom)||!1,p=f===i.HMSRoomState.Preview,m=e.useMemo((()=>({userName:t,authToken:r,metaData:o,rememberDeviceSelection:!0,settings:a,initEndpoint:s,asRole:c,captureNetworkQualityInPreview:l,autoManageVideo:u,autoManageWakeLock:d})),[t,r,o,s,a,l,c,u,d]),w=e.useCallback((()=>b(void 0,void 0,void 0,(function*(){if(r)try{(g||f!==i.HMSRoomState.Disconnected)&&(yield h.leave().catch((()=>{}))),yield h.preview(m)}catch(e){n(e,"preview")}}))),[r,g,f,h,m,n]);return{enableJoin:p,join:e.useCallback((()=>b(void 0,void 0,void 0,(function*(){if(r)try{yield h.join(m)}catch(e){n(e,"join")}}))),[h,m,n,r]),isConnected:g,preview:w}},exports.useRecordingStreaming=()=>{const e=v(i.selectRecordingState),t=v(i.selectRTMPState),r=v(i.selectHLSState),o=e.server.running,n=e.browser.running,s=e.hls.running,a=o||n||s;return{isServerRecordingOn:o,isBrowserRecordingOn:n,isHLSRecordingOn:s,isStreamingOn:r.running||t.running,isHLSRunning:r.running,isRTMPRunning:t.running,isRecordingOn:a}},exports.useRemoteAVToggle=(t,r,o=P)=>{const n=y(),s=v(i.selectAudioTrackByID(t)),a=v(i.selectVideoTrackByID(r)),l=v(i.selectAudioTrackVolume(null==s?void 0:s.id)),c=v(i.selectPermissions),u=(null==a?void 0:a.enabled)?null==c?void 0:c.mute:null==c?void 0:c.unmute,d=(null==s?void 0:s.enabled)?null==c?void 0:c.mute:null==c?void 0:c.unmute,h=e.useCallback((()=>b(void 0,void 0,void 0,(function*(){yield C(n,s,o)}))),[n,s,o]),f=e.useCallback((()=>b(void 0,void 0,void 0,(function*(){yield C(n,a,o)}))),[n,o,a]),g=e.useCallback((e=>{s&&n.setVolume(e,s.id)}),[n,s]);return{isAudioEnabled:!!(null==s?void 0:s.enabled),isVideoEnabled:!!(null==a?void 0:a.enabled),volume:l,toggleAudio:s&&d?h:void 0,toggleVideo:"regular"===(null==a?void 0:a.source)&&u?f:void 0,setVolume:s?g:void 0}},exports.useScreenShare=R,exports.useTranscript=({onTranscript:t,handleError:r=P})=>{const o="hms_transcript",n=w();e.useEffect((()=>{if(!n)return;return n.onNotification((e=>{const i=e.data;if(i&&i.type===o)try{const e=JSON.parse(i.message).results;null==t||t(e)}catch(e){r(e,"handleCaptionEvent")}}),i.HMSNotificationTypes.NEW_MESSAGE)}),[n,o,r,t])},exports.useVideo=({trackId:t,attach:r})=>{const o=y(),n=e.useRef(null),s=v(i.selectVideoTrackByID(t)),a=e.useRef(),l=e.useCallback((e=>{e&&(n.current=e)}),[]);return e.useEffect((()=>{a.current?(null==s?void 0:s.id)&&a.current!==(null==s?void 0:s.id)&&b(void 0,void 0,void 0,(function*(){if(n.current)try{u.d("detaching because different track is passed"),yield o.detachVideo(a.current,n.current)}catch(e){u.w("detach video error for track",a.current,e)}a.current=null==s?void 0:s.id})):a.current=null==s?void 0:s.id}),[null==s?void 0:s.id,o]),e.useEffect((()=>{b(void 0,void 0,void 0,(function*(){(null==s?void 0:s.id)&&n.current&&(!1!==r?yield o.attachVideo(s.id,n.current):yield o.detachVideo(s.id,n.current))}))}),[s,r,o]),e.useEffect((()=>()=>{b(void 0,void 0,void 0,(function*(){if(n.current&&s)try{yield o.detachVideo(s.id,n.current)}catch(e){u.w("detach video error for track",s.id,e)}}))}),[]),{videoRef:l}},exports.useVideoList=({peers:t,maxTileCount:o,maxColCount:n,maxRowCount:s,includeScreenShareForPeer:a=(()=>!1),aspectRatio:l=T,filterNonPublishingPeers:c=!0,offsetY:u=0})=>{const{width:d=0,height:h=0,ref:f}=r.useResizeDetector(),v=m().getState(i.selectTracksMap),g=N(t,v,a,c),p=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 n=e[o];null===t[n]?t[n]=1:t[n]++,t[n]>r&&(i=n,r=t[n])}return i}(g.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,g]),w=g.length,{tilesInFirstPage:y,defaultWidth:S,defaultHeight:b,lastPageWidth:P,lastPageHeight:E,isLastPageDifferentFromFirstPage:k}=e.useMemo((()=>x({count:w,parentWidth:Math.floor(d),parentHeight:Math.floor(h)-Math.min(h,u),maxTileCount:o,maxRowCount:s,maxColCount:n,aspectRatio:p})),[w,d,h,o,s,n,p,u]);return{pagesWithTiles:e.useMemo((()=>I({elements:g,tilesInFirstPage:y,onlyOnePage:!1,isLastPageDifferentFromFirstPage:k,defaultWidth:S,defaultHeight:b,lastPageWidth:P,lastPageHeight:E})),[g,y,k,S,b,P,E]),ref:f}},exports.useWhiteboard=(t=!1)=>{var r,o;const n=v(i.selectIsConnectedToRoom),s=null===(r=v(i.selectLocalPeer))||void 0===r?void 0:r.customerUserId,a=v(i.selectWhiteboard),l=v(i.selectAppData("disableNotifications")),c=!!(null==a?void 0:a.open),u=(null==a?void 0:a.owner)===s,d=y(),[h,f]=e.useState(!1),g=null===(o=v(i.selectPermissions))||void 0===o?void 0:o.whiteboard,p=!!(null==g?void 0:g.includes("admin")),m=e.useRef(null);e.useEffect((()=>{if(!(null==a?void 0:a.url)||!m.current)return;const e=new URL(a.url);(l||t)&&e.searchParams.set("zoom_to_content","true"),m.current.src=e.toString()}),[null==a?void 0:a.url,l,t]),e.useEffect((()=>{n&&f(d.interactivityCenter.whiteboard.isEnabled)}),[n,d]);const w=e.useCallback((()=>b(void 0,void 0,void 0,(function*(){n&&p&&(c?u&&(yield d.interactivityCenter.whiteboard.close()):yield d.interactivityCenter.whiteboard.open())}))),[d,u,p,c,n]);return{open:c,isOwner:u,isAdmin:p,iframeRef:m,toggle:h&&p?w:void 0}},Object.keys(i).forEach((function(e){"default"===e||exports.hasOwnProperty(e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return i[e]}})}));
|
|
2
2
|
//# sourceMappingURL=index.cjs.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import t,{createContext as e,useMemo as o,useEffect as r,useContext as s,useState as n}from"react";import i from"zustand";import{HMSReactiveStore as a}from"@100mslive/hms-video-store";import{makeHMSStoreHook as c,makeHMSStatsStoreHook as f,hooksErrorMessage as u}from"./store.js";import{isBrowser as l}from"../utils/isBrowser.js";const w=e(null),d=({children:e,actions:s,store:n,notifications:c,stats:f,isHMSStatsOn:u=!1,leaveOnUnload:d=!0})=>{const m=o((()=>{let e;const o=()=>{throw new Error("modifying store is not allowed")};if(s&&n)e={actions:s,store:i(Object.assign(Object.assign({},n),{setState:o,destroy:o}))},c&&(e.notifications=c),f&&(e.statsStore=i({getState:f.getState,subscribe:f.subscribe,setState:o,destroy:o}));else{const t=new a;if(e={actions:t.getActions(),store:i(Object.assign(Object.assign({},t.getStore()),{setState:o,destroy:o})),notifications:t.getNotifications()},u){const r=t.getStats();e.statsStore=i({getState:r.getState,subscribe:r.subscribe,setState:o,destroy:o})}}return e.actions.setFrameworkInfo({type:"react-web",version:t.version,sdkVersion:"0.10.8-alpha.
|
|
1
|
+
import t,{createContext as e,useMemo as o,useEffect as r,useContext as s,useState as n}from"react";import i from"zustand";import{HMSReactiveStore as a}from"@100mslive/hms-video-store";import{makeHMSStoreHook as c,makeHMSStatsStoreHook as f,hooksErrorMessage as u}from"./store.js";import{isBrowser as l}from"../utils/isBrowser.js";const w=e(null),d=({children:e,actions:s,store:n,notifications:c,stats:f,isHMSStatsOn:u=!1,leaveOnUnload:d=!0})=>{const m=o((()=>{let e;const o=()=>{throw new Error("modifying store is not allowed")};if(s&&n)e={actions:s,store:i(Object.assign(Object.assign({},n),{setState:o,destroy:o}))},c&&(e.notifications=c),f&&(e.statsStore=i({getState:f.getState,subscribe:f.subscribe,setState:o,destroy:o}));else{const t=new a;if(e={actions:t.getActions(),store:i(Object.assign(Object.assign({},t.getStore()),{setState:o,destroy:o})),notifications:t.getNotifications()},u){const r=t.getStats();e.statsStore=i({getState:r.getState,subscribe:r.subscribe,setState:o,destroy:o})}}return e.actions.setFrameworkInfo({type:"react-web",version:t.version,sdkVersion:"0.10.8-alpha.4"}),e}),[s,n,c,f,u]);return r((()=>{if(l&&d){const t=()=>m.actions.leave();return window.addEventListener("unload",t),()=>{window.removeEventListener("unload",t)}}return()=>{}}),[d,m]),t.createElement(w.Provider,{value:m},e)},m=c(w),S=f(w),b=()=>{const t=s(w);if(!t)throw new Error(u);return t.store},g=()=>{const t=s(w);if(!t)throw new Error(u);return t.notifications},v=()=>{const t=s(w);if(!t)throw new Error(u);return t.actions},h=t=>{const e=s(w),[o,i]=n(null);if(!e)throw new Error(u);return r((()=>{if(!e.notifications)return;return e.notifications.onNotification((t=>{i(t)}),t)}),[e.notifications,t]),o};export{d as HMSRoomProvider,v as useHMSActions,h as useHMSNotifications,S as useHMSStatsStore,m as useHMSStore,g as useHMSVanillaNotifications,b as useHMSVanillaStore};
|
|
2
2
|
//# sourceMappingURL=HmsRoomProvider.js.map
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"main": "dist/index.cjs.js",
|
|
5
5
|
"module": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
7
|
-
"version": "0.10.8-alpha.
|
|
7
|
+
"version": "0.10.8-alpha.4",
|
|
8
8
|
"author": "100ms",
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"repository": {
|
|
@@ -48,9 +48,9 @@
|
|
|
48
48
|
"react": ">=16.8 <19.0.0"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@100mslive/hms-video-store": "0.12.8-alpha.
|
|
51
|
+
"@100mslive/hms-video-store": "0.12.8-alpha.4",
|
|
52
52
|
"react-resize-detector": "^7.0.0",
|
|
53
53
|
"zustand": "^3.6.2"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "1ac0f11a034d8e0aed06479e20671c86bffd77f8"
|
|
56
56
|
}
|