-
Notifications
You must be signed in to change notification settings - Fork 395
Expand file tree
/
Copy pathutil.ts
More file actions
1071 lines (895 loc) · 33.5 KB
/
util.ts
File metadata and controls
1071 lines (895 loc) · 33.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import {LocalCameraStream, LocalMicrophoneStream} from '@webex/media-helpers';
import url from 'url';
import {cloneDeep} from 'lodash';
import {MeetingNotActiveError, UserNotJoinedError} from '../common/errors/webex-errors';
import LoggerProxy from '../common/logs/logger-proxy';
import {
INTENT_TO_JOIN,
_LEFT_,
_IDLE_,
_JOINED_,
PASSWORD_STATUS,
DISPLAY_HINTS,
FULL_STATE,
SELF_POLICY,
EVENT_TRIGGERS,
LOCAL_SHARE_ERRORS,
IP_VERSION,
} from '../constants';
import BrowserDetection from '../common/browser-detection';
import IntentToJoinError from '../common/errors/intent-to-join';
import JoinMeetingError from '../common/errors/join-meeting';
import ParameterError from '../common/errors/parameter';
import PermissionError from '../common/errors/permission';
import PasswordError from '../common/errors/password-error';
import CaptchaError from '../common/errors/captcha-error';
import Trigger from '../common/events/trigger-proxy';
import {ServerRoles} from '../member/types';
const MeetingUtil = {
parseLocusJoin: (response) => {
const parsed: any = {};
// First todo: add check for existance
parsed.locus = response.body.locus;
parsed.dataSets = response.body.dataSets;
parsed.metadata = response.body.metaData;
parsed.mediaConnections = response.body.mediaConnections;
parsed.locusUrl = parsed.locus.url;
parsed.locusId = parsed.locus.url.split('/').pop();
parsed.selfId = parsed.locus.self.id;
// we need mediaId before making roap calls
parsed.mediaConnections.forEach((mediaConnection) => {
if (mediaConnection.mediaId) {
parsed.mediaId = mediaConnection.mediaId;
}
});
return parsed;
},
/**
* Sanitizes a WebSocket URL by extracting only protocol, host, and pathname
* Returns concatenated protocol + host + pathname for safe logging
* Note: This is used for logging only; URL matching uses partial matching via _urlsPartiallyMatch
* @param {string} urlString - The URL to sanitize
* @returns {string} Sanitized URL or empty string if parsing fails
*/
sanitizeWebSocketUrl: (urlString: string): string => {
if (!urlString || typeof urlString !== 'string') {
return '';
}
try {
const parsedUrl = url.parse(urlString);
const protocol = parsedUrl.protocol || '';
const host = parsedUrl.host || '';
// If we don't have at least protocol and host, it's not a valid URL
if (!protocol || !host) {
return '';
}
const pathname = parsedUrl.pathname || '';
// Strip trailing slash if pathname is just '/'
const normalizedPathname = pathname === '/' ? '' : pathname;
return `${protocol}//${host}${normalizedPathname}`;
} catch (error) {
LoggerProxy.logger.warn(
`Meeting:util#sanitizeWebSocketUrl --> unable to parse URL: ${error}`
);
return '';
}
},
/**
* Checks if two URLs partially match using an endsWith approach
* Combines host and pathname, then checks if one ends with the other
* This handles cases where one URL goes through a proxy (e.g., /webproxy/) while the other is direct
* @param {string} url1 - First URL to compare
* @param {string} url2 - Second URL to compare
* @returns {boolean} True if one URL path ends with the other (partial match), false otherwise
*/
_urlsPartiallyMatch: (url1: string, url2: string): boolean => {
if (!url1 || !url2) {
return false;
}
try {
const parsedUrl1 = url.parse(url1);
const parsedUrl2 = url.parse(url2);
const host1 = parsedUrl1.host || '';
const host2 = parsedUrl2.host || '';
const pathname1 = parsedUrl1.pathname || '';
const pathname2 = parsedUrl2.pathname || '';
// If either failed to parse, they don't match
if (!host1 || !host2 || !pathname1 || !pathname2) {
return false;
}
// Combine host and pathname for comparison
const combined1 = host1 + pathname1;
const combined2 = host2 + pathname2;
// Check if one combined path ends with the other (handles proxy URLs)
return combined1.endsWith(combined2) || combined2.endsWith(combined1);
} catch (e) {
LoggerProxy.logger.warn('Meeting:util#_urlsPartiallyMatch --> error comparing URLs', e);
return false;
}
},
/**
* Gets socket URL information for metrics, including whether the socket URLs match
* Uses partial matching to handle proxy URLs (e.g., URLs with /webproxy/ prefix)
* @param {Object} webex - The webex instance
* @returns {Object} Object with hasMismatchedSocket, mercurySocketUrl, and deviceSocketUrl properties
*/
getSocketUrlInfo: (
webex: any
): {hasMismatchedSocket: boolean; mercurySocketUrl: string; deviceSocketUrl: string} => {
try {
const mercuryUrl = webex?.internal?.mercury?.socket?.url;
const deviceUrl = webex?.internal?.device?.webSocketUrl;
const sanitizedMercuryUrl = MeetingUtil.sanitizeWebSocketUrl(mercuryUrl);
const sanitizedDeviceUrl = MeetingUtil.sanitizeWebSocketUrl(deviceUrl);
// Only report a mismatch if both URLs are present and they don't match
// If either URL is missing, we can't determine if there's a mismatch, so return false
let hasMismatchedSocket = false;
if (sanitizedMercuryUrl && sanitizedDeviceUrl) {
hasMismatchedSocket = !MeetingUtil._urlsPartiallyMatch(mercuryUrl, deviceUrl);
}
return {
hasMismatchedSocket,
mercurySocketUrl: sanitizedMercuryUrl,
deviceSocketUrl: sanitizedDeviceUrl,
};
} catch (error) {
LoggerProxy.logger.warn(
`Meeting:util#getSocketUrlInfo --> error getting socket URL info: ${error}`
);
return {
hasMismatchedSocket: false,
mercurySocketUrl: '',
deviceSocketUrl: '',
};
}
},
remoteUpdateAudioVideo: (meeting, audioMuted?: boolean, videoMuted?: boolean) => {
if (!meeting) {
return Promise.reject(new ParameterError('You need a meeting object.'));
}
if (!meeting.locusMediaRequest) {
return Promise.reject(
new ParameterError(
'You need a meeting with a media connection, call Meeting.addMedia() first.'
)
);
}
return meeting.locusMediaRequest.send({
type: 'LocalMute',
selfUrl: meeting.selfUrl,
mediaId: meeting.mediaId,
sequence: meeting.locusInfo.sequence,
muteOptions: {
audioMuted,
videoMuted,
},
});
},
hasOwner: (info) => info && info.owner,
isOwnerSelf: (owner, selfId) => owner === selfId,
isPinOrGuest: (err) => err?.body?.errorCode && INTENT_TO_JOIN.includes(err.body.errorCode),
/**
* Returns the current state of knowledge about whether we are on an ipv4-only or ipv6-only or mixed (ipv4 and ipv6) network.
* The return value matches the possible values of "ipver" parameter used by the backend APIs.
*
* @param {Object} webex webex instance
* @returns {IP_VERSION|undefined} ipver value to be passed to the backend APIs or undefined if we should not pass any value to the backend
*/
getIpVersion(webex: any): IP_VERSION | undefined {
const {supportsIpV4, supportsIpV6} = webex.internal.device.ipNetworkDetector;
if (
!webex.config.meetings.backendIpv6NativeSupport &&
BrowserDetection().isBrowser('firefox')
) {
// when backend doesn't support native ipv6,
// then our NAT64/DNS64 based solution relies on FQDN ICE candidates, but Firefox doesn't support them,
// see https://bugzilla.mozilla.org/show_bug.cgi?id=1713128
// so for Firefox we don't want the backend to activate the "ipv6 feature"
return undefined;
}
if (supportsIpV4 && supportsIpV6) {
return IP_VERSION.ipv4_and_ipv6;
}
if (supportsIpV4) {
return IP_VERSION.only_ipv4;
}
if (supportsIpV6) {
return IP_VERSION.only_ipv6;
}
return IP_VERSION.unknown;
},
/**
* Returns CA event labels related to Orpheus ipver parameter that can be sent to CA with any CA event
* @param {any} webex instance
* @returns {Array<string>|undefined} array of CA event labels or undefined if no labels should be sent
*/
getCaEventLabelsForIpVersion(webex: any): Array<string> | undefined {
const ipver = MeetingUtil.getIpVersion(webex);
switch (ipver) {
case IP_VERSION.unknown:
return undefined;
case IP_VERSION.only_ipv4:
return ['hasIpv4_true'];
case IP_VERSION.only_ipv6:
return ['hasIpv6_true'];
case IP_VERSION.ipv4_and_ipv6:
return ['hasIpv4_true', 'hasIpv6_true'];
default:
return undefined;
}
},
joinMeeting: async (meeting, options) => {
if (!meeting) {
return Promise.reject(new ParameterError('You need a meeting object.'));
}
const webex = meeting.getWebexObject();
// @ts-ignore
webex.internal.newMetrics.submitClientEvent({
name: 'client.locus.join.request',
options: {meetingId: meeting.id},
});
let reachability;
let clientMediaPreferences = {
// bare minimum fallback value that should allow us to join
ipver: IP_VERSION.unknown,
joinCookie: undefined,
preferTranscoding: !meeting.isMultistream,
};
try {
clientMediaPreferences = await webex.meetings.reachability.getClientMediaPreferences(
meeting.isMultistream,
MeetingUtil.getIpVersion(webex)
);
if (options.roapMessage) {
// we only need to attach reachability if we are sending a roap message
// sending reachability on its own will cause Locus to reject our join request
reachability = await webex.meetings.reachability.getReachabilityReportToAttachToRoap();
}
} catch (e) {
LoggerProxy.logger.error(
'Meeting:util#joinMeeting --> Error getting reachability or clientMediaPreferences:',
e
);
}
// eslint-disable-next-line no-warning-comments
// TODO: check if the meeting is in JOINING state
// if Joining state termintate the request as user might click multiple times
return meeting.meetingRequest
.joinMeeting({
inviteeAddress: meeting.meetingJoinUrl || meeting.sipUri,
meetingNumber: meeting.meetingNumber,
deviceUrl: meeting.deviceUrl,
locusUrl: meeting.locusUrl,
locusClusterUrl: meeting.meetingInfo?.locusClusterUrl,
correlationId: meeting.correlationId,
reachability,
roapMessage: options.roapMessage,
permissionToken: meeting.permissionToken,
resourceId: options.resourceId || null,
moderator: options.moderator,
pin: options.pin,
moveToResource: options.moveToResource,
asResourceOccupant: options.asResourceOccupant,
breakoutsSupported: options.breakoutsSupported,
locale: options.locale,
deviceCapabilities: options.deviceCapabilities,
liveAnnotationSupported: options.liveAnnotationSupported,
clientMediaPreferences,
alias: options.alias,
})
.then((res) => {
const parsed = MeetingUtil.parseLocusJoin(res);
meeting.setLocus(parsed);
meeting.isoLocalClientMeetingJoinTime = res?.headers?.date; // read from header if exist, else fall back to system clock : https://jira-eng-gpk2.cisco.com/jira/browse/SPARK-555657
const socketUrlInfo = MeetingUtil.getSocketUrlInfo(webex);
webex.internal.newMetrics.submitClientEvent({
name: 'client.locus.join.response',
payload: {
trigger: 'loci-update',
identifiers: {
trackingId: res.headers.trackingid,
},
eventData: {
...socketUrlInfo,
},
},
options: {
meetingId: meeting.id,
mediaConnections: parsed.mediaConnections,
},
});
return parsed;
})
.catch((err) => {
const socketUrlInfo = MeetingUtil.getSocketUrlInfo(webex);
webex.internal.newMetrics.submitClientEvent({
name: 'client.locus.join.response',
payload: {
identifiers: {meetingLookupUrl: meeting.meetingInfo?.meetingLookupUrl},
eventData: {
...socketUrlInfo,
},
},
options: {
meetingId: meeting.id,
rawError: err,
},
});
throw err;
});
},
cleanUp: (meeting) => {
meeting.getWebexObject().internal.device.meetingEnded();
meeting.stopPeriodicLogUpload();
meeting.breakouts.cleanUp();
meeting.simultaneousInterpretation.cleanUp();
meeting.locusMediaRequest = undefined;
meeting.webex?.internal?.newMetrics?.callDiagnosticMetrics?.clearEventLimitsForCorrelationId(
meeting.correlationId
);
// make sure we send last metrics before we close the peerconnection
const stopStatsAnalyzer = meeting.statsAnalyzer
? meeting.statsAnalyzer.stopAnalyzer()
: Promise.resolve();
return stopStatsAnalyzer
.then(() => meeting.closeRemoteStreams())
.then(() => meeting.closePeerConnections())
.then(() => {
meeting.cleanupLocalStreams();
meeting.unsetRemoteStreams();
meeting.unsetPeerConnections();
meeting.reconnectionManager.cleanUp();
})
.then(() => meeting.stopKeepAlive())
.then(() => {
if (meeting.config?.enableAutomaticLLM) {
meeting.updateLLMConnection();
}
});
},
disconnectPhoneAudio: (meeting, phoneUrl) => {
if (meeting.meetingState === FULL_STATE.INACTIVE) {
return Promise.reject(new MeetingNotActiveError());
}
const options = {
locusUrl: meeting.locusUrl,
selfId: meeting.selfId,
correlationId: meeting.correlationId,
phoneUrl,
};
return meeting.meetingRequest.disconnectPhoneAudio(options).catch((err) => {
LoggerProxy.logger.error(
`Meeting:util#disconnectPhoneAudio --> An error occured while disconnecting phone audio in meeting ${meeting.id}, error: ${err}`
);
return Promise.reject(err);
});
},
/**
* Returns options for leaving a meeting.
* @param {any} meeting
* @param {any} options
* @returns {any} leave options
*/
prepareLeaveMeetingOptions: (meeting, options: any = {}) => {
const defaultOptions = {
locusUrl: meeting.locusUrl,
selfId: meeting.selfId,
correlationId: meeting.correlationId,
resourceId: meeting.resourceId,
deviceUrl: meeting.deviceUrl,
};
return {...defaultOptions, ...options};
},
// by default will leave on meeting's resourceId
// if you explicity want it not to leave on resource id, pass
// {resourceId: null}
// TODO: chris, you can modify this however you want
leaveMeeting: (meeting, options: any = {}) => {
if (meeting.meetingState === FULL_STATE.INACTIVE) {
// TODO: clean up if the meeting is already inactive
return Promise.reject(new MeetingNotActiveError());
}
if (MeetingUtil.isUserInLeftState(meeting.locusInfo)) {
return Promise.reject(new UserNotJoinedError());
}
const leaveOptions = MeetingUtil.prepareLeaveMeetingOptions(meeting, options);
return meeting.meetingRequest
.leaveMeeting(leaveOptions)
.then(() => {
if (options.moveMeeting) {
return Promise.resolve();
}
return MeetingUtil.cleanUp(meeting);
})
.catch((err) => {
// TODO: If the meeting state comes as LEFT or INACTIVE as response then
// 1) on leave clean up the meeting or simply do a sync on the meeting
// 2) If the error says meeting is inactive then destroy the meeting object
LoggerProxy.logger.error(
`Meeting:util#leaveMeeting --> An error occured while trying to leave meeting with an id of ${meeting.id}, error: ${err}`
);
return Promise.reject(err);
});
},
declineMeeting: (meeting, reason) =>
meeting.meetingRequest.declineMeeting({
locusUrl: meeting.locusUrl,
deviceUrl: meeting.deviceUrl,
reason,
}),
isUserInLeftState: (locusInfo) => locusInfo.parsedLocus?.self?.state === _LEFT_,
isUserInIdleState: (locusInfo) => locusInfo.parsedLocus?.self?.state === _IDLE_,
isUserInJoinedState: (locusInfo) => locusInfo.parsedLocus?.self?.state === _JOINED_,
isMediaEstablished: (currentMediaStatus) =>
currentMediaStatus &&
(currentMediaStatus.audio || currentMediaStatus.video || currentMediaStatus.share),
joinMeetingOptions: (meeting, options: any = {}) => {
const webex = meeting.getWebexObject();
meeting.resourceId = meeting.resourceId || options.resourceId;
if (meeting.requiredCaptcha) {
const errorToThrow = new CaptchaError();
// @ts-ignore
webex.internal.newMetrics.submitClientEvent({
name: 'client.meetinginfo.response',
options: {
meetingId: meeting.id,
},
payload: {
errors: [
{
fatal: false,
category: 'expected',
name: 'other',
shownToUser: false,
errorCode: errorToThrow.code,
errorDescription: errorToThrow.name,
rawErrorMessage: errorToThrow.sdkMessage,
},
],
},
});
return Promise.reject(errorToThrow);
}
if (meeting.passwordStatus === PASSWORD_STATUS.REQUIRED) {
const errorToThrow = new PasswordError();
// @ts-ignore
webex.internal.newMetrics.submitClientEvent({
name: 'client.meetinginfo.response',
options: {
meetingId: meeting.id,
},
payload: {
errors: [
{
fatal: false,
category: 'expected',
name: 'other',
shownToUser: false,
errorCode: errorToThrow.code,
errorDescription: errorToThrow.name,
rawErrorMessage: errorToThrow.sdkMessage,
},
],
},
});
return Promise.reject(errorToThrow);
}
if (options.pin) {
// @ts-ignore
webex.internal.newMetrics.submitClientEvent({
name: 'client.pin.collected',
options: {
meetingId: meeting.id,
},
});
}
// normal join meeting, scenario A, D
return MeetingUtil.joinMeeting(meeting, options).catch((err) => {
// joining a claimed PMR that is not my own, scenario B
if (MeetingUtil.isPinOrGuest(err)) {
webex.internal.newMetrics.submitClientEvent({
name: 'client.pin.prompt',
options: {
meetingId: meeting.id,
},
});
// request host pin or non host for unclaimed PMR, start of Scenario C
// see https://sqbu-github.cisco.com/WebExSquared/locus/wiki/Locus-Lobby-and--IVR-Feature
return Promise.reject(new IntentToJoinError('Error Joining Meeting', err));
}
LoggerProxy.logger.error('Meeting:util#joinMeetingOptions --> Error joining the call, ', err);
return Promise.reject(new JoinMeetingError(options, 'Error Joining Meeting', err));
});
},
/**
* Returns request options for leaving a meeting.
* @param {any} meeting
* @param {any} options
* @returns {any} request options
*/
buildLeaveFetchRequestOptions: (meeting, options: any = {}) => {
const leaveOptions = MeetingUtil.prepareLeaveMeetingOptions(meeting, options);
return meeting.meetingRequest.buildLeaveMeetingRequestOptions(leaveOptions);
},
getTrack: (stream) => {
let audioTrack = null;
let videoTrack = null;
let audioTracks = null;
let videoTracks = null;
if (!stream) {
return {audioTrack: null, videoTrack: null};
}
if (stream.getAudioTracks) {
audioTracks = stream.getAudioTracks();
}
if (stream.getVideoTracks) {
videoTracks = stream.getVideoTracks();
}
if (audioTracks && audioTracks.length > 0) {
[audioTrack] = audioTracks;
}
if (videoTracks && videoTracks.length > 0) {
[videoTrack] = videoTracks;
}
return {audioTrack, videoTrack};
},
getModeratorFromLocusInfo: (locusInfo) =>
locusInfo &&
locusInfo.parsedLocus &&
locusInfo.parsedLocus.info &&
locusInfo.parsedLocus.info &&
locusInfo.parsedLocus.info.moderator,
getPolicyFromLocusInfo: (locusInfo) =>
locusInfo &&
locusInfo.parsedLocus &&
locusInfo.parsedLocus.info &&
locusInfo.parsedLocus.info &&
locusInfo.parsedLocus.info.policy,
getUserDisplayHintsFromLocusInfo: (locusInfo) =>
locusInfo?.parsedLocus?.info?.userDisplayHints || [],
canInviteNewParticipants: (displayHints) => displayHints.includes(DISPLAY_HINTS.ADD_GUEST),
canAdmitParticipant: (displayHints) =>
displayHints.includes(DISPLAY_HINTS.ROSTER_WAITING_TO_JOIN),
canUserLock: (displayHints) =>
displayHints.includes(DISPLAY_HINTS.LOCK_CONTROL_LOCK) &&
displayHints.includes(DISPLAY_HINTS.LOCK_STATUS_UNLOCKED),
canUserUnlock: (displayHints) =>
displayHints.includes(DISPLAY_HINTS.LOCK_CONTROL_UNLOCK) &&
displayHints.includes(DISPLAY_HINTS.LOCK_STATUS_LOCKED),
canUserRaiseHand: (displayHints) => displayHints.includes(DISPLAY_HINTS.RAISE_HAND),
canUserLowerAllHands: (displayHints) => displayHints.includes(DISPLAY_HINTS.LOWER_ALL_HANDS),
canUserLowerSomeoneElsesHand: (displayHints) =>
displayHints.includes(DISPLAY_HINTS.LOWER_SOMEONE_ELSES_HAND),
bothLeaveAndEndMeetingAvailable: (displayHints) =>
displayHints.includes(DISPLAY_HINTS.LEAVE_TRANSFER_HOST_END_MEETING) ||
displayHints.includes(DISPLAY_HINTS.LEAVE_END_MEETING),
canManageBreakout: (displayHints) => displayHints.includes(DISPLAY_HINTS.BREAKOUT_MANAGEMENT),
canStartBreakout: (displayHints) => !displayHints.includes(DISPLAY_HINTS.DISABLE_BREAKOUT_START),
canBroadcastMessageToBreakout: (displayHints, policies = {}) =>
displayHints.includes(DISPLAY_HINTS.BROADCAST_MESSAGE_TO_BREAKOUT) &&
!!policies[SELF_POLICY.SUPPORT_BROADCAST_MESSAGE],
isSuppressBreakoutSupport: (displayHints) =>
displayHints.includes(DISPLAY_HINTS.UCF_SUPPRESS_BREAKOUTS_SUPPORT),
canAdmitLobbyToBreakout: (displayHints) =>
!displayHints.includes(DISPLAY_HINTS.DISABLE_LOBBY_TO_BREAKOUT),
isBreakoutPreassignmentsEnabled: (displayHints) =>
!displayHints.includes(DISPLAY_HINTS.DISABLE_BREAKOUT_PREASSIGNMENTS),
canUserAskForHelp: (displayHints) => !displayHints.includes(DISPLAY_HINTS.DISABLE_ASK_FOR_HELP),
lockMeeting: (actions, request, locusUrl) => {
if (actions && actions.canLock) {
return request.lockMeeting({locusUrl, lock: true});
}
return Promise.reject(new PermissionError('Lock not allowed, due to joined property.'));
},
unlockMeeting: (actions, request, locusUrl) => {
if (actions && actions.canUnlock) {
return request.lockMeeting({locusUrl, lock: false});
}
return Promise.reject(new PermissionError('Unlock not allowed, due to joined property.'));
},
handleAudioLogging: (audioStream?: LocalMicrophoneStream) => {
const LOG_HEADER = 'MeetingUtil#handleAudioLogging -->';
if (audioStream) {
const settings = audioStream.getSettings();
const {deviceId} = settings;
LoggerProxy.logger.log(LOG_HEADER, `deviceId = ${deviceId}`);
LoggerProxy.logger.log(LOG_HEADER, 'settings =', JSON.stringify(settings));
}
},
handleVideoLogging: (videoStream?: LocalCameraStream) => {
const LOG_HEADER = 'MeetingUtil#handleVideoLogging -->';
if (videoStream) {
const settings = videoStream.getSettings();
const {deviceId} = settings;
LoggerProxy.logger.log(LOG_HEADER, `deviceId = ${deviceId}`);
LoggerProxy.logger.log(LOG_HEADER, 'settings =', JSON.stringify(settings));
}
},
endMeetingForAll: (meeting) => {
if (meeting.meetingState === FULL_STATE.INACTIVE) {
return Promise.reject(new MeetingNotActiveError());
}
const endOptions = {
locusUrl: meeting.locusUrl,
};
return meeting.meetingRequest
.endMeetingForAll(endOptions)
.then(() => MeetingUtil.cleanUp(meeting))
.catch((err) => {
LoggerProxy.logger.error(
`Meeting:util#endMeetingForAll An error occured while trying to end meeting for all with an id of ${meeting.id}, error: ${err}`
);
return Promise.reject(err);
});
},
canEnableClosedCaption: (displayHints) => displayHints.includes(DISPLAY_HINTS.CAPTION_START),
isSaveTranscriptsEnabled: (displayHints) =>
displayHints.includes(DISPLAY_HINTS.SAVE_TRANSCRIPTS_ENABLED),
canStartTranscribing: (displayHints) =>
displayHints.includes(DISPLAY_HINTS.TRANSCRIPTION_CONTROL_START),
canStopTranscribing: (displayHints) =>
displayHints.includes(DISPLAY_HINTS.TRANSCRIPTION_CONTROL_STOP),
isClosedCaptionActive: (displayHints) =>
displayHints.includes(DISPLAY_HINTS.CAPTION_STATUS_ACTIVE),
canStartManualCaption: (displayHints) =>
displayHints.includes(DISPLAY_HINTS.MANUAL_CAPTION_START),
isLocalRecordingStarted: (displayHints) =>
displayHints.includes(DISPLAY_HINTS.LOCAL_RECORDING_STATUS_STARTED),
isLocalRecordingStopped: (displayHints) =>
displayHints.includes(DISPLAY_HINTS.LOCAL_RECORDING_STATUS_STOPPED),
isLocalRecordingPaused: (displayHints) =>
displayHints.includes(DISPLAY_HINTS.LOCAL_RECORDING_STATUS_PAUSED),
isLocalStreamingStarted: (displayHints) =>
displayHints.includes(DISPLAY_HINTS.STREAMING_STATUS_STARTED),
isLocalStreamingStopped: (displayHints) =>
displayHints.includes(DISPLAY_HINTS.STREAMING_STATUS_STOPPED),
canStopManualCaption: (displayHints) => displayHints.includes(DISPLAY_HINTS.MANUAL_CAPTION_STOP),
isManualCaptionActive: (displayHints) =>
displayHints.includes(DISPLAY_HINTS.MANUAL_CAPTION_STATUS_ACTIVE),
isSpokenLanguageAutoDetectionEnabled: (displayHints) =>
displayHints.includes(DISPLAY_HINTS.SPOKEN_LANGUAGE_AUTO_DETECTION_ENABLED),
isWebexAssistantActive: (displayHints) =>
displayHints.includes(DISPLAY_HINTS.WEBEX_ASSISTANT_STATUS_ACTIVE),
canViewCaptionPanel: (displayHints) => displayHints.includes(DISPLAY_HINTS.ENABLE_CAPTION_PANEL),
isRealTimeTranslationEnabled: (displayHints) =>
displayHints.includes(DISPLAY_HINTS.DISPLAY_REAL_TIME_TRANSLATION),
canSelectSpokenLanguages: (displayHints) =>
displayHints.includes(DISPLAY_HINTS.DISPLAY_NON_ENGLISH_ASR),
waitingForOthersToJoin: (displayHints) => displayHints.includes(DISPLAY_HINTS.WAITING_FOR_OTHERS),
showAutoEndMeetingWarning: (displayHints) =>
displayHints.includes(DISPLAY_HINTS.SHOW_AUTO_END_MEETING_WARNING),
canSendReactions: (originalValue, displayHints) => {
if (displayHints.includes(DISPLAY_HINTS.REACTIONS_ACTIVE)) {
return true;
}
if (displayHints.includes(DISPLAY_HINTS.REACTIONS_INACTIVE)) {
return false;
}
return originalValue;
},
canUserRenameSelfAndObserved: (displayHints) =>
displayHints.includes(DISPLAY_HINTS.CAN_RENAME_SELF_AND_OBSERVED),
requiresPostMeetingDataConsentPrompt: (displayHints) =>
displayHints.includes(DISPLAY_HINTS.SHOW_POST_MEETING_DATA_CONSENT_PROMPT),
canUserRenameOthers: (displayHints) => displayHints.includes(DISPLAY_HINTS.CAN_RENAME_OTHERS),
// Default empty value for policies if we get an undefined value (ie permissionToken is not available)
canShareWhiteBoard: (displayHints, policies = {}) =>
displayHints.includes(DISPLAY_HINTS.SHARE_WHITEBOARD) &&
!!policies[SELF_POLICY.SUPPORT_WHITEBOARD],
canMoveToLobby: (displayHints) => displayHints.includes(DISPLAY_HINTS.MOVE_TO_LOBBY),
/**
* Adds the current locus sequence information to a request body
* @param {Object} meeting The meeting object
* @param {Object} requestBody The body of a request to locus
* @returns {void}
*/
addSequence: (meeting, requestBody) => {
const sequence = meeting?.locusInfo?.sequence;
if (!sequence) {
return;
}
requestBody.sequence = sequence;
},
/**
* Updates the locus info for the meeting with the locus
* information returned from API requests made to Locus
* Returns the original response object
* @param {Object} meeting The meeting object
* @param {Object} response The response of the http request
* @returns {Object}
*/
updateLocusFromApiResponse: (meeting, response) => {
if (!meeting) {
return response;
}
if (response?.body?.locus) {
meeting.locusInfo.handleLocusAPIResponse(meeting, response.body);
}
return response;
},
generateBuildLocusDeltaRequestOptions: (originalMeeting) => {
const meetingRef = new WeakRef(originalMeeting);
const buildLocusDeltaRequestOptions = (originalOptions) => {
const meeting = meetingRef.deref();
if (!meeting) {
return originalOptions;
}
const options = cloneDeep(originalOptions);
if (!options.body) {
options.body = {};
}
MeetingUtil.addSequence(meeting, options.body);
return options;
};
return buildLocusDeltaRequestOptions;
},
generateLocusDeltaRequest: (originalMeeting) => {
const meetingRef = new WeakRef(originalMeeting);
const buildLocusDeltaRequestOptions =
MeetingUtil.generateBuildLocusDeltaRequestOptions(originalMeeting);
const locusDeltaRequest = (originalOptions) => {
const meeting = meetingRef.deref();
if (!meeting) {
return Promise.resolve();
}
const options = buildLocusDeltaRequestOptions(originalOptions);
return meeting
.request(options)
.then((response) => MeetingUtil.updateLocusFromApiResponse(meeting, response));
};
return locusDeltaRequest;
},
canAttendeeRequestAiAssistantEnabled: (displayHints = [], roles: any[] = []) => {
const isHostOrCoHost =
roles.includes(ServerRoles.Cohost) || roles.includes(ServerRoles.Moderator);
if (isHostOrCoHost) {
return false;
}
if (displayHints.includes(DISPLAY_HINTS.ATTENDEE_REQUEST_AI_ASSISTANT_ENABLED)) {
return true;
}
return false;
},
attendeeRequestAiAssistantDeclinedAll: (displayHints = []) =>
displayHints.includes(DISPLAY_HINTS.ATTENDEE_REQUEST_AI_ASSISTANT_DECLINED_ALL),
selfSupportsFeature: (feature: SELF_POLICY, userPolicies: Record<SELF_POLICY, boolean>) => {
if (!userPolicies) {
return true;
}
return userPolicies[feature];
},
parseInterpretationInfo: (meeting, meetingInfo) => {
if (!meeting || !meetingInfo) {
return;
}
const siInfo = meetingInfo.simultaneousInterpretation;
meeting.simultaneousInterpretation.updateMeetingSIEnabled(
!!meetingInfo.turnOnSimultaneousInterpretation,
!!siInfo?.currentSIInterpreter
);
const hostSIEnabled = !!(
meetingInfo.turnOnSimultaneousInterpretation &&
meetingInfo?.meetingSiteSetting?.enableHostInterpreterControlSI
);
meeting.simultaneousInterpretation.updateHostSIEnabled(hostSIEnabled);
function renameKey(obj, oldKey, newKey) {
if (oldKey in obj) {
obj[newKey] = obj[oldKey];
delete obj[oldKey];
}
}
if (siInfo) {
const lanuagesInfo = cloneDeep(siInfo.siLanguages);
for (const language of lanuagesInfo) {
renameKey(language, 'languageCode', 'languageName');
renameKey(language, 'languageGroupId', 'languageCode');
}
if (!meeting.simultaneousInterpretation?.siLanguages?.length) {
meeting.simultaneousInterpretation.updateInterpretation({siLanguages: lanuagesInfo});
}
}
Trigger.trigger(
meeting,
{
file: 'meeting/util',
function: 'parseInterpretationInfo',
},
EVENT_TRIGGERS.MEETING_INTERPRETATION_UPDATE
);
},
/**
* Returns a CA-recognized error payload for the specified raw error message/reason.
*
* New errors can be added to this function for handling in the future
*
* @param {String} reason the raw error message
* @returns {Array<object>} an array of payload objects
*/
getChangeMeetingFloorErrorPayload: (reason: string) => {
const errorPayload = {
errorDescription: reason,
name: 'locus.response',
shownToUser: false,
};
if (reason.includes(LOCAL_SHARE_ERRORS.UNDEFINED)) {
return [
{
...errorPayload,
fatal: true,
category: 'signaling',
errorCode: 1100,
},
];
}
if (reason.includes(LOCAL_SHARE_ERRORS.DEVICE_NOT_JOINED)) {
return [
{