2018-02-17 03:18:53 +08:00
|
|
|
import React, { Component } from 'react';
|
2019-07-24 06:24:31 +08:00
|
|
|
import PropTypes from 'prop-types';
|
2018-07-28 04:42:45 +08:00
|
|
|
import ReconnectingWebSocket from 'reconnecting-websocket';
|
2020-09-17 22:37:28 +08:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
|
|
|
import _ from 'lodash';
|
2018-02-19 12:23:05 +08:00
|
|
|
import VideoService from './service';
|
2020-08-19 01:00:47 +08:00
|
|
|
import VideoListContainer from './video-list/container';
|
2020-05-21 12:20:46 +08:00
|
|
|
import {
|
|
|
|
fetchWebRTCMappedStunTurnServers,
|
|
|
|
getMappedFallbackStun,
|
|
|
|
} from '/imports/utils/fetchStunTurnServers';
|
2019-11-28 21:13:06 +08:00
|
|
|
import logger from '/imports/startup/client/logger';
|
2021-01-21 03:03:12 +08:00
|
|
|
import { notifyStreamStateChange } from '/imports/ui/services/bbb-webrtc-sfu/stream-state-service';
|
2018-02-17 03:18:53 +08:00
|
|
|
|
2020-07-09 23:22:14 +08:00
|
|
|
// Default values and default empty object to be backwards compat with 2.2.
|
|
|
|
// FIXME Remove hardcoded defaults 2.3.
|
|
|
|
const WS_CONN_TIMEOUT = Meteor.settings.public.kurento.wsConnectionTimeout || 4000;
|
2020-05-27 01:05:04 +08:00
|
|
|
|
2020-07-09 23:22:14 +08:00
|
|
|
const {
|
|
|
|
baseTimeout: CAMERA_SHARE_FAILED_WAIT_TIME = 15000,
|
|
|
|
maxTimeout: MAX_CAMERA_SHARE_FAILED_WAIT_TIME = 60000,
|
|
|
|
} = Meteor.settings.public.kurento.cameraTimeouts || {};
|
2021-06-22 04:59:55 +08:00
|
|
|
const CAMERA_QUALITY_THRESHOLDS_ENABLED = Meteor.settings.public.kurento.cameraQualityThresholds.enabled;
|
2019-11-28 21:13:06 +08:00
|
|
|
const PING_INTERVAL = 15000;
|
2018-08-21 02:08:10 +08:00
|
|
|
|
2018-07-21 03:34:50 +08:00
|
|
|
const intlClientErrors = defineMessages({
|
2018-05-17 02:15:46 +08:00
|
|
|
permissionError: {
|
|
|
|
id: 'app.video.permissionError',
|
2019-11-28 21:13:06 +08:00
|
|
|
description: 'Webcam permission error',
|
2018-05-17 21:23:18 +08:00
|
|
|
},
|
2018-08-13 06:39:39 +08:00
|
|
|
iceConnectionStateError: {
|
|
|
|
id: 'app.video.iceConnectionStateError',
|
2019-11-28 21:13:06 +08:00
|
|
|
description: 'Ice connection state failed',
|
2018-08-13 06:39:39 +08:00
|
|
|
},
|
2018-12-18 01:45:57 +08:00
|
|
|
mediaFlowTimeout: {
|
|
|
|
id: 'app.video.mediaFlowTimeout1020',
|
2019-11-28 21:13:06 +08:00
|
|
|
description: 'Media flow timeout',
|
2018-12-18 01:45:57 +08:00
|
|
|
},
|
2021-07-08 23:10:22 +08:00
|
|
|
mediaTimedOutError: {
|
|
|
|
id: 'app.video.mediaTimedOutError',
|
|
|
|
description: 'Media was ejected by the server due to lack of valid media',
|
|
|
|
},
|
2018-07-21 03:34:50 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
const intlSFUErrors = defineMessages({
|
|
|
|
2000: {
|
|
|
|
id: 'app.sfu.mediaServerConnectionError2000',
|
2019-11-28 21:13:06 +08:00
|
|
|
description: 'SFU connection to the media server',
|
2018-07-21 03:34:50 +08:00
|
|
|
},
|
|
|
|
2001: {
|
|
|
|
id: 'app.sfu.mediaServerOffline2001',
|
2019-11-28 21:13:06 +08:00
|
|
|
description: 'SFU is offline',
|
2018-05-17 02:15:46 +08:00
|
|
|
},
|
2018-07-21 03:34:50 +08:00
|
|
|
2002: {
|
|
|
|
id: 'app.sfu.mediaServerNoResources2002',
|
2019-11-28 21:13:06 +08:00
|
|
|
description: 'Media server lacks disk, CPU or FDs',
|
2018-07-21 03:34:50 +08:00
|
|
|
},
|
|
|
|
2003: {
|
|
|
|
id: 'app.sfu.mediaServerRequestTimeout2003',
|
2019-11-28 21:13:06 +08:00
|
|
|
description: 'Media requests timeout due to lack of resources',
|
2018-07-21 03:34:50 +08:00
|
|
|
},
|
|
|
|
2021: {
|
|
|
|
id: 'app.sfu.serverIceGatheringFailed2021',
|
2019-11-28 21:13:06 +08:00
|
|
|
description: 'Server cannot enact ICE gathering',
|
2018-07-21 03:34:50 +08:00
|
|
|
},
|
|
|
|
2022: {
|
|
|
|
id: 'app.sfu.serverIceStateFailed2022',
|
2019-11-28 21:13:06 +08:00
|
|
|
description: 'Server endpoint transitioned to a FAILED ICE state',
|
2018-07-21 03:34:50 +08:00
|
|
|
},
|
2018-12-18 01:45:57 +08:00
|
|
|
2200: {
|
|
|
|
id: 'app.sfu.mediaGenericError2200',
|
2019-11-28 21:13:06 +08:00
|
|
|
description: 'SFU component generated a generic error',
|
2018-12-18 01:45:57 +08:00
|
|
|
},
|
2018-07-21 03:34:50 +08:00
|
|
|
2202: {
|
|
|
|
id: 'app.sfu.invalidSdp2202',
|
2019-11-28 21:13:06 +08:00
|
|
|
description: 'Client provided an invalid SDP',
|
2018-07-21 03:34:50 +08:00
|
|
|
},
|
|
|
|
2203: {
|
|
|
|
id: 'app.sfu.noAvailableCodec2203',
|
2019-11-28 21:13:06 +08:00
|
|
|
description: 'Server has no available codec for the client',
|
2018-08-13 06:40:53 +08:00
|
|
|
},
|
2018-02-17 03:18:53 +08:00
|
|
|
});
|
|
|
|
|
2019-07-24 06:24:31 +08:00
|
|
|
const propTypes = {
|
2019-11-28 21:13:06 +08:00
|
|
|
streams: PropTypes.arrayOf(Array).isRequired,
|
2019-07-24 06:24:31 +08:00
|
|
|
intl: PropTypes.objectOf(Object).isRequired,
|
2019-11-28 21:13:06 +08:00
|
|
|
isUserLocked: PropTypes.bool.isRequired,
|
|
|
|
swapLayout: PropTypes.bool.isRequired,
|
2020-08-20 23:43:02 +08:00
|
|
|
currentVideoPageIndex: PropTypes.number.isRequired,
|
2020-08-27 10:16:17 +08:00
|
|
|
totalNumberOfStreams: PropTypes.number.isRequired,
|
2019-07-24 06:24:31 +08:00
|
|
|
};
|
|
|
|
|
2018-02-17 03:18:53 +08:00
|
|
|
class VideoProvider extends Component {
|
2020-04-23 22:07:44 +08:00
|
|
|
static onBeforeUnload() {
|
|
|
|
VideoService.onBeforeUnload();
|
|
|
|
}
|
|
|
|
|
2018-02-17 03:18:53 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
2018-03-20 01:52:39 +08:00
|
|
|
socketOpen: false,
|
2018-02-17 03:18:53 +08:00
|
|
|
};
|
|
|
|
|
2019-11-28 21:13:06 +08:00
|
|
|
this.info = VideoService.getInfo();
|
|
|
|
|
2018-02-17 03:18:53 +08:00
|
|
|
// Set a valid bbb-webrtc-sfu application server socket in the settings
|
2020-07-09 22:18:56 +08:00
|
|
|
this.ws = new ReconnectingWebSocket(
|
2020-08-05 22:20:58 +08:00
|
|
|
VideoService.getAuthenticatedURL(),
|
2020-07-09 22:18:56 +08:00
|
|
|
[],
|
|
|
|
{ connectionTimeout: WS_CONN_TIMEOUT },
|
|
|
|
);
|
2018-02-17 03:18:53 +08:00
|
|
|
this.wsQueue = [];
|
2018-05-23 04:44:30 +08:00
|
|
|
this.restartTimeout = {};
|
|
|
|
this.restartTimer = {};
|
2018-02-17 03:18:53 +08:00
|
|
|
this.webRtcPeers = {};
|
2019-11-28 23:27:34 +08:00
|
|
|
this.outboundIceQueues = {};
|
2018-07-10 05:29:27 +08:00
|
|
|
this.videoTags = {};
|
2018-02-17 03:18:53 +08:00
|
|
|
|
2018-12-18 06:19:26 +08:00
|
|
|
this.createVideoTag = this.createVideoTag.bind(this);
|
2021-01-21 03:03:12 +08:00
|
|
|
this.destroyVideoTag = this.destroyVideoTag.bind(this);
|
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);
|
2019-11-28 21:13:06 +08:00
|
|
|
this.updateStreams = this.updateStreams.bind(this);
|
2020-08-20 23:43:02 +08:00
|
|
|
this.debouncedConnectStreams = _.debounce(
|
|
|
|
this.connectStreams,
|
|
|
|
VideoService.getPageChangeDebounceTime(),
|
2020-09-17 22:37:28 +08:00
|
|
|
{ leading: false, trailing: true },
|
2020-08-20 23:43:02 +08:00
|
|
|
);
|
2018-05-03 01:53:53 +08:00
|
|
|
}
|
|
|
|
|
2019-11-28 21:13:06 +08:00
|
|
|
componentDidMount() {
|
2018-12-18 06:19:26 +08:00
|
|
|
this.ws.onopen = this.onWsOpen;
|
2018-12-18 01:45:57 +08:00
|
|
|
this.ws.onclose = this.onWsClose;
|
2018-02-17 03:18:53 +08:00
|
|
|
|
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);
|
|
|
|
|
2018-12-18 01:45:57 +08:00
|
|
|
this.ws.onmessage = this.onWsMessage;
|
2019-11-28 21:13:06 +08:00
|
|
|
|
2020-04-23 22:07:44 +08:00
|
|
|
window.addEventListener('beforeunload', VideoProvider.onBeforeUnload);
|
2018-02-17 03:18:53 +08:00
|
|
|
}
|
|
|
|
|
2019-11-28 21:13:06 +08:00
|
|
|
componentDidUpdate(prevProps) {
|
2020-08-20 23:43:02 +08:00
|
|
|
const { isUserLocked, streams, currentVideoPageIndex } = this.props;
|
|
|
|
|
|
|
|
// Only debounce when page changes to avoid unecessary debouncing
|
|
|
|
const shouldDebounce = VideoService.isPaginationEnabled()
|
|
|
|
&& prevProps.currentVideoPageIndex !== currentVideoPageIndex;
|
2018-04-12 02:50:14 +08:00
|
|
|
|
2020-08-20 23:43:02 +08:00
|
|
|
this.updateStreams(streams, shouldDebounce);
|
2018-04-12 02:50:14 +08:00
|
|
|
|
2019-11-28 21:13:06 +08:00
|
|
|
if (!prevProps.isUserLocked && isUserLocked) VideoService.lockUser();
|
2019-06-03 22:05:09 +08:00
|
|
|
}
|
|
|
|
|
2018-02-17 03:18:53 +08:00
|
|
|
componentWillUnmount() {
|
2018-12-18 01:45:57 +08:00
|
|
|
this.ws.onmessage = null;
|
|
|
|
this.ws.onopen = null;
|
|
|
|
this.ws.onclose = null;
|
2018-02-17 03:18:53 +08:00
|
|
|
|
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);
|
2019-11-28 21:13:06 +08:00
|
|
|
|
2020-04-23 22:07:44 +08:00
|
|
|
window.removeEventListener('beforeunload', VideoProvider.onBeforeUnload);
|
2018-02-17 03:18:53 +08:00
|
|
|
|
2019-11-28 21:13:06 +08:00
|
|
|
VideoService.exitVideo();
|
2018-02-17 03:18:53 +08:00
|
|
|
|
2021-04-09 10:58:13 +08:00
|
|
|
Object.keys(this.webRtcPeers).forEach((stream) => {
|
|
|
|
this.stopWebRTCPeer(stream, false);
|
2018-02-17 03:18:53 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
// Close websocket connection to prevent multiple reconnects from happening
|
2018-04-26 23:39:24 +08:00
|
|
|
this.ws.close();
|
2018-02-17 03:18:53 +08:00
|
|
|
}
|
|
|
|
|
2019-11-28 21:13:06 +08:00
|
|
|
onWsMessage(message) {
|
|
|
|
const parsedMessage = JSON.parse(message.data);
|
2018-02-17 03:18:53 +08:00
|
|
|
|
2019-01-22 04:05:52 +08:00
|
|
|
if (parsedMessage.id === 'pong') return;
|
2019-11-28 21:13:06 +08:00
|
|
|
|
2018-12-18 06:19:26 +08:00
|
|
|
switch (parsedMessage.id) {
|
|
|
|
case 'startResponse':
|
|
|
|
this.startResponse(parsedMessage);
|
|
|
|
break;
|
2018-05-03 21:57:03 +08:00
|
|
|
|
2018-12-18 06:19:26 +08:00
|
|
|
case 'playStart':
|
|
|
|
this.handlePlayStart(parsedMessage);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'playStop':
|
|
|
|
this.handlePlayStop(parsedMessage);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'iceCandidate':
|
|
|
|
this.handleIceCandidate(parsedMessage);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'pong':
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'error':
|
|
|
|
default:
|
|
|
|
this.handleSFUError(parsedMessage);
|
|
|
|
break;
|
|
|
|
}
|
2018-02-17 03:18:53 +08:00
|
|
|
}
|
|
|
|
|
2018-12-18 06:19:26 +08:00
|
|
|
onWsClose() {
|
2021-01-21 04:25:02 +08:00
|
|
|
logger.info({
|
2019-11-28 21:13:06 +08:00
|
|
|
logCode: 'video_provider_onwsclose',
|
|
|
|
}, 'Multiple video provider websocket connection closed.');
|
2018-02-17 03:18:53 +08:00
|
|
|
|
2018-05-03 21:57:03 +08:00
|
|
|
clearInterval(this.pingInterval);
|
2018-03-20 01:52:39 +08:00
|
|
|
|
2019-11-28 21:13:06 +08:00
|
|
|
VideoService.exitVideo();
|
2018-12-18 01:45:57 +08:00
|
|
|
|
2018-03-20 01:52:39 +08:00
|
|
|
this.setState({ socketOpen: false });
|
2018-02-17 03:18:53 +08:00
|
|
|
}
|
|
|
|
|
2018-12-18 06:19:26 +08:00
|
|
|
onWsOpen() {
|
2021-01-21 04:25:02 +08:00
|
|
|
logger.info({
|
2019-11-28 21:13:06 +08:00
|
|
|
logCode: 'video_provider_onwsopen',
|
|
|
|
}, 'Multiple video provider websocket connection opened.');
|
2018-12-18 06:19:26 +08:00
|
|
|
|
2019-11-28 21:13:06 +08:00
|
|
|
// Resend queued messages that happened when socket was not connected
|
2018-12-18 06:19:26 +08:00
|
|
|
while (this.wsQueue.length > 0) {
|
|
|
|
this.sendMessage(this.wsQueue.pop());
|
|
|
|
}
|
|
|
|
|
|
|
|
this.pingInterval = setInterval(this.ping.bind(this), PING_INTERVAL);
|
|
|
|
|
|
|
|
this.setState({ socketOpen: true });
|
2018-05-03 21:57:03 +08:00
|
|
|
}
|
|
|
|
|
2021-06-22 04:59:55 +08:00
|
|
|
updateThreshold(numberOfPublishers) {
|
|
|
|
const { threshold, profile } = VideoService.getThreshold(numberOfPublishers);
|
|
|
|
if (profile) {
|
|
|
|
const publishers = Object.values(this.webRtcPeers)
|
|
|
|
.filter(peer => peer.isPublisher)
|
|
|
|
.forEach((peer) => {
|
|
|
|
// 0 means no threshold in place. Reapply original one if needed
|
|
|
|
const profileToApply = (threshold === 0) ? peer.originalProfileId : profile;
|
|
|
|
VideoService.applyCameraProfile(peer, profileToApply);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-19 01:00:47 +08:00
|
|
|
getStreamsToConnectAndDisconnect(streams) {
|
2021-06-22 04:59:55 +08:00
|
|
|
const streamsCameraIds = streams.map(s => s.stream);
|
2019-11-28 21:13:06 +08:00
|
|
|
const streamsConnected = Object.keys(this.webRtcPeers);
|
2018-02-17 03:18:53 +08:00
|
|
|
|
2021-06-22 04:59:55 +08:00
|
|
|
const streamsToConnect = streamsCameraIds.filter(stream => {
|
|
|
|
return !streamsConnected.includes(stream);
|
|
|
|
});
|
2019-11-29 04:28:41 +08:00
|
|
|
|
2021-06-22 04:59:55 +08:00
|
|
|
const streamsToDisconnect = streamsConnected.filter(stream => {
|
|
|
|
return !streamsCameraIds.includes(stream);
|
|
|
|
});
|
2018-02-17 03:18:53 +08:00
|
|
|
|
2020-08-19 01:00:47 +08:00
|
|
|
return [streamsToConnect, streamsToDisconnect];
|
|
|
|
}
|
|
|
|
|
2021-06-22 04:59:55 +08:00
|
|
|
connectStreams(streamsToConnect) {
|
|
|
|
streamsToConnect.forEach((stream) => {
|
|
|
|
const isLocal = VideoService.isLocalStream(stream);
|
|
|
|
this.createWebRTCPeer(stream, isLocal);
|
|
|
|
});
|
|
|
|
}
|
2021-06-22 04:16:59 +08:00
|
|
|
|
2021-06-22 04:59:55 +08:00
|
|
|
disconnectStreams(streamsToDisconnect) {
|
|
|
|
streamsToDisconnect.forEach(stream => this.stopWebRTCPeer(stream, false));
|
2020-08-19 01:00:47 +08:00
|
|
|
}
|
|
|
|
|
2020-08-20 23:43:02 +08:00
|
|
|
updateStreams(streams, shouldDebounce = false) {
|
2020-08-19 01:00:47 +08:00
|
|
|
const [streamsToConnect, streamsToDisconnect] = this.getStreamsToConnectAndDisconnect(streams);
|
|
|
|
|
2020-09-17 22:37:28 +08:00
|
|
|
if (shouldDebounce) {
|
2020-08-20 23:43:02 +08:00
|
|
|
this.debouncedConnectStreams(streamsToConnect);
|
|
|
|
} else {
|
|
|
|
this.connectStreams(streamsToConnect);
|
|
|
|
}
|
|
|
|
|
2020-08-19 01:00:47 +08:00
|
|
|
this.disconnectStreams(streamsToDisconnect);
|
2020-05-27 01:05:04 +08:00
|
|
|
|
|
|
|
if (CAMERA_QUALITY_THRESHOLDS_ENABLED) {
|
2021-06-22 04:59:55 +08:00
|
|
|
this.updateThreshold(this.props.totalNumberOfStreams);
|
2020-05-27 01:05:04 +08:00
|
|
|
}
|
2018-12-18 06:19:26 +08:00
|
|
|
}
|
2018-02-17 03:18:53 +08:00
|
|
|
|
2018-12-18 06:19:26 +08:00
|
|
|
ping() {
|
2019-11-28 21:13:06 +08:00
|
|
|
const message = { id: 'ping' };
|
2018-12-18 06:19:26 +08:00
|
|
|
this.sendMessage(message);
|
2018-02-17 03:18:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
sendMessage(message) {
|
2018-06-15 03:20:14 +08:00
|
|
|
const { ws } = this;
|
2018-02-17 03:18:53 +08:00
|
|
|
|
|
|
|
if (this.connectedToMediaServer()) {
|
|
|
|
const jsonMessage = JSON.stringify(message);
|
|
|
|
ws.send(jsonMessage, (error) => {
|
|
|
|
if (error) {
|
2019-07-03 03:51:35 +08:00
|
|
|
logger.error({
|
2019-07-19 04:44:21 +08:00
|
|
|
logCode: 'video_provider_ws_send_error',
|
2019-07-03 03:51:35 +08:00
|
|
|
extraInfo: {
|
2021-01-21 04:25:02 +08:00
|
|
|
errorMessage: error.message || 'Unknown',
|
|
|
|
errorCode: error.code,
|
2019-07-03 03:51:35 +08:00
|
|
|
},
|
2021-01-21 04:25:02 +08:00
|
|
|
}, 'Camera request failed to be sent to SFU');
|
2018-02-17 03:18:53 +08:00
|
|
|
}
|
|
|
|
});
|
2019-04-24 04:23:32 +08:00
|
|
|
} else if (message.id !== 'stop') {
|
2018-02-17 03:18:53 +08:00
|
|
|
// No need to queue video stop messages
|
2019-04-24 04:23:32 +08:00
|
|
|
this.wsQueue.push(message);
|
2018-02-17 03:18:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
connectedToMediaServer() {
|
|
|
|
return this.ws.readyState === WebSocket.OPEN;
|
|
|
|
}
|
|
|
|
|
2021-04-09 10:58:13 +08:00
|
|
|
processOutboundIceQueue(peer, role, stream) {
|
|
|
|
const queue = this.outboundIceQueues[stream];
|
2019-11-28 23:27:34 +08:00
|
|
|
while (queue && queue.length) {
|
|
|
|
const candidate = queue.shift();
|
2021-04-09 10:58:13 +08:00
|
|
|
this.sendIceCandidateToSFU(peer, role, candidate, stream);
|
2019-11-28 23:27:34 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-17 03:18:53 +08:00
|
|
|
startResponse(message) {
|
2021-04-09 10:58:13 +08:00
|
|
|
const { cameraId: stream, role } = message;
|
|
|
|
const peer = this.webRtcPeers[stream];
|
2018-02-17 03:18:53 +08:00
|
|
|
|
2021-01-21 04:25:02 +08:00
|
|
|
logger.debug({
|
2019-07-19 04:44:21 +08:00
|
|
|
logCode: 'video_provider_start_response_success',
|
2021-04-09 10:58:13 +08:00
|
|
|
extraInfo: { cameraId: stream, role },
|
2021-01-21 04:25:02 +08:00
|
|
|
}, `Camera start request accepted by SFU. Role: ${role}`);
|
2018-02-17 03:18:53 +08:00
|
|
|
|
2018-07-12 00:32:19 +08:00
|
|
|
if (peer) {
|
|
|
|
peer.processAnswer(message.sdpAnswer, (error) => {
|
|
|
|
if (error) {
|
2019-07-19 04:44:21 +08:00
|
|
|
logger.error({
|
|
|
|
logCode: 'video_provider_peerconnection_processanswer_error',
|
2019-07-03 03:51:35 +08:00
|
|
|
extraInfo: {
|
2021-04-09 10:58:13 +08:00
|
|
|
cameraId: stream,
|
2021-01-28 02:31:17 +08:00
|
|
|
role,
|
2021-01-21 04:25:02 +08:00
|
|
|
errorMessage: error.message,
|
|
|
|
errorCode: error.code,
|
2019-07-03 03:51:35 +08:00
|
|
|
},
|
2021-01-21 04:25:02 +08:00
|
|
|
}, 'Camera answer processing failed');
|
2019-11-28 21:13:06 +08:00
|
|
|
|
2019-07-19 04:44:21 +08:00
|
|
|
return;
|
2018-07-12 00:32:19 +08:00
|
|
|
}
|
2018-12-22 03:47:15 +08:00
|
|
|
|
|
|
|
peer.didSDPAnswered = true;
|
2021-04-09 10:58:13 +08:00
|
|
|
this.processOutboundIceQueue(peer, role, stream);
|
|
|
|
VideoService.processInboundIceQueue(peer, stream);
|
2018-07-12 00:32:19 +08:00
|
|
|
});
|
|
|
|
} else {
|
2019-11-28 21:13:06 +08:00
|
|
|
logger.warn({
|
|
|
|
logCode: 'video_provider_startresponse_no_peer',
|
2021-04-09 10:58:13 +08:00
|
|
|
extraInfo: { cameraId: stream, role },
|
2021-01-21 04:25:02 +08:00
|
|
|
}, 'No peer on SFU camera start response handler');
|
2018-07-12 00:32:19 +08:00
|
|
|
}
|
2018-02-17 03:18:53 +08:00
|
|
|
}
|
|
|
|
|
2021-06-22 04:59:55 +08:00
|
|
|
handleIceCandidate(message) {
|
|
|
|
const { cameraId: stream, candidate } = message;
|
|
|
|
const peer = this.webRtcPeers[stream];
|
|
|
|
|
|
|
|
if (peer) {
|
|
|
|
if (peer.didSDPAnswered) {
|
|
|
|
VideoService.addCandidateToPeer(peer, candidate, stream);
|
|
|
|
} else {
|
|
|
|
// ICE candidates are queued until a SDP answer has been processed.
|
|
|
|
// This was done due to a long term iOS/Safari quirk where it'd
|
|
|
|
// fail if candidates were added before the offer/answer cycle was completed.
|
|
|
|
// Dunno if that still happens, but it works even if it slows the ICE checks
|
|
|
|
// a bit - prlanzarin july 2019
|
|
|
|
if (peer.inboundIceQueue == null) {
|
|
|
|
peer.inboundIceQueue = [];
|
|
|
|
}
|
|
|
|
peer.inboundIceQueue.push(candidate);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
logger.warn({
|
|
|
|
logCode: 'video_provider_addicecandidate_no_peer',
|
|
|
|
extraInfo: { cameraId: stream },
|
|
|
|
}, 'Trailing camera ICE candidate, discarded');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-22 04:16:59 +08:00
|
|
|
clearRestartTimers(stream) {
|
2021-04-09 10:58:13 +08:00
|
|
|
if (this.restartTimeout[stream]) {
|
|
|
|
clearTimeout(this.restartTimeout[stream]);
|
|
|
|
delete this.restartTimeout[stream];
|
2021-01-21 03:03:12 +08:00
|
|
|
}
|
|
|
|
|
2021-04-09 10:58:13 +08:00
|
|
|
if (this.restartTimer[stream]) {
|
|
|
|
delete this.restartTimer[stream];
|
2021-01-21 03:03:12 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-09 10:58:13 +08:00
|
|
|
stopWebRTCPeer(stream, restarting = false) {
|
|
|
|
const isLocal = VideoService.isLocalStream(stream);
|
2018-02-17 03:18:53 +08:00
|
|
|
|
2018-08-14 04:26:45 +08:00
|
|
|
// in this case, 'closed' state is not caused by an error;
|
|
|
|
// we stop listening to prevent this from being treated as an error
|
2021-04-09 10:58:13 +08:00
|
|
|
const peer = this.webRtcPeers[stream];
|
2019-11-28 23:27:34 +08:00
|
|
|
if (peer && peer.peerConnection) {
|
2019-11-28 21:13:06 +08:00
|
|
|
const conn = peer.peerConnection;
|
|
|
|
conn.oniceconnectionstatechange = null;
|
2018-08-21 02:08:10 +08:00
|
|
|
}
|
2018-08-14 04:26:45 +08:00
|
|
|
|
2019-11-28 21:13:06 +08:00
|
|
|
if (isLocal) {
|
2021-04-09 10:58:13 +08:00
|
|
|
VideoService.stopVideo(stream);
|
2018-04-12 02:50:14 +08:00
|
|
|
}
|
|
|
|
|
2019-11-28 21:13:06 +08:00
|
|
|
const role = VideoService.getRole(isLocal);
|
2019-07-19 04:44:21 +08:00
|
|
|
|
2019-11-28 21:13:06 +08:00
|
|
|
logger.info({
|
|
|
|
logCode: 'video_provider_stopping_webcam_sfu',
|
2021-04-09 10:58:13 +08:00
|
|
|
extraInfo: { role, cameraId: stream, restarting },
|
2021-01-21 04:25:02 +08:00
|
|
|
}, `Camera feed stop requested. Role ${role}, restarting ${restarting}`);
|
|
|
|
|
2018-04-14 03:16:06 +08:00
|
|
|
this.sendMessage({
|
2019-11-28 21:13:06 +08:00
|
|
|
id: 'stop',
|
2018-04-14 03:16:06 +08:00
|
|
|
type: 'video',
|
2021-04-09 10:58:13 +08:00
|
|
|
cameraId: stream,
|
2019-07-19 04:44:21 +08:00
|
|
|
role,
|
2018-04-14 03:16:06 +08:00
|
|
|
});
|
|
|
|
|
2019-11-29 01:44:39 +08:00
|
|
|
// Clear the shared camera media flow timeout and current reconnect period
|
|
|
|
// when destroying it if the peer won't restart
|
2018-12-18 22:54:17 +08:00
|
|
|
if (!restarting) {
|
2021-04-09 10:58:13 +08:00
|
|
|
this.clearRestartTimers(stream);
|
2018-12-18 01:45:57 +08:00
|
|
|
}
|
2018-05-23 04:44:30 +08:00
|
|
|
|
2021-04-09 10:58:13 +08:00
|
|
|
this.destroyWebRTCPeer(stream);
|
2018-04-19 02:16:26 +08:00
|
|
|
}
|
2018-02-17 03:18:53 +08:00
|
|
|
|
2021-04-09 10:58:13 +08:00
|
|
|
destroyWebRTCPeer(stream) {
|
|
|
|
const peer = this.webRtcPeers[stream];
|
|
|
|
const isLocal = VideoService.isLocalStream(stream);
|
2021-01-28 02:31:17 +08:00
|
|
|
const role = VideoService.getRole(isLocal);
|
|
|
|
|
2019-11-28 21:13:06 +08:00
|
|
|
if (peer) {
|
|
|
|
if (typeof peer.dispose === 'function') {
|
|
|
|
peer.dispose();
|
2019-05-25 03:55:35 +08:00
|
|
|
}
|
2021-04-09 10:58:13 +08:00
|
|
|
delete this.outboundIceQueues[stream];
|
|
|
|
delete this.webRtcPeers[stream];
|
2018-02-17 03:18:53 +08:00
|
|
|
} else {
|
2019-11-28 21:13:06 +08:00
|
|
|
logger.warn({
|
|
|
|
logCode: 'video_provider_destroywebrtcpeer_no_peer',
|
2021-04-09 10:58:13 +08:00
|
|
|
extraInfo: { cameraId: stream, role },
|
2021-01-21 04:25:02 +08:00
|
|
|
}, 'Trailing camera destroy request.');
|
2019-07-19 04:44:21 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-09 10:58:13 +08:00
|
|
|
async createWebRTCPeer(stream, isLocal) {
|
2018-07-10 05:29:27 +08:00
|
|
|
let iceServers = [];
|
2021-01-28 02:31:17 +08:00
|
|
|
const role = VideoService.getRole(isLocal);
|
2018-02-17 03:18:53 +08:00
|
|
|
|
2018-11-10 00:25:48 +08:00
|
|
|
// Check if the peer is already being processed
|
2021-04-09 10:58:13 +08:00
|
|
|
if (this.webRtcPeers[stream]) {
|
2018-11-10 00:25:48 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-04-09 10:58:13 +08:00
|
|
|
this.webRtcPeers[stream] = {};
|
2021-04-03 11:06:39 +08:00
|
|
|
const { constraints, bitrate, id: profileId } = VideoService.getCameraProfile();
|
|
|
|
const peerOptions = {
|
|
|
|
mediaConstraints: {
|
|
|
|
audio: false,
|
|
|
|
video: constraints,
|
|
|
|
},
|
|
|
|
onicecandidate: this._getOnIceCandidateCallback(stream, isLocal),
|
|
|
|
videoStream: VideoService.getPreloadedStream(),
|
|
|
|
};
|
2018-11-10 00:25:48 +08:00
|
|
|
|
2018-07-10 05:29:27 +08:00
|
|
|
try {
|
2019-11-28 21:13:06 +08:00
|
|
|
iceServers = await fetchWebRTCMappedStunTurnServers(this.info.sessionToken);
|
2018-07-10 05:29:27 +08:00
|
|
|
} catch (error) {
|
2019-07-03 03:51:35 +08:00
|
|
|
logger.error({
|
2019-07-19 04:44:21 +08:00
|
|
|
logCode: 'video_provider_fetchstunturninfo_error',
|
2019-07-03 03:51:35 +08:00
|
|
|
extraInfo: {
|
2021-04-09 10:58:13 +08:00
|
|
|
cameraId: stream,
|
2021-01-28 02:31:17 +08:00
|
|
|
role,
|
2020-05-21 12:20:46 +08:00
|
|
|
errorCode: error.code,
|
|
|
|
errorMessage: error.message,
|
2019-07-24 06:24:31 +08:00
|
|
|
},
|
2019-07-19 04:44:21 +08:00
|
|
|
}, 'video-provider failed to fetch STUN/TURN info, using default');
|
2020-05-21 12:20:46 +08:00
|
|
|
// Use fallback STUN server
|
|
|
|
iceServers = getMappedFallbackStun();
|
2018-07-10 05:29:27 +08:00
|
|
|
} finally {
|
2021-04-09 10:58:13 +08:00
|
|
|
this.outboundIceQueues[stream] = [];
|
2018-02-17 05:11:59 +08:00
|
|
|
|
2018-07-10 05:29:27 +08:00
|
|
|
if (iceServers.length > 0) {
|
2019-07-19 04:44:21 +08:00
|
|
|
peerOptions.configuration = {};
|
|
|
|
peerOptions.configuration.iceServers = iceServers;
|
2018-07-10 05:29:27 +08:00
|
|
|
}
|
2018-04-12 02:50:14 +08:00
|
|
|
|
2018-10-04 02:39:55 +08:00
|
|
|
let WebRtcPeerObj;
|
2019-11-28 21:13:06 +08:00
|
|
|
if (isLocal) {
|
2018-07-10 05:29:27 +08:00
|
|
|
WebRtcPeerObj = window.kurentoUtils.WebRtcPeer.WebRtcPeerSendonly;
|
2018-10-04 02:39:55 +08:00
|
|
|
} else {
|
|
|
|
WebRtcPeerObj = window.kurentoUtils.WebRtcPeer.WebRtcPeerRecvonly;
|
2018-07-10 05:29:27 +08:00
|
|
|
}
|
2018-05-23 04:44:30 +08:00
|
|
|
|
2021-04-09 10:58:13 +08:00
|
|
|
this.webRtcPeers[stream] = new WebRtcPeerObj(peerOptions, (error) => {
|
|
|
|
const peer = this.webRtcPeers[stream];
|
2019-11-28 21:13:06 +08:00
|
|
|
|
2021-04-09 10:58:13 +08:00
|
|
|
peer.stream = stream;
|
2018-07-10 05:29:27 +08:00
|
|
|
peer.started = false;
|
|
|
|
peer.attached = false;
|
|
|
|
peer.didSDPAnswered = false;
|
2020-05-27 01:05:04 +08:00
|
|
|
peer.isPublisher = isLocal;
|
|
|
|
peer.originalProfileId = profileId;
|
|
|
|
peer.currentProfileId = profileId;
|
|
|
|
|
2019-11-28 23:27:34 +08:00
|
|
|
if (peer.inboundIceQueue == null) {
|
|
|
|
peer.inboundIceQueue = [];
|
2018-07-21 03:34:50 +08:00
|
|
|
}
|
2018-02-17 03:18:53 +08:00
|
|
|
|
2018-07-10 05:29:27 +08:00
|
|
|
if (error) {
|
2021-04-09 10:58:13 +08:00
|
|
|
return this._onWebRTCError(error, stream, isLocal);
|
2018-02-17 03:18:53 +08:00
|
|
|
}
|
|
|
|
|
2018-07-10 05:29:27 +08:00
|
|
|
peer.generateOffer((errorGenOffer, offerSdp) => {
|
|
|
|
if (errorGenOffer) {
|
2021-04-09 10:58:13 +08:00
|
|
|
return this._onWebRTCError(errorGenOffer, stream, isLocal);
|
2018-07-10 05:29:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const message = {
|
|
|
|
id: 'start',
|
2019-11-28 21:13:06 +08:00
|
|
|
type: 'video',
|
2021-04-09 10:58:13 +08:00
|
|
|
cameraId: stream,
|
2021-01-21 04:25:02 +08:00
|
|
|
role,
|
2018-07-10 05:29:27 +08:00
|
|
|
sdpOffer: offerSdp,
|
2019-11-28 21:13:06 +08:00
|
|
|
meetingId: this.info.meetingId,
|
|
|
|
voiceBridge: this.info.voiceBridge,
|
|
|
|
userId: this.info.userId,
|
|
|
|
userName: this.info.userName,
|
2019-06-14 02:24:54 +08:00
|
|
|
bitrate,
|
2020-08-22 06:10:25 +08:00
|
|
|
record: VideoService.getRecord(),
|
2018-07-10 05:29:27 +08:00
|
|
|
};
|
2019-07-19 04:44:21 +08:00
|
|
|
|
|
|
|
logger.info({
|
2019-07-24 06:24:31 +08:00
|
|
|
logCode: 'video_provider_sfu_request_start_camera',
|
2019-07-19 04:44:21 +08:00
|
|
|
extraInfo: {
|
2021-04-09 10:58:13 +08:00
|
|
|
cameraId: stream,
|
2019-07-19 04:44:21 +08:00
|
|
|
cameraProfile: profileId,
|
2021-01-21 04:25:02 +08:00
|
|
|
role,
|
2019-07-19 04:44:21 +08:00
|
|
|
},
|
2021-01-21 04:25:02 +08:00
|
|
|
}, `Camera offer generated. Role: ${role}`);
|
2019-07-19 04:44:21 +08:00
|
|
|
|
2018-07-10 05:29:27 +08:00
|
|
|
this.sendMessage(message);
|
2021-04-09 10:58:13 +08:00
|
|
|
this.setReconnectionTimeout(stream, isLocal, false);
|
2019-07-24 06:24:31 +08:00
|
|
|
|
|
|
|
return false;
|
2018-07-10 05:29:27 +08:00
|
|
|
});
|
2019-07-24 06:24:31 +08:00
|
|
|
return false;
|
2018-02-17 03:18:53 +08:00
|
|
|
});
|
2019-11-28 21:13:06 +08:00
|
|
|
|
2021-04-09 10:58:13 +08:00
|
|
|
const peer = this.webRtcPeers[stream];
|
2019-11-28 21:13:06 +08:00
|
|
|
if (peer && peer.peerConnection) {
|
|
|
|
const conn = peer.peerConnection;
|
2021-01-21 03:03:12 +08:00
|
|
|
conn.onconnectionstatechange = () => {
|
2021-04-09 10:58:13 +08:00
|
|
|
this._handleIceConnectionStateChange(stream, isLocal);
|
2021-01-21 03:03:12 +08:00
|
|
|
};
|
2019-05-25 03:55:35 +08:00
|
|
|
}
|
2018-07-10 05:29:27 +08:00
|
|
|
}
|
2018-02-17 03:18:53 +08:00
|
|
|
}
|
|
|
|
|
2021-04-09 10:58:13 +08:00
|
|
|
_getWebRTCStartTimeout(stream, isLocal) {
|
2019-11-28 21:13:06 +08:00
|
|
|
const { intl } = this.props;
|
2018-05-23 04:44:30 +08:00
|
|
|
|
|
|
|
return () => {
|
2021-01-28 02:31:17 +08:00
|
|
|
const role = VideoService.getRole(isLocal);
|
2021-01-21 03:03:12 +08:00
|
|
|
if (!isLocal) {
|
|
|
|
// Peer that timed out is a subscriber/viewer
|
|
|
|
// Subscribers try to reconnect according to their timers if media could
|
|
|
|
// not reach the server. That's why we pass the restarting flag as true
|
|
|
|
// to the stop procedure as to not destroy the timers
|
2019-07-19 04:44:21 +08:00
|
|
|
// Create new reconnect interval time
|
2021-04-09 10:58:13 +08:00
|
|
|
const oldReconnectTimer = this.restartTimer[stream];
|
2019-07-19 04:44:21 +08:00
|
|
|
const newReconnectTimer = Math.min(
|
2019-11-29 01:44:39 +08:00
|
|
|
2 * oldReconnectTimer,
|
2019-07-24 06:24:31 +08:00
|
|
|
MAX_CAMERA_SHARE_FAILED_WAIT_TIME,
|
2019-07-19 04:44:21 +08:00
|
|
|
);
|
2021-04-09 10:58:13 +08:00
|
|
|
this.restartTimer[stream] = newReconnectTimer;
|
2019-07-19 04:44:21 +08:00
|
|
|
|
2019-11-29 01:44:39 +08:00
|
|
|
// Clear the current reconnect interval so it can be re-set in createWebRTCPeer
|
2021-04-09 10:58:13 +08:00
|
|
|
if (this.restartTimeout[stream]) {
|
|
|
|
delete this.restartTimeout[stream];
|
2019-11-29 01:44:39 +08:00
|
|
|
}
|
|
|
|
|
2019-07-19 04:44:21 +08:00
|
|
|
logger.error({
|
|
|
|
logCode: 'video_provider_camera_view_timeout',
|
|
|
|
extraInfo: {
|
2021-04-09 10:58:13 +08:00
|
|
|
cameraId: stream,
|
2021-01-28 02:31:17 +08:00
|
|
|
role,
|
2019-11-29 01:44:39 +08:00
|
|
|
oldReconnectTimer,
|
|
|
|
newReconnectTimer,
|
2019-07-24 06:24:31 +08:00
|
|
|
},
|
2021-01-21 04:25:02 +08:00
|
|
|
}, 'Camera VIEWER failed. Reconnecting.');
|
2019-11-28 21:13:06 +08:00
|
|
|
|
2021-04-09 10:58:13 +08:00
|
|
|
this.reconnect(stream, isLocal);
|
2021-01-21 03:03:12 +08:00
|
|
|
} else {
|
|
|
|
// Peer that timed out is a sharer/publisher, clean it up, stop.
|
|
|
|
logger.error({
|
|
|
|
logCode: 'video_provider_camera_share_timeout',
|
2021-01-28 02:31:17 +08:00
|
|
|
extraInfo: {
|
2021-04-09 10:58:13 +08:00
|
|
|
cameraId: stream,
|
2021-01-28 02:31:17 +08:00
|
|
|
role,
|
|
|
|
},
|
2021-01-21 04:25:02 +08:00
|
|
|
}, 'Camera SHARER failed.');
|
2021-01-21 03:03:12 +08:00
|
|
|
VideoService.notify(intl.formatMessage(intlClientErrors.mediaFlowTimeout));
|
2021-04-09 10:58:13 +08:00
|
|
|
this.stopWebRTCPeer(stream, false);
|
2018-05-23 04:44:30 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-04-09 10:58:13 +08:00
|
|
|
_onWebRTCError(error, stream, isLocal) {
|
2019-11-29 01:44:39 +08:00
|
|
|
const { intl } = this.props;
|
2021-01-21 03:03:12 +08:00
|
|
|
const errorMessage = intlClientErrors[error.name] || intlSFUErrors[error];
|
2018-12-22 05:25:47 +08:00
|
|
|
|
2021-01-21 03:03:12 +08:00
|
|
|
logger.error({
|
|
|
|
logCode: 'video_provider_webrtc_peer_error',
|
|
|
|
extraInfo: {
|
2021-04-09 10:58:13 +08:00
|
|
|
cameraId: stream,
|
2021-01-28 02:31:17 +08:00
|
|
|
role: VideoService.getRole(isLocal),
|
2021-01-21 03:03:12 +08:00
|
|
|
errorName: error.name,
|
2021-01-21 04:25:02 +08:00
|
|
|
errorMessage: error.message,
|
2021-01-21 03:03:12 +08:00
|
|
|
},
|
2021-01-21 04:25:02 +08:00
|
|
|
}, 'Camera peer failed');
|
2018-05-23 04:44:30 +08:00
|
|
|
|
2019-11-29 01:44:39 +08:00
|
|
|
// Only display WebRTC negotiation error toasts to sharers. The viewer streams
|
|
|
|
// will try to autoreconnect silently, but the error will log nonetheless
|
2021-01-21 03:03:12 +08:00
|
|
|
if (isLocal) {
|
2021-04-09 10:58:13 +08:00
|
|
|
this.stopWebRTCPeer(stream, false);
|
2021-01-21 03:03:12 +08:00
|
|
|
if (errorMessage) VideoService.notify(intl.formatMessage(errorMessage));
|
2019-11-29 01:44:39 +08:00
|
|
|
} else {
|
|
|
|
// If it's a viewer, set the reconnection timeout. There's a good chance
|
|
|
|
// no local candidate was generated and it wasn't set.
|
2021-04-09 10:58:13 +08:00
|
|
|
const peer = this.webRtcPeers[stream];
|
2021-01-21 03:03:12 +08:00
|
|
|
const isEstablishedConnection = peer && peer.started;
|
2021-04-09 10:58:13 +08:00
|
|
|
this.setReconnectionTimeout(stream, isLocal, isEstablishedConnection);
|
2021-01-21 03:03:12 +08:00
|
|
|
// second argument means it will only try to reconnect if
|
|
|
|
// it's a viewer instance (see stopWebRTCPeer restarting argument)
|
2021-04-09 10:58:13 +08:00
|
|
|
this.stopWebRTCPeer(stream, true);
|
2019-11-29 01:44:39 +08:00
|
|
|
}
|
2021-01-21 03:03:12 +08:00
|
|
|
}
|
2019-11-29 01:44:39 +08:00
|
|
|
|
2021-04-09 10:58:13 +08:00
|
|
|
reconnect(stream, isLocal) {
|
|
|
|
this.stopWebRTCPeer(stream, true);
|
|
|
|
this.createWebRTCPeer(stream, isLocal);
|
2018-05-23 04:44:30 +08:00
|
|
|
}
|
|
|
|
|
2021-06-22 04:59:55 +08:00
|
|
|
setReconnectionTimeout(stream, isLocal, isEstablishedConnection) {
|
|
|
|
const peer = this.webRtcPeers[stream];
|
|
|
|
const shouldSetReconnectionTimeout = !this.restartTimeout[stream] && !isEstablishedConnection;
|
2019-11-29 01:44:39 +08:00
|
|
|
|
2021-06-22 04:59:55 +08:00
|
|
|
// This is an ongoing reconnection which succeeded in the first place but
|
|
|
|
// then failed mid call. Try to reconnect it right away. Clear the restart
|
|
|
|
// timers since we don't need them in this case.
|
|
|
|
if (isEstablishedConnection) {
|
|
|
|
this.clearRestartTimers(stream);
|
|
|
|
return this.reconnect(stream, isLocal);
|
|
|
|
}
|
2019-11-29 01:44:39 +08:00
|
|
|
|
2021-06-22 04:59:55 +08:00
|
|
|
// This is a reconnection timer for a peer that hasn't succeeded in the first
|
|
|
|
// place. Set reconnection timeouts with random intervals between them to try
|
|
|
|
// and reconnect without flooding the server
|
|
|
|
if (shouldSetReconnectionTimeout) {
|
|
|
|
const newReconnectTimer = this.restartTimer[stream] || CAMERA_SHARE_FAILED_WAIT_TIME;
|
|
|
|
this.restartTimer[stream] = newReconnectTimer;
|
|
|
|
|
|
|
|
this.restartTimeout[stream] = setTimeout(
|
|
|
|
this._getWebRTCStartTimeout(stream, isLocal),
|
|
|
|
this.restartTimer[stream]
|
|
|
|
);
|
2019-11-29 01:44:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-09 10:58:13 +08:00
|
|
|
_getOnIceCandidateCallback(stream, isLocal) {
|
2018-05-23 04:44:30 +08:00
|
|
|
return (candidate) => {
|
2021-04-09 10:58:13 +08:00
|
|
|
const peer = this.webRtcPeers[stream];
|
2020-02-01 03:32:57 +08:00
|
|
|
const role = VideoService.getRole(isLocal);
|
2018-02-17 03:18:53 +08:00
|
|
|
|
2019-11-28 23:27:34 +08:00
|
|
|
if (peer && !peer.didSDPAnswered) {
|
2021-04-09 10:58:13 +08:00
|
|
|
this.outboundIceQueues[stream].push(candidate);
|
2019-11-28 23:27:34 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-04-09 10:58:13 +08:00
|
|
|
this.sendIceCandidateToSFU(peer, role, candidate, stream);
|
2019-11-28 23:27:34 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-04-09 10:58:13 +08:00
|
|
|
sendIceCandidateToSFU(peer, role, candidate, stream) {
|
2019-11-28 23:27:34 +08:00
|
|
|
const message = {
|
|
|
|
type: 'video',
|
|
|
|
role,
|
|
|
|
id: 'onIceCandidate',
|
|
|
|
candidate,
|
2021-04-09 10:58:13 +08:00
|
|
|
cameraId: stream,
|
2018-03-20 01:52:39 +08:00
|
|
|
};
|
2019-11-28 23:27:34 +08:00
|
|
|
this.sendMessage(message);
|
2018-03-20 01:52:39 +08:00
|
|
|
}
|
2018-02-17 03:18:53 +08:00
|
|
|
|
2021-06-22 04:16:59 +08:00
|
|
|
_handleIceConnectionStateChange(stream, isLocal) {
|
2018-08-13 06:39:39 +08:00
|
|
|
const { intl } = this.props;
|
2021-04-09 10:58:13 +08:00
|
|
|
const peer = this.webRtcPeers[stream];
|
2021-01-28 02:31:17 +08:00
|
|
|
const role = VideoService.getRole(isLocal);
|
2018-08-13 06:39:39 +08:00
|
|
|
|
2021-01-21 03:03:12 +08:00
|
|
|
if (peer && peer.peerConnection) {
|
|
|
|
const pc = peer.peerConnection;
|
2021-06-22 04:59:55 +08:00
|
|
|
const connectionState = pc.connectionState;
|
2021-04-09 10:58:13 +08:00
|
|
|
notifyStreamStateChange(stream, connectionState);
|
2021-01-21 03:03:12 +08:00
|
|
|
|
|
|
|
if (connectionState === 'failed' || connectionState === 'closed') {
|
|
|
|
const error = new Error('iceConnectionStateError');
|
|
|
|
// prevent the same error from being detected multiple times
|
|
|
|
pc.onconnectionstatechange = null;
|
2021-01-21 04:25:02 +08:00
|
|
|
|
2021-01-21 03:03:12 +08:00
|
|
|
logger.error({
|
|
|
|
logCode: 'video_provider_ice_connection_failed_state',
|
|
|
|
extraInfo: {
|
2021-04-09 10:58:13 +08:00
|
|
|
cameraId: stream,
|
2021-01-21 03:03:12 +08:00
|
|
|
connectionState,
|
2021-01-21 04:25:02 +08:00
|
|
|
role,
|
2021-01-21 03:03:12 +08:00
|
|
|
},
|
2021-01-21 04:25:02 +08:00
|
|
|
}, `Camera ICE connection state changed: ${connectionState}. Role: ${role}.`);
|
2021-06-22 04:59:55 +08:00
|
|
|
if (isLocal) VideoService.notify(intl.formatMessage(intlClientErrors.iceConnectionStateError));
|
2019-11-28 21:13:06 +08:00
|
|
|
|
2021-04-09 10:58:13 +08:00
|
|
|
this._onWebRTCError(error, stream, isLocal);
|
2021-01-21 03:03:12 +08:00
|
|
|
}
|
|
|
|
} else {
|
2019-11-28 21:13:06 +08:00
|
|
|
logger.error({
|
2021-01-28 02:31:17 +08:00
|
|
|
logCode: 'video_provider_ice_connection_nopeer',
|
2021-04-09 10:58:13 +08:00
|
|
|
extraInfo: { cameraId: stream, role },
|
|
|
|
}, `No peer at ICE connection state handler. Camera: ${stream}. Role: ${role}`);
|
2021-01-21 03:03:12 +08:00
|
|
|
}
|
2018-08-13 06:39:39 +08:00
|
|
|
}
|
|
|
|
|
2021-04-09 10:58:13 +08:00
|
|
|
attachVideoStream(stream) {
|
|
|
|
const video = this.videoTags[stream];
|
2021-01-21 03:03:12 +08:00
|
|
|
|
2018-07-10 05:29:27 +08:00
|
|
|
if (video == null) {
|
2019-07-03 03:51:35 +08:00
|
|
|
logger.warn({
|
2019-07-19 04:44:21 +08:00
|
|
|
logCode: 'video_provider_delay_attach_video_stream',
|
2021-04-09 10:58:13 +08:00
|
|
|
extraInfo: { cameraId: stream },
|
2021-01-21 03:03:12 +08:00
|
|
|
}, 'Delaying video stream attachment');
|
2018-07-12 00:32:19 +08:00
|
|
|
return;
|
2018-07-10 05:29:27 +08:00
|
|
|
}
|
|
|
|
|
2021-04-09 10:58:13 +08:00
|
|
|
const isLocal = VideoService.isLocalStream(stream);
|
|
|
|
const peer = this.webRtcPeers[stream];
|
2018-03-20 01:52:39 +08:00
|
|
|
|
2021-01-21 03:03:12 +08:00
|
|
|
if (peer && peer.attached && video.srcObject) {
|
|
|
|
return; // Skip if the stream is already attached
|
|
|
|
}
|
|
|
|
|
2018-05-30 02:54:01 +08:00
|
|
|
const attachVideoStreamHelper = () => {
|
2021-06-22 04:59:55 +08:00
|
|
|
const stream = isLocal ? peer.getLocalStream() : peer.getRemoteStream();
|
2018-04-12 02:50:14 +08:00
|
|
|
video.pause();
|
2021-06-22 04:59:55 +08:00
|
|
|
video.srcObject = stream;
|
2018-04-12 02:50:14 +08:00
|
|
|
video.load();
|
2018-05-23 04:55:24 +08:00
|
|
|
peer.attached = true;
|
2018-04-12 02:50:14 +08:00
|
|
|
};
|
|
|
|
|
2021-01-21 03:03:12 +08:00
|
|
|
// Conditions to safely attach a stream to a video element in all browsers:
|
|
|
|
// 1 - Peer exists
|
|
|
|
// 2 - It hasn't been attached yet
|
|
|
|
// 3a - If the stream is a local one (webcam sharer), we can just attach it
|
|
|
|
// (no need to wait for server confirmation)
|
|
|
|
// 3b - If the stream is a remote one, the safest (*ahem* Safari) moment to
|
|
|
|
// do so is waiting for the server to confirm that media has flown out of it
|
|
|
|
// towards the remote end.
|
|
|
|
const isAbleToAttach = peer && !peer.attached && (peer.started || isLocal);
|
|
|
|
if (isAbleToAttach) attachVideoStreamHelper();
|
2018-02-17 03:18:53 +08:00
|
|
|
}
|
|
|
|
|
2021-04-09 10:58:13 +08:00
|
|
|
createVideoTag(stream, video) {
|
|
|
|
const peer = this.webRtcPeers[stream];
|
|
|
|
this.videoTags[stream] = video;
|
2018-07-10 05:29:27 +08:00
|
|
|
|
2021-01-21 03:03:12 +08:00
|
|
|
if (peer && !peer.attached) {
|
2021-04-09 10:58:13 +08:00
|
|
|
this.attachVideoStream(stream);
|
2018-04-27 06:16:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-09 10:58:13 +08:00
|
|
|
destroyVideoTag(stream) {
|
2021-06-22 04:59:55 +08:00
|
|
|
delete this.videoTags[stream]
|
|
|
|
}
|
|
|
|
|
|
|
|
handlePlayStop(message) {
|
2021-07-08 23:10:22 +08:00
|
|
|
const { intl } = this.props;
|
2021-06-22 04:59:55 +08:00
|
|
|
const { cameraId: stream, role } = message;
|
|
|
|
|
|
|
|
logger.info({
|
|
|
|
logCode: 'video_provider_handle_play_stop',
|
|
|
|
extraInfo: {
|
|
|
|
cameraId: stream,
|
|
|
|
role,
|
|
|
|
},
|
|
|
|
}, `Received request from SFU to stop camera. Role: ${role}`);
|
2021-07-08 23:10:22 +08:00
|
|
|
|
|
|
|
VideoService.notify(intl.formatMessage(intlClientErrors.mediaTimedOutError));
|
2021-06-22 04:59:55 +08:00
|
|
|
this.stopWebRTCPeer(stream, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
handlePlayStart(message) {
|
|
|
|
const { cameraId: stream, role } = message;
|
|
|
|
const peer = this.webRtcPeers[stream];
|
|
|
|
|
|
|
|
if (peer) {
|
|
|
|
logger.info({
|
|
|
|
logCode: 'video_provider_handle_play_start_flowing',
|
|
|
|
extraInfo: {
|
|
|
|
cameraId: stream,
|
|
|
|
role,
|
|
|
|
},
|
|
|
|
}, `Camera media is flowing (server). Role: ${role}`);
|
|
|
|
|
|
|
|
peer.started = true;
|
|
|
|
|
|
|
|
// Clear camera shared timeout when camera succesfully starts
|
|
|
|
this.clearRestartTimers(stream);
|
|
|
|
|
|
|
|
if (!peer.attached) {
|
|
|
|
this.attachVideoStream(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
VideoService.playStart(stream);
|
|
|
|
} else {
|
|
|
|
logger.warn({
|
|
|
|
logCode: 'video_provider_playstart_no_peer',
|
|
|
|
extraInfo: { cameraId: stream, role },
|
|
|
|
}, 'Trailing camera playStart response.');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleSFUError(message) {
|
|
|
|
const { intl } = this.props;
|
|
|
|
const { code, reason, streamId } = message;
|
|
|
|
const isLocal = VideoService.isLocalStream(streamId);
|
|
|
|
const role = VideoService.getRole(isLocal);
|
|
|
|
|
|
|
|
logger.error({
|
|
|
|
logCode: 'video_provider_handle_sfu_error',
|
|
|
|
extraInfo: {
|
|
|
|
errorCode: code,
|
|
|
|
errorReason: reason,
|
|
|
|
cameraId: streamId,
|
|
|
|
role,
|
|
|
|
},
|
|
|
|
}, `SFU returned an error. Code: ${code}, reason: ${reason}`);
|
|
|
|
|
|
|
|
if (isLocal) {
|
|
|
|
// The publisher instance received an error from the server. There's no reconnect,
|
|
|
|
// stop it.
|
|
|
|
VideoService.stopVideo(streamId);
|
|
|
|
VideoService.notify(intl.formatMessage(intlSFUErrors[code] || intlSFUErrors[2200]));
|
|
|
|
} else {
|
|
|
|
this.stopWebRTCPeer(streamId, true);
|
|
|
|
}
|
2018-02-17 03:18:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2021-06-22 04:16:59 +08:00
|
|
|
const {
|
|
|
|
swapLayout,
|
|
|
|
currentVideoPageIndex,
|
|
|
|
streams,
|
|
|
|
cameraDockBounds,
|
|
|
|
} = this.props;
|
2018-04-12 02:50:14 +08:00
|
|
|
|
2018-02-17 03:18:53 +08:00
|
|
|
return (
|
2020-08-19 01:00:47 +08:00
|
|
|
<VideoListContainer
|
2021-06-22 04:16:59 +08:00
|
|
|
{...{
|
|
|
|
streams,
|
|
|
|
swapLayout,
|
|
|
|
currentVideoPageIndex,
|
|
|
|
cameraDockBounds,
|
|
|
|
}}
|
2021-01-21 03:03:12 +08:00
|
|
|
onVideoItemMount={this.createVideoTag}
|
|
|
|
onVideoItemUnmount={this.destroyVideoTag}
|
2018-03-20 01:52:39 +08:00
|
|
|
/>
|
2018-02-17 03:18:53 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-24 06:24:31 +08:00
|
|
|
VideoProvider.propTypes = propTypes;
|
|
|
|
|
2018-03-12 23:29:51 +08:00
|
|
|
export default injectIntl(VideoProvider);
|