project

The project plugin exposes APIs that allow developers to get info about the current project, get a list of associated projects and navigate to another project.

Example

function getRandomHeadNode() {
    // Get the project's metadata which is an object that may contain any arbitrary data.
    let projectMetadata = player.project.current.metadata;

    // In this example, a "headNodes" array (that contains node IDs of potential head nodes)
    // has been added to the project's metadata.
    let headNodes = projectMetadata.headNodes;

    return headNodes[Math.floor(Math.random()*headNodes.length)];
}

Properties

player.project.current : Project
propertyreadonly

The current project’s info.

Example

console.log('The current project ID is:', player.project.current.id);
console.log('The current project revision is:', player.project.current.revision);
console.log('The current project latest revision is:', player.project.current.latestRevision);

player.project.version : string
propertyreadonly

The project plugin’s version string.

Example

console.log('The project plugin version is', player.project.version);

Methods

player.project.getList() ⇒ Promise.<ProjectList>
method

Get this project’s ProjectList.
The returned object contains a list of projects (an ordered Eko playlist as defined on Eko’s CMS) that are associated with the current project.
Note that the returned list may be empty if the project is not being served from within the context of an Eko playlist.

Returns: Promise.<ProjectList> - A Promise which resolves with a ProjectList object.
Example

// Get the project-list
player.project.getList()
    .then((projectList) => {
        // Find the first project in the list that has a "level"
        // metadata property with a value of "medium"
        let nextProject = projectList.projects
            .filter((proj) => proj.metadata.level === "medium")[0];

        // If such a project was found, navigate to it
        if (nextProject) {
            player.project.navigateTo(nextProject.id);
        }
    });

player.project.getNext() ⇒ Promise.<Project>
method

Get the next project.
This is the project that by default will be navigated to next, once this project ends.

Returns: Promise.<Project> - A Promise which resolves with a Project object.
Example

// Get the next project object
this.getNext()
    .then((nextProject) => {
        // If exists, navigate to it
        if (nextProject) {
            player.project.navigateTo(nextProject.id);
        }
    });

player.project.navigateTo(projectId, [options])
method

Navigate to another project.

Param Type Description
projectId string The project ID to navigate to.
[options] object Optional. An options object.
[options.target] string Target attribute, the 2nd argument of the window.open() method. Default: "_self".
[options.queryParams] object An object with any additional query params to include when navigating to the next project.

Example

// Navigate to project with ID "aBcD5"
// and use the query string param "headnodeid=node_coolio"
player.project.navigateTo('aBcD5', {
    queryParams: {
        headnodeid: 'node_coolio'
    }
});

Objects

Project : object
property

An object that contains information about a project.

Example

{
    // String. The unique identifier of the project.
    id: 'aBcD5'

    // Object. Contains any arbitrary metadata attached to this project.
    metadata: {
        ...
    }
}

ProjectList : object
property

An object that contains information about a list of associated projects.

Example

{
    // String. The unique identifier of the project-list.
    id: 'eFgH6'

    // Object. Contains any arbitrary metadata attached to this project-list.
    metadata: {
        ...
    },

    // An array of Project objects.
    // This is an ordered *Eko playlist* as defined on Eko's CMS.
    projects: [
        {
            id: 'aBcD5',
            metadata: { ... }
        },
        ...
    ]
}
Rate this page: X
Tell us more!