Bitmovin Player API 8.268.0
    Preparing search index...

    Interface NetworkConfig

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

    7.4

    interface NetworkConfig {
        defaultRequestTimeout?: number;
        preprocessHttpRequest?: (
            type: HttpRequestType,
            request: HttpRequest,
        ) => Promise<HttpRequest>;
        preprocessHttpResponse?: <T extends HttpResponseBody>(
            type: HttpRequestType,
            response: HttpResponse<T>,
        ) => Promise<HttpResponse<T>>;
        requestApi?: NetworkRequestApi;
        requestTimeout?: Partial<Record<HttpRequestType, number>>;
        retryHttpRequest?: <T extends HttpResponseBody>(
            type: HttpRequestType,
            response: HttpResponse<T>,
            retry: number,
        ) => Promise<HttpRequest>;
        sendHttpRequest?: <T extends HttpResponseBody>(
            type: HttpRequestType,
            request: HttpRequest,
        ) => RequestController<T>;
    }
    Index
    defaultRequestTimeout?: number

    Default timeout for network requests in seconds. Can be overridden for specific request types using the requestTimeout property.

    Default: 20

    8.245.0

    preprocessHttpRequest?: (
        type: HttpRequestType,
        request: HttpRequest,
    ) => Promise<HttpRequest>

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

    Example:

    network: {
    preprocessHttpRequest: function(type, request) {
    if (type === bitmovin.player.HttpRequestType.DRM_LICENSE_WIDEVINE) {
    // withCredentials = true
    request.credentials = 'include';
    // custom headers
    request.headers['customdata'] = 'AUTHENTICATION-XML';
    } else if (type === bitmovin.player.HttpRequestType.MEDIA_VIDEO ||
    type === bitmovin.player.HttpRequestType.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);
    }
    }

    Type Declaration

    preprocessHttpResponse?: <T extends HttpResponseBody>(
        type: HttpRequestType,
        response: HttpResponse<T>,
    ) => Promise<HttpResponse<T>>

    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.HttpRequestType.DRM_LICENSE_WIDEVINE) {
    drmHeaders = response.headers;
    }
    }
    }

    Type Declaration

    requestApi?: NetworkRequestApi

    Specifies which Browser API should be used to perform network requests.

    Default is XHR.

    8.149.0

    requestTimeout?: Partial<Record<HttpRequestType, number>>

    Timeout for specific request types in seconds. Overrides the default timeout configured in defaultRequestTimeout for the given request types.

    Example:

    network: {
    requestTimeout: {
    [HttpRequestType.MANIFEST_DASH]: 10,
    [HttpRequestType.MEDIA_VIDEO]: 5,
    [HttpRequestType.MEDIA_AUDIO]: 5,
    }
    }

    8.245.0

    retryHttpRequest?: <T extends HttpResponseBody>(
        type: HttpRequestType,
        response: HttpResponse<T>,
        retry: number,
    ) => Promise<HttpRequest>

    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);
    });
    }
    }

    Type Declaration

    sendHttpRequest?: <T extends HttpResponseBody>(
        type: HttpRequestType,
        request: HttpRequest,
    ) => RequestController<T>

    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() {},
    }
    }
    }

    Type Declaration

    7.7