From b63b99710af7590a93c2b71b72231d903806e06a Mon Sep 17 00:00:00 2001 From: pabloFuente Date: Thu, 9 Mar 2017 19:46:07 +0100 Subject: [PATCH] Join session with audio and/or video off. Toggle both during session --- README.md | 14 ++-- .../src/main/resources/ts/Participant.ts | 3 +- .../src/main/resources/ts/Stream.ts | 16 +++++ .../src/app/app.component.html | 10 +++ openvidu-ng-testapp/src/app/app.component.ts | 67 ++++++++++++++++--- openvidu-server/pom.xml | 15 +++++ 6 files changed, 111 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 82f4cdb9..b34f325b 100644 --- a/README.md +++ b/README.md @@ -90,8 +90,15 @@ mvn install -DskipTests=true ``` **/openvidu/openvidu-server** ``` -mvn compile exec:java -Dexec.mainClass="org.openvidu.server.OpenViduServer" +mvn compile exec:java ``` + +*(or if you prefer you can just run the Java application in your favourite IDE)* + + +---------- + + At these point, you can start modifying *openvidu-ng-testapp*, *openvidu-browser* or *openvidu-server*. - *openvidu-ng-testapp*: the previous "ng serve" command will take care of refreshing the browser's page whenever any change takes place. @@ -105,7 +112,6 @@ At these point, you can start modifying *openvidu-ng-testapp*, *openvidu-browser **/openvidu/openvidu-server** ``` - mvn compile exec:java -Dexec.mainClass="org.openvidu.server.OpenViduServer" + mvn compile exec:java ``` - - +*(or re-launch the Java application in your IDE)* diff --git a/openvidu-browser/src/main/resources/ts/Participant.ts b/openvidu-browser/src/main/resources/ts/Participant.ts index 29957e93..7c849510 100644 --- a/openvidu-browser/src/main/resources/ts/Participant.ts +++ b/openvidu-browser/src/main/resources/ts/Participant.ts @@ -33,7 +33,8 @@ export class Participant { recvAudio: ( streamOptions.recvAudio == undefined ? true : streamOptions.recvAudio ), audio: streamOptions.audio, video: streamOptions.video, - data: streamOptions.data + data: streamOptions.data, + mediaConstraints: streamOptions.mediaConstraints } let stream = new Stream( openVidu, false, room, streamOpts ); diff --git a/openvidu-browser/src/main/resources/ts/Stream.ts b/openvidu-browser/src/main/resources/ts/Stream.ts index 53429b2d..a8995745 100644 --- a/openvidu-browser/src/main/resources/ts/Stream.ts +++ b/openvidu-browser/src/main/resources/ts/Stream.ts @@ -35,6 +35,7 @@ export interface StreamOptions { video: boolean; audio: boolean; data: boolean; + mediaConstraints: any; } export interface VideoOptions { @@ -55,6 +56,9 @@ export class Stream { private speechEvent: any; private recvVideo: any; private recvAudio: any; + private sendVideo: boolean; + private sendAudio: boolean; + private mediaConstraints: any; private showMyRemote = false; private localMirrored = false; private chanId = 0; @@ -73,6 +77,9 @@ export class Stream { this.recvVideo = options.recvVideo; this.recvAudio = options.recvAudio; this.dataChannel = options.data || false; + this.sendVideo = options.video; + this.sendAudio = options.audio; + this.mediaConstraints = options.mediaConstraints; } getRecvVideo() { @@ -262,6 +269,9 @@ export class Stream { }; navigator.getUserMedia( constraints, userStream => { + userStream.getAudioTracks()[0].enabled = this.sendAudio; + userStream.getVideoTracks()[0].enabled = this.sendVideo; + this.wrStream = userStream; callback(undefined, this); }, error => { @@ -316,9 +326,15 @@ export class Stream { private initWebRtcPeer( sdpOfferCallback ) { if ( this.local ) { + + let userMediaConstraints = { + audio : this.sendAudio, + video : this.sendVideo + } let options: any = { videoStream: this.wrStream, + mediaConstraints: userMediaConstraints, onicecandidate: this.participant.sendIceCandidate.bind( this.participant ), } diff --git a/openvidu-ng-testapp/src/app/app.component.html b/openvidu-ng-testapp/src/app/app.component.html index b607fe69..e45f6506 100644 --- a/openvidu-ng-testapp/src/app/app.component.html +++ b/openvidu-ng-testapp/src/app/app.component.html @@ -9,6 +9,12 @@

+

+ Send video +

+

+ Send audio +

@@ -18,6 +24,10 @@

{{sessionId}}

+ Toggle your video + Toggle your audio
diff --git a/openvidu-ng-testapp/src/app/app.component.ts b/openvidu-ng-testapp/src/app/app.component.ts index 9c48c43d..82a5a6f2 100644 --- a/openvidu-ng-testapp/src/app/app.component.ts +++ b/openvidu-ng-testapp/src/app/app.component.ts @@ -9,14 +9,20 @@ export class AppComponent { private openVidu: OpenVidu; - //Join form + // Join form sessionId: string; participantId: string; - //Session + // Session session: Session; streams: Stream[] = []; + // Publish options + joinWithVideo: boolean = true; + joinWithAudio: boolean = true; + toggleVideo: boolean; + toggleAudio: boolean; + constructor() { this.generateParticipantInfo(); window.onbeforeunload = () => { @@ -24,22 +30,35 @@ export class AppComponent { } } - private generateParticipantInfo(){ + private generateParticipantInfo() { this.sessionId = "SessionA"; - this.participantId = "Participant"+Math.floor(Math.random() * 100); + this.participantId = "Participant" + Math.floor(Math.random() * 100); } - private addVideoTag(stream:Stream){ + private addVideoTag(stream: Stream) { console.log("Stream added"); this.streams.push(stream); } - private removeVideoTag(stream:Stream){ + private removeVideoTag(stream: Stream) { console.log("Stream removed"); this.streams.slice(this.streams.indexOf(stream), 1); } joinSession() { + var cameraOptions = { + audio: this.joinWithAudio, + video: this.joinWithVideo, + data: true, + mediaConstraints: {} + } + this.joinSessionShared(cameraOptions); + } + + joinSessionShared(cameraOptions) { + + this.toggleVideo = this.joinWithVideo; + this.toggleAudio = this.joinWithAudio; this.openVidu = new OpenVidu("wss://127.0.0.1:8443/"); @@ -48,7 +67,7 @@ export class AppComponent { if (error) return console.log(error); - let camera = openVidu.getCamera(); + let camera = openVidu.getCamera(cameraOptions); camera.requestCameraAccess((error, camera) => { @@ -72,11 +91,11 @@ export class AppComponent { camera.publish(); session.addEventListener("stream-added", streamEvent => { - this.addVideoTag(streamEvent.stream); + this.addVideoTag(streamEvent.stream); }); session.addEventListener("stream-removed", streamEvent => { - this.removeVideoTag(streamEvent.stream); + this.removeVideoTag(streamEvent.stream); }); }); @@ -91,4 +110,34 @@ export class AppComponent { this.generateParticipantInfo(); } + updateToggleVideo(event) { + this.toggleVideoTrack(event.target.checked); + let msg = (event.target.checked) ? 'Publishing video...' : 'Unpublishing video...' + console.log(msg); + } + + updateToggleAudio(event) { + this.toggleAudioTrack(event.target.checked); + let msg = (event.target.checked) ? 'Publishing audio...' : 'Unpublishing audio...' + console.log(msg); + } + + toggleVideoTrack(activate: boolean) { + this.openVidu.getCamera().getWebRtcPeer().videoEnabled = activate; + } + + toggleAudioTrack(activate: boolean) { + this.openVidu.getCamera().getWebRtcPeer().audioEnabled = activate; + } + + publishVideoAudio() { + this.toggleVideoTrack(true); + this.toggleAudioTrack(true); + } + + unpublishVideoAudio() { + this.toggleVideoTrack(false); + this.toggleAudioTrack(false); + } + } diff --git a/openvidu-server/pom.xml b/openvidu-server/pom.xml index 7425c7a2..2caafac7 100644 --- a/openvidu-server/pom.xml +++ b/openvidu-server/pom.xml @@ -45,6 +45,11 @@ http://www.kurento.org + + + + org.openvidu.server.OpenViduServer + @@ -60,6 +65,16 @@ + + + + org.codehaus.mojo + exec-maven-plugin + + ${start-class} + + +