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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /* global $, $iq, config, connection, Etherpad, hangUp, Strophe, Toolbar,
  2. 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. // FIXME: we need to show the fact that we're waiting for the focus
  60. // to the user(or that focus is not available)
  61. my.allocateConferenceFocus = function (roomName, callback) {
  62. var elem = $iq({to: config.hosts.focus, type: 'set'});
  63. elem.c('conference', {
  64. xmlns: 'http://jitsi.org/protocol/focus',
  65. room: roomName
  66. });
  67. elem.up();
  68. connection.sendIQ(elem,
  69. function (result) {
  70. if ('true' === $(result).find('conference').attr('ready')) {
  71. // Reset both timers
  72. getNextTimeout(true);
  73. getNextErrorTimeout(true);
  74. callback();
  75. } else {
  76. var waitMs = getNextTimeout();
  77. console.info("Waiting for the focus... " + waitMs);
  78. // Reset error timeout
  79. getNextErrorTimeout(true);
  80. window.setTimeout(
  81. function () {
  82. Moderator.allocateConferenceFocus(roomName, callback);
  83. }, waitMs);
  84. }
  85. },
  86. function (error) {
  87. var waitMs = getNextErrorTimeout();
  88. console.error("Focus error, retry after " + waitMs, error);
  89. // Reset response timeout
  90. getNextTimeout(true);
  91. window.setTimeout(
  92. function () {
  93. Moderator.allocateConferenceFocus(roomName, callback);
  94. }, waitMs);
  95. }
  96. );
  97. };
  98. return my;
  99. }(Moderator || {}));