2020-04-29 11:33:45 +08:00
|
|
|
import Logger from '/imports/startup/server/logger';
|
|
|
|
|
|
|
|
class PendingAuthentitcations {
|
2020-05-26 01:32:24 +08:00
|
|
|
constructor() {
|
|
|
|
Logger.debug('PendingAuthentitcations :: constructor');
|
|
|
|
this.store = [];
|
|
|
|
}
|
2020-04-29 11:33:45 +08:00
|
|
|
|
2020-05-26 01:32:24 +08:00
|
|
|
generateKey(meetingId, userId, authToken) {
|
|
|
|
// Protect against separator injection
|
|
|
|
meetingId = meetingId.replace(/ /g, '');
|
|
|
|
userId = userId.replace(/ /g, '');
|
|
|
|
authToken = authToken.replace(/ /g, '');
|
2020-04-29 11:33:45 +08:00
|
|
|
|
2020-05-26 01:32:24 +08:00
|
|
|
// Space separated key
|
|
|
|
return `${meetingId} ${userId} ${authToken}`;
|
|
|
|
}
|
2020-04-29 11:33:45 +08:00
|
|
|
|
2020-05-26 01:32:24 +08:00
|
|
|
add(meetingId, userId, authToken, methodInvocationObject) {
|
|
|
|
Logger.debug('PendingAuthentitcations :: add', { meetingId, userId, authToken });
|
|
|
|
this.store.push({
|
|
|
|
key: this.generateKey(meetingId, userId, authToken),
|
|
|
|
meetingId,
|
|
|
|
userId,
|
|
|
|
authToken,
|
|
|
|
methodInvocationObject,
|
|
|
|
});
|
|
|
|
}
|
2020-04-29 11:33:45 +08:00
|
|
|
|
2020-05-26 01:32:24 +08:00
|
|
|
take(meetingId, userId, authToken) {
|
|
|
|
const key = this.generateKey(meetingId, userId, authToken);
|
|
|
|
Logger.debug('PendingAuthentitcations :: take', {
|
|
|
|
key, meetingId, userId, authToken,
|
|
|
|
});
|
|
|
|
|
|
|
|
// find matches
|
|
|
|
const matches = this.store.filter(e => e.key === key);
|
|
|
|
// remove matches (if any)
|
|
|
|
if (matches.length) {
|
|
|
|
this.store = this.store.filter(e => e.key !== key);
|
2020-04-29 11:33:45 +08:00
|
|
|
}
|
2020-05-26 01:32:24 +08:00
|
|
|
|
|
|
|
// return matches
|
|
|
|
return matches;
|
|
|
|
}
|
2020-04-29 11:33:45 +08:00
|
|
|
}
|
2020-05-26 01:32:24 +08:00
|
|
|
export default new PendingAuthentitcations();
|