Browse Source

fail if user is trying to add second video track to the conference

master
isymchych 9 years ago
parent
commit
00733623f1
4 changed files with 43 additions and 15 deletions
  1. 5
    0
      JitsiConference.js
  2. 3
    3
      doc/API.md
  3. 14
    7
      modules/RTC/JitsiLocalTrack.js
  4. 21
    5
      modules/RTC/RTC.js

+ 5
- 0
JitsiConference.js View File

@@ -275,9 +275,14 @@ JitsiConference.prototype.setSubject = function (subject) {
275 275
  * Adds JitsiLocalTrack object to the conference.
276 276
  * @param track the JitsiLocalTrack object.
277 277
  * @returns {Promise<JitsiLocalTrack>}
278
+ * @throws will throw and error if track is video track
279
+ * and there is already another video track in the conference.
278 280
  */
279 281
 JitsiConference.prototype.addTrack = function (track) {
280 282
     if (track.isVideoTrack()) {
283
+        if (this.rtc.getLocalVideoStream()) {
284
+            throw new Error("cannot add second video track to the conference");
285
+        }
281 286
         this.removeCommand("videoType");
282 287
         this.sendCommand("videoType", {
283 288
             value: track.videoType,

+ 3
- 3
doc/API.md View File

@@ -247,10 +247,10 @@ The object represents a conference. We have the following methods to control the
247 247
 16. removeCommandListener(command) - removes the listeners for the specified command
248 248
     - command - the name of the command
249 249
 
250
-17. addTrack(track) - Adds JitsiLocalTrack object to the conference.
250
+17. addTrack(track) - Adds JitsiLocalTrack object to the conference. Throws an error if adding second video stream. Returns Promise.
251 251
     - track - the JitsiLocalTrack
252 252
 
253
-18. removeTrack(track) - Removes JitsiLocalTrack object to the conference.
253
+18. removeTrack(track) - Removes JitsiLocalTrack object to the conference. Returns Promise.
254 254
     - track - the JitsiLocalTrack
255 255
 
256 256
 19. isDTMFSupported() - Check if at least one user supports DTMF.
@@ -319,7 +319,7 @@ We have the following methods for controling the tracks:
319 319
 
320 320
 6. detach(container) - removes the track from the container.
321 321
 
322
-7. stop() - stop sending the track to the other participants in the conference.
322
+7. stop() - stop sending the track to the other participants in the conference. Returns Promise.
323 323
 
324 324
    Note: This method is implemented only for the local tracks.
325 325
 

+ 14
- 7
modules/RTC/JitsiLocalTrack.js View File

@@ -1,3 +1,4 @@
1
+/* global Promise */
1 2
 var JitsiTrack = require("./JitsiTrack");
2 3
 var RTCBrowserType = require("./RTCBrowserType");
3 4
 var JitsiTrackEvents = require('../../JitsiTrackEvents');
@@ -126,16 +127,22 @@ JitsiLocalTrack.prototype._setMute = function (mute) {
126 127
 /**
127 128
  * Stops sending the media track. And removes it from the HTML.
128 129
  * NOTE: Works for local tracks only.
130
+ * @returns {Promise}
129 131
  */
130 132
 JitsiLocalTrack.prototype.stop = function () {
131
-    if(this.conference){
132
-        this.conference.removeTrack(this);
133
+    var promise = Promise.resolve();
134
+
135
+    if (this.conference){
136
+        promise = this.conference.removeTrack(this);
133 137
     }
134
-    if(!this.stream)
135
-        return;
136
-    RTCUtils.stopMediaStream(this.stream);
137
-    this.detach();
138
-}
138
+
139
+    if (this.stream) {
140
+        RTCUtils.stopMediaStream(this.stream);
141
+        this.detach();
142
+    }
143
+
144
+    return promise;
145
+};
139 146
 
140 147
 /**
141 148
  * Returns <tt>true</tt> - if the stream is muted

+ 21
- 5
modules/RTC/RTC.js View File

@@ -142,13 +142,21 @@ RTC.prototype.addLocalStream = function (stream) {
142 142
     this.localStreams.push(stream);
143 143
     stream._setRTC(this);
144 144
 
145
-    if (stream.type == "audio") {
145
+    if (stream.isAudioTrack()) {
146 146
         this.localAudio = stream;
147 147
     } else {
148 148
         this.localVideo = stream;
149 149
     }
150 150
 };
151 151
 
152
+/**
153
+ * Get local video track.
154
+ * @returns {JitsiLocalTrack}
155
+ */
156
+RTC.prototype.getLocalVideoStream = function () {
157
+    return this.localVideo;
158
+};
159
+
152 160
 /**
153 161
  * Set mute for all local audio streams attached to the conference.
154 162
  * @param value the mute value
@@ -163,10 +171,18 @@ RTC.prototype.setAudioMute = function (value) {
163 171
     }
164 172
 }
165 173
 
166
-RTC.prototype.removeLocalStream = function (track) {
167
-    var pos = this.localStreams.indexOf(track);
168
-    if (pos > -1) {
169
-        this.localStreams.splice(pos, 1);
174
+RTC.prototype.removeLocalStream = function (stream) {
175
+    var pos = this.localStreams.indexOf(stream);
176
+    if (pos === -1) {
177
+        return;
178
+    }
179
+
180
+    this.localStreams.splice(pos, 1);
181
+
182
+    if (stream.isAudioTrack()) {
183
+        this.localAudio = null;
184
+    } else {
185
+        this.localVideo = null;
170 186
     }
171 187
 };
172 188
 

Loading…
Cancel
Save