Source: externs/shaka/net.js

  1. /**
  2. * @license
  3. * Copyright 2016 Google Inc.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /** @externs */
  18. /**
  19. * @typedef {{
  20. * maxAttempts: number,
  21. * baseDelay: number,
  22. * backoffFactor: number,
  23. * fuzzFactor: number,
  24. * timeout: number
  25. * }}
  26. *
  27. * @description
  28. * Parameters for retrying requests.
  29. *
  30. * @property {number} maxAttempts
  31. * The maximum number of times the request should be attempted.
  32. * @property {number} baseDelay
  33. * The delay before the first retry, in milliseconds.
  34. * @property {number} backoffFactor
  35. * The multiplier for successive retry delays.
  36. * @property {number} fuzzFactor
  37. * The maximum amount of fuzz to apply to each retry delay.
  38. * For example, 0.5 means "between 50% below and 50% above the retry delay."
  39. * @property {number} timeout
  40. * The request timeout, in milliseconds. Zero means "unlimited".
  41. *
  42. * @tutorial network-and-buffering-config
  43. *
  44. * @exportDoc
  45. */
  46. shakaExtern.RetryParameters;
  47. /**
  48. * @typedef {{
  49. * uris: !Array.<string>,
  50. * method: string,
  51. * body: ArrayBuffer,
  52. * headers: !Object.<string, string>,
  53. * allowCrossSiteCredentials: boolean,
  54. * retryParameters: !shakaExtern.RetryParameters
  55. * }}
  56. *
  57. * @description
  58. * Defines a network request. This is passed to one or more request filters
  59. * that may alter the request, then it is passed to a scheme plugin which
  60. * performs the actual operation.
  61. *
  62. * @property {!Array.<string>} uris
  63. * An array of URIs to attempt. They will be tried in the order they are
  64. * given.
  65. * @property {string} method
  66. * The HTTP method to use for the request.
  67. * @property {ArrayBuffer} body
  68. * The body of the request.
  69. * @property {!Object.<string, string>} headers
  70. * A mapping of headers for the request. e.g.: {'HEADER': 'VALUE'}
  71. * @property {boolean} allowCrossSiteCredentials
  72. * Make requests with credentials. This will allow cookies in cross-site
  73. * requests. See <a href="http://goo.gl/YBRKPe">http://goo.gl/YBRKPe</a>.
  74. * @property {!shakaExtern.RetryParameters} retryParameters
  75. * An object used to define how often to make retries.
  76. *
  77. * @exportDoc
  78. */
  79. shakaExtern.Request;
  80. /**
  81. * @typedef {{
  82. * uri: string,
  83. * data: ArrayBuffer,
  84. * headers: !Object.<string, string>,
  85. * timeMs: (number|undefined),
  86. * fromCache: (boolean|undefined)
  87. * }}
  88. *
  89. * @description
  90. * Defines a response object. This includes the response data and header info.
  91. * This is given back from the scheme plugin. This is passed to a response
  92. * filter before being returned from the request call.
  93. *
  94. * @property {string} uri
  95. * The URI which was loaded. Request filters and server redirects can cause
  96. * this to be different from the original request URIs.
  97. * @property {ArrayBuffer} data
  98. * The body of the response.
  99. * @property {!Object.<string, string>} headers
  100. * A map of response headers, if supported by the underlying protocol.
  101. * All keys should be lowercased.
  102. * For HTTP/HTTPS, may not be available cross-origin.
  103. * @property {(number|undefined)} timeMs
  104. * Optional. The time it took to get the response, in miliseconds. If not
  105. * given, NetworkingEngine will calculate it using Date.now.
  106. * @property {(boolean|undefined)} fromCache
  107. * Optional. If true, this response was from a cache and should be ignored
  108. * for bandwidth estimation.
  109. *
  110. * @exportDoc
  111. */
  112. shakaExtern.Response;
  113. /**
  114. * Defines a plugin that handles a specific scheme.
  115. *
  116. * @typedef {!function(string,
  117. * shakaExtern.Request,
  118. * shaka.net.NetworkingEngine.RequestType):
  119. * !Promise.<shakaExtern.Response>}
  120. * @exportDoc
  121. */
  122. shakaExtern.SchemePlugin;
  123. /**
  124. * Defines a filter for requests. This filter takes the request and modifies
  125. * it before it is sent to the scheme plugin.
  126. * A request filter can run asynchronously by returning a promise; in this case,
  127. * the request will not be sent until the promise is resolved.
  128. *
  129. * @typedef {!function(shaka.net.NetworkingEngine.RequestType,
  130. * shakaExtern.Request):
  131. (Promise|undefined)}
  132. * @exportDoc
  133. */
  134. shakaExtern.RequestFilter;
  135. /**
  136. * Defines a filter for responses. This filter takes the response and modifies
  137. * it before it is returned.
  138. * A response filter can run asynchronously by returning a promise.
  139. *
  140. * @typedef {!function(shaka.net.NetworkingEngine.RequestType,
  141. * shakaExtern.Response):
  142. (Promise|undefined)}
  143. * @exportDoc
  144. */
  145. shakaExtern.ResponseFilter;