浏览代码

Allows to switch to desktop stream from the very beginning of the conference.

master
paweldomas 11 年前
父节点
当前提交
1f51021041
共有 3 个文件被更改,包括 39 次插入15 次删除
  1. 5
    1
      app.js
  2. 24
    13
      desktopsharing.js
  3. 10
    1
      libs/strophe/strophe.jingle.sessionbase.js

+ 5
- 1
app.js 查看文件

@@ -221,7 +221,9 @@ $(document).bind('remotestreamadded.jingle', function (event, data, sid) {
221 221
         }
222 222
     } else {
223 223
         if (data.stream.id !== 'mixedmslabel') {
224
-            console.warn('can not associate stream', data.stream.id, 'with a participant');
224
+            console.error('can not associate stream', data.stream.id, 'with a participant');
225
+            // We don't want to add it here since it will cause troubles
226
+            return;
225 227
         }
226 228
         // FIXME: for the mixed ms we dont need a video -- currently
227 229
         container = document.createElement('span');
@@ -448,6 +450,8 @@ $(document).bind('callactive.jingle', function (event, videoelem, sid) {
448 450
 
449 451
 $(document).bind('callterminated.jingle', function (event, sid, reason) {
450 452
     // FIXME
453
+    focus = null;
454
+    activecall = null;
451 455
 });
452 456
 
453 457
 $(document).bind('setLocalDescription.jingle', function (event, sid) {

+ 24
- 13
desktopsharing.js 查看文件

@@ -42,14 +42,17 @@ function setDesktopSharing(method) {
42 42
     if(method == "ext") {
43 43
         if(RTC.browser === 'chrome') {
44 44
             obtainDesktopStream = obtainScreenFromExtension;
45
+            console.info("Using Chrome extension for desktop sharing");
45 46
         } else {
46
-            console.log("Chrome is required to use extension method");
47
+            console.error("Chrome is required to use extension method");
47 48
             obtainDesktopStream = null;
48 49
         }
49 50
     } else if(method == "webrtc") {
50 51
         obtainDesktopStream = obtainWebRTCScreen;
52
+        console.info("Using WebRTC for desktop sharing");
51 53
     } else {
52 54
         obtainDesktopStream = null;
55
+        console.info("Desktop sharing disabled");
53 56
     }
54 57
     showDesktopSharingButton();
55 58
 }
@@ -66,11 +69,8 @@ function showDesktopSharingButton() {
66 69
  * Toggles screen sharing.
67 70
  */
68 71
 function toggleScreenSharing() {
69
-    if (!(connection && connection.connected
70
-        && !switchInProgress
71
-        && getConferenceHandler().peerconnection.signalingState == 'stable'
72
-        && getConferenceHandler().peerconnection.iceConnectionState == 'connected'
73
-        && obtainDesktopStream )) {
72
+    if (switchInProgress || !obtainDesktopStream) {
73
+        console.warn("Switch in progress or no method defined");
74 74
         return;
75 75
     }
76 76
     switchInProgress = true;
@@ -85,7 +85,7 @@ function toggleScreenSharing() {
85 85
                 // Hook 'ended' event to restore camera when screen stream stops
86 86
                 stream.addEventListener('ended',
87 87
                     function(e) {
88
-                        if(!switchInProgress) {
88
+                        if(!switchInProgress && isUsingScreenStream) {
89 89
                             toggleScreenSharing();
90 90
                         }
91 91
                     }
@@ -118,13 +118,24 @@ function newStreamCreated(stream) {
118 118
 
119 119
     change_local_video(stream, !isUsingScreenStream);
120 120
 
121
-    // FIXME: will block switchInProgress on true value in case of exception
122
-    getConferenceHandler().switchStreams(
123
-        stream, oldStream,
124
-        function() {
125
-            // Switch operation has finished
121
+    var conferenceHandler = getConferenceHandler();
122
+    if(conferenceHandler) {
123
+        console.info("Conference considered as started");
124
+        // FIXME: will block switchInProgress on true value in case of exception
125
+        conferenceHandler.switchStreams(stream, oldStream, streamSwitchDone);
126
+    } else {
127
+        // We are done immediately
128
+        console.error("No conference handler");
129
+        streamSwitchDone();
130
+    }
131
+}
132
+
133
+function streamSwitchDone() {
134
+    //window.setTimeout(
135
+    //    function() {
126 136
             switchInProgress = false;
127
-        });
137
+    //    }, 100
138
+    //);
128 139
 }
129 140
 
130 141
 /**

+ 10
- 1
libs/strophe/strophe.jingle.sessionbase.js 查看文件

@@ -49,7 +49,10 @@ SessionBase.prototype.switchStreams = function (new_stream, oldStream, success_c
49 49
     var self = this;
50 50
 
51 51
     // Remember SDP to figure out added/removed SSRCs
52
-    var oldSdp = new SDP(self.peerconnection.localDescription.sdp);
52
+    var oldSdp = null;
53
+    if(self.peerconnection.localDescription) {
54
+        oldSdp = new SDP(self.peerconnection.localDescription.sdp);
55
+    }
53 56
 
54 57
     // Stop the stream to trigger onended event for old stream
55 58
     oldStream.stop();
@@ -63,6 +66,12 @@ SessionBase.prototype.switchStreams = function (new_stream, oldStream, success_c
63 66
     self.connection.jingle.localStreams.push(self.connection.jingle.localAudio);
64 67
     self.connection.jingle.localStreams.push(self.connection.jingle.localVideo);
65 68
 
69
+    // Conference is not active
70
+    if(!oldSdp) {
71
+        success_callback();
72
+        return;
73
+    }
74
+
66 75
     self.peerconnection.switchstreams = true;
67 76
     self.modifySources(function() {
68 77
         console.log('modify sources done');

正在加载...
取消
保存