PhoenixPresence constructor
PhoenixPresence({
- required PhoenixChannel channel,
- Map<
String, String> eventNames = const {'state' : 'presence_state', 'diff' : 'presence_diff'},
Attaches a Phoenix Presence client to listen to new presence messages on an existing channel.
By default, the 'state' and 'diff' event names which this client listens to are :
- For state events: 'presence_state'
- For diff events: 'presence_diff'
This can be customized by passing a custom name map eventNames for those events.
Implementation
PhoenixPresence({
required this.channel,
this.eventNames = const {
'state': 'presence_state',
'diff': 'presence_diff'
},
}) {
// Listens to new messages on the [channel] matching [eventNames]
// and processes them according to [_onMessage].
_subscription = channel.messages
.where((message) => eventNames.containsValue(message.event.value))
.listen(_onMessage);
}