VideoCacheServer class

This plugin starts a local HttpServer, handles requests with particular urls:

video_url => http://localhost:${proxyServerPort}?url=${Uri.encodeComponent(video_url)}

and saves the response data to cacheDir.

For m3u8 file requests, the media urls in m3u8 files are replaced by the proxy ones. A living m3u8 is ignored(does not contain a #EXT-X-ENDLIST). See postRemoteRequestHandler and

See the sample codes for detail usage.

Constructors

VideoCacheServer.new({String? address, int? port, required String cacheDir, HttpClient? httpClient, bool lazy = true, SecurityContext? securityContext, int? backlog, bool? shared, BadCertificateCallback? badCertificateCallback, PassThrough? passThrough = passThroughForMp4TrailingMetadataRequest, PostRemoteRequestHandler? postRemoteRequestHandler = handleM3u8})
Instantiate a VideoCacheServer that listens on the specified address and port.

Properties

address InternetAddress?
The InternetAddress the cache server is listening on, return null if the server is not started.
no setter
backlog int?
This field is passed to HttpServer.bind transparently, see the doc of that method for more information.
final
badCertificateCallback BadCertificateCallback?
final
cacheFileIndex int
getter/setter pair
caches Map<String, CacheInfo>
no setter
hashCode int
The hash code for this object.
no setterinherited
lazy bool
final
passThrough PassThrough?
Provide a tester to pass through the request, executed before cache is checked.
final
port int?
The port number the cache server is listening on, return null if the server is not started.
no setter
postRemoteRequestHandler PostRemoteRequestHandler?
A handler executed immediately after the request to remote returned. The default one is handleM3u8
final
quiet bool
getter/setter pair
requestHeaderInterceptor RequestHeaderInterceptor?
Provide a way to modify the request headers
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
securityContext SecurityContext?
This field is passed to HttpServer.bind transparently, see the doc of that method for more information.
final
server HttpServer?
Get the running HttpServer
no setter
shared bool?
This field is passed to HttpServer.bind transparently, see the doc of that method for more information.
final
started bool
no setter

Methods

clear() Future<void>
Clears the held cache info and the cache files.
getProxyUrl(String raw, [Map<String, String>? extraQueries]) String
Gets a proxy url for raw which will be handled by the cache server.
handleRequest(HttpRequest request) Future<void>
isCached(String url) bool
Queries if any data associated with url is cached.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
start() Future<VideoCacheServer>
Starts the cache server and returns the VideoCacheServer instance.
stop(String? realUrl) → void
Stops the cache server.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

handleM3u8(Uri uri, IOStreamedResponse remoteResponse, HttpResponse response, VideoCacheServer server, String? owner) Future<bool>
Intercept and proxy m3u8 content.
passThroughForMp4TrailingMetadataRequest(ProxyRequest serverRequest, CacheInfo? cacheInfo) bool
Pass through the request for fetching mp4 metadata, this is usually happened when the player detected that the metadata is at the end of the mp4 file.