bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/external-video-player/service.js

70 lines
1.6 KiB
JavaScript
Raw Normal View History

import Meetings from '/imports/api/meetings';
import Users from '/imports/api/users';
import Auth from '/imports/ui/services/auth';
import Logger from '/imports/startup/client/logger';
import { getStreamer } from '/imports/api/external-videos';
import { makeCall } from '/imports/ui/services/api';
import ReactPlayer from 'react-player';
const isUrlValid = url => ReactPlayer.canPlay(url);
const startWatching = (url) => {
2019-07-13 04:08:55 +08:00
const externalVideoUrl = url;
makeCall('startWatchingExternalVideo', { externalVideoUrl });
};
const stopWatching = () => {
makeCall('stopWatchingExternalVideo');
};
const sendMessage = (event, data) => {
const {
time,
rate,
state,
timestamp,
} = data;
const meetingId = Auth.meetingID;
const userId = Auth.userID;
const user = Users.findOne({ userId });
const suc = user && user.presenter;
if (!suc) {
Logger.warn("Message rejected");
} else {
const streamer = getStreamer(meetingId);
streamer.emit(event, { ...data, meetingId, userId});
}
};
const onMessage = (message, func) => {
const streamer = getStreamer(Auth.meetingID);
streamer.on(message, func);
};
const removeAllListeners = (eventType) => {
const streamer = getStreamer(Auth.meetingID);
streamer.removeAllListeners(eventType);
};
2019-07-13 04:08:55 +08:00
const getVideoUrl = () => {
2019-01-21 13:49:01 +08:00
const meetingId = Auth.meetingID;
2019-09-11 02:04:42 +08:00
const meeting = Meetings.findOne({ meetingId }, { fields: { externalVideoUrl: 1 } });
return meeting && meeting.externalVideoUrl;
};
export {
sendMessage,
onMessage,
removeAllListeners,
2019-07-13 04:08:55 +08:00
getVideoUrl,
isUrlValid,
startWatching,
stopWatching,
};