2018-11-30 01:24:02 +08:00
|
|
|
import Meetings from '/imports/api/meetings';
|
|
|
|
import Auth from '/imports/ui/services/auth';
|
|
|
|
import ExternalVideoStreamer from '/imports/api/external-videos';
|
|
|
|
|
|
|
|
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) => {
|
2019-01-16 04:44:41 +08:00
|
|
|
ExternalVideoStreamer.emit(event, {
|
|
|
|
...data,
|
2019-01-21 13:49:01 +08:00
|
|
|
meetingId: Auth.meetingID,
|
|
|
|
userId: Auth.userID,
|
2019-01-16 04:44:41 +08:00
|
|
|
});
|
2018-11-30 01:24:02 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const onMessage = (message, func) => {
|
|
|
|
ExternalVideoStreamer.on(message, func);
|
|
|
|
};
|
|
|
|
|
2019-09-11 03:35:58 +08:00
|
|
|
const removeAllListeners = (eventType) => {
|
|
|
|
ExternalVideoStreamer.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 } });
|
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,
|
|
|
|
};
|