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.

Settings.js 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /* global JitsiMeetJS */
  2. import UIUtil from '../UI/util/UIUtil';
  3. let email = '';
  4. let displayName = '';
  5. let language = null;
  6. let cameraDeviceId = '';
  7. let micDeviceId = '';
  8. let welcomePageDisabled = false;
  9. let localFlipX = null;
  10. let avatarUrl = '';
  11. function supportsLocalStorage() {
  12. try {
  13. return 'localStorage' in window && window.localStorage !== null;
  14. } catch (e) {
  15. console.log("localstorage is not supported");
  16. return false;
  17. }
  18. }
  19. function generateUniqueId() {
  20. function _p8() {
  21. return (Math.random().toString(16) + "000000000").substr(2, 8);
  22. }
  23. return _p8() + _p8() + _p8() + _p8();
  24. }
  25. if (supportsLocalStorage()) {
  26. if (!window.localStorage.jitsiMeetId) {
  27. window.localStorage.jitsiMeetId = generateUniqueId();
  28. console.log("generated id", window.localStorage.jitsiMeetId);
  29. }
  30. email = UIUtil.unescapeHtml(window.localStorage.email || '');
  31. avatarUrl = UIUtil.unescapeHtml(window.localStorage.avatarUrl || '');
  32. localFlipX = JSON.parse(window.localStorage.localFlipX || true);
  33. displayName = UIUtil.unescapeHtml(window.localStorage.displayname || '');
  34. language = window.localStorage.language;
  35. cameraDeviceId = window.localStorage.cameraDeviceId || '';
  36. micDeviceId = window.localStorage.micDeviceId || '';
  37. welcomePageDisabled = JSON.parse(
  38. window.localStorage.welcomePageDisabled || false
  39. );
  40. // Currently audio output device change is supported only in Chrome and
  41. // default output always has 'default' device ID
  42. var audioOutputDeviceId = window.localStorage.audioOutputDeviceId
  43. || 'default';
  44. if (audioOutputDeviceId !==
  45. JitsiMeetJS.mediaDevices.getAudioOutputDevice()) {
  46. JitsiMeetJS.mediaDevices.setAudioOutputDevice(audioOutputDeviceId)
  47. .catch((ex) => {
  48. console.warn('Failed to set audio output device from local ' +
  49. 'storage. Default audio output device will be used' +
  50. 'instead.', ex);
  51. });
  52. }
  53. } else {
  54. console.log("local storage is not supported");
  55. }
  56. export default {
  57. /**
  58. * Sets the local user display name and saves it to local storage
  59. *
  60. * @param {string} newDisplayName unescaped display name for the local user
  61. */
  62. setDisplayName (newDisplayName) {
  63. displayName = newDisplayName;
  64. window.localStorage.displayname = UIUtil.escapeHtml(displayName);
  65. },
  66. /**
  67. * Returns the escaped display name currently used by the user
  68. * @returns {string} currently valid user display name.
  69. */
  70. getDisplayName: function () {
  71. return displayName;
  72. },
  73. /**
  74. * Sets new email for local user and saves it to the local storage.
  75. * @param {string} newEmail new email for the local user
  76. */
  77. setEmail: function (newEmail) {
  78. email = newEmail;
  79. window.localStorage.email = UIUtil.escapeHtml(newEmail);
  80. },
  81. /**
  82. * Returns email address of the local user.
  83. * @returns {string} email
  84. */
  85. getEmail: function () {
  86. return email;
  87. },
  88. /**
  89. * Sets new avatarUrl for local user and saves it to the local storage.
  90. * @param {string} newAvatarUrl new avatarUrl for the local user
  91. */
  92. setAvatarUrl: function (newAvatarUrl) {
  93. avatarUrl = newAvatarUrl;
  94. window.localStorage.avatarUrl = UIUtil.escapeHtml(newAvatarUrl);
  95. },
  96. /**
  97. * Returns avatarUrl address of the local user.
  98. * @returns {string} avatarUrl
  99. */
  100. getAvatarUrl: function () {
  101. return avatarUrl;
  102. },
  103. getLanguage () {
  104. return language;
  105. },
  106. setLanguage: function (lang) {
  107. language = lang;
  108. window.localStorage.language = lang;
  109. },
  110. /**
  111. * Sets new flipX state of local video and saves it to the local storage.
  112. * @param {string} val flipX state of local video
  113. */
  114. setLocalFlipX: function (val) {
  115. localFlipX = val;
  116. window.localStorage.localFlipX = val;
  117. },
  118. /**
  119. * Returns flipX state of local video.
  120. * @returns {string} flipX
  121. */
  122. getLocalFlipX: function () {
  123. return localFlipX;
  124. },
  125. /**
  126. * Get device id of the camera which is currently in use.
  127. * Empty string stands for default device.
  128. * @returns {String}
  129. */
  130. getCameraDeviceId: function () {
  131. return cameraDeviceId;
  132. },
  133. /**
  134. * Set device id of the camera which is currently in use.
  135. * Empty string stands for default device.
  136. * @param {string} newId new camera device id
  137. */
  138. setCameraDeviceId: function (newId = '') {
  139. cameraDeviceId = newId;
  140. window.localStorage.cameraDeviceId = newId;
  141. },
  142. /**
  143. * Get device id of the microphone which is currently in use.
  144. * Empty string stands for default device.
  145. * @returns {String}
  146. */
  147. getMicDeviceId: function () {
  148. return micDeviceId;
  149. },
  150. /**
  151. * Set device id of the microphone which is currently in use.
  152. * Empty string stands for default device.
  153. * @param {string} newId new microphone device id
  154. */
  155. setMicDeviceId: function (newId = '') {
  156. micDeviceId = newId;
  157. window.localStorage.micDeviceId = newId;
  158. },
  159. /**
  160. * Get device id of the audio output device which is currently in use.
  161. * Empty string stands for default device.
  162. * @returns {String}
  163. */
  164. getAudioOutputDeviceId: function () {
  165. return JitsiMeetJS.mediaDevices.getAudioOutputDevice();
  166. },
  167. /**
  168. * Set device id of the audio output device which is currently in use.
  169. * Empty string stands for default device.
  170. * @param {string} newId='default' - new audio output device id
  171. * @returns {Promise}
  172. */
  173. setAudioOutputDeviceId: function (newId = 'default') {
  174. return JitsiMeetJS.mediaDevices.setAudioOutputDevice(newId)
  175. .then(() => window.localStorage.audioOutputDeviceId = newId);
  176. },
  177. /**
  178. * Check if welcome page is enabled or not.
  179. * @returns {boolean}
  180. */
  181. isWelcomePageEnabled () {
  182. return !welcomePageDisabled;
  183. },
  184. /**
  185. * Enable or disable welcome page.
  186. * @param {boolean} enabled if welcome page should be enabled or not
  187. */
  188. setWelcomePageEnabled (enabled) {
  189. welcomePageDisabled = !enabled;
  190. window.localStorage.welcomePageDisabled = welcomePageDisabled;
  191. }
  192. };