浏览代码

create remote video containers on muc join/leave

j8
Philipp Hancke 11 年前
父节点
当前提交
bb3897a89d
共有 1 个文件被更改,包括 39 次插入17 次删除
  1. 39
    17
      app.js

+ 39
- 17
app.js 查看文件

136
         }
136
         }
137
     }
137
     }
138
 
138
 
139
-    var vid = document.createElement('video');
140
-    // FIXME: the span should not be created here but on muc join
141
-    var span = document.createElement('span');
139
+    var container;
140
+    var remotes = document.getElementById('remoteVideos');
142
     if (data.peerjid) {
141
     if (data.peerjid) {
143
-        // FIXME: how to name this span? data.peerjid is not set for jingle clients
144
-        span.id = 'participant_' + Strophe.getResourceFromJid(data.peerjid);
145
-    } else if (data.stream.id != 'mixedmslabel') {
146
-        console.warn('can not associate stream', data.stream.id, 'with a participant');
142
+        container  = document.getElementById('participant_' + Strophe.getResourceFromJid(data.peerjid));
143
+        if (!container) {
144
+            console.warn('no container for', data.peerjid);
145
+            // create for now...
146
+            // FIXME: should be removed
147
+            container = document.createElement('span');
148
+            container.id = 'participant_' + Strophe.getResourceFromJid(data.peerjid);
149
+            container.className = 'videocontainer';
150
+            remotes.appendChild(container);
151
+        } else {
152
+            //console.log('found container for', data.peerjid);
153
+        }
154
+    } else {
155
+        if (data.stream.id != 'mixedmslabel') {
156
+            console.warn('can not associate stream', data.stream.id, 'with a participant');
157
+        }
158
+        // FIXME: for the mixed ms we dont need a video -- currently
159
+        container = document.createElement('span');
160
+        container.className = 'videocontainer';
161
+        remotes.appendChild(container);
147
     }
162
     }
148
-    span.className = 'videocontainer';
163
+    var vid = document.createElement('video');
149
     var id = 'remoteVideo_' + sid + '_' + data.stream.id;
164
     var id = 'remoteVideo_' + sid + '_' + data.stream.id;
150
     vid.id = id;
165
     vid.id = id;
151
     vid.autoplay = true;
166
     vid.autoplay = true;
152
     vid.oncontextmenu = function () { return false; };
167
     vid.oncontextmenu = function () { return false; };
153
-    var remotes = document.getElementById('remoteVideos');
154
-    span.appendChild(vid);
168
+    container.appendChild(vid);
169
+    // TODO: make mixedstream display:none via css?
155
     if (id.indexOf('mixedmslabel') != -1) {
170
     if (id.indexOf('mixedmslabel') != -1) {
156
-        $(span).hide();
171
+        container.id = 'mixedstream';
172
+        $(container).hide();
157
     }
173
     }
158
-    remotes.appendChild(span);
159
     var sel = $('#' + id);
174
     var sel = $('#' + id);
160
     sel.hide();
175
     sel.hide();
161
     RTC.attachMediaStream(sel, data.stream);
176
     RTC.attachMediaStream(sel, data.stream);
163
     data.stream.onended = function () {
178
     data.stream.onended = function () {
164
         console.log('stream ended', this.id);
179
         console.log('stream ended', this.id);
165
         var src = $('#' + id).attr('src');
180
         var src = $('#' + id).attr('src');
166
-        // FIXME: likewise, the parent should not be removed here
167
-        // but on MUC part
168
-        $('#' + id).parent().remove();
169
         if (src === $('#largeVideo').attr('src')) {
181
         if (src === $('#largeVideo').attr('src')) {
170
             // this is currently displayed as large
182
             // this is currently displayed as large
171
             // pick the last visible video in the row
183
             // pick the last visible video in the row
172
             // if nobody else is left, this picks the local video
184
             // if nobody else is left, this picks the local video
173
-            var pick = $('#remoteVideos>span:visible:last>video').get(0);
185
+            var pick = $('#remoteVideos>span[id!="mixedstream"]:visible:last>video').get(0);
174
             // mute if localvideo
186
             // mute if localvideo
175
             document.getElementById('largeVideo').volume = pick.volume;
187
             document.getElementById('largeVideo').volume = pick.volume;
176
             document.getElementById('largeVideo').src = pick.src;
188
             document.getElementById('largeVideo').src = pick.src;
177
         }
189
         }
190
+        $('#' + id).parent().remove();
178
         resizeThumbnails();
191
         resizeThumbnails();
179
     };
192
     };
180
     sel.click(
193
     sel.click(
245
 $(document).bind('entered.muc', function (event, jid, info, pres) {
258
 $(document).bind('entered.muc', function (event, jid, info, pres) {
246
     console.log('entered', jid, info);
259
     console.log('entered', jid, info);
247
     console.log(focus);
260
     console.log(focus);
261
+    var container = document.createElement('span');
262
+    container.id = 'participant_' + Strophe.getResourceFromJid(jid);
263
+    container.className = 'videocontainer';
264
+    var remotes = document.getElementById('remoteVideos');
265
+    remotes.appendChild(container);
248
 
266
 
249
     if (focus !== null) {
267
     if (focus !== null) {
250
         // FIXME: this should prepare the video
268
         // FIXME: this should prepare the video
269
 $(document).bind('left.muc', function (event, jid) {
287
 $(document).bind('left.muc', function (event, jid) {
270
     console.log('left', jid);
288
     console.log('left', jid);
271
     connection.jingle.terminateByJid(jid);
289
     connection.jingle.terminateByJid(jid);
272
-    // FIXME: this should actually hide the video already for a nicer UX
290
+    var container = document.getElementById('participant_' + Strophe.getResourceFromJid(jid));
291
+    if (container) {
292
+        // hide here, wait for video to close before removing
293
+        $(container).hide(); 
294
+    }
273
 
295
 
274
     if (Object.keys(connection.emuc.members).length === 0) {
296
     if (Object.keys(connection.emuc.members).length === 0) {
275
         console.log('everyone left');
297
         console.log('everyone left');

正在加载...
取消
保存