Skip to content

Commit 8e72147

Browse files
committed
Added leave effect handler
1 parent 8467815 commit 8e72147

File tree

6 files changed

+49
-1
lines changed

6 files changed

+49
-1
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using System.Threading.Tasks;
4+
using Newtonsoft.Json;
5+
using PubnubApi.EndPoint;
6+
using PubnubApi.PubnubEventEngine.Core;
7+
using PubnubApi.PubnubEventEngine.Subscribe.Invocations;
8+
9+
namespace PubnubApi.PubnubEventEngine.Subscribe.Effects {
10+
internal class LeaveEffectHandler : Core.IEffectHandler<LeaveInvocation> {
11+
private SubscribeManager2 manager;
12+
private EventQueue eventQueue;
13+
14+
public LeaveEffectHandler(SubscribeManager2 manager, EventQueue eventQueue) {
15+
this.manager = manager;
16+
this.eventQueue = eventQueue;
17+
}
18+
19+
public async Task Run(LeaveInvocation invocation) {
20+
// TODO identity method for unsubscribe all
21+
//var resp = null;//await manager.UnsubscribeRequest<string>(
22+
// PNOperationType.PNSubscribeOperation,
23+
// invocation.Channels.ToArray(),
24+
// invocation.ChannelGroups.ToArray(),
25+
//);
26+
27+
28+
}
29+
30+
public async Task Cancel() {
31+
//manager.LeaveRequestCancellation();
32+
}
33+
}
34+
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,11 @@ internal class ReceiveReconnectInvocation: Core.IEffectInvocation
6666
}
6767

6868
internal class CancelReceiveReconnectInvocation: ReceiveReconnectInvocation, Core.IEffectCancelInvocation { }
69+
70+
internal class LeaveInvocation: Core.IEffectInvocation
71+
{
72+
public IEnumerable<string> Channels;
73+
public IEnumerable<string> ChannelGroups;
74+
}
75+
internal class CancelLeaveInvocation : LeaveInvocation, Core.IEffectCancelInvocation { }
6976
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ internal class UnsubscribedState : Core.State
99
{
1010
public IEnumerable<string> Channels;
1111
public IEnumerable<string> ChannelGroups;
12-
public override IEnumerable<IEffectInvocation> OnEntry { get; } = null;
12+
public override IEnumerable<IEffectInvocation> OnEntry => new LeaveInvocation()
13+
{ Channels = this.Channels, ChannelGroups = this.ChannelGroups }.AsArray();
1314
public override IEnumerable<IEffectInvocation> OnExit { get; } = null;
1415

1516
public override TransitionResult Transition(Core.IEvent e)

src/Api/PubnubApi/EventEngine/Subscribe/SubscribeEventEngine.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ public SubscribeEventEngine(SubscribeManager2 subscribeManager) {
1515
dispatcher.Register<Invocations.HandshakeInvocation, Effects.HandshakeEffectHandler>(handshakeHandler);
1616
dispatcher.Register<Invocations.CancelHandshakeInvocation, Effects.HandshakeEffectHandler>(handshakeHandler);
1717

18+
var leaveHandler = new Effects.LeaveEffectHandler(subscribeManager, eventQueue);
19+
dispatcher.Register<Invocations.LeaveInvocation, Effects.LeaveEffectHandler>(leaveHandler);
20+
dispatcher.Register<Invocations.CancelLeaveInvocation, Effects.LeaveEffectHandler>(leaveHandler);
21+
1822
currentState = new UnsubscribedState();
1923
}
2024
}

src/Api/PubnubApiPCL/PubnubApiPCL.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@
229229
<Compile Include="..\PubnubApi\EventEngine\ReceivingEffectHandler.cs" Link="EventEngine\ReceivingEffectHandler.cs" />
230230
<Compile Include="..\PubnubApi\EventEngine\State.cs" Link="EventEngine\State.cs" />
231231
<Compile Include="..\PubnubApi\EventEngine\Subscribe\Effects\HandshakeEffectHandler.cs" Link="EventEngine\Subscribe\Effects\HandshakeEffectHandler.cs" />
232+
<Compile Include="..\PubnubApi\EventEngine\Subscribe\Effects\LeaveEffectHandler.cs" Link="EventEngine\Subscribe\Effects\LeaveEffectHandler.cs" />
232233
<Compile Include="..\PubnubApi\EventEngine\Subscribe\Events\SubscriptionEvents.cs" Link="EventEngine\Subscribe\Events\SubscriptionEvents.cs" />
233234
<Compile Include="..\PubnubApi\EventEngine\Subscribe\Invocations\SubscriptionInvocations.cs" Link="EventEngine\Subscribe\Invocations\SubscriptionInvocations.cs" />
234235
<Compile Include="..\PubnubApi\EventEngine\Subscribe\States\HandshakeFailedState.cs" Link="EventEngine\Subscribe\States\HandshakeFailedState.cs" />

src/Api/PubnubApiUWP/PubnubApiUWP.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@
346346
<Compile Include="..\PubnubApi\EventEngine\ReceivingEffectHandler.cs" Link="EventEngine\ReceivingEffectHandler.cs" />
347347
<Compile Include="..\PubnubApi\EventEngine\State.cs" Link="EventEngine\State.cs" />
348348
<Compile Include="..\PubnubApi\EventEngine\Subscribe\Effects\HandshakeEffectHandler.cs" Link="EventEngine\Subscribe\Effects\HandshakeEffectHandler.cs" />
349+
<Compile Include="..\PubnubApi\EventEngine\Subscribe\Effects\LeaveEffectHandler.cs" Link="EventEngine\Subscribe\Effects\LeaveEffectHandler.cs" />
349350
<Compile Include="..\PubnubApi\EventEngine\Subscribe\Events\SubscriptionEvents.cs" Link="EventEngine\Subscribe\Events\SubscriptionEvents.cs" />
350351
<Compile Include="..\PubnubApi\EventEngine\Subscribe\Invocations\SubscriptionInvocations.cs" Link="EventEngine\Subscribe\Invocations\SubscriptionInvocations.cs" />
351352
<Compile Include="..\PubnubApi\EventEngine\Subscribe\States\HandshakeFailedState.cs" Link="EventEngine\Subscribe\States\HandshakeFailedState.cs" />

0 commit comments

Comments
 (0)