RealtimeManager class

The realtime manager allows realtime publish and subscribe (pub/sub) messaging through websockets.

Realtime makes it possible to open a two-way interactive communication session between the user's device (e.g., browser, smartphone) and a server. With realtime, you can send messages to a server and receive event-driven responses without having to poll the server for a reply.

The configuration parameters of the realtime module is specified when creating the Altogic client library instance. In particular three key parameters affect how realtime messaging works in your apps.

  • echoMessages - This boolean parmeter enables or prevents realtime messages originating from this connection being echoed back on the same connection. By default messsages are echoed back.
  • bufferMessages - By default, any event emitted while the realtime socket is not connected will be buffered until reconnection. You can turn on/off the message buffering using this parameter. While enabling this feature is useful in most cases (when the reconnection delay is short), it could result in a huge spike of events when the connection is restored.
  • autoJoinChannels - This parameter enables or disables automatic join to channels already subscribed in case of websocket reconnection. When websocket is disconnected, it automatically leaves subscribed channels. This parameter helps re-joining to already joined channels when the connection is restored. If this parameter is set to false, you need to listen to connect and disconnect events to manage your channel subscriptions.
Inheritance

Constructors

RealtimeManager(Fetcher fetcher, [RealtimeOptions? options])

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

broadcast(String eventName, dynamic message, [bool? echo]) → void
Sends the message identified by the eventName to all connected members of the app. All serializable datastructures are supported for the message, including Buffer.
close() → void
Manually closes the realtime connection. In this case, the socket will not try to reconnect.
getMembers(String channel) Future<APIResponse<List<MemberData>?>>
Returns the members of the specified channel.
getSocketId() String
Returns the unique identifier of the underlying websocket returns the socket id
isConnected() bool
Returns true if the realtime socket is connected otherwise false
join(String channel, [bool? echo]) → void
Adds the realtime socket to the specified channel. As a result of this action a channel:join event is sent to all members of the channel notifying the new member arrival.
leave(String channel, [bool? echo]) → void
Removes the realtime socket from the specified channel. As a result of this action a channel:leave event is sent to all members of the channel notifying the departure of existing member.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
off(String eventName, EventCallback? listener) → void
Removes the specified listener function from the listener array for the event named eventName.
offAny(void listener(String, dynamic)) → void
Removes the previously registered listener function. If no listener is provided, all catch-all listener functions are removed.
on(String eventName, EventCallback listener) → void
Register a new listener function for the given event.
onAny(void listener(String, dynamic)) → void
Registers a new catch-all listener function. This listener function is triggered for all messages sent to this socket.
once(String eventName, EventCallback listener) → void
Adds a one-time listener function for the event named eventName. The next time eventName is triggered, this listener is removed and then invoked.
onConnect(void listener(dynamic)) → void
Callback function fired upon successfully realtime connection, including a successful reconnection.
onDisconnect(void listener(dynamic reason)) → void
Callback function fired upon realtime disconnection. Passes the disconnection reason as a string parameter to the callback function.
onError(void listener(dynamic)) → void
Callback function fired upon a realtime connection error. Passes the error as a parameter to the callback function.
onJoin(EventCallback listener) → void
Convenience method which registers a new listener function for channel:join events which are emitted when a new member joins a channel.
onLeave(EventCallback listener) → void
Convenience method which registers a new listener function for channel:leave events which are emitted when an existing member leaves a channel.
onReconnectAttempt(void listener(int number)) → void
Callback function fired upon an attempt to reconnect. Passes the reconnection attempt number as a parameter to the callback function.
onUpdate(EventCallback listener) → void
Convenience method which registers a new listener function for channel:update events which are emitted when a channel member updates its member data.
onUserEvent(UserEventListenerFunction listener) → void
Registers a method to listen to main user events. The following events will be listened:
open() → void
Manually open the realtime connection, connects the socket.
send(String channel, String eventName, dynamic message, [bool? echo]) → void
Sends the message identified by the eventName to the provided channel members only. All serializable datastructures are supported for the message, including Buffer.
toString() String
A string representation of this object.
inherited
updateProfile(dynamic data, [bool? echo]) → void
Update the current realtime socket member data and broadcast an update event to each joined channel so that other channel members can get the information about the updated member data. Whenever the socket joins a new channel, this updated member data will be broadcasted to channel members. As a result of this action a channel:update event is sent to all members of the subscribed channels notifying the member data update.

Operators

operator ==(Object other) bool
The equality operator.
inherited