upsertPresenceTo method

void upsertPresenceTo({
  1. required String status,
  2. required String presenceId,
  3. List<String>? permissions,
  4. Map<String, dynamic>? metadata,
})
inherited

Fire-and-forget presence upsert. Records the latest payload in state so that — if the WebSocket isn't open yet, or later reconnects — the most recent presence is automatically (re)sent on the next connected event. When the socket is already open, the frame is sent immediately.

Implementation

void upsertPresenceTo({
  required String status,
  required String presenceId,
  List<String>? permissions,
  Map<String, dynamic>? metadata,
}) {
  final data = <String, dynamic>{
    'status': status,
    'presenceId': presenceId,
  };
  if (permissions != null) data['permissions'] = permissions;
  if (metadata != null) data['metadata'] = metadata;

  _pendingPresence = data;

  // Both subscribe() and upsertPresence() may need to open the socket.
  // _createSocket() is single-flight (see `_creatingSocket`), so calling
  // it here is a no-op when one is already in flight or healthy.
  if (_websok == null || _websok?.closeCode != null) {
    // Fire-and-forget; keeps upsertPresence's documented void return.
    _createSocket();
  }

  // Opportunistic send for when the socket is already past `connected`.
  // The _appConnected gate inside _flushPendingPresence keeps this a no-op
  // until the application-level handshake completes.
  _flushPendingPresence();
}