Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

RoomLocker.js 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /* global APP, JitsiMeetJS */
  2. import messageHandler from '../util/MessageHandler';
  3. import UIUtil from '../util/UIUtil';
  4. //FIXME:
  5. import AnalyticsAdapter from '../../statistics/AnalyticsAdapter';
  6. /**
  7. * Show dialog which asks user for new password for the conference.
  8. * @returns {Promise<string>} password or nothing if user canceled
  9. */
  10. function askForNewPassword () {
  11. let passMsg = APP.translation.generateTranslationHTML("dialog.passwordMsg");
  12. let yourPassMsg = APP.translation.translateString("dialog.yourPassword");
  13. let msg = `
  14. <h2>${passMsg}</h2>
  15. <input name="lockKey" type="text"
  16. data-i18n="[placeholder]dialog.yourPassword"
  17. placeholder="${yourPassMsg}" autofocus>
  18. `;
  19. return new Promise(function (resolve, reject) {
  20. messageHandler.openTwoButtonDialog(
  21. null, null, null,
  22. msg, false, "dialog.Save",
  23. function (e, v, m, f) {
  24. if (v && f.lockKey) {
  25. resolve(UIUtil.escapeHtml(f.lockKey));
  26. }
  27. else {
  28. reject(messageHandler.CANCEL);
  29. }
  30. },
  31. null, null, 'input:first'
  32. );
  33. });
  34. }
  35. /**
  36. * Show dialog which asks for required conference password.
  37. * @returns {Promise<string>} password or nothing if user canceled
  38. */
  39. function askForPassword () {
  40. let passRequiredMsg = APP.translation.translateString(
  41. "dialog.passwordRequired"
  42. );
  43. let passMsg = APP.translation.translateString("dialog.password");
  44. let msg = `
  45. <h2 data-i18n="dialog.passwordRequired">${passRequiredMsg}</h2>
  46. <input name="lockKey" type="text"
  47. data-i18n="[placeholder]dialog.password"
  48. placeholder="${passMsg}" autofocus>
  49. `;
  50. return new Promise(function (resolve, reject) {
  51. messageHandler.openTwoButtonDialog(
  52. null, null, null, msg,
  53. true, "dialog.Ok",
  54. function (e, v, m, f) {}, null,
  55. function (e, v, m, f) {
  56. if (v && f.lockKey) {
  57. resolve(UIUtil.escapeHtml(f.lockKey));
  58. } else {
  59. reject(messageHandler.CANCEL);
  60. }
  61. },
  62. ':input:first'
  63. );
  64. });
  65. }
  66. /**
  67. * Show dialog which asks if user want remove password from the conference.
  68. * @returns {Promise}
  69. */
  70. function askToUnlock () {
  71. return new Promise(function (resolve, reject) {
  72. messageHandler.openTwoButtonDialog(
  73. null, null, "dialog.passwordCheck",
  74. null, false, "dialog.Remove",
  75. function (e, v) {
  76. if (v) {
  77. resolve();
  78. } else {
  79. reject(messageHandler.CANCEL);
  80. }
  81. }
  82. );
  83. });
  84. }
  85. /**
  86. * Show notification that user cannot set password for the conference
  87. * because server doesn't support that.
  88. */
  89. function notifyPasswordNotSupported () {
  90. console.warn('room passwords not supported');
  91. messageHandler.showError("dialog.warning", "dialog.passwordNotSupported");
  92. }
  93. /**
  94. * Show notification that setting password for the conference failed.
  95. * @param {Error} err error
  96. */
  97. function notifyPasswordFailed(err) {
  98. console.warn('setting password failed', err);
  99. messageHandler.showError("dialog.lockTitle", "dialog.lockMessage");
  100. }
  101. const ConferenceErrors = JitsiMeetJS.errors.conference;
  102. /**
  103. * Create new RoomLocker for the conference.
  104. * It allows to set or remove password for the conference,
  105. * or ask for required password.
  106. * @returns {RoomLocker}
  107. */
  108. export default function createRoomLocker (room) {
  109. let password;
  110. function lock (newPass) {
  111. return room.lock(newPass).then(function () {
  112. password = newPass;
  113. }).catch(function (err) {
  114. console.error(err);
  115. if (err === ConferenceErrors.PASSWORD_NOT_SUPPORTED) {
  116. notifyPasswordNotSupported();
  117. } else {
  118. notifyPasswordFailed(err);
  119. }
  120. throw err;
  121. });
  122. }
  123. /**
  124. * @class RoomLocker
  125. */
  126. return {
  127. get isLocked () {
  128. return !!password;
  129. },
  130. get password () {
  131. return password;
  132. },
  133. /**
  134. * Allows to remove password from the conference (asks user first).
  135. * @returns {Promise}
  136. */
  137. askToUnlock () {
  138. return askToUnlock().then(
  139. () => { return lock(); }
  140. ).then(function () {
  141. AnalyticsAdapter.sendEvent('toolbar.lock.disabled');
  142. }).catch(
  143. reason => {
  144. if (reason !== messageHandler.CANCEL)
  145. console.error(reason);
  146. }
  147. );
  148. },
  149. /**
  150. * Allows to set password for the conference.
  151. * It asks user for new password and locks the room.
  152. * @returns {Promise}
  153. */
  154. askToLock () {
  155. return askForNewPassword().then(
  156. newPass => { return lock(newPass);}
  157. ).then(function () {
  158. AnalyticsAdapter.sendEvent('toolbar.lock.enabled');
  159. }).catch(
  160. reason => {
  161. if (reason !== messageHandler.CANCEL)
  162. console.error(reason);
  163. }
  164. );
  165. },
  166. /**
  167. * Asks user for required conference password.
  168. */
  169. requirePassword () {
  170. return askForPassword().then(
  171. newPass => { password = newPass; }
  172. ).catch(
  173. reason => {
  174. if (reason !== messageHandler.CANCEL)
  175. console.error(reason);
  176. }
  177. );
  178. },
  179. /**
  180. * Show notification that to set/remove password user must be moderator.
  181. */
  182. notifyModeratorRequired () {
  183. if (password) {
  184. messageHandler.openMessageDialog(null, "dialog.passwordError");
  185. } else {
  186. messageHandler.openMessageDialog(null, "dialog.passwordError2");
  187. }
  188. }
  189. };
  190. }