eventsApp - Events API

description

Register additional users, after initialisation, to subscribe or publish to.

arguments userHashes (Object). Object similar to the config.users initialisation option.

returns -

addUsers example

    document.getElementById('addUsers').onclick = function () {

        var user_hashes = {
          '5fb6d972-157b-4e25-b449-85e58089e714': '9bcffb8898d59fc3f3e425faa1041bf6b8f8950997cbb9cc37d576368be5d341'
        };

        eventsApp.addUsers(user_hashes);
    };
description

Set event handler callback for certain events

callback is called with an array of events.

arguments

events (Array). An array of objects describing the events to subscribe to. Required properties for each event object are user_id and kind. Optionally, activity_id can be passed to filter events by Activity ID.

callback (Function)

returns -

on example

    document.getElementById('onButton').onclick = function () {

        var eventHandler = function (events) {
            console.log(events);

            /* Example:
            [
                {
                    "id": "ac478bc1-2e0e-44c1-a19c-6cb065f06bad",
                    "timestamp": "2014-10-08T00:51:28.808Z",
                    "actor": {
                        "account": {
                            "homePage": "yis0TYCu7U9V4o7M",
                            "name": "jessepinkman"
                        },
                        "objectType": "Agent"
                    },
                    "verb": {
                        "id": "http://adlnet.gov/expapi/verbs/progressed",
                        "display": {
                            "en-US": "progressed"
                        }
                    },
                    "object": {
                        "id": "https://xapi.learnosity.com/activities/org/1/pool/null/activity/demoactivity",
                        "definition": {
                            "extensions": {
                                "data": 1
                            }
                        },
                        "objectType": "Activity"
                    }
                }
            ]
            */
        };

        eventsApp.on(events, eventHandler);
    };
description

Publish raw or valid XAPI compliant events through Events App.

arguments

object (Object). Parameters are xapi - whether the objects are XAPI-compliant, and events, an array of event objects to publish. Every event must have a kind property.

returns

-

publish example

    document.getElementById('publishButton').onclick = function () {

            eventsApp.publish({
                "xapi": false,  // whether it's a full(or raw) xAPI events array, true | false (default)
                "events": [{
                    "kind": "assess_logging",
                    "actor": "jessepinkman",  // string, user_id
                    "verb": "progressed", // string, verb
                    "object": {  // string (unique "id") or object (full object)
                        "id": "https://xapi.learnosity.com/activities/org/1/pool/null/activity/demoactivity",
                        "definition": {
                            "extensions": {
                                "data": 1
                            }
                        }
                    }
                }]
            })

    };
description

Reset the Events App - stop subscribing to events, return any unpublished events.

arguments

-

returns

events (Array). An array of events that had been passed to publish() but not yet actually published, due to batching or errors requiring retry.

reset example

    document.getElementById('resetButton').onclick = function () {
            eventsApp.reset();
    };
    </script>
    </body>
</html>
Was this article helpful?

Did you arrive here by accident? If so, learn more about Learnosity.