Skip to content

Commit fd63a9b

Browse files
HandshakeReconnectingState and other Pascal casing (#172)
* HandshakeReconnectingState * EmitStatusInvocation * HandshakeFailedState
1 parent 5b8de6c commit fd63a9b

File tree

7 files changed

+114
-32
lines changed

7 files changed

+114
-32
lines changed

src/Api/PubnubApi/EventEngine/Subscribe/Effects/HandshakeEffectHandler.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ public async Task Run(HandshakeInvocation invocation) {
2020
// TODO fix this, probably wrong :)
2121
var resp = await manager.HandshakeRequest<string>(
2222
PNOperationType.PNSubscribeOperation,
23-
invocation.channels.ToArray(),
24-
invocation.channelGroups.ToArray(),
23+
invocation.Channels.ToArray(),
24+
invocation.ChannelGroups.ToArray(),
2525
null,
2626
null,
27-
invocation.initialSubscribeQueryParams,
28-
invocation.externalQueryParams
27+
invocation.InitialSubscribeQueryParams,
28+
invocation.ExternalQueryParams
2929
);
3030

3131
if (!resp.Item2.Error) {

src/Api/PubnubApi/EventEngine/Subscribe/Events/SubscriptionEvents.cs

+11-5
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
namespace PubnubApi.PubnubEventEngine.Subscribe.Events {
44
public class SubscriptionChangedEvent : Core.IEvent {
5-
public IEnumerable<string> channels;
6-
public IEnumerable<string> channelGroups;
5+
public IEnumerable<string> Channels;
6+
public IEnumerable<string> ChannelGroups;
77
}
88

99
public class SubscriptionRestoredEvent : Core.IEvent {
10-
public IEnumerable<string> channels;
11-
public IEnumerable<string> channelGroups;
12-
public SubscriptionCursor cursor;
10+
public IEnumerable<string> Channels;
11+
public IEnumerable<string> ChannelGroups;
12+
public SubscriptionCursor Cursor;
1313
}
1414

1515
public class HandshakeSuccessEvent : Core.IEvent {
@@ -22,6 +22,8 @@ public class HandshakeFailureEvent : Core.IEvent {
2222
}
2323

2424
public class HandshakeReconnectSuccessEvent : HandshakeSuccessEvent {
25+
public IEnumerable<string> Channels;
26+
public IEnumerable<string> ChannelGroups;
2527
}
2628

2729
public class HandshakeReconnectFailureEvent : HandshakeFailureEvent {
@@ -31,6 +33,8 @@ public class HandshakeReconnectRetryEvent : Core.IEvent {
3133
}
3234

3335
public class HandshakeReconnectGiveUpEvent : Core.IEvent {
36+
public IEnumerable<string> Channels;
37+
public IEnumerable<string> ChannelGroups;
3438
// TODO status or reason?
3539
public PNStatus status;
3640
}
@@ -65,5 +69,7 @@ public class DisconnectEvent : Core.IEvent {
6569
}
6670

6771
public class ReconnectEvent : Core.IEvent {
72+
public IEnumerable<string> Channels;
73+
public IEnumerable<string> ChannelGroups;
6874
}
6975
}

src/Api/PubnubApi/EventEngine/Subscribe/Invocations/SubscriptionInvocations.cs

+17-7
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,34 @@ internal class EmitMessagesInvocation : Core.IEffectInvocation {
77
}
88

99
internal class EmitStatusInvocation : Core.IEffectInvocation {
10-
10+
public IEnumerable<string> Channels;
11+
public IEnumerable<string> ChannelGroups;
1112
}
1213

1314
internal class HandshakeInvocation : Core.IEffectInvocation {
14-
public IEnumerable<string> channels;
15-
public IEnumerable<string> channelGroups;
16-
public Dictionary<string, string> initialSubscribeQueryParams = new Dictionary<string, string>();
17-
public Dictionary<string, object> externalQueryParams = new Dictionary<string, object>();
15+
public IEnumerable<string> Channels;
16+
public IEnumerable<string> ChannelGroups;
17+
public Dictionary<string, string> InitialSubscribeQueryParams = new Dictionary<string, string>();
18+
public Dictionary<string, object> ExternalQueryParams = new Dictionary<string, object>();
1819
}
1920

20-
internal class ReceiveMessagesInvocation : Core.IEffectInvocation { }
21+
internal class ReceiveMessagesInvocation : Core.IEffectInvocation
22+
{
23+
public IEnumerable<string> Channels;
24+
public IEnumerable<string> ChannelGroups;
25+
}
2126

2227
internal class CancelReceiveMessagesInvocation : ReceiveMessagesInvocation, Core.IEffectCancelInvocation { }
2328

2429
internal class HandshakeCancelInvocation : HandshakeInvocation, Core.IEffectCancelInvocation { }
2530

2631
//internal class ReconnectInvocation : Core.IEffectInvocation { }
27-
internal class HandshakeReconnectInvocation: Core.IEffectInvocation { }
32+
internal class HandshakeReconnectInvocation: Core.IEffectInvocation
33+
{
34+
public IEnumerable<string> Channels;
35+
public IEnumerable<string> ChannelGroups;
36+
}
37+
2838
internal class CancelHandshakeReconnectInvocation: HandshakeReconnectInvocation, Core.IEffectCancelInvocation { }
2939

3040
internal class ReceiveReconnectInvocation: Core.IEffectInvocation { }

src/Api/PubnubApi/EventEngine/Subscribe/States/HandshakeFailedState.cs

+43-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,49 @@ internal class HandshakeFailedState : Core.IState {
1212
public IEnumerable<IEffectInvocation> OnEntry { get; }
1313
public IEnumerable<IEffectInvocation> OnExit { get; }
1414
public Tuple<Core.IState, IEnumerable<IEffectInvocation>> Transition(IEvent e) {
15-
throw new NotImplementedException();
15+
switch (e) {
16+
case Events.SubscriptionChangedEvent subscriptionChanged:
17+
return new Tuple<Core.IState, IEnumerable<IEffectInvocation>>(
18+
new HandshakingState() {
19+
Channels = subscriptionChanged.Channels,
20+
ChannelGroups = subscriptionChanged.ChannelGroups,
21+
},
22+
new[] {
23+
new HandshakeInvocation() {
24+
Channels = subscriptionChanged.Channels,
25+
ChannelGroups = subscriptionChanged.ChannelGroups,
26+
},
27+
}
28+
);
29+
case Events.ReconnectEvent reconnect:
30+
return new Tuple<Core.IState, IEnumerable<IEffectInvocation>>(
31+
new HandshakingState() {
32+
Channels = reconnect.Channels,
33+
ChannelGroups = reconnect.ChannelGroups,
34+
},
35+
new[] {
36+
new HandshakeInvocation() {
37+
Channels = reconnect.Channels,
38+
ChannelGroups = reconnect.ChannelGroups,
39+
},
40+
}
41+
);
42+
case Events.SubscriptionRestoredEvent subscriptionRestored:
43+
return new Tuple<IState, IEnumerable<IEffectInvocation>>(
44+
new ReceivingState() {
45+
Channels = subscriptionRestored.Channels,
46+
ChannelGroups = subscriptionRestored.ChannelGroups
47+
},
48+
new[] {
49+
new ReceiveMessagesInvocation() {
50+
Channels = subscriptionRestored.Channels,
51+
ChannelGroups = subscriptionRestored.ChannelGroups,
52+
},
53+
}
54+
);
55+
56+
default: return null;
57+
}
1658
}
1759
}
1860
}

src/Api/PubnubApi/EventEngine/Subscribe/States/HandshakeReconnectingState.cs

+33-9
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,51 @@ internal class HandshakeReconnectingState : Core.IState {
1616
case Events.SubscriptionChangedEvent subscriptionChanged:
1717
return new Tuple<Core.IState, IEnumerable<IEffectInvocation>>(
1818
new HandshakingState() {
19-
channels = subscriptionChanged.channels,
20-
channelGroups = subscriptionChanged.channelGroups,
19+
Channels = subscriptionChanged.Channels,
20+
ChannelGroups = subscriptionChanged.ChannelGroups,
2121
},
2222
new[] {
2323
new HandshakeInvocation() {
24-
channels = subscriptionChanged.channels,
25-
channelGroups = subscriptionChanged.channelGroups,
24+
Channels = subscriptionChanged.Channels,
25+
ChannelGroups = subscriptionChanged.ChannelGroups,
2626
},
2727
}
2828
);
29-
case Events.DisconnectEvent disconnectEvent:
29+
case Events.DisconnectEvent disconnect:
3030
return new Tuple<Core.IState, IEnumerable<IEffectInvocation>>(
3131
new HandshakeStoppedState() {
32-
Channels = disconnectEvent.Channels,
33-
ChannelGroups = disconnectEvent.ChannelGroups
32+
Channels = disconnect.Channels,
33+
ChannelGroups = disconnect.ChannelGroups
3434
},
3535
null
3636
);
37-
case Events.HandshakeReconnectGiveUpEvent handshakeReconnectGiveUpEvent:
37+
case Events.HandshakeReconnectGiveUpEvent handshakeReconnectGiveUp:
3838
return new Tuple<IState, IEnumerable<IEffectInvocation>>(
39-
new HandshakeFailedState() { },
39+
new HandshakeFailedState() {
40+
Channels = handshakeReconnectGiveUp.Channels,
41+
ChannelGroups = handshakeReconnectGiveUp.ChannelGroups
42+
},
43+
null
44+
);
45+
case Events.HandshakeReconnectSuccessEvent handshakeReconnectSuccess:
46+
return new Tuple<IState, IEnumerable<IEffectInvocation>>(
47+
new ReceivingState() {
48+
Channels = handshakeReconnectSuccess.Channels,
49+
ChannelGroups = handshakeReconnectSuccess.ChannelGroups
50+
},
51+
new[] {
52+
new EmitStatusInvocation() {
53+
Channels = handshakeReconnectSuccess.Channels,
54+
ChannelGroups = handshakeReconnectSuccess.ChannelGroups,
55+
},
56+
}
57+
);
58+
case Events.SubscriptionRestoredEvent subscriptionRestored:
59+
return new Tuple<IState, IEnumerable<IEffectInvocation>>(
60+
new HandshakeFailedState() {
61+
Channels = subscriptionRestored.Channels,
62+
ChannelGroups = subscriptionRestored.ChannelGroups
63+
},
4064
null
4165
);
4266

src/Api/PubnubApi/EventEngine/Subscribe/States/HandshakingState.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
namespace PubnubApi.PubnubEventEngine.Subscribe.States {
66
internal class HandshakingState : Core.IState {
77

8-
public IEnumerable<string> channels;
9-
public IEnumerable<string> channelGroups;
8+
public IEnumerable<string> Channels;
9+
public IEnumerable<string> ChannelGroups;
1010

1111
public IEnumerable<IEffectInvocation> OnEntry { get; }
1212
public IEnumerable<IEffectInvocation> OnExit { get; }

src/Api/PubnubApi/EventEngine/Subscribe/States/UnsubscribedState.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ internal class UnsubscribedState : Core.IState {
1212
case Events.SubscriptionChangedEvent subscriptionChanged:
1313
return new Tuple<Core.IState, IEnumerable<IEffectInvocation>>(
1414
new HandshakingState() {
15-
channels = subscriptionChanged.channels,
16-
channelGroups = subscriptionChanged.channelGroups,
15+
Channels = subscriptionChanged.Channels,
16+
ChannelGroups = subscriptionChanged.ChannelGroups,
1717
},
1818
new[] {
1919
new HandshakeInvocation() {
20-
channels = subscriptionChanged.channels,
21-
channelGroups = subscriptionChanged.channelGroups,
20+
Channels = subscriptionChanged.Channels,
21+
ChannelGroups = subscriptionChanged.ChannelGroups,
2222
},
2323
}
2424
);

0 commit comments

Comments
 (0)