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.

RoomLocker.js 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /* global APP, JitsiMeetJS */
  2. import messageHandler from './UI/util/MessageHandler';
  3. import UIUtil from './UI/util/UIUtil';
  4. import AnalyticsAdapter from './statistics/AnalyticsAdapter';
  5. function askForNewPassword () {
  6. let passMsg = APP.translation.generateTranslationHTML("dialog.passwordMsg");
  7. let yourPassMsg = APP.translation.translateString("dialog.yourPassword");
  8. let msg = `
  9. <h2>${passMsg}</h2>
  10. <input name="lockKey" type="text"
  11. data-i18n="[placeholder]dialog.yourPassword"
  12. placeholder="${yourPassMsg}" autofocus>
  13. `;
  14. return new Promise(function (resolve, reject) {
  15. messageHandler.openTwoButtonDialog(
  16. null, null, null,
  17. msg, false, "dialog.Save",
  18. function (e, v, m, f) {
  19. if (v && f.lockKey) {
  20. resolve(UIUtil.escapeHtml(f.lockKey));
  21. } else {
  22. reject();
  23. }
  24. },
  25. null, null, 'input:first'
  26. );
  27. });
  28. }
  29. function askForPassword () {
  30. let passRequiredMsg = APP.translation.translateString(
  31. "dialog.passwordRequired"
  32. );
  33. let passMsg = APP.translation.translateString("dialog.password");
  34. let msg = `
  35. <h2 data-i18n="dialog.passwordRequired">${passRequiredMsg}</h2>
  36. <input name="lockKey" type="text"
  37. data-i18n="[placeholder]dialog.password"
  38. placeholder="${passMsg}" autofocus>
  39. `;
  40. return new Promise(function (resolve, reject) {
  41. messageHandler.openTwoButtonDialog(
  42. null, null, null, msg,
  43. true, "dialog.Ok",
  44. function (e, v, m, f) {}, null,
  45. function (e, v, m, f) {
  46. if (v && f.lockKey) {
  47. resolve(UIUtil.escapeHtml(f.lockKey));
  48. } else {
  49. reject();
  50. }
  51. },
  52. ':input:first'
  53. );
  54. });
  55. }
  56. function askToUnlock () {
  57. return new Promise(function (resolve, reject) {
  58. messageHandler.openTwoButtonDialog(
  59. null, null, "dialog.passwordCheck",
  60. null, false, "dialog.Remove",
  61. function (e, v) {
  62. if (v) {
  63. resolve();
  64. } else {
  65. reject();
  66. }
  67. }
  68. );
  69. });
  70. }
  71. function notifyPasswordNotSupported (err) {
  72. console.warn('setting password failed', err);
  73. messageHandler.showError("dialog.warning", "dialog.passwordNotSupported");
  74. }
  75. function notifyPasswordFailed() {
  76. console.warn('room passwords not supported');
  77. messageHandler.showError("dialog.lockTitle", "dialog.lockMessage");
  78. }
  79. const ConferenceErrors = JitsiMeetJS.errors.conference;
  80. export default function createRoomLocker (room) {
  81. let password;
  82. function lock (newPass) {
  83. return room.lock(newPass).then(function () {
  84. password = newPass;
  85. }).catch(function (err) {
  86. if (err === ConferenceErrors.PASSWORD_NOT_SUPPORTED) {
  87. notifyPasswordNotSupported();
  88. } else {
  89. notifyPasswordFailed(err);
  90. }
  91. throw err;
  92. });
  93. }
  94. return {
  95. get isLocked () {
  96. return !!password;
  97. },
  98. get password () {
  99. return password;
  100. },
  101. askToUnlock () {
  102. askToUnlock().then(function () {
  103. return lock();
  104. }).then(function () {
  105. AnalyticsAdapter.sendEvent('toolbar.lock.disabled');
  106. });
  107. },
  108. askToLock () {
  109. return askForNewPassword().then(function (newPass) {
  110. return lock(newPass);
  111. }).then(function () {
  112. AnalyticsAdapter.sendEvent('toolbar.lock.enabled');
  113. });
  114. },
  115. requirePassword () {
  116. return askForPassword().then(function (newPass) {
  117. password = newPass;
  118. });
  119. },
  120. notifyModeratorRequired () {
  121. if (password) {
  122. messageHandler.openMessageDialog(null, "dialog.passwordError");
  123. } else {
  124. messageHandler.openMessageDialog(null, "dialog.passwordError2");
  125. }
  126. }
  127. };
  128. }