Fix webcam recording when changing orientation in a mobile device

This commit is contained in:
Lucas Fialho Zawacki 2018-05-14 18:19:18 +00:00
parent 658b9d81b3
commit 4b2df07667
5 changed files with 69 additions and 3 deletions

View File

@ -89,6 +89,16 @@ class VideoProvider extends Component {
this.pauseViewers = this.pauseViewers.bind(this);
this.unpauseViewers = this.unpauseViewers.bind(this);
this.orientationChange = this.orientationChange.bind(this);
}
orientationChange () {
this.sendMessage({
cameraId: this.props.userId,
id: 'orientationChange',
type: 'video',
role: 'share'
});
}
_sendPauseStream (id, role, state) {
@ -104,7 +114,6 @@ class VideoProvider extends Component {
pauseViewers () {
log("debug", "Calling pause in viewer streams");
Object.keys(this.webRtcPeers).forEach((id) => {
if (this.props.userId !== id) {
this._sendPauseStream(id, 'viewer', true);
@ -137,6 +146,8 @@ class VideoProvider extends Component {
this.visibility.onVisible(this.unpauseViewers);
this.visibility.onHidden(this.pauseViewers);
window.addEventListener('orientationchange', this.orientationChange);
}
componentWillUpdate({ users, userId }) {
@ -164,6 +175,8 @@ class VideoProvider extends Component {
window.removeEventListener('online', this.openWs);
window.removeEventListener('offline', this.onWsClose);
window.removeEventListener('orientationchange', this.orientationChange);
this.visibility.removeEventListeners();
// Unshare user webcam

View File

@ -110,9 +110,9 @@ module.exports = class MCSApiStub extends EventEmitter {
}
}
async stopRecording(mediaId) {
async stopRecording(userId, sourceId, recId) {
try {
let answer = await this._mediaController.stopRecording(mediaId);
let answer = await this._mediaController.stopRecording(userId, sourceId, recId);
return Promise.resolve(answer);
}
catch (err) {

View File

@ -286,6 +286,8 @@ module.exports = class MediaController {
await sourceSession.connect(session._mediaElement);
sourceSession.subscribedSessions.push(session.id);
this._mediaSessions[session.id] = session;
return Promise.resolve(answer);
}
catch (err) {
@ -299,6 +301,35 @@ module.exports = class MediaController {
}
}
async stopRecording (userId, sourceId, recId) {
Logger.info("[mcs-controller] stopRecording ", recId);
const user = await this.getUserMCS(userId);
let answer;
let recSession = this._mediaSessions[recId];
let sourceSession = this._mediaSessions[sourceId];
if (!recSession) {
return Promise.reject(new Error("[mcs-controller] Recording session", recId, "was not found"));
}
if (!sourceSession) {
return Promise.reject(new Error("[mcs-controller] Media session", sourceId, "was not found"));
}
try {
answer = await user.stopSession(recSession.id);
user.unsubscribe(recSession.id);
this._mediaSessions[recId] = null;
return Promise.resolve(answer);
}
catch (err) {
err = this._handleError(err);
return Promise.reject(err);
}
}
async connect (sourceId, sinkId, type) {
Logger.info("[mcs-controller] Connect", sourceId, "to", sinkId, "with type", type);

View File

@ -112,6 +112,11 @@ module.exports = class VideoManager extends BaseManager {
this._stopSession(sessionId);
break;
case 'orientationChange':
if (video) {
video.orientationChange();
}
case 'pause':
if (video) {
video.pause(message.state);

View File

@ -195,6 +195,12 @@ module.exports = class Video extends EventEmitter {
this.sendStartShareEvent();
}
async stopRecording() {
await this.mcs.stopRecording(this.userId, this.mediaId, this.recording.recordingId);
this.sendStopShareEvent();
this.recording = {};
}
async start (sdpOffer, callback) {
Logger.info("[video] Starting video instance for", this.streamName);
let sdpAnswer;
@ -264,6 +270,17 @@ module.exports = class Video extends EventEmitter {
}
async orientationChange () {
Logger.info("[video] Orientation change");
if (this.isRecorded) {
Logger.info("[video] Flipped the screen, restart recording");
await this.stopRecording();
await this.startRecording();
} else {
Logger.info("[video] Not recording do nothing");
}
}
sendStartShareEvent() {
let shareCamEvent = Messaging.generateWebRTCShareEvent('StartWebRTCShareEvent', this.meetingId, this.recording.filename);
this.bbbGW.writeMeetingKey(this.meetingId, shareCamEvent, function(error) {});