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