From 1ba5e3ebad1d5e6ac930bbb5eec9c8cf3a1b550a Mon Sep 17 00:00:00 2001 From: Mac Date: Tue, 10 Apr 2018 16:13:11 +0800 Subject: [PATCH] 1. modify screen share, request screen => initScreenPublisher => publish(screenPublisher) 2. detect screen share stopped by user --- openvidu-browser/ts/OpenVidu/OpenVidu.ts | 64 +++++++++++++++++++ openvidu-browser/ts/OpenVidu/Publisher.ts | 9 +++ .../ts/OpenViduInternal/Stream.ts | 4 ++ .../ts/OpenViduInternal/WebRtcStats.ts | 2 +- 4 files changed, 78 insertions(+), 1 deletion(-) diff --git a/openvidu-browser/ts/OpenVidu/OpenVidu.ts b/openvidu-browser/ts/OpenVidu/OpenVidu.ts index 259a735d..200c96bc 100644 --- a/openvidu-browser/ts/OpenVidu/OpenVidu.ts +++ b/openvidu-browser/ts/OpenVidu/OpenVidu.ts @@ -192,6 +192,70 @@ export class OpenVidu { } } + requestScreen(cameraOptions?: any, callback?: Function) { + if (DetectRTC.browser.name === 'Firefox' && DetectRTC.browser.version >= 52) { + screenSharingAuto.getScreenId((error, sourceId, screenConstraints) => { + cameraOptions = { + sendAudio: cameraOptions.audio, + sendVideo: cameraOptions.video, + activeAudio: cameraOptions.audioActive != null ? cameraOptions.audioActive : true, + activeVideo: cameraOptions.videoActive != null ? cameraOptions.videoActive : true, + dataChannel: true, + mediaConstraints: { + video: screenConstraints.video, + audio: false + } + } + if (callback) { + callback(cameraOptions); + } + }); + + + }else if (DetectRTC.browser.name === 'Chrome') { + screenSharingAuto.getScreenId((error, sourceId, screenConstraints) => { + if (error === 'not-installed') { + let error = new OpenViduError(OpenViduErrorName.SCREEN_EXTENSION_NOT_INSTALLED, 'https://chrome.google.com/webstore/detail/screen-capturing/ajhifddimkapgcifgcodmmfdlknahffk'); + console.error(error); + if (callback) callback('not-installed'); + return; + }else if (error === 'permission-denied') { + let error = new OpenViduError(OpenViduErrorName.SCREEN_CAPTURE_DENIED, 'You must allow access to one window of your desktop'); + console.error(error); + if (callback) callback('permission-denied'); + return; + } else { + cameraOptions = { + sendAudio: cameraOptions.audio != null ? cameraOptions.audio : true, + sendVideo: cameraOptions.video != null ? cameraOptions.video : true, + activeAudio: cameraOptions.audioActive != null ? cameraOptions.audioActive : true, + activeVideo: cameraOptions.videoActive != null ? cameraOptions.videoActive : true, + dataChannel: true, + mediaConstraints: { + video: screenConstraints.video, + audio: false + } + } + if (callback) { + callback(cameraOptions); + } + } + }, (error) => { + console.error('getScreenId error', error); + return; + }); + + } + + } + + initScreenPublisher(parentId: string, cameraOptions: any, callback?: Function): any{ + let publisher = new Publisher(this.openVidu.initPublisherScreen(parentId, true, callback), parentId, true); + publisher.stream.configureScreenOptions(cameraOptions); + publisher.stream.ee.emitEvent('can-request-screen'); + return publisher; + } + reinitPublisher(publisher: Publisher): any { if (publisher.stream.typeOfVideo !== 'SCREEN') { publisher = new Publisher(this.openVidu.initPublisherTagged(publisher.stream.getParentId(), publisher.stream.outboundOptions, false), publisher.stream.getParentId(), false); diff --git a/openvidu-browser/ts/OpenVidu/Publisher.ts b/openvidu-browser/ts/OpenVidu/Publisher.ts index 946ce9ce..f3f7f99b 100644 --- a/openvidu-browser/ts/OpenVidu/Publisher.ts +++ b/openvidu-browser/ts/OpenVidu/Publisher.ts @@ -144,5 +144,14 @@ export class Publisher { }); } } + if (eventName == 'screen-stopped-by-user') { + if (this.stream.isScreenRequestedReady) { + this.ee.emitEvent('screen-stopped-by-user'); + } else { + this.stream.addEventListener('screen-stopped-by-user', () => { + this.ee.emitEvent('screen-stopped-by-user'); + }); + } + } } } \ No newline at end of file diff --git a/openvidu-browser/ts/OpenViduInternal/Stream.ts b/openvidu-browser/ts/OpenViduInternal/Stream.ts index 3abc66ea..a2b3d11a 100644 --- a/openvidu-browser/ts/OpenViduInternal/Stream.ts +++ b/openvidu-browser/ts/OpenViduInternal/Stream.ts @@ -543,6 +543,10 @@ export class Stream { // FIXME: Throw error when stream is not local if (this.isReadyToPublish) { this.initWebRtcPeer(this.publishVideoCallback); + let that = this; + this.mediaStream.getVideoTracks()[0].onended = function() { + that.ee.emitEvent('screen-stopped-by-user'); + } } else { this.ee.once('stream-ready', streamEvent => { this.publish(); diff --git a/openvidu-browser/ts/OpenViduInternal/WebRtcStats.ts b/openvidu-browser/ts/OpenViduInternal/WebRtcStats.ts index de2e596c..4997ce30 100644 --- a/openvidu-browser/ts/OpenViduInternal/WebRtcStats.ts +++ b/openvidu-browser/ts/OpenViduInternal/WebRtcStats.ts @@ -5,7 +5,7 @@ import * as DetectRTC from '../KurentoUtils/DetectRTC'; export class WebRtcStats { private webRtcStatsEnabled: boolean = false; - private webRtcStatsIntervalId: number; + private webRtcStatsIntervalId: any; private statsInterval: number = 1; private stats: any = { "inbound": {