NetworkAPI

The NetworkAPI interface registers a callback to intercept requests. This callback receives either an intercepted request or an intercepted response as its argument.
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 Allows you to add request interceptors for manifests, segments etc. The RequestInterceptor function accepts a Request object as its argument.
removeRequestInterceptor RequestInterceptor Allows you to remove request interceptors.The RequestInterceptor is a function which accepts a Request object as its argument.
addResponseInterceptor ResponseInterceptor Allows you to add response interceptors for manifests, segments etc.The ResponseInterceptor is a function which accepts a Request or a Response object as its argument.
removeResponseInterceptor ResponseInterceptor Allows you to remove response interceptors. The ResponseInterceptor is a function which accepts a Request or a Response object as its argument.
addEventListener type : string, listener : EventListener Adds the given listener to the player instance for the given event type.
removeEventListener type : string, listener : EventListener Removes the given listener to the player instance 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.

 

Request

The Request object provides the following properties and methods for defining a request object as an argument for the RequestInterceptor.

 

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
useCredentials boolean  If the request contains any credentials
type '' | 'manifest' | 'segment'  Type of request
responseType 'arraybuffer' | 'blob' | 'document' | 'json' | 'text'  Type of response
timeout number  A timeout value for the request

 

Methods

Method Arguments Description
redirect string OR RequestInit Allows to replace the actual request with the given request. If the request's url property needs to be modified then this can be specified as a string. A RequestInit object can be used to modify all the properties of the original request.
respondWith ResponseInit Allows to replace the actual request's response with the given response. A ResponseInit object can be used to modify the properties of the original response.

 

RequestInit

A RequestInit interface has the following properties.

 

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  If the request contains any credentials
type '' | 'manifest' | 'segment'  Yes  Type of request
responseType 'arraybuffer' | 'blob' | 'document' | 'json' | 'text'  Yes  Type of response
timeout number  Yes  A timeout value for the request

 

Response

The Response object provides the following properties and methods for defining a response object as an argument for the ResponseInterceptor.

 

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
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 Allows to replace the actual request's response with the given response. A ResponseInit object can be used to modify the properties of the original response.

 

ResponseInit

A ResponseInit interface has the following properties.

 

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