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.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /* global APP, JitsiMeetJS */
  2. import UIUtil from '../util/UIUtil';
  3. /**
  4. * Show dialog which asks user for new password for the conference.
  5. * @returns {Promise<string>} password or nothing if user canceled
  6. */
  7. function askForNewPassword () {
  8. let passMsg = APP.translation.generateTranslationHTML("dialog.passwordMsg");
  9. let yourPassMsg = APP.translation.translateString("dialog.yourPassword");
  10. let msg = `
  11. <h2>${passMsg}</h2>
  12. <input name="lockKey" type="text"
  13. data-i18n="[placeholder]dialog.yourPassword"
  14. placeholder="${yourPassMsg}" autofocus>
  15. `;
  16. return new Promise(function (resolve, reject) {
  17. APP.UI.messageHandler.openTwoButtonDialog(
  18. null, null, null,
  19. msg, false, "dialog.Save",
  20. function (e, v, m, f) {
  21. if (v && f.lockKey) {
  22. resolve(UIUtil.escapeHtml(f.lockKey));
  23. }
  24. else {
  25. reject(APP.UI.messageHandler.CANCEL);
  26. }
  27. },
  28. null, null, 'input:first'
  29. );
  30. });
  31. }
  32. /**
  33. * Show dialog which asks for required conference password.
  34. * @returns {Promise<string>} password or nothing if user canceled
  35. */
  36. function askForPassword () {
  37. let passRequiredMsg = APP.translation.translateString(
  38. "dialog.passwordRequired"
  39. );
  40. let passMsg = APP.translation.translateString("dialog.password");
  41. let msg = `
  42. <h2 data-i18n="dialog.passwordRequired">${passRequiredMsg}</h2>
  43. <input name="lockKey" type="text"
  44. data-i18n="[placeholder]dialog.password"
  45. placeholder="${passMsg}" autofocus>
  46. `;
  47. return new Promise(function (resolve, reject) {
  48. APP.UI.messageHandler.openTwoButtonDialog(
  49. null, null, null, msg,
  50. true, "dialog.Ok",
  51. function (e, v, m, f) {}, null,
  52. function (e, v, m, f) {
  53. if (v && f.lockKey) {
  54. resolve(UIUtil.escapeHtml(f.lockKey));
  55. } else {
  56. reject(APP.UI.messageHandler.CANCEL);
  57. }
  58. },
  59. ':input:first'
  60. );
  61. });
  62. }
  63. /**
  64. * Show dialog which asks if user want remove password from the conference.
  65. * @returns {Promise}
  66. */
  67. function askToUnlock () {
  68. return new Promise(function (resolve, reject) {
  69. APP.UI.messageHandler.openTwoButtonDialog(
  70. null, null, "dialog.passwordCheck",
  71. null, false, "dialog.Remove",
  72. function (e, v) {
  73. if (v) {
  74. resolve();
  75. } else {
  76. reject(APP.UI.messageHandler.CANCEL);
  77. }
  78. }
  79. );
  80. });
  81. }
  82. /**
  83. * Show notification that user cannot set password for the conference
  84. * because server doesn't support that.
  85. */
  86. function notifyPasswordNotSupported () {
  87. console.warn('room passwords not supported');
  88. APP.UI.messageHandler.showError(
  89. "dialog.warning", "dialog.passwordNotSupported");
  90. }
  91. /**
  92. * Show notification that setting password for the conference failed.
  93. * @param {Error} err error
  94. */
  95. function notifyPasswordFailed(err) {
  96. console.warn('setting password failed', err);
  97. APP.UI.messageHandler.showError(
  98. "dialog.lockTitle", "dialog.lockMessage");
  99. }
  100. const ConferenceErrors = JitsiMeetJS.errors.conference;
  101. /**
  102. * Create new RoomLocker for the conference.
  103. * It allows to set or remove password for the conference,
  104. * or ask for required password.
  105. * @returns {RoomLocker}
  106. */
  107. export default function createRoomLocker (room) {
  108. let password;
  109. let dialog = null;
  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. JitsiMeetJS.analytics.sendEvent('toolbar.lock.disabled');
  142. }).catch(
  143. reason => {
  144. if (reason !== APP.UI.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. JitsiMeetJS.analytics.sendEvent('toolbar.lock.enabled');
  159. }).catch(
  160. reason => {
  161. if (reason !== APP.UI.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 !== APP.UI.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 (dialog)
  184. return;
  185. let closeCallback = function () {
  186. dialog = null;
  187. };
  188. if (password) {
  189. dialog = APP.UI.messageHandler
  190. .openMessageDialog(null, "dialog.passwordError",
  191. null, null, closeCallback);
  192. } else {
  193. dialog = APP.UI.messageHandler
  194. .openMessageDialog(null, "dialog.passwordError2",
  195. null, null, closeCallback);
  196. }
  197. }
  198. };
  199. }