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.

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