Revision 7d20a360

View differences:

html/devicetest.js
364 364
										echotest.send({"message": { "bitrate": bitrate }});
365 365
										return false;
366 366
									});
367
									if(adapter.browserDetails.browser === "chrome" || adapter.browserDetails.browser === "firefox") {
367
									if(adapter.browserDetails.browser === "chrome" || adapter.browserDetails.browser === "firefox" ||
368
											adapter.browserDetails.browser === "safari") {
368 369
										$('#curbitrate').removeClass('hide').show();
369 370
										bitrateTimer = setInterval(function() {
370 371
											// Display updated bitrate, if supported
html/echotest.js
285 285
										echotest.send({"message": { "bitrate": bitrate }});
286 286
										return false;
287 287
									});
288
									if(adapter.browserDetails.browser === "chrome" || adapter.browserDetails.browser === "firefox") {
288
									if(adapter.browserDetails.browser === "chrome" || adapter.browserDetails.browser === "firefox" ||
289
											adapter.browserDetails.browser === "safari") {
289 290
										$('#curbitrate').removeClass('hide').show();
290 291
										bitrateTimer = setInterval(function() {
291 292
											// Display updated bitrate, if supported
html/janus.js
767 767
		if(apisecret !== null && apisecret !== undefined)
768 768
			request["apisecret"] = apisecret;
769 769
		// If we know the browser supports BUNDLE and/or rtcp-mux, let's advertise those right away
770
		if(adapter.browserDetails.browser == "chrome" || adapter.browserDetails.browser == "firefox") {
770
		if(adapter.browserDetails.browser == "chrome" || adapter.browserDetails.browser == "firefox" ||
771
				adapter.browserDetails.browser == "safari") {
771 772
			request["force-bundle"] = true;
772 773
			request["force-rtcp-mux"] = true;
773 774
		}
......
1989 1990
		if(config.pc === null || config.pc === undefined)
1990 1991
			return "Invalid PeerConnection";
1991 1992
		// Start getting the bitrate, if getStats is supported
1992
		if(config.pc.getStats && adapter.browserDetails.browser == "chrome") {
1993
			// Do it the Chrome way
1994
			if(config.remoteStream === null || config.remoteStream === undefined) {
1995
				Janus.warn("Remote stream unavailable");
1996
				return "Remote stream unavailable";
1997
			}
1998
			// http://webrtc.googlecode.com/svn/trunk/samples/js/demos/html/constraints-and-stats.html
1993
		if(config.pc.getStats) {
1999 1994
			if(config.bitrate.timer === null || config.bitrate.timer === undefined) {
2000
				Janus.log("Starting bitrate timer (Chrome)");
1995
				Janus.log("Starting bitrate timer (via getStats)");
2001 1996
				config.bitrate.timer = setInterval(function() {
2002
					config.pc.getStats(function(stats) {
2003
						var results = stats.result();
2004
						for(var i=0; i<results.length; i++) {
2005
							var res = results[i];
2006
							if(res.type == 'ssrc' && res.stat('googFrameHeightReceived')) {
2007
								config.bitrate.bsnow = res.stat('bytesReceived');
2008
								config.bitrate.tsnow = res.timestamp;
2009
								if(config.bitrate.bsbefore === null || config.bitrate.tsbefore === null) {
2010
									// Skip this round
2011
									config.bitrate.bsbefore = config.bitrate.bsnow;
2012
									config.bitrate.tsbefore = config.bitrate.tsnow;
2013
								} else {
2014
									// Calculate bitrate
2015
									var bitRate = Math.round((config.bitrate.bsnow - config.bitrate.bsbefore) * 8 / (config.bitrate.tsnow - config.bitrate.tsbefore));
2016
									config.bitrate.value = bitRate + ' kbits/sec';
2017
									//~ Janus.log("Estimated bitrate is " + config.bitrate.value);
2018
									config.bitrate.bsbefore = config.bitrate.bsnow;
2019
									config.bitrate.tsbefore = config.bitrate.tsnow;
1997
					config.pc.getStats()
1998
						.then(function(stats) {
1999
							stats.forEach(res => {
2000
								if(res && (res.mediaType === "video" || res.id.toLowerCase().indexOf("video") > -1) &&
2001
										res.type === "inbound-rtp" && res.id.indexOf("rtcp") < 0) {
2002
									config.bitrate.bsnow = res.bytesReceived;
2003
									config.bitrate.tsnow = res.timestamp;
2004
									if(config.bitrate.bsbefore === null || config.bitrate.tsbefore === null) {
2005
										// Skip this round
2006
										config.bitrate.bsbefore = config.bitrate.bsnow;
2007
										config.bitrate.tsbefore = config.bitrate.tsnow;
2008
									} else {
2009
										// Calculate bitrate
2010
										var timePassed = config.bitrate.tsnow - config.bitrate.tsbefore;
2011
										if(adapter.browserDetails.browser == "safari")
2012
											timePassed = timePassed/1000;	// Apparently the timestamp is in microseconds, in Safari
2013
										var bitRate = Math.round((config.bitrate.bsnow - config.bitrate.bsbefore) * 8 / timePassed);
2014
										config.bitrate.value = bitRate + ' kbits/sec';
2015
										//~ Janus.log("Estimated bitrate is " + config.bitrate.value);
2016
										config.bitrate.bsbefore = config.bitrate.bsnow;
2017
										config.bitrate.tsbefore = config.bitrate.tsnow;
2018
									}
2020 2019
								}
2021
							}
2022
						}
2023
					});
2024
				}, 1000);
2025
				return "0 kbits/sec";	// We don't have a bitrate value yet
2026
			}
2027
			return config.bitrate.value;
2028
		} else if(config.pc.getStats && adapter.browserDetails.browser == "firefox") {
2029
			// Do it the Firefox way
2030
			if(config.remoteStream === null || config.remoteStream === undefined
2031
					|| config.remoteStream.streams[0] === null || config.remoteStream.streams[0] === undefined) {
2032
				Janus.warn("Remote stream unavailable");
2033
				return "Remote stream unavailable";
2034
			}
2035
			var videoTracks = config.remoteStream.streams[0].getVideoTracks();
2036
			if(videoTracks === null || videoTracks === undefined || videoTracks.length < 1) {
2037
				Janus.warn("No video track");
2038
				return "No video track";
2039
			}
2040
			// https://github.com/muaz-khan/getStats/blob/master/getStats.js
2041
			if(config.bitrate.timer === null || config.bitrate.timer === undefined) {
2042
				Janus.log("Starting bitrate timer (Firefox)");
2043
				config.bitrate.timer = setInterval(function() {
2044
					// We need a helper callback
2045
					var cb = function(res) {
2046
						if(res === null || res === undefined ||
2047
								res.inbound_rtp_video_1 == null || res.inbound_rtp_video_1 == null) {
2048
							config.bitrate.value = "Missing inbound_rtp_video_1";
2049
							return;
2050
						}
2051
						config.bitrate.bsnow = res.inbound_rtp_video_1.bytesReceived;
2052
						config.bitrate.tsnow = res.inbound_rtp_video_1.timestamp;
2053
						if(config.bitrate.bsbefore === null || config.bitrate.tsbefore === null) {
2054
							// Skip this round
2055
							config.bitrate.bsbefore = config.bitrate.bsnow;
2056
							config.bitrate.tsbefore = config.bitrate.tsnow;
2057
						} else {
2058
							// Calculate bitrate
2059
							var bitRate = Math.round((config.bitrate.bsnow - config.bitrate.bsbefore) * 8 / (config.bitrate.tsnow - config.bitrate.tsbefore));
2060
							config.bitrate.value = bitRate + ' kbits/sec';
2061
							config.bitrate.bsbefore = config.bitrate.bsnow;
2062
							config.bitrate.tsbefore = config.bitrate.tsnow;
2063
						}
2064
					};
2065
					// Actually get the stats
2066
					config.pc.getStats(videoTracks[0], function(stats) {
2067
						cb(stats);
2068
					}, cb);
2020
							});
2021
						});
2069 2022
				}, 1000);
2070 2023
				return "0 kbits/sec";	// We don't have a bitrate value yet
2071 2024
			}
html/janus.nojquery.js
828 828
		if(apisecret !== null && apisecret !== undefined)
829 829
			request["apisecret"] = apisecret;
830 830
		// If we know the browser supports BUNDLE and/or rtcp-mux, let's advertise those right away
831
		if(adapter.browserDetails.browser == "chrome" || adapter.browserDetails.browser == "firefox") {
831
		if(adapter.browserDetails.browser == "chrome" || adapter.browserDetails.browser == "firefox" ||
832
				adapter.browserDetails.browser == "safari") {
832 833
			request["force-bundle"] = true;
833 834
			request["force-rtcp-mux"] = true;
834 835
		}
......
2041 2042
		if(config.pc === null || config.pc === undefined)
2042 2043
			return "Invalid PeerConnection";
2043 2044
		// Start getting the bitrate, if getStats is supported
2044
		if(config.pc.getStats && adapter.browserDetails.browser == "chrome") {
2045
			// Do it the Chrome way
2046
			if(config.remoteStream === null || config.remoteStream === undefined) {
2047
				Janus.warn("Remote stream unavailable");
2048
				return "Remote stream unavailable";
2049
			}
2050
			// http://webrtc.googlecode.com/svn/trunk/samples/js/demos/html/constraints-and-stats.html
2045
		if(config.pc.getStats) {
2051 2046
			if(config.bitrate.timer === null || config.bitrate.timer === undefined) {
2052
				Janus.log("Starting bitrate timer (Chrome)");
2047
				Janus.log("Starting bitrate timer (via getStats)");
2053 2048
				config.bitrate.timer = setInterval(function() {
2054
					config.pc.getStats(function(stats) {
2055
						var results = stats.result();
2056
						for(var i=0; i<results.length; i++) {
2057
							var res = results[i];
2058
							if(res.type == 'ssrc' && res.stat('googFrameHeightReceived')) {
2059
								config.bitrate.bsnow = res.stat('bytesReceived');
2060
								config.bitrate.tsnow = res.timestamp;
2061
								if(config.bitrate.bsbefore === null || config.bitrate.tsbefore === null) {
2062
									// Skip this round
2063
									config.bitrate.bsbefore = config.bitrate.bsnow;
2064
									config.bitrate.tsbefore = config.bitrate.tsnow;
2065
								} else {
2066
									// Calculate bitrate
2067
									var bitRate = Math.round((config.bitrate.bsnow - config.bitrate.bsbefore) * 8 / (config.bitrate.tsnow - config.bitrate.tsbefore));
2068
									config.bitrate.value = bitRate + ' kbits/sec';
2069
									//~ Janus.log("Estimated bitrate is " + config.bitrate.value);
2070
									config.bitrate.bsbefore = config.bitrate.bsnow;
2071
									config.bitrate.tsbefore = config.bitrate.tsnow;
2049
					config.pc.getStats()
2050
						.then(function(stats) {
2051
							stats.forEach(res => {
2052
								if(res && (res.mediaType === "video" || res.id.toLowerCase().indexOf("video") > -1) &&
2053
										res.type === "inbound-rtp" && res.id.indexOf("rtcp") < 0) {
2054
									config.bitrate.bsnow = res.bytesReceived;
2055
									config.bitrate.tsnow = res.timestamp;
2056
									if(config.bitrate.bsbefore === null || config.bitrate.tsbefore === null) {
2057
										// Skip this round
2058
										config.bitrate.bsbefore = config.bitrate.bsnow;
2059
										config.bitrate.tsbefore = config.bitrate.tsnow;
2060
									} else {
2061
										// Calculate bitrate
2062
										if(adapter.browserDetails.browser == "safari")
2063
											timePassed = timePassed/1000;	// Apparently the timestamp is in microseconds, in Safari
2064
										var bitRate = Math.round((config.bitrate.bsnow - config.bitrate.bsbefore) * 8 / timePassed);
2065
										config.bitrate.value = bitRate + ' kbits/sec';
2066
										//~ Janus.log("Estimated bitrate is " + config.bitrate.value);
2067
										config.bitrate.bsbefore = config.bitrate.bsnow;
2068
										config.bitrate.tsbefore = config.bitrate.tsnow;
2069
									}
2072 2070
								}
2073
							}
2074
						}
2075
					});
2076
				}, 1000);
2077
				return "0 kbits/sec";	// We don't have a bitrate value yet
2078
			}
2079
			return config.bitrate.value;
2080
		} else if(config.pc.getStats && adapter.browserDetails.browser == "firefox") {
2081
			// Do it the Firefox way
2082
			if(config.remoteStream === null || config.remoteStream === undefined
2083
					|| config.remoteStream.streams[0] === null || config.remoteStream.streams[0] === undefined) {
2084
				Janus.warn("Remote stream unavailable");
2085
				return "Remote stream unavailable";
2086
			}
2087
			var videoTracks = config.remoteStream.streams[0].getVideoTracks();
2088
			if(videoTracks === null || videoTracks === undefined || videoTracks.length < 1) {
2089
				Janus.warn("No video track");
2090
				return "No video track";
2091
			}
2092
			// https://github.com/muaz-khan/getStats/blob/master/getStats.js
2093
			if(config.bitrate.timer === null || config.bitrate.timer === undefined) {
2094
				Janus.log("Starting bitrate timer (Firefox)");
2095
				config.bitrate.timer = setInterval(function() {
2096
					// We need a helper callback
2097
					var cb = function(res) {
2098
						if(res === null || res === undefined ||
2099
								res.inbound_rtp_video_1 == null || res.inbound_rtp_video_1 == null) {
2100
							config.bitrate.value = "Missing inbound_rtp_video_1";
2101
							return;
2102
						}
2103
						config.bitrate.bsnow = res.inbound_rtp_video_1.bytesReceived;
2104
						config.bitrate.tsnow = res.inbound_rtp_video_1.timestamp;
2105
						if(config.bitrate.bsbefore === null || config.bitrate.tsbefore === null) {
2106
							// Skip this round
2107
							config.bitrate.bsbefore = config.bitrate.bsnow;
2108
							config.bitrate.tsbefore = config.bitrate.tsnow;
2109
						} else {
2110
							// Calculate bitrate
2111
							var bitRate = Math.round((config.bitrate.bsnow - config.bitrate.bsbefore) * 8 / (config.bitrate.tsnow - config.bitrate.tsbefore));
2112
							config.bitrate.value = bitRate + ' kbits/sec';
2113
							config.bitrate.bsbefore = config.bitrate.bsnow;
2114
							config.bitrate.tsbefore = config.bitrate.tsnow;
2115
						}
2116
					};
2117
					// Actually get the stats
2118
					config.pc.getStats(videoTracks[0], function(stats) {
2119
						cb(stats);
2120
					}, cb);
2071
							});
2072
						});
2121 2073
				}, 1000);
2122 2074
				return "0 kbits/sec";	// We don't have a bitrate value yet
2123 2075
			}
html/videocalltest.js
371 371
										videocall.send({"message": { "request": "set", "bitrate": bitrate }});
372 372
										return false;
373 373
									});
374
									if(adapter.browserDetails.browser === "chrome" || adapter.browserDetails.browser === "firefox") {
374
									if(adapter.browserDetails.browser === "chrome" || adapter.browserDetails.browser === "firefox" ||
375
											adapter.browserDetails.browser === "safari") {
375 376
										$('#curbitrate').removeClass('hide').show();
376 377
										bitrateTimer = setInterval(function() {
377 378
											// Display updated bitrate, if supported
html/videoroomtest.js
507 507
							'<span class="no-video-text" style="font-size: 16px;">No remote video available</span>' +
508 508
						'</div>');
509 509
				}
510
				if(adapter.browserDetails.browser === "chrome" || adapter.browserDetails.browser === "firefox") {
510
				if(adapter.browserDetails.browser === "chrome" || adapter.browserDetails.browser === "firefox" ||
511
						adapter.browserDetails.browser === "safari") {
511 512
					$('#curbitrate'+remoteFeed.rfindex).removeClass('hide').show();
512 513
					bitrateTimer[remoteFeed.rfindex] = setInterval(function() {
513 514
						// Display updated bitrate, if supported

Also available in: Unified diff