[Pkg-voip-commits] [janus] 09/163: Use tracks instead of streams in janus.js

Jonas Smedegaard dr at jones.dk
Sat Oct 28 01:22:03 UTC 2017


This is an automated email from the git hooks/post-receive script.

js pushed a commit to annotated tag debian/0.2.5-1
in repository janus.

commit 0054bb12b792d33f0b49dce8dac1de7b480b3a51
Author: Lorenzo Miniero <lminiero at gmail.com>
Date:   Tue Jul 4 19:19:42 2017 +0200

    Use tracks instead of streams in janus.js
---
 html/audiobridgetest.js   |  4 ++--
 html/devicetest.js        | 54 +++++++++++++++++++++--------------------
 html/echotest.js          | 45 ++++++++++++++++++++--------------
 html/janus.js             | 26 ++++++--------------
 html/janus.nojquery.js    | 26 ++++++--------------
 html/recordplaytest.js    | 28 ++++++++++++----------
 html/screensharingtest.js | 16 +++++++------
 html/siptest.js           | 61 +++++++++++++++++++++++++++--------------------
 html/streamingtest.js     | 31 ++++++++++++++++++++----
 html/textroomtest.js      |  2 +-
 html/videocalltest.js     | 24 +++++++++++++------
 html/videoroomtest.js     | 29 +++++++++++++++-------
 html/voicemailtest.js     |  2 +-
 13 files changed, 195 insertions(+), 153 deletions(-)

diff --git a/html/audiobridgetest.js b/html/audiobridgetest.js
index 92b5f05..078dbec 100644
--- a/html/audiobridgetest.js
+++ b/html/audiobridgetest.js
@@ -126,7 +126,7 @@ $(document).ready(function() {
 								},
 								onmessage: function(msg, jsep) {
 									Janus.debug(" ::: Got a message :::");
-									Janus.debug(JSON.stringify(msg));
+									Janus.debug(msg);
 									var event = msg["audiobridge"];
 									Janus.debug("Event: " + event);
 									if(event != undefined && event != null) {
@@ -256,7 +256,7 @@ $(document).ready(function() {
 								},
 								onlocalstream: function(stream) {
 									Janus.debug(" ::: Got a local stream :::");
-									Janus.debug(JSON.stringify(stream));
+									Janus.debug(stream);
 									// We're not going to attach the local audio stream
 									$('#audiojoin').hide();
 									$('#room').removeClass('hide').show();
diff --git a/html/devicetest.js b/html/devicetest.js
index 9d0ab12..55751f9 100644
--- a/html/devicetest.js
+++ b/html/devicetest.js
@@ -229,7 +229,7 @@ $(document).ready(function() {
 								},
 								onmessage: function(msg, jsep) {
 									Janus.debug(" ::: Got a message :::");
-									Janus.debug(JSON.stringify(msg));
+									Janus.debug(msg);
 									if(jsep !== undefined && jsep !== null) {
 										Janus.debug("Handling SDP as well...");
 										Janus.debug(jsep);
@@ -264,7 +264,7 @@ $(document).ready(function() {
 								},
 								onlocalstream: function(stream) {
 									Janus.debug(" ::: Got a local stream :::");
-									Janus.debug(JSON.stringify(stream));
+									Janus.debug(stream);
 									if($('#myvideo').length === 0) {
 										$('#videos').removeClass('hide').show();
 										$('#videoleft').append('<video class="rounded centered" id="myvideo" width=320 height=240 autoplay muted="muted"/>');
@@ -295,37 +295,38 @@ $(document).ready(function() {
 								},
 								onremotestream: function(stream) {
 									Janus.debug(" ::: Got a remote stream :::");
-									Janus.debug(JSON.stringify(stream));
-									if($('#peervideo').length === 0) {
-										$('#videos').removeClass('hide').show();
-										$('#videoright').append('<video class="rounded centered hide" id="peervideo" width=320 height=240 autoplay/>');
-										// Show the video, hide the spinner and show the resolution when we get a playing event
-										$("#peervideo").bind("playing", function () {
-											$('#waitingvideo').remove();
-											$('#peervideo').removeClass('hide');
-											if(spinner !== null && spinner !== undefined)
-												spinner.stop();
-											spinner = null;
-											var width = this.videoWidth;
-											var height = this.videoHeight;
-											$('#curres').removeClass('hide').text(width+'x'+height).show();
-											if(adapter.browserDetails.browser === "firefox") {
-												// Firefox Stable has a bug: width and height are not immediately available after a playing
-												setTimeout(function() {
-													var width = $("#peervideo").get(0).videoWidth;
-													var height = $("#peervideo").get(0).videoHeight;
-													$('#curres').removeClass('hide').text(width+'x'+height).show();
-												}, 2000);
-											}
-										});
+									Janus.debug(stream);
+									if($('#peervideo').length > 0) {
+										// Been here already: let's see if anything changed
+										var videoTracks = stream.getVideoTracks();
+										if(videoTracks && videoTracks.length > 0 && !videoTracks[0].muted) {
+											$('#novideo').remove();
+											if($("#peervideo").get(0).videoWidth)
+												$('#peervideo').show();
+										}
+										return;
 									}
+									$('#videos').removeClass('hide').show();
+									$('#videoright').append('<video class="rounded centered hide" id="peervideo" width=320 height=240 autoplay/>');
+									// Show the video, hide the spinner and show the resolution when we get a playing event
+									$("#peervideo").bind("playing", function () {
+										$('#waitingvideo').remove();
+										if(this.videoWidth)
+											$('#peervideo').removeClass('hide').show();
+										if(spinner !== null && spinner !== undefined)
+											spinner.stop();
+										spinner = null;
+										var width = this.videoWidth;
+										var height = this.videoHeight;
+										$('#curres').removeClass('hide').text(width+'x'+height).show();
+									});
 									Janus.attachMediaStream($('#peervideo').get(0), stream);
 									var videoTracks = stream.getVideoTracks();
 									if(videoTracks === null || videoTracks === undefined || videoTracks.length === 0 || videoTracks[0].muted) {
 										// No remote video
 										$('#peervideo').hide();
 										$('#videoright').append(
-											'<div class="no-video-container">' +
+											'<div id="novideo" class="no-video-container">' +
 												'<i class="fa fa-video-camera fa-5 no-video-icon"></i>' +
 												'<span class="no-video-text">No remote video available</span>' +
 											'</div>');
@@ -397,6 +398,7 @@ $(document).ready(function() {
 									$('#myvideo').remove();
 									$('#waitingvideo').remove();
 									$('#peervideo').remove();
+									$('.no-video-container').remove();
 									audioenabled = true;
 									$('#toggleaudio').attr('disabled', true).html("Disable audio").removeClass("btn-success").addClass("btn-danger");
 									videoenabled = true;
diff --git a/html/echotest.js b/html/echotest.js
index 1e2201e..0b62763 100644
--- a/html/echotest.js
+++ b/html/echotest.js
@@ -161,7 +161,7 @@ $(document).ready(function() {
 								},
 								onmessage: function(msg, jsep) {
 									Janus.debug(" ::: Got a message :::");
-									Janus.debug(JSON.stringify(msg));
+									Janus.debug(msg);
 									if(jsep !== undefined && jsep !== null) {
 										Janus.debug("Handling SDP as well...");
 										Janus.debug(jsep);
@@ -188,7 +188,7 @@ $(document).ready(function() {
 								},
 								onlocalstream: function(stream) {
 									Janus.debug(" ::: Got a local stream :::");
-									Janus.debug(JSON.stringify(stream));
+									Janus.debug(stream);
 									if($('#myvideo').length === 0) {
 										$('#videos').removeClass('hide').show();
 										$('#videoleft').append('<video class="rounded centered" id="myvideo" width=320 height=240 autoplay muted="muted"/>');
@@ -224,29 +224,38 @@ $(document).ready(function() {
 								},
 								onremotestream: function(stream) {
 									Janus.debug(" ::: Got a remote stream :::");
-									Janus.debug(JSON.stringify(stream));
-									if($('#peervideo').length === 0) {
-										$('#videos').removeClass('hide').show();
-										$('#videoright').append('<video class="rounded centered hide" id="peervideo" width=320 height=240 autoplay/>');
-										// Show the video, hide the spinner and show the resolution when we get a playing event
-										$("#peervideo").bind("playing", function () {
-											$('#waitingvideo').remove();
-											$('#peervideo').removeClass('hide');
-											if(spinner !== null && spinner !== undefined)
-												spinner.stop();
-											spinner = null;
-											var width = this.videoWidth;
-											var height = this.videoHeight;
-											$('#curres').removeClass('hide').text(width+'x'+height).show();
-										});
+									Janus.debug(stream);
+									if($('#peervideo').length > 0) {
+										// Been here already: let's see if anything changed
+										var videoTracks = stream.getVideoTracks();
+										if(videoTracks && videoTracks.length > 0 && !videoTracks[0].muted) {
+											$('#novideo').remove();
+											if($("#peervideo").get(0).videoWidth)
+												$('#peervideo').show();
+										}
+										return;
 									}
+									$('#videos').removeClass('hide').show();
+									$('#videoright').append('<video class="rounded centered hide" id="peervideo" width=320 height=240 autoplay/>');
+									// Show the video, hide the spinner and show the resolution when we get a playing event
+									$("#peervideo").bind("playing", function () {
+										$('#waitingvideo').remove();
+										if(this.videoWidth)
+											$('#peervideo').removeClass('hide').show();
+										if(spinner !== null && spinner !== undefined)
+											spinner.stop();
+										spinner = null;
+										var width = this.videoWidth;
+										var height = this.videoHeight;
+										$('#curres').removeClass('hide').text(width+'x'+height).show();
+									});
 									Janus.attachMediaStream($('#peervideo').get(0), stream);
 									var videoTracks = stream.getVideoTracks();
 									if(videoTracks === null || videoTracks === undefined || videoTracks.length === 0 || videoTracks[0].muted) {
 										// No remote video
 										$('#peervideo').hide();
 										$('#videoright').append(
-											'<div class="no-video-container">' +
+											'<div id="novideo" class="no-video-container">' +
 												'<i class="fa fa-video-camera fa-5 no-video-icon"></i>' +
 												'<span class="no-video-text">No remote video available</span>' +
 											'</div>');
diff --git a/html/janus.js b/html/janus.js
index 2f26688..932bc0c 100644
--- a/html/janus.js
+++ b/html/janus.js
@@ -112,9 +112,6 @@ Janus.init = function(options) {
 						callback(devices);
 						// Get rid of the now useless stream
 						try {
-							stream.stop();
-						} catch(e) {}
-						try {
 							var tracks = stream.getTracks();
 							for(var i in tracks) {
 								var mst = tracks[i];
@@ -1299,14 +1296,14 @@ function Janus(gatewayCallbacks) {
 		};
 		if(stream !== null && stream !== undefined) {
 			Janus.log('Adding local stream');
-			config.pc.addStream(stream);
+			stream.getTracks().forEach(track => config.pc.addTrack(track, stream));
 			pluginHandle.onlocalstream(stream);
 		}
-		config.pc.onaddstream = function(remoteStream) {
-			Janus.log("Handling Remote Stream");
-			Janus.debug(remoteStream);
-			config.remoteStream = remoteStream;
-			pluginHandle.onremotestream(remoteStream.stream);
+		config.pc.ontrack = function(event) {
+			Janus.log("Handling Remote Track");
+			Janus.debug(event);
+			config.remoteStream = event.streams[0];
+			pluginHandle.onremotestream(config.remoteStream);
 		};
 		// Any data channel to create?
 		if(isDataEnabled(media)) {
@@ -2086,16 +2083,7 @@ function Janus(gatewayCallbacks) {
 			config.bitrate.tsbefore = null;
 			config.bitrate.value = null;
 			try {
-				// Try a MediaStream.stop() first
-				if(!config.streamExternal && config.myStream !== null && config.myStream !== undefined) {
-					Janus.log("Stopping local stream");
-					config.myStream.stop();
-				}
-			} catch(e) {
-				// Do nothing if this fails
-			}
-			try {
-				// Try a MediaStreamTrack.stop() for each track as well
+				// Try a MediaStreamTrack.stop() for each track
 				if(!config.streamExternal && config.myStream !== null && config.myStream !== undefined) {
 					Janus.log("Stopping local stream tracks");
 					var tracks = config.myStream.getTracks();
diff --git a/html/janus.nojquery.js b/html/janus.nojquery.js
index bda3314..2c96197 100644
--- a/html/janus.nojquery.js
+++ b/html/janus.nojquery.js
@@ -112,9 +112,6 @@ Janus.init = function(options) {
 						callback(devices);
 						// Get rid of the now useless stream
 						try {
-							stream.stop();
-						} catch(e) {}
-						try {
 							var tracks = stream.getTracks();
 							for(var i in tracks) {
 								var mst = tracks[i];
@@ -1350,14 +1347,14 @@ function Janus(gatewayCallbacks) {
 		};
 		if(stream !== null && stream !== undefined) {
 			Janus.log('Adding local stream');
-			config.pc.addStream(stream);
+			stream.getTracks().forEach(track => config.pc.addTrack(track, stream));
 			pluginHandle.onlocalstream(stream);
 		}
-		config.pc.onaddstream = function(remoteStream) {
-			Janus.log("Handling Remote Stream");
-			Janus.debug(remoteStream);
-			config.remoteStream = remoteStream;
-			pluginHandle.onremotestream(remoteStream.stream);
+		config.pc.ontrack = function(event) {
+			Janus.log("Handling Remote Track");
+			Janus.debug(event);
+			config.remoteStream = event.streams[0];
+			pluginHandle.onremotestream(config.remoteStream);
 		};
 		// Any data channel to create?
 		if(isDataEnabled(media)) {
@@ -2135,16 +2132,7 @@ function Janus(gatewayCallbacks) {
 			config.bitrate.tsbefore = null;
 			config.bitrate.value = null;
 			try {
-				// Try a MediaStream.stop() first
-				if(!config.streamExternal && config.myStream !== null && config.myStream !== undefined) {
-					Janus.log("Stopping local stream");
-					config.myStream.stop();
-				}
-			} catch(e) {
-				// Do nothing if this fails
-			}
-			try {
-				// Try a MediaStreamTrack.stop() for each track as well
+				// Try a MediaStreamTrack.stop() for each track
 				if(!config.streamExternal && config.myStream !== null && config.myStream !== undefined) {
 					Janus.log("Stopping local stream tracks");
 					var tracks = config.myStream.getTracks();
diff --git a/html/recordplaytest.js b/html/recordplaytest.js
index 99c567c..9c2275d 100644
--- a/html/recordplaytest.js
+++ b/html/recordplaytest.js
@@ -130,7 +130,7 @@ $(document).ready(function() {
 								},
 								onmessage: function(msg, jsep) {
 									Janus.debug(" ::: Got a message :::");
-									Janus.debug(JSON.stringify(msg));
+									Janus.debug(msg);
 									var result = msg["result"];
 									if(result !== null && result !== undefined) {
 										if(result["status"] !== undefined && result["status"] !== null) {
@@ -231,7 +231,7 @@ $(document).ready(function() {
 									if(playing === true)
 										return;
 									Janus.debug(" ::: Got a local stream :::");
-									Janus.debug(JSON.stringify(stream));
+									Janus.debug(stream);
 									$('#videotitle').html("Recording...");
 									$('#stop').unbind('click').click(stop);
 									$('#video').removeClass('hide').show();
@@ -252,20 +252,22 @@ $(document).ready(function() {
 									if(playing === false)
 										return;
 									Janus.debug(" ::: Got a remote stream :::");
-									Janus.debug(JSON.stringify(stream));
+									Janus.debug(stream);
+									if($('#thevideo').length > 0) {
+										// Been here already
+										return;
+									}
 									$('#videotitle').html(selectedRecordingInfo);
 									$('#stop').unbind('click').click(stop);
 									$('#video').removeClass('hide').show();
-									if($('#thevideo').length === 0) {
-										$('#videobox').append('<video class="rounded centered hide" id="thevideo" width=320 height=240 autoplay/>');
-										// No remote video yet
-										$('#videobox').append('<video class="rounded centered" id="waitingvideo" width=320 height=240 />');
-										if(spinner == null) {
-											var target = document.getElementById('videobox');
-											spinner = new Spinner({top:100}).spin(target);
-										} else {
-											spinner.spin();
-										}
+									$('#videobox').append('<video class="rounded centered hide" id="thevideo" width=320 height=240 autoplay/>');
+									// No remote video yet
+									$('#videobox').append('<video class="rounded centered" id="waitingvideo" width=320 height=240 />');
+									if(spinner == null) {
+										var target = document.getElementById('videobox');
+										spinner = new Spinner({top:100}).spin(target);
+									} else {
+										spinner.spin();
 									}
 									// Show the video, hide the spinner and show the resolution when we get a playing event
 									$("#thevideo").bind("playing", function () {
diff --git a/html/screensharingtest.js b/html/screensharingtest.js
index c4132de..c58363f 100644
--- a/html/screensharingtest.js
+++ b/html/screensharingtest.js
@@ -147,7 +147,7 @@ $(document).ready(function() {
 								},
 								onmessage: function(msg, jsep) {
 									Janus.debug(" ::: Got a message (publisher) :::");
-									Janus.debug(JSON.stringify(msg));
+									Janus.debug(msg);
 									var event = msg["videoroom"];
 									Janus.debug("Event: " + event);
 									if(event != undefined && event != null) {
@@ -221,7 +221,7 @@ $(document).ready(function() {
 								},
 								onlocalstream: function(stream) {
 									Janus.debug(" ::: Got a local stream :::");
-									Janus.debug(JSON.stringify(stream));
+									Janus.debug(stream);
 									$('#screenmenu').hide();
 									$('#room').removeClass('hide').show();
 									if($('#screenvideo').length === 0) {
@@ -412,7 +412,7 @@ function newRemoteFeed(id, display) {
 			},
 			onmessage: function(msg, jsep) {
 				Janus.debug(" ::: Got a message (listener) :::");
-				Janus.debug(JSON.stringify(msg));
+				Janus.debug(msg);
 				var event = msg["videoroom"];
 				Janus.debug("Event: " + event);
 				if(event != undefined && event != null) {
@@ -456,11 +456,13 @@ function newRemoteFeed(id, display) {
 				// The subscriber stream is recvonly, we don't expect anything here
 			},
 			onremotestream: function(stream) {
-				if($('#screenvideo').length === 0) {
-					// No remote video yet
-					$('#screencapture').append('<video class="rounded centered" id="waitingvideo" width="100%" height="100%" />');
-					$('#screencapture').append('<video class="rounded centered hide" id="screenvideo" width="100%" height="100%" autoplay/>');
+				if($('#screenvideo').length > 0) {
+					// Been here already
+					return;
 				}
+				// No remote video yet
+				$('#screencapture').append('<video class="rounded centered" id="waitingvideo" width="100%" height="100%" />');
+				$('#screencapture').append('<video class="rounded centered hide" id="screenvideo" width="100%" height="100%" autoplay/>');
 				// Show the video, hide the spinner and show the resolution when we get a playing event
 				$("#screenvideo").bind("playing", function () {
 					$('#waitingvideo').remove();
diff --git a/html/siptest.js b/html/siptest.js
index 7849155..73aeb54 100644
--- a/html/siptest.js
+++ b/html/siptest.js
@@ -148,7 +148,7 @@ $(document).ready(function() {
 								},
 								onmessage: function(msg, jsep) {
 									Janus.debug(" ::: Got a message :::");
-									Janus.debug(JSON.stringify(msg));
+									Janus.debug(msg);
 									// Any error?
 									var error = msg["error"];
 									if(error != null && error != undefined) {
@@ -325,7 +325,7 @@ $(document).ready(function() {
 								},
 								onlocalstream: function(stream) {
 									Janus.debug(" ::: Got a local stream :::");
-									Janus.debug(JSON.stringify(stream));
+									Janus.debug(stream);
 									$('#videos').removeClass('hide').show();
 									if($('#myvideo').length === 0)
 										$('#videoleft').append('<video class="rounded centered" id="myvideo" width=320 height=240 autoplay muted="muted"/>');
@@ -352,34 +352,43 @@ $(document).ready(function() {
 								},
 								onremotestream: function(stream) {
 									Janus.debug(" ::: Got a remote stream :::");
-									Janus.debug(JSON.stringify(stream));
-									if($('#remotevideo').length === 0) {
-										$('#videoright').parent().find('h3').html(
-											'Send DTMF: <span id="dtmf" class="btn-group btn-group-xs"></span>');
-										$('#videoright').append(
-											'<video class="rounded centered hide" id="remotevideo" width=320 height=240 autoplay/>');
-										for(var i=0; i<12; i++) {
-											if(i<10)
-												$('#dtmf').append('<button class="btn btn-info dtmf">' + i + '</button>');
-											else if(i == 10)
-												$('#dtmf').append('<button class="btn btn-info dtmf">#</button>');
-											else if(i == 11)
-												$('#dtmf').append('<button class="btn btn-info dtmf">*</button>');
+									Janus.debug(stream);
+									if($('#remotevideo').length > 0) {
+										// Been here already: let's see if anything changed
+										var videoTracks = stream.getVideoTracks();
+										if(videoTracks && videoTracks.length > 0 && !videoTracks[0].muted) {
+											$('#novideo').remove();
+											if($("#remotevideo").get(0).videoWidth)
+												$('#remotevideo').show();
 										}
-										$('.dtmf').click(function() {
-											if(adapter.browserDetails.browser === 'chrome') {
-												// Send DTMF tone (inband)
-												sipcall.dtmf({dtmf: { tones: $(this).text()}});
-											} else {
-												// Try sending the DTMF tone using SIP INFO
-												sipcall.send({message: {request: "dtmf_info", digit: $(this).text()}});
-											}
-										});
+										return;
 									}
+									$('#videoright').parent().find('h3').html(
+										'Send DTMF: <span id="dtmf" class="btn-group btn-group-xs"></span>');
+									$('#videoright').append(
+										'<video class="rounded centered hide" id="remotevideo" width=320 height=240 autoplay/>');
+									for(var i=0; i<12; i++) {
+										if(i<10)
+											$('#dtmf').append('<button class="btn btn-info dtmf">' + i + '</button>');
+										else if(i == 10)
+											$('#dtmf').append('<button class="btn btn-info dtmf">#</button>');
+										else if(i == 11)
+											$('#dtmf').append('<button class="btn btn-info dtmf">*</button>');
+									}
+									$('.dtmf').click(function() {
+										if(adapter.browserDetails.browser === 'chrome') {
+											// Send DTMF tone (inband)
+											sipcall.dtmf({dtmf: { tones: $(this).text()}});
+										} else {
+											// Try sending the DTMF tone using SIP INFO
+											sipcall.send({message: {request: "dtmf_info", digit: $(this).text()}});
+										}
+									});
 									// Show the peer and hide the spinner when we get a playing event
 									$("#remotevideo").bind("playing", function () {
 										$('#waitingvideo').remove();
-										$('#remotevideo').removeClass('hide');
+										if(this.videoWidth)
+											$('#remotevideo').removeClass('hide').show();
 										if(spinner !== null && spinner !== undefined)
 											spinner.stop();
 										spinner = null;
@@ -390,7 +399,7 @@ $(document).ready(function() {
 										// No remote video
 										$('#remotevideo').hide();
 										$('#videoright').append(
-											'<div class="no-video-container">' +
+											'<div id="novideo" class="no-video-container">' +
 												'<i class="fa fa-video-camera fa-5 no-video-icon"></i>' +
 												'<span class="no-video-text">No remote video available</span>' +
 											'</div>');
diff --git a/html/streamingtest.js b/html/streamingtest.js
index 582616c..29f61de 100644
--- a/html/streamingtest.js
+++ b/html/streamingtest.js
@@ -104,7 +104,7 @@ $(document).ready(function() {
 								},
 								onmessage: function(msg, jsep) {
 									Janus.debug(" ::: Got a message :::");
-									Janus.debug(JSON.stringify(msg));
+									Janus.debug(msg);
 									var result = msg["result"];
 									if(result !== null && result !== undefined) {
 										if(result["status"] !== undefined && result["status"] !== null) {
@@ -145,23 +145,44 @@ $(document).ready(function() {
 								},
 								onremotestream: function(stream) {
 									Janus.debug(" ::: Got a remote stream :::");
-									Janus.debug(JSON.stringify(stream));
-									if($('#remotevideo').length === 0)
-										$('#stream').append('<video class="rounded centered hide" id="remotevideo" width=320 height=240 autoplay/>');
+									Janus.debug(stream);
+									if($('#remotevideo').length > 0) {
+										// Been here already: let's see if anything changed
+										var videoTracks = stream.getVideoTracks();
+										if(videoTracks && videoTracks.length > 0 && !videoTracks[0].muted) {
+											$('#novideo').remove();
+											if($("#remotevideo").get(0).videoWidth)
+												$('#remotevideo').show();
+										}
+										return;
+									}
+									$('#stream').append('<video class="rounded centered hide" id="remotevideo" width=320 height=240 autoplay/>');
 									// Show the stream and hide the spinner when we get a playing event
 									$("#remotevideo").bind("playing", function () {
 										$('#waitingvideo').remove();
-										$('#remotevideo').removeClass('hide');
+										if(this.videoWidth)
+											$('#remotevideo').removeClass('hide').show();
 										if(spinner !== null && spinner !== undefined)
 											spinner.stop();
 										spinner = null;
 									});
 									Janus.attachMediaStream($('#remotevideo').get(0), stream);
+									var videoTracks = stream.getVideoTracks();
+									if(videoTracks === null || videoTracks === undefined || videoTracks.length === 0 || videoTracks[0].muted) {
+										// No remote video
+										$('#remotevideo').hide();
+										$('#stream').append(
+											'<div id="novideo" class="no-video-container">' +
+												'<i class="fa fa-video-camera fa-5 no-video-icon"></i>' +
+												'<span class="no-video-text">No remote video available</span>' +
+											'</div>');
+									}
 								},
 								oncleanup: function() {
 									Janus.log(" ::: Got a cleanup notification :::");
 									$('#waitingvideo').remove();
 									$('#remotevideo').remove();
+									$('.no-video-container').remove();
 								}
 							});
 					},
diff --git a/html/textroomtest.js b/html/textroomtest.js
index 58a06ec..d6681a7 100644
--- a/html/textroomtest.js
+++ b/html/textroomtest.js
@@ -108,7 +108,7 @@ $(document).ready(function() {
 								},
 								onmessage: function(msg, jsep) {
 									Janus.debug(" ::: Got a message :::");
-									Janus.debug(JSON.stringify(msg));
+									Janus.debug(msg);
 									if(msg["error"] !== undefined && msg["error"] !== null) {
 										bootbox.alert(msg["error"]);
 									}
diff --git a/html/videocalltest.js b/html/videocalltest.js
index c993fbd..db3f36b 100644
--- a/html/videocalltest.js
+++ b/html/videocalltest.js
@@ -134,7 +134,7 @@ $(document).ready(function() {
 								},
 								onmessage: function(msg, jsep) {
 									Janus.debug(" ::: Got a message :::");
-									Janus.debug(JSON.stringify(msg));
+									Janus.debug(msg);
 									var result = msg["result"];
 									if(result !== null && result !== undefined) {
 										if(result["list"] !== undefined && result["list"] !== null) {
@@ -273,7 +273,7 @@ $(document).ready(function() {
 								},
 								onlocalstream: function(stream) {
 									Janus.debug(" ::: Got a local stream :::");
-									Janus.debug(JSON.stringify(stream));
+									Janus.debug(stream);
 									$('#videos').removeClass('hide').show();
 									if($('#myvideo').length === 0)
 										$('#videoleft').append('<video class="rounded centered" id="myvideo" width=320 height=240 autoplay muted="muted"/>');
@@ -308,13 +308,22 @@ $(document).ready(function() {
 								},
 								onremotestream: function(stream) {
 									Janus.debug(" ::: Got a remote stream :::");
-									Janus.debug(JSON.stringify(stream));
-									if($('#remotevideo').length === 0)
-										$('#videoright').append('<video class="rounded centered hide" id="remotevideo" width=320 height=240 autoplay/>');
+									Janus.debug(stream);
+									if($('#remotevideo').length > 0) {
+										// Been here already: let's see if anything changed
+										var videoTracks = stream.getVideoTracks();
+										if(videoTracks && videoTracks.length > 0 && !videoTracks[0].muted) {
+											$('#novideo').remove();
+											if($("#remotevideo").get(0).videoWidth)
+												$('#remotevideo').show();
+										}
+									}
+									$('#videoright').append('<video class="rounded centered hide" id="remotevideo" width=320 height=240 autoplay/>');
 									// Show the video, hide the spinner and show the resolution when we get a playing event
 									$("#remotevideo").bind("playing", function () {
 										$('#waitingvideo').remove();
-										$('#remotevideo').removeClass('hide');
+										if(this.videoWidth)
+											$('#remotevideo').removeClass('hide').show();
 										if(spinner !== null && spinner !== undefined)
 											spinner.stop();
 										spinner = null;
@@ -328,7 +337,7 @@ $(document).ready(function() {
 										// No remote video
 										$('#remotevideo').hide();
 										$('#videoright').append(
-											'<div class="no-video-container">' +
+											'<div id="novideo" class="no-video-container">' +
 												'<i class="fa fa-video-camera fa-5 no-video-icon"></i>' +
 												'<span class="no-video-text">No remote video available</span>' +
 											'</div>');
@@ -400,6 +409,7 @@ $(document).ready(function() {
 									$('#myvideo').remove();
 									$('#remotevideo').remove();
 									$("#videoleft").parent().unblock();
+									$('.no-video-container').remove();
 									$('#callee').empty().hide();
 									yourusername = null;
 									$('#curbitrate').hide();
diff --git a/html/videoroomtest.js b/html/videoroomtest.js
index 86ab4a0..bad7d34 100644
--- a/html/videoroomtest.js
+++ b/html/videoroomtest.js
@@ -137,7 +137,7 @@ $(document).ready(function() {
 								},
 								onmessage: function(msg, jsep) {
 									Janus.debug(" ::: Got a message (publisher) :::");
-									Janus.debug(JSON.stringify(msg));
+									Janus.debug(msg);
 									var event = msg["videoroom"];
 									Janus.debug("Event: " + event);
 									if(event != undefined && event != null) {
@@ -242,7 +242,7 @@ $(document).ready(function() {
 								onlocalstream: function(stream) {
 									Janus.debug(" ::: Got a local stream :::");
 									mystream = stream;
-									Janus.debug(JSON.stringify(stream));
+									Janus.debug(stream);
 									$('#videolocal').empty();
 									$('#videojoin').hide();
 									$('#videos').removeClass('hide').show();
@@ -409,7 +409,7 @@ function newRemoteFeed(id, display) {
 			},
 			onmessage: function(msg, jsep) {
 				Janus.debug(" ::: Got a message (listener) :::");
-				Janus.debug(JSON.stringify(msg));
+				Janus.debug(msg);
 				var event = msg["videoroom"];
 				Janus.debug("Event: " + event);
 				if(event != undefined && event != null) {
@@ -469,11 +469,19 @@ function newRemoteFeed(id, display) {
 			},
 			onremotestream: function(stream) {
 				Janus.debug("Remote feed #" + remoteFeed.rfindex);
-				if($('#remotevideo'+remoteFeed.rfindex).length === 0) {
-					// No remote video yet
-					$('#videoremote'+remoteFeed.rfindex).append('<video class="rounded centered" id="waitingvideo' + remoteFeed.rfindex + '" width=320 height=240 />');
-					$('#videoremote'+remoteFeed.rfindex).append('<video class="rounded centered relative hide" id="remotevideo' + remoteFeed.rfindex + '" width="100%" height="100%" autoplay/>');
+				if($('#remotevideo'+remoteFeed.rfindex).length > 0) {
+					// Been here already: let's see if anything changed
+					var videoTracks = stream.getVideoTracks();
+					if(videoTracks && videoTracks.length > 0 && !videoTracks[0].muted) {
+						$('#novideo'+remoteFeed.rfindex).remove();
+						if($("#remotevideo"+remoteFeed.rfindex).get(0).videoWidth)
+							$('#remotevideo'+remoteFeed.rfindex).show();
+					}
+					return;
 				}
+				// No remote video yet
+				$('#videoremote'+remoteFeed.rfindex).append('<video class="rounded centered" id="waitingvideo' + remoteFeed.rfindex + '" width=320 height=240 />');
+				$('#videoremote'+remoteFeed.rfindex).append('<video class="rounded centered relative hide" id="remotevideo' + remoteFeed.rfindex + '" width="100%" height="100%" autoplay/>');
 				$('#videoremote'+remoteFeed.rfindex).append(
 					'<span class="label label-primary hide" id="curres'+remoteFeed.rfindex+'" style="position: absolute; bottom: 0px; left: 0px; margin: 15px;"></span>' +
 					'<span class="label label-info hide" id="curbitrate'+remoteFeed.rfindex+'" style="position: absolute; bottom: 0px; right: 0px; margin: 15px;"></span>');
@@ -483,7 +491,8 @@ function newRemoteFeed(id, display) {
 						remoteFeed.spinner.stop();
 					remoteFeed.spinner = null;
 					$('#waitingvideo'+remoteFeed.rfindex).remove();
-					$('#remotevideo'+remoteFeed.rfindex).removeClass('hide');
+					if(this.videoWidth)
+						$('#remotevideo'+remoteFeed.rfindex).removeClass('hide').show();
 					var width = this.videoWidth;
 					var height = this.videoHeight;
 					$('#curres'+remoteFeed.rfindex).removeClass('hide').text(width+'x'+height).show();
@@ -502,7 +511,7 @@ function newRemoteFeed(id, display) {
 					// No remote video
 					$('#remotevideo'+remoteFeed.rfindex).hide();
 					$('#videoremote'+remoteFeed.rfindex).append(
-						'<div class="no-video-container">' +
+						'<div id="novideo'+remoteFeed.rfindex+'" class="no-video-container">' +
 							'<i class="fa fa-video-camera fa-5 no-video-icon" style="height: 100%;"></i>' +
 							'<span class="no-video-text" style="font-size: 16px;">No remote video available</span>' +
 						'</div>');
@@ -527,7 +536,9 @@ function newRemoteFeed(id, display) {
 				if(remoteFeed.spinner !== undefined && remoteFeed.spinner !== null)
 					remoteFeed.spinner.stop();
 				remoteFeed.spinner = null;
+				$('#remotevideo'+remoteFeed.rfindex).remove();
 				$('#waitingvideo'+remoteFeed.rfindex).remove();
+				$('#novideo'+remoteFeed.rfindex).remove();
 				$('#curbitrate'+remoteFeed.rfindex).remove();
 				$('#curres'+remoteFeed.rfindex).remove();
 				if(bitrateTimer[remoteFeed.rfindex] !== null && bitrateTimer[remoteFeed.rfindex] !== null) 
diff --git a/html/voicemailtest.js b/html/voicemailtest.js
index 52d3fc1..ee6c27b 100644
--- a/html/voicemailtest.js
+++ b/html/voicemailtest.js
@@ -125,7 +125,7 @@ $(document).ready(function() {
 								},
 								onmessage: function(msg, jsep) {
 									Janus.debug(" ::: Got a message :::");
-									Janus.debug(JSON.stringify(msg));
+									Janus.debug(msg);
 									var event = msg["voicemail"];
 									Janus.debug("Event: " + event);
 									if(event != undefined && event != null) {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-voip/janus.git



More information about the Pkg-voip-commits mailing list