瀏覽代碼

Turns off the camera when video is muted on https connection.

j8
hristoterezov 10 年之前
父節點
當前提交
3a0ee11ccd
共有 8 個文件被更改,包括 1343 次插入1293 次删除
  1. 1
    1
      index.html
  2. 1240
    1213
      libs/app.bundle.js
  3. 25
    5
      modules/RTC/LocalStream.js
  4. 28
    1
      modules/RTC/RTC.js
  5. 9
    5
      modules/RTC/RTCUtils.js
  6. 16
    15
      modules/UI/UI.js
  7. 0
    26
      modules/xmpp/JingleSession.js
  8. 24
    27
      modules/xmpp/xmpp.js

+ 1
- 1
index.html 查看文件

@@ -19,7 +19,7 @@
19 19
     <script src="libs/popover.js?v=1"></script><!-- bootstrap tooltip lib -->
20 20
     <script src="libs/toastr.js?v=1"></script><!-- notifications lib -->
21 21
     <script src="interface_config.js?v=5"></script>
22
-    <script src="libs/app.bundle.js?v=43"></script>
22
+    <script src="libs/app.bundle.js?v=44"></script>
23 23
     <script src="analytics.js?v=1"></script><!-- google analytics plugin -->
24 24
     <link rel="stylesheet" href="css/font.css?v=6"/>
25 25
     <link rel="stylesheet" href="css/toastr.css?v=1">

+ 1240
- 1213
libs/app.bundle.js
文件差異過大導致無法顯示
查看文件


+ 25
- 5
modules/RTC/LocalStream.js 查看文件

@@ -1,5 +1,6 @@
1 1
 var StreamEventTypes = require("../../service/RTC/StreamEventTypes.js");
2 2
 
3
+
3 4
 function LocalStream(stream, type, eventEmitter, videoType)
4 5
 {
5 6
     this.stream = stream;
@@ -53,10 +54,29 @@ LocalStream.prototype.mute = function()
53 54
 
54 55
 LocalStream.prototype.setMute = function(mute)
55 56
 {
56
-    var tracks = this.getTracks();
57 57
 
58
-    for (var idx = 0; idx < tracks.length; idx++) {
59
-        tracks[idx].enabled = mute;
58
+    if(window.location.protocol != "https:" ||
59
+        this.isAudioStream() || this.videoType === "screen")
60
+    {
61
+        var tracks = this.getTracks();
62
+
63
+        for (var idx = 0; idx < tracks.length; idx++) {
64
+            tracks[idx].enabled = mute;
65
+        }
66
+    }
67
+    else
68
+    {
69
+        if(mute === false) {
70
+            APP.xmpp.removeStream(this.stream);
71
+            this.stream.stop();
72
+        }
73
+        else
74
+        {
75
+            APP.RTC.rtcUtils.obtainAudioAndVideoPermissions(["video"],
76
+                function (stream) {
77
+                    APP.RTC.changeLocalVideo(stream, false, function () {});
78
+                });
79
+        }
60 80
     }
61 81
 };
62 82
 
@@ -68,6 +88,8 @@ LocalStream.prototype.isMuted = function () {
68 88
     }
69 89
     else
70 90
     {
91
+        if(this.stream.ended)
92
+            return true;
71 93
         tracks = this.stream.getVideoTracks();
72 94
     }
73 95
     for (var idx = 0; idx < tracks.length; idx++) {
@@ -81,6 +103,4 @@ LocalStream.prototype.getId = function () {
81 103
     return this.stream.getTracks()[0].id;
82 104
 }
83 105
 
84
-
85
-
86 106
 module.exports = LocalStream;

+ 28
- 1
modules/RTC/RTC.js 查看文件

@@ -166,10 +166,18 @@ var RTC = {
166 166
     changeLocalVideo: function (stream, isUsingScreenStream, callback) {
167 167
         var oldStream = this.localVideo.getOriginalStream();
168 168
         var type = (isUsingScreenStream? "screen" : "video");
169
+        var localCallback = callback;
170
+        if(this.localVideo.isMuted() && this.localVideo.videoType !== type)
171
+        {
172
+            localCallback = function() {
173
+                APP.xmpp.setVideoMute(false, APP.UI.setVideoMuteButtonsState);
174
+                callback();
175
+            };
176
+        }
169 177
         this.localVideo = this.createLocalStream(stream, "video", true, type);
170 178
         // Stop the stream to trigger onended event for old stream
171 179
         oldStream.stop();
172
-        APP.xmpp.switchStreams(stream, oldStream,callback);
180
+        APP.xmpp.switchStreams(stream, oldStream,localCallback);
173 181
     },
174 182
     /**
175 183
      * Checks if video identified by given src is desktop stream.
@@ -196,6 +204,25 @@ var RTC = {
196 204
             isDesktop = (stream.videoType === "screen");
197 205
 
198 206
         return isDesktop;
207
+    },
208
+    setVideoMute: function(mute, callback, options) {
209
+        if(!this.localVideo)
210
+            return;
211
+
212
+        if (mute == APP.RTC.localVideo.isMuted())
213
+        {
214
+            APP.xmpp.sendVideoInfoPresence(mute);
215
+            if(callback)
216
+                callback();
217
+        }
218
+        else
219
+        {
220
+            APP.RTC.localVideo.setMute(!mute);
221
+            APP.xmpp.setVideoMute(
222
+                mute,
223
+                callback,
224
+                options);
225
+        }
199 226
     }
200 227
 };
201 228
 

+ 9
- 5
modules/RTC/RTCUtils.js 查看文件

@@ -272,14 +272,20 @@ RTCUtils.prototype.getUserMediaWithConstraints = function(
272 272
  * We ask for audio and video combined stream in order to get permissions and
273 273
  * not to ask twice.
274 274
  */
275
-RTCUtils.prototype.obtainAudioAndVideoPermissions = function() {
275
+RTCUtils.prototype.obtainAudioAndVideoPermissions = function(devices, callback) {
276 276
     var self = this;
277 277
     // Get AV
278 278
 
279
+    if(!devices)
280
+        devices = ['audio', 'video'];
281
+
279 282
     this.getUserMediaWithConstraints(
280
-        ['audio', 'video'],
283
+        devices,
281 284
         function (stream) {
282
-            self.successCallback(stream);
285
+            if(callback)
286
+                callback(stream);
287
+            else
288
+                self.successCallback(stream);
283 289
         },
284 290
         function (error) {
285 291
             self.errorCallback(error);
@@ -357,6 +363,4 @@ RTCUtils.prototype.handleLocalStream = function(stream)
357 363
 
358 364
 };
359 365
 
360
-
361
-
362 366
 module.exports = RTCUtils;

+ 16
- 15
modules/UI/UI.js 查看文件

@@ -230,21 +230,8 @@ function registerListeners() {
230 230
  * contrast to an automatic decision taken by the application logic)
231 231
  */
232 232
 function setVideoMute(mute, options) {
233
-    APP.xmpp.setVideoMute(
234
-        mute,
235
-        function (mute) {
236
-            var video = $('#video');
237
-            var communicativeClass = "icon-camera";
238
-            var muteClass = "icon-camera icon-camera-disabled";
239
-
240
-            if (mute) {
241
-                video.removeClass(communicativeClass);
242
-                video.addClass(muteClass);
243
-            } else {
244
-                video.removeClass(muteClass);
245
-                video.addClass(communicativeClass);
246
-            }
247
-        },
233
+    APP.RTC.setVideoMute(mute,
234
+        UI.setVideoMuteButtonsState,
248 235
         options);
249 236
 }
250 237
 
@@ -743,5 +730,19 @@ UI.dockToolbar = function (isDock) {
743 730
     return ToolbarToggler.dockToolbar(isDock);
744 731
 }
745 732
 
733
+UI.setVideoMuteButtonsState = function (mute) {
734
+    var video = $('#video');
735
+    var communicativeClass = "icon-camera";
736
+    var muteClass = "icon-camera icon-camera-disabled";
737
+
738
+    if (mute) {
739
+        video.removeClass(communicativeClass);
740
+        video.addClass(muteClass);
741
+    } else {
742
+        video.removeClass(muteClass);
743
+        video.addClass(communicativeClass);
744
+    }
745
+}
746
+
746 747
 module.exports = UI;
747 748
 

+ 0
- 26
modules/xmpp/JingleSession.js 查看文件

@@ -1056,26 +1056,6 @@ JingleSession.prototype.notifyMySSRCUpdate = function (old_sdp, new_sdp) {
1056 1056
     }
1057 1057
 };
1058 1058
 
1059
-/**
1060
- * Determines whether the (local) video is mute i.e. all video tracks are
1061
- * disabled.
1062
- *
1063
- * @return <tt>true</tt> if the (local) video is mute i.e. all video tracks are
1064
- * disabled; otherwise, <tt>false</tt>
1065
- */
1066
-JingleSession.prototype.isVideoMute = function () {
1067
-    var tracks = APP.RTC.localVideo.getVideoTracks();
1068
-    var mute = true;
1069
-
1070
-    for (var i = 0; i < tracks.length; ++i) {
1071
-        if (tracks[i].enabled) {
1072
-            mute = false;
1073
-            break;
1074
-        }
1075
-    }
1076
-    return mute;
1077
-};
1078
-
1079 1059
 /**
1080 1060
  * Mutes/unmutes the (local) video i.e. enables/disables all video tracks.
1081 1061
  *
@@ -1114,12 +1094,6 @@ JingleSession.prototype.setVideoMute = function (mute, callback, options) {
1114 1094
     this.modifySources(callback(mute));
1115 1095
 };
1116 1096
 
1117
-// SDP-based mute by going recvonly/sendrecv
1118
-// FIXME: should probably black out the screen as well
1119
-JingleSession.prototype.toggleVideoMute = function (callback) {
1120
-    this.service.setVideoMute(APP.RTC.localVideo.isMuted(), callback);
1121
-};
1122
-
1123 1097
 JingleSession.prototype.hardMuteVideo = function (muted) {
1124 1098
     this.pendingop = muted ? 'mute' : 'unmute';
1125 1099
 };

+ 24
- 27
modules/xmpp/xmpp.js 查看文件

@@ -202,10 +202,12 @@ var XMPP = {
202 202
             // FIXME: probably removing streams is not required and close() should
203 203
             // be enough
204 204
             if (APP.RTC.localAudio) {
205
-                handler.peerconnection.removeStream(APP.RTC.localAudio.getOriginalStream(), onUnload);
205
+                handler.peerconnection.removeStream(
206
+                    APP.RTC.localAudio.getOriginalStream(), onUnload);
206 207
             }
207 208
             if (APP.RTC.localVideo) {
208
-                handler.peerconnection.removeStream(APP.RTC.localVideo.getOriginalStream(), onUnload);
209
+                handler.peerconnection.removeStream(
210
+                    APP.RTC.localVideo.getOriginalStream(), onUnload);
209 211
             }
210 212
             handler.peerconnection.close();
211 213
         }
@@ -251,38 +253,28 @@ var XMPP = {
251 253
             callback();
252 254
         }
253 255
     },
256
+    sendVideoInfoPresence: function (mute) {
257
+        connection.emuc.addVideoInfoToPresence(mute);
258
+        connection.emuc.sendPresence();
259
+    },
254 260
     setVideoMute: function (mute, callback, options) {
255
-        if(!connection || !APP.RTC.localVideo)
261
+        if(!connection)
256 262
             return;
257
-
263
+        var self = this;
258 264
         var localCallback = function (mute) {
259
-            connection.emuc.addVideoInfoToPresence(mute);
260
-            connection.emuc.sendPresence();
265
+            self.sendVideoInfoPresence(mute);
261 266
             return callback(mute);
262 267
         };
263 268
 
264
-        if (mute == APP.RTC.localVideo.isMuted())
269
+        if(connection.jingle.activecall)
265 270
         {
266
-            // Even if no change occurs, the specified callback is to be executed.
267
-            // The specified callback may, optionally, return a successCallback
268
-            // which is to be executed as well.
269
-            var successCallback = localCallback(mute);
270
-
271
-            if (successCallback) {
272
-                successCallback();
273
-            }
274
-        } else {
275
-            APP.RTC.localVideo.setMute(!mute);
276
-            if(connection.jingle.activecall)
277
-            {
278
-                connection.jingle.activecall.setVideoMute(
279
-                    mute, localCallback, options);
280
-            }
281
-            else {
282
-                localCallback(mute);
283
-            }
284
-
271
+            connection.jingle.activecall.setVideoMute(
272
+                mute, localCallback, options);
273
+        }
274
+        else {
275
+            localCallback(mute);
285 276
         }
277
+
286 278
     },
287 279
     setAudioMute: function (mute, callback) {
288 280
         if (!(connection && APP.RTC.localAudio)) {
@@ -472,8 +464,13 @@ var XMPP = {
472 464
     },
473 465
     getSessions: function () {
474 466
         return connection.jingle.sessions;
467
+    },
468
+    removeStream: function (stream) {
469
+        if(!connection || !connection.jingle.activecall ||
470
+            !connection.jingle.activecall.peerconnection)
471
+            return;
472
+        connection.jingle.activecall.peerconnection.removeStream(stream);
475 473
     }
476
-
477 474
 };
478 475
 
479 476
 module.exports = XMPP;

Loading…
取消
儲存