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 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /* global $, $iq, config, connection, Etherpad, hangUp, messageHandler,
  2. roomName, sessionTerminated, Strophe, 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' && !sessionTerminated) {
  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.getFocusComponent = 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. return focusComponent;
  77. };
  78. my.createConferenceIq = function () {
  79. // Generate create conference IQ
  80. var elem = $iq({to: Moderator.getFocusComponent(), type: 'set'});
  81. elem.c('conference', {
  82. xmlns: 'http://jitsi.org/protocol/focus',
  83. room: roomName
  84. });
  85. if (config.hosts.bridge !== undefined)
  86. {
  87. elem.c(
  88. 'property',
  89. { name: 'bridge', value: config.hosts.bridge})
  90. .up();
  91. }
  92. if (config.channelLastN !== undefined)
  93. {
  94. elem.c(
  95. 'property',
  96. { name: 'channelLastN', value: config.channelLastN})
  97. .up();
  98. }
  99. if (config.adaptiveLastN !== undefined)
  100. {
  101. elem.c(
  102. 'property',
  103. { name: 'adaptiveLastN', value: config.adaptiveLastN})
  104. .up();
  105. }
  106. if (config.adaptiveSimulcast !== undefined)
  107. {
  108. elem.c(
  109. 'property',
  110. { name: 'adaptiveSimulcast', value: config.adaptiveSimulcast})
  111. .up();
  112. }
  113. if (config.openSctp !== undefined)
  114. {
  115. elem.c(
  116. 'property',
  117. { name: 'openSctp', value: config.openSctp})
  118. .up();
  119. }
  120. if (config.enableFirefoxSupport !== undefined)
  121. {
  122. elem.c(
  123. 'property',
  124. { name: 'enableFirefoxHacks', value: config.enableFirefoxSupport})
  125. .up();
  126. }
  127. elem.up();
  128. return elem;
  129. };
  130. // FIXME: we need to show the fact that we're waiting for the focus
  131. // to the user(or that focus is not available)
  132. my.allocateConferenceFocus = function (roomName, callback) {
  133. // Try to use focus user JID from the config
  134. Moderator.setFocusUserJid(config.focusUserJid);
  135. // Send create conference IQ
  136. var iq = Moderator.createConferenceIq();
  137. connection.sendIQ(
  138. iq,
  139. function (result) {
  140. if ('true' === $(result).find('conference').attr('ready')) {
  141. // Reset both timers
  142. getNextTimeout(true);
  143. getNextErrorTimeout(true);
  144. Moderator.setFocusUserJid(
  145. $(result).find('conference').attr('focusjid'));
  146. callback();
  147. } else {
  148. var waitMs = getNextTimeout();
  149. console.info("Waiting for the focus... " + waitMs);
  150. // Reset error timeout
  151. getNextErrorTimeout(true);
  152. window.setTimeout(
  153. function () {
  154. Moderator.allocateConferenceFocus(
  155. roomName, callback);
  156. }, waitMs);
  157. }
  158. },
  159. function (error) {
  160. var waitMs = getNextErrorTimeout();
  161. console.error("Focus error, retry after " + waitMs, error);
  162. // Show message
  163. messageHandler.notify(
  164. 'Conference focus', 'disconnected',
  165. Moderator.getFocusComponent() +
  166. ' not available - retry in ' + (waitMs / 1000) + ' sec');
  167. // Reset response timeout
  168. getNextTimeout(true);
  169. window.setTimeout(
  170. function () {
  171. Moderator.allocateConferenceFocus(roomName, callback);
  172. }, waitMs);
  173. }
  174. );
  175. };
  176. return my;
  177. }(Moderator || {}));