2019-11-23 05:08:27 +08:00
|
|
|
import Logger from '/imports/startup/server/logger';
|
2019-11-27 04:31:41 +08:00
|
|
|
import Users from '/imports/api/users';
|
2019-11-23 05:08:27 +08:00
|
|
|
|
|
|
|
const FLASH_STREAM_REGEX = /^([A-z0-9]+)-([A-z0-9]+)-([A-z0-9]+)(-recorded)?$/;
|
|
|
|
const TOKEN = '_';
|
|
|
|
|
2019-11-27 04:31:41 +08:00
|
|
|
const isValidStream = stream => !FLASH_STREAM_REGEX.test(stream);
|
2019-11-23 05:08:27 +08:00
|
|
|
const getDeviceId = (stream) => {
|
|
|
|
const splitStream = stream.split(TOKEN);
|
|
|
|
if (splitStream.length === 3) return splitStream[2];
|
|
|
|
Logger.warn(`Could not get deviceId from stream=${stream}`);
|
|
|
|
return stream;
|
|
|
|
};
|
|
|
|
|
2019-11-27 04:31:41 +08:00
|
|
|
const getUserName = (userId) => {
|
|
|
|
const user = Users.findOne(
|
|
|
|
{ userId },
|
|
|
|
{ fields: { name: 1 } },
|
|
|
|
);
|
|
|
|
if (user) return user.name;
|
|
|
|
return userId;
|
|
|
|
};
|
|
|
|
|
2019-11-23 05:08:27 +08:00
|
|
|
export {
|
|
|
|
isValidStream,
|
|
|
|
getDeviceId,
|
2019-11-27 04:31:41 +08:00
|
|
|
getUserName,
|
2019-11-23 05:08:27 +08:00
|
|
|
};
|