RealtimeChannel constructor
RealtimeChannel(
- String topic,
- RealtimeClient socket, {
- RealtimeChannelConfig params = const RealtimeChannelConfig(),
Implementation
RealtimeChannel(
this.topic,
this.socket, {
RealtimeChannelConfig params = const RealtimeChannelConfig(),
}) : _timeout = socket.timeout,
params = params.toMap(),
subTopic = topic.replaceFirst(
RegExp(r"^realtime:", caseSensitive: false), "") {
broadcastEndpointURL = _broadcastEndpointURL;
joinPush = Push(
this,
ChannelEvents.join,
this.params,
_timeout,
);
_rejoinTimer =
RetryTimer(() => rejoinUntilConnected(), socket.reconnectAfterMs);
joinPush.receive('ok', (_) {
_state = ChannelStates.joined;
_rejoinTimer.reset();
for (final pushEvent in _pushBuffer) {
pushEvent.send();
}
_pushBuffer = [];
});
_onClose(() {
_rejoinTimer.reset();
socket.log('channel', 'close $topic $joinRef');
_state = ChannelStates.closed;
socket.remove(this);
});
_onError((String? reason) {
if (isLeaving || isClosed) {
return;
}
socket.log('channel', 'error $topic', reason);
_state = ChannelStates.errored;
_rejoinTimer.scheduleTimeout();
});
joinPush.receive('timeout', (_) {
if (!isJoining) {
return;
}
socket.log('channel', 'timeout $topic', joinPush.timeout);
_state = ChannelStates.errored;
_rejoinTimer.scheduleTimeout();
});
onEvents(ChannelEvents.reply.eventName(), ChannelFilter(), (payload,
[ref]) {
trigger(replyEventName(ref), payload);
});
presence = RealtimePresence(this);
}