2017-06-04 10:40:14 +08:00
|
|
|
import React, { Component } from 'react';
|
2017-07-25 03:29:34 +08:00
|
|
|
import ScreenshareContainer from '/imports/ui/components/screenshare/container';
|
2017-10-12 01:54:00 +08:00
|
|
|
import styles from './styles';
|
2017-11-18 02:55:59 +08:00
|
|
|
import { log } from '/imports/ui/services/api';
|
|
|
|
|
2016-05-04 04:40:46 +08:00
|
|
|
|
2017-11-06 23:42:00 +08:00
|
|
|
class VideoElement extends Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2017-09-01 23:26:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-04 04:40:46 +08:00
|
|
|
export default class VideoDock extends Component {
|
2017-09-01 23:26:57 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
2017-12-09 00:35:46 +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 = [];
|
|
|
|
this.webRtcPeers = {};
|
2017-12-15 03:09:45 +08:00
|
|
|
this.reconnectWebcam = false;
|
|
|
|
this.reconnectList = false;
|
|
|
|
this.sharedCameraTimeout = null;
|
|
|
|
this.subscribedCamerasTimeouts = [];
|
|
|
|
|
2017-09-01 23:26:57 +08:00
|
|
|
this.state = {
|
2017-12-15 02:42:13 +08:00
|
|
|
videos: {},
|
2017-09-01 23:26:57 +08:00
|
|
|
};
|
|
|
|
|
2017-12-15 03:09:45 +08:00
|
|
|
this.ws.addEventListener('open', () => {
|
2017-12-06 03:13:42 +08:00
|
|
|
log('debug', '------ Websocket connection opened.');
|
2017-12-02 07:40:25 +08:00
|
|
|
|
|
|
|
// -- Resend queued messages that happened when socket was not connected
|
2017-12-15 03:09:45 +08:00
|
|
|
while (this.wsQueue.length > 0) {
|
|
|
|
this.sendMessage(this.wsQueue.pop());
|
2017-10-13 03:47:36 +08:00
|
|
|
}
|
2017-12-02 07:40:25 +08:00
|
|
|
|
|
|
|
this.reconnectVideos();
|
|
|
|
});
|
|
|
|
|
2017-12-15 03:09:45 +08:00
|
|
|
this.ws.addEventListener('close', (error) => {
|
2017-12-06 03:13:42 +08:00
|
|
|
log('debug', '------ Websocket connection closed.');
|
2017-12-02 07:40:25 +08:00
|
|
|
|
|
|
|
this.setupReconnectVideos();
|
|
|
|
});
|
2017-10-13 03:47:36 +08:00
|
|
|
|
2017-09-01 23:26:57 +08:00
|
|
|
this.sendUserShareWebcam = props.sendUserShareWebcam.bind(this);
|
|
|
|
this.sendUserUnshareWebcam = props.sendUserUnshareWebcam.bind(this);
|
|
|
|
|
|
|
|
this.unshareWebcam = this.unshareWebcam.bind(this);
|
|
|
|
this.shareWebcam = this.shareWebcam.bind(this);
|
|
|
|
}
|
|
|
|
|
2017-12-02 07:40:25 +08:00
|
|
|
setupReconnectVideos() {
|
2017-12-15 03:09:45 +08:00
|
|
|
for (id in this.webRtcPeers) {
|
2017-12-02 07:40:25 +08:00
|
|
|
this.disconnected(id);
|
|
|
|
this.stop(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
reconnectVideos() {
|
2017-12-15 03:09:45 +08:00
|
|
|
for (i in this.reconnectList) {
|
|
|
|
const id = this.reconnectList[i];
|
2017-12-02 07:40:25 +08:00
|
|
|
|
2017-12-15 02:42:13 +08:00
|
|
|
// TODO: base this on BBB API users instead of using memory
|
2017-12-15 03:09:45 +08:00
|
|
|
if (id != this.myId) {
|
2017-12-15 02:42:13 +08:00
|
|
|
setTimeout(() => {
|
|
|
|
log('debug', ` [camera] Trying to reconnect camera ${id}`);
|
|
|
|
this.start(id, false, this.refs.videoInput);
|
|
|
|
}, 5000);
|
2017-12-02 07:40:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-15 03:09:45 +08:00
|
|
|
if (this.reconnectWebcam) {
|
|
|
|
log('debug', ` [camera] Trying to re-share ${this.myId} after reconnect.`);
|
|
|
|
this.start(this.myId, true, this.refs.videoInput);
|
2017-12-02 07:40:25 +08:00
|
|
|
}
|
|
|
|
|
2017-12-15 03:09:45 +08:00
|
|
|
this.reconnectWebcam = false;
|
|
|
|
this.reconnectList = [];
|
2017-12-02 07:40:25 +08:00
|
|
|
}
|
|
|
|
|
2017-09-01 23:26:57 +08:00
|
|
|
componentDidMount() {
|
2017-12-09 00:35:46 +08:00
|
|
|
const ws = this.ws;
|
2017-09-20 00:29:48 +08:00
|
|
|
const { users } = this.props;
|
|
|
|
for (let i = 0; i < users.length; i++) {
|
|
|
|
if (users[i].has_stream) {
|
2017-10-13 03:47:36 +08:00
|
|
|
this.start(users[i].userId, false, this.refs.videoInput);
|
2017-09-20 00:29:48 +08:00
|
|
|
}
|
|
|
|
}
|
2017-09-01 23:26:57 +08:00
|
|
|
|
2017-12-09 00:35:46 +08:00
|
|
|
document.addEventListener('joinVideo', this.shareWebcam.bind(this));// TODO find a better way to do this
|
|
|
|
document.addEventListener('exitVideo', this.unshareWebcam.bind(this));
|
2017-09-20 11:12:10 +08:00
|
|
|
|
2017-12-09 00:35:46 +08:00
|
|
|
window.addEventListener('resize', this.adjustVideos);
|
2017-09-01 23:26:57 +08:00
|
|
|
|
2017-12-09 00:35:46 +08:00
|
|
|
ws.addEventListener('message', this.onWsMessage.bind(this));
|
|
|
|
}
|
2017-09-01 23:26:57 +08:00
|
|
|
|
2017-12-09 00:35:46 +08:00
|
|
|
componentWillMount () {
|
|
|
|
this.ws.onopen = () => {
|
|
|
|
while (this.wsQueue.length > 0) {
|
|
|
|
this.sendMessage(this.wsQueue.pop());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2017-09-01 23:26:57 +08:00
|
|
|
|
2017-12-09 00:35:46 +08:00
|
|
|
componentWillUnmount () {
|
|
|
|
document.removeEventListener('joinVideo', this.shareWebcam);
|
|
|
|
document.removeEventListener('exitVideo', this.shareWebcam);
|
|
|
|
window.removeEventListener('resize', this.adjustVideos);
|
|
|
|
this.ws.removeEventListener('message', this.onWsMessage);
|
|
|
|
}
|
2017-09-01 23:26:57 +08:00
|
|
|
|
2017-12-09 00:35:46 +08:00
|
|
|
adjustVideos () {
|
|
|
|
window.adjustVideos('webcamArea', true);
|
|
|
|
}
|
2017-09-01 23:26:57 +08:00
|
|
|
|
2017-12-09 00:35:46 +08:00
|
|
|
onWsMessage (msg) {
|
|
|
|
const parsedMessage = JSON.parse(msg.data);
|
2017-09-01 23:26:57 +08:00
|
|
|
|
2017-12-09 00:35:46 +08:00
|
|
|
console.log('Received message new ws message: ');
|
|
|
|
console.log(parsedMessage);
|
2017-09-01 23:26:57 +08:00
|
|
|
|
2017-12-09 00:35:46 +08:00
|
|
|
switch (parsedMessage.id) {
|
2017-09-01 23:26:57 +08:00
|
|
|
|
2017-12-09 00:35:46 +08:00
|
|
|
case 'startResponse':
|
|
|
|
this.startResponse(parsedMessage);
|
|
|
|
break;
|
2017-09-01 23:26:57 +08:00
|
|
|
|
2017-12-09 00:35:46 +08:00
|
|
|
case 'error':
|
|
|
|
this.handleError(parsedMessage);
|
|
|
|
break;
|
2017-12-15 02:42:13 +08:00
|
|
|
|
2017-12-09 00:35:46 +08:00
|
|
|
case 'playStart':
|
|
|
|
this.handlePlayStart(parsedMessage);
|
|
|
|
break;
|
2017-12-15 02:42:13 +08:00
|
|
|
|
2017-12-09 00:35:46 +08:00
|
|
|
case 'playStop':
|
|
|
|
this.handlePlayStop(parsedMessage);
|
2017-09-01 23:26:57 +08:00
|
|
|
|
2017-12-09 00:35:46 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'iceCandidate':
|
|
|
|
|
|
|
|
const webRtcPeer = this.webRtcPeers[parsedMessage.cameraId];
|
|
|
|
|
|
|
|
if (webRtcPeer !== null) {
|
|
|
|
if (webRtcPeer.didSDPAnswered) {
|
|
|
|
webRtcPeer.addIceCandidate(parsedMessage.candidate, (err) => {
|
|
|
|
if (err) {
|
|
|
|
return log('error', `Error adding candidate: ${err}`);
|
|
|
|
}
|
|
|
|
});
|
2017-09-01 23:26:57 +08:00
|
|
|
} else {
|
2017-12-09 00:35:46 +08:00
|
|
|
webRtcPeer.iceQueue.push(parsedMessage.candidate);
|
2017-09-01 23:26:57 +08:00
|
|
|
}
|
2017-12-09 00:35:46 +08:00
|
|
|
} else {
|
|
|
|
log('error', ' [ICE] Message arrived before webRtcPeer?');
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
2017-09-01 23:26:57 +08:00
|
|
|
|
|
|
|
start(id, shareWebcam, videoInput) {
|
|
|
|
const that = this;
|
|
|
|
|
2017-12-09 00:35:46 +08:00
|
|
|
const ws = this.ws;
|
2017-09-01 23:26:57 +08:00
|
|
|
|
2017-11-25 02:59:40 +08:00
|
|
|
console.log(`Starting video call for video: ${id}`);
|
2017-11-18 02:55:59 +08:00
|
|
|
log('info', 'Creating WebRtcPeer and generating local sdp offer ...');
|
2017-09-01 23:26:57 +08:00
|
|
|
|
|
|
|
const onIceCandidate = function (candidate) {
|
|
|
|
const message = {
|
2017-11-25 02:59:40 +08:00
|
|
|
type: 'video',
|
2017-12-06 03:13:42 +08:00
|
|
|
role: shareWebcam ? 'share' : 'viewer',
|
2017-09-01 23:26:57 +08:00
|
|
|
id: 'onIceCandidate',
|
|
|
|
candidate,
|
|
|
|
cameraId: id,
|
|
|
|
};
|
|
|
|
that.sendMessage(message);
|
|
|
|
};
|
|
|
|
|
2017-11-29 03:31:36 +08:00
|
|
|
var videoConstraints = {};
|
|
|
|
if (!!navigator.userAgent.match(/Version\/[\d\.]+.*Safari/)) { // Custom constraints for Safari
|
|
|
|
videoConstraints = {
|
|
|
|
width: {min:320, max:640},
|
|
|
|
height: {min:240, max:480}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
videoConstraints = {
|
|
|
|
width: {min: 320, ideal: 320},
|
|
|
|
height: {min: 240, ideal:240},
|
|
|
|
frameRate: {min: 5, ideal: 10}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-09-01 23:26:57 +08:00
|
|
|
const options = {
|
2017-12-06 03:13:42 +08:00
|
|
|
mediaConstraints: {
|
|
|
|
audio: false,
|
2017-11-29 03:31:36 +08:00
|
|
|
video: videoConstraints
|
2017-11-06 23:42:00 +08:00
|
|
|
},
|
2017-09-01 23:26:57 +08:00
|
|
|
onicecandidate: onIceCandidate,
|
|
|
|
};
|
|
|
|
|
|
|
|
let peerObj;
|
|
|
|
if (shareWebcam) {
|
|
|
|
options.localVideo = videoInput;
|
|
|
|
peerObj = kurentoUtils.WebRtcPeer.WebRtcPeerSendonly;
|
|
|
|
} else {
|
|
|
|
peerObj = kurentoUtils.WebRtcPeer.WebRtcPeerRecvonly;
|
|
|
|
|
2017-12-06 03:13:42 +08:00
|
|
|
options.remoteVideo = this.createVideoTag(id);
|
2017-09-01 23:26:57 +08:00
|
|
|
document.getElementById('webcamArea').appendChild(options.remoteVideo);
|
|
|
|
}
|
|
|
|
|
2017-12-15 03:09:45 +08:00
|
|
|
var webRtcPeer = new peerObj(options, function (error) {
|
2017-09-01 23:26:57 +08:00
|
|
|
if (error) {
|
2017-12-06 03:13:42 +08:00
|
|
|
log('error', ' WebRTC peerObj create error');
|
|
|
|
|
|
|
|
that.destroyWebRTCPeer(id);
|
|
|
|
that.destroyVideoTag(id);
|
|
|
|
|
|
|
|
return log('error', error);
|
2017-09-01 23:26:57 +08:00
|
|
|
}
|
|
|
|
|
2017-11-29 03:31:36 +08:00
|
|
|
this.didSDPAnswered = false;
|
|
|
|
this.iceQueue = [];
|
|
|
|
|
2017-12-15 03:09:45 +08:00
|
|
|
that.webRtcPeers[id] = webRtcPeer;
|
2017-10-14 05:13:41 +08:00
|
|
|
if (shareWebcam) {
|
2017-12-15 03:09:45 +08:00
|
|
|
that.sharedWebcam = webRtcPeer;
|
2017-12-09 00:35:46 +08:00
|
|
|
that.myId = id;
|
2017-10-14 05:13:41 +08:00
|
|
|
}
|
|
|
|
|
2017-09-01 23:26:57 +08:00
|
|
|
this.generateOffer((error, offerSdp) => {
|
|
|
|
if (error) {
|
2017-12-06 03:13:42 +08:00
|
|
|
log('error', ' WebRtc generate offer error');
|
|
|
|
|
|
|
|
that.destroyWebRTCPeer(id);
|
|
|
|
that.destroyVideoTag(id);
|
|
|
|
|
2017-11-18 02:55:59 +08:00
|
|
|
return log('error', error);
|
2017-09-01 23:26:57 +08:00
|
|
|
}
|
|
|
|
|
2017-11-25 02:59:40 +08:00
|
|
|
console.log(`Invoking SDP offer callback function ${location.host}`);
|
2017-09-01 23:26:57 +08:00
|
|
|
const message = {
|
2017-11-25 02:59:40 +08:00
|
|
|
type: 'video',
|
2017-12-06 03:13:42 +08:00
|
|
|
role: shareWebcam ? 'share' : 'viewer',
|
2017-09-01 23:26:57 +08:00
|
|
|
id: 'start',
|
|
|
|
sdpOffer: offerSdp,
|
|
|
|
cameraId: id,
|
|
|
|
cameraShared: shareWebcam,
|
|
|
|
};
|
|
|
|
that.sendMessage(message);
|
|
|
|
});
|
2017-11-29 03:31:36 +08:00
|
|
|
while (this.iceQueue.length) {
|
|
|
|
var candidate = this.iceQueue.shift();
|
|
|
|
this.addIceCandidate(candidate, (err) => {
|
|
|
|
if (err) {
|
|
|
|
return console.error(`Error adding candidate: ${err}`);
|
2017-12-06 03:58:58 +08:00
|
|
|
}
|
2017-11-29 03:31:36 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
this.didSDPAnswered = true;
|
2017-09-01 23:26:57 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-12-02 07:40:25 +08:00
|
|
|
disconnected(id) {
|
2017-12-15 03:09:45 +08:00
|
|
|
if (this.sharedWebcam) {
|
2017-12-15 02:42:13 +08:00
|
|
|
log('debug', ' [camera] Webcam disconnected, will try re-share webcam later.');
|
2017-12-15 03:09:45 +08:00
|
|
|
this.reconnectWebcam = true;
|
2017-12-02 07:40:25 +08:00
|
|
|
} else {
|
2017-12-15 03:09:45 +08:00
|
|
|
this.reconnectList.push(id);
|
2017-12-02 07:40:25 +08:00
|
|
|
|
2017-12-06 03:13:42 +08:00
|
|
|
log('debug', ` [camera] ${id} disconnected, will try re-subscribe later.`);
|
2017-12-02 07:40:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-01 23:26:57 +08:00
|
|
|
stop(id) {
|
2017-11-06 23:42:00 +08:00
|
|
|
const { users } = this.props;
|
|
|
|
if (id == users[0].userId) {
|
|
|
|
this.unshareWebcam();
|
|
|
|
}
|
2017-12-06 03:13:42 +08:00
|
|
|
|
|
|
|
this.destroyWebRTCPeer(id);
|
|
|
|
this.destroyVideoTag(id);
|
|
|
|
|
|
|
|
this.sendMessage({
|
|
|
|
type: 'video',
|
|
|
|
role: 'any',
|
|
|
|
id: 'stop',
|
|
|
|
cameraId: id,
|
|
|
|
});
|
|
|
|
|
|
|
|
window.adjustVideos('webcamArea', true);
|
|
|
|
}
|
|
|
|
|
|
|
|
createVideoTag(id) {
|
|
|
|
let remoteVideo = {};
|
|
|
|
remoteVideo = document.createElement('video');
|
|
|
|
remoteVideo.id = `video-elem-${id}`;
|
|
|
|
remoteVideo.width = 320;
|
|
|
|
remoteVideo.height = 240;
|
|
|
|
remoteVideo.autoplay = true;
|
|
|
|
remoteVideo.playsinline = true;
|
|
|
|
|
|
|
|
document.getElementById('webcamArea').appendChild(remoteVideo);
|
|
|
|
|
|
|
|
return remoteVideo;
|
|
|
|
}
|
|
|
|
|
|
|
|
destroyVideoTag(id) {
|
|
|
|
const videoTag = document.getElementById(`video-elem-${id}`);
|
|
|
|
if (videoTag) {
|
|
|
|
document.getElementById('webcamArea').removeChild(videoTag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
destroyWebRTCPeer(id) {
|
2017-12-09 00:35:46 +08:00
|
|
|
const webRtcPeer = this.webRtcPeers[id];
|
2017-09-01 23:26:57 +08:00
|
|
|
|
|
|
|
if (webRtcPeer) {
|
2017-11-18 02:55:59 +08:00
|
|
|
log('info', 'Stopping WebRTC peer');
|
2017-09-01 23:26:57 +08:00
|
|
|
|
2017-12-15 03:09:45 +08:00
|
|
|
if (id == this.myId && this.sharedWebcam) {
|
2017-12-09 00:35:46 +08:00
|
|
|
this.sharedWebcam.dispose();
|
|
|
|
this.sharedWebcam = null;
|
2017-10-14 05:13:41 +08:00
|
|
|
}
|
|
|
|
|
2017-09-01 23:26:57 +08:00
|
|
|
webRtcPeer.dispose();
|
2017-12-09 00:35:46 +08:00
|
|
|
delete this.webRtcPeers[id];
|
2017-09-01 23:26:57 +08:00
|
|
|
} else {
|
2017-12-06 03:13:42 +08:00
|
|
|
log('info', 'No WebRTC peer to stop (not an error)');
|
2017-09-01 23:26:57 +08:00
|
|
|
}
|
|
|
|
|
2017-12-15 03:09:45 +08:00
|
|
|
if (this.sharedWebcam) {
|
|
|
|
this.sharedWebcam.dispose();
|
|
|
|
this.sharedWebcam = null;
|
2017-12-06 03:13:42 +08:00
|
|
|
} else {
|
|
|
|
log('info', 'No shared camera WebRTC peer to stop (not an error)');
|
2017-09-01 23:26:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
shareWebcam() {
|
|
|
|
const { users } = this.props;
|
2017-09-19 21:53:27 +08:00
|
|
|
const id = users[0].userId;
|
2017-09-01 23:26:57 +08:00
|
|
|
|
2017-12-15 02:42:13 +08:00
|
|
|
if (this.connectedToMediaServer()) {
|
|
|
|
this.start(id, true, this.refs.videoInput);
|
|
|
|
} else {
|
|
|
|
log("error", "Not connected to media server BRA");
|
|
|
|
}
|
|
|
|
|
2017-09-01 23:26:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
unshareWebcam() {
|
2017-12-06 03:13:42 +08:00
|
|
|
log('info', 'Unsharing webcam');
|
2017-09-19 21:53:27 +08:00
|
|
|
const { users } = this.props;
|
|
|
|
const id = users[0].userId;
|
|
|
|
this.sendUserUnshareWebcam(id);
|
2017-09-01 23:26:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
startResponse(message) {
|
|
|
|
const id = message.cameraId;
|
2017-12-09 00:35:46 +08:00
|
|
|
const webRtcPeer = this.webRtcPeers[id];
|
2017-09-01 23:26:57 +08:00
|
|
|
|
|
|
|
if (message.sdpAnswer == null) {
|
2017-11-18 02:55:59 +08:00
|
|
|
return log('debug', 'Null sdp answer. Camera unplugged?');
|
2017-09-01 23:26:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (webRtcPeer == null) {
|
2017-11-18 02:55:59 +08:00
|
|
|
return log('debug', 'Null webrtc peer ????');
|
2017-09-01 23:26:57 +08:00
|
|
|
}
|
|
|
|
|
2017-11-18 02:55:59 +08:00
|
|
|
log('info', 'SDP answer received from server. Processing ...');
|
2017-09-01 23:26:57 +08:00
|
|
|
|
|
|
|
webRtcPeer.processAnswer(message.sdpAnswer, (error) => {
|
|
|
|
if (error) {
|
2017-12-06 03:13:42 +08:00
|
|
|
return log('error', error);
|
2017-09-01 23:26:57 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-09-19 21:53:27 +08:00
|
|
|
this.sendUserShareWebcam(id);
|
2017-09-01 23:26:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
sendMessage(message) {
|
2017-12-09 00:35:46 +08:00
|
|
|
const ws = this.ws;
|
2017-09-01 23:26:57 +08:00
|
|
|
|
2017-12-02 07:40:25 +08:00
|
|
|
if (this.connectedToMediaServer()) {
|
2017-10-13 03:47:36 +08:00
|
|
|
const jsonMessage = JSON.stringify(message);
|
2017-11-25 02:59:40 +08:00
|
|
|
console.log(`Sending message: ${jsonMessage}`);
|
2017-10-13 03:47:36 +08:00
|
|
|
ws.send(jsonMessage, (error) => {
|
|
|
|
if (error) {
|
2017-11-25 02:59:40 +08:00
|
|
|
console.error(`client: Websocket error "${error}" on message "${jsonMessage.id}"`);
|
2017-10-13 03:47:36 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
2017-12-02 07:40:25 +08:00
|
|
|
// No need to queue video stop messages
|
2017-12-06 03:13:42 +08:00
|
|
|
if (message.id != 'stop') {
|
2017-12-15 03:09:45 +08:00
|
|
|
this.wsQueue.push(message);
|
2017-12-02 07:40:25 +08:00
|
|
|
}
|
2017-10-13 03:47:36 +08:00
|
|
|
}
|
2017-09-01 23:26:57 +08:00
|
|
|
}
|
|
|
|
|
2017-12-02 07:40:25 +08:00
|
|
|
connectedToMediaServer() {
|
2017-12-15 03:09:45 +08:00
|
|
|
return this.ws.readyState === WebSocket.OPEN;
|
2017-12-02 07:40:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
connectionStatus() {
|
2017-12-15 03:09:45 +08:00
|
|
|
return this.ws.readyState;
|
2017-12-02 07:40:25 +08:00
|
|
|
}
|
|
|
|
|
2017-09-01 23:26:57 +08:00
|
|
|
handlePlayStop(message) {
|
2017-11-18 02:55:59 +08:00
|
|
|
log('info', 'Handle play stop <--------------------');
|
2017-12-15 02:42:13 +08:00
|
|
|
log('error', message);
|
2017-09-01 23:26:57 +08:00
|
|
|
|
|
|
|
this.stop(message.cameraId);
|
|
|
|
}
|
|
|
|
|
|
|
|
handlePlayStart(message) {
|
2017-11-18 02:55:59 +08:00
|
|
|
log('info', 'Handle play start <===================');
|
2017-09-01 23:26:57 +08:00
|
|
|
|
2017-11-06 23:42:00 +08:00
|
|
|
window.adjustVideos('webcamArea', true);
|
2017-09-01 23:26:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
handleError(message) {
|
2017-12-06 03:13:42 +08:00
|
|
|
console.error(' Handle error --------------------->');
|
|
|
|
log('debug', message.message);
|
2017-09-01 23:26:57 +08:00
|
|
|
}
|
|
|
|
|
2016-05-04 04:40:46 +08:00
|
|
|
render() {
|
|
|
|
return (
|
2017-09-01 23:26:57 +08:00
|
|
|
|
2016-05-04 04:40:46 +08:00
|
|
|
<div className={styles.videoDock}>
|
2017-09-01 23:26:57 +08:00
|
|
|
<div id="webcamArea" />
|
|
|
|
<video id="shareWebcamVideo" className={styles.sharedWebcamVideo} ref="videoInput" />
|
2016-05-04 04:40:46 +08:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2017-09-01 23:26:57 +08:00
|
|
|
|
2017-12-02 07:40:25 +08:00
|
|
|
componentWillUnmount() {
|
|
|
|
// Close websocket connection to prevent multiple reconnects from happening
|
2017-12-15 03:09:45 +08:00
|
|
|
this.ws.close();
|
2017-12-02 07:40:25 +08:00
|
|
|
|
2017-12-15 03:09:45 +08:00
|
|
|
this.ws.removeEventListener('message', () => {});
|
2017-12-02 07:40:25 +08:00
|
|
|
}
|
|
|
|
|
2017-09-01 23:26:57 +08:00
|
|
|
shouldComponentUpdate(nextProps, nextState) {
|
|
|
|
const { users } = this.props;
|
|
|
|
const nextUsers = nextProps.users;
|
|
|
|
|
|
|
|
if (users) {
|
|
|
|
let suc = false;
|
|
|
|
|
|
|
|
for (let i = 0; i < users.length; i++) {
|
2017-09-19 21:53:27 +08:00
|
|
|
if (users && users[i] &&
|
|
|
|
nextUsers && nextUsers[i]) {
|
|
|
|
if (users[i].has_stream !== nextUsers[i].has_stream) {
|
2017-11-25 02:59:40 +08:00
|
|
|
console.log(`User ${nextUsers[i].has_stream ? '' : 'un'}shared webcam ${users[i].userId}`);
|
2017-09-01 23:26:57 +08:00
|
|
|
|
2017-09-19 21:53:27 +08:00
|
|
|
if (nextUsers[i].has_stream) {
|
|
|
|
this.start(users[i].userId, false, this.refs.videoInput);
|
2017-09-01 23:26:57 +08:00
|
|
|
} else {
|
2017-09-19 21:53:27 +08:00
|
|
|
this.stop(users[i].userId);
|
2017-09-01 23:26:57 +08:00
|
|
|
}
|
|
|
|
|
2017-12-15 02:42:13 +08:00
|
|
|
if (!nextUsers[i].has_stream) {
|
|
|
|
console.log(" DESTROYING ----------------------- " + users[i].userId);
|
|
|
|
this.destroyVideoTag(users[i].userId);
|
|
|
|
}
|
|
|
|
|
2017-09-01 23:26:57 +08:00
|
|
|
suc = suc || true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-04 04:40:46 +08:00
|
|
|
}
|