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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 getNextTimeout = Util.createExpBackoffTimer(1000);
  9. var getNextErrorTimeout = Util.createExpBackoffTimer(1000);
  10. my.isModerator = function () {
  11. return connection.emuc.isModerator();
  12. };
  13. my.onModeratorStatusChanged = function (isModerator) {
  14. Toolbar.showSipCallButton(isModerator);
  15. Toolbar.showRecordingButton(
  16. isModerator); //&&
  17. // FIXME:
  18. // Recording visible if
  19. // there are at least 2(+ 1 focus) participants
  20. //Object.keys(connection.emuc.members).length >= 3);
  21. if (isModerator && config.etherpad_base) {
  22. Etherpad.init();
  23. }
  24. $(document).trigger('local.role.moderator', [isModerator]);
  25. };
  26. my.init = function () {
  27. $(document).bind(
  28. 'role.changed.muc',
  29. function (event, jid, info, pres) {
  30. console.info(
  31. "Role changed for " + jid + ", new role: " + info.role);
  32. VideoLayout.showModeratorIndicator();
  33. }
  34. );
  35. $(document).bind(
  36. 'local.role.changed.muc',
  37. function (event, jid, info, pres) {
  38. console.info("My role changed, new role: " + info.role);
  39. VideoLayout.showModeratorIndicator();
  40. Moderator.onModeratorStatusChanged(Moderator.isModerator());
  41. }
  42. );
  43. $(document).bind(
  44. 'left.muc',
  45. function (event, jid) {
  46. console.info("Someone left is it focus ? " + jid);
  47. var resource = Strophe.getResourceFromJid(jid);
  48. if (resource === 'focus') {
  49. console.info(
  50. "Focus has left the room - leaving conference");
  51. //hangUp();
  52. // We'd rather reload to have everything re-initialized
  53. // FIXME: show some message before reload
  54. location.reload();
  55. }
  56. }
  57. );
  58. };
  59. my.createConferenceIq = function () {
  60. var elem = $iq({to: config.hosts.focus, type: 'set'});
  61. elem.c('conference', {
  62. xmlns: 'http://jitsi.org/protocol/focus',
  63. room: roomName
  64. });
  65. if (config.channelLastN !== undefined)
  66. {
  67. elem.c(
  68. 'property',
  69. { name: 'channelLastN', value: config.channelLastN})
  70. .up();
  71. }
  72. if (config.adaptiveLastN !== undefined)
  73. {
  74. elem.c(
  75. 'property',
  76. { name: 'adaptiveLastN', value: config.adaptiveLastN})
  77. .up();
  78. }
  79. if (config.adaptiveSimulcast !== undefined)
  80. {
  81. elem.c(
  82. 'property',
  83. { name: 'adaptiveSimulcast', value: config.adaptiveSimulcast})
  84. .up();
  85. }
  86. elem.up();
  87. return elem;
  88. };
  89. // FIXME: we need to show the fact that we're waiting for the focus
  90. // to the user(or that focus is not available)
  91. my.allocateConferenceFocus = function (roomName, callback) {
  92. var iq = Moderator.createConferenceIq();
  93. connection.sendIQ(
  94. iq,
  95. function (result) {
  96. if ('true' === $(result).find('conference').attr('ready')) {
  97. // Reset both timers
  98. getNextTimeout(true);
  99. getNextErrorTimeout(true);
  100. callback();
  101. } else {
  102. var waitMs = getNextTimeout();
  103. console.info("Waiting for the focus... " + waitMs);
  104. // Reset error timeout
  105. getNextErrorTimeout(true);
  106. window.setTimeout(
  107. function () {
  108. Moderator.allocateConferenceFocus(
  109. roomName, callback);
  110. }, waitMs);
  111. }
  112. },
  113. function (error) {
  114. var waitMs = getNextErrorTimeout();
  115. console.error("Focus error, retry after " + waitMs, error);
  116. // Reset response timeout
  117. getNextTimeout(true);
  118. window.setTimeout(
  119. function () {
  120. Moderator.allocateConferenceFocus(roomName, callback);
  121. }, waitMs);
  122. }
  123. );
  124. };
  125. return my;
  126. }(Moderator || {}));