浏览代码

implement muting in a safe way, fixes #41

master
Philipp Hancke 11 年前
父节点
当前提交
b78fda3a55
共有 1 个文件被更改,包括 31 次插入1 次删除
  1. 31
    1
      libs/colibri.js

+ 31
- 1
libs/colibri.js 查看文件

55
     this.addssrc = [];
55
     this.addssrc = [];
56
     // ssrc lines to be removed on next update
56
     // ssrc lines to be removed on next update
57
     this.removessrc = [];
57
     this.removessrc = [];
58
+    // pending mute/unmute video op that modify local description
59
+    this.pendingop = null;
58
 
60
 
59
     // container for candidates from the focus
61
     // container for candidates from the focus
60
     // gathered before confid is known
62
     // gathered before confid is known
802
 
804
 
803
 ColibriFocus.prototype.modifySources = function () {
805
 ColibriFocus.prototype.modifySources = function () {
804
     var self = this;
806
     var self = this;
805
-    if (!(this.addssrc.length || this.removessrc.length)) return;
806
     if (this.peerconnection.signalingState == 'closed') return;
807
     if (this.peerconnection.signalingState == 'closed') return;
808
+    if (!(this.addssrc.length || this.removessrc.length || this.pendingop !== null)) return;
807
 
809
 
808
     // FIXME: this is a big hack
810
     // FIXME: this is a big hack
809
     // https://code.google.com/p/webrtc/issues/detail?id=2688
811
     // https://code.google.com/p/webrtc/issues/detail?id=2688
844
             self.peerconnection.createAnswer(
846
             self.peerconnection.createAnswer(
845
                 function (modifiedAnswer) {
847
                 function (modifiedAnswer) {
846
                     console.log('modifiedAnswer created');
848
                     console.log('modifiedAnswer created');
849
+
850
+                    // change video direction, see https://github.com/jitsi/jitmeet/issues/41
851
+                    if (self.pendingop !== null) {
852
+                        var sdp = new SDP(modifiedAnswer.sdp);
853
+                        if (sdp.media.length > 1) {
854
+                            switch(self.pendingop) {
855
+                            case 'mute':
856
+                                sdp.media[1] = sdp.media[1].replace('a=sendrecv', 'a=recvonly');
857
+                                break;
858
+                            case 'unmute':
859
+                                sdp.media[1] = sdp.media[1].replace('a=recvonly', 'a=sendrecv');
860
+                                break;
861
+                            }
862
+                            sdp.raw = sdp.session + sdp.media.join('');
863
+                            modifiedAnswer.sdp = sdp.raw;
864
+                        }
865
+                        self.pendingop = null;
866
+                    }
867
+
847
                     // FIXME: pushing down an answer while ice connection state 
868
                     // FIXME: pushing down an answer while ice connection state 
848
                     // is still checking is bad...
869
                     // is still checking is bad...
849
                     //console.log(self.peerconnection.iceConnectionState);
870
                     //console.log(self.peerconnection.iceConnectionState);
900
     */
921
     */
901
 };
922
 };
902
 
923
 
924
+ColibriFocus.prototype.hardMuteVideo = function (muted) {
925
+    this.pendingop = muted ? 'mute' : 'unmute';
926
+    this.modifySources();
927
+
928
+    this.localStream.getVideoTracks.forEach(function (track) {
929
+        track.enabled = !muted;
930
+    });
931
+};
932
+
903
 // A colibri session is similar to a jingle session, it just implements some things differently
933
 // A colibri session is similar to a jingle session, it just implements some things differently
904
 // FIXME: inherit jinglesession, see https://github.com/legastero/Jingle-RTCPeerConnection/blob/master/index.js
934
 // FIXME: inherit jinglesession, see https://github.com/legastero/Jingle-RTCPeerConnection/blob/master/index.js
905
 function ColibriSession(me, sid, connection) {
935
 function ColibriSession(me, sid, connection) {

正在加载...
取消
保存