2018-04-25 02:42:59 +08:00
|
|
|
import Users from '/imports/api/users';
|
2021-09-07 04:51:42 +08:00
|
|
|
import Logger from '/imports/startup/server/logger';
|
2016-05-13 01:43:59 +08:00
|
|
|
|
2018-04-12 21:41:32 +08:00
|
|
|
const MSG_DIRECT_TYPE = 'DIRECT';
|
|
|
|
const NODE_USER = 'nodeJSapp';
|
2016-05-13 01:43:59 +08:00
|
|
|
|
2019-11-15 01:07:02 +08:00
|
|
|
export const spokeTimeoutHandles = {};
|
|
|
|
export const clearSpokeTimeout = (meetingId, userId) => {
|
|
|
|
if (spokeTimeoutHandles[`${meetingId}-${userId}`]) {
|
|
|
|
Meteor.clearTimeout(spokeTimeoutHandles[`${meetingId}-${userId}`]);
|
|
|
|
delete spokeTimeoutHandles[`${meetingId}-${userId}`];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-05-05 01:00:57 +08:00
|
|
|
export const indexOf = [].indexOf || function (item) {
|
2017-08-10 11:59:53 +08:00
|
|
|
for (let i = 0, l = this.length; i < l; i += 1) {
|
2017-06-03 03:25:02 +08:00
|
|
|
if (i in this && this[i] === item) {
|
|
|
|
return i;
|
2016-06-28 02:24:37 +08:00
|
|
|
}
|
2017-06-03 03:25:02 +08:00
|
|
|
}
|
2016-06-28 02:24:37 +08:00
|
|
|
|
2017-06-03 03:25:02 +08:00
|
|
|
return -1;
|
|
|
|
};
|
2016-05-05 04:25:34 +08:00
|
|
|
|
2021-09-07 04:51:42 +08:00
|
|
|
export const processForHTML5ServerOnly = (fn) => (message, ...args) => {
|
2018-04-12 21:41:32 +08:00
|
|
|
const { envelope } = message;
|
|
|
|
const { routing } = envelope;
|
2018-04-25 22:29:55 +08:00
|
|
|
const { msgType, meetingId, userId } = routing;
|
2018-04-12 21:41:32 +08:00
|
|
|
|
2018-04-25 02:42:59 +08:00
|
|
|
const selector = {
|
2018-04-25 22:29:55 +08:00
|
|
|
userId,
|
|
|
|
meetingId,
|
2018-04-25 02:42:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const user = Users.findOne(selector);
|
|
|
|
|
2018-04-25 22:29:55 +08:00
|
|
|
const shouldSkip = user && msgType === MSG_DIRECT_TYPE && userId !== NODE_USER && user.clientType !== 'HTML5';
|
2018-04-12 21:41:32 +08:00
|
|
|
if (shouldSkip) return () => { };
|
2018-04-23 20:30:14 +08:00
|
|
|
return fn(message, ...args);
|
2018-04-12 21:41:32 +08:00
|
|
|
};
|
|
|
|
|
2020-02-07 04:47:28 +08:00
|
|
|
export const extractCredentials = (credentials) => {
|
2020-02-14 03:40:15 +08:00
|
|
|
if (!credentials) return {};
|
2020-02-07 04:47:28 +08:00
|
|
|
const credentialsArray = credentials.split('--');
|
|
|
|
const meetingId = credentialsArray[0];
|
|
|
|
const requesterUserId = credentialsArray[1];
|
|
|
|
return { meetingId, requesterUserId };
|
|
|
|
};
|
2021-09-07 04:51:42 +08:00
|
|
|
|
|
|
|
// Creates a background job to periodically check the result of the provided function.
|
|
|
|
// The provided function is publication-specific and must check the "survival condition" of the publication.
|
|
|
|
export const publicationSafeGuard = function (fn, self) {
|
|
|
|
let stopped = false;
|
|
|
|
const periodicCheck = function () {
|
|
|
|
if (stopped) return;
|
|
|
|
if (!fn()) {
|
|
|
|
self.added(self._name, 'publication-stop-marker', { id: 'publication-stop-marker', stopped: true });
|
|
|
|
self.stop();
|
|
|
|
} else Meteor.setTimeout(periodicCheck, 1000);
|
|
|
|
};
|
|
|
|
|
|
|
|
self.onStop(() => {
|
|
|
|
stopped = true;
|
|
|
|
Logger.info(`Publication ${self._name} has stopped in server side`);
|
|
|
|
});
|
|
|
|
|
|
|
|
periodicCheck();
|
|
|
|
};
|