connectExtension function
Future<KernelClientConnection>
connectExtension(
- KernelClientHost? clientHost, {
- required String id,
- required ClientTransport transport,
Canonical way to drive the extension-transport seam off a — possibly
null, possibly non-capable — clientHost. Probes ExtensionTransportConnect
and injects transport, or throws a StateError if the host cannot.
Hosts (AppPlayer core, Studio backbone) and the extension_transport
recipe call this instead of hand-rolling the probe. The explicit cast is
required because ExtensionTransportConnect is unrelated to the declared
KernelClientHost?, so an is test does not promote the variable — a
footgun this helper hides in one place.
Implementation
Future<KernelClientConnection> connectExtension(
KernelClientHost? clientHost, {
required String id,
required ClientTransport transport,
}) async {
if (clientHost is! ExtensionTransportConnect) {
throw StateError(
'client host does not support injected extension transports '
'(not an ExtensionTransportConnect; the kernel booted without one, '
'or with a host that only drives kernel-built transports)',
);
}
return (clientHost as ExtensionTransportConnect)
.connectWith(id: id, transport: transport);
}