Main class, handles tasks that are required for all instances such as bandwidth checking and loading of plugins

Methods

checkBandwidth()

Item Value
Scope public
Returns Akita

This will perform a bandwidth test. Fires a bandwidthCheckComplete event


error(message, data)

Item Value
Scope public
Returns Akita

Parameters

Parameter Description
String message A short message describing the error
Akita.player instance Needs to contain the config for the instance that threw the error

A custom Error class that will ensure that errors are logged

throw new Akita.error('missing parameter', {
    config: this.di.config
});

initPlugins(plugins, instance, di)

Item Value
Scope private
Returns Akita

Parameters

Parameter Description
Array plugins An array of plugins to initialise
Akita.player instance A reference to the instance you want to initialise plugins on
Object di The DI object containing the dependencies for a plugin

This initialises plugins on a player.

Akita.initPlugins(['myPlugin'],Akita.playerInstances['instanceId'], {config:{},eventEmitter:{}});

log(message, level, data)

Item Value
Scope public
Returns Akita

Parameters

Parameter Description
String message A short message describing the error/warning
String level The error level can be exception|error|warn|info|log
Object data Any extra data you want to log

A custom Error class that will ensure that errors are logged.

Akita.log('Value updated as expected', 'info', {
    config: this.di.config,
    oldValue: 10,
    newValue: 200
});

registerPlayerInstance(instanceId, instance)

Item Value
Scope private
Returns Akita

Parameters

Parameter Description
String instanceId A unique string to reference a player instance with
Akita.player instance The player instance itself

This will register your player instance so you can reference it later using Akita.playerInstances


registerPlugin(pluginName, plugin)

Item Value
Scope private
Returns Akita

Parameters

Parameter Description
String pluginName A name for your plugin
Function plugin A self executing function that contains your plugin logic

This allows you to register a plugin which can then be loaded by a player instance. The passed in function requires a di parameter.
di is an object which gives you access to the instance eventEmitter and config. You will need to call initPlugin to initialise the plugin within a player instance

Akita.registerPlugin('myPlugin',(function(di){

    this.config = di.config;
    this.eventEmitter = di.eventEmitter;

    this.eventEmitter.on('ended', function(event){
        // do something on ended event
    });

})());

Properties

clientBandwidth

Item Value
Scope public
Returns Number

available bandwidth in kbps


bitrate

Item Value
Scope public
Returns Int

most appropriate bitrate (kbps) selected by us dependant on client bandwidth


device

Item Value
Scope public
Returns Object

Information about the clients device

{
    name:'iPhone',
    browser: 'Mobile Safari',
    version: '6'
}

eventEmitter

Item Value
Scope public
Returns EventEmitter

This is what you will listen/emit events on.


playerInstances

Item Value
Scope public
Returns Array

An array of player instances that have been registered on the page


plugins

Item Value
Scope public
Returns Array

An array of plugins that have been registered and can be loaded into an instance


userAgent

Item Value
Scope public
Returns String

The clients user agent


endpoint

Item Value
Scope public
Returns Object

The endpoints to use

{
    api: 'https://api.buto.tv',
    ...
}

loggedEvents

Item Value
Scope public
Returns Object

All events that have been logged by the player. Used for debugging


Events

bandwidthCheckComplete

Fired on bandwidth test complete. Returns the available bandwidth in kbps and the ideal bitrate

{
    availableBandwidth: 10235,
    idealBitrate: 3500
}

logComplete

Fired when something is logged using (Akita.log)[#log(message,level, data)]

{
    data: {
        message: 'too many attempts',
        level: 'warn',
        data: {},
        timestamp: 123424546
    }
}

Custom plugins

You can add your own custom plugins to Akita. This can be achieved by creating an AkitaCustomPlugins object, containing the plugins before the embed code.

When Akita instantiates a new player it will automatically load in any custom plugins. Dependencies such as the instances config and event emitter will be passed in via the di param

N.B. Custom plugins will be applied to all instances of the player on the page

Dependency Injection

The player instance will inject a DI container object into the plugin

{
    config: {},
    eventEmitter: EventEmitter()
}

AkitaCustomPlugins

This must fire two events at least. PluginInitialised and PluginReady prefixed with the name of the plugin.

Plugin Initialised is when all properties / methods are declared. The player will wait until all plugins are initialised before continuing

Plugin Ready is when the plugin is ready to interact with


var AkitaCustomPlugins = {}; AkitaCustomPlugins['custom'] = (function(di){ // The di param is an object which passes in the dependencies this.config = di.config; this.eventEmitter = di.eventEmitter; //plugin initialised this.di.eventEmitter.emit('customPluginInitialised', event_data); //make async call to fetch data required for plugin var request = new XMLHttpRequest(); request.open('GET', '/my/url', true); request.onload = function() { if (request.status >= 200 && request.status < 400){ // Success! data = JSON.parse(request.responseText); var event_data = { data: { plugin_name: 'custom' } }; //plugin ready this.di.eventEmitter.emit('customPluginReady', event_data); } else { // We reached our target server, but it returned an error } }; request.onerror = function() { // There was a connection error of some sort }; request.send(); return this; });