You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openmeetings.apache.org by so...@apache.org on 2018/09/30 06:45:09 UTC

[openmeetings] branch master updated: [OPENMEETINGS-1649] audio volume control seems to work

This is an automated email from the ASF dual-hosted git repository.

solomax pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openmeetings.git


The following commit(s) were added to refs/heads/master by this push:
     new faf0ceb  [OPENMEETINGS-1649] audio volume control seems to work
faf0ceb is described below

commit faf0ceb510c3324b4ab676fb2ac6f249747a3b13
Author: Maxim Solodovnik <so...@gmail.com>
AuthorDate: Sun Sep 30 13:44:55 2018 +0700

    [OPENMEETINGS-1649] audio volume control seems to work
---
 .../apache/openmeetings/web/room/raw-settings.js   | 11 +--
 .../openmeetings/web/room/raw-video-manager.js     | 34 ++++----
 .../org/apache/openmeetings/web/room/raw-video.js  | 98 +++++++++-------------
 3 files changed, 63 insertions(+), 80 deletions(-)

diff --git a/openmeetings-web/src/main/java/org/apache/openmeetings/web/room/raw-settings.js b/openmeetings-web/src/main/java/org/apache/openmeetings/web/room/raw-settings.js
index b406f9d..a74eb9a 100644
--- a/openmeetings-web/src/main/java/org/apache/openmeetings/web/room/raw-settings.js
+++ b/openmeetings-web/src/main/java/org/apache/openmeetings/web/room/raw-settings.js
@@ -45,7 +45,7 @@ var MicLevel = (function() {
 					return;
 				}
 				t = Date.now();
-				_micActivity(140 * vol); // magic number
+				_micActivity(vol);
 			};
 		} catch (err) {
 			_error(err);
@@ -93,11 +93,8 @@ var VideoSettings = (function() {
 	}
 	function _clear(_ms) {
 		const ms = _ms || (vid.length === 1 ? vid[0].srcObject : null);
-		if (ms !== null && 'function' === typeof(ms.getAudioTracks)) {
-			ms.getAudioTracks().forEach(function(track) {
-				track.stop();
-			});
-			ms.getVideoTracks().forEach(function(track) {
+		if (ms !== null && 'function' === typeof(ms.getTracks)) {
+			ms.getTracks().forEach(function(track) {
 				track.stop();
 			});
 			if (vid.length === 1) {
@@ -330,7 +327,7 @@ var VideoSettings = (function() {
 		playBtn.prop('disabled', false).button('refresh');
 	}
 	function _micActivity(level) {
-		lm.progressbar("value", Math.max(0, level));
+		lm.progressbar("value", Math.max(0, 140 * level)); // magic number
 	}
 	function _setLoading(el) {
 		el.find('option').remove();
diff --git a/openmeetings-web/src/main/java/org/apache/openmeetings/web/room/raw-video-manager.js b/openmeetings-web/src/main/java/org/apache/openmeetings/web/room/raw-video-manager.js
index 4daf883..28086c1 100644
--- a/openmeetings-web/src/main/java/org/apache/openmeetings/web/room/raw-video-manager.js
+++ b/openmeetings-web/src/main/java/org/apache/openmeetings/web/room/raw-video-manager.js
@@ -21,29 +21,31 @@ var VideoManager = (function() {
 			, w = Video().init(msg.client, VideoUtil.getPos(VideoUtil.getRects(VID_SEL), msg.stream.width, msg.stream.height + 25))
 			, v = w.data()
 			, cl = v.client();
-		OmUtil.log(uid + " registered in room");
-
+		OmUtil.log(uid + ' registered in room');
+		//each bool OR https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackConstraints
+		const constraints = {
+			audio : VideoUtil.hasAudio(cl)
+			, video : VideoUtil.hasVideo(cl)
+		}
+		if (constraints.video) {
+			constraints.video = {
+				mandatory : {
+					maxWidth : cl.width,
+					maxFrameRate : cl.height,
+				}
+			};
+		}
 		v.setPeer(new kurentoUtils.WebRtcPeer.WebRtcPeerSendonly(
 			{
 				localVideo: v.video()
-				, mediaConstraints:
-					{ //each bool OR https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackConstraints
-						audio : VideoUtil.hasAudio(cl)
-						, video : VideoUtil.hasVideo(cl)
-						/* TODO FIXME {
-							mandatory : {
-								maxWidth : cl.width,
-								maxFrameRate : cl.height,
-								minFrameRate : 15
-							}
-						}*/
-					}
+				, mediaConstraints: constraints
 				, onicecandidate: v.onIceCandidate
 			}
 			, function (error) {
 				if (error) {
 					return OmUtil.error(error);
 				}
+				v.initGain();
 				this.generateOffer(function(error, offerSdp, wp) {
 					if (error) {
 						return OmUtil.error('Sender sdp offer error');
@@ -65,7 +67,7 @@ var VideoManager = (function() {
 			, w = Video().init(c, VideoUtil.getPos(VideoUtil.getRects(VID_SEL), c.width, c.height + 25))
 			, v = w.data()
 			, cl = v.client();
-		OmUtil.log(uid + " receiving video");
+		OmUtil.log(uid + ' receiving video');
 
 		v.setPeer(new kurentoUtils.WebRtcPeer.WebRtcPeerRecvonly({
 				remoteVideo : v.video()
@@ -117,7 +119,7 @@ var VideoManager = (function() {
 
 							v.getPeer().addIceCandidate(m.candidate, function (error) {
 								if (error) {
-									OmUtil.error("Error adding candidate: " + error);
+									OmUtil.error('Error adding candidate: ' + error);
 									return;
 								}
 							});
diff --git a/openmeetings-web/src/main/java/org/apache/openmeetings/web/room/raw-video.js b/openmeetings-web/src/main/java/org/apache/openmeetings/web/room/raw-video.js
index c23a626..3d52bbd 100644
--- a/openmeetings-web/src/main/java/org/apache/openmeetings/web/room/raw-video.js
+++ b/openmeetings-web/src/main/java/org/apache/openmeetings/web/room/raw-video.js
@@ -2,7 +2,7 @@
 var Video = (function() {
 	const self = {};
 	let c, v, vc, t, f, size, vol, slider, handle, video, rtcPeer
-		, lastVolume = 50;
+		, lastVolume = 50, aCtx, gainNode;
 
 	function _getName() {
 		return c.user.firstName + ' ' + c.user.lastName;
@@ -15,11 +15,6 @@ var Video = (function() {
 		_resizeDlgArea(_w, h);
 		return h;
 	}
-	function _vidResize(_w, _h) {
-		try {
-			swf[0].vidResize(Math.floor(_w), Math.floor(_h));
-		} catch (err) {}
-	}
 	function _resizeDlgArea(_w, _h) {
 		v.dialog('option', 'width', _w).dialog('option', 'height', _h);
 		const h = _h - _getExtra();
@@ -27,7 +22,6 @@ var Video = (function() {
 		if (Room.getOptions().interview) {
 			v.dialog('widget').css(VideoUtil.getPos());
 		}
-		_vidResize(_w, h);
 	}
 	function _resizePod() {
 		const p = v.parents('.pod,.pod-big')
@@ -38,6 +32,27 @@ var Video = (function() {
 		vc.width(w).height(h);
 		video.width(w).height(h);
 	}
+	function _initGain() {
+		if (!rtcPeer) {
+			return;
+		}
+		const stream = rtcPeer.getLocalStream();
+		if (!stream || stream.getAudioTracks().length === 0) {
+			return;
+		}
+		vol.show();
+		aCtx = new AudioContext();
+		gainNode = aCtx.createGain();
+		const aSrc = aCtx.createMediaStreamSource(stream)
+			, aDest = aCtx.createMediaStreamDestination();
+		aSrc.connect(gainNode);
+		gainNode.connect(aDest);
+
+		//update stream
+		const pc = rtcPeer.peerConnection;
+		pc.getSenders().forEach(sender => pc.removeTrack(sender));
+		aDest.stream.getTracks().forEach(track => pc.addTrack(track, aDest.stream));
+	}
 	function _handleMicStatus(state) {
 		if (!f.is(':visible')) {
 			return;
@@ -56,6 +71,11 @@ var Video = (function() {
 	}
 	function _handleVolume(val) {
 		handle.text(val);
+		if (c.self) { //FIXME TODO multistream support
+			gainNode.gain.value = val / 100;
+		} else {
+			video[0].volume = val / 100;
+		}
 		const ico = vol.find('.ui-icon');
 		if (val > 0 && ico.hasClass('ui-icon-volume-off')) {
 			ico.toggleClass('ui-icon-volume-off ui-icon-volume-on');
@@ -66,11 +86,6 @@ var Video = (function() {
 			vol.addClass('ui-state-error');
 			_handleMicStatus(false);
 		}
-		/* TODO
-		if (typeof(swf[0].setVolume) === 'function') {
-			swf[0].setVolume(val);
-		}
-		*/
 	}
 	function _mute(mute) {
 		if (!slider) {
@@ -120,7 +135,6 @@ var Video = (function() {
 				const w = ui.size.width - 2
 					, h = ui.size.height - t.height() - 4 - (f.is(':visible') ? f.height() : 0);
 				_resize(w, h);
-				_vidResize(w, h);
 			});
 			if (VideoUtil.isSharing(c)) {
 				v.on('dialogclose', function() {
@@ -210,19 +224,9 @@ var Video = (function() {
 					_handleVolume(ui.value);
 				}
 			});
-			const hasAudio = VideoUtil.hasAudio(c);
-			_handleMicStatus(hasAudio);
-			if (!hasAudio) {
-				vol.hide();
-			}
+			vol.hide();
 		}
-		v.on("remove", function () {
-			OmUtil.log('Disposing participant ' + c.uid);
-			if (!!rtcPeer) {
-				rtcPeer.dispose();
-				rtcPeer = null;
-			}
-		});
+		v.on("remove", _cleanup);
 		vc = v.find('.video');
 		vc.width(_w).height(_h);
 		//broadcast
@@ -256,12 +260,11 @@ var Video = (function() {
 		} else {
 			vc.addClass('audio-only').css('background-image', 'url(' + imgUrl + ')');
 		}
+		if (!c.self) { //FIXME TODO multi-stream
+			_handleVolume(lastVolume);
+		}
 
 		vc.append(video);
-		/* TODO
-		swf = initSwf(vc, 'main.swf', _id + '-swf', o);
-		swf.attr('width', _w).attr('height', _h);
-		*/
 		v.dialog('widget').css(_pos);
 		return v;
 	}
@@ -285,40 +288,21 @@ var Video = (function() {
 		}
 		const name = _getName();
 		v.dialog('option', 'title', name).parent().find('.ui-dialog-titlebar').attr('title', name);
-		/* TODO
-		if (typeof(swf[0].update) === 'function') {
-			c.self ? swf[0].update() : swf[0].update(c);
-		}
-		*/
 	}
 	function _refresh(_opts) {
-		/*
-		if (typeof(swf[0].refresh) === 'function') {
-			const opts = _opts || {};
-			if (!Room.getOptions().interview && !isNaN(opts.width)) {
-				_resizeDlg(opts.width, opts.height);
-			}
-			try {
-				swf[0].refresh(opts);
-			} catch (e) {
-				//swf might throw
-			}
-		}
-		*/
 	}
 	function _setRights(_r) {
-		/*
-		if (typeof(swf[0].setRights) === 'function') {
-			swf[0].setRights(_r);
-		}
-		*/
 	}
 	function _cleanup() {
-		/*
-		if (typeof(swf[0].cleanup) === 'function') {
-			swf[0].cleanup();
+		OmUtil.log('Disposing participant ' + c.uid);
+		if (!!rtcPeer) {
+			rtcPeer.dispose();
+			rtcPeer = null;
+		}
+		if (!!aCtx) {
+			aCtx.close();
+			aCtx = null;
 		}
-		*/
 	}
 
 	self.update = _update;
@@ -326,9 +310,9 @@ var Video = (function() {
 	self.mute = _mute;
 	self.isMuted = function() { return 0 === slider.slider('option', 'value'); };
 	self.init = _init;
+	self.initGain = _initGain;
 	self.client = function() { return c; };
 	self.setRights = _setRights;
-	self.cleanup = _cleanup;
 	self.video = function() { return video[0]; };
 	self.setPeer = function(p) { rtcPeer = p; };
 	self.getPeer = function() { return rtcPeer; };