Selaa lähdekoodia

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

j8
hristoterezov 10 vuotta sitten
vanhempi
commit
3a0ee11ccd
8 muutettua tiedostoa jossa 1343 lisäystä ja 1293 poistoa
  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 Näytä tiedosto

19
     <script src="libs/popover.js?v=1"></script><!-- bootstrap tooltip lib -->
19
     <script src="libs/popover.js?v=1"></script><!-- bootstrap tooltip lib -->
20
     <script src="libs/toastr.js?v=1"></script><!-- notifications lib -->
20
     <script src="libs/toastr.js?v=1"></script><!-- notifications lib -->
21
     <script src="interface_config.js?v=5"></script>
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
     <script src="analytics.js?v=1"></script><!-- google analytics plugin -->
23
     <script src="analytics.js?v=1"></script><!-- google analytics plugin -->
24
     <link rel="stylesheet" href="css/font.css?v=6"/>
24
     <link rel="stylesheet" href="css/font.css?v=6"/>
25
     <link rel="stylesheet" href="css/toastr.css?v=1">
25
     <link rel="stylesheet" href="css/toastr.css?v=1">

+ 1240
- 1213
libs/app.bundle.js
File diff suppressed because it is too large
Näytä tiedosto


+ 25
- 5
modules/RTC/LocalStream.js Näytä tiedosto

1
 var StreamEventTypes = require("../../service/RTC/StreamEventTypes.js");
1
 var StreamEventTypes = require("../../service/RTC/StreamEventTypes.js");
2
 
2
 
3
+
3
 function LocalStream(stream, type, eventEmitter, videoType)
4
 function LocalStream(stream, type, eventEmitter, videoType)
4
 {
5
 {
5
     this.stream = stream;
6
     this.stream = stream;
53
 
54
 
54
 LocalStream.prototype.setMute = function(mute)
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
     }
88
     }
69
     else
89
     else
70
     {
90
     {
91
+        if(this.stream.ended)
92
+            return true;
71
         tracks = this.stream.getVideoTracks();
93
         tracks = this.stream.getVideoTracks();
72
     }
94
     }
73
     for (var idx = 0; idx < tracks.length; idx++) {
95
     for (var idx = 0; idx < tracks.length; idx++) {
81
     return this.stream.getTracks()[0].id;
103
     return this.stream.getTracks()[0].id;
82
 }
104
 }
83
 
105
 
84
-
85
-
86
 module.exports = LocalStream;
106
 module.exports = LocalStream;

+ 28
- 1
modules/RTC/RTC.js Näytä tiedosto

166
     changeLocalVideo: function (stream, isUsingScreenStream, callback) {
166
     changeLocalVideo: function (stream, isUsingScreenStream, callback) {
167
         var oldStream = this.localVideo.getOriginalStream();
167
         var oldStream = this.localVideo.getOriginalStream();
168
         var type = (isUsingScreenStream? "screen" : "video");
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
         this.localVideo = this.createLocalStream(stream, "video", true, type);
177
         this.localVideo = this.createLocalStream(stream, "video", true, type);
170
         // Stop the stream to trigger onended event for old stream
178
         // Stop the stream to trigger onended event for old stream
171
         oldStream.stop();
179
         oldStream.stop();
172
-        APP.xmpp.switchStreams(stream, oldStream,callback);
180
+        APP.xmpp.switchStreams(stream, oldStream,localCallback);
173
     },
181
     },
174
     /**
182
     /**
175
      * Checks if video identified by given src is desktop stream.
183
      * Checks if video identified by given src is desktop stream.
196
             isDesktop = (stream.videoType === "screen");
204
             isDesktop = (stream.videoType === "screen");
197
 
205
 
198
         return isDesktop;
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 Näytä tiedosto

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

+ 16
- 15
modules/UI/UI.js Näytä tiedosto

230
  * contrast to an automatic decision taken by the application logic)
230
  * contrast to an automatic decision taken by the application logic)
231
  */
231
  */
232
 function setVideoMute(mute, options) {
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
         options);
235
         options);
249
 }
236
 }
250
 
237
 
743
     return ToolbarToggler.dockToolbar(isDock);
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
 module.exports = UI;
747
 module.exports = UI;
747
 
748
 

+ 0
- 26
modules/xmpp/JingleSession.js Näytä tiedosto

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
  * Mutes/unmutes the (local) video i.e. enables/disables all video tracks.
1060
  * Mutes/unmutes the (local) video i.e. enables/disables all video tracks.
1081
  *
1061
  *
1114
     this.modifySources(callback(mute));
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
 JingleSession.prototype.hardMuteVideo = function (muted) {
1097
 JingleSession.prototype.hardMuteVideo = function (muted) {
1124
     this.pendingop = muted ? 'mute' : 'unmute';
1098
     this.pendingop = muted ? 'mute' : 'unmute';
1125
 };
1099
 };

+ 24
- 27
modules/xmpp/xmpp.js Näytä tiedosto

202
             // FIXME: probably removing streams is not required and close() should
202
             // FIXME: probably removing streams is not required and close() should
203
             // be enough
203
             // be enough
204
             if (APP.RTC.localAudio) {
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
             if (APP.RTC.localVideo) {
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
             handler.peerconnection.close();
212
             handler.peerconnection.close();
211
         }
213
         }
251
             callback();
253
             callback();
252
         }
254
         }
253
     },
255
     },
256
+    sendVideoInfoPresence: function (mute) {
257
+        connection.emuc.addVideoInfoToPresence(mute);
258
+        connection.emuc.sendPresence();
259
+    },
254
     setVideoMute: function (mute, callback, options) {
260
     setVideoMute: function (mute, callback, options) {
255
-        if(!connection || !APP.RTC.localVideo)
261
+        if(!connection)
256
             return;
262
             return;
257
-
263
+        var self = this;
258
         var localCallback = function (mute) {
264
         var localCallback = function (mute) {
259
-            connection.emuc.addVideoInfoToPresence(mute);
260
-            connection.emuc.sendPresence();
265
+            self.sendVideoInfoPresence(mute);
261
             return callback(mute);
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
     setAudioMute: function (mute, callback) {
279
     setAudioMute: function (mute, callback) {
288
         if (!(connection && APP.RTC.localAudio)) {
280
         if (!(connection && APP.RTC.localAudio)) {
472
     },
464
     },
473
     getSessions: function () {
465
     getSessions: function () {
474
         return connection.jingle.sessions;
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
 module.exports = XMPP;
476
 module.exports = XMPP;

Loading…
Peruuta
Tallenna