Source: externs/shaka/net.js

  1. /*! @license
  2. * Shaka Player
  3. * Copyright 2016 Google LLC
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @externs
  8. */
  9. /**
  10. * @typedef {{
  11. * maxAttempts: number,
  12. * baseDelay: number,
  13. * backoffFactor: number,
  14. * fuzzFactor: number,
  15. * timeout: number,
  16. * stallTimeout: number,
  17. * connectionTimeout: number
  18. * }}
  19. *
  20. * @description
  21. * Parameters for retrying requests.
  22. *
  23. * @property {number} maxAttempts
  24. * The maximum number of times the request should be attempted.
  25. * @property {number} baseDelay
  26. * The delay before the first retry, in milliseconds.
  27. * @property {number} backoffFactor
  28. * The multiplier for successive retry delays.
  29. * @property {number} fuzzFactor
  30. * The maximum amount of fuzz to apply to each retry delay.
  31. * For example, 0.5 means "between 50% below and 50% above the retry delay."
  32. * @property {number} timeout
  33. * The request timeout, in milliseconds. Zero means "unlimited".
  34. * <i>Defaults to 30000 milliseconds.</i>
  35. * @property {number} stallTimeout
  36. * The request stall timeout, in milliseconds. Zero means "unlimited".
  37. * <i>Defaults to 5000 milliseconds.</i>
  38. * @property {number} connectionTimeout
  39. * The request connection timeout, in milliseconds. Zero means "unlimited".
  40. * <i>Defaults to 10000 milliseconds.</i>
  41. *
  42. * @tutorial network-and-buffering-config
  43. *
  44. * @exportDoc
  45. */
  46. shaka.extern.RetryParameters;
  47. /**
  48. * @typedef {{
  49. * uris: !Array.<string>,
  50. * method: string,
  51. * body: ?BufferSource,
  52. * headers: !Object.<string, string>,
  53. * allowCrossSiteCredentials: boolean,
  54. * retryParameters: !shaka.extern.RetryParameters,
  55. * licenseRequestType: ?string,
  56. * sessionId: ?string,
  57. * drmInfo: ?shaka.extern.DrmInfo,
  58. * initData: ?Uint8Array,
  59. * initDataType: ?string,
  60. * streamDataCallback: ?function(BufferSource):!Promise,
  61. * requestStartTime: (?number|undefined),
  62. * timeToFirstByte: (?number|undefined),
  63. * packetNumber: (?number|undefined),
  64. * contentType: (?string|undefined)
  65. * }}
  66. *
  67. * @description
  68. * Defines a network request. This is passed to one or more request filters
  69. * that may alter the request, then it is passed to a scheme plugin which
  70. * performs the actual operation.
  71. *
  72. * @property {!Array.<string>} uris
  73. * An array of URIs to attempt. They will be tried in the order they are
  74. * given.
  75. * @property {string} method
  76. * The HTTP method to use for the request.
  77. * @property {?BufferSource} body
  78. * The body of the request.
  79. * @property {!Object.<string, string>} headers
  80. * A mapping of headers for the request. e.g.: {'HEADER': 'VALUE'}
  81. * @property {boolean} allowCrossSiteCredentials
  82. * Make requests with credentials. This will allow cookies in cross-site
  83. * requests. See {@link https://bit.ly/CorsCred}.
  84. * @property {!shaka.extern.RetryParameters} retryParameters
  85. * An object used to define how often to make retries.
  86. * @property {?string} licenseRequestType
  87. * If this is a LICENSE request, this field contains the type of license
  88. * request it is (not the type of license). This is the |messageType| field
  89. * of the EME message. For example, this could be 'license-request' or
  90. * 'license-renewal'.
  91. * @property {?string} sessionId
  92. * If this is a LICENSE request, this field contains the session ID of the
  93. * EME session that made the request.
  94. * @property {?shaka.extern.DrmInfo} drmInfo
  95. * If this is a LICENSE request, this field contains the DRM info used to
  96. * initialize EME.
  97. * @property {?Uint8Array} initData
  98. * If this is a LICENSE request, this field contains the initData info used
  99. * to initialize EME.
  100. * @property {?string} initDataType
  101. * If this is a LICENSE request, this field contains the initDataType info
  102. * used to initialize EME.
  103. * @property {?function(BufferSource):!Promise} streamDataCallback
  104. * A callback function to handle the chunked data of the ReadableStream.
  105. * @property {(?number|undefined)} requestStartTime
  106. * The time that the request started.
  107. * @property {(?number|undefined)} timeToFirstByte
  108. * The time taken to the first byte.
  109. * @property {(?number|undefined)} packetNumber
  110. * A number representing the order the packet within the request.
  111. * @property {(?string|undefined)} contentType
  112. * Content type (e.g. 'video', 'audio' or 'text', 'image')
  113. * @exportDoc
  114. */
  115. shaka.extern.Request;
  116. /**
  117. * @typedef {{
  118. * uri: string,
  119. * originalUri: string,
  120. * data: BufferSource,
  121. * status: (number|undefined),
  122. * headers: !Object.<string, string>,
  123. * timeMs: (number|undefined),
  124. * fromCache: (boolean|undefined)
  125. * }}
  126. *
  127. * @description
  128. * Defines a response object. This includes the response data and header info.
  129. * This is given back from the scheme plugin. This is passed to a response
  130. * filter before being returned from the request call.
  131. *
  132. * @property {string} uri
  133. * The URI which was loaded. Request filters and server redirects can cause
  134. * this to be different from the original request URIs.
  135. * @property {string} originalUri
  136. * The original URI passed to the browser for networking. This is before any
  137. * redirects, but after request filters are executed.
  138. * @property {BufferSource} data
  139. * The body of the response.
  140. * @property {(number|undefined)} status
  141. * The response HTTP status code.
  142. * @property {!Object.<string, string>} headers
  143. * A map of response headers, if supported by the underlying protocol.
  144. * All keys should be lowercased.
  145. * For HTTP/HTTPS, may not be available cross-origin.
  146. * @property {(number|undefined)} timeMs
  147. * Optional. The time it took to get the response, in milliseconds. If not
  148. * given, NetworkingEngine will calculate it using Date.now.
  149. * @property {(boolean|undefined)} fromCache
  150. * Optional. If true, this response was from a cache and should be ignored
  151. * for bandwidth estimation.
  152. *
  153. * @exportDoc
  154. */
  155. shaka.extern.Response;
  156. /**
  157. * @typedef {!function(string,
  158. * shaka.extern.Request,
  159. * shaka.net.NetworkingEngine.RequestType,
  160. * shaka.extern.ProgressUpdated,
  161. * shaka.extern.HeadersReceived):
  162. * !shaka.extern.IAbortableOperation.<shaka.extern.Response>}
  163. * @description
  164. * Defines a plugin that handles a specific scheme.
  165. *
  166. * The functions accepts four parameters, uri string, request, request type,
  167. * a progressUpdated function, and a headersReceived function. The
  168. * progressUpdated and headersReceived functions can be ignored by plugins that
  169. * do not have this information, but it will always be provided by
  170. * NetworkingEngine.
  171. *
  172. * @exportDoc
  173. */
  174. shaka.extern.SchemePlugin;
  175. /**
  176. * @typedef {function(number, number, number)}
  177. *
  178. * @description
  179. * A callback function to handle progress event through networking engine in
  180. * player.
  181. * The first argument is a number for duration in milliseconds, that the request
  182. * took to complete.
  183. * The second argument is the total number of bytes downloaded during that
  184. * time.
  185. * The third argument is the number of bytes remaining to be loaded in a
  186. * segment.
  187. * @exportDoc
  188. */
  189. shaka.extern.ProgressUpdated;
  190. /**
  191. * @typedef {function(!Object.<string, string>)}
  192. *
  193. * @description
  194. * A callback function to handle headers received events through networking
  195. * engine in player.
  196. * The first argument is the headers object of the response.
  197. */
  198. shaka.extern.HeadersReceived;
  199. /**
  200. * @typedef {{
  201. * type: (shaka.net.NetworkingEngine.AdvancedRequestType|undefined),
  202. * stream: (shaka.extern.Stream|undefined),
  203. * segment: (shaka.media.SegmentReference|undefined)
  204. * }}
  205. *
  206. * @description
  207. * Defines contextual data about a request
  208. *
  209. * @property {shaka.net.NetworkingEngine.AdvancedRequestType=} type
  210. * The advanced type
  211. * @property {shaka.extern.Stream=} stream
  212. * The duration of the segment in seconds
  213. * @property {shaka.media.SegmentReference=} segment
  214. * The request's segment reference
  215. * @exportDoc
  216. */
  217. shaka.extern.RequestContext;
  218. /**
  219. * Defines a filter for requests. This filter takes the request and modifies
  220. * it before it is sent to the scheme plugin.
  221. * The RequestType describes the basic type of the request (manifest, segment,
  222. * etc). The optional RequestContext will be provided where applicable to
  223. * provide additional information about the request. A request filter can run
  224. * asynchronously by returning a promise; in this case, the request will not be
  225. * sent until the promise is resolved.
  226. *
  227. * @typedef {!function(shaka.net.NetworkingEngine.RequestType,
  228. * shaka.extern.Request,
  229. * shaka.extern.RequestContext=):
  230. * (Promise|undefined)}
  231. * @exportDoc
  232. */
  233. shaka.extern.RequestFilter;
  234. /**
  235. * Defines a filter for responses. This filter takes the response and modifies
  236. * it before it is returned.
  237. * The RequestType describes the basic type of the request (manifest, segment,
  238. * etc). The optional RequestContext will be provided where applicable to
  239. * provide additional information about the request. A response filter can run
  240. * asynchronously by returning a promise.
  241. *
  242. * @typedef {!function(shaka.net.NetworkingEngine.RequestType,
  243. * shaka.extern.Response,
  244. * shaka.extern.RequestContext=):
  245. * (Promise|undefined)}
  246. * @exportDoc
  247. */
  248. shaka.extern.ResponseFilter;