2019-10-23 05:18:54 +08:00
|
|
|
import { Meteor } from 'meteor/meteor';
|
|
|
|
import { check } from 'meteor/check';
|
|
|
|
import Users from '/imports/api/users';
|
|
|
|
import Logger from '/imports/startup/server/logger';
|
|
|
|
|
2020-01-14 06:20:17 +08:00
|
|
|
const allowFromPresenter = (eventName, message) => {
|
|
|
|
const {
|
|
|
|
userId,
|
|
|
|
time,
|
|
|
|
rate,
|
|
|
|
state,
|
|
|
|
} = message;
|
|
|
|
|
2019-10-23 05:18:54 +08:00
|
|
|
const user = Users.findOne({ userId });
|
|
|
|
const ret = user && user.presenter;
|
|
|
|
|
2020-01-18 01:12:44 +08:00
|
|
|
Logger.info(`ExternalVideo Streamer auth userid: ${userId}, meetingId: ${user.meetingId}, event: ${eventName}, suc: ${ret}, time: ${time}, rate: ${rate}, state: ${state}`);
|
2019-10-23 05:18:54 +08:00
|
|
|
|
2019-10-24 04:29:06 +08:00
|
|
|
return ret;
|
2019-10-23 05:18:54 +08:00
|
|
|
};
|
|
|
|
|
2019-10-24 04:29:06 +08:00
|
|
|
export default function initializeExternalVideo(credentials) {
|
2019-10-23 05:18:54 +08:00
|
|
|
const { meetingId } = credentials;
|
|
|
|
|
|
|
|
check(meetingId, String);
|
|
|
|
|
2019-10-24 03:20:52 +08:00
|
|
|
const streamName = `external-videos-${meetingId}`;
|
|
|
|
if (!Meteor.StreamerCentral.instances[streamName]) {
|
2019-10-24 03:24:34 +08:00
|
|
|
const streamer = new Meteor.Streamer(streamName);
|
2019-10-24 03:20:52 +08:00
|
|
|
streamer.allowRead('all');
|
|
|
|
streamer.allowWrite('all');
|
|
|
|
streamer.allowEmit(allowFromPresenter);
|
|
|
|
} else {
|
2020-01-14 06:20:17 +08:00
|
|
|
Logger.debug(`External Video streamer is already created for ${streamName}`);
|
2019-10-24 03:20:52 +08:00
|
|
|
}
|
2019-10-24 03:24:34 +08:00
|
|
|
}
|