connectToPort static method
- SqliteWebEndpoint endpoint, {
- Future<
JSAny?> handleCustomRequest()?,
Connects to an endpoint previously obtained with Database.additionalConnection.
As a SqliteWebEndpoint record only consists of fields that are transferrable in JavaScript, these endpoints can be sent to other workers, which can then call connectToPort to open a database connection originally established by another JavaScript connection.
Note that, depending on the access mode, the returned Database may only be valid as long as the original Database where Database.additionalConnection was called. This limitation does not exist for databases hosted by shared workers.
The optional handleCustomRequest
function is invoked when the controller
sends a custom request to the client (via ClientConnection.customRequest).
If it's absent, the default is to throw an exception when called.
Implementation
static Future<Database> connectToPort(
SqliteWebEndpoint endpoint, {
Future<JSAny?> Function(JSAny?)? handleCustomRequest,
}) {
final client = DatabaseClient(Uri.base, Uri.base,
const _DefaultDatabaseController(), handleCustomRequest);
return client.connectToExisting(endpoint);
}