Fixes NPE. Prevents from asking for permission twice(by obtaining audio+video stream and closing it).

This commit is contained in:
paweldomas 2014-03-24 18:31:59 +01:00
parent 4bb8c3c48c
commit 68b8512b27
1 changed files with 26 additions and 5 deletions

31
app.js
View File

@ -48,10 +48,13 @@ function init() {
if (config.useStunTurn) {
connection.jingle.getStunAndTurnCredentials();
}
getUserMediaWithConstraints( ['audio'], audioStreamReady,
function(error){
console.error('failed to obtain audio stream - stop', error);
});
obtainAudioAndVideoPermissions(function(){
getUserMediaWithConstraints( ['audio'], audioStreamReady,
function(error){
console.error('failed to obtain audio stream - stop', error);
});
});
document.getElementById('connect').disabled = true;
} else {
console.log('status', status);
@ -59,6 +62,23 @@ function init() {
});
}
/**
* We first ask for audio and video combined stream in order to get permissions and not to ask twice.
* Then we dispose the stream and continue with separate audio, video streams(required for desktop sharing).
*/
function obtainAudioAndVideoPermissions(callback){
// Get AV
getUserMediaWithConstraints(
['audio', 'video'],
function(avStream) {
avStream.stop();
callback();
},
function(error){
console.error('failed to obtain audio/video stream - stop', error);
});
}
function audioStreamReady(stream) {
change_local_audio(stream);
@ -965,7 +985,8 @@ $(window).bind('beforeunload', function () {
function disposeConference() {
var handler = getConferenceHandler();
if(handler) {
if(handler && handler.peerconnection) {
// FIXME: probably removing streams is not required and close() should be enough
if(connection.jingle.localAudio) {
handler.peerconnection.removeStream(connection.jingle.localAudio);
}