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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. */
  61. setDisplayName (newDisplayName) {
  62. displayName = newDisplayName;
  63. window.localStorage.displayname = UIUtil.escapeHtml(displayName);
  64. },
  65. /**
  66. * Returns the escaped display name currently used by the user
  67. * @returns {string} currently valid user display name.
  68. */
  69. getDisplayName: function () {
  70. return displayName;
  71. },
  72. /**
  73. * Sets new email for local user and saves it to the local storage.
  74. * @param {string} newEmail new email for the local user
  75. */
  76. setEmail: function (newEmail) {
  77. email = newEmail;
  78. window.localStorage.email = UIUtil.escapeHtml(newEmail);
  79. },
  80. /**
  81. * Returns email address of the local user.
  82. * @returns {string} email
  83. */
  84. getEmail: function () {
  85. return email;
  86. },
  87. /**
  88. * Sets new avatarUrl for local user and saves it to the local storage.
  89. * @param {string} newAvatarUrl new avatarUrl for the local user
  90. */
  91. setAvatarUrl: function (newAvatarUrl) {
  92. avatarUrl = newAvatarUrl;
  93. },
  94. /**
  95. * Returns avatarUrl address of the local user.
  96. * @returns {string} avatarUrl
  97. */
  98. getAvatarUrl: function () {
  99. return avatarUrl;
  100. },
  101. getLanguage () {
  102. return language;
  103. },
  104. setLanguage: function (lang) {
  105. language = lang;
  106. window.localStorage.language = lang;
  107. },
  108. /**
  109. * Sets new flipX state of local video and saves it to the local storage.
  110. * @param {string} val flipX state of local video
  111. */
  112. setLocalFlipX: function (val) {
  113. localFlipX = val;
  114. window.localStorage.localFlipX = val;
  115. },
  116. /**
  117. * Returns flipX state of local video.
  118. * @returns {string} flipX
  119. */
  120. getLocalFlipX: function () {
  121. return localFlipX;
  122. },
  123. /**
  124. * Get device id of the camera which is currently in use.
  125. * Empty string stands for default device.
  126. * @returns {String}
  127. */
  128. getCameraDeviceId: function () {
  129. return cameraDeviceId;
  130. },
  131. /**
  132. * Set device id of the camera which is currently in use.
  133. * Empty string stands for default device.
  134. * @param {string} newId new camera device id
  135. */
  136. setCameraDeviceId: function (newId = '') {
  137. cameraDeviceId = newId;
  138. window.localStorage.cameraDeviceId = newId;
  139. },
  140. /**
  141. * Get device id of the microphone which is currently in use.
  142. * Empty string stands for default device.
  143. * @returns {String}
  144. */
  145. getMicDeviceId: function () {
  146. return micDeviceId;
  147. },
  148. /**
  149. * Set device id of the microphone which is currently in use.
  150. * Empty string stands for default device.
  151. * @param {string} newId new microphone device id
  152. */
  153. setMicDeviceId: function (newId = '') {
  154. micDeviceId = newId;
  155. window.localStorage.micDeviceId = newId;
  156. },
  157. /**
  158. * Get device id of the audio output device which is currently in use.
  159. * Empty string stands for default device.
  160. * @returns {String}
  161. */
  162. getAudioOutputDeviceId: function () {
  163. return JitsiMeetJS.mediaDevices.getAudioOutputDevice();
  164. },
  165. /**
  166. * Set device id of the audio output device which is currently in use.
  167. * Empty string stands for default device.
  168. * @param {string} newId='default' - new audio output device id
  169. * @returns {Promise}
  170. */
  171. setAudioOutputDeviceId: function (newId = 'default') {
  172. return JitsiMeetJS.mediaDevices.setAudioOutputDevice(newId)
  173. .then(() => window.localStorage.audioOutputDeviceId = newId);
  174. },
  175. /**
  176. * Check if welcome page is enabled or not.
  177. * @returns {boolean}
  178. */
  179. isWelcomePageEnabled () {
  180. return !welcomePageDisabled;
  181. },
  182. /**
  183. * Enable or disable welcome page.
  184. * @param {boolean} enabled if welcome page should be enabled or not
  185. */
  186. setWelcomePageEnabled (enabled) {
  187. welcomePageDisabled = !enabled;
  188. window.localStorage.welcomePageDisabled = welcomePageDisabled;
  189. }
  190. };