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. * }}
  62. *
  63. * @description
  64. * Defines a network request. This is passed to one or more request filters
  65. * that may alter the request, then it is passed to a scheme plugin which
  66. * performs the actual operation.
  67. *
  68. * @property {!Array.<string>} uris
  69. * An array of URIs to attempt. They will be tried in the order they are
  70. * given.
  71. * @property {string} method
  72. * The HTTP method to use for the request.
  73. * @property {?BufferSource} body
  74. * The body of the request.
  75. * @property {!Object.<string, string>} headers
  76. * A mapping of headers for the request. e.g.: {'HEADER': 'VALUE'}
  77. * @property {boolean} allowCrossSiteCredentials
  78. * Make requests with credentials. This will allow cookies in cross-site
  79. * requests. See {@link https://bit.ly/CorsCred}.
  80. * @property {!shaka.extern.RetryParameters} retryParameters
  81. * An object used to define how often to make retries.
  82. * @property {?string} licenseRequestType
  83. * If this is a LICENSE request, this field contains the type of license
  84. * request it is (not the type of license). This is the |messageType| field
  85. * of the EME message. For example, this could be 'license-request' or
  86. * 'license-renewal'.
  87. * @property {?string} sessionId
  88. * If this is a LICENSE request, this field contains the session ID of the
  89. * EME session that made the request.
  90. * @property {?shaka.extern.DrmInfo} drmInfo
  91. * If this is a LICENSE request, this field contains the DRM info used to
  92. * initialize EME.
  93. * @property {?Uint8Array} initData
  94. * If this is a LICENSE request, this field contains the initData info used
  95. * to initialize EME.
  96. * @property {?string} initDataType
  97. * If this is a LICENSE request, this field contains the initDataType info
  98. * used to initialize EME.
  99. * @property {?function(BufferSource):!Promise} streamDataCallback
  100. * A callback function to handle the chunked data of the ReadableStream.
  101. * @exportDoc
  102. */
  103. shaka.extern.Request;
  104. /**
  105. * @typedef {{
  106. * uri: string,
  107. * data: BufferSource,
  108. * status: (number|undefined),
  109. * headers: !Object.<string, string>,
  110. * timeMs: (number|undefined),
  111. * fromCache: (boolean|undefined)
  112. * }}
  113. *
  114. * @description
  115. * Defines a response object. This includes the response data and header info.
  116. * This is given back from the scheme plugin. This is passed to a response
  117. * filter before being returned from the request call.
  118. *
  119. * @property {string} uri
  120. * The URI which was loaded. Request filters and server redirects can cause
  121. * this to be different from the original request URIs.
  122. * @property {string} originalUri
  123. * The original URI passed to the browser for networking. This is before any
  124. * redirects, but after request filters are executed.
  125. * @property {BufferSource} data
  126. * The body of the response.
  127. * @property {(number|undefined)} status
  128. * The response HTTP status code.
  129. * @property {!Object.<string, string>} headers
  130. * A map of response headers, if supported by the underlying protocol.
  131. * All keys should be lowercased.
  132. * For HTTP/HTTPS, may not be available cross-origin.
  133. * @property {(number|undefined)} timeMs
  134. * Optional. The time it took to get the response, in milliseconds. If not
  135. * given, NetworkingEngine will calculate it using Date.now.
  136. * @property {(boolean|undefined)} fromCache
  137. * Optional. If true, this response was from a cache and should be ignored
  138. * for bandwidth estimation.
  139. *
  140. * @exportDoc
  141. */
  142. shaka.extern.Response;
  143. /**
  144. * @typedef {!function(string,
  145. * shaka.extern.Request,
  146. * shaka.net.NetworkingEngine.RequestType,
  147. * shaka.extern.ProgressUpdated,
  148. * shaka.extern.HeadersReceived):
  149. * !shaka.extern.IAbortableOperation.<shaka.extern.Response>}
  150. * @description
  151. * Defines a plugin that handles a specific scheme.
  152. *
  153. * The functions accepts four parameters, uri string, request, request type,
  154. * a progressUpdated function, and a headersReceived function. The
  155. * progressUpdated and headersReceived functions can be ignored by plugins that
  156. * do not have this information, but it will always be provided by
  157. * NetworkingEngine.
  158. *
  159. * @exportDoc
  160. */
  161. shaka.extern.SchemePlugin;
  162. /**
  163. * @typedef {function(number, number, number)}
  164. *
  165. * @description
  166. * A callback function to handle progress event through networking engine in
  167. * player.
  168. * The first argument is a number for duration in milliseconds, that the request
  169. * took to complete.
  170. * The second argument is the total number of bytes downloaded during that
  171. * time.
  172. * The third argument is the number of bytes remaining to be loaded in a
  173. * segment.
  174. * @exportDoc
  175. */
  176. shaka.extern.ProgressUpdated;
  177. /**
  178. * @typedef {function(!Object.<string, string>)}
  179. *
  180. * @description
  181. * A callback function to handle headers received events through networking
  182. * engine in player.
  183. * The first argument is the headers object of the response.
  184. */
  185. shaka.extern.HeadersReceived;
  186. /**
  187. * Defines a filter for requests. This filter takes the request and modifies
  188. * it before it is sent to the scheme plugin.
  189. * A request filter can run asynchronously by returning a promise; in this case,
  190. * the request will not be sent until the promise is resolved.
  191. *
  192. * @typedef {!function(shaka.net.NetworkingEngine.RequestType,
  193. * shaka.extern.Request):
  194. (Promise|undefined)}
  195. * @exportDoc
  196. */
  197. shaka.extern.RequestFilter;
  198. /**
  199. * Defines a filter for responses. This filter takes the response and modifies
  200. * it before it is returned.
  201. * A response filter can run asynchronously by returning a promise.
  202. *
  203. * @typedef {!function(shaka.net.NetworkingEngine.RequestType,
  204. * shaka.extern.Response):
  205. (Promise|undefined)}
  206. * @exportDoc
  207. */
  208. shaka.extern.ResponseFilter;