Skip to main content

Description

RoomConnectionScope is a widget that manages the connection lifecycle for a MeshAgent RoomClient.
  • authorization: Future<RoomConnectionInfo> Function() that returns URL/JWT (or use helpers like staticAuthorization/developmentAuthorization).
  • builder: (BuildContext, RoomClient) called when the client is ready.
  • authorizingBuilder (optional): UI while fetching auth.
  • connectingBuilder (optional): UI while connecting after auth is fetched.
  • doneBuilder (optional): UI when the connection ends or errors.
  • onReady (optional): Callback invoked when the client is connected (after messaging is enabled if configured).
  • enableMessaging (default true): Auto-enable messaging on connect.
  • oauthTokenRequestHandler (optional): Handle OAuth prompts from secrets.request_oauth_token.
  • client (optional string): Client identifier passed to the SDK.
  • Returns: Widget that rebuilds based on connection state.

Example

import 'package:flutter/widgets.dart';
import 'package:meshagent/meshagent.dart';
import 'package:meshagent_flutter/meshagent_flutter.dart';

class SampleWidget extends StatelessWidget {
  const SampleWidget({
    super.key,
    required this.projectId,
    required this.roomName,
    required this.url,
    required this.jwt,
  });

  final String projectId;
  final String roomName;
  final Uri url;
  final String jwt;

  @override
  Widget build(BuildContext context) {
    return RoomConnectionScope(
      authorization: staticAuthorization(
        projectId: projectId,
        roomName: roomName,
        url: url,
        jwt: jwt,
      ),
      authorizingBuilder: (context) => const Center(child: CircularProgressIndicator()),
      connectingBuilder: (context, client) => const Center(child: Text('Connecting...')),
      builder: (context, client) => const Text('Connection established'),
      doneBuilder: (context, error) => Text('Connection ended with error: $error'),
      onReady: (client) {
        // Client is connected; you can start using room APIs here.
      },
      enableMessaging: true,
    );
  }
}