winlin

layout the chat in 2x8 table

@@ -286,19 +286,19 @@ function srs_chat_initialize_page( @@ -286,19 +286,19 @@ function srs_chat_initialize_page(
286 286
287 //var gops = ["0.3", "0.5", "1", "2", "3", "4", 287 //var gops = ["0.3", "0.5", "1", "2", "3", "4",
288 // "5", "6", "7", "8", "9", "10", "15", "20"]; 288 // "5", "6", "7", "8", "9", "10", "15", "20"];
289 - $(sl_gop + " option[value='0.5']").attr("selected", true); 289 + $(sl_gop + " option[value='1']").attr("selected", true);
290 290
291 //var sizes = ["176x144", "320x240", "352x240", 291 //var sizes = ["176x144", "320x240", "352x240",
292 // "352x288", "460x240", "640x480", "720x480", "720x576", "800x600", 292 // "352x288", "460x240", "640x480", "720x480", "720x576", "800x600",
293 // "1024x768", "1280x720", "1360x768", "1920x1080"]; 293 // "1024x768", "1280x720", "1360x768", "1920x1080"];
294 - $(sl_size + " option[value='320x240']").attr("selected", true); 294 + $(sl_size + " option[value='640x480']").attr("selected", true);
295 295
296 //var fpses = ["5", "10", "15", "20", "24", "25", "29.97", "30"]; 296 //var fpses = ["5", "10", "15", "20", "24", "25", "29.97", "30"];
297 - $(sl_fps + " option[value='10']").attr("selected", true); 297 + $(sl_fps + " option[value='15']").attr("selected", true);
298 298
299 //var bitrates = ["50", "200", "350", "500", "650", "800", 299 //var bitrates = ["50", "200", "350", "500", "650", "800",
300 // "950", "1000", "1200", "1500", "1800", "2000", "3000", "5000"]; 300 // "950", "1000", "1200", "1500", "1800", "2000", "3000", "5000"];
301 - $(sl_bitrate + " option[value='200']").attr("selected", true); 301 + $(sl_bitrate + " option[value='350']").attr("selected", true);
302 } 302 }
303 /** 303 /**
304 * get the vcodec and acodec. 304 * get the vcodec and acodec.
@@ -87,6 +87,9 @@ SrsPublisher.prototype.start = function() { @@ -87,6 +87,9 @@ SrsPublisher.prototype.start = function() {
87 * @param acodec an object contains the audio codec info. 87 * @param acodec an object contains the audio codec info.
88 */ 88 */
89 SrsPublisher.prototype.publish = function(url, vcodec, acodec) { 89 SrsPublisher.prototype.publish = function(url, vcodec, acodec) {
  90 + this.stop();
  91 + SrsPublisher.__publishers.push(this);
  92 +
90 if (url) { 93 if (url) {
91 this.url = url; 94 this.url = url;
92 } 95 }
@@ -100,6 +103,17 @@ SrsPublisher.prototype.publish = function(url, vcodec, acodec) { @@ -100,6 +103,17 @@ SrsPublisher.prototype.publish = function(url, vcodec, acodec) {
100 this.callbackObj.ref.__publish(this.url, this.width, this.height, this.vcodec, this.acodec); 103 this.callbackObj.ref.__publish(this.url, this.width, this.height, this.vcodec, this.acodec);
101 } 104 }
102 SrsPublisher.prototype.stop = function() { 105 SrsPublisher.prototype.stop = function() {
  106 + for (var i = 0; i < SrsPublisher.__publishers.length; i++) {
  107 + var player = SrsPublisher.__publishers[i];
  108 +
  109 + if (player.id != this.id) {
  110 + continue;
  111 + }
  112 +
  113 + SrsPublisher.__publishers.splice(i, 1);
  114 + break;
  115 + }
  116 +
103 this.callbackObj.ref.__stop(); 117 this.callbackObj.ref.__stop();
104 } 118 }
105 /** 119 /**
@@ -86,6 +86,16 @@ @@ -86,6 +86,16 @@
86 realtime_player.start(); 86 realtime_player.start();
87 } 87 }
88 88
  89 + // 2x8 users
  90 + for (var i = 0; i < 8; i++) {
  91 + var tr = $("<tr></tr>").hide();
  92 + $("#lst_chats").append(tr);
  93 +
  94 + for (var j = 0; j < 2; j++) {
  95 + tr.append($("<td></td>").attr("id", "td_" + (i * 8 + j)));
  96 + }
  97 + }
  98 +
89 api_server = "http://" + query.hostname + ":" + srs_get_api_server_port() + "/api/v1/chats"; 99 api_server = "http://" + query.hostname + ":" + srs_get_api_server_port() + "/api/v1/chats";
90 refresh(); 100 refresh();
91 }); 101 });
@@ -187,28 +197,84 @@ @@ -187,28 +197,84 @@
187 } 197 }
188 }); 198 });
189 } 199 }
190 - function render_chat_room(chats) { 200 + function render_chat_room(original_chats) {
191 if (!self_chat) { 201 if (!self_chat) {
192 return; 202 return;
193 } 203 }
194 204
195 - // new added chat  
196 - for (var i = 0; i < chats.length; i++) {  
197 - var chat = chats[i]; 205 + var chats = [];
  206 + for (var i = 0; i < original_chats.length; i++) {
  207 + var chat = original_chats[i];
  208 +
198 // ignore the self. 209 // ignore the self.
199 if (self_chat && self_chat.id == chat.id) { 210 if (self_chat && self_chat.id == chat.id) {
200 continue; 211 continue;
201 } 212 }
202 213
  214 + chats.push(chat);
  215 + }
  216 +
  217 + // new added chat
  218 + for (var i = 0; i < chats.length; i++) {
  219 + var chat = chats[i];
  220 +
203 // if previous exists, ignore, only add new here. 221 // if previous exists, ignore, only add new here.
204 var previous_chat = get_previous_chat_user(previous_chats, chat.id); 222 var previous_chat = get_previous_chat_user(previous_chats, chat.id);
205 if (previous_chat) { 223 if (previous_chat) {
206 // update reference. 224 // update reference.
  225 + chat.ui = previous_chat.ui;
  226 + chat.parent = previous_chat.parent;
207 chat.player = previous_chat.player; 227 chat.player = previous_chat.player;
  228 + if (chat.player) {
208 chat.player.private_object = chat; 229 chat.player.private_object = chat;
  230 + }
  231 + continue;
  232 + }
  233 + }
  234 +
  235 + // removed chat
  236 + for (var i = 0; i < previous_chats.length; i++) {
  237 + var chat = previous_chats[i];
  238 +
  239 + var new_chat = get_previous_chat_user(chats, chat.id);
  240 + if (new_chat) {
209 continue; 241 continue;
210 } 242 }
211 243
  244 + if (chat.player) {
  245 + chat.player.stop();
  246 + }
  247 + $("#div_" + chat.id).remove();
  248 + }
  249 +
  250 + // hide empty rows.
  251 + $("#lst_chats").find("tr").each(function(){
  252 + var empty = true;
  253 +
  254 + $(this).find("td").each(function(){
  255 + if ($(this).html() != "") {
  256 + empty = false;
  257 + return false; // abort each
  258 + }
  259 + return true;
  260 + });
  261 +
  262 + if (empty) {
  263 + $(this).hide();
  264 + }
  265 + });
  266 +
  267 + // render the chat
  268 + for (var i = 0; i < chats.length; i++) {
  269 + var chat = chats[i];
  270 +
  271 + // if redered, ignore.
  272 + if (chat.parent) {
  273 + continue;
  274 + }
  275 +
  276 + // generate the ui of chat
  277 + if (!chat.ui) {
212 global_chat_user_id++; 278 global_chat_user_id++;
213 279
214 // username: a str indicates the user name. 280 // username: a str indicates the user name.
@@ -216,6 +282,10 @@ @@ -216,6 +282,10 @@
216 // join_date: a str indicates the join timestamp in seconds. 282 // join_date: a str indicates the join timestamp in seconds.
217 // join_date_str: friendly formated time. 283 // join_date_str: friendly formated time.
218 var obj = $("<div/>").html($("#template").html()); 284 var obj = $("<div/>").html($("#template").html());
  285 + if (true) {
  286 + // save current ui object to the chat.
  287 + chat.ui = obj;
  288 +
219 $(obj).attr("chat_id", chat.id); 289 $(obj).attr("chat_id", chat.id);
220 $(obj).attr("id", "div_" + chat.id); // for specifed chat: $("#div_" + chat_id) 290 $(obj).attr("id", "div_" + chat.id); // for specifed chat: $("#div_" + chat_id)
221 $(obj).attr("class", "div_chat"); // for all chats: $(".div_chat") 291 $(obj).attr("class", "div_chat"); // for all chats: $(".div_chat")
@@ -225,14 +295,38 @@ @@ -225,14 +295,38 @@
225 $(obj).find("#join_date").text(chat.join_date_str); 295 $(obj).find("#join_date").text(chat.join_date_str);
226 $(obj).find("#collapseM").attr("id", "collapse_" + global_chat_user_id); 296 $(obj).find("#collapseM").attr("id", "collapse_" + global_chat_user_id);
227 $(obj).find("#headerN").attr("href", "#collapse_" + global_chat_user_id); 297 $(obj).find("#headerN").attr("href", "#collapse_" + global_chat_user_id);
  298 + }
  299 + }
228 300
229 - $("#lst_chats").append(obj); 301 + // find a idle td to render the chat.
  302 + var parent = null;
  303 + $("#lst_chats").find("td").each(function(){
  304 + if ($(this).html() != "") {
  305 + return true;
  306 + }
  307 +
  308 + parent = $(this);
  309 + return false; // abort each
  310 + });
  311 +
  312 + if (!parent) {
  313 + warn("没有可用的位置展示流。");
  314 + break;
  315 + }
  316 + $(parent).append(chat.ui);
  317 + $(parent).parent().show();
  318 +
  319 + // when ui elements appent to the page,
  320 + // create the player, or flash will failed.
  321 + if (!chat.parent) {
  322 + chat.parent = $(parent);
230 323
231 if (!no_play) { 324 if (!no_play) {
232 // start the realtime player. 325 // start the realtime player.
233 - var _player = new SrsPlayer("rp_raw_" + chat.id, 600, 300, chat); 326 + var _player = new SrsPlayer("rp_raw_" + chat.id, 430, 185, chat);
234 _player.on_player_ready = function() { 327 _player.on_player_ready = function() {
235 this.set_bt(0.5); 328 this.set_bt(0.5);
  329 + this.play();
236 }; 330 };
237 _player.on_player_metadata = function(metadata) { 331 _player.on_player_metadata = function(metadata) {
238 this.set_dar(0, 0); 332 this.set_dar(0, 0);
@@ -262,24 +356,6 @@ @@ -262,24 +356,6 @@
262 chat.player.play(); 356 chat.player.play();
263 }); 357 });
264 } 358 }
265 -  
266 - // removed chat  
267 - for (var i = 0; i < previous_chats.length; i++) {  
268 - var chat = previous_chats[i];  
269 - // ignore the self.  
270 - if (self_chat && self_chat.id == chat.id) {  
271 - continue;  
272 - }  
273 -  
274 - var new_chat = get_previous_chat_user(chats, chat.id);  
275 - if (new_chat) {  
276 - continue;  
277 - }  
278 -  
279 - if (chat.player) {  
280 - chat.player.stop();  
281 - }  
282 - $("#div_" + chat.id).remove();  
283 } 359 }
284 360
285 previous_chats = chats; 361 previous_chats = chats;
@@ -325,10 +401,6 @@ @@ -325,10 +401,6 @@
325 // removed chat 401 // removed chat
326 for (var i = 0; i < previous_chats.length; i++) { 402 for (var i = 0; i < previous_chats.length; i++) {
327 var chat = previous_chats[i]; 403 var chat = previous_chats[i];
328 - // ignore the self.  
329 - if (self_chat && self_chat.id == chat.id) {  
330 - continue;  
331 - }  
332 404
333 if (chat.player) { 405 if (chat.player) {
334 chat.player.stop(); 406 chat.player.stop();
@@ -517,26 +589,18 @@ @@ -517,26 +589,18 @@
517 <img src="img/tooltip.png"/> 589 <img src="img/tooltip.png"/>
518 </span> 590 </span>
519 </div> 591 </div>
520 - <div id="collapseM" class="accordion-body collapse"> 592 + <div id="collapseM" class="accordion-body collapse in">
521 <div class="accordion-inner"> 593 <div class="accordion-inner">
522 - <div class="row-fluid">  
523 - <div class="span2">  
524 - </div>  
525 - <div class="span8">  
526 <div id="chat_player"> 594 <div id="chat_player">
527 <div id="chat_player_raw"> 595 <div id="chat_player_raw">
528 </div> 596 </div>
529 </div> 597 </div>
530 </div> 598 </div>
531 - <div class="span2">  
532 - </div>  
533 - </div>  
534 - </div>  
535 - </div>  
536 </div> 599 </div>
537 </div> 600 </div>
538 - <div class="container" id="lst_chats">  
539 </div> 601 </div>
  602 + <table id="lst_chats" class="table">
  603 + </table>
540 <div id="video_modal" class="modal hide fade"> 604 <div id="video_modal" class="modal hide fade">
541 <div class="modal-header"> 605 <div class="modal-header">
542 <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> 606 <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>