-
Notifications
You must be signed in to change notification settings - Fork 341
/
utilv2.ts
324 lines (278 loc) · 9.66 KB
/
utilv2.ts
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
import url from 'url';
// @ts-ignore
import {deconstructHydraId} from '@webex/common';
import {
_SIP_URI_,
_PERSONAL_ROOM_,
_MEETING_ID_,
_CONVERSATION_URL_,
_LOCUS_ID_,
_MEETING_LINK_,
_PEOPLE_,
_ROOM_,
_MEETING_UUID_,
DIALER_REGEX,
WEBEX_DOT_COM,
CONVERSATION_SERVICE,
JOIN,
MEET,
MEET_M,
MEET_CISCO,
MEET_CO,
HTTPS_PROTOCOL,
UUID_REG,
VALID_EMAIL_ADDRESS,
DEFAULT_MEETING_INFO_REQUEST_BODY,
} from '../constants';
import ParameterError from '../common/errors/parameter';
import LoggerProxy from '../common/logs/logger-proxy';
import {SpaceIDDeprecatedError} from '../common/errors/webex-errors';
const MeetingInfoUtil: any = {};
const meetingInfoError =
'MeetingInfo is fetched with the meeting link, SIP URI, phone number, Hydra people ID, or a conversation URL.';
MeetingInfoUtil.getParsedUrl = (link) => {
try {
let parsedUrl = url.parse(link);
if (!parsedUrl) {
return false;
}
// hack for links such as <company>.webex.com/meet/<user> without a protocol
if (!parsedUrl.protocol) {
parsedUrl = url.parse(`${HTTPS_PROTOCOL}${link}`);
}
return parsedUrl;
} catch (error) {
LoggerProxy.logger.warn(
`Meeting-info:util#getParsedUrl --> unable to parse the URL, error: ${error}`
);
return null;
}
};
/**
* Helper function to check if a string matches a known meeting link pattern
* @param {String} value string to parse and see if it matches a meeting link
* @returns {Boolean}
*/
MeetingInfoUtil.isMeetingLink = (value: string) => {
const parsedUrl = MeetingInfoUtil.getParsedUrl(value);
const hostNameBool = parsedUrl.hostname && parsedUrl.hostname.includes(WEBEX_DOT_COM);
const pathNameBool =
parsedUrl.pathname &&
(parsedUrl.pathname.includes(`/${MEET}`) ||
parsedUrl.pathname.includes(`/${MEET_M}`) ||
parsedUrl.pathname.includes(`/${MEET_CISCO}`) ||
parsedUrl.pathname.includes(`/${MEET_CO}`) ||
parsedUrl.pathname.includes(`/${JOIN}`));
return hostNameBool && pathNameBool;
};
MeetingInfoUtil.isConversationUrl = (value, webex) => {
const clusterId = webex.internal.services.getClusterId(value);
if (clusterId) {
return clusterId.endsWith(CONVERSATION_SERVICE);
}
return false;
};
MeetingInfoUtil.isSipUri = (sipString) => {
// TODO: lets remove regex from this equation and user URI matchers and such
// have not found a great sip uri parser library as of now
const sipUri = DIALER_REGEX.SIP_ADDRESS.exec(sipString);
return sipUri;
};
MeetingInfoUtil.isPhoneNumber = (phoneNumber) => {
const isValidNumber = DIALER_REGEX.PHONE_NUMBER.test(phoneNumber);
return isValidNumber;
};
MeetingInfoUtil.getHydraId = (destination) => {
const {type, id, cluster} = deconstructHydraId(destination);
if (id && UUID_REG.test(id)) {
if (type === _ROOM_) {
return {room: true, destination: id, cluster};
}
if (type === _PEOPLE_) {
return {people: true, destination: id, cluster};
}
return {};
}
return {};
};
MeetingInfoUtil.getSipUriFromHydraPersonId = (destination, webex) =>
webex.people
.get(destination)
.then((res) => {
if (res.emails && res.emails.length) {
return res.emails[0];
}
throw new ParameterError('Hydra Id Lookup was an invalid hydra person id.');
})
.catch((err) => {
LoggerProxy.logger.error(
`Meeting-info:util#MeetingInfoUtil.getSipUriFromHydraPersonId --> getSipUriFromHydraPersonId ${err} `
);
throw err;
});
MeetingInfoUtil.getDestinationType = async (from) => {
const {type, webex} = from;
let {destination} = from;
if (type === _PERSONAL_ROOM_) {
// this case checks if your type is personal room
if (!destination) {
// if we are not getting anything in desination we fetch org and user ids from webex instance
destination = {
userId: webex.internal.device.userId,
orgId: webex.internal.device.orgId,
};
} else {
const options = VALID_EMAIL_ADDRESS.test(destination)
? {email: destination}
: {id: destination}; // we are assuming userId as default
const res = await webex.people.list(options);
let {orgId, id: userId} = res.items[0];
userId = deconstructHydraId(userId).id;
orgId = deconstructHydraId(orgId).id;
destination = {userId, orgId};
}
}
if (type) {
return {
destination,
type,
};
}
const options: any = {};
let hydraId;
if (webex && webex.config && webex.config.meetings && webex.config.meetings.disableHydraId) {
hydraId = null;
} else {
hydraId = MeetingInfoUtil.getHydraId(destination);
}
if (MeetingInfoUtil.isMeetingLink(destination)) {
LoggerProxy.logger.warn(
'Meeting-info:util#generateOptions --> WARN, use of Meeting Link is deprecated, please use a SIP URI instead'
);
options.type = _MEETING_LINK_;
options.destination = destination;
} else if (MeetingInfoUtil.isSipUri(destination)) {
options.type = _SIP_URI_;
options.destination = destination;
} else if (MeetingInfoUtil.isPhoneNumber(destination)) {
options.type = _SIP_URI_;
options.destination = destination;
} else if (MeetingInfoUtil.isConversationUrl(destination, webex)) {
options.type = _CONVERSATION_URL_;
options.destination = destination;
} else if (hydraId && hydraId.people) {
options.type = _SIP_URI_;
return MeetingInfoUtil.getSipUriFromHydraPersonId(hydraId && hydraId.destination, webex).then(
(res) => {
options.destination = res;
// Since hydra person ids require a unique case in which they are
// entirely converted to a SIP URI, we need to set a flag for detecting
// this type of destination.
options.wasHydraPerson = true;
return Promise.resolve(options);
}
);
} else if (hydraId.room) {
LoggerProxy.logger.error(
`Meeting-info:util#getDestinationType --> Using the space ID as a destination is no longer supported. Please refer to the [migration guide](https://github.com/webex/webex-js-sdk/wiki/Migration-to-Unified-Space-Meetings) to migrate to use the meeting ID or SIP address.`
);
// Error code 30105 added as Space ID deprecated as of beta, Please refer migration guide.
throw new SpaceIDDeprecatedError();
} else {
LoggerProxy.logger.warn(`Meeting-info:util#getDestinationType --> ${meetingInfoError}`);
throw new ParameterError(`${meetingInfoError}`);
}
return Promise.resolve(options);
};
/**
* Helper function to build up a correct locus url depending on the value passed
* @param {Object} options type and value to fetch meeting info
* @param {String} options.type One of [SIP_URI, PERSONAL_ROOM, MEETING_ID, CONVERSATION_URL, LOCUS_ID, MEETING_LINK]
* @param {String} options.installedOrgID org ID of user's machine
* @param {Object} options.destination ?? value.value
* @returns {Object} returns an object with {resource, method}
*/
MeetingInfoUtil.getRequestBody = (options: {type: string; destination: object} | any) => {
const {type, destination, password, captchaInfo, installedOrgID, locusId, extraParams} = options;
const body: any = {
...DEFAULT_MEETING_INFO_REQUEST_BODY,
...extraParams,
};
switch (type) {
case _SIP_URI_:
body.sipUrl = destination;
break;
case _PERSONAL_ROOM_:
body.userId = destination.userId;
body.orgId = destination.orgId;
break;
case _MEETING_ID_:
body.meetingKey = destination;
break;
case _CONVERSATION_URL_:
body.conversationUrl = destination;
break;
case _LOCUS_ID_:
// use meetingID for the completer meeting info for the already started meeting
if (destination.info?.webExMeetingId) {
body.meetingKey = destination.info.webExMeetingId;
} else if (destination.info?.sipUri) {
body.sipUrl = destination.info.sipUri;
}
break;
case _MEETING_LINK_:
body.meetingUrl = destination;
break;
case _MEETING_UUID_: {
body.meetingUUID = destination;
break;
}
default:
}
if (password) {
body.password = password;
}
if (captchaInfo) {
body.captchaID = captchaInfo.id;
body.captchaVerifyCode = captchaInfo.code;
}
if (installedOrgID) {
body.installedOrgID = installedOrgID;
}
if (locusId) {
body.locusId = locusId;
}
return body;
};
/**
* Helper function to parse the webex site/host from a URI string.
* @param {String} uri string (e.g. '10019857020@convergedats.webex.com')
* @returns {String} the site/host part of the URI string (e.g. 'convergedats.webex.com')
*/
MeetingInfoUtil.getWebexSite = (uri: string) => {
const exceptedDomains = ['meet.webex.com', 'meetup.webex.com', 'ciscospark.com'];
const site = uri?.match(/.+@([^.]+\.[^.]+\.[^.]+)$/)?.[1];
return exceptedDomains.includes(site) ? null : site;
};
/**
* Helper function to return the direct URI for fetching meeting info (to avoid a redirect).
* @param {Object} options type and value to fetch meeting info
* @param {String} options.type One of [SIP_URI, PERSONAL_ROOM, MEETING_ID, CONVERSATION_URL, LOCUS_ID, MEETING_LINK]
* @param {Object} options.destination ?? value.value
* @returns {String} returns a URI string or null of there is no direct URI
*/
MeetingInfoUtil.getDirectMeetingInfoURI = (options: {type: string; destination: any}) => {
const {type, destination} = options;
let preferredWebexSite = null;
switch (type) {
case _SIP_URI_:
preferredWebexSite = MeetingInfoUtil.getWebexSite(destination);
break;
case _LOCUS_ID_:
preferredWebexSite = destination.info?.webExSite;
break;
default:
}
return preferredWebexSite ? `https://${preferredWebexSite}/wbxappapi/v1/meetingInfo` : null;
};
export default MeetingInfoUtil;