1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
use crate::dx::subscribe::result::Update;
use crate::{
core::{event_engine::Event, PubNubError},
dx::subscribe::SubscriptionCursor,
lib::alloc::{string::String, vec::Vec},
};
/// Subscription events.
///
/// Subscribe state machine behaviour depends on from external events which it
/// receives.
#[derive(Debug)]
pub(crate) enum SubscribeEvent {
/// Current list of channels / groups has been changed.
///
/// Emitted when updates list of channels / groups has been passed for
/// subscription.
SubscriptionChanged {
channels: Option<Vec<String>>,
channel_groups: Option<Vec<String>>,
},
/// Catching up on updates.
///
/// Emitted when subscription has been called with timetoken (cursor)
/// starting from which updates should be received.
SubscriptionRestored {
channels: Option<Vec<String>>,
channel_groups: Option<Vec<String>>,
cursor: SubscriptionCursor,
},
/// Handshake completed successfully.
///
/// Emitted when [`PubNub`] network returned timetoken (cursor) which will
/// be used for subscription loop.
///
/// [`PubNub`]: https://www.pubnub.com/
HandshakeSuccess { cursor: SubscriptionCursor },
/// Handshake completed with error.
///
/// Emitted when handshake effect was unable to receive response from
/// [`PubNub`] network (network issues or permissions).
///
/// [`PubNub`]: https://www.pubnub.com/
HandshakeFailure { reason: PubNubError },
/// Receive updates completed successfully.
///
/// Emitted when [`PubNub`] network returned list of real-time updates along
/// with timetoken (cursor) which will be used for next subscription loop.
///
/// [`PubNub`]: https://www.pubnub.com/
ReceiveSuccess {
cursor: SubscriptionCursor,
messages: Vec<Update>,
},
/// Receive updates completed with error.
///
/// Emitted when receive updates effect was unable to receive response from
/// [`PubNub`] network (network issues or revoked / expired permissions).
///
/// [`PubNub`]: https://www.pubnub.com/
ReceiveFailure { reason: PubNubError },
/// Disconnect from [`PubNub`] network.
///
/// Emitted when explicitly requested to stop receiving real-time updates.
///
/// [`PubNub`]: https://www.pubnub.com/
Disconnect,
/// Reconnect to [`PubNub`] network.
///
/// Emitted when explicitly requested to restore real-time updates receive.
///
/// [`PubNub`]: https://www.pubnub.com/
Reconnect { cursor: Option<SubscriptionCursor> },
/// Unsubscribe from all channels and groups.
///
/// Emitted when explicitly requested by user to leave all channels and
/// groups.
UnsubscribeAll,
}
impl Event for SubscribeEvent {
fn id(&self) -> &str {
match self {
Self::SubscriptionChanged { .. } => "SUBSCRIPTION_CHANGED",
Self::SubscriptionRestored { .. } => "SUBSCRIPTION_RESTORED",
Self::HandshakeSuccess { .. } => "HANDSHAKE_SUCCESS",
Self::HandshakeFailure { .. } => "HANDSHAKE_FAILURE",
Self::ReceiveSuccess { .. } => "RECEIVE_SUCCESS",
Self::ReceiveFailure { .. } => "RECEIVE_FAILURE",
Self::Disconnect => "DISCONNECT",
Self::Reconnect { .. } => "RECONNECT",
Self::UnsubscribeAll => "UNSUBSCRIBE_ALL",
}
}
}