Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface NetworkConfig

The network API gives the ability to influence network requests. It enables preprocessing requests, processing responses or influencing the retry behavior.

since

7.4

Hierarchy

  • NetworkConfig

Index

Properties

Optional preprocessHttpRequest

preprocessHttpRequest: function

Can be used to change request parameters before a request is made.
This will not be called before a NetworkConfig.retryHttpRequest.

Example:

network: {
  preprocessHttpRequest: function(type, request) {
    if (type === bitmovin.player.network.REQUEST_TYPE.DRM_LICENSE_WIDEVINE) {
      // withCredentials = true
      request.credentials = 'include';
      // custom headers
      request.headers.push({
      name: 'customdata',
        value: 'AUTHENTICATION-XML'
      });
    } else if (type === bitmovin.player.network.REQUEST_TYPE.MEDIA_VIDEO ||
      type === bitmovin.player.network.REQUEST_TYPE.MEDIA_AUDIO) {

      // async call of custom API and add token to media URLs
      return customApiCall.then(function(data) {
        request.url += '?token=' + data.token;
        return request;
      });
    }
    return Promise.resolve(request);
  }
}
param

String type of the request to be made.

param

Configuration object of the request.

returns

The request can be canceled with Promise.reject() or data can be retrieved asynchronously before processing the request properties.

Type declaration

Optional preprocessHttpResponse

preprocessHttpResponse: function

Can be used to the access or change properties of the response before it gets into the player.

Example:

network: {
  preprocessHttpResponse: function(type, response) {
    if (type === bitmovin.player.network.REQUEST_TYPE.DRM_LICENSE_WIDEVINE) {
      drmHeaders = response.headers;
    }
  }
}
param

String type of the request to be made.

param

Contains all important fields of the response.

returns

The response that shall go back into the player.

Type declaration

Optional retryHttpRequest

retryHttpRequest: function

Is called when a request is failed. Will override the default retry behavior.

Example:

network: {
  retryHttpRequest: function(type, response) {
    // delay the retry by 1 second
    return new Promise(function(resolve) {
      setTimeout(function() {
        resolve(response.request);
      }, 1000);
    });
  }
}
param

String type of the request to be made.

param

Response of the failed request.

param

Amount of retries

returns

The request the shall be used on the retry.

Type declaration

Optional sendHttpRequest

sendHttpRequest: function

Can be used to provide a custom implementation to download requested files. When null or undefined is returned for a certain request, the default implementation is used.

Example:

network: {
  sendHttpRequest: function(type, request) {
    return {
      getResponse: function() {
        // get data from somewhere else
        var response = {
          request: request,
          url: request.url,
          headers: [],
          status: 200,
          statusText: 'OK',
          body: 'my message',
        }
        return Promise.resolve(response);
      },
      setProgressListener: function() {},
      cancel: function() {},
    }
  }
}
param

String type of the request to be made.

param

Configuration object of the request.

returns

The custom implementation of the RequestController.

since

7.7

Type declaration

Generated using TypeDoc