您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

RoomLocker.js 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /* global APP, JitsiMeetJS */
  2. const logger = require("jitsi-meet-logger").getLogger(__filename);
  3. /**
  4. * Show notification that user cannot set password for the conference
  5. * because server doesn't support that.
  6. */
  7. function notifyPasswordNotSupported () {
  8. logger.warn('room passwords not supported');
  9. APP.UI.messageHandler.showError(
  10. "dialog.warning", "dialog.passwordNotSupported");
  11. }
  12. /**
  13. * Show notification that setting password for the conference failed.
  14. * @param {Error} err error
  15. */
  16. function notifyPasswordFailed(err) {
  17. logger.warn('setting password failed', err);
  18. APP.UI.messageHandler.showError(
  19. "dialog.lockTitle", "dialog.lockMessage");
  20. }
  21. const ConferenceErrors = JitsiMeetJS.errors.conference;
  22. /**
  23. * Create new RoomLocker for the conference.
  24. * It allows to set or remove password for the conference,
  25. * or ask for required password.
  26. * @returns {RoomLocker}
  27. */
  28. export default function createRoomLocker (room) {
  29. let password;
  30. /**
  31. * If the room was locked from someone other than us, we indicate it with
  32. * this property in order to have correct roomLocker state of isLocked.
  33. * @type {boolean} whether room is locked, but not from us.
  34. */
  35. let lockedElsewhere = false;
  36. /**
  37. * @class RoomLocker
  38. */
  39. return {
  40. get isLocked () {
  41. return !!password || lockedElsewhere;
  42. },
  43. get password () {
  44. return password;
  45. },
  46. /**
  47. * Allows to set new password
  48. * @param newPass
  49. * @returns {Promise.<TResult>}
  50. */
  51. lock (newPass) {
  52. return room.lock(newPass).then(() => {
  53. password = newPass;
  54. // If the password is undefined this means that we're removing
  55. // it for everyone.
  56. if (!password)
  57. lockedElsewhere = false;
  58. }).catch(function (err) {
  59. logger.error(err);
  60. if (err === ConferenceErrors.PASSWORD_NOT_SUPPORTED) {
  61. notifyPasswordNotSupported();
  62. } else {
  63. notifyPasswordFailed(err);
  64. }
  65. throw err;
  66. });
  67. },
  68. /**
  69. * Sets that the room is locked from another user, not us.
  70. * @param {boolean} value locked/unlocked state
  71. */
  72. set lockedElsewhere (value) {
  73. lockedElsewhere = value;
  74. },
  75. /**
  76. * Whether room is locked from someone else.
  77. * @returns {boolean} whether room is not locked locally,
  78. * but it is still locked.
  79. */
  80. get lockedElsewhere () {
  81. return lockedElsewhere;
  82. },
  83. /**
  84. * Reset the password. Can be useful when room
  85. * has been unlocked from elsewhere and we can use
  86. * this method for sync the pass
  87. */
  88. resetPassword() {
  89. password = null;
  90. },
  91. };
  92. }