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.

JitsiLocalStorage.js 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /**
  2. * Dummy implementation of Storage interface with empty methods.
  3. */
  4. class DummyLocalStorage {
  5. /**
  6. * Empty function
  7. */
  8. getItem() { }
  9. /**
  10. * Empty function
  11. */
  12. setItem() { }
  13. /**
  14. * Empty function
  15. */
  16. removeItem() { }
  17. }
  18. /**
  19. * Wrapper class for browser's local storage object.
  20. */
  21. class JitsiLocalStorage extends DummyLocalStorage {
  22. /**
  23. * @constructor
  24. * @param {Storage} storage browser's local storage object.
  25. */
  26. constructor(storage) {
  27. super();
  28. this.storage = storage || new DummyLocalStorage();
  29. }
  30. /**
  31. * Returns that passed key's value.
  32. * @param {string} keyName the name of the key you want to retrieve
  33. * the value of.
  34. * @returns {String|null} the value of the key. If the key does not exist,
  35. * null is returned.
  36. */
  37. getItem(keyName) {
  38. return this.storage.getItem(keyName);
  39. }
  40. /**
  41. * Adds a key to the storage, or update key's value if it already exists.
  42. * @param {string} keyName the name of the key you want to create/update.
  43. * @param {string} keyValue the value you want to give the key you are
  44. * creating/updating.
  45. */
  46. setItem(keyName, keyValue) {
  47. return this.storage.setItem(keyName, keyValue);
  48. }
  49. /**
  50. * Remove a key from the storage.
  51. * @param {string} keyName the name of the key you want to remove.
  52. */
  53. removeItem(keyName) {
  54. return this.storage.removeItem(keyName);
  55. }
  56. }
  57. export default new JitsiLocalStorage(window.localStorage);