Browse Source

Merge pull request #14 from isymchych/only-one-video-stream

Fail if user is trying to add second video track to the conference
master
Paweł Domas 9 years ago
parent
commit
683ab24f50
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
  * Adds JitsiLocalTrack object to the conference.
275
  * Adds JitsiLocalTrack object to the conference.
276
  * @param track the JitsiLocalTrack object.
276
  * @param track the JitsiLocalTrack object.
277
  * @returns {Promise<JitsiLocalTrack>}
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
 JitsiConference.prototype.addTrack = function (track) {
281
 JitsiConference.prototype.addTrack = function (track) {
280
     if (track.isVideoTrack()) {
282
     if (track.isVideoTrack()) {
283
+        if (this.rtc.getLocalVideoStream()) {
284
+            throw new Error("cannot add second video track to the conference");
285
+        }
281
         this.removeCommand("videoType");
286
         this.removeCommand("videoType");
282
         this.sendCommand("videoType", {
287
         this.sendCommand("videoType", {
283
             value: track.videoType,
288
             value: track.videoType,

+ 3
- 3
doc/API.md View File

247
 16. removeCommandListener(command) - removes the listeners for the specified command
247
 16. removeCommandListener(command) - removes the listeners for the specified command
248
     - command - the name of the command
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
     - track - the JitsiLocalTrack
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
     - track - the JitsiLocalTrack
254
     - track - the JitsiLocalTrack
255
 
255
 
256
 19. isDTMFSupported() - Check if at least one user supports DTMF.
256
 19. isDTMFSupported() - Check if at least one user supports DTMF.
319
 
319
 
320
 6. detach(container) - removes the track from the container.
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
    Note: This method is implemented only for the local tracks.
324
    Note: This method is implemented only for the local tracks.
325
 
325
 

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

1
+/* global Promise */
1
 var JitsiTrack = require("./JitsiTrack");
2
 var JitsiTrack = require("./JitsiTrack");
2
 var RTCBrowserType = require("./RTCBrowserType");
3
 var RTCBrowserType = require("./RTCBrowserType");
3
 var JitsiTrackEvents = require('../../JitsiTrackEvents');
4
 var JitsiTrackEvents = require('../../JitsiTrackEvents');
126
 /**
127
 /**
127
  * Stops sending the media track. And removes it from the HTML.
128
  * Stops sending the media track. And removes it from the HTML.
128
  * NOTE: Works for local tracks only.
129
  * NOTE: Works for local tracks only.
130
+ * @returns {Promise}
129
  */
131
  */
130
 JitsiLocalTrack.prototype.stop = function () {
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
  * Returns <tt>true</tt> - if the stream is muted
148
  * Returns <tt>true</tt> - if the stream is muted

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

142
     this.localStreams.push(stream);
142
     this.localStreams.push(stream);
143
     stream._setRTC(this);
143
     stream._setRTC(this);
144
 
144
 
145
-    if (stream.type == "audio") {
145
+    if (stream.isAudioTrack()) {
146
         this.localAudio = stream;
146
         this.localAudio = stream;
147
     } else {
147
     } else {
148
         this.localVideo = stream;
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
  * Set mute for all local audio streams attached to the conference.
161
  * Set mute for all local audio streams attached to the conference.
154
  * @param value the mute value
162
  * @param value the mute 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