Bitmovin Player React Native SDK - v1.1.0
    Preparing search index...

    Interface NetworkConfig

    The network API gives the ability to influence network requests. It enables preprocessing requests and preprocessing responses.

    interface NetworkConfig {
        nativeId?: string;
        preprocessHttpRequest?: (
            type: HttpRequestType,
            request: HttpRequest,
        ) => Promise<HttpRequest>;
        preprocessHttpResponse?: (
            type: HttpRequestType,
            response: HttpResponse,
        ) => Promise<HttpResponse>;
    }

    Hierarchy

    • NativeInstanceConfig
      • NetworkConfig
    Index

    Properties

    nativeId?: string

    Optionally user-defined string id for the native instance. Used to access a certain native instance from any point in the source code then call methods/properties on it.

    When left empty, a random UUIDv4 is generated for it.

    Accessing or creating the Player with nativeId equal to my-player:

    const player = new Player({ nativeId: 'my-player' })
    player.play(); // call methods and properties...
    preprocessHttpRequest?: (
        type: HttpRequestType,
        request: HttpRequest,
    ) => Promise<HttpRequest>

    Called before an HTTP request is made. Can be used to change request parameters.

    Type declaration

      • (type: HttpRequestType, request: HttpRequest): Promise<HttpRequest>
      • Parameters

        Returns Promise<HttpRequest>

        A Promise that resolves to an HttpRequest object. - If the promise resolves, the player will use the processed request. - If the promise rejects, the player will fall back to using the original request.

     const requestCallback = (type: HttpRequestType, request: HttpRequest) => {
    // Access current properties

    console.log(JSON.stringify(type));
    console.log(JSON.stringify(request));

    // Modify the request

    request.headers['New-Header'] = 'val';
    request.method = 'GET';

    // Return the processed request via a Promise

    const processed: HttpRequest = {
    body: request.body,
    headers: request.headers,
    method: request.method,
    url: request.url,
    };
    return Promise.resolve(processed);
    };

    const player = usePlayer({
    networkConfig: {
    preprocessHttpRequest: requestCallback,
    },
    });
    preprocessHttpResponse?: (
        type: HttpRequestType,
        response: HttpResponse,
    ) => Promise<HttpResponse>

    Called before an HTTP response is accessed by the player. Can be used to access or change the response.

    Type declaration

      • (type: HttpRequestType, response: HttpResponse): Promise<HttpResponse>
      • Parameters

        Returns Promise<HttpResponse>

        A Promise that resolves to an HttpResponse object. - If the promise resolves, the player will use the processed response. - If the promise rejects, the player will fall back to using the original response.

     const responseCallback = (type: HttpRequestType, response: HttpResponse) => {
    // Access response properties

    console.log(JSON.stringify(type));
    console.log(JSON.stringify(response));

    // Modify the response

    response.headers['New-Header'] = 'val';
    response.url = response.request.url; // remove eventual redirect changes

    // Return the processed response via a Promise

    const processed: HttpResponse = {
    body: response.body,
    headers: response.headers,
    request: response.request,
    status: response.status,
    url: response.url,
    };
    return Promise.resolve(processed);
    };

    // Properly attach the callback to the config
    const player = usePlayer({
    networkConfig: {
    preprocessHttpResponse: responseCallback,
    },
    });