@webex/plugin-meetings 3.0.0-beta.1 → 3.0.0-beta.11

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 (281) hide show
  1. package/dist/common/browser-detection.js.map +1 -1
  2. package/dist/common/collection.js.map +1 -1
  3. package/dist/common/config.js.map +1 -1
  4. package/dist/common/errors/captcha-error.js +7 -0
  5. package/dist/common/errors/captcha-error.js.map +1 -1
  6. package/dist/common/errors/intent-to-join.js +8 -0
  7. package/dist/common/errors/intent-to-join.js.map +1 -1
  8. package/dist/common/errors/join-meeting.js +8 -0
  9. package/dist/common/errors/join-meeting.js.map +1 -1
  10. package/dist/common/errors/media.js +7 -0
  11. package/dist/common/errors/media.js.map +1 -1
  12. package/dist/common/errors/parameter.js.map +1 -1
  13. package/dist/common/errors/password-error.js +7 -0
  14. package/dist/common/errors/password-error.js.map +1 -1
  15. package/dist/common/errors/permission.js +7 -0
  16. package/dist/common/errors/permission.js.map +1 -1
  17. package/dist/common/errors/reconnection-in-progress.js.map +1 -1
  18. package/dist/common/errors/reconnection.js +7 -0
  19. package/dist/common/errors/reconnection.js.map +1 -1
  20. package/dist/common/errors/stats.js +7 -0
  21. package/dist/common/errors/stats.js.map +1 -1
  22. package/dist/common/errors/webex-errors.js +5 -29
  23. package/dist/common/errors/webex-errors.js.map +1 -1
  24. package/dist/common/errors/webex-meetings-error.js +5 -2
  25. package/dist/common/errors/webex-meetings-error.js.map +1 -1
  26. package/dist/common/events/events-scope.js.map +1 -1
  27. package/dist/common/events/events.js.map +1 -1
  28. package/dist/common/events/trigger-proxy.js.map +1 -1
  29. package/dist/common/events/util.js.map +1 -1
  30. package/dist/common/logs/logger-config.js.map +1 -1
  31. package/dist/common/logs/logger-proxy.js.map +1 -1
  32. package/dist/common/logs/request.js +3 -0
  33. package/dist/common/logs/request.js.map +1 -1
  34. package/dist/common/queue.js.map +1 -1
  35. package/dist/config.js +1 -0
  36. package/dist/config.js.map +1 -1
  37. package/dist/constants.js +15 -74
  38. package/dist/constants.js.map +1 -1
  39. package/dist/locus-info/controlsUtils.js.map +1 -1
  40. package/dist/locus-info/embeddedAppsUtils.js.map +1 -1
  41. package/dist/locus-info/fullState.js.map +1 -1
  42. package/dist/locus-info/hostUtils.js.map +1 -1
  43. package/dist/locus-info/index.js +43 -5
  44. package/dist/locus-info/index.js.map +1 -1
  45. package/dist/locus-info/infoUtils.js +4 -0
  46. package/dist/locus-info/infoUtils.js.map +1 -1
  47. package/dist/locus-info/mediaSharesUtils.js.map +1 -1
  48. package/dist/locus-info/parser.js +12 -3
  49. package/dist/locus-info/parser.js.map +1 -1
  50. package/dist/locus-info/selfUtils.js.map +1 -1
  51. package/dist/media/index.js +71 -210
  52. package/dist/media/index.js.map +1 -1
  53. package/dist/media/internal-media-core-wrapper.js +22 -0
  54. package/dist/media/internal-media-core-wrapper.js.map +1 -0
  55. package/dist/media/properties.js +32 -25
  56. package/dist/media/properties.js.map +1 -1
  57. package/dist/media/util.js +0 -27
  58. package/dist/media/util.js.map +1 -1
  59. package/dist/mediaQualityMetrics/config.js.map +1 -1
  60. package/dist/meeting/effectsState.js +8 -1
  61. package/dist/meeting/effectsState.js.map +1 -1
  62. package/dist/meeting/index.js +1146 -602
  63. package/dist/meeting/index.js.map +1 -1
  64. package/dist/meeting/muteState.js +6 -0
  65. package/dist/meeting/muteState.js.map +1 -1
  66. package/dist/meeting/request.js +83 -24
  67. package/dist/meeting/request.js.map +1 -1
  68. package/dist/meeting/state.js.map +1 -1
  69. package/dist/meeting/util.js +5 -44
  70. package/dist/meeting/util.js.map +1 -1
  71. package/dist/meeting-info/collection.js +4 -1
  72. package/dist/meeting-info/collection.js.map +1 -1
  73. package/dist/meeting-info/index.js +5 -0
  74. package/dist/meeting-info/index.js.map +1 -1
  75. package/dist/meeting-info/meeting-info-v2.js +14 -2
  76. package/dist/meeting-info/meeting-info-v2.js.map +1 -1
  77. package/dist/meeting-info/request.js +3 -0
  78. package/dist/meeting-info/request.js.map +1 -1
  79. package/dist/meeting-info/util.js.map +1 -1
  80. package/dist/meeting-info/utilv2.js.map +1 -1
  81. package/dist/meetings/collection.js +4 -1
  82. package/dist/meetings/collection.js.map +1 -1
  83. package/dist/meetings/index.js +136 -25
  84. package/dist/meetings/index.js.map +1 -1
  85. package/dist/meetings/request.js +4 -0
  86. package/dist/meetings/request.js.map +1 -1
  87. package/dist/meetings/util.js +24 -1
  88. package/dist/meetings/util.js.map +1 -1
  89. package/dist/member/index.js +30 -7
  90. package/dist/member/index.js.map +1 -1
  91. package/dist/member/util.js +2 -1
  92. package/dist/member/util.js.map +1 -1
  93. package/dist/members/collection.js +1 -0
  94. package/dist/members/collection.js.map +1 -1
  95. package/dist/members/index.js +82 -1
  96. package/dist/members/index.js.map +1 -1
  97. package/dist/members/request.js +19 -9
  98. package/dist/members/request.js.map +1 -1
  99. package/dist/members/util.js.map +1 -1
  100. package/dist/metrics/config.js.map +1 -1
  101. package/dist/metrics/constants.js.map +1 -1
  102. package/dist/metrics/index.js +8 -0
  103. package/dist/metrics/index.js.map +1 -1
  104. package/dist/multistream/mediaRequestManager.js +133 -0
  105. package/dist/multistream/mediaRequestManager.js.map +1 -0
  106. package/dist/multistream/multistreamMedia.js +116 -0
  107. package/dist/multistream/multistreamMedia.js.map +1 -0
  108. package/dist/multistream/receiveSlot.js +209 -0
  109. package/dist/multistream/receiveSlot.js.map +1 -0
  110. package/dist/multistream/receiveSlotManager.js +195 -0
  111. package/dist/multistream/receiveSlotManager.js.map +1 -0
  112. package/dist/multistream/remoteMedia.js +289 -0
  113. package/dist/multistream/remoteMedia.js.map +1 -0
  114. package/dist/multistream/remoteMediaGroup.js +243 -0
  115. package/dist/multistream/remoteMediaGroup.js.map +1 -0
  116. package/dist/multistream/remoteMediaManager.js +1113 -0
  117. package/dist/multistream/remoteMediaManager.js.map +1 -0
  118. package/dist/networkQualityMonitor/index.js +10 -2
  119. package/dist/networkQualityMonitor/index.js.map +1 -1
  120. package/dist/personal-meeting-room/index.js +11 -0
  121. package/dist/personal-meeting-room/index.js.map +1 -1
  122. package/dist/personal-meeting-room/request.js +2 -1
  123. package/dist/personal-meeting-room/request.js.map +1 -1
  124. package/dist/personal-meeting-room/util.js.map +1 -1
  125. package/dist/reachability/index.js +17 -7
  126. package/dist/reachability/index.js.map +1 -1
  127. package/dist/reachability/request.js +1 -0
  128. package/dist/reachability/request.js.map +1 -1
  129. package/dist/reactions/reactions.js +111 -0
  130. package/dist/reactions/reactions.js.map +1 -0
  131. package/dist/reactions/reactions.type.js +40 -0
  132. package/dist/reactions/reactions.type.js.map +1 -0
  133. package/dist/reconnection-manager/index.js +130 -132
  134. package/dist/reconnection-manager/index.js.map +1 -1
  135. package/dist/roap/index.js +58 -231
  136. package/dist/roap/index.js.map +1 -1
  137. package/dist/roap/request.js +7 -116
  138. package/dist/roap/request.js.map +1 -1
  139. package/dist/roap/turnDiscovery.js +20 -6
  140. package/dist/roap/turnDiscovery.js.map +1 -1
  141. package/dist/statsAnalyzer/global.js +2 -0
  142. package/dist/statsAnalyzer/global.js.map +1 -1
  143. package/dist/statsAnalyzer/index.js +58 -37
  144. package/dist/statsAnalyzer/index.js.map +1 -1
  145. package/dist/statsAnalyzer/mqaUtil.js +9 -3
  146. package/dist/statsAnalyzer/mqaUtil.js.map +1 -1
  147. package/dist/transcription/index.js +10 -3
  148. package/dist/transcription/index.js.map +1 -1
  149. package/package.json +21 -20
  150. package/src/common/{browser-detection.js → browser-detection.ts} +1 -1
  151. package/src/common/collection.ts +6 -6
  152. package/src/common/{config.js → config.ts} +1 -1
  153. package/src/common/errors/{captcha-error.js → captcha-error.ts} +5 -1
  154. package/src/common/errors/{intent-to-join.js → intent-to-join.ts} +6 -1
  155. package/src/common/errors/{join-meeting.js → join-meeting.ts} +6 -1
  156. package/src/common/errors/{media.js → media.ts} +5 -1
  157. package/src/common/errors/parameter.ts +3 -2
  158. package/src/common/errors/{password-error.js → password-error.ts} +5 -1
  159. package/src/common/errors/{permission.js → permission.ts} +5 -1
  160. package/src/common/errors/{reconnection-in-progress.js → reconnection-in-progress.ts} +0 -0
  161. package/src/common/errors/{reconnection.js → reconnection.ts} +5 -1
  162. package/src/common/errors/{stats.js → stats.ts} +5 -1
  163. package/src/common/errors/{webex-errors.js → webex-errors.ts} +1 -20
  164. package/src/common/errors/{webex-meetings-error.js → webex-meetings-error.ts} +3 -1
  165. package/src/common/events/{events-scope.js → events-scope.ts} +1 -1
  166. package/src/common/events/{events.js → events.ts} +0 -0
  167. package/src/common/events/{trigger-proxy.js → trigger-proxy.ts} +1 -2
  168. package/src/common/events/{util.js → util.ts} +1 -1
  169. package/src/common/logs/{logger-config.js → logger-config.ts} +1 -2
  170. package/src/common/logs/{logger-proxy.js → logger-proxy.ts} +1 -1
  171. package/src/common/logs/{request.js → request.ts} +12 -2
  172. package/src/common/queue.ts +1 -2
  173. package/src/{config.js → config.ts} +2 -0
  174. package/src/constants.ts +139 -179
  175. package/src/locus-info/{controlsUtils.js → controlsUtils.ts} +4 -4
  176. package/src/locus-info/{embeddedAppsUtils.js → embeddedAppsUtils.ts} +5 -6
  177. package/src/locus-info/{fullState.js → fullState.ts} +1 -1
  178. package/src/locus-info/{hostUtils.js → hostUtils.ts} +5 -5
  179. package/src/locus-info/{index.js → index.ts} +67 -32
  180. package/src/locus-info/{infoUtils.js → infoUtils.ts} +7 -4
  181. package/src/locus-info/{mediaSharesUtils.js → mediaSharesUtils.ts} +13 -13
  182. package/src/locus-info/{parser.js → parser.ts} +22 -12
  183. package/src/locus-info/{selfUtils.js → selfUtils.ts} +17 -19
  184. package/src/media/{index.js → index.ts} +130 -205
  185. package/src/media/internal-media-core-wrapper.ts +9 -0
  186. package/src/media/{properties.js → properties.ts} +35 -29
  187. package/src/media/util.ts +16 -0
  188. package/src/mediaQualityMetrics/{config.js → config.ts} +1 -1
  189. package/src/meeting/{effectsState.js → effectsState.ts} +12 -6
  190. package/src/meeting/{index.js → index.ts} +993 -474
  191. package/src/meeting/{muteState.js → muteState.ts} +16 -11
  192. package/src/meeting/{request.js → request.ts} +148 -36
  193. package/src/meeting/{state.js → state.ts} +6 -6
  194. package/src/meeting/{util.js → util.ts} +9 -51
  195. package/src/meeting-info/{collection.js → collection.ts} +4 -1
  196. package/src/meeting-info/{index.js → index.ts} +10 -6
  197. package/src/meeting-info/{meeting-info-v2.js → meeting-info-v2.ts} +28 -10
  198. package/src/meeting-info/{request.js → request.ts} +6 -2
  199. package/src/meeting-info/{util.js → util.ts} +6 -5
  200. package/src/meeting-info/{utilv2.js → utilv2.ts} +8 -7
  201. package/src/meetings/{collection.js → collection.ts} +5 -2
  202. package/src/meetings/{index.js → index.ts} +118 -22
  203. package/src/meetings/{request.js → request.ts} +6 -1
  204. package/src/meetings/{util.js → util.ts} +28 -5
  205. package/src/member/{index.js → index.ts} +46 -15
  206. package/src/member/{util.js → util.ts} +17 -16
  207. package/src/members/{collection.js → collection.ts} +2 -1
  208. package/src/members/{index.js → index.ts} +94 -26
  209. package/src/members/{request.js → request.ts} +16 -5
  210. package/src/members/{util.js → util.ts} +7 -7
  211. package/src/metrics/{config.js → config.ts} +0 -2
  212. package/src/metrics/{constants.js → constants.ts} +0 -0
  213. package/src/metrics/{index.js → index.ts} +27 -8
  214. package/src/multistream/mediaRequestManager.ts +166 -0
  215. package/src/multistream/multistreamMedia.ts +92 -0
  216. package/src/multistream/receiveSlot.ts +141 -0
  217. package/src/multistream/receiveSlotManager.ts +142 -0
  218. package/src/multistream/remoteMedia.ts +228 -0
  219. package/src/multistream/remoteMediaGroup.ts +224 -0
  220. package/src/multistream/remoteMediaManager.ts +911 -0
  221. package/src/networkQualityMonitor/{index.js → index.ts} +18 -3
  222. package/src/personal-meeting-room/{index.js → index.ts} +17 -4
  223. package/src/personal-meeting-room/{request.js → request.ts} +3 -1
  224. package/src/personal-meeting-room/{util.js → util.ts} +1 -1
  225. package/src/reachability/{index.js → index.ts} +28 -17
  226. package/src/reachability/request.ts +4 -2
  227. package/src/reactions/reactions.ts +104 -0
  228. package/src/reactions/reactions.type.ts +36 -0
  229. package/src/reconnection-manager/{index.js → index.ts} +81 -65
  230. package/src/roap/index.ts +229 -0
  231. package/src/roap/{request.js → request.ts} +15 -74
  232. package/src/roap/turnDiscovery.ts +26 -11
  233. package/src/statsAnalyzer/{global.js → global.ts} +2 -0
  234. package/src/statsAnalyzer/{index.js → index.ts} +66 -61
  235. package/src/statsAnalyzer/{mqaUtil.js → mqaUtil.ts} +6 -1
  236. package/src/transcription/{index.js → index.ts} +16 -11
  237. package/test/integration/spec/journey.js +1 -1
  238. package/test/integration/spec/space-meeting.js +1 -2
  239. package/test/unit/spec/locus-info/infoUtils.js +17 -1
  240. package/test/unit/spec/media/index.ts +207 -0
  241. package/test/unit/spec/media/properties.ts +73 -82
  242. package/test/unit/spec/meeting/effectsState.js +1 -3
  243. package/test/unit/spec/meeting/index.js +672 -245
  244. package/test/unit/spec/meeting/muteState.js +7 -0
  245. package/test/unit/spec/meeting/request.js +25 -1
  246. package/test/unit/spec/meeting/utils.js +63 -2
  247. package/test/unit/spec/meetings/index.js +0 -4
  248. package/test/unit/spec/members/index.js +164 -2
  249. package/test/unit/spec/multistream/mediaRequestManager.ts +515 -0
  250. package/test/unit/spec/multistream/receiveSlot.ts +104 -0
  251. package/test/unit/spec/multistream/receiveSlotManager.ts +173 -0
  252. package/test/unit/spec/multistream/remoteMedia.ts +225 -0
  253. package/test/unit/spec/multistream/remoteMediaGroup.ts +396 -0
  254. package/test/unit/spec/multistream/remoteMediaManager.ts +1309 -0
  255. package/test/unit/spec/reconnection-manager/index.js +68 -2
  256. package/test/unit/spec/roap/index.ts +63 -35
  257. package/test/unit/spec/stats-analyzer/index.js +19 -22
  258. package/dist/peer-connection-manager/index.js +0 -794
  259. package/dist/peer-connection-manager/index.js.map +0 -1
  260. package/dist/peer-connection-manager/util.js +0 -124
  261. package/dist/peer-connection-manager/util.js.map +0 -1
  262. package/dist/roap/collection.js +0 -73
  263. package/dist/roap/collection.js.map +0 -1
  264. package/dist/roap/handler.js +0 -337
  265. package/dist/roap/handler.js.map +0 -1
  266. package/dist/roap/state.js +0 -164
  267. package/dist/roap/state.js.map +0 -1
  268. package/dist/roap/util.js +0 -102
  269. package/dist/roap/util.js.map +0 -1
  270. package/src/media/util.js +0 -38
  271. package/src/peer-connection-manager/index.js +0 -723
  272. package/src/peer-connection-manager/util.ts +0 -117
  273. package/src/roap/collection.js +0 -63
  274. package/src/roap/handler.js +0 -252
  275. package/src/roap/index.js +0 -380
  276. package/src/roap/state.js +0 -149
  277. package/src/roap/util.js +0 -93
  278. package/test/unit/spec/peerconnection-manager/index.js +0 -188
  279. package/test/unit/spec/peerconnection-manager/utils.js +0 -48
  280. package/test/unit/spec/peerconnection-manager/utils.test-fixtures.ts +0 -389
  281. package/test/unit/spec/roap/util.js +0 -30
@@ -0,0 +1,228 @@
1
+ /* eslint-disable valid-jsdoc */
2
+ import LoggerProxy from '../common/logs/logger-proxy';
3
+ import EventsScope from '../common/events/events-scope';
4
+
5
+ import {MediaRequestId, MediaRequestManager} from './mediaRequestManager';
6
+ import {CSI, ReceiveSlot, ReceiveSlotEvents} from './receiveSlot';
7
+
8
+ export const RemoteMediaEvents = {
9
+ SourceUpdate: ReceiveSlotEvents.SourceUpdate,
10
+ Stopped: 'stopped',
11
+ };
12
+
13
+ export type RemoteVideoResolution =
14
+ | 'thumbnail' // the smallest possible resolution, 90p or less
15
+ | 'very small' // 180p or less
16
+ | 'small' // 360p or less
17
+ | 'medium' // 720p or less
18
+ | 'large' // 1080p or less
19
+ | 'best'; // highest possible resolution
20
+
21
+ /**
22
+ * Converts pane size into h264 maxFs
23
+ * @param {PaneSize} paneSize
24
+ * @returns {number}
25
+ */
26
+ export function getMaxFs(paneSize: RemoteVideoResolution): number {
27
+ let maxFs;
28
+
29
+ switch (paneSize) {
30
+ case 'thumbnail':
31
+ maxFs = 60;
32
+ break;
33
+ case 'very small':
34
+ maxFs = 240;
35
+ break;
36
+ case 'small':
37
+ maxFs = 920;
38
+ break;
39
+ case 'medium':
40
+ maxFs = 3600;
41
+ break;
42
+ case 'large':
43
+ maxFs = 8192;
44
+ break;
45
+ case 'best':
46
+ maxFs = 8192; // for now 'best' is 1080p, so same as 'large'
47
+ break;
48
+ default:
49
+ LoggerProxy.logger.warn(
50
+ `RemoteMedia#getMaxFs --> unsupported paneSize: ${paneSize}, using "medium" instead`
51
+ );
52
+ maxFs = 3600;
53
+ }
54
+
55
+ return maxFs;
56
+ }
57
+
58
+ type Options = {
59
+ resolution?: RemoteVideoResolution; // applies only to groups of type MC.MediaType.VideoMain and MC.MediaType.VideoSlides
60
+ };
61
+
62
+ export type RemoteMediaId = string;
63
+
64
+ let remoteMediaCounter = 0;
65
+
66
+ /**
67
+ * Class representing a remote audio/video stream.
68
+ *
69
+ * Internally it is associated with a specific receive slot
70
+ * and a media request for it.
71
+ */
72
+ export class RemoteMedia extends EventsScope {
73
+ private receiveSlot?: ReceiveSlot;
74
+
75
+ private readonly mediaRequestManager: MediaRequestManager;
76
+
77
+ private readonly options: Options;
78
+
79
+ private mediaRequestId?: MediaRequestId;
80
+
81
+ public readonly id: RemoteMediaId;
82
+
83
+ /**
84
+ * Constructs RemoteMedia instance
85
+ *
86
+ * @param receiveSlot
87
+ * @param mediaRequestManager
88
+ * @param options
89
+ */
90
+ constructor(
91
+ receiveSlot: ReceiveSlot,
92
+ mediaRequestManager: MediaRequestManager,
93
+ options?: Options
94
+ ) {
95
+ super();
96
+ remoteMediaCounter += 1;
97
+ this.receiveSlot = receiveSlot;
98
+ this.mediaRequestManager = mediaRequestManager;
99
+ this.options = options || {};
100
+ this.setupEventListeners();
101
+ this.id = `RM${remoteMediaCounter}-${this.receiveSlot.id}`;
102
+ }
103
+
104
+ /**
105
+ * Invalidates the remote media by clearing the reference to a receive slot and
106
+ * cancelling the media request.
107
+ * After this call the remote media is unusable.
108
+ *
109
+ * @param {boolean} commit - whether to commit the cancellation of the media request
110
+ * @internal
111
+ */
112
+ public stop(commit: boolean = true) {
113
+ this.cancelMediaRequest(commit);
114
+ this.receiveSlot?.removeAllListeners();
115
+ this.receiveSlot = undefined;
116
+ this.emit(
117
+ {
118
+ file: 'multistream/remoteMedia',
119
+ function: 'stop',
120
+ },
121
+ RemoteMediaEvents.Stopped,
122
+ {}
123
+ );
124
+ }
125
+
126
+ /**
127
+ * Sends a new media request. This method can only be used for receiver-selected policy,
128
+ * because only in that policy we have a 1-1 relationship between RemoteMedia and MediaRequest
129
+ * and the request id is then stored in this RemoteMedia instance.
130
+ * For active-speaker policy, the same request is shared among many RemoteMedia instances,
131
+ * so it's managed through RemoteMediaGroup
132
+ *
133
+ * @internal
134
+ */
135
+ public sendMediaRequest(csi: CSI, commit: boolean) {
136
+ if (this.mediaRequestId) {
137
+ this.cancelMediaRequest(false);
138
+ }
139
+
140
+ if (!this.receiveSlot) {
141
+ throw new Error('sendMediaRequest() called on an invalidated RemoteMedia instance');
142
+ }
143
+
144
+ this.mediaRequestId = this.mediaRequestManager.addRequest(
145
+ {
146
+ policyInfo: {
147
+ policy: 'receiver-selected',
148
+ csi,
149
+ },
150
+ receiveSlots: [this.receiveSlot],
151
+ codecInfo: this.options.resolution && {
152
+ codec: 'h264',
153
+ maxFs: getMaxFs(this.options.resolution),
154
+ },
155
+ },
156
+ commit
157
+ );
158
+ }
159
+
160
+ /**
161
+ * @internal
162
+ */
163
+ public cancelMediaRequest(commit: boolean) {
164
+ if (this.mediaRequestId) {
165
+ this.mediaRequestManager.cancelRequest(this.mediaRequestId, commit);
166
+ this.mediaRequestId = undefined;
167
+ }
168
+ }
169
+
170
+ /**
171
+ * registers event listeners on the receive slot and forwards all the events
172
+ */
173
+ private setupEventListeners() {
174
+ if (this.receiveSlot) {
175
+ const scope = {
176
+ file: 'multistream/remoteMedia',
177
+ function: 'setupEventListeners',
178
+ };
179
+
180
+ this.receiveSlot.on(ReceiveSlotEvents.SourceUpdate, (data) => {
181
+ this.emit(scope, RemoteMediaEvents.SourceUpdate, data);
182
+ });
183
+ }
184
+ }
185
+
186
+ /**
187
+ * Getter for mediaType
188
+ */
189
+ public get mediaType() {
190
+ return this.receiveSlot?.mediaType;
191
+ }
192
+
193
+ /**
194
+ * Getter for memberId
195
+ */
196
+ public get memberId() {
197
+ return this.receiveSlot?.memberId;
198
+ }
199
+
200
+ /**
201
+ * Getter for csi
202
+ */
203
+ public get csi() {
204
+ return this.receiveSlot?.csi;
205
+ }
206
+
207
+ /**
208
+ * Getter for source state
209
+ */
210
+ public get sourceState() {
211
+ return this.receiveSlot?.sourceState;
212
+ }
213
+
214
+ /**
215
+ * Getter for remote media stream
216
+ */
217
+ public get stream() {
218
+ return this.receiveSlot?.stream;
219
+ }
220
+
221
+ /**
222
+ * @internal
223
+ * @returns {ReceiveSlot}
224
+ */
225
+ public getUnderlyingReceiveSlot() {
226
+ return this.receiveSlot;
227
+ }
228
+ }
@@ -0,0 +1,224 @@
1
+ /* eslint-disable valid-jsdoc */
2
+ /* eslint-disable require-jsdoc */
3
+ /* eslint-disable import/prefer-default-export */
4
+ import LoggerProxy from '../common/logs/logger-proxy';
5
+
6
+ import {getMaxFs, RemoteMedia, RemoteVideoResolution} from './remoteMedia';
7
+ import {MediaRequestId, MediaRequestManager} from './mediaRequestManager';
8
+ import {CSI, ReceiveSlot} from './receiveSlot';
9
+
10
+ type Options = {
11
+ resolution?: RemoteVideoResolution; // applies only to groups of type MC.MediaType.VideoMain and MC.MediaType.VideoSlides
12
+ preferLiveVideo?: boolean; // applies only to groups of type MC.MediaType.VideoMain and MC.MediaType.VideoSlides
13
+ };
14
+
15
+ export class RemoteMediaGroup {
16
+ private mediaRequestManager: MediaRequestManager;
17
+
18
+ private priority: number;
19
+
20
+ private options: Options;
21
+
22
+ private unpinnedRemoteMedia: RemoteMedia[];
23
+
24
+ private mediaRequestId?: MediaRequestId; // id of the "active-speaker" media request id
25
+
26
+ private pinnedRemoteMedia: RemoteMedia[];
27
+
28
+ constructor(
29
+ mediaRequestManager: MediaRequestManager,
30
+ receiveSlots: ReceiveSlot[],
31
+ priority: number,
32
+ commitMediaRequest: boolean,
33
+ options: Options = {}
34
+ ) {
35
+ this.mediaRequestManager = mediaRequestManager;
36
+ this.priority = priority;
37
+ this.options = options;
38
+
39
+ this.unpinnedRemoteMedia = receiveSlots.map(
40
+ (slot) =>
41
+ new RemoteMedia(slot, this.mediaRequestManager, {
42
+ resolution: this.options.resolution,
43
+ })
44
+ );
45
+ this.pinnedRemoteMedia = [];
46
+
47
+ this.sendActiveSpeakerMediaRequest(commitMediaRequest);
48
+ }
49
+
50
+ /**
51
+ * Gets the array of remote media elements from the group
52
+ *
53
+ * @param {string} filter - 'all' (default) returns both pinned and unpinned
54
+ * @returns {Array<RemoteMedia>}
55
+ */
56
+ public getRemoteMedia(filter: 'all' | 'pinned' | 'unpinned' = 'all') {
57
+ if (filter === 'unpinned') {
58
+ // return a shallow copy so that the client cannot modify this.unpinnedRemoteMedia array
59
+ return [...this.unpinnedRemoteMedia];
60
+ }
61
+ if (filter === 'pinned') {
62
+ // return a shallow copy so that the client cannot modify this.pinnedRemoteMedia array
63
+ return [...this.pinnedRemoteMedia];
64
+ }
65
+ return [...this.unpinnedRemoteMedia, ...this.pinnedRemoteMedia];
66
+ }
67
+
68
+ /**
69
+ * Pins a specific remote media instance to a specfic CSI, so the media will
70
+ * no longer come from active speaker, but from that CSI.
71
+ * If no CSI is given, the current CSI value is used.
72
+ *
73
+ */
74
+ public pin(remoteMedia: RemoteMedia, csi?: CSI): void {
75
+ // if csi is not specified, use the current one
76
+ const targetCsi = csi || remoteMedia.csi;
77
+
78
+ if (!targetCsi) {
79
+ throw new Error(
80
+ `failed to pin a remote media object ${remoteMedia.id}, because it has no CSI set and no CSI value was given`
81
+ );
82
+ }
83
+
84
+ if (this.pinnedRemoteMedia.indexOf(remoteMedia) >= 0) {
85
+ if (targetCsi === remoteMedia.csi) {
86
+ // remote media already pinned to target CSI, nothing to do
87
+ LoggerProxy.logger.log(
88
+ `RemoteMediaGroup#pin --> remote media ${remoteMedia.id} already pinned`
89
+ );
90
+
91
+ return;
92
+ }
93
+ } else {
94
+ const idx = this.unpinnedRemoteMedia.indexOf(remoteMedia);
95
+
96
+ if (idx < 0) {
97
+ throw new Error(
98
+ `failed to pin a remote media object ${remoteMedia.id}, because it is not found in this remote media group`
99
+ );
100
+ }
101
+
102
+ this.unpinnedRemoteMedia.splice(idx, 1);
103
+ this.pinnedRemoteMedia.push(remoteMedia);
104
+
105
+ this.cancelActiveSpeakerMediaRequest(false);
106
+ this.sendActiveSpeakerMediaRequest(false);
107
+ }
108
+
109
+ remoteMedia.sendMediaRequest(targetCsi, false);
110
+ this.mediaRequestManager.commit();
111
+ }
112
+
113
+ /**
114
+ * Unpins a remote media instance, so that it will again provide media from active speakers
115
+ *
116
+ */
117
+ public unpin(remoteMedia: RemoteMedia) {
118
+ if (this.unpinnedRemoteMedia.indexOf(remoteMedia) >= 0) {
119
+ LoggerProxy.logger.log(
120
+ `RemoteMediaGroup#pin --> remote media ${remoteMedia.id} already unpinned`
121
+ );
122
+
123
+ return;
124
+ }
125
+ const idx = this.pinnedRemoteMedia.indexOf(remoteMedia);
126
+
127
+ if (idx < 0) {
128
+ throw new Error(
129
+ `failed to unpin a remote media object ${remoteMedia.id}, because it is not found in this remote media group`
130
+ );
131
+ }
132
+
133
+ this.pinnedRemoteMedia.splice(idx, 1);
134
+ this.unpinnedRemoteMedia.push(remoteMedia);
135
+
136
+ remoteMedia.cancelMediaRequest(false);
137
+ this.cancelActiveSpeakerMediaRequest(false);
138
+ this.sendActiveSpeakerMediaRequest(false);
139
+ this.mediaRequestManager.commit();
140
+ }
141
+
142
+ public isPinned(remoteMedia: RemoteMedia) {
143
+ if (this.unpinnedRemoteMedia.indexOf(remoteMedia) >= 0) {
144
+ return false;
145
+ }
146
+ if (this.pinnedRemoteMedia.indexOf(remoteMedia) >= 0) {
147
+ return true;
148
+ }
149
+
150
+ throw new Error(`remote media object ${remoteMedia.id} not found in the group`);
151
+ }
152
+
153
+ private sendActiveSpeakerMediaRequest(commit: boolean) {
154
+ this.cancelActiveSpeakerMediaRequest(false);
155
+
156
+ this.mediaRequestId = this.mediaRequestManager.addRequest(
157
+ {
158
+ policyInfo: {
159
+ policy: 'active-speaker',
160
+ priority: this.priority,
161
+ crossPriorityDuplication: false,
162
+ crossPolicyDuplication: false,
163
+ preferLiveVideo: !!this.options?.preferLiveVideo,
164
+ },
165
+ receiveSlots: this.unpinnedRemoteMedia.map((remoteMedia) =>
166
+ remoteMedia.getUnderlyingReceiveSlot()
167
+ ) as ReceiveSlot[],
168
+ codecInfo: this.options.resolution && {
169
+ codec: 'h264',
170
+ maxFs: getMaxFs(this.options.resolution),
171
+ },
172
+ },
173
+ commit
174
+ );
175
+ }
176
+
177
+ private cancelActiveSpeakerMediaRequest(commit: boolean) {
178
+ if (this.mediaRequestId) {
179
+ this.mediaRequestManager.cancelRequest(this.mediaRequestId, commit);
180
+ this.mediaRequestId = undefined;
181
+ }
182
+ }
183
+
184
+ /**
185
+ * Invalidates the remote media group by clearing the references to the receive slots
186
+ * used by all remote media from that group and cancelling all media requests.
187
+ * After this call the remote media group is unusable.
188
+ *
189
+ * @param{boolean} commit whether to commit the cancellation of media requests
190
+ * @internal
191
+ */
192
+ public stop(commit: boolean = true) {
193
+ this.unpinnedRemoteMedia.forEach((remoteMedia) => remoteMedia.stop(false));
194
+ this.pinnedRemoteMedia.forEach((remoteMedia) => remoteMedia.stop(false));
195
+ this.cancelActiveSpeakerMediaRequest(false);
196
+
197
+ if (commit) {
198
+ this.mediaRequestManager.commit();
199
+ }
200
+ }
201
+
202
+ /**
203
+ * Checks if a given RemoteMedia instance belongs to this group.
204
+ *
205
+ * @param remoteMedia RemoteMedia instance to check
206
+ * @param filter controls which remote media from the group to check
207
+ * @returns true if remote media is found
208
+ */
209
+ public includes(
210
+ remoteMedia: RemoteMedia,
211
+ filter: 'all' | 'pinned' | 'unpinned' = 'all'
212
+ ): boolean {
213
+ if (filter === 'pinned') {
214
+ return this.pinnedRemoteMedia.includes(remoteMedia);
215
+ }
216
+ if (filter === 'unpinned') {
217
+ return this.unpinnedRemoteMedia.includes(remoteMedia);
218
+ }
219
+
220
+ return (
221
+ this.unpinnedRemoteMedia.includes(remoteMedia) || this.pinnedRemoteMedia.includes(remoteMedia)
222
+ );
223
+ }
224
+ }