Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!(realtime_client): make channel methods private and add @internal label #724

Merged
merged 1 commit into from
Nov 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions packages/realtime_client/lib/src/realtime_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ class RealtimeChannel {
_pushBuffer = [];
});

onClose(() {
_onClose(() {
_rejoinTimer.reset();
socket.log('channel', 'close $topic $joinRef');
_state = ChannelStates.closed;
socket.remove(this);
});

onError((String? reason) {
_onError((String? reason) {
if (isLeaving || isClosed) {
return;
}
Expand Down Expand Up @@ -111,10 +111,10 @@ class RealtimeChannel {
final broadcast = params['config']['broadcast'];
final presence = params['config']['presence'];

onError((e) {
_onError((e) {
if (callback != null) callback(RealtimeSubscribeStatus.channelError, e);
});
onClose(() {
_onClose(() {
if (callback != null) callback(RealtimeSubscribeStatus.closed, null);
});

Expand Down Expand Up @@ -237,13 +237,13 @@ class RealtimeChannel {
}

/// Registers a callback that will be executed when the channel closes.
void onClose(Function callback) {
void _onClose(Function callback) {
onEvents(ChannelEvents.close.eventName(), ChannelFilter(),
(reason, [ref]) => callback());
}

/// Registers a callback that will be executed when the channel encounteres an error.
void onError(void Function(String?) callback) {
void _onError(void Function(String?) callback) {
onEvents(ChannelEvents.error.eventName(), ChannelFilter(),
(reason, [ref]) => callback(reason?.toString()));
}
Expand All @@ -256,6 +256,7 @@ class RealtimeChannel {
return onEvents(type.toType(), filter, callback);
}

@internal
RealtimeChannel onEvents(
String type, ChannelFilter filter, BindingCallback callback) {
final typeLower = type.toLowerCase();
Expand All @@ -271,6 +272,7 @@ class RealtimeChannel {
return this;
}

@internal
RealtimeChannel off(String type, Map<String, String> filter) {
final typeLower = type.toLowerCase();

Expand All @@ -286,6 +288,7 @@ class RealtimeChannel {
return socket.isConnected && isJoined;
}

@internal
Push push(
ChannelEvents event,
Map<String, dynamic> payload, [
Expand Down Expand Up @@ -380,6 +383,7 @@ class RealtimeChannel {
return completer.future;
}

@internal
void updateJoinPayload(Map<String, dynamic> payload) {
joinPush.updatePayload(payload);
}
Expand Down Expand Up @@ -449,14 +453,17 @@ class RealtimeChannel {
///
/// Receives all events for specialized message handling before dispatching to the channel callbacks.
/// Must return the payload, modified or unmodified.
@internal
dynamic onMessage(String event, dynamic payload, [String? ref]) {
return payload;
}

@internal
bool isMember(String? topic) {
return this.topic == topic;
}

@internal
String get joinRef => joinPush.ref;

@internal
Expand Down Expand Up @@ -530,6 +537,7 @@ class RealtimeChannel {
}
}

@internal
String replyEventName(String? ref) {
return 'chan_reply_$ref';
}
Expand Down