public interface HttpServer
The role of the server is to deliver protected contents in streaming mode. It makes sense when the source media file is encrypted and a storage in decrypted form is not admitted, even temporary for the playing duration. If there is no cryptographic nor any other content processing, then giving directly the file path to the player would be just enough.
The encrypted resource can be sourced locally from:
Environment.getExternalStorageDirectory()
.zip
file.obb
APK Expansion Zip fileOr remotely from:
Permissions
A server requires the INTERNET
permission.
Note that even if no outgoing connection is ever made, the permission is needed to act as a server.
Modifier and Type | Interface and Description |
---|---|
static interface |
HttpServer.JsInterface
Interface for a Java object accessible from JavaScript in a WebView.
|
Modifier and Type | Method and Description |
---|---|
HttpServer.JsInterface |
getJsInterfaceObject()
Returns a Java object for injection into a WebView.
|
String |
getURL(DocumentFile docFile)
Returns the URL to serve a resource managed by a document provider.
|
String |
getURL(int mainVersion,
int patchVersion,
String entryPath)
Returns the URL to serve a resource embedded into APK Expansion Zip files.
|
String |
getURL(String path)
Returns the URL to serve a resource specified by the provided path.
|
String |
getURL(String zipPath,
String entryPath)
Returns the URL to serve a resource embedded into a Zip file.
|
HttpServer |
setCipher(Cipher cipher)
Sets the Cipher for decryption.
|
HttpServer |
setCipherFactory(CipherFactory cipherFactory)
Sets a cipher factory for decryption.
|
HttpServer |
setDataSource(DataSource dataSource)
Sets a custom data provider.
|
void |
start()
Starts the server.
|
void |
stop()
Stops the server.
|
String getURL(String path)
For example: http://127.0.0.1:54123/path/to/a/file.ext
The path parameter supports various meanings:
path
- The path of a resource.null
if the server is not initialized or a necessary library is missing.String getURL(DocumentFile docFile)
docFile
- The document to target.null
if the server is not initialized.String getURL(String zipPath, String entryPath)
zipPath
- The path of the Zip file.entryPath
- The path to the desired file, relative to the root of the ZIP file contents.null
if the server is not initialized or the zipfile library is missing.String getURL(int mainVersion, int patchVersion, String entryPath)
mainVersion
- The parameter defined for getAPKExpansionZipFile() in the APK Expansion Zip Library.patchVersion
- The parameter defined for getAPKExpansionZipFile() in the APK Expansion Zip Library.entryPath
- The path to the desired file, relative to the root of the ZIP file contents.null
if the server is not initialized or the zipfile library is missing.HttpServer.JsInterface getJsInterfaceObject()
Example: webview.addJavascriptInterface(mServer.getJsInterfaceObject(), "serverObject");
HttpServer setDataSource(DataSource dataSource)
This is an option, as there is already a default data provider instance, able to deal with files of various kind (regular, zip, expansion, asset, SMB, remote, ...). Note that this default instance is lost once you give your own.
dataSource
- A data provider. Cannot be null
.HttpServer setCipher(Cipher cipher)
This is an option, by default there is no cryptographic processing.
The object is immediately forwarded to the current data provider,
so if you intend to use a custom data provider,
you must set it before with setDataSource()
.
Alternatively, you may use setCipherFactory(CipherFactory)
.
In case you use both, this method has precedence over CipherFactory.getCipher()
.
But this is not a recommended design: a better approach is to group all cipher related actions
at the same place.
cipher
- The cipher for decrypting the resource,
or null
to deactivate the cryptographic processing.HttpServer setCipherFactory(CipherFactory cipherFactory)
This is an option, by default there is no cryptographic processing.
The object is immediately forwarded to the current data provider,
so if you intend to use a custom data provider,
you must set it before with setDataSource()
.
Alternatively, you may use setCipher(Cipher)
.
cipherFactory
- The instance to generate ciphers on demand,
or null
to deactivate the cryptographic processing.void start()
Once started, use stop()
to stop a running server.
A stopped server cannot be started again, instead create another one.
void stop()
Stopping a server that is not started is illegal but has no penalty.
The server should be either waiting for the next request from its connected client, either waiting for a client to connect. Anyway, and even if there is a transmission in progress, all sockets are immediately closed.