Skip to content

JS integration lib

The purpose of this document is to show you how to add peach-user.js and use it in order to access the user service suite.

How it works

First we have to load the peach-user.js main script, located here.

This step provides the _pu javascript object that has all the needed functions for initialisation, api access and redirects to the identity provider.

Integrate Peach User Suite Library

function PeachUserLoaded() {
    var _pu = window._pu = new PeachUser(window);

    _pu.init({
        idp_url: 'https://peach-staging.ebu.io/idp',
        api_url: 'https://peach-staging.ebu.io/api'
    })
}

(function (j, c) {
    var s = function (o) {
        var t = document.createElement('script');
        for (var p in o) {t[p] = o[p];};
        return t;
    };
    var p = s({src: j, defer: true, async: true, onload: c});
    var i = document.getElementsByTagName('script')[0];
    i.parentNode.insertBefore(p, i);
})('//peach-static.ebu.io/peach-user.min.js', PeachUserLoaded);

Use the library

Accessing the identity provider (idp)

// Redirects to the idp that handles the ui

_pu.idp(redirect = window.location.href) // redirects to idp login adds referrer
_pu.signup(redirect = window.location.href) // redirects to idp signup adds referrer

// Promises.then(c => console.log(c)).catch(e => console.log(e))

_pu.login(USER_NAME, PASSWORD)
_pu.isAuthorized() // adds JWT token to session storage
_pu.logout() // removes JWT token from session storage
_pu.basicAuth(USER_NAME, PASSWORD) // sets idp cookie 

User profile

_pu.getSessionProfile() // returns the idps user information
_pu.getCombinedSessionAndPreferenceProfile(key = profile_preference_key) // Combines the idps user information with an extension that is stored in dedicated preferences field 
_pu.setCombinedSessionAndPreferenceProfile(key = profile_preference_key, data = {}) // Stores user data in preferences

Playlists and bookmarks

_pu.getPlaylists(playlistId = null)
_pu.createPlaylist(playlistName, itemId = null)
_pu.deletePlaylists(playlistId = null)   // WARNING: playlistId=null deletes all playlists
_pu.getBookmarks(playlistId = null)
_pu.addBookmarkToPlaylist(playlistId, bookmarkId = null) // bookmarkId = null generates a fake uuid
_pu.deleteBookmark(playlistId, bookmarkId)

Media history

_pu.getHistory(limit = 10)
_pu.deleteHistory()
_pu.updateMediaPlaybackPosition(deviceId, mediaId, playbackPosition)
_pu.getMediaPlaybackPositions(mediaIds = [])
_pu.deleteMediaHistory(mediaId)

Preferences

_pu.getPreferences(key = null, path = null)
_pu.setPreferences(key, payload)
_pu.replacePreferences(key, path, payload)
_pu.deletePreferences(key, path = null)