2017-06-04 10:40:14 +08:00
|
|
|
import React, { Component } from 'react';
|
2018-02-19 12:23:05 +08:00
|
|
|
import { styles } from '../styles';
|
2018-01-06 03:43:53 +08:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2017-11-18 02:55:59 +08:00
|
|
|
import { log } from '/imports/ui/services/api';
|
2018-01-06 01:13:22 +08:00
|
|
|
import { notify } from '/imports/ui/services/notification';
|
2018-01-11 09:15:44 +08:00
|
|
|
import { toast } from 'react-toastify';
|
2018-02-08 03:20:10 +08:00
|
|
|
import { styles as mediaStyles } from '/imports/ui/components/media/styles';
|
2018-01-11 09:15:44 +08:00
|
|
|
import Toast from '/imports/ui/components/toast/component';
|
2018-02-14 03:45:03 +08:00
|
|
|
import _ from 'lodash';
|
2016-05-04 04:40:46 +08:00
|
|
|
|
2018-02-19 12:23:05 +08:00
|
|
|
import VideoElement from '../video-element/component';
|
2018-02-15 02:34:00 +08:00
|
|
|
|
2018-02-19 11:43:30 +08:00
|
|
|
const INITIAL_SHARE_WAIT_TIME = 2000;
|
|
|
|
|
2018-01-06 03:43:53 +08:00
|
|
|
const intlMessages = defineMessages({
|
2018-02-19 11:43:30 +08:00
|
|
|
chromeExtensionError: {
|
|
|
|
id: 'app.video.chromeExtensionError',
|
|
|
|
description: 'Error message for Chrome Extension not installed',
|
2018-01-06 03:43:53 +08:00
|
|
|
},
|
2018-02-19 11:43:30 +08:00
|
|
|
chromeExtensionErrorLink: {
|
|
|
|
id: 'app.video.chromeExtensionErrorLink',
|
|
|
|
description: 'Error message for Chrome Extension not installed',
|
2018-01-06 03:43:53 +08:00
|
|
|
},
|
|
|
|
});
|
2016-05-04 04:40:46 +08:00
|
|
|
|
2018-01-06 03:43:53 +08:00
|
|
|
class VideoDock extends Component {
|
2017-09-01 23:26:57 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
2018-03-20 01:52:39 +08:00
|
|
|
this.state = {};
|
2017-12-02 07:40:25 +08:00
|
|
|
}
|
|
|
|
|
2017-09-01 23:26:57 +08:00
|
|
|
componentDidMount() {
|
2018-01-13 02:39:16 +08:00
|
|
|
const { users, userId } = this.props;
|
2017-12-20 01:02:54 +08:00
|
|
|
|
2018-02-19 11:43:30 +08:00
|
|
|
document.addEventListener('installChromeExtension', this.installChromeExtension.bind(this));
|
2017-09-20 11:12:10 +08:00
|
|
|
|
2017-12-09 00:35:46 +08:00
|
|
|
window.addEventListener('resize', this.adjustVideos);
|
2018-02-07 22:44:11 +08:00
|
|
|
window.addEventListener('orientationchange', this.adjustVideos);
|
2018-01-29 19:52:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
2017-12-09 00:35:46 +08:00
|
|
|
window.removeEventListener('resize', this.adjustVideos);
|
2018-02-09 00:32:12 +08:00
|
|
|
window.removeEventListener('orientationchange', this.adjustVideos);
|
2018-02-19 11:43:30 +08:00
|
|
|
document.removeEventListener('installChromeExtension', this.installChromeExtension.bind(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate() {
|
|
|
|
this.adjustVideos();
|
2017-12-09 00:35:46 +08:00
|
|
|
}
|
2017-09-01 23:26:57 +08:00
|
|
|
|
2018-02-19 11:43:30 +08:00
|
|
|
notifyError(message) {
|
|
|
|
notify(message, 'error', 'video');
|
|
|
|
}
|
|
|
|
|
|
|
|
installChromeExtension() {
|
|
|
|
console.log(intlMessages);
|
|
|
|
const { intl } = this.props;
|
|
|
|
const CHROME_EXTENSION_LINK = Meteor.settings.public.kurento.chromeExtensionLink;
|
|
|
|
|
|
|
|
this.notifyError(<div>
|
|
|
|
{intl.formatMessage(intlMessages.chromeExtensionError)}{' '}
|
|
|
|
<a href={CHROME_EXTENSION_LINK} target="_blank">
|
|
|
|
{intl.formatMessage(intlMessages.chromeExtensionErrorLink)}
|
|
|
|
</a>
|
|
|
|
</div>);
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
// Find a better place to put this piece of code
|
2018-01-29 19:52:07 +08:00
|
|
|
adjustVideos() {
|
2018-01-11 04:57:20 +08:00
|
|
|
setTimeout(() => {
|
2018-02-14 00:20:59 +08:00
|
|
|
window.adjustVideos('webcamArea', true, mediaStyles.moreThan4Videos, mediaStyles.container, mediaStyles.overlayWrapper, 'presentationAreaData', 'screenshareVideo');
|
2018-01-11 04:57:20 +08:00
|
|
|
}, 0);
|
2017-12-09 00:35:46 +08:00
|
|
|
}
|
2017-09-01 23:26:57 +08:00
|
|
|
|
2018-03-22 03:25:32 +08:00
|
|
|
getUsersWithActiveStreams() {
|
|
|
|
const { userId, sharedWebcam } = this.props;
|
|
|
|
const activeFilter = (user) => {
|
|
|
|
return user.has_stream || (sharedWebcam && user.userId == userId);
|
|
|
|
};
|
|
|
|
|
|
|
|
return this.props.users.filter(activeFilter);
|
|
|
|
}
|
|
|
|
|
2016-05-04 04:40:46 +08:00
|
|
|
render() {
|
2018-03-20 01:52:39 +08:00
|
|
|
if (!this.props.socketOpen) {
|
|
|
|
// TODO: return something when disconnected
|
2018-03-22 02:33:53 +08:00
|
|
|
return null;
|
2018-03-20 01:52:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const id = this.props.userId;
|
|
|
|
const sharedWebcam = this.props.sharedWebcam;
|
|
|
|
|
2016-05-04 04:40:46 +08:00
|
|
|
return (
|
2018-03-12 23:29:51 +08:00
|
|
|
<div className={styles.videoDock} id={this.props.sharedWebcam.toString()}>
|
2018-02-06 03:52:07 +08:00
|
|
|
<div id="webcamArea" className={styles.webcamArea}>
|
2018-03-22 03:25:32 +08:00
|
|
|
{this.getUsersWithActiveStreams().map(user => (
|
2018-02-17 03:18:53 +08:00
|
|
|
<VideoElement
|
2018-03-20 01:52:39 +08:00
|
|
|
shared={id === user.userId && sharedWebcam}
|
|
|
|
videoId={user.userId}
|
|
|
|
key={user.userId}
|
|
|
|
name={user.name}
|
|
|
|
localCamera={id === user.userId}
|
|
|
|
onShareWebcam={this.props.onShareWebcam.bind(this)}
|
|
|
|
onMount={this.props.onStart.bind(this)}
|
|
|
|
onUnmount={this.props.onStop.bind(this)}
|
|
|
|
/>
|
2018-02-17 03:18:53 +08:00
|
|
|
))}
|
2017-12-20 00:29:09 +08:00
|
|
|
</div>
|
2016-05-04 04:40:46 +08:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2018-01-06 03:43:53 +08:00
|
|
|
|
|
|
|
export default injectIntl(VideoDock);
|