瀏覽代碼

Modifies the semantics of JitsiTrack#attach method, so that it will return current stream container instance. Also it now takes HTML element instance directly instead of jQuery selector.

master
paweldomas 9 年之前
父節點
當前提交
e4785039e4
共有 4 個檔案被更改,包括 44 行新增25 行删除
  1. 3
    2
      modules/RTC/JitsiLocalTrack.js
  2. 21
    9
      modules/RTC/JitsiTrack.js
  3. 1
    1
      modules/RTC/RTC.js
  4. 19
    13
      modules/RTC/RTCUtils.js

+ 3
- 2
modules/RTC/JitsiLocalTrack.js 查看文件

@@ -98,8 +98,9 @@ JitsiLocalTrack.prototype._setMute = function (mute) {
98 98
 
99 99
                     for(var i = 0; i < self.containers.length; i++)
100 100
                     {
101
-                        RTCUtils.attachMediaStream(
102
-                            self.containers[i], self.stream);
101
+                        self.containers[i]
102
+                            = RTCUtils.attachMediaStream(
103
+                                    self.containers[i], self.stream);
103 104
                     }
104 105
 
105 106
                     self.rtc.room.addStream(stream.stream,

+ 21
- 9
modules/RTC/JitsiTrack.js 查看文件

@@ -149,35 +149,47 @@ JitsiTrack.prototype.unmute = function () {
149 149
 }
150 150
 
151 151
 /**
152
- * Attaches the MediaStream of this track to an HTML container (?).
152
+ * Attaches the MediaStream of this track to an HTML container.
153 153
  * Adds the container to the list of containers that are displaying the track.
154
- * @param container the HTML container
154
+ * Note that Temasys plugin will replace original audio/video element with
155
+ * 'object' when stream is being attached to the container for the first time.
156
+ *
157
+ * @param container the HTML container which can be 'video' or 'audio' element.
158
+ *        It can also be 'object' element if Temasys plugin is in use and this
159
+ *        method has been called previously on video or audio HTML element.
160
+ *
161
+ * @returns potentially new instance of container if it was replaced by the
162
+ *          library. That's the case when Temasys plugin is in use.
155 163
  */
156 164
 JitsiTrack.prototype.attach = function (container) {
157 165
     if(this.stream)
158
-        require("./RTCUtils").attachMediaStream(container, this.stream);
166
+        container = require("./RTCUtils").attachMediaStream(container, this.stream);
159 167
     this.containers.push(container);
168
+    return container;
160 169
 }
161 170
 
162 171
 /**
163 172
  * Removes the track from the passed HTML container.
164 173
  * @param container the HTML container. If <tt>null</tt> all containers are removed.
174
+ *        A container can be 'video', 'audio' or 'object' HTML element instance
175
+ *        to which this JitsiTrack is currently attached to.
165 176
  */
166 177
 JitsiTrack.prototype.detach = function (container) {
167 178
     for(var i = 0; i < this.containers.length; i++)
168 179
     {
169
-        if(this.containers[i].is(container))
180
+        if(!container)
170 181
         {
171
-            this.containers.splice(i,1);
182
+            require("./RTCUtils").setVideoSrc(this.containers[i], null);
172 183
         }
173
-        if(!container)
184
+        if(!container || $(this.containers[i]).is($(container)))
174 185
         {
175
-            this.containers[i].find(">video").remove();
186
+            this.containers.splice(i,1);
176 187
         }
177 188
     }
178
-    if(container)
179
-        $(container).find(">video").remove();
180 189
 
190
+    if(container) {
191
+        require("./RTCUtils").setVideoSrc(container, null);
192
+    }
181 193
 }
182 194
 
183 195
 /**

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

@@ -188,7 +188,7 @@ RTC.getPCConstraints = function () {
188 188
 };
189 189
 
190 190
 RTC.attachMediaStream =  function (elSelector, stream) {
191
-    RTCUtils.attachMediaStream(elSelector, stream);
191
+    return RTCUtils.attachMediaStream(elSelector, stream);
192 192
 };
193 193
 
194 194
 RTC.getStreamID = function (stream) {

+ 19
- 13
modules/RTC/RTCUtils.js 查看文件

@@ -440,10 +440,12 @@ var RTCUtils = {
440 440
                     //
441 441
                     // https://groups.google.com/forum/#!topic/mozilla.dev.media/pKOiioXonJg
442 442
                     // https://github.com/webrtc/samples/issues/302
443
-                    if (!element[0])
443
+                    if (!element)
444 444
                         return;
445
-                    element[0].mozSrcObject = stream;
446
-                    element[0].play();
445
+                    element.mozSrcObject = stream;
446
+                    element.play();
447
+
448
+                    return element;
447 449
                 };
448 450
                 this.getStreamID = function (stream) {
449 451
                     var id = stream.id;
@@ -488,7 +490,9 @@ var RTCUtils = {
488 490
                             = webkitURL.createObjectURL(stream);
489 491
                     }
490 492
 
491
-                    element.attr('src', stream.jitsiObjectURL);
493
+                    element.src = stream.jitsiObjectURL;
494
+
495
+                    return element;
492 496
                 };
493 497
                 this.getStreamID = function (stream) {
494 498
                     // streams from FF endpoints have the characters '{' and '}'
@@ -537,18 +541,18 @@ var RTCUtils = {
537 541
                     self.peerconnection = RTCPeerConnection;
538 542
                     self.getUserMedia = window.getUserMedia;
539 543
                     self.enumerateDevices = enumerateDevicesThroughMediaStreamTrack;
540
-                    self.attachMediaStream = function (elSel, stream) {
544
+                    self.attachMediaStream = function (element, stream) {
541 545
 
542 546
                         if (stream.id === "dummyAudio" || stream.id === "dummyVideo") {
543 547
                             return;
544 548
                         }
545 549
 
546 550
                         var isVideoStream = !!stream.getVideoTracks().length;
547
-                        if (isVideoStream && !elSel.is(':visible')) {
551
+                        if (isVideoStream && !$(element).is(':visible')) {
548 552
                             throw new Error('video element must be visible to attach video stream');
549 553
                         }
550 554
 
551
-                        attachMediaStream(elSel[0], stream);
555
+                        return attachMediaStream(element, stream);
552 556
                     };
553 557
                     self.getStreamID = function (stream) {
554 558
                         var id = SDPUtil.filter_special_chars(stream.label);
@@ -571,13 +575,15 @@ var RTCUtils = {
571 575
                     self.setVideoSrc = function (element, src) {
572 576
                         //logger.info("Set video src: ", element, src);
573 577
                         if (!src) {
574
-                            logger.warn("Not attaching video stream, 'src' is null");
575
-                            return;
578
+                            attachMediaStream(element, null);
579
+                        } else {
580
+                            AdapterJS.WebRTCPlugin.WaitForPluginReady();
581
+                            var stream
582
+                                = AdapterJS.WebRTCPlugin.plugin
583
+                                    .getStreamWithId(
584
+                                        AdapterJS.WebRTCPlugin.pageId, src);
585
+                            attachMediaStream(element, stream);
576 586
                         }
577
-                        AdapterJS.WebRTCPlugin.WaitForPluginReady();
578
-                        var stream = AdapterJS.WebRTCPlugin.plugin
579
-                            .getStreamWithId(AdapterJS.WebRTCPlugin.pageId, src);
580
-                        attachMediaStream(element, stream);
581 587
                     };
582 588
 
583 589
                     onReady(options, self.getUserMediaWithConstraints);

Loading…
取消
儲存