PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/labs/bbb-api-php/demo4.js

http://github.com/bigbluebutton/bigbluebutton
JavaScript | 147 lines | 91 code | 22 blank | 34 comment | 27 complexity | ebb3cec32dcf0ab298c49f68553e93f5 MD5 | raw file
Possible License(s): LGPL-3.0
  1. /*
  2. BigBlueButton - http://www.bigbluebutton.org
  3. Copyright (c) 2008-2009 by respective authors (see below). All rights reserved.
  4. BigBlueButton is free software; you can redistribute it and/or modify it under the
  5. terms of the GNU Lesser General Public License as published by the Free Software
  6. Foundation; either version 3 of the License, or (at your option) any later
  7. version.
  8. BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
  9. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  10. PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License along
  12. with BigBlueButton; if not, If not, see <http://www.gnu.org/licenses/>.
  13. Author: Islam El-Ashi <ielashi@gmail.com>
  14. */
  15. var meetings; // will hold the meetings data
  16. $(document).ready(function(){
  17. updateMeetingInfo(); // update the available meeting information as soon as the page is loaded.
  18. setInterval("updateMeetingInfo()", 15000); // update the meeting information every 15 seconds
  19. });
  20. // For each active meeting, create a table listing the participants and insert it into the page.
  21. function createMeetings() {
  22. var nOfMeetings = 0;
  23. if (meetings.meeting) {
  24. for (var i in meetings.meeting) {
  25. // this variable is to work around the JSON nuance of having a variable instead of an array of one member.
  26. // if we detect there is more than one meeting use the array, otherwise use the variable
  27. var meeting = (meetings.meeting[i].attendees != null) ? meetings.meeting[i] : meetings.meeting;
  28. createMeetingTable(meeting);
  29. if (meeting.participantCount != "0") nOfMeetings++;
  30. // this is also to work around the JSON nuance, if we previously detected that there is only
  31. // one element (i.e. a variable) then we shouldn't loop again.
  32. if (meeting == meetings.meeting) break;
  33. }
  34. }
  35. // if there are no meetings then display a message to the user.
  36. if (nOfMeetings == 0) {
  37. $("#no_meetings").text("No meetings currently running.");
  38. $("#meetings").text('');
  39. }
  40. else
  41. $("#no_meetings").text('');
  42. }
  43. // creates div tags for each meeting to be able to insert the meeting table into the DOM afterwards
  44. function initializeDivTags() {
  45. if (meetings.meeting) {
  46. var meetingID;
  47. var meeting;
  48. var encodedMeetingID;
  49. for (var i in meetings.meeting) {
  50. meeting = (meetings.meeting[i].attendees != null) ? meetings.meeting[i] : meetings.meeting;
  51. meetingID = meeting.meetingID;
  52. encodedMeeting = encode(meetingID);
  53. if ($("#" + encodedMeeting).length == 0) {
  54. // assign the div tag an id unique to each meeting
  55. // the id assigned is the encoded value of the meeting id, the encoding is to avoid
  56. // special characters and spaces in the id
  57. $("#meetings").append('<div id="' + encodedMeeting + '" class="hiddenDiv"></div>');
  58. }
  59. if (meeting == meetings.meeting) break;
  60. }
  61. }
  62. }
  63. // call the demo4 helper page to fetch the updated data, this is executed every 15 seconds.
  64. function updateMeetingInfo() {
  65. $.ajax({
  66. type: "GET",
  67. url: 'demo4_helper.php?getxml=true',
  68. dataType: "text/xml",
  69. cache: false,
  70. success: function(xml) {
  71. meetings = $.xml2json(xml);
  72. initializeDivTags();
  73. createMeetings();
  74. },
  75. error: function() {
  76. $("#no_meetings").text("Failed to connect to API.");
  77. $("#meetings").text("");
  78. }
  79. });
  80. }
  81. function getMeetingsInfoURL(meetingID, password, checksum) {
  82. return '../api/getMeetingInfo?meetingID=' + meetingID + '&password=' + password + '&checksum=' + checksum;
  83. }
  84. function createMeetingTable(meeting) {
  85. var tableContent = '<table name="' + meeting.meetingID + '" class="hor-minimalist-b" cellspacing="0" summary="The current participants in a meeting"><caption>' + meeting.meetingID + '</caption><tr><th scope="col" abbr="Participants">Participants</th><th scope="col" abbr="Name">Name</th><th scope="col" abbr="Role">Role</th></tr>';
  86. var encodedMeetingID = encode(meeting.meetingID);
  87. var tableRowId;
  88. var newRows = new Array();
  89. var numberOfRows = 0;
  90. if (meeting.attendees.attendee) {
  91. for (var i in meeting.attendees.attendee) {
  92. var attendee = (meeting.attendees.attendee[i].userID != null) ? meeting.attendees.attendee[i] : meeting.attendees.attendee;
  93. tableRowId = encodedMeetingID + '_' + attendee.userID;
  94. tableContent += '<tr id="' + tableRowId + '"><td>' + attendee.userID + '<td>' + attendee.fullName + '</td><td>' + attendee.role + '</td></tr>'
  95. // if there is a new row to be added, then add to the new rows array to display it with a flash effect.
  96. if ($("#" + tableRowId).length == 0) {
  97. newRows[newRows.length] = tableRowId;
  98. }
  99. numberOfRows++;
  100. if (attendee == meeting.attendees.attendee) break;
  101. }
  102. }
  103. tableContent += '</table>';
  104. if (numberOfRows > 0) {
  105. $("#" + encodedMeetingID).html(tableContent);
  106. $("#" + encodedMeetingID).show("fast");
  107. }
  108. else {
  109. $("#" + encodedMeetingID).hide("fast");
  110. }
  111. for (var i = 0; i < newRows.length; i++) {
  112. $("#" + newRows[i]).effect("highlight", {}, 3000);
  113. }
  114. }
  115. // the encoding hashes the string to an md5, which ensures - to a great extent - that the encoded string will be
  116. // 1. unique per the original string
  117. // 2. has no spaces and/or special characters
  118. function encode(string) {
  119. return hex_md5(string);
  120. }