VideoCacheServer constructor

VideoCacheServer({
  1. String? address,
  2. int? port,
  3. required String cacheDir,
  4. HttpClient? httpClient,
  5. bool lazy = true,
  6. SecurityContext? securityContext,
  7. int? backlog,
  8. bool? shared,
  9. BadCertificateCallback? badCertificateCallback,
  10. PassThrough? passThrough = passThroughForMp4TrailingMetadataRequest,
  11. PostRemoteRequestHandler? postRemoteRequestHandler = handleM3u8,
})

Instantiate a VideoCacheServer that listens on the specified address and port.

If address is not provided, localhost will be used.

A random free port will be picked if port is not specified.

cacheDir is the directory for storing cache data, default to ${AppTemporaryDirectory}/video_cache_server/.

You can provide a httpClient to customize the HttpClient, and the cache server will set autoUncompress to false to let the response consumer do the uncompressing work.

To prevent unnecessary traffic usage, the cache server responds to the pause/resume signal from the consumer(eg:A media player's buffering strategy). Set lazy to false if you want to cache complete data whenever perform a request regardless of traffic.

The cache server doesn't provide an in-box persistence functionality since caching multiple video data is usually not necessary.

You can implement one by yourself if needed. See local file restoring test case in unit tests for more information. But you need to manage the lifecycle of the cached data by yourself.

Provide a tester to passThrough particular requests.

If the badCertificateCallback is not provided, a all-pass-through one will be used.

The securityContext, backlog and shared arguments is transparently passed to the HttpServer.bind, please read doc of that method for more information.

Implementation

VideoCacheServer({
  String? address,
  int? port,
  required String cacheDir,
  HttpClient? httpClient,
  this.lazy = true,
  this.securityContext,
  this.backlog,
  this.shared,
  this.badCertificateCallback,
  this.passThrough = passThroughForMp4TrailingMetadataRequest,
  this.postRemoteRequestHandler = handleM3u8,
})  : _address = address ?? 'localhost',
      _port = port ?? 0,
      _cacheDir = cacheDir,
      _cacheInfoFile = '$cacheDir/cache_info.json',
    _httpClient = httpClient;