Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix volume-related functions in janus.js #1935

Merged
merged 1 commit into from Feb 5, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 11 additions & 12 deletions html/janus.js
Expand Up @@ -2897,8 +2897,10 @@ function Janus(gatewayCallbacks) {
var config = pluginHandle.webrtcStuff;
if(!config.volume[stream])
config.volume[stream] = { value: 0 };
// Start getting the volume, if getStats is supported
if(config.pc.getStats && Janus.webRTCAdapter.browserDetails.browser === "chrome") {
// Start getting the volume, if audioLevel in getStats is supported (apparently
// they're only available in Chrome/Safari right now: https://webrtc-stats.callstats.io/)
if(config.pc.getStats && (Janus.webRTCAdapter.browserDetails.browser === "chrome" ||
Janus.webRTCAdapter.browserDetails.browser === "safari")) {
if(remote && !config.remoteStream) {
Janus.warn("Remote stream unavailable");
return 0;
Expand All @@ -2911,16 +2913,13 @@ function Janus(gatewayCallbacks) {
config.volume[stream].timer = setInterval(function() {
config.pc.getStats()
.then(function(stats) {
var results = stats.result();
for(var i=0; i<results.length; i++) {
var res = results[i];
if(res.type == 'ssrc') {
if(remote && res.stat('audioOutputLevel'))
config.volume[stream].value = parseInt(res.stat('audioOutputLevel'));
else if(!remote && res.stat('audioInputLevel'))
config.volume[stream].value = parseInt(res.stat('audioInputLevel'));
}
}
stats.forEach(function (res) {
if(!res || res.kind !== "audio")
return;
if((remote && !res.remoteSource) || (!remote && res.type !== "media-source"))
return;
config.volume[stream].value = (res.audioLevel ? res.audioLevel : 0);
});
});
}, 200);
return 0; // We don't have a volume to return yet
Expand Down