npm package: @meisterplayer/plugin-bitmovin
Description: Meister plugin as a wrapper around Bitmovin
Author: Triple
Latest version: 5.2.2

Bitmovin plugin for meister
===========

This plugin allows using the Bitmovin player as a media plugin for Meister.

Installation
-----

You can install this plugin through npm:

```
npm install @meisterplayer/plugin-bitmovin
```

and importing it

``` JavaScript
import Meister from 'meisterplayer';
import Bitmovin from '@meisterplayer/plugin-bitmovin'
```

Getting started
-----------

Load the plugin by adding a `bitmovin` configuration object to the Meister initialisation options. You'll have to provide the license key in the top level config, any other Bitmovin config items you can pass through the `bmConfig` object.

Example:

``` JavaScript
var meisterPlayer = new Meister('#player', {
    bitmovin: {
        key: 'YOUR_KEY_HERE'
    }
});

meisterPlayer.setItem({
    src: 'https://example.com/secure/stream/manifest.mpd',
    type: 'mpd',
});

meisterPlayer.load();

```

### Configuration ###

Options are required unless marked as [optional].

* **key** :: *string*  
    Your Bitmovin license key.
* [optional] **analyticsKey** :: *string*  
    Your Bitmovin analytics license key.
* [optional] **dvrThreshold** :: *Number*  
    Content with a window longer than this threshold is considered as having a DVR window. This is measured in seconds. Defaults to 300 (5 minutes).
* [optional] **bmConfig** :: *Object*  
    Through this option it is possible to set default values in the Bitmovin player configuration. This object is directly passed to the Player constructor when instantiating the Bitmovin player. These options can be overridden on a per item basis by setting a `bmConfig` property on the item. See the [docs](https://bitmovin.com/docs/player/api-reference/web/web-sdk-api-reference-v8#/player/web/8/docs/modules/core_config.html) for information on the configuration object.  
    ```JavaScript
    var meisterPlayer = new Meister('#player', {
        bitmovin: {
            key: 'YOUR_KEY_HERE',
            bmConfig: {
                tweaks: {
                    startup_threshold?: 5;
                },
            }
        },
    });
    ```

Item options
------------

The following options can be added per item

### startFromLive *[Boolean]* (default: false) ###

Start from the live edge this will bring the player as close as possible to the live edge.

``` JavaScript
meisterPlayer.setItem({
    src: 'https://example.com/secure/stream/manifest.mpd',
    startFromLive: true,
    type: 'mpd'
});
```

### startFromBeginning *[Boolean|Object]* (default: false) ###

Start from the beginning of the live stream. (VOD streams will always begin from the beginning).

``` JavaScript
meisterPlayer.setItem({
    src: 'https://example.com/secure/stream/manifest.mpd',
    startFromBeginning: true,
    type: 'mpd'
});
```

Or you can give an object with an offset to start from a offset

``` JavaScript
meisterPlayer.setItem({
    src: 'https://example.com/secure/stream/manifest.mpd',
    startFromBeginning: {
        offset: 10, // Start from the "beginning" with an offset of 10 seconds
    },
    type: 'mpd'
});
```

### bmConfig *[Object]* (default: {}) ###

Through this option it is possible to set override default values in the Bitmovin player configuration on a per item basis. This object is directly passed to the Player constructor when instantiating the Bitmovin player. See the [docs](https://bitmovin.com/docs/player/api-reference/web/web-sdk-api-reference-v8#/player/web/8/docs/modules/core_config.html) for information on the configuration object.  
```JavaScript
meisterPlayer.setItem({
    src: 'https://example.com/secure/stream/manifest.mpd',
    bmConfig: {
        tweaks: {
            startup_threshold?: 5;
        },
    },
    type: 'mpd'
});
```

### prepareMessage *function* (default: null) ###

While using Bitmovin for playback of DRM encrypted content there are extra fields you can add to the Widevine and FairPlay configs of the drmConfig object. The `prepareMessage` field allow modifications to license request sent from the client. See the Bitmovin [Widevine docs](https://cdn.bitmovin.com/player/web/8/docs/interfaces/drm.widevinemodulardrmconfig.html#preparemessage) or [FairPlay docs](https://cdn.bitmovin.com/player/web/8/docs/interfaces/drm.applefairplaydrmconfig.html#preparemessage) for more details.
```JavaScript
meisterPlayer.setItem({
    src: 'https://example.com/secure/stream/manifest.mpd',
    drmConfig: {
        widevine: {
            prepareMessage: (keyMessage) => {
                return keyMessage.message;
            },
        },
        fairplay: {
            prepareMessage: (event, session) => {
                return event.messageBase64Encoded;
            },
        },
    }
    type: 'mpd'
});
```

### prepareLicense *function* (default: null) ###

The `prepareLicense` field allow modifications to license response before passing it to the CDM. See the Bitmovin [Widevine docs](https://cdn.bitmovin.com/player/web/8/docs/interfaces/drm.widevinemodulardrmconfig.html#preparelicense) or [FairPlay docs](https://cdn.bitmovin.com/player/web/8/docs/interfaces/drm.applefairplaydrmconfig.html#preparelicense) for more details.
```JavaScript
meisterPlayer.setItem({
    src: 'https://example.com/secure/stream/manifest.mpd',
    drmConfig: {
        widevine: {
            prepareLicense: (response) => {
                return new Uint8Array(response.license);
            },
        },
        fairplay: {
            prepareLicense: (response) => {
                return new Uint8Array(response.license);
            },
        },
    }
    type: 'mpd'
});
```