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

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