Realtime
Realtime in the Flutter SDK.
import 'package:nexus_flutter/nexus.dart';| Symbol | Kind | Summary |
|---|---|---|
NexusEventHandler | typedef | |
NexusRealtime | class | Realtime messaging over Socket.IO. |
NexusEventHandler
typedeftypedef NexusEventHandler = void Function(dynamic data)NexusRealtime
classRealtime messaging over Socket.IO. Authenticates with the API key + the current journey identity, so realtime connections join the same session.
View sourceisConnected
propertybool get isConnectedisActive
propertybool get isActiveWhether a socket exists (connected, or connecting/reconnecting) — i.e. the app wants realtime up, even if the link is momentarily down.
View sourceconnect()
methodvoid connect()Open the connection (idempotent). Rooms are re-joined after a reconnect.
View sourcejoin()
methodFuture<dynamic> join(String room)Join a room (first/created on the server). Re-joined automatically on
reconnect. Returns the server's acknowledgement ({ ok, room, related }).
Parameters
Prop
Type
Returns Future<dynamic>
leave()
methodFuture<dynamic> leave(String room)Leave a room. Returns the server's acknowledgement ({ ok }).
Parameters
Prop
Type
Returns Future<dynamic>
emit()
methodFuture<dynamic> emit(String room, dynamic event, [Object? payload])Emit one or more named events to a room with a payload. Returns the
server's acknowledgement ({ ok, room, recipients, related } or
{ error }), which is also logged.
Parameters
Prop
Type
Returns Future<dynamic>
on()
methodvoid on(String event, NexusEventHandler handler)Listen for a server event. Persisted, so it survives (re)connects and works even if called before the socket is open.
Parameters
Prop
Type
off()
methodvoid off(String event)Stop listening for a server event.
Parameters
Prop
Type
disconnect()
methodvoid disconnect()