瀏覽代碼

Removes local streams from the connection object.

j8
hristoterezov 10 年之前
父節點
當前提交
e6fbb0934e

+ 15
- 46
app.js 查看文件

@@ -58,11 +58,6 @@ function init() {
58 58
 }
59 59
 
60 60
 function connect(jid, password) {
61
-    var localAudio, localVideo;
62
-    if (connection && connection.jingle) {
63
-        localAudio = connection.jingle.localAudio;
64
-        localVideo = connection.jingle.localVideo;
65
-    }
66 61
     connection = new Strophe.Connection(document.getElementById('boshURL').value || config.bosh || '/http-bind');
67 62
 
68 63
     var settings = UI.getSettings();
@@ -86,8 +81,6 @@ function connect(jid, password) {
86 81
         if (!connection.jingle.pc_constraints.optional) connection.jingle.pc_constraints.optional = [];
87 82
         connection.jingle.pc_constraints.optional.push({googIPv6: true});
88 83
     }
89
-    if (localAudio) connection.jingle.localAudio = localAudio;
90
-    if (localVideo) connection.jingle.localVideo = localVideo;
91 84
 
92 85
     if(!password)
93 86
         password = document.getElementById('password').value;
@@ -127,7 +120,7 @@ function connect(jid, password) {
127 120
 
128 121
 function maybeDoJoin() {
129 122
     if (connection && connection.connected && Strophe.getResourceFromJid(connection.jid) // .connected is true while connecting?
130
-        && (connection.jingle.localAudio || connection.jingle.localVideo)) {
123
+        && (RTC.localAudio || RTC.localVideo)) {
131 124
         doJoin();
132 125
     }
133 126
 }
@@ -300,7 +293,7 @@ function waitForPresence(data, sid) {
300 293
     if (isVideo &&
301 294
         data.peerjid && sess.peerjid === data.peerjid &&
302 295
         data.stream.getVideoTracks().length === 0 &&
303
-        connection.jingle.localVideo.getVideoTracks().length > 0) {
296
+        RTC.localVideo.getTracks().length > 0) {
304 297
         //
305 298
         window.setTimeout(function () {
306 299
             sendKeyframe(sess.peerconnection);
@@ -621,11 +614,9 @@ function isVideoSrcDesktop(jid) {
621 614
  * contrast to an automatic decision taken by the application logic)
622 615
  */
623 616
 function setVideoMute(mute, options) {
624
-    if (connection && connection.jingle.localVideo) {
625
-        var session = activecall;
626
-
627
-        if (session) {
628
-            session.setVideoMute(
617
+    if (connection && RTC.localVideo) {
618
+        if (activecall) {
619
+            activecall.setVideoMute(
629 620
                 mute,
630 621
                 function (mute) {
631 622
                     var video = $('#video');
@@ -659,12 +650,8 @@ $(document).on('inlastnchanged', function (event, oldValue, newValue) {
659 650
 function toggleVideo() {
660 651
     buttonClick("#video", "icon-camera icon-camera-disabled");
661 652
 
662
-    if (connection && connection.jingle.localVideo) {
663
-        var session = activecall;
664
-
665
-        if (session) {
666
-            setVideoMute(!session.isVideoMute());
667
-        }
653
+    if (connection && activecall && RTC.localVideo ) {
654
+        setVideoMute(!RTC.localVideo.isMuted());
668 655
     }
669 656
 }
670 657
 
@@ -672,14 +659,14 @@ function toggleVideo() {
672 659
  * Mutes / unmutes audio for the local participant.
673 660
  */
674 661
 function toggleAudio() {
675
-    setAudioMuted(!isAudioMuted());
662
+    setAudioMuted(!RTC.localAudio.isMuted());
676 663
 }
677 664
 
678 665
 /**
679 666
  * Sets muted audio state for the local participant.
680 667
  */
681 668
 function setAudioMuted(mute) {
682
-    if (!(connection && connection.jingle.localAudio)) {
669
+    if (!(connection && RTC.localAudio)) {
683 670
         preMuted = mute;
684 671
         // We still click the button.
685 672
         buttonClick("#mute", "icon-microphone icon-mic-disabled");
@@ -693,7 +680,7 @@ function setAudioMuted(mute) {
693 680
         forceMuted = false;
694 681
     }
695 682
 
696
-    if (mute == isAudioMuted()) {
683
+    if (mute == RTC.localAudio.isMuted()) {
697 684
         // Nothing to do
698 685
         return;
699 686
     }
@@ -701,12 +688,7 @@ function setAudioMuted(mute) {
701 688
     // It is not clear what is the right way to handle multiple tracks.
702 689
     // So at least make sure that they are all muted or all unmuted and
703 690
     // that we send presence just once.
704
-    var localAudioTracks = connection.jingle.localAudio.getAudioTracks();
705
-    if (localAudioTracks.length > 0) {
706
-        for (var idx = 0; idx < localAudioTracks.length; idx++) {
707
-            localAudioTracks[idx].enabled = !mute;
708
-        }
709
-    }
691
+    RTC.localAudio.mute();
710 692
     // isMuted is the opposite of audioEnabled
711 693
     connection.emuc.addAudioInfoToPresence(mute);
712 694
     connection.emuc.sendPresence();
@@ -715,19 +697,6 @@ function setAudioMuted(mute) {
715 697
     buttonClick("#mute", "icon-microphone icon-mic-disabled");
716 698
 }
717 699
 
718
-/**
719
- * Checks whether the audio is muted or not.
720
- * @returns {boolean} true if audio is muted and false if not.
721
- */
722
-function isAudioMuted()
723
-{
724
-    var localAudio = connection.jingle.localAudio;
725
-    for (var idx = 0; idx < localAudio.getAudioTracks().length; idx++) {
726
-        if(localAudio.getAudioTracks()[idx].enabled === true)
727
-            return false;
728
-    }
729
-    return true;
730
-}
731 700
 
732 701
 $(document).ready(function () {
733 702
 
@@ -780,11 +749,11 @@ function disposeConference(onUnload) {
780 749
     if (handler && handler.peerconnection) {
781 750
         // FIXME: probably removing streams is not required and close() should
782 751
         // be enough
783
-        if (connection.jingle.localAudio) {
784
-            handler.peerconnection.removeStream(connection.jingle.localAudio, onUnload);
752
+        if (RTC.localAudio) {
753
+            handler.peerconnection.removeStream(RTC.localAudio.getOriginalStream(), onUnload);
785 754
         }
786
-        if (connection.jingle.localVideo) {
787
-            handler.peerconnection.removeStream(connection.jingle.localVideo, onUnload);
755
+        if (RTC.localVideo) {
756
+            handler.peerconnection.removeStream(RTC.localVideo.getOriginalStream(), onUnload);
788 757
         }
789 758
         handler.peerconnection.close();
790 759
     }

+ 2
- 2
desktopsharing.js 查看文件

@@ -254,9 +254,9 @@ function streamSwitchDone() {
254 254
 
255 255
 function newStreamCreated(stream) {
256 256
 
257
-    var oldStream = connection.jingle.localVideo;
257
+    var oldStream = RTC.localVideo.getOriginalStream();
258 258
 
259
-    connection.jingle.localVideo = stream;
259
+    RTC.localVideo.stream = stream;
260 260
 
261 261
     UI.changeLocalVideo(stream, !isUsingScreenStream);
262 262
 

+ 8
- 8
index.html 查看文件

@@ -15,9 +15,9 @@
15 15
     <script src="libs/strophe/strophe.min.js?v=1"></script>
16 16
     <script src="libs/strophe/strophe.disco.min.js?v=1"></script>
17 17
     <script src="libs/strophe/strophe.caps.jsonly.min.js?v=1"></script>
18
-    <script src="libs/strophe/strophe.jingle.js?v=2"></script>
19
-    <script src="libs/strophe/strophe.jingle.sdp.js?v=4"></script>
20
-    <script src="libs/strophe/strophe.jingle.session.js?v=4"></script>
18
+    <script src="libs/strophe/strophe.jingle.js?v=3"></script>
19
+    <script src="libs/strophe/strophe.jingle.sdp.js?v=5"></script>
20
+    <script src="libs/strophe/strophe.jingle.session.js?v=5"></script>
21 21
     <script src="libs/strophe/strophe.util.js"></script>
22 22
     <script src="libs/jquery-ui.js"></script>
23 23
     <script src="libs/rayo.js?v=1"></script>
@@ -29,22 +29,22 @@
29 29
     <script src="service/RTC/RTCBrowserType.js?v=1"></script>
30 30
     <script src="service/RTC/StreamEventTypes.js?v=1"></script>
31 31
     <script src="service/RTC/MediaStreamTypes.js?v=1"></script>
32
-    <script src="libs/modules/simulcast.bundle.js?v=1"></script>
32
+    <script src="libs/modules/simulcast.bundle.js?v=2"></script>
33 33
     <script src="libs/modules/connectionquality.bundle.js?v=1"></script>
34
-    <script src="libs/modules/UI.bundle.js?v=2"></script>
34
+    <script src="libs/modules/UI.bundle.js?v=3"></script>
35 35
     <script src="libs/modules/statistics.bundle.js?v=1"></script>
36
-    <script src="libs/modules/RTC.bundle.js?v=1"></script>
36
+    <script src="libs/modules/RTC.bundle.js?v=2"></script>
37 37
     <script src="muc.js?v=17"></script><!-- simple MUC library -->
38 38
     <script src="estos_log.js?v=2"></script><!-- simple stanza logger -->
39 39
     <script src="desktopsharing.js?v=3"></script><!-- desktop sharing -->
40
-    <script src="app.js?v=24"></script><!-- application logic -->
40
+    <script src="app.js?v=25"></script><!-- application logic -->
41 41
     <script src="libs/modules/API.bundle.js?v=1"></script>
42 42
     <script src="util.js?v=7"></script><!-- utility functions -->
43 43
     <script src="moderatemuc.js?v=4"></script><!-- moderator plugin -->
44 44
     <script src="analytics.js?v=1"></script><!-- google analytics plugin -->
45 45
     <script src="moderator.js?v=2"></script><!-- media stream -->
46 46
     <script src="tracking.js?v=1"></script><!-- tracking -->
47
-    <script src="keyboard_shortcut.js?v=3"></script>
47
+    <script src="keyboard_shortcut.js?v=4"></script>
48 48
     <link rel="stylesheet" href="css/font.css?v=6"/>
49 49
     <link rel="stylesheet" href="css/toastr.css?v=1">
50 50
     <link rel="stylesheet" type="text/css" media="screen" href="css/main.css?v=30"/>

+ 2
- 2
keyboard_shortcut.js 查看文件

@@ -19,7 +19,7 @@ var KeyboardShortcut = (function(my) {
19 19
         84: {
20 20
             character: "T",
21 21
             function: function() {
22
-                if(!isAudioMuted()) {
22
+                if(!RTC.localAudio.isMuted()) {
23 23
                     toggleAudio();
24 24
                 }
25 25
             }
@@ -52,7 +52,7 @@ var KeyboardShortcut = (function(my) {
52 52
     window.onkeydown = function(e) {
53 53
         if(!($(":focus").is("input[type=text]") || $(":focus").is("input[type=password]") || $(":focus").is("textarea"))) {
54 54
             if(e.which === "T".charCodeAt(0)) {
55
-                if(isAudioMuted()) {
55
+                if(RTC.localAudio.isMuted()) {
56 56
                     toggleAudio();
57 57
                 }
58 58
             }

+ 47
- 15
libs/modules/RTC.bundle.js 查看文件

@@ -243,8 +243,20 @@ function LocalStream(stream, type, eventEmitter)
243 243
     this.stream = stream;
244 244
     this.eventEmitter = eventEmitter;
245 245
     this.type = type;
246
-
247 246
     var self = this;
247
+    if(type == "audio")
248
+    {
249
+        this.getTracks = function () {
250
+            return self.stream.getAudioTracks();
251
+        };
252
+    }
253
+    else
254
+    {
255
+        this.getTracks = function () {
256
+            return self.stream.getVideoTracks();
257
+        };
258
+    }
259
+
248 260
     this.stream.onended = function()
249 261
     {
250 262
         self.streamEnded();
@@ -262,31 +274,32 @@ LocalStream.prototype.getOriginalStream = function()
262 274
 
263 275
 LocalStream.prototype.isAudioStream = function () {
264 276
     return (this.stream.getAudioTracks() && this.stream.getAudioTracks().length > 0);
265
-}
277
+};
266 278
 
267 279
 LocalStream.prototype.mute = function()
268 280
 {
269 281
     var ismuted = false;
270
-    var tracks = [];
271
-    if(this.type = "audio")
272
-    {
273
-        tracks = this.stream.getAudioTracks();
274
-    }
275
-    else
276
-    {
277
-        tracks = this.stream.getVideoTracks();
278
-    }
282
+    var tracks = this.getTracks();
279 283
 
280 284
     for (var idx = 0; idx < tracks.length; idx++) {
281 285
         ismuted = !tracks[idx].enabled;
282
-        tracks[idx].enabled = !tracks[idx].enabled;
286
+        tracks[idx].enabled = ismuted;
283 287
     }
284 288
     return ismuted;
285
-}
289
+};
290
+
291
+LocalStream.prototype.setMute = function(mute)
292
+{
293
+    var tracks = this.getTracks();
294
+
295
+    for (var idx = 0; idx < tracks.length; idx++) {
296
+        tracks[idx].enabled = mute;
297
+    }
298
+};
286 299
 
287 300
 LocalStream.prototype.isMuted = function () {
288 301
     var tracks = [];
289
-    if(this.type = "audio")
302
+    if(this.type == "audio")
290 303
     {
291 304
         tracks = this.stream.getAudioTracks();
292 305
     }
@@ -301,6 +314,12 @@ LocalStream.prototype.isMuted = function () {
301 314
     return true;
302 315
 }
303 316
 
317
+LocalStream.prototype.getId = function () {
318
+    return this.stream.getTracks()[0].id;
319
+}
320
+
321
+
322
+
304 323
 module.exports = LocalStream;
305 324
 
306 325
 },{}],3:[function(require,module,exports){
@@ -394,7 +413,10 @@ var RTC = {
394 413
     createLocalStream: function (stream, type) {
395 414
 
396 415
         var localStream =  new LocalStream(stream, type, eventEmitter);
397
-        this.localStreams.push(localStream);
416
+        //in firefox we have only one stream object
417
+        if(this.localStreams.length == 0 ||
418
+            this.localStreams[0].getOriginalStream() != stream)
419
+            this.localStreams.push(localStream);
398 420
         if(type == "audio")
399 421
         {
400 422
             this.localAudio = localStream;
@@ -484,6 +506,16 @@ var RTC = {
484 506
             return true;
485 507
         }
486 508
         return false;
509
+    },
510
+    switchVideoStreams: function (new_stream) {
511
+        this.localVideo.stream = new_stream;
512
+
513
+        this.localStreams = [];
514
+
515
+        //in firefox we have only one stream object
516
+        if(this.localAudio.getOriginalStream() != new_stream)
517
+            this.localStreams.push(this.localAudio);
518
+        this.localStreams.push(this.localVideo);
487 519
     }
488 520
 
489 521
 };

+ 1
- 5
libs/modules/UI.bundle.js 查看文件

@@ -84,7 +84,7 @@ function registerListeners() {
84 84
         if(jid === statistics.LOCAL_JID)
85 85
         {
86 86
             resourceJid = AudioLevels.LOCAL_LEVEL;
87
-            if(isAudioMuted())
87
+            if(RTC.localAudio.isMuted())
88 88
             {
89 89
                 audioLevel = 0;
90 90
             }
@@ -4591,12 +4591,10 @@ var VideoLayout = (function (my) {
4591 4591
     };
4592 4592
 
4593 4593
     my.changeLocalStream = function (stream) {
4594
-        connection.jingle.localAudio = stream;
4595 4594
         VideoLayout.changeLocalVideo(stream, true);
4596 4595
     };
4597 4596
 
4598 4597
     my.changeLocalAudio = function(stream) {
4599
-        connection.jingle.localAudio = stream;
4600 4598
         RTC.attachMediaStream($('#localAudio'), stream);
4601 4599
         document.getElementById('localAudio').autoplay = true;
4602 4600
         document.getElementById('localAudio').volume = 0;
@@ -4607,8 +4605,6 @@ var VideoLayout = (function (my) {
4607 4605
     };
4608 4606
 
4609 4607
     my.changeLocalVideo = function(stream, flipX) {
4610
-        connection.jingle.localVideo = stream;
4611
-
4612 4608
         var localVideo = document.createElement('video');
4613 4609
         localVideo.id = 'localVideo_' + RTC.getStreamID(stream);
4614 4610
         localVideo.autoplay = true;

+ 1
- 1
libs/modules/simulcast.bundle.js 查看文件

@@ -369,7 +369,7 @@ SimulcastSender.prototype.getLocalVideoStream = function () {
369 369
     return (this.displayedLocalVideoStream != null)
370 370
         ? this.displayedLocalVideoStream
371 371
         // in case we have no simulcast at all, i.e. we didn't perform the GUM
372
-        : connection.jingle.localVideo;
372
+        : RTC.localVideo.getOriginalStream();
373 373
 };
374 374
 
375 375
 function NativeSimulcastSender() {

+ 0
- 17
libs/strophe/strophe.jingle.js 查看文件

@@ -31,9 +31,6 @@ Strophe.addConnectionPlugin('jingle', {
31 31
         }
32 32
         // MozDontOfferDataChannel: true when this is firefox
33 33
     },
34
-    localAudio: null,
35
-    localVideo: null,
36
-
37 34
     init: function (conn) {
38 35
         this.connection = conn;
39 36
         if (this.connection.disco) {
@@ -108,13 +105,6 @@ Strophe.addConnectionPlugin('jingle', {
108 105
                 sess = new JingleSession($(iq).attr('to'), $(iq).find('jingle').attr('sid'), this.connection);
109 106
                 // configure session
110 107
 
111
-                //in firefox we have only one stream object
112
-                if (this.localAudio != this.localVideo) {
113
-                    sess.localStreams.push(this.localAudio);
114
-                }
115
-                if (this.localVideo) {
116
-                    sess.localStreams.push(this.localVideo);
117
-                }
118 108
                 sess.media_constraints = this.media_constraints;
119 109
                 sess.pc_constraints = this.pc_constraints;
120 110
                 sess.ice_config = this.ice_config;
@@ -195,13 +185,6 @@ Strophe.addConnectionPlugin('jingle', {
195 185
             this.connection);
196 186
         // configure session
197 187
 
198
-        //in firefox we have only one stream
199
-        if (this.localAudio != this.localVideo) {
200
-            sess.localStreams.push(this.localAudio);
201
-        }
202
-        if (this.localVideo) {
203
-            sess.localStreams.push(this.localVideo);
204
-        }
205 188
         sess.media_constraints = this.media_constraints;
206 189
         sess.pc_constraints = this.pc_constraints;
207 190
         sess.ice_config = this.ice_config;

+ 2
- 2
libs/strophe/strophe.jingle.sdp.js 查看文件

@@ -396,11 +396,11 @@ SDP.prototype.toJingle = function (elem, thecreator, ssrcs) {
396 396
                     var msid = null;
397 397
                     if(mline.media == "audio")
398 398
                     {
399
-                        msid = connection.jingle.localAudio.getAudioTracks()[0].id;
399
+                        msid = RTC.localAudio.getId();
400 400
                     }
401 401
                     else
402 402
                     {
403
-                        msid = connection.jingle.localVideo.getVideoTracks()[0].id;
403
+                        msid = RTC.localVideo.getId();
404 404
                     }
405 405
                     if(msid != null)
406 406
                     {

+ 7
- 19
libs/strophe/strophe.jingle.session.js 查看文件

@@ -11,7 +11,6 @@ function JingleSession(me, sid, connection) {
11 11
     this.state = null;
12 12
     this.localSDP = null;
13 13
     this.remoteSDP = null;
14
-    this.localStreams = [];
15 14
     this.relayedStreams = [];
16 15
     this.remoteStreams = [];
17 16
     this.startTime = null;
@@ -103,8 +102,8 @@ JingleSession.prototype.initiate = function (peerjid, isInitiator) {
103 102
         $(document).trigger('iceconnectionstatechange.jingle', [self.sid, self]);
104 103
     };
105 104
     // add any local and relayed stream
106
-    this.localStreams.forEach(function(stream) {
107
-        self.peerconnection.addStream(stream);
105
+    RTC.localStreams.forEach(function(stream) {
106
+        self.peerconnection.addStream(stream.getOriginalStream());
108 107
     });
109 108
     this.relayedStreams.forEach(function(stream) {
110 109
         self.peerconnection.addStream(stream);
@@ -934,14 +933,7 @@ JingleSession.prototype.switchStreams = function (new_stream, oldStream, success
934 933
         self.peerconnection.addStream(new_stream);
935 934
     }
936 935
 
937
-    self.connection.jingle.localVideo = new_stream;
938
-
939
-    self.connection.jingle.localStreams = [];
940
-
941
-    //in firefox we have only one stream object
942
-    if(self.connection.jingle.localAudio != self.connection.jingle.localVideo)
943
-        self.connection.jingle.localStreams.push(self.connection.jingle.localAudio);
944
-    self.connection.jingle.localStreams.push(self.connection.jingle.localVideo);
936
+    RTC.switchVideoStreams(new_stream, oldStream);
945 937
 
946 938
     // Conference is not active
947 939
     if(!oldSdp || !self.peerconnection) {
@@ -1031,7 +1023,7 @@ JingleSession.prototype.notifyMySSRCUpdate = function (old_sdp, new_sdp) {
1031 1023
  * disabled; otherwise, <tt>false</tt>
1032 1024
  */
1033 1025
 JingleSession.prototype.isVideoMute = function () {
1034
-    var tracks = connection.jingle.localVideo.getVideoTracks();
1026
+    var tracks = RTC.localVideo.getVideoTracks();
1035 1027
     var mute = true;
1036 1028
 
1037 1029
     for (var i = 0; i < tracks.length; ++i) {
@@ -1075,7 +1067,7 @@ JingleSession.prototype.setVideoMute = function (mute, callback, options) {
1075 1067
     } else if (this.videoMuteByUser) {
1076 1068
         return;
1077 1069
     }
1078
-    if (mute == this.isVideoMute())
1070
+    if (mute == RTC.localVideo.isMuted())
1079 1071
     {
1080 1072
         // Even if no change occurs, the specified callback is to be executed.
1081 1073
         // The specified callback may, optionally, return a successCallback
@@ -1086,11 +1078,7 @@ JingleSession.prototype.setVideoMute = function (mute, callback, options) {
1086 1078
             successCallback();
1087 1079
         }
1088 1080
     } else {
1089
-        var tracks = connection.jingle.localVideo.getVideoTracks();
1090
-
1091
-        for (var i = 0; i < tracks.length; ++i) {
1092
-            tracks[i].enabled = !mute;
1093
-        }
1081
+        RTC.localVideo.setMute(!mute);
1094 1082
 
1095 1083
         this.hardMuteVideo(mute);
1096 1084
 
@@ -1101,7 +1089,7 @@ JingleSession.prototype.setVideoMute = function (mute, callback, options) {
1101 1089
 // SDP-based mute by going recvonly/sendrecv
1102 1090
 // FIXME: should probably black out the screen as well
1103 1091
 JingleSession.prototype.toggleVideoMute = function (callback) {
1104
-    setVideoMute(isVideoMute(), callback);
1092
+    setVideoMute(RTC.localVideo.isMuted(), callback);
1105 1093
 };
1106 1094
 
1107 1095
 JingleSession.prototype.hardMuteVideo = function (muted) {

+ 33
- 14
modules/RTC/LocalStream.js 查看文件

@@ -5,8 +5,20 @@ function LocalStream(stream, type, eventEmitter)
5 5
     this.stream = stream;
6 6
     this.eventEmitter = eventEmitter;
7 7
     this.type = type;
8
-
9 8
     var self = this;
9
+    if(type == "audio")
10
+    {
11
+        this.getTracks = function () {
12
+            return self.stream.getAudioTracks();
13
+        };
14
+    }
15
+    else
16
+    {
17
+        this.getTracks = function () {
18
+            return self.stream.getVideoTracks();
19
+        };
20
+    }
21
+
10 22
     this.stream.onended = function()
11 23
     {
12 24
         self.streamEnded();
@@ -24,31 +36,32 @@ LocalStream.prototype.getOriginalStream = function()
24 36
 
25 37
 LocalStream.prototype.isAudioStream = function () {
26 38
     return (this.stream.getAudioTracks() && this.stream.getAudioTracks().length > 0);
27
-}
39
+};
28 40
 
29 41
 LocalStream.prototype.mute = function()
30 42
 {
31 43
     var ismuted = false;
32
-    var tracks = [];
33
-    if(this.type = "audio")
34
-    {
35
-        tracks = this.stream.getAudioTracks();
36
-    }
37
-    else
38
-    {
39
-        tracks = this.stream.getVideoTracks();
40
-    }
44
+    var tracks = this.getTracks();
41 45
 
42 46
     for (var idx = 0; idx < tracks.length; idx++) {
43 47
         ismuted = !tracks[idx].enabled;
44
-        tracks[idx].enabled = !tracks[idx].enabled;
48
+        tracks[idx].enabled = ismuted;
45 49
     }
46 50
     return ismuted;
47
-}
51
+};
52
+
53
+LocalStream.prototype.setMute = function(mute)
54
+{
55
+    var tracks = this.getTracks();
56
+
57
+    for (var idx = 0; idx < tracks.length; idx++) {
58
+        tracks[idx].enabled = mute;
59
+    }
60
+};
48 61
 
49 62
 LocalStream.prototype.isMuted = function () {
50 63
     var tracks = [];
51
-    if(this.type = "audio")
64
+    if(this.type == "audio")
52 65
     {
53 66
         tracks = this.stream.getAudioTracks();
54 67
     }
@@ -63,4 +76,10 @@ LocalStream.prototype.isMuted = function () {
63 76
     return true;
64 77
 }
65 78
 
79
+LocalStream.prototype.getId = function () {
80
+    return this.stream.getTracks()[0].id;
81
+}
82
+
83
+
84
+
66 85
 module.exports = LocalStream;

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

@@ -27,7 +27,10 @@ var RTC = {
27 27
     createLocalStream: function (stream, type) {
28 28
 
29 29
         var localStream =  new LocalStream(stream, type, eventEmitter);
30
-        this.localStreams.push(localStream);
30
+        //in firefox we have only one stream object
31
+        if(this.localStreams.length == 0 ||
32
+            this.localStreams[0].getOriginalStream() != stream)
33
+            this.localStreams.push(localStream);
31 34
         if(type == "audio")
32 35
         {
33 36
             this.localAudio = localStream;
@@ -117,6 +120,16 @@ var RTC = {
117 120
             return true;
118 121
         }
119 122
         return false;
123
+    },
124
+    switchVideoStreams: function (new_stream) {
125
+        this.localVideo.stream = new_stream;
126
+
127
+        this.localStreams = [];
128
+
129
+        //in firefox we have only one stream object
130
+        if(this.localAudio.getOriginalStream() != new_stream)
131
+            this.localStreams.push(this.localAudio);
132
+        this.localStreams.push(this.localVideo);
120 133
     }
121 134
 
122 135
 };

+ 1
- 1
modules/UI/UI.js 查看文件

@@ -83,7 +83,7 @@ function registerListeners() {
83 83
         if(jid === statistics.LOCAL_JID)
84 84
         {
85 85
             resourceJid = AudioLevels.LOCAL_LEVEL;
86
-            if(isAudioMuted())
86
+            if(RTC.localAudio.isMuted())
87 87
             {
88 88
                 audioLevel = 0;
89 89
             }

+ 0
- 4
modules/UI/videolayout/VideoLayout.js 查看文件

@@ -414,12 +414,10 @@ var VideoLayout = (function (my) {
414 414
     };
415 415
 
416 416
     my.changeLocalStream = function (stream) {
417
-        connection.jingle.localAudio = stream;
418 417
         VideoLayout.changeLocalVideo(stream, true);
419 418
     };
420 419
 
421 420
     my.changeLocalAudio = function(stream) {
422
-        connection.jingle.localAudio = stream;
423 421
         RTC.attachMediaStream($('#localAudio'), stream);
424 422
         document.getElementById('localAudio').autoplay = true;
425 423
         document.getElementById('localAudio').volume = 0;
@@ -430,8 +428,6 @@ var VideoLayout = (function (my) {
430 428
     };
431 429
 
432 430
     my.changeLocalVideo = function(stream, flipX) {
433
-        connection.jingle.localVideo = stream;
434
-
435 431
         var localVideo = document.createElement('video');
436 432
         localVideo.id = 'localVideo_' + RTC.getStreamID(stream);
437 433
         localVideo.autoplay = true;

+ 1
- 1
modules/simulcast/SimulcastSender.js 查看文件

@@ -32,7 +32,7 @@ SimulcastSender.prototype.getLocalVideoStream = function () {
32 32
     return (this.displayedLocalVideoStream != null)
33 33
         ? this.displayedLocalVideoStream
34 34
         // in case we have no simulcast at all, i.e. we didn't perform the GUM
35
-        : connection.jingle.localVideo;
35
+        : RTC.localVideo.getOriginalStream();
36 36
 };
37 37
 
38 38
 function NativeSimulcastSender() {

Loading…
取消
儲存