@100mslive/react-sdk 0.8.7 → 0.8.9

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 (82) hide show
  1. package/dist/hooks/types.d.ts +6 -0
  2. package/dist/hooks/useAVToggle.d.ts +24 -0
  3. package/dist/hooks/useAVToggle.js +2 -0
  4. package/dist/hooks/useAVToggle.js.map +1 -0
  5. package/dist/hooks/useAudioLevelStyles.d.ts +15 -0
  6. package/dist/hooks/useAudioLevelStyles.js +2 -0
  7. package/dist/hooks/useAudioLevelStyles.js.map +1 -0
  8. package/dist/hooks/useAutoplayError.d.ts +17 -0
  9. package/dist/hooks/useAutoplayError.js +2 -0
  10. package/dist/hooks/useAutoplayError.js.map +1 -0
  11. package/dist/hooks/useCustomEvent.d.ts +58 -0
  12. package/dist/hooks/useCustomEvent.js +2 -0
  13. package/dist/hooks/useCustomEvent.js.map +1 -0
  14. package/dist/hooks/useDevices.d.ts +36 -0
  15. package/dist/hooks/useDevices.js +2 -0
  16. package/dist/hooks/useDevices.js.map +1 -0
  17. package/dist/hooks/useEmbedShare.d.ts +28 -0
  18. package/dist/hooks/useEmbedShare.js +2 -0
  19. package/dist/hooks/useEmbedShare.js.map +1 -0
  20. package/dist/hooks/usePDFShare.d.ts +28 -0
  21. package/dist/hooks/usePDFShare.js +2 -0
  22. package/dist/hooks/usePDFShare.js.map +1 -0
  23. package/dist/hooks/useParticipantList.d.ts +13 -0
  24. package/dist/hooks/useParticipantList.js +2 -0
  25. package/dist/hooks/useParticipantList.js.map +1 -0
  26. package/dist/hooks/useParticipants.d.ts +42 -0
  27. package/dist/hooks/useParticipants.js +2 -0
  28. package/dist/hooks/useParticipants.js.map +1 -0
  29. package/dist/hooks/usePreviewJoin.d.ts +70 -0
  30. package/dist/hooks/usePreviewJoin.js +2 -0
  31. package/dist/hooks/usePreviewJoin.js.map +1 -0
  32. package/dist/hooks/useRecordingStreaming.d.ts +10 -0
  33. package/dist/hooks/useRecordingStreaming.js +2 -0
  34. package/dist/hooks/useRecordingStreaming.js.map +1 -0
  35. package/dist/hooks/useRemoteAVToggle.d.ts +36 -0
  36. package/dist/hooks/useRemoteAVToggle.js +2 -0
  37. package/dist/hooks/useRemoteAVToggle.js.map +1 -0
  38. package/dist/hooks/useScreenShare.d.ts +40 -0
  39. package/dist/hooks/useScreenShare.js +2 -0
  40. package/dist/hooks/useScreenShare.js.map +1 -0
  41. package/dist/hooks/useVideo.d.ts +23 -0
  42. package/dist/hooks/useVideo.js +2 -0
  43. package/dist/hooks/useVideo.js.map +1 -0
  44. package/dist/hooks/useVideoList.d.ts +68 -0
  45. package/dist/hooks/useVideoList.js +2 -0
  46. package/dist/hooks/useVideoList.js.map +1 -0
  47. package/dist/index.cjs.js +2 -0
  48. package/dist/index.cjs.js.map +1 -0
  49. package/dist/index.d.ts +33 -0
  50. package/dist/index.js +2 -0
  51. package/dist/index.js.map +1 -0
  52. package/dist/node_modules/tslib/tslib.es6.js +2 -0
  53. package/dist/node_modules/tslib/tslib.es6.js.map +1 -0
  54. package/dist/packages/react-sdk/node_modules/zustand/esm/shallow.js +2 -0
  55. package/dist/packages/react-sdk/node_modules/zustand/esm/shallow.js.map +1 -0
  56. package/dist/primitives/HmsRoomProvider.d.ts +58 -0
  57. package/dist/primitives/HmsRoomProvider.js +2 -0
  58. package/dist/primitives/HmsRoomProvider.js.map +1 -0
  59. package/dist/primitives/store.d.ts +17 -0
  60. package/dist/primitives/store.js +2 -0
  61. package/dist/primitives/store.js.map +1 -0
  62. package/dist/primitives/types.d.ts +5 -0
  63. package/dist/utils/commons.d.ts +10 -0
  64. package/dist/utils/commons.js +2 -0
  65. package/dist/utils/commons.js.map +1 -0
  66. package/dist/utils/groupBy.d.ts +15 -0
  67. package/dist/utils/groupBy.js +2 -0
  68. package/dist/utils/groupBy.js.map +1 -0
  69. package/dist/utils/isBrowser.d.ts +1 -0
  70. package/dist/utils/isBrowser.js +2 -0
  71. package/dist/utils/isBrowser.js.map +1 -0
  72. package/dist/utils/layout.d.ts +116 -0
  73. package/dist/utils/layout.js +2 -0
  74. package/dist/utils/layout.js.map +1 -0
  75. package/dist/utils/logger.d.ts +17 -0
  76. package/dist/utils/logger.js +2 -0
  77. package/dist/utils/logger.js.map +1 -0
  78. package/package.json +3 -3
  79. package/src/hooks/useEmbedShare.ts +96 -0
  80. package/src/hooks/usePDFShare.ts +116 -0
  81. package/src/index.ts +5 -0
  82. package/src/utils/commons.ts +20 -0
@@ -0,0 +1,116 @@
1
+ import { HMSPeer, HMSScreenVideoTrack, HMSTrack, HMSTrackID, HMSVideoTrack } from '@100mslive/hms-video-store';
2
+ export declare const chunk: <T>(elements: T[], chunkSize: number, onlyOnePage: boolean) => T[][];
3
+ interface ChunkElements<T> {
4
+ elements: T[];
5
+ tilesInFirstPage: number;
6
+ onlyOnePage: boolean;
7
+ isLastPageDifferentFromFirstPage: boolean;
8
+ defaultWidth: number;
9
+ defaultHeight: number;
10
+ lastPageWidth: number;
11
+ lastPageHeight: number;
12
+ }
13
+ /**
14
+ * Given a list of tracks/elements and some constraints, group the tracks in separate pages.
15
+ * @return 2D list for every page which has the original element and height and width
16
+ * for its tile.
17
+ */
18
+ export declare const chunkElements: <T>({ elements, tilesInFirstPage, onlyOnePage, isLastPageDifferentFromFirstPage, defaultWidth, defaultHeight, lastPageWidth, lastPageHeight, }: ChunkElements<T>) => (T & {
19
+ width: number;
20
+ height: number;
21
+ })[][];
22
+ /**
23
+ * Mathematical mode - the element with the highest occurrence in an array
24
+ * @param array
25
+ */
26
+ export declare function mode(array: number[]): number | null;
27
+ export declare type TrackWithPeer = {
28
+ track?: HMSVideoTrack | HMSScreenVideoTrack;
29
+ peer: HMSPeer;
30
+ };
31
+ /**
32
+ * get the aspect ration occurring with the highest frequency
33
+ * @param tracks - video tracks to infer aspect ratios from
34
+ */
35
+ export declare const getModeAspectRatio: (tracks: TrackWithPeer[]) => number | null;
36
+ interface GetTileSizesInList {
37
+ count: number;
38
+ parentWidth: number;
39
+ parentHeight: number;
40
+ maxTileCount?: number;
41
+ maxRowCount?: number;
42
+ maxColCount?: number;
43
+ aspectRatio: {
44
+ width: number;
45
+ height: number;
46
+ };
47
+ }
48
+ interface GetTileSizes {
49
+ parentWidth: number;
50
+ parentHeight: number;
51
+ count: number;
52
+ maxCount: number;
53
+ aspectRatio: {
54
+ width: number;
55
+ height: number;
56
+ };
57
+ }
58
+ /**
59
+ * Finds the largest rectangle area when trying to place N rectangle into a containing
60
+ * rectangle without rotation.
61
+ *
62
+ * @param {Number} containerWidth The width of the container.
63
+ * @param {Number} containerHeight The height of the container.
64
+ * @param {Number} numRects How many rectangles must fit within.
65
+ * @param {Number} width The unscaled width of the rectangles to be placed.
66
+ * @param {Number} height The unscaled height of the rectangles to be placed.
67
+ * @return {Object} The area and number of rows and columns that fit.
68
+ */
69
+ export declare const largestRect: (containerWidth: number, containerHeight: number, numRects: number, width: number | undefined, height: number | undefined) => {
70
+ area: number;
71
+ cols: number;
72
+ rows: number;
73
+ width: number;
74
+ height: number;
75
+ };
76
+ export declare const getTileSizesWithColConstraint: ({ parentWidth, parentHeight, count, maxCount, aspectRatio, }: GetTileSizes) => {
77
+ tilesInFirstPage: number;
78
+ defaultWidth: number;
79
+ defaultHeight: number;
80
+ lastPageWidth: number;
81
+ lastPageHeight: number;
82
+ isLastPageDifferentFromFirstPage: boolean;
83
+ };
84
+ export declare const getTileSizesWithPageConstraint: ({ parentWidth, parentHeight, count, maxCount, aspectRatio, }: GetTileSizes) => {
85
+ tilesInFirstPage: number;
86
+ defaultWidth: number;
87
+ defaultHeight: number;
88
+ lastPageWidth: number;
89
+ lastPageHeight: number;
90
+ isLastPageDifferentFromFirstPage: boolean;
91
+ };
92
+ export declare const getTileSizesWithRowConstraint: ({ parentWidth, parentHeight, count, maxCount, aspectRatio, }: GetTileSizes) => {
93
+ tilesInFirstPage: number;
94
+ defaultWidth: number;
95
+ defaultHeight: number;
96
+ lastPageWidth: number;
97
+ lastPageHeight: number;
98
+ isLastPageDifferentFromFirstPage: boolean;
99
+ };
100
+ export declare function calculateLayoutSizes({ count, parentWidth, parentHeight, maxTileCount, maxRowCount, maxColCount, aspectRatio, }: GetTileSizesInList): {
101
+ tilesInFirstPage: number;
102
+ defaultWidth: number;
103
+ defaultHeight: number;
104
+ lastPageWidth: number;
105
+ lastPageHeight: number;
106
+ isLastPageDifferentFromFirstPage: boolean;
107
+ };
108
+ /**
109
+ * given list of peers and all tracks in the room, get a list of tile objects to show in the UI
110
+ * @param peers
111
+ * @param tracks
112
+ * @param includeScreenShareForPeer - fn will be called to check whether to include screenShare for the peer in returned tiles
113
+ * @param filterNonPublishingPeers - by default a peer with no tracks won't be counted towards final tiles
114
+ */
115
+ export declare const getVideoTracksFromPeers: (peers: HMSPeer[], tracks: Record<HMSTrackID, HMSTrack>, includeScreenShareForPeer: (peer: HMSPeer) => boolean, filterNonPublishingPeers?: boolean) => TrackWithPeer[];
116
+ export {};
@@ -0,0 +1,2 @@
1
+ const t=(t,e,i)=>t.reduce(((t,a,r)=>{const h=Math.floor(r/e);return h>0&&i||(t[h]||(t[h]=[]),t[h].push(a)),t}),[]),e=({elements:e,tilesInFirstPage:i,onlyOnePage:a,isLastPageDifferentFromFirstPage:r,defaultWidth:h,defaultHeight:n,lastPageWidth:s,lastPageHeight:o})=>{const l=t(e,i,a);return l.map(((t,e)=>t.map((t=>{const i=e===l.length-1,a=r&&i?s:h,g=r&&i?o:n;return Object.assign(Object.assign({},t),{height:g,width:a})}))))};function i(t){if(0===t.length)return null;const e={};let i=t[0],a=1;for(let r=0;r<t.length;r++){const h=t[r];null===e[h]?e[h]=1:e[h]++,e[h]>a&&(i=h,a=e[h])}return i}const a=t=>i(t.filter((t=>{var e,i;return(null===(e=t.track)||void 0===e?void 0:e.width)&&(null===(i=t.track)||void 0===i?void 0:i.height)})).map((t=>{var e,i;return((null===(e=t.track)||void 0===e?void 0:e.width)||1)/((null===(i=t.track)||void 0===i?void 0:i.height)||1)}))),r=(t,e,i,a,r)=>{if(t<0||e<0)throw new Error("Container must have a non-negative area");if(i<1||!Number.isInteger(i))throw new Error("Number of shapes to place must be a positive integer");const h=a&&r&&a/r;if(void 0!==h&&isNaN(h))throw new Error("Aspect ratio must be a number");let n={area:0,cols:0,rows:0,width:0,height:0};if(void 0!==h)for(let a=i;a>0;a+=-1){const r=Math.ceil(i/a);let s,o;t/(a*h)<=e/r?(s=t/a,o=s/h):(o=e/r,s=o*h);const l=s*o;l>n.area&&(n={area:l,width:s,height:o,rows:r,cols:a})}return n},h=({parentWidth:t,parentHeight:e,count:i,maxCount:a,aspectRatio:r})=>{let h=0,n=0,s=0,o=0,l=!1,g=0,d=0;const u=Math.min(Math.ceil(Math.sqrt(i*(t/e)/(r.width/r.height))),a);let c=t/u,f=c/(r.width/r.height);f>e&&(f=e,c=f/(r.height/r.width));const P=Math.floor(e/f);if(n=f,h=c,g=Math.min(i,P*u),d=i%(P*u),l=d>0&&i>P*u,l){let i=t/Math.min(Math.ceil(Math.sqrt(d*(t/e)/(r.width/r.height))),a),h=i/(r.width/r.height);h>e&&(h=e,i=h/(r.height/r.width)),o=h,s=i}return{tilesInFirstPage:g,defaultWidth:h,defaultHeight:n,lastPageWidth:s,lastPageHeight:o,isLastPageDifferentFromFirstPage:l}},n=({parentWidth:t,parentHeight:e,count:i,maxCount:a,aspectRatio:h})=>{let n=0,s=0,o=0,l=0,g=!1,d=0,u=0;const{width:c,height:f}=r(t,e,Math.min(i,a),h.width,h.height);if(n=c,s=f,d=Math.min(i,a),u=i%a,g=u>0&&i>a,g){const{width:i,height:a}=r(t,e,u,h.width,h.height);o=i,l=a}return{tilesInFirstPage:d,defaultWidth:n,defaultHeight:s,lastPageWidth:o,lastPageHeight:l,isLastPageDifferentFromFirstPage:g}},s=({parentWidth:t,parentHeight:e,count:i,maxCount:a,aspectRatio:r})=>{let h=0,n=0,s=0,o=0,l=!1,g=0,d=0;const u=Math.min(Math.ceil(Math.sqrt(i*(r.width/r.height)/(t/e))),a),c=e/u,f=c*(r.width/r.height),P=Math.floor(t/f);if(h=f,n=c,g=Math.min(i,u*P),d=i%(u*P),l=d>0&&i>u*P,l){const i=e/Math.min(Math.ceil(Math.sqrt(d*(r.width/r.height)/(t/e))),a);o=i,s=i*(r.width/r.height)}return{tilesInFirstPage:g,defaultWidth:h,defaultHeight:n,lastPageWidth:s,lastPageHeight:o,isLastPageDifferentFromFirstPage:l}};function o({count:t,parentWidth:e,parentHeight:i,maxTileCount:a,maxRowCount:o,maxColCount:l,aspectRatio:g}){let d=0,u=0,c=0,f=0,P=!1,p=0;if(0===t)return{tilesInFirstPage:p,defaultWidth:d,defaultHeight:u,lastPageWidth:c,lastPageHeight:f,isLastPageDifferentFromFirstPage:P};if(a)({tilesInFirstPage:p,defaultWidth:d,defaultHeight:u,lastPageWidth:c,lastPageHeight:f,isLastPageDifferentFromFirstPage:P}=n({parentWidth:e,parentHeight:i,count:t,maxCount:a,aspectRatio:g}));else if(o)({tilesInFirstPage:p,defaultWidth:d,defaultHeight:u,lastPageWidth:c,lastPageHeight:f,isLastPageDifferentFromFirstPage:P}=s({parentWidth:e,parentHeight:i,count:t,maxCount:o,aspectRatio:g}));else if(l)({tilesInFirstPage:p,defaultWidth:d,defaultHeight:u,lastPageWidth:c,lastPageHeight:f,isLastPageDifferentFromFirstPage:P}=h({parentWidth:e,parentHeight:i,count:t,maxCount:l,aspectRatio:g}));else{const{width:a,height:h}=r(e,i,t,g.width,g.height);d=a,u=h,p=t}return{tilesInFirstPage:p,defaultWidth:d,defaultHeight:u,lastPageWidth:c,lastPageHeight:f,isLastPageDifferentFromFirstPage:P}}const l=(t,e,i,a=!0)=>{if(!t||!e||!i)return[];const r=[];for(const h of t){if(void 0===h.videoTrack&&h.audioTrack&&e[h.audioTrack]?r.push({peer:h}):h.videoTrack&&e[h.videoTrack]?r.push({track:e[h.videoTrack],peer:h}):a||r.push({peer:h}),h.auxiliaryTracks.length>0&&h.auxiliaryTracks.forEach((t=>{const i=e[t];"video"===(null==i?void 0:i.type)&&"regular"===(null==i?void 0:i.source)&&r.push({track:i,peer:h})})),i(h)&&h.auxiliaryTracks.length>0){const t=h.auxiliaryTracks.find((t=>{const i=e[t];return"video"===(null==i?void 0:i.type)&&"screen"===(null==i?void 0:i.source)}));t&&r.push({track:e[t],peer:h})}}return r};export{o as calculateLayoutSizes,t as chunk,e as chunkElements,a as getModeAspectRatio,h as getTileSizesWithColConstraint,n as getTileSizesWithPageConstraint,s as getTileSizesWithRowConstraint,l as getVideoTracksFromPeers,r as largestRect,i as mode};
2
+ //# sourceMappingURL=layout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layout.js","sources":["../../src/utils/layout.ts"],"sourcesContent":[null],"names":["chunk","elements","chunkSize","onlyOnePage","reduce","resultArray","tile","index","chunkIndex","Math","floor","push","chunkElements","tilesInFirstPage","isLastPageDifferentFromFirstPage","defaultWidth","defaultHeight","lastPageWidth","lastPageHeight","chunks","map","ch","page","element","isLastPage","length","width","height","Object","assign","mode","array","modeMap","maxEl","maxCount","i","el","getModeAspectRatio","tracks","filter","track","_b","_a","largestRect","containerWidth","containerHeight","numRects","Error","Number","isInteger","aspectRatio","isNaN","best","area","cols","rows","ceil","width2","height2","getTileSizesWithColConstraint","parentWidth","parentHeight","count","tilesinLastPage","min","sqrt","getTileSizesWithPageConstraint","initialWidth","initialHeight","remWidth","remHeight","getTileSizesWithRowConstraint","maxTileCount","maxRowCount","maxColCount","getVideoTracksFromPeers","peers","includeScreenShareForPeer","filterNonPublishingPeers","peerTiles","peer","videoTrack","audioTrack","auxiliaryTracks","forEach","trackId","type","source","screenShareTrackID","find","trackID"],"mappings":"AAKa,MAAAA,EAAQ,CAAIC,EAAeC,EAAmBC,IACzDF,EAASG,QAAO,CAACC,EAAoBC,EAASC,KACtC,MAAAC,EAAaC,KAAKC,MAAMH,EAAQL,GAClC,OAAAM,EAAa,GAAKL,IAGjBE,EAAYG,KACfH,EAAYG,GAAc,IAG5BH,EAAYG,GAAYG,KAAKL,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8
+ }
9
+ export default class HMSLogger {
10
+ static level: HMSLogLevel;
11
+ static v(tag: string, ...data: any[]): void;
12
+ static d(tag: string, ...data: any[]): void;
13
+ static i(tag: string, ...data: any[]): void;
14
+ static w(tag: string, ...data: any[]): void;
15
+ static e(tag: string, ...data: any[]): void;
16
+ private static log;
17
+ }
@@ -0,0 +1,2 @@
1
+ var s,e;(e=s||(s={}))[e.VERBOSE=0]="VERBOSE",e[e.DEBUG=1]="DEBUG",e[e.INFO=2]="INFO",e[e.WARN=3]="WARN",e[e.ERROR=4]="ERROR",e[e.NONE=5]="NONE";class o{static v(e,...o){this.log(s.VERBOSE,e,...o)}static d(e,...o){this.log(s.DEBUG,e,...o)}static i(e,...o){this.log(s.INFO,e,...o)}static w(e,...o){this.log(s.WARN,e,...o)}static e(e,...o){this.log(s.ERROR,e,...o)}static log(e,o,...t){if(!(this.level.valueOf()>e.valueOf()))switch(e){case s.VERBOSE:console.log("HMSui-components: ",o,...t);break;case s.DEBUG:console.debug("HMSui-components: ",o,...t);break;case s.INFO:console.info("HMSui-components: ",o,...t);break;case s.WARN:console.warn("HMSui-components: ",o,...t);break;case s.ERROR:console.error("HMSui-components: ",o,...t)}}}o.level=s.VERBOSE;export{s as HMSLogLevel,o as default};
2
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sources":["../../src/utils/logger.ts"],"sourcesContent":[null],"names":["HMSLogLevel","HMSLogLevel2","HMSLogger","static","tag","data","this","log","VERBOSE","DEBUG","INFO","WARN","ERROR","level","valueOf","console","debug","info","warn","error"],"mappings":"AAAY,IAAAA,EAAAC,KAAAD,IAOXA,EAAA,CAAA,IANCC,UAAA,GAAA,UACAA,EAAAA,QAAA,GAAA,QACAA,EAAAA,OAAA,GAAA,OACAA,EAAAA,OAAA,GAAA,OACAA,EAAAA,QAAA,GAAA,QACAA,EAAAA,OAAA,GAAA,OAGF,MAA8BC,EAGrBC,SAAEC,KAAgBC,GACvBC,KAAKC,IAAIP,EAAYQ,QAASJ,KAAQC,EAAA,CAGjCF,SAAEC,KAAgBC,GACvBC,KAAKC,IAAIP,EAAYS,MAAOL,KAAQC,EAAA,CAG/BF,SAAEC,KAAgBC,GACvBC,KAAKC,IAAIP,EAAYU,KAAMN,KAAQC,EAAA,CAG9BF,SAAEC,KAAgBC,GACvBC,KAAKC,IAAIP,EAAYW,KAAMP,KAAQC,EAAA,CAG9BF,SAAEC,KAAgBC,GACvBC,KAAKC,IAAIP,EAAYY,MAAOR,KAAQC,EAAA,CAIvBF,WAAIU,EAAoBT,KAAgBC,GACrD,KAAIC,KAAKO,MAAMC,UAAYD,EAAMC,WAIzB,OAAAD,GAAA,KACDb,EAAYQ,QACPO,QAAAR,IAAI,qBAAsBH,KAAQC,GAC1C,MAAA,KAEGL,EAAYS,MACPM,QAAAC,MAAM,qBAAsBZ,KAAQC,GAC5C,MAAA,KAEGL,EAAYU,KACPK,QAAAE,KAAK,qBAAsBb,KAAQC,GAC3C,MAAA,KAEGL,EAAYW,KACPI,QAAAG,KAAK,qBAAsBd,KAAQC,GAC3C,MAAA,KAEGL,EAAYY,MACPG,QAAAI,MAAM,qBAAsBf,KAAQC,GAC5C,EA/CCH,EAAAW,MAAqBb,EAAYQ"}
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.8.7",
7
+ "version": "0.8.9",
8
8
  "author": "100ms",
9
9
  "license": "MIT",
10
10
  "files": [
@@ -43,9 +43,9 @@
43
43
  "react": ">=16.8 <19.0.0"
44
44
  },
45
45
  "dependencies": {
46
- "@100mslive/hms-video-store": "0.10.7",
46
+ "@100mslive/hms-video-store": "0.10.9",
47
47
  "react-resize-detector": "^7.0.0",
48
48
  "zustand": "^3.6.2"
49
49
  },
50
- "gitHead": "ed377e90d4e54468b0fcd5e3edc12fe3e135c95f"
50
+ "gitHead": "15cb6d59a886be7d2ba20d442e58f724a790d424"
51
51
  }
@@ -0,0 +1,96 @@
1
+ import { useCallback, useEffect, useRef, useState } from 'react';
2
+ import { useScreenShare } from './useScreenShare';
3
+ import usePrevious, { isChromiumBased } from '../utils/commons';
4
+
5
+ export interface useEmbedShareResult {
6
+ /**
7
+ * used to start screen share
8
+ * It throws error in given below scenarios:
9
+ * 1. When url is not passed.
10
+ * 2. Reference to a iframe or element is not at attached.
11
+ * 3. Unable to start screen share
12
+ */
13
+ startEmbedShare: (value: string) => Promise<void>;
14
+
15
+ /**
16
+ * stop your screen share.
17
+ */
18
+ stopEmbedShare: () => Promise<void>;
19
+ /**
20
+ * am I sharing embed view in a room
21
+ */
22
+ isEmbedShareInProgress: boolean;
23
+
24
+ /**
25
+ * reference of iframe where embed url will be launched
26
+ */
27
+ iframeRef: React.RefObject<HTMLIFrameElement | null>;
28
+ }
29
+
30
+ /**
31
+ * @param resetConfig pass resetConfig where you were mounting the iframe, it will help to clear configuration when stop screen share occurs
32
+ * @returns useEmbedShareResult
33
+ */
34
+ export const useEmbedShare = (resetConfig?: () => void): useEmbedShareResult => {
35
+ const iframeRef = useRef<HTMLIFrameElement | null>(null);
36
+ const [sharing, setSharing] = useState(false);
37
+
38
+ const handleScreenShareError = useCallback(() => {
39
+ throw new Error('unable to start screen share');
40
+ }, []);
41
+ const inProgress = useRef(false);
42
+ const { amIScreenSharing, toggleScreenShare } = useScreenShare(handleScreenShareError);
43
+ // store previous state of screensharing, it will help to reset the config after screensharing stop.
44
+ const previouslySharing = usePrevious(amIScreenSharing);
45
+
46
+ const stopShare = useCallback(async () => {
47
+ if (amIScreenSharing) {
48
+ await toggleScreenShare?.(); // Stop screen sharing
49
+ iframeRef.current = null;
50
+ }
51
+ }, [amIScreenSharing, toggleScreenShare]);
52
+
53
+ const startShare = useCallback(
54
+ async (value: string) => {
55
+ if (inProgress.current) {
56
+ return;
57
+ }
58
+ if (!value) {
59
+ throw new Error('URL not found');
60
+ }
61
+ if (amIScreenSharing) {
62
+ throw new Error('You are already sharing');
63
+ }
64
+ if (!iframeRef.current) {
65
+ throw new Error('Attach a reference `iframeRef` to iframe for sharing');
66
+ }
67
+ iframeRef.current.src = value;
68
+ inProgress.current = true;
69
+ setSharing(true);
70
+ await toggleScreenShare?.({
71
+ forceCurrentTab: isChromiumBased,
72
+ cropElement: iframeRef.current,
73
+ preferCurrentTab: isChromiumBased,
74
+ });
75
+ },
76
+ [amIScreenSharing, toggleScreenShare],
77
+ );
78
+
79
+ useEffect(() => {
80
+ if (previouslySharing && !amIScreenSharing) {
81
+ resetConfig?.();
82
+ if (iframeRef.current) {
83
+ iframeRef.current.src = '';
84
+ }
85
+ inProgress.current = false;
86
+ setSharing(false);
87
+ }
88
+ }, [amIScreenSharing, previouslySharing, resetConfig]);
89
+
90
+ return {
91
+ startEmbedShare: startShare,
92
+ stopEmbedShare: stopShare,
93
+ iframeRef,
94
+ isEmbedShareInProgress: sharing,
95
+ };
96
+ };
@@ -0,0 +1,116 @@
1
+ import { useCallback, useEffect, useRef, useState } from 'react';
2
+ import { useScreenShare } from './useScreenShare';
3
+ import usePrevious, { isChromiumBased, pdfIframeURL } from '../utils/commons';
4
+
5
+ export interface usePDFShareResult {
6
+ /**
7
+ * used to start screen share
8
+ * It throws error in given below scenarios:
9
+ * 1. When file or url is not passed.
10
+ * 2. Reference to a iframe or element is not yet attached.
11
+ * 3. Unable to start screen share
12
+ */
13
+ startPDFShare: (value: File | string) => Promise<void>;
14
+
15
+ /**
16
+ * stop your screen share.
17
+ */
18
+ stopPDFShare: () => Promise<void>;
19
+ /**
20
+ * am I sharing pdf annotator in a room
21
+ */
22
+ isPDFShareInProgress: boolean;
23
+
24
+ /**
25
+ * reference of iframe where pdf annotator will be launched
26
+ */
27
+ iframeRef: React.RefObject<HTMLIFrameElement | null>;
28
+ }
29
+
30
+ /**
31
+ * @param resetConfig pass resetConfig where you were mounting the iframe, it will help to clear configuration when stop screen share occurs
32
+ * @returns usePDFShareResult
33
+ */
34
+ export const usePDFShare = (resetConfig?: () => void): usePDFShareResult => {
35
+ const iframeRef = useRef<HTMLIFrameElement | null>(null);
36
+ const [sharing, setSharing] = useState(false);
37
+
38
+ const handleScreenShareError = useCallback(() => {
39
+ throw new Error('unable to start screen share');
40
+ }, []);
41
+ const inProgress = useRef(false);
42
+ const { amIScreenSharing, toggleScreenShare } = useScreenShare(handleScreenShareError);
43
+ // store previous state of screensharing, it will help to reset the config after screensharing stop.
44
+ const previouslySharing = usePrevious(amIScreenSharing);
45
+
46
+ const sendDataToPDFIframe = useCallback((file?: File) => {
47
+ if (iframeRef.current) {
48
+ iframeRef.current.contentWindow?.postMessage(
49
+ {
50
+ theme: 2, // dark theme -> 2, light theme -> 1
51
+ file,
52
+ },
53
+ '*',
54
+ );
55
+ }
56
+ }, []);
57
+
58
+ const stopShare = useCallback(async () => {
59
+ if (amIScreenSharing) {
60
+ await toggleScreenShare?.(); // Stop screen sharing
61
+ }
62
+ }, [amIScreenSharing, toggleScreenShare]);
63
+
64
+ const startShare = useCallback(
65
+ // eslint-disable-next-line complexity
66
+ async (value: File | string) => {
67
+ if (inProgress.current) {
68
+ return;
69
+ }
70
+ if (!value) {
71
+ throw new Error('File or url not found');
72
+ }
73
+ if (amIScreenSharing) {
74
+ throw new Error('You are already sharing');
75
+ }
76
+ if (!iframeRef.current) {
77
+ throw new Error('Attach a reference `iframeRef` to iframe for sharing');
78
+ }
79
+
80
+ iframeRef.current.src = `${pdfIframeURL}${typeof value === 'string' ? `?file=${value}` : ''}`;
81
+ iframeRef.current.onload = () => {
82
+ requestAnimationFrame(() => {
83
+ if (value instanceof File) {
84
+ sendDataToPDFIframe(value);
85
+ }
86
+ });
87
+ };
88
+ inProgress.current = true;
89
+ setSharing(true);
90
+ await toggleScreenShare?.({
91
+ forceCurrentTab: isChromiumBased,
92
+ cropElement: iframeRef.current,
93
+ preferCurrentTab: isChromiumBased,
94
+ });
95
+ },
96
+ [amIScreenSharing, sendDataToPDFIframe, toggleScreenShare],
97
+ );
98
+
99
+ useEffect(() => {
100
+ if (previouslySharing && !amIScreenSharing) {
101
+ resetConfig?.();
102
+ if (iframeRef.current) {
103
+ iframeRef.current.removeAttribute('src');
104
+ }
105
+ inProgress.current = false;
106
+ setSharing(false);
107
+ }
108
+ }, [amIScreenSharing, previouslySharing, resetConfig]);
109
+
110
+ return {
111
+ startPDFShare: startShare,
112
+ stopPDFShare: stopShare,
113
+ iframeRef,
114
+ isPDFShareInProgress: sharing,
115
+ };
116
+ };
package/src/index.ts CHANGED
@@ -20,6 +20,9 @@ export { useRecordingStreaming } from './hooks/useRecordingStreaming';
20
20
  export { useAutoplayError } from './hooks/useAutoplayError';
21
21
  export { useCustomEvent } from './hooks/useCustomEvent';
22
22
  export { useParticipants } from './hooks/useParticipants';
23
+ export { useEmbedShare } from './hooks/useEmbedShare';
24
+ export { usePDFShare } from './hooks/usePDFShare';
25
+
23
26
  // types
24
27
  export type { hooksErrHandler } from './hooks/types';
25
28
  export type { usePreviewInput, usePreviewResult } from './hooks/usePreviewJoin';
@@ -34,6 +37,8 @@ export type { useParticipantsResult, useParticipantsParams } from './hooks/usePa
34
37
  export type { useVideoInput, useVideoOutput } from './hooks/useVideo';
35
38
  export type { useAutoplayErrorResult } from './hooks/useAutoplayError';
36
39
  export type { useCustomEventInput, useCustomEventResult } from './hooks/useCustomEvent';
40
+ export type { useEmbedShareResult } from './hooks/useEmbedShare';
41
+ export type { usePDFShareResult } from './hooks/usePDFShare';
37
42
 
38
43
  // helpers
39
44
  export { throwErrorHandler } from './utils/commons';
@@ -1,3 +1,5 @@
1
+ import { useEffect, useRef } from 'react';
2
+ import { parsedUserAgent } from '@100mslive/hms-video-store';
1
3
  import HMSLogger from './logger';
2
4
  import { hooksErrHandler } from '../hooks/types';
3
5
 
@@ -12,3 +14,21 @@ export const logErrorHandler: hooksErrHandler = (err: Error, method?: string) =>
12
14
  export const throwErrorHandler: hooksErrHandler = (err: Error) => {
13
15
  throw err;
14
16
  };
17
+
18
+ export default function usePrevious<T>(state: T): T | undefined {
19
+ const ref = useRef<T>();
20
+
21
+ useEffect(() => {
22
+ ref.current = state;
23
+ });
24
+
25
+ return ref.current;
26
+ }
27
+
28
+ const chromiumBasedBrowsers = ['chrome', 'brave', 'opera', 'edge'];
29
+
30
+ export const isChromiumBased = chromiumBasedBrowsers.some(
31
+ (value: string) => parsedUserAgent.getBrowser()?.name?.toLowerCase() === value,
32
+ );
33
+
34
+ export const pdfIframeURL = 'https://pdf-annotation.100ms.live/generic/web/viewer.html';