Преглед на файлове

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

master
paweldomas преди 11 години
родител
ревизия
68b8512b27
променени са 1 файла, в които са добавени 26 реда и са изтрити 5 реда
  1. 26
    5
      app.js

+ 26
- 5
app.js Целия файл

48
             if (config.useStunTurn) {
48
             if (config.useStunTurn) {
49
                 connection.jingle.getStunAndTurnCredentials();
49
                 connection.jingle.getStunAndTurnCredentials();
50
             }
50
             }
51
-            getUserMediaWithConstraints( ['audio'], audioStreamReady,
52
-                function(error){
53
-                    console.error('failed to obtain audio stream - stop', error);
54
-                });
51
+            obtainAudioAndVideoPermissions(function(){
52
+                getUserMediaWithConstraints( ['audio'], audioStreamReady,
53
+                    function(error){
54
+                        console.error('failed to obtain audio stream - stop', error);
55
+                    });
56
+            });
57
+
55
             document.getElementById('connect').disabled = true;
58
             document.getElementById('connect').disabled = true;
56
         } else {
59
         } else {
57
             console.log('status', status);
60
             console.log('status', status);
59
     });
62
     });
60
 }
63
 }
61
 
64
 
65
+/**
66
+ * We first ask for audio and video combined stream in order to get permissions and not to ask twice.
67
+ * Then we dispose the stream and continue with separate audio, video streams(required for desktop sharing).
68
+ */
69
+function obtainAudioAndVideoPermissions(callback){
70
+    // Get AV
71
+    getUserMediaWithConstraints(
72
+        ['audio', 'video'],
73
+        function(avStream) {
74
+            avStream.stop();
75
+            callback();
76
+        },
77
+        function(error){
78
+            console.error('failed to obtain audio/video stream - stop', error);
79
+        });
80
+}
81
+
62
 function audioStreamReady(stream) {
82
 function audioStreamReady(stream) {
63
 
83
 
64
     change_local_audio(stream);
84
     change_local_audio(stream);
965
 
985
 
966
 function disposeConference() {
986
 function disposeConference() {
967
     var handler = getConferenceHandler();
987
     var handler = getConferenceHandler();
968
-    if(handler) {
988
+    if(handler && handler.peerconnection) {
989
+        // FIXME: probably removing streams is not required and close() should be enough
969
         if(connection.jingle.localAudio) {
990
         if(connection.jingle.localAudio) {
970
             handler.peerconnection.removeStream(connection.jingle.localAudio);
991
             handler.peerconnection.removeStream(connection.jingle.localAudio);
971
         }
992
         }

Loading…
Отказ
Запис