2018-11-30 01:24:02 +08:00
|
|
|
import Meetings from '/imports/api/meetings';
|
2020-02-27 05:55:56 +08:00
|
|
|
import Users from '/imports/api/users';
|
2018-11-30 01:24:02 +08:00
|
|
|
import Auth from '/imports/ui/services/auth';
|
2020-02-27 05:55:56 +08:00
|
|
|
import Logger from '/imports/startup/client/logger';
|
|
|
|
|
2019-10-23 04:15:53 +08:00
|
|
|
import { getStreamer } from '/imports/api/external-videos';
|
2018-11-30 01:24:02 +08:00
|
|
|
import { makeCall } from '/imports/ui/services/api';
|
|
|
|
|
2019-07-16 04:12:07 +08:00
|
|
|
import ReactPlayer from 'react-player';
|
2018-11-30 01:24:02 +08:00
|
|
|
|
2019-07-16 04:12:07 +08:00
|
|
|
const isUrlValid = url => ReactPlayer.canPlay(url);
|
2019-01-16 04:44:41 +08:00
|
|
|
|
|
|
|
const startWatching = (url) => {
|
2019-07-13 04:08:55 +08:00
|
|
|
const externalVideoUrl = url;
|
2019-01-16 04:44:41 +08:00
|
|
|
makeCall('startWatchingExternalVideo', { externalVideoUrl });
|
|
|
|
};
|
|
|
|
|
|
|
|
const stopWatching = () => {
|
|
|
|
makeCall('stopWatchingExternalVideo');
|
|
|
|
};
|
2018-11-30 01:24:02 +08:00
|
|
|
|
|
|
|
const sendMessage = (event, data) => {
|
2020-02-27 05:55:56 +08:00
|
|
|
const {
|
|
|
|
time,
|
|
|
|
rate,
|
|
|
|
state,
|
|
|
|
timestamp,
|
|
|
|
} = data;
|
|
|
|
|
|
|
|
const meetingId = Auth.meetingID;
|
|
|
|
const userId = Auth.userID;
|
|
|
|
|
|
|
|
const user = Users.findOne({ userId });
|
|
|
|
const suc = user && user.presenter;
|
2019-10-23 04:15:53 +08:00
|
|
|
|
2020-02-27 05:55:56 +08:00
|
|
|
if (!suc) {
|
|
|
|
Logger.warn("Message rejected");
|
|
|
|
} else {
|
|
|
|
const streamer = getStreamer(meetingId);
|
|
|
|
streamer.emit(event, { ...data, meetingId, userId});
|
|
|
|
}
|
2018-11-30 01:24:02 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const onMessage = (message, func) => {
|
2019-10-23 04:15:53 +08:00
|
|
|
const streamer = getStreamer(Auth.meetingID);
|
|
|
|
streamer.on(message, func);
|
2018-11-30 01:24:02 +08:00
|
|
|
};
|
|
|
|
|
2019-09-11 03:35:58 +08:00
|
|
|
const removeAllListeners = (eventType) => {
|
2019-10-23 04:15:53 +08:00
|
|
|
const streamer = getStreamer(Auth.meetingID);
|
|
|
|
streamer.removeAllListeners(eventType);
|
2019-09-11 03:35:58 +08:00
|
|
|
};
|
|
|
|
|
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 } });
|
2018-11-30 01:24:02 +08:00
|
|
|
|
|
|
|
return meeting && meeting.externalVideoUrl;
|
2019-01-16 04:44:41 +08:00
|
|
|
};
|
2018-11-30 01:24:02 +08:00
|
|
|
|
|
|
|
export {
|
|
|
|
sendMessage,
|
|
|
|
onMessage,
|
2019-09-11 03:35:58 +08:00
|
|
|
removeAllListeners,
|
2019-07-13 04:08:55 +08:00
|
|
|
getVideoUrl,
|
2019-01-16 04:44:41 +08:00
|
|
|
isUrlValid,
|
2018-11-30 01:24:02 +08:00
|
|
|
startWatching,
|
|
|
|
stopWatching,
|
|
|
|
};
|