2018-02-17 03:18:53 +08:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import { styles } from './styles';
|
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
|
|
|
import { log } from '/imports/ui/services/api';
|
|
|
|
import { notify } from '/imports/ui/services/notification';
|
|
|
|
import { toast } from 'react-toastify';
|
2018-05-03 01:53:53 +08:00
|
|
|
import VisibilityEvent from '/imports/utils/visibilityEvent';
|
2018-02-17 03:18:53 +08:00
|
|
|
import Toast from '/imports/ui/components/toast/component';
|
|
|
|
import _ from 'lodash';
|
|
|
|
|
2018-02-19 12:23:05 +08:00
|
|
|
import VideoService from './service';
|
2018-04-12 02:50:14 +08:00
|
|
|
import VideoList from './video-list/component';
|
2018-02-17 03:18:53 +08:00
|
|
|
|
|
|
|
const intlMessages = defineMessages({
|
|
|
|
iceCandidateError: {
|
|
|
|
id: 'app.video.iceCandidateError',
|
|
|
|
description: 'Error message for ice candidate fail',
|
|
|
|
},
|
|
|
|
sharingError: {
|
|
|
|
id: 'app.video.sharingError',
|
|
|
|
description: 'Error on sharing webcam',
|
|
|
|
},
|
|
|
|
chromeExtensionError: {
|
|
|
|
id: 'app.video.chromeExtensionError',
|
|
|
|
description: 'Error message for Chrome Extension not installed',
|
|
|
|
},
|
|
|
|
chromeExtensionErrorLink: {
|
|
|
|
id: 'app.video.chromeExtensionErrorLink',
|
|
|
|
description: 'Error message for Chrome Extension not installed',
|
2018-03-20 01:52:39 +08:00
|
|
|
},
|
2018-05-17 02:15:46 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
const intlMediaErrorsMessages = defineMessages({
|
|
|
|
permissionError: {
|
|
|
|
id: 'app.video.permissionError',
|
|
|
|
description: 'Error message for webcam permission',
|
|
|
|
},
|
2018-05-17 00:53:06 +08:00
|
|
|
NotFoundError: {
|
|
|
|
id: 'app.video.notFoundError',
|
|
|
|
description: 'error message when can not get webcam video',
|
|
|
|
},
|
|
|
|
NotAllowedError: {
|
|
|
|
id: 'app.video.notAllowed',
|
|
|
|
description: 'error message when webcam had permission denied',
|
|
|
|
},
|
|
|
|
NotSupportedError: {
|
|
|
|
id: 'app.video.notSupportedError',
|
|
|
|
description: 'error message when origin do not have ssl valid',
|
|
|
|
},
|
2018-05-17 02:15:46 +08:00
|
|
|
NotReadableError: {
|
|
|
|
id: 'app.video.notReadableError',
|
|
|
|
description: 'error message when origin do not have ssl valid',
|
|
|
|
},
|
2018-02-17 03:18:53 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
const CAMERA_SHARE_FAILED_WAIT_TIME = 10000;
|
2018-05-03 21:57:03 +08:00
|
|
|
const PING_INTERVAL = 15000;
|
2018-02-17 03:18:53 +08:00
|
|
|
|
|
|
|
class VideoProvider extends Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
2018-03-12 23:29:51 +08:00
|
|
|
sharedWebcam: false,
|
2018-03-20 01:52:39 +08:00
|
|
|
socketOpen: false,
|
2018-02-17 03:18:53 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// Set a valid bbb-webrtc-sfu application server socket in the settings
|
|
|
|
this.ws = new ReconnectingWebSocket(Meteor.settings.public.kurento.wsUrl);
|
|
|
|
this.wsQueue = [];
|
|
|
|
|
2018-05-03 01:53:53 +08:00
|
|
|
this.visibility = new VisibilityEvent();
|
|
|
|
|
2018-02-17 03:18:53 +08:00
|
|
|
this.reconnectWebcam = false;
|
|
|
|
this.cameraTimeouts = {};
|
|
|
|
this.webRtcPeers = {};
|
|
|
|
|
2018-04-14 03:16:06 +08:00
|
|
|
this.openWs = this.ws.open.bind(this.ws);
|
2018-02-17 03:18:53 +08:00
|
|
|
this.onWsOpen = this.onWsOpen.bind(this);
|
|
|
|
this.onWsClose = this.onWsClose.bind(this);
|
|
|
|
this.onWsMessage = this.onWsMessage.bind(this);
|
|
|
|
|
|
|
|
this.unshareWebcam = this.unshareWebcam.bind(this);
|
|
|
|
this.shareWebcam = this.shareWebcam.bind(this);
|
2018-05-03 01:53:53 +08:00
|
|
|
|
|
|
|
this.pauseViewers = this.pauseViewers.bind(this);
|
|
|
|
this.unpauseViewers = this.unpauseViewers.bind(this);
|
|
|
|
}
|
|
|
|
|
2018-05-05 04:58:35 +08:00
|
|
|
_sendPauseStream (id, role, state) {
|
|
|
|
this.sendMessage({
|
|
|
|
cameraId: id,
|
|
|
|
id: 'pause',
|
|
|
|
type: 'video',
|
|
|
|
role,
|
|
|
|
state,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-05-03 01:53:53 +08:00
|
|
|
pauseViewers () {
|
|
|
|
log("debug", "Calling pause in viewer streams");
|
|
|
|
|
2018-05-05 04:58:35 +08:00
|
|
|
|
2018-05-03 01:53:53 +08:00
|
|
|
Object.keys(this.webRtcPeers).forEach((id) => {
|
2018-05-05 04:58:35 +08:00
|
|
|
if (this.props.userId !== id) {
|
|
|
|
this._sendPauseStream(id, 'viewer', true);
|
2018-05-03 01:53:53 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
unpauseViewers () {
|
|
|
|
log("debug", "Calling un-pause in viewer streams");
|
|
|
|
|
|
|
|
Object.keys(this.webRtcPeers).forEach((id) => {
|
2018-05-05 04:58:35 +08:00
|
|
|
if (id !== this.props.userId) {
|
|
|
|
this._sendPauseStream(id, 'viewer', false);
|
2018-05-03 01:53:53 +08:00
|
|
|
}
|
|
|
|
});
|
2018-02-17 03:18:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillMount() {
|
|
|
|
this.ws.addEventListener('open', this.onWsOpen);
|
|
|
|
this.ws.addEventListener('close', this.onWsClose);
|
|
|
|
|
2018-04-14 03:16:06 +08:00
|
|
|
window.addEventListener('online', this.openWs);
|
2018-02-17 03:18:53 +08:00
|
|
|
window.addEventListener('offline', this.onWsClose);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
2018-04-14 03:16:06 +08:00
|
|
|
document.addEventListener('joinVideo', this.shareWebcam); // TODO find a better way to do this
|
|
|
|
document.addEventListener('exitVideo', this.unshareWebcam);
|
2018-02-17 03:18:53 +08:00
|
|
|
this.ws.addEventListener('message', this.onWsMessage);
|
2018-05-03 01:53:53 +08:00
|
|
|
|
|
|
|
this.visibility.onVisible(this.unpauseViewers);
|
|
|
|
this.visibility.onHidden(this.pauseViewers);
|
2018-02-17 03:18:53 +08:00
|
|
|
}
|
|
|
|
|
2018-04-12 02:50:14 +08:00
|
|
|
componentWillUpdate({ users, userId }) {
|
|
|
|
const usersSharingIds = users.map(u => u.id);
|
|
|
|
const usersConnected = Object.keys(this.webRtcPeers);
|
|
|
|
|
|
|
|
const usersToConnect = usersSharingIds.filter(id => !usersConnected.includes(id));
|
|
|
|
const usersToDisconnect = usersConnected.filter(id => !usersSharingIds.includes(id));
|
|
|
|
|
|
|
|
usersToConnect.forEach(id => this.createWebRTCPeer(id, userId === id));
|
2018-04-19 02:16:26 +08:00
|
|
|
usersToDisconnect.forEach(id => this.stopWebRTCPeer(id));
|
2018-04-12 02:50:14 +08:00
|
|
|
|
|
|
|
console.warn('[usersToConnect]', usersToConnect);
|
|
|
|
console.warn('[usersToDisconnect]', usersToDisconnect);
|
|
|
|
}
|
|
|
|
|
2018-02-17 03:18:53 +08:00
|
|
|
componentWillUnmount() {
|
|
|
|
document.removeEventListener('joinVideo', this.shareWebcam);
|
|
|
|
document.removeEventListener('exitVideo', this.unshareWebcam);
|
|
|
|
|
|
|
|
this.ws.removeEventListener('message', this.onWsMessage);
|
|
|
|
this.ws.removeEventListener('open', this.onWsOpen);
|
|
|
|
this.ws.removeEventListener('close', this.onWsClose);
|
|
|
|
|
2018-04-14 03:16:06 +08:00
|
|
|
window.removeEventListener('online', this.openWs);
|
2018-02-17 03:18:53 +08:00
|
|
|
window.removeEventListener('offline', this.onWsClose);
|
|
|
|
|
2018-05-03 01:53:53 +08:00
|
|
|
this.visibility.removeEventListeners();
|
|
|
|
|
2018-02-17 03:18:53 +08:00
|
|
|
// Unshare user webcam
|
|
|
|
if (this.state.sharedWebcam) {
|
|
|
|
this.unshareWebcam();
|
|
|
|
}
|
|
|
|
|
|
|
|
Object.keys(this.webRtcPeers).forEach((id) => {
|
2018-04-19 02:16:26 +08:00
|
|
|
this.stopWebRTCPeer(id);
|
2018-02-17 03:18:53 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
// Close websocket connection to prevent multiple reconnects from happening
|
2018-04-14 03:16:06 +08:00
|
|
|
// Don't disonnect socket on unmount to prevent multiple reconnects
|
2018-04-26 23:39:24 +08:00
|
|
|
this.ws.close();
|
2018-02-17 03:18:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
onWsOpen() {
|
|
|
|
log('debug', '------ Websocket connection opened.');
|
|
|
|
|
|
|
|
// -- Resend queued messages that happened when socket was not connected
|
|
|
|
while (this.wsQueue.length > 0) {
|
|
|
|
this.sendMessage(this.wsQueue.pop());
|
|
|
|
}
|
|
|
|
|
2018-05-03 21:57:03 +08:00
|
|
|
this.pingInterval = setInterval(this.ping.bind(this), PING_INTERVAL);
|
|
|
|
|
2018-03-20 01:52:39 +08:00
|
|
|
this.setState({ socketOpen: true });
|
2018-02-17 03:18:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
onWsClose(error) {
|
|
|
|
log('debug', '------ Websocket connection closed.');
|
|
|
|
|
2018-04-19 02:16:26 +08:00
|
|
|
this.stopWebRTCPeer(this.props.userId);
|
2018-05-03 21:57:03 +08:00
|
|
|
clearInterval(this.pingInterval);
|
2018-03-20 01:52:39 +08:00
|
|
|
|
|
|
|
this.setState({ socketOpen: false });
|
2018-02-17 03:18:53 +08:00
|
|
|
}
|
|
|
|
|
2018-05-03 21:57:03 +08:00
|
|
|
ping() {
|
|
|
|
const message = {
|
|
|
|
id: 'ping'
|
|
|
|
};
|
|
|
|
this.sendMessage(message);
|
|
|
|
}
|
|
|
|
|
2018-02-17 03:18:53 +08:00
|
|
|
disconnected(id) {
|
|
|
|
this.reconnectList.push(id);
|
2018-03-20 01:52:39 +08:00
|
|
|
|
2018-02-17 03:18:53 +08:00
|
|
|
log('debug', ` [camera] ${id} disconnected, will try re-subscribe later.`);
|
|
|
|
}
|
|
|
|
|
|
|
|
onWsMessage(msg) {
|
|
|
|
const { intl } = this.props;
|
|
|
|
const parsedMessage = JSON.parse(msg.data);
|
|
|
|
|
|
|
|
console.log('Received message new ws message: ');
|
|
|
|
console.log(parsedMessage);
|
|
|
|
|
|
|
|
switch (parsedMessage.id) {
|
|
|
|
case 'startResponse':
|
|
|
|
this.startResponse(parsedMessage);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'playStart':
|
|
|
|
this.handlePlayStart(parsedMessage);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'playStop':
|
|
|
|
this.handlePlayStop(parsedMessage);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'iceCandidate':
|
|
|
|
this.handleIceCandidate(parsedMessage);
|
|
|
|
break;
|
|
|
|
|
2018-05-03 21:57:03 +08:00
|
|
|
case 'pong':
|
|
|
|
console.debug("Received pong from server");
|
|
|
|
break;
|
|
|
|
|
2018-02-17 03:18:53 +08:00
|
|
|
case 'error':
|
|
|
|
default:
|
|
|
|
this.handleError(parsedMessage);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sendMessage(message) {
|
|
|
|
const ws = this.ws;
|
|
|
|
|
|
|
|
if (this.connectedToMediaServer()) {
|
|
|
|
const jsonMessage = JSON.stringify(message);
|
|
|
|
console.log(`Sending message: ${jsonMessage}`);
|
|
|
|
ws.send(jsonMessage, (error) => {
|
|
|
|
if (error) {
|
|
|
|
console.error(`client: Websocket error "${error}" on message "${jsonMessage.id}"`);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// No need to queue video stop messages
|
|
|
|
if (message.id != 'stop') {
|
|
|
|
this.wsQueue.push(message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
connectedToMediaServer() {
|
|
|
|
return this.ws.readyState === WebSocket.OPEN;
|
|
|
|
}
|
|
|
|
|
|
|
|
startResponse(message) {
|
|
|
|
const id = message.cameraId;
|
|
|
|
const webRtcPeer = this.webRtcPeers[id];
|
|
|
|
|
|
|
|
if (message.sdpAnswer == null || webRtcPeer == null) {
|
|
|
|
return log('debug', 'Null sdp answer or null webrtcpeer');
|
|
|
|
}
|
|
|
|
|
|
|
|
log('info', 'SDP answer received from server. Processing ...');
|
|
|
|
|
|
|
|
webRtcPeer.processAnswer(message.sdpAnswer, (error) => {
|
|
|
|
if (error) {
|
|
|
|
return log('error', error);
|
|
|
|
}
|
|
|
|
|
2018-02-17 05:11:59 +08:00
|
|
|
if (message.cameraId == this.props.userId) {
|
2018-02-17 03:18:53 +08:00
|
|
|
log('info', 'camera id sendusershare ', id);
|
|
|
|
VideoService.sendUserShareWebcam(id);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
handleIceCandidate(message) {
|
2018-03-12 23:29:51 +08:00
|
|
|
const { intl } = this.props;
|
2018-02-17 03:18:53 +08:00
|
|
|
const webRtcPeer = this.webRtcPeers[message.cameraId];
|
|
|
|
|
|
|
|
if (webRtcPeer) {
|
|
|
|
if (webRtcPeer.didSDPAnswered) {
|
|
|
|
webRtcPeer.addIceCandidate(message.candidate, (err) => {
|
|
|
|
if (err) {
|
|
|
|
return log('error', `Error adding candidate: ${err}`);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
webRtcPeer.iceQueue.push(message.candidate);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
log('error', ' [ICE] Message arrived after the peer was already thrown out, discarding it...');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-19 02:16:26 +08:00
|
|
|
stopWebRTCPeer(id) {
|
|
|
|
log('info', 'Stopping webcam', id);
|
2018-04-25 00:18:12 +08:00
|
|
|
const userId = this.props.userId;
|
2018-04-19 02:16:26 +08:00
|
|
|
const shareWebcam = id === userId;
|
2018-02-17 03:18:53 +08:00
|
|
|
|
2018-04-12 02:50:14 +08:00
|
|
|
if (shareWebcam) {
|
|
|
|
this.unshareWebcam();
|
|
|
|
}
|
|
|
|
|
2018-04-14 03:16:06 +08:00
|
|
|
this.sendMessage({
|
|
|
|
type: 'video',
|
2018-04-19 02:16:26 +08:00
|
|
|
role: shareWebcam ? 'share' : 'viewer',
|
2018-04-14 03:16:06 +08:00
|
|
|
id: 'stop',
|
|
|
|
cameraId: id,
|
|
|
|
});
|
|
|
|
|
2018-02-17 03:18:53 +08:00
|
|
|
// Clear the shared camera fail timeout when destroying
|
|
|
|
clearTimeout(this.cameraTimeouts[id]);
|
2018-04-19 02:16:26 +08:00
|
|
|
delete this.cameraTimeouts[id];
|
|
|
|
this.destroyWebRTCPeer(id);
|
|
|
|
}
|
2018-02-17 03:18:53 +08:00
|
|
|
|
2018-04-19 02:16:26 +08:00
|
|
|
destroyWebRTCPeer(id) {
|
|
|
|
const webRtcPeer = this.webRtcPeers[id];
|
2018-02-17 03:18:53 +08:00
|
|
|
if (webRtcPeer) {
|
|
|
|
log('info', 'Stopping WebRTC peer');
|
|
|
|
webRtcPeer.dispose();
|
|
|
|
delete this.webRtcPeers[id];
|
|
|
|
} else {
|
|
|
|
log('info', 'No WebRTC peer to stop (not an error)');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-12 02:50:14 +08:00
|
|
|
createWebRTCPeer(id, shareWebcam) {
|
2018-02-17 03:18:53 +08:00
|
|
|
const that = this;
|
2018-03-20 01:52:39 +08:00
|
|
|
const { intl, meetingId } = this.props;
|
2018-02-17 03:18:53 +08:00
|
|
|
|
2018-04-09 22:39:27 +08:00
|
|
|
const videoConstraints = {
|
|
|
|
width: {
|
|
|
|
min: 320,
|
|
|
|
max: 640,
|
|
|
|
},
|
|
|
|
height: {
|
|
|
|
min: 180,
|
2018-04-18 01:58:15 +08:00
|
|
|
max: 480,
|
2018-04-09 22:39:27 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!navigator.userAgent.match(/Version\/[\d\.]+.*Safari/)) {
|
|
|
|
videoConstraints.frameRate = { min: 5, ideal: 10 };
|
|
|
|
}
|
|
|
|
|
2018-03-20 01:52:39 +08:00
|
|
|
const options = {
|
2018-02-17 05:11:59 +08:00
|
|
|
mediaConstraints: {
|
|
|
|
audio: false,
|
2018-04-09 22:39:27 +08:00
|
|
|
video: videoConstraints,
|
2018-02-17 05:11:59 +08:00
|
|
|
},
|
|
|
|
onicecandidate: this.getOnIceCandidateCallback(id, shareWebcam),
|
|
|
|
};
|
|
|
|
|
2018-04-12 02:50:14 +08:00
|
|
|
let WebRtcPeerObj = window.kurentoUtils.WebRtcPeer.WebRtcPeerRecvonly;
|
|
|
|
|
2018-02-17 05:11:59 +08:00
|
|
|
if (shareWebcam) {
|
2018-04-12 02:50:14 +08:00
|
|
|
WebRtcPeerObj = window.kurentoUtils.WebRtcPeer.WebRtcPeerSendonly;
|
2018-04-09 22:39:27 +08:00
|
|
|
this.shareWebcam();
|
2018-02-17 05:11:59 +08:00
|
|
|
}
|
|
|
|
|
2018-04-14 03:16:06 +08:00
|
|
|
WebRtcPeerObj.started = false;
|
|
|
|
|
2018-04-12 02:50:14 +08:00
|
|
|
that.webRtcPeers[id] = new WebRtcPeerObj(options, function (error) {
|
2018-02-17 03:18:53 +08:00
|
|
|
if (error) {
|
|
|
|
log('error', ' WebRTC peerObj create error');
|
|
|
|
log('error', error);
|
2018-05-17 02:15:46 +08:00
|
|
|
const errorMessage = intlMediaErrorsMessages[error.name]
|
|
|
|
|| intlMediaErrorsMessages.permissionError;
|
2018-05-17 00:53:06 +08:00
|
|
|
that.notifyError(intl.formatMessage(errorMessage));
|
2018-02-17 03:18:53 +08:00
|
|
|
/* This notification error is displayed considering kurento-utils
|
|
|
|
* returned the error 'The request is not allowed by the user agent
|
|
|
|
* or the platform in the current context.', but there are other
|
|
|
|
* errors that could be returned. */
|
|
|
|
|
2018-04-19 02:16:26 +08:00
|
|
|
that.stopWebRTCPeer(id);
|
2018-03-20 01:52:39 +08:00
|
|
|
|
|
|
|
if (shareWebcam) {
|
2018-04-04 05:22:15 +08:00
|
|
|
that.unshareWebcam();
|
2018-03-20 01:52:39 +08:00
|
|
|
}
|
2018-02-17 03:18:53 +08:00
|
|
|
return log('error', error);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.didSDPAnswered = false;
|
|
|
|
this.iceQueue = [];
|
|
|
|
|
|
|
|
this.generateOffer((error, offerSdp) => {
|
|
|
|
if (error) {
|
|
|
|
log('error', ' WebRtc generate offer error');
|
|
|
|
|
2018-04-19 02:16:26 +08:00
|
|
|
that.stopWebRTCPeer(id);
|
2018-02-17 03:18:53 +08:00
|
|
|
return log('error', error);
|
|
|
|
}
|
|
|
|
|
2018-04-05 00:15:20 +08:00
|
|
|
that.cameraTimeouts[id] = setTimeout(() => {
|
2018-04-13 21:06:11 +08:00
|
|
|
log('error', `Camera share has not suceeded in ${CAMERA_SHARE_FAILED_WAIT_TIME} for ${id}`);
|
2018-04-05 00:15:20 +08:00
|
|
|
if (that.props.userId == id) {
|
|
|
|
that.notifyError(intl.formatMessage(intlMessages.sharingError));
|
|
|
|
that.unshareWebcam();
|
2018-04-12 02:50:14 +08:00
|
|
|
that.destroyWebRTCPeer(id);
|
2018-04-19 02:16:26 +08:00
|
|
|
} else {
|
|
|
|
that.stopWebRTCPeer(id);
|
2018-04-12 02:50:14 +08:00
|
|
|
that.createWebRTCPeer(id, shareWebcam);
|
2018-04-05 00:15:20 +08:00
|
|
|
}
|
|
|
|
}, CAMERA_SHARE_FAILED_WAIT_TIME);
|
|
|
|
|
2018-02-17 03:18:53 +08:00
|
|
|
console.log(`Invoking SDP offer callback function ${location.host}`);
|
|
|
|
const message = {
|
|
|
|
type: 'video',
|
|
|
|
role: shareWebcam ? 'share' : 'viewer',
|
|
|
|
id: 'start',
|
|
|
|
sdpOffer: offerSdp,
|
|
|
|
cameraId: id,
|
2018-03-20 01:52:39 +08:00
|
|
|
meetingId,
|
2018-02-17 03:18:53 +08:00
|
|
|
};
|
|
|
|
that.sendMessage(message);
|
|
|
|
});
|
|
|
|
while (this.iceQueue.length) {
|
|
|
|
const candidate = this.iceQueue.shift();
|
|
|
|
this.addIceCandidate(candidate, (err) => {
|
|
|
|
if (err) {
|
|
|
|
this.notifyError(intl.formatMessage(intlMessages.iceCandidateError));
|
|
|
|
return console.error(`Error adding candidate: ${err}`);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
this.didSDPAnswered = true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-03-20 01:52:39 +08:00
|
|
|
getOnIceCandidateCallback(id, shareWebcam) {
|
|
|
|
const that = this;
|
2018-02-17 03:18:53 +08:00
|
|
|
|
|
|
|
return function (candidate) {
|
|
|
|
const message = {
|
|
|
|
type: 'video',
|
|
|
|
role: shareWebcam ? 'share' : 'viewer',
|
|
|
|
id: 'onIceCandidate',
|
|
|
|
candidate,
|
|
|
|
cameraId: id,
|
|
|
|
};
|
|
|
|
that.sendMessage(message);
|
2018-03-20 01:52:39 +08:00
|
|
|
};
|
|
|
|
}
|
2018-02-17 03:18:53 +08:00
|
|
|
|
2018-04-12 02:50:14 +08:00
|
|
|
attachVideoStream(id, video) {
|
|
|
|
if (video.srcObject) return; // Skip if the stream is already attached
|
2018-02-17 03:18:53 +08:00
|
|
|
|
2018-04-12 02:50:14 +08:00
|
|
|
const isCurrent = id === this.props.userId;
|
|
|
|
const peer = this.webRtcPeers[id];
|
|
|
|
const { peerConnection } = peer;
|
2018-03-20 01:52:39 +08:00
|
|
|
|
2018-04-12 02:50:14 +08:00
|
|
|
const attachVideoStream = () => {
|
|
|
|
const stream = isCurrent ? peer.getLocalStream() : peer.getRemoteStream();
|
|
|
|
video.pause();
|
|
|
|
video.srcObject = stream;
|
|
|
|
video.load();
|
|
|
|
};
|
|
|
|
|
2018-04-19 02:16:26 +08:00
|
|
|
if (peer) {
|
|
|
|
if (peer.started === true) {
|
|
|
|
attachVideoStream();
|
|
|
|
return;
|
|
|
|
}
|
2018-02-17 03:18:53 +08:00
|
|
|
|
2018-04-19 02:16:26 +08:00
|
|
|
peer.on('playStart', attachVideoStream);
|
|
|
|
}
|
2018-02-17 03:18:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
handlePlayStop(message) {
|
2018-03-20 01:52:39 +08:00
|
|
|
const id = message.cameraId;
|
2018-04-19 02:16:26 +08:00
|
|
|
|
|
|
|
log('info', 'Handle play stop for camera', id);
|
|
|
|
this.stopWebRTCPeer(id);
|
2018-02-17 03:18:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
handlePlayStart(message) {
|
2018-04-19 02:16:26 +08:00
|
|
|
const id = message.cameraId;
|
|
|
|
log('info', 'Handle play start for camera', id);
|
2018-02-17 03:18:53 +08:00
|
|
|
|
2018-04-19 02:16:26 +08:00
|
|
|
const peer = this.webRtcPeers[id];
|
2018-04-14 03:16:06 +08:00
|
|
|
|
2018-02-17 03:18:53 +08:00
|
|
|
// Clear camera shared timeout when camera succesfully starts
|
2018-04-19 02:16:26 +08:00
|
|
|
clearTimeout(this.cameraTimeouts[id]);
|
|
|
|
this.cameraTimeouts[id] = null;
|
2018-02-17 03:18:53 +08:00
|
|
|
|
2018-04-14 03:16:06 +08:00
|
|
|
peer.emit('playStart');
|
|
|
|
peer.started = true;
|
|
|
|
|
2018-02-17 05:11:59 +08:00
|
|
|
if (message.cameraId == this.props.userId) {
|
2018-02-17 03:18:53 +08:00
|
|
|
VideoService.joinedVideo();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleError(message) {
|
|
|
|
const { intl } = this.props;
|
2018-02-17 05:11:59 +08:00
|
|
|
const userId = this.props.userId;
|
2018-02-17 03:18:53 +08:00
|
|
|
|
|
|
|
if (message.cameraId == userId) {
|
|
|
|
this.unshareWebcam();
|
|
|
|
this.notifyError(intl.formatMessage(intlMessages.sharingError));
|
|
|
|
} else {
|
2018-04-19 02:16:26 +08:00
|
|
|
this.stopWebRTCPeer(message.cameraId);
|
2018-02-17 03:18:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
console.error(' Handle error --------------------->');
|
|
|
|
log('debug', message.message);
|
|
|
|
}
|
|
|
|
|
|
|
|
notifyError(message) {
|
|
|
|
notify(message, 'error', 'video');
|
|
|
|
}
|
|
|
|
|
|
|
|
shareWebcam() {
|
2018-04-09 22:39:27 +08:00
|
|
|
const { intl } = this.props;
|
2018-02-17 03:18:53 +08:00
|
|
|
|
2018-03-21 15:27:06 +08:00
|
|
|
if (this.connectedToMediaServer()) {
|
2018-04-19 02:16:26 +08:00
|
|
|
log('info', 'Sharing webcam');
|
2018-03-21 15:27:06 +08:00
|
|
|
this.setState({ sharedWebcam: true });
|
|
|
|
VideoService.joiningVideo();
|
|
|
|
} else {
|
2018-04-19 02:16:26 +08:00
|
|
|
log('debug', 'Error on sharing webcam');
|
2018-03-21 15:27:06 +08:00
|
|
|
this.notifyError(intl.formatMessage(intlMessages.sharingError));
|
|
|
|
}
|
2018-02-17 03:18:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
unshareWebcam() {
|
|
|
|
log('info', 'Unsharing webcam');
|
2018-02-17 05:11:59 +08:00
|
|
|
|
|
|
|
VideoService.sendUserUnshareWebcam(this.props.userId);
|
2018-04-19 02:16:26 +08:00
|
|
|
VideoService.exitedVideo();
|
|
|
|
this.setState({ sharedWebcam: false });
|
2018-02-17 03:18:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2018-04-12 02:50:14 +08:00
|
|
|
if (!this.state.socketOpen) return null;
|
|
|
|
|
2018-02-17 03:18:53 +08:00
|
|
|
return (
|
2018-04-12 02:50:14 +08:00
|
|
|
<VideoList
|
|
|
|
users={this.props.users}
|
|
|
|
onMount={this.attachVideoStream.bind(this)}
|
2018-03-20 01:52:39 +08:00
|
|
|
/>
|
2018-02-17 03:18:53 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-12 23:29:51 +08:00
|
|
|
export default injectIntl(VideoProvider);
|