Skip to content

Commit

Permalink
Add all pushes
Browse files Browse the repository at this point in the history
  • Loading branch information
PlugFox committed Aug 1, 2023
1 parent 63549cc commit 7ae1846
Show file tree
Hide file tree
Showing 12 changed files with 281 additions and 31 deletions.
3 changes: 3 additions & 0 deletions lib/src/model/channel_presence.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:meta/meta.dart';
sealed class CentrifugeChannelPresence extends CentrifugeChannelPush {
/// {@macro channel_presence}
const CentrifugeChannelPresence({
required super.timestamp,
required super.channel,
required this.info,
});
Expand All @@ -31,6 +32,7 @@ sealed class CentrifugeChannelPresence extends CentrifugeChannelPush {
final class CentrifugeJoin extends CentrifugeChannelPresence {
/// {@macro channel_presence}
const CentrifugeJoin({
required super.timestamp,
required super.channel,
required super.info,
});
Expand All @@ -49,6 +51,7 @@ final class CentrifugeJoin extends CentrifugeChannelPresence {
final class CentrifugeLeave extends CentrifugeChannelPresence {
/// {@macro channel_presence}
const CentrifugeLeave({
required super.timestamp,
required super.channel,
required super.info,
});
Expand Down
1 change: 1 addition & 0 deletions lib/src/model/channel_push.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:centrifuge_dart/src/model/event.dart';
abstract base class CentrifugeChannelPush extends CentrifugeEvent {
/// {@template centrifuge_channel_event}
const CentrifugeChannelPush({
required super.timestamp,
required this.channel,
});

Expand Down
54 changes: 54 additions & 0 deletions lib/src/model/connect.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import 'package:centrifuge_dart/src/model/channel_push.dart';

/// {@template connect}
/// Connect push from Centrifugo server.
/// {@endtemplate}
final class CentrifugeConnect extends CentrifugeChannelPush {
/// {@macro connect}
const CentrifugeConnect({
required super.timestamp,
required super.channel,
required this.client,
required this.version,
required this.data,
this.expires,
this.ttl,
this.pingInterval,
this.sendPong,
this.session,
this.node,
});

@override
String get type => 'connect';

/// Unique client connection ID server issued to this connection
final String client;

/// Server version
final String version;

/// Whether a server will expire connection at some point
final bool? expires;

/// Time when connection will be expired
final DateTime? ttl;

/// Client must periodically (once in 25 secs, configurable) send
/// ping messages to server. If pong has not beed received in 5 secs
/// (configurable) then client must disconnect from server
/// and try to reconnect with backoff strategy.
final Duration? pingInterval;

/// Whether to send asynchronous message when pong received.
final bool? sendPong;

/// Session ID.
final String? session;

/// Server node ID.
final String? node;

/// Payload of connected push.
final List<int> data;
}
27 changes: 27 additions & 0 deletions lib/src/model/disconnect.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'package:centrifuge_dart/src/model/channel_push.dart';

/// {@template disconnect}
/// Disconnect push from Centrifugo server.
/// {@endtemplate}
final class CentrifugeDisconnect extends CentrifugeChannelPush {
/// {@macro disconnect}
const CentrifugeDisconnect({
required super.timestamp,
required super.channel,
required this.code,
required this.reason,
required this.reconnect,
});

@override
String get type => 'disconnect';

/// Code of disconnect.
final int code;

/// Reason of disconnect.
final String reason;

/// Reconnect flag.
final bool reconnect;
}
7 changes: 6 additions & 1 deletion lib/src/model/event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ import 'package:meta/meta.dart';
@immutable
abstract base class CentrifugeEvent {
/// {@template centrifuge_event}
const CentrifugeEvent();
const CentrifugeEvent({
required this.timestamp,
});

/// Event type.
abstract final String type;

/// Timestamp of event
final DateTime timestamp;
}
19 changes: 19 additions & 0 deletions lib/src/model/message.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import 'package:centrifuge_dart/src/model/channel_push.dart';

/// {@template message}
/// Message push from Centrifugo server.
/// {@endtemplate}
final class CentrifugeMessage extends CentrifugeChannelPush {
/// {@macro message}
const CentrifugeMessage({
required super.timestamp,
required super.channel,
required this.data,
});

@override
String get type => 'message';

/// Payload of message.
final List<int> data;
}
1 change: 1 addition & 0 deletions lib/src/model/publication.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:meta/meta.dart';
final class CentrifugePublication extends CentrifugeChannelPush {
/// {@macro publication}
const CentrifugePublication({
required super.timestamp,
required super.channel,
required this.data,
this.offset,
Expand Down
23 changes: 23 additions & 0 deletions lib/src/model/refresh.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
import 'package:centrifuge_dart/src/model/channel_push.dart';
import 'package:meta/meta.dart';

/// {@template refresh}
/// Refresh push from Centrifugo server.
/// {@endtemplate}
final class CentrifugeRefresh extends CentrifugeChannelPush {
/// {@macro refresh}
const CentrifugeRefresh({
required super.timestamp,
required super.channel,
required this.expires,
this.ttl,
});

@override
String get type => 'refresh';

/// Whether a server will expire connection at some point
final bool expires;

/// Time when connection will be expired
final DateTime? ttl;
}

/// {@nodoc}
@internal
@immutable
Expand Down
32 changes: 32 additions & 0 deletions lib/src/model/subscribe.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'package:centrifuge_dart/src/model/channel_push.dart';
import 'package:centrifuge_dart/src/model/stream_position.dart';

/// {@template subscribe}
/// Subscribe push from Centrifugo server.
/// {@endtemplate}
final class CentrifugeSubscribe extends CentrifugeChannelPush {
/// {@macro subscribe}
const CentrifugeSubscribe({
required super.timestamp,
required super.channel,
required this.positioned,
required this.recoverable,
required this.data,
required this.streamPosition,
});

@override
String get type => 'subscribe';

/// Whether subscription is positioned.
final bool positioned;

/// Whether subscription is recoverable.
final bool recoverable;

/// Data attached to subscription.
final List<int> data;

/// Stream position.
final CentrifugeStreamPosition? streamPosition;
}
12 changes: 0 additions & 12 deletions lib/src/model/subscribe_event.dart

This file was deleted.

23 changes: 23 additions & 0 deletions lib/src/model/unsubscribe.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import 'package:centrifuge_dart/src/model/channel_push.dart';

/// {@template unsubscribe}
/// Unsubscribe push from Centrifugo server.
/// {@endtemplate}
final class CentrifugeUnsubscribe extends CentrifugeChannelPush {
/// {@macro unsubscribe}
const CentrifugeUnsubscribe({
required super.timestamp,
required super.channel,
required this.code,
required this.reason,
});

@override
String get type => 'unsubscribe';

/// Code of unsubscribe.
final int code;

/// Reason of unsubscribe.
final String reason;
}
Loading

0 comments on commit 7ae1846

Please sign in to comment.