70 lines
1.6 KiB
JavaScript
70 lines
1.6 KiB
JavaScript
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) => {
|
|
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);
|
|
};
|
|
|
|
const getVideoUrl = () => {
|
|
const meetingId = Auth.meetingID;
|
|
const meeting = Meetings.findOne({ meetingId }, { fields: { externalVideoUrl: 1 } });
|
|
|
|
return meeting && meeting.externalVideoUrl;
|
|
};
|
|
|
|
export {
|
|
sendMessage,
|
|
onMessage,
|
|
removeAllListeners,
|
|
getVideoUrl,
|
|
isUrlValid,
|
|
startWatching,
|
|
stopWatching,
|
|
};
|