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.

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