IntentCallFlutterHost.bindRegistry constructor

IntentCallFlutterHost.bindRegistry({
  1. required AgentRegistry registry,
  2. IntentCallAuthorizationPolicy policy = const IntentCallAuthorizationPolicy.denyAll(),
  3. bool registerWebMcp = false,
  4. bool drainOnStart = true,
  5. bool drainOnResume = true,
  6. bool listenForDeepLinks = false,
  7. String? protocolScheme,
  8. IntentCallPendingReader? takePendingInvocations,
  9. Stream<IntentCallDrainTrigger>? wakeSignals,
  10. IntentCallEnvelopeCallback? onEnvelope,
  11. IntentCallResultCallback? onResult,
  12. IntentCallResultCallback? onDenied,
  13. IntentCallErrorCallback? onError,
})

Implementation

factory IntentCallFlutterHost.bindRegistry({
  required final AgentRegistry registry,
  final IntentCallAuthorizationPolicy policy =
      const IntentCallAuthorizationPolicy.denyAll(),
  final bool registerWebMcp = false,
  final bool drainOnStart = true,
  final bool drainOnResume = true,
  final bool listenForDeepLinks = false,
  final String? protocolScheme,
  final IntentCallPendingReader? takePendingInvocations,
  final Stream<IntentCallDrainTrigger>? wakeSignals,
  final IntentCallEnvelopeCallback? onEnvelope,
  final IntentCallResultCallback? onResult,
  final IntentCallResultCallback? onDenied,
  final IntentCallErrorCallback? onError,
}) {
  final lifecycleWakeSignals = wakeSignals == null && drainOnResume
      ? IntentCallLifecycleWakeSignals()
      : null;
  late final IntentCallFlutterHost host;
  final deepLinkListener = listenForDeepLinks
      ? IntentCallInvokeLinkListener(
          protocolScheme: _requireProtocolScheme(protocolScheme),
          onQualifiedName: (_) {
            unawaited(
              host
                  .requestDrain(IntentCallDrainTrigger.deepLink)
                  .catchError((_) => <AgentResult>[]),
            );
          },
        )
      : null;
  // The deep-link callback captures the host, so this cannot be inlined.
  // ignore: join_return_with_assignment
  host = IntentCallFlutterHost._(
    bridge: IntentCallNativeBridge.bindRegistry(
      registry: registry,
      policy: policy,
    ),
    takePendingInvocations:
        takePendingInvocations ??
        const IntentCallPendingInvocations().takePending,
    registerWebMcp: registerWebMcp,
    onEnvelope: onEnvelope,
    onResult: onResult,
    onDenied: onDenied,
    onError: onError,
    drainOnStart: drainOnStart,
    wakeSignals: wakeSignals ?? lifecycleWakeSignals?.resumeSignals,
    lifecycleWakeSignals: lifecycleWakeSignals,
    deepLinkListener: deepLinkListener,
  );
  return host;
}