openSession method

  1. @override
RealtimeSessionScope openSession({
  1. Uri? uri,
  2. String? sessionId,
  3. Map<String, String>? headers,
  4. RealtimeProtocolType protocolType = RealtimeProtocolType.webSocket,
})
override

Opens and returns a RealtimeSessionScope for tracking an active connection.

Implementation

@override
RealtimeSessionScope openSession({
  Uri? uri,
  String? sessionId,
  Map<String, String>? headers,
  RealtimeProtocolType protocolType = RealtimeProtocolType.webSocket,
}) {
  session.markRealtimeActive();
  final effectiveId = sessionId ?? RequestId.generate();

  final isCaptured = shouldCapture(uri);

  if (uri != null && isCaptured) {
    guardCapture(() {
      session.recordRealtimeConnection(
        id: effectiveId,
        url: uri.toString(),
        headers: headers ?? const {},
        isPreValidated: true,
        protocolType: protocolType,
      );
    });
  }

  final scope = RealtimeSessionScope(
    collector: this,
    sessionId: effectiveId,
    uri: uri,
    protocolType: protocolType,
    shouldCapture: isCaptured,
  );
  _activeScopes[effectiveId] = scope;
  return scope;
}