demo/full/scripts/lib/localStorage.js
/**
 * Save a new content to local storage (or just to the state if localStorage
 * is not available.
 * @param {Object} content - content to save
 * @returns {Object} - The content created
 */
Save a new content to local storage (or just to the state if localStorage
is not available.
@param {Object} content - content to save
@returns {Object} - The content created
Save a new content to local storage ( or just to the state if localStorage is not available . @param { Object } content - content to save @returns { Object } - The content created
function storeContent(content) {
  const localStorageContents = getLocalStorageContents();
  let id = content.id;
  let index;
  if (content.id != null) {
    index = localStorageContents.findIndex(e => e.id === id);
  } else {
    const lastContentID = localStorageContents.reduce((acc, val) => {
      const contentId = val.id || 0;
      return Math.max(acc, contentId);
    }, 0);
    id = lastContentID + 1;
    index = -1;
  }
  const localContent = { drmInfos: content.drmInfos,
                         fallbackKeyError: content.fallbackKeyError,
                         fallbackLicenseRequest: content.fallbackLicenseRequest,
                         id,
                         localContent: true,
                         lowLatency: content.lowLatency,
                         name: content.name,
                         transport: content.transport,
                         url: content.url };
  if (index > -1) {
    localStorageContents.splice(index, 1, localContent);
  } else {
    localStorageContents.push(localContent);
  }
  saveLocalStorageContents(localStorageContents);
  return localContent;
}
function storeContent ( content ) { const localStorageContents = getLocalStorageContents ( ) ; let id = content . id ; let index ; if ( content . id != null ) { index = localStorageContents . findIndex ( e => e . id === id ) ; } else { const lastContentID = localStorageContents . reduce ( ( acc , val ) => { const contentId = val . id || 0 ; return Math . max ( acc , contentId ) ; } , 0 ) ; id = lastContentID + 1 ; index = - 1 ; } const localContent = { drmInfos : content . drmInfos , fallbackKeyError : content . fallbackKeyError , fallbackLicenseRequest : content . fallbackLicenseRequest , id , localContent : true , lowLatency : content . lowLatency , name : content . name , transport : content . transport , url : content . url } ; if ( index > - 1 ) { localStorageContents . splice ( index , 1 , localContent ) ; } else { localStorageContents . push ( localContent ) ; } saveLocalStorageContents ( localStorageContents ) ; return localContent ; }
Save a new content to local storage (or just to the state if localStorage
 is not available.
Save a new content to local storage ( or just to the state if localStorage is not available .