NetworkAPI

The NetworkAPI interface registers a callback to intercept requests. This callback receives either an intercepted request or an intercepted response as its argument. A getting started guide for the Network API can be found here.


The API contains the following property, methods and events.

 

Properties

Property Type Description
online boolean Indicates whether the stream is online

 

Methods

Method Arguments Description
addRequestInterceptor RequestInterceptor Adds a RequestInterceptor for manifests, segments etc.
removeRequestInterceptor RequestInterceptor Removes a RequestInterceptor.
addResponseInterceptor ResponseInterceptor Adds a ResponseInterceptor for manifests, segments etc.
removeResponseInterceptor ResponseInterceptor Removes a ResponseInterceptor.
addEventListener type : string, listener : EventListener Adds the listener for the given event type.
removeEventListener type : string, listener : EventListener Removes the listener for the given event type.

 

Events

Event Description
online Thrown to indicate that the stream has come back online and the player can now continue playback, usually after an 'offline' event is thrown.
offline Thrown to indicate that the stream is offline.

 

RequestInterceptor

The RequestInterceptor is a function that accepts a Request object as its argument and can return a promise. If it returns a promise then the request waits until the promise is resolved.

 

ResponseInterceptor

The ResponseInterceptor is a function that accepts a Response object as its argument and can return a promise. If it returns a promise then the response waits until the promise is resolved.

 

Request

The Request object provides the following properties and methods.

 

Properties

Property Type Description
url string Requested URL
method 'DELETE' | 'GET' | 'POST' | 'OPTIONS' | 'HEAD' | 'PUT' Request's method
headers { [headerName : string] : string } Associated headers of the request
body Blob | ArrayBuffer | ArrayBufferView | string The body of the request
closed boolean A readonly property indicating whether the request is closed. When a request is closed, any calls to redirect or respondWith will cause an error.
useCredentials boolean True if the credentials should be added to the request
type '' | 'manifest' | 'segment' Type of request
responseType 'arraybuffer' | 'blob' | 'document' | 'json' | 'text' Type of response

 

Methods

Method Arguments Description
redirect string | RequestInit Replaces the actual request with the given request. If only a string is provided then the request's URL property is modified. A RequestInit object modifies some or all of the properties of the original request. Once this method successfully executes, the request is closed and the closed property is set to true, any other calls to redirect or respondWith in the same interceptor will cause an error. Following a successful redirection the next RequestInterceptors will be executed.
respondWith ResponseInit Responds to the actual request with the given response. A ResponseInit object can be used to set a response to the request. Once this method executes with a successful response, the request is closed and the closed property is set to true, any other calls to redirect or respondWith in the same interceptor will cause an error. Following successful response the next RequestInterceptors will be executed. If the following interceptors attempts to redirect or respondWith then an error will be thrown.
waitUntil WaitUntilCallback | PromiseLike The player waits until the callback function calls the provided done callback or until the promise is resolved. This method will throw an error if a redirect or a respondWith method has already closed the request prior to a waitUntil call. Executing all the waitUntil blocks(with or without response/redirect) inside the interceptor will set the closed property to true. 

 

RequestInit

The RequestInit object can be used to create a Request object. The interface has the following properties which get default values if none are provided. 

 

Properties

Property Type Optional Description
url string  Yes Requested URL
method 'DELETE' | 'GET' | 'POST' | 'OPTIONS' | 'HEAD' | 'PUT'  Yes Request's method
headers { [headerName : string] : string }  Yes Associated headers of the request
body Blob | ArrayBuffer | ArrayBufferView | string  Yes The body of the request
useCredentials boolean  Yes True if the credentials should be added to the request
type '' | 'manifest' | 'segment'  Yes Type of request
responseType 'arraybuffer' | 'blob' | 'document' | 'json' | 'text'  Yes Type of response

 

Response

The Response object provides the following properties and methods.

 

Properties

Property Type Description
url string Responded URL
request Request Original request
headers { [headerName : string] : string } Associated headers of the response
body Blob | ArrayBuffer | ArrayBufferView | string The body of the response
closed boolean A read-only property indicating whether the response is closed. When a response is closed, any calls to respondWith will cause an error.
status number Status code of the response ( eg., 200 for a success)
statusText string Status message corresponding to the status code

 

Methods

Method Arguments Description
respondWith ResponseInit Replaces the actual response with the given response. A ResponseInit object can be used to modify the properties of the original response. Once this method executes with a successful response, the response is closed and the closed property is set to true, any other calls to respondWith in the same interceptor will cause an error. Following successful response the next ResponseInterceptors will be executed.
waitUntil WaitUntilCallback | PromiseLike The player waits until the callback function calls the provided done callback or until the promise is resolved. This method will throw an error if a respondWith method has already closed the response prior to a waitUntil call. Executing all the waitUntil blocks(with or without response) inside the interceptor will set the closed property to true. 

 

ResponseInit

The ResponseInit object can be used to create a Response object. The interface has the following properties which get default values if none are provided. 

 

Properties

Property Type Optional Description
url string  Yes Responded URL
request Request  Yes Original request
headers { [headerName : string] : string }  Yes Associated headers of the response
body Blob | ArrayBuffer | ArrayBufferView | string  Yes The body of the response
status number  Yes Status code of the response ( eg., 200 for a success)
statusText string  Yes Status message corresponding to the status code