You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

moderator.js 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /* global $, $iq, config, connection, Etherpad, hangUp, roomName, Strophe,
  2. Toolbar, Util, VideoLayout */
  3. /**
  4. * Contains logic responsible for enabling/disabling functionality available
  5. * only to moderator users.
  6. */
  7. var Moderator = (function (my) {
  8. var focusUserJid;
  9. var getNextTimeout = Util.createExpBackoffTimer(1000);
  10. var getNextErrorTimeout = Util.createExpBackoffTimer(1000);
  11. my.isModerator = function () {
  12. return connection.emuc.isModerator();
  13. };
  14. my.onModeratorStatusChanged = function (isModerator) {
  15. Toolbar.showSipCallButton(isModerator);
  16. Toolbar.showRecordingButton(
  17. isModerator); //&&
  18. // FIXME:
  19. // Recording visible if
  20. // there are at least 2(+ 1 focus) participants
  21. //Object.keys(connection.emuc.members).length >= 3);
  22. if (isModerator && config.etherpad_base) {
  23. Etherpad.init();
  24. }
  25. $(document).trigger('local.role.moderator', [isModerator]);
  26. };
  27. my.init = function () {
  28. $(document).bind(
  29. 'role.changed.muc',
  30. function (event, jid, info, pres) {
  31. console.info(
  32. "Role changed for " + jid + ", new role: " + info.role);
  33. VideoLayout.showModeratorIndicator();
  34. }
  35. );
  36. $(document).bind(
  37. 'local.role.changed.muc',
  38. function (event, jid, info, pres) {
  39. console.info("My role changed, new role: " + info.role);
  40. VideoLayout.showModeratorIndicator();
  41. Moderator.onModeratorStatusChanged(Moderator.isModerator());
  42. }
  43. );
  44. $(document).bind(
  45. 'left.muc',
  46. function (event, jid) {
  47. console.info("Someone left is it focus ? " + jid);
  48. var resource = Strophe.getResourceFromJid(jid);
  49. if (resource === 'focus') {
  50. console.info(
  51. "Focus has left the room - leaving conference");
  52. //hangUp();
  53. // We'd rather reload to have everything re-initialized
  54. // FIXME: show some message before reload
  55. location.reload();
  56. }
  57. }
  58. );
  59. };
  60. my.setFocusUserJid = function (focusJid) {
  61. if (!focusUserJid) {
  62. focusUserJid = focusJid;
  63. console.info("Focus jid set to: " + focusUserJid);
  64. }
  65. };
  66. my.getFocusUserJid = function () {
  67. return focusUserJid;
  68. };
  69. my.createConferenceIq = function () {
  70. // Get focus component address
  71. var focusComponent = config.hosts.focus;
  72. // If not specified use default: 'focus.domain'
  73. if (!focusComponent) {
  74. focusComponent = 'focus.' + config.hosts.domain;
  75. }
  76. // Generate create conference IQ
  77. var elem = $iq({to: focusComponent, type: 'set'});
  78. elem.c('conference', {
  79. xmlns: 'http://jitsi.org/protocol/focus',
  80. room: roomName
  81. });
  82. if (config.channelLastN !== undefined)
  83. {
  84. elem.c(
  85. 'property',
  86. { name: 'channelLastN', value: config.channelLastN})
  87. .up();
  88. }
  89. if (config.adaptiveLastN !== undefined)
  90. {
  91. elem.c(
  92. 'property',
  93. { name: 'adaptiveLastN', value: config.adaptiveLastN})
  94. .up();
  95. }
  96. if (config.adaptiveSimulcast !== undefined)
  97. {
  98. elem.c(
  99. 'property',
  100. { name: 'adaptiveSimulcast', value: config.adaptiveSimulcast})
  101. .up();
  102. }
  103. if (config.openSctp !== undefined)
  104. {
  105. elem.c(
  106. 'property',
  107. { name: 'openSctp', value: config.openSctp})
  108. .up();
  109. }
  110. if (config.enableFirefoxSupport !== undefined)
  111. {
  112. elem.c(
  113. 'property',
  114. { name: 'enableFirefoxHacks', value: config.enableFirefoxSupport})
  115. .up();
  116. }
  117. elem.up();
  118. return elem;
  119. };
  120. // FIXME: we need to show the fact that we're waiting for the focus
  121. // to the user(or that focus is not available)
  122. my.allocateConferenceFocus = function (roomName, callback) {
  123. // Try to use focus user JID from the config
  124. Moderator.setFocusUserJid(config.focusUserJid);
  125. // Send create conference IQ
  126. var iq = Moderator.createConferenceIq();
  127. connection.sendIQ(
  128. iq,
  129. function (result) {
  130. if ('true' === $(result).find('conference').attr('ready')) {
  131. // Reset both timers
  132. getNextTimeout(true);
  133. getNextErrorTimeout(true);
  134. Moderator.setFocusUserJid(
  135. $(result).find('conference').attr('focusjid'));
  136. callback();
  137. } else {
  138. var waitMs = getNextTimeout();
  139. console.info("Waiting for the focus... " + waitMs);
  140. // Reset error timeout
  141. getNextErrorTimeout(true);
  142. window.setTimeout(
  143. function () {
  144. Moderator.allocateConferenceFocus(
  145. roomName, callback);
  146. }, waitMs);
  147. }
  148. },
  149. function (error) {
  150. var waitMs = getNextErrorTimeout();
  151. console.error("Focus error, retry after " + waitMs, error);
  152. // Reset response timeout
  153. getNextTimeout(true);
  154. window.setTimeout(
  155. function () {
  156. Moderator.allocateConferenceFocus(roomName, callback);
  157. }, waitMs);
  158. }
  159. );
  160. };
  161. return my;
  162. }(Moderator || {}));