From b4bcc30849b04e0dd2093a8d0848805d66910d19 Mon Sep 17 00:00:00 2001 From: Xavrax Date: Tue, 23 Jan 2024 07:44:29 +0100 Subject: [PATCH 01/32] add events --- .../Presence/Events/PresenceEvents.cs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/Api/PubnubApi/EventEngine/Presence/Events/PresenceEvents.cs diff --git a/src/Api/PubnubApi/EventEngine/Presence/Events/PresenceEvents.cs b/src/Api/PubnubApi/EventEngine/Presence/Events/PresenceEvents.cs new file mode 100644 index 000000000..2dee9b9e1 --- /dev/null +++ b/src/Api/PubnubApi/EventEngine/Presence/Events/PresenceEvents.cs @@ -0,0 +1,32 @@ +using System.Collections.Generic; +using PubnubApi.Model.Consumer.PNStatus; + +namespace PubnubApi.EventEngine.Presence.Events { + public class JoinedEvent : Core.IEvent { + public IEnumerable Channels { get; set; } + public IEnumerable ChannelGroups { get; set; } + } + + public class LeftEvent : Core.IEvent { + public IEnumerable Channels { get; set; } + public IEnumerable ChannelGroups { get; set; } + } + + public class LeftAllEvent : Core.IEvent {} + + public class HeartbeatSuccessEvent : Core.IEvent {} + + public class HeartbeatFailureEvent : Core.IEvent { + public PNStatus Status { get; set; } + } + + public class HeartbeatGiveUpEvent : Core.IEvent { + public PNStatus Status { get; set; } + } + + public class ReconnectEvent : Core.IEvent {} + + public class DisconnectEvent : Core.IEvent {} + + public class TimesUpEvent : Core.IEvent {} +} From c405b5158c208bfbc83f898aa91d4913ce61f6cc Mon Sep 17 00:00:00 2001 From: Xavrax Date: Tue, 23 Jan 2024 07:49:02 +0100 Subject: [PATCH 02/32] proper formatting --- .../EventEngine/Presence/Events/PresenceEvents.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Api/PubnubApi/EventEngine/Presence/Events/PresenceEvents.cs b/src/Api/PubnubApi/EventEngine/Presence/Events/PresenceEvents.cs index 2dee9b9e1..c94a82ec3 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/Events/PresenceEvents.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/Events/PresenceEvents.cs @@ -2,12 +2,14 @@ using PubnubApi.Model.Consumer.PNStatus; namespace PubnubApi.EventEngine.Presence.Events { - public class JoinedEvent : Core.IEvent { + public class JoinedEvent : Core.IEvent + { public IEnumerable Channels { get; set; } public IEnumerable ChannelGroups { get; set; } } - public class LeftEvent : Core.IEvent { + public class LeftEvent : Core.IEvent + { public IEnumerable Channels { get; set; } public IEnumerable ChannelGroups { get; set; } } @@ -16,11 +18,13 @@ public class LeftAllEvent : Core.IEvent {} public class HeartbeatSuccessEvent : Core.IEvent {} - public class HeartbeatFailureEvent : Core.IEvent { + public class HeartbeatFailureEvent : Core.IEvent + { public PNStatus Status { get; set; } } - public class HeartbeatGiveUpEvent : Core.IEvent { + public class HeartbeatGiveUpEvent : Core.IEvent + { public PNStatus Status { get; set; } } From 135c876b808ce2d33baf0911cf77fa62a210e10f Mon Sep 17 00:00:00 2001 From: Xavrax Date: Tue, 23 Jan 2024 09:31:22 +0100 Subject: [PATCH 03/32] all states declared --- .../EventEngine/Presence/Invocations/Dummy.cs | 10 +++++++ .../Presence/States/APresenceState.cs | 17 +++++++++++ .../Presence/States/CooldownState.cs | 22 +++++++++++++++ .../Presence/States/FailedState.cs | 22 +++++++++++++++ .../Presence/States/HeartBeatingState.cs | 22 +++++++++++++++ .../Presence/States/InactiveState.cs | 28 +++++++++++++++++++ .../Presence/States/ReconnectingState.cs | 22 +++++++++++++++ .../Presence/States/StoppedState.cs | 22 +++++++++++++++ 8 files changed, 165 insertions(+) create mode 100644 src/Api/PubnubApi/EventEngine/Presence/Invocations/Dummy.cs create mode 100644 src/Api/PubnubApi/EventEngine/Presence/States/APresenceState.cs create mode 100644 src/Api/PubnubApi/EventEngine/Presence/States/CooldownState.cs create mode 100644 src/Api/PubnubApi/EventEngine/Presence/States/FailedState.cs create mode 100644 src/Api/PubnubApi/EventEngine/Presence/States/HeartBeatingState.cs create mode 100644 src/Api/PubnubApi/EventEngine/Presence/States/InactiveState.cs create mode 100644 src/Api/PubnubApi/EventEngine/Presence/States/ReconnectingState.cs create mode 100644 src/Api/PubnubApi/EventEngine/Presence/States/StoppedState.cs diff --git a/src/Api/PubnubApi/EventEngine/Presence/Invocations/Dummy.cs b/src/Api/PubnubApi/EventEngine/Presence/Invocations/Dummy.cs new file mode 100644 index 000000000..db39ac82a --- /dev/null +++ b/src/Api/PubnubApi/EventEngine/Presence/Invocations/Dummy.cs @@ -0,0 +1,10 @@ +// TODO: Dummy Invocation until we have real ones +namespace PubnubApi.EventEngine.Presence.Invocations { + public class DummyInvocation : Core.IEffectInvocation {} + + DummyInvocation[] DummyInvocations() { + return new DummyInvocation[] { + new DummyInvocation(), + }; + } +} diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/APresenceState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/APresenceState.cs new file mode 100644 index 000000000..63bdecd75 --- /dev/null +++ b/src/Api/PubnubApi/EventEngine/Presence/States/APresenceState.cs @@ -0,0 +1,17 @@ +using PubnubApi.EventEngine.Core; + +namespace PubnubApi.EventEngine.Presence.States +{ + public abstract class APresenceState : Core.State + { + public IEnumerable Channels { get; set; } + public IEnumerable ChannelGroups { get; set; } + + public bool IsEmpty() + { + return (Channels == null && ChannelGroups == null) + || ((Channels != null && Channels.Count() == 0) + && (ChannelGroups != null && ChannelGroups.Count() == 0)); + } + } +} diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/CooldownState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/CooldownState.cs new file mode 100644 index 000000000..6602355f0 --- /dev/null +++ b/src/Api/PubnubApi/EventEngine/Presence/States/CooldownState.cs @@ -0,0 +1,22 @@ +using PubnubApi.EventEngine.Presence.Invocations; +using PubnubApi.EventEngine.Core; + +namespace PubnubApi.EventEngine.Presence.States +{ + public class CooldownState : APresenceState + { + // TODO: Dummy Invocation until we have real ones + public override IEnumerable OnEntry => DummyInvocations(); + public override IEnumerable OnExit => DummyInvocations(); + + // TODO: transitions + public override TransitionResult Transition(Transition transition) + { + return e switch + { + _ => null, + }; + } + } + +} diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/FailedState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/FailedState.cs new file mode 100644 index 000000000..528d3a14e --- /dev/null +++ b/src/Api/PubnubApi/EventEngine/Presence/States/FailedState.cs @@ -0,0 +1,22 @@ +using PubnubApi.EventEngine.Presence.Invocations; +using PubnubApi.EventEngine.Core; + +namespace PubnubApi.EventEngine.Presence.States +{ + public class FailedState : APresenceState + { + // TODO: Dummy Invocation until we have real ones + public override IEnumerable OnEntry => DummyInvocations(); + public override IEnumerable OnExit => DummyInvocations(); + + // TODO: transitions + public override TransitionResult Transition(Transition transition) + { + return e switch + { + _ => null, + }; + } + } + +} diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/HeartBeatingState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/HeartBeatingState.cs new file mode 100644 index 000000000..ecc20ace9 --- /dev/null +++ b/src/Api/PubnubApi/EventEngine/Presence/States/HeartBeatingState.cs @@ -0,0 +1,22 @@ +using PubnubApi.EventEngine.Presence.Invocations; +using PubnubApi.EventEngine.Core; + +namespace PubnubApi.EventEngine.Presence.States +{ + public class HeartbeatingState : APresenceState + { + // TODO: Dummy Invocation until we have real ones + public override IEnumerable OnEntry => DummyInvocations(); + public override IEnumerable OnExit => DummyInvocations(); + + // TODO: transitions + public override TransitionResult Transition(Transition transition) + { + return e switch + { + _ => null, + }; + } + } + +} diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/InactiveState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/InactiveState.cs new file mode 100644 index 000000000..9c0e7d066 --- /dev/null +++ b/src/Api/PubnubApi/EventEngine/Presence/States/InactiveState.cs @@ -0,0 +1,28 @@ +using PubnubApi.EventEngine.Presence.Invocations; +using PubnubApi.EventEngine.Core; + +namespace PubnubApi.EventEngine.Presence.States +{ + public class InactiveState : APresenceState + { + public InactiveState() + { + Channels = null; + ChannelGroups = null; + } + + // TODO: Dummy Invocation until we have real ones + public override IEnumerable OnEntry => DummyInvocations(); + public override IEnumerable OnExit => DummyInvocations(); + + // TODO: transitions + public override TransitionResult Transition(Transition transition) + { + return e switch + { + _ => null, + }; + } + } + +} diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/ReconnectingState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/ReconnectingState.cs new file mode 100644 index 000000000..9ef54573a --- /dev/null +++ b/src/Api/PubnubApi/EventEngine/Presence/States/ReconnectingState.cs @@ -0,0 +1,22 @@ +using PubnubApi.EventEngine.Presence.Invocations; +using PubnubApi.EventEngine.Core; + +namespace PubnubApi.EventEngine.Presence.States +{ + public class ReconnectingState : APresenceState + { + // TODO: Dummy Invocation until we have real ones + public override IEnumerable OnEntry => DummyInvocations(); + public override IEnumerable OnExit => DummyInvocations(); + + // TODO: transitions + public override TransitionResult Transition(Transition transition) + { + return e switch + { + _ => null, + }; + } + } + +} diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/StoppedState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/StoppedState.cs new file mode 100644 index 000000000..800a12f73 --- /dev/null +++ b/src/Api/PubnubApi/EventEngine/Presence/States/StoppedState.cs @@ -0,0 +1,22 @@ +using PubnubApi.EventEngine.Presence.Invocations; +using PubnubApi.EventEngine.Core; + +namespace PubnubApi.EventEngine.Presence.States +{ + public class StoppedState : APresenceState + { + // TODO: Dummy Invocation until we have real ones + public override IEnumerable OnEntry => DummyInvocations(); + public override IEnumerable OnExit => DummyInvocations(); + + // TODO: transitions + public override TransitionResult Transition(Transition transition) + { + return e switch + { + _ => null, + }; + } + } + +} From 0ac1abab22635ba647727d47a45e9063666c8c2b Mon Sep 17 00:00:00 2001 From: Xavrax Date: Tue, 23 Jan 2024 09:34:12 +0100 Subject: [PATCH 04/32] fields declared --- src/Api/PubnubApi/EventEngine/Presence/States/FailedState.cs | 2 ++ .../PubnubApi/EventEngine/Presence/States/ReconnectingState.cs | 2 ++ src/Api/PubnubApi/EventEngine/Presence/States/StoppedState.cs | 2 ++ 3 files changed, 6 insertions(+) diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/FailedState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/FailedState.cs index 528d3a14e..c793831b2 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/FailedState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/FailedState.cs @@ -5,6 +5,8 @@ namespace PubnubApi.EventEngine.Presence.States { public class FailedState : APresenceState { + public PNStatus Reason { get; set; } + // TODO: Dummy Invocation until we have real ones public override IEnumerable OnEntry => DummyInvocations(); public override IEnumerable OnExit => DummyInvocations(); diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/ReconnectingState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/ReconnectingState.cs index 9ef54573a..6b0064a1c 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/ReconnectingState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/ReconnectingState.cs @@ -5,6 +5,8 @@ namespace PubnubApi.EventEngine.Presence.States { public class ReconnectingState : APresenceState { + public short RetryCount { get; set; } + // TODO: Dummy Invocation until we have real ones public override IEnumerable OnEntry => DummyInvocations(); public override IEnumerable OnExit => DummyInvocations(); diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/StoppedState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/StoppedState.cs index 800a12f73..257dc42fe 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/StoppedState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/StoppedState.cs @@ -5,6 +5,8 @@ namespace PubnubApi.EventEngine.Presence.States { public class StoppedState : APresenceState { + public PNStatus reason { get; set; } + // TODO: Dummy Invocation until we have real ones public override IEnumerable OnEntry => DummyInvocations(); public override IEnumerable OnExit => DummyInvocations(); From 2ffd098cf57754c89a1d17cf2006874e1e01e007 Mon Sep 17 00:00:00 2001 From: Xavrax Date: Tue, 23 Jan 2024 10:11:32 +0100 Subject: [PATCH 05/32] joined event --- .../Presence/Common/PresenceInput.cs | 24 +++++++++++++++++++ .../Presence/Events/PresenceEvents.cs | 7 +++--- .../Presence/States/APresenceState.cs | 8 +++---- .../Presence/States/CooldownState.cs | 4 ++++ .../Presence/States/FailedState.cs | 4 ++++ .../Presence/States/HeartBeatingState.cs | 4 ++++ .../Presence/States/InactiveState.cs | 7 ++++-- .../Presence/States/ReconnectingState.cs | 4 ++++ .../Presence/States/StoppedState.cs | 6 +++-- 9 files changed, 55 insertions(+), 13 deletions(-) create mode 100644 src/Api/PubnubApi/EventEngine/Presence/Common/PresenceInput.cs diff --git a/src/Api/PubnubApi/EventEngine/Presence/Common/PresenceInput.cs b/src/Api/PubnubApi/EventEngine/Presence/Common/PresenceInput.cs new file mode 100644 index 000000000..adacee656 --- /dev/null +++ b/src/Api/PubnubApi/EventEngine/Presence/Common/PresenceInput.cs @@ -0,0 +1,24 @@ +namespace PubnubApi.EventEngine.Presence.Common +{ + public class PresenceInput + { + public string[] Channels { get; set; } + public string[] ChannelGroups { get; set; } + + public static PresenceInput operator +(PresenceInput a, PresenceInput b) + { + return new PresenceInput + { + Channels = a.Channels?.Union(b.Channels ?? new string[0]).ToArray(), + ChannelGroups = a.ChannelGroups?.Union(b.ChannelGroups ?? new string[0]).ToArray(), + }; + } + + public bool IsEmpty() + { + return (Channels == null && ChannelGroups == null) + || ((Channels != null && Channels.Count() == 0) + && (ChannelGroups != null && ChannelGroups.Count() == 0)); + } + } +} diff --git a/src/Api/PubnubApi/EventEngine/Presence/Events/PresenceEvents.cs b/src/Api/PubnubApi/EventEngine/Presence/Events/PresenceEvents.cs index c94a82ec3..87458fef2 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/Events/PresenceEvents.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/Events/PresenceEvents.cs @@ -1,17 +1,16 @@ using System.Collections.Generic; using PubnubApi.Model.Consumer.PNStatus; +using PubnubApi.EventEngine.Presence.Common; namespace PubnubApi.EventEngine.Presence.Events { public class JoinedEvent : Core.IEvent { - public IEnumerable Channels { get; set; } - public IEnumerable ChannelGroups { get; set; } + public PresenceInput Input { get; set; } } public class LeftEvent : Core.IEvent { - public IEnumerable Channels { get; set; } - public IEnumerable ChannelGroups { get; set; } + public PresenceInput Input { get; set; } } public class LeftAllEvent : Core.IEvent {} diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/APresenceState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/APresenceState.cs index 63bdecd75..dfc82407c 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/APresenceState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/APresenceState.cs @@ -1,17 +1,15 @@ using PubnubApi.EventEngine.Core; +using PubnubApi.EventEngine.Presence.Common; namespace PubnubApi.EventEngine.Presence.States { public abstract class APresenceState : Core.State { - public IEnumerable Channels { get; set; } - public IEnumerable ChannelGroups { get; set; } + public PresenceInput Input { get; set; } public bool IsEmpty() { - return (Channels == null && ChannelGroups == null) - || ((Channels != null && Channels.Count() == 0) - && (ChannelGroups != null && ChannelGroups.Count() == 0)); + return Input.IsEmpty(); } } } diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/CooldownState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/CooldownState.cs index 6602355f0..dd73d721b 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/CooldownState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/CooldownState.cs @@ -14,6 +14,10 @@ public override TransitionResult Transition(Transition transition) { return e switch { + Events.JoinedEvent e => new HeartbeatingState() + { + Input = e.Input != this.Input ? this.Input + e.Input : this.Input, + }, _ => null, }; } diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/FailedState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/FailedState.cs index c793831b2..e1b55f990 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/FailedState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/FailedState.cs @@ -16,6 +16,10 @@ public override TransitionResult Transition(Transition transition) { return e switch { + Events.JoinedEvent e => new HeartbeatingState() + { + Input = e.Input != this.Input ? this.Input + e.Input : this.Input, + }, _ => null, }; } diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/HeartBeatingState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/HeartBeatingState.cs index ecc20ace9..c55a34184 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/HeartBeatingState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/HeartBeatingState.cs @@ -14,6 +14,10 @@ public override TransitionResult Transition(Transition transition) { return e switch { + Events.JoinedEvent e => new HeartbeatingState() + { + Input = e.Input != this.Input ? this.Input + e.Input : this.Input, + }, _ => null, }; } diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/InactiveState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/InactiveState.cs index 9c0e7d066..cf2eae9a7 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/InactiveState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/InactiveState.cs @@ -7,8 +7,7 @@ public class InactiveState : APresenceState { public InactiveState() { - Channels = null; - ChannelGroups = null; + Input = null; } // TODO: Dummy Invocation until we have real ones @@ -20,6 +19,10 @@ public override TransitionResult Transition(Transition transition) { return e switch { + Events.JoinedEvent e => new HeartbeatingState() + { + Input = e.Input, + }, _ => null, }; } diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/ReconnectingState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/ReconnectingState.cs index 6b0064a1c..7fc6b0247 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/ReconnectingState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/ReconnectingState.cs @@ -16,6 +16,10 @@ public override TransitionResult Transition(Transition transition) { return e switch { + Events.JoinedEvent e => new HeartbeatingState() + { + Input = e.Input != this.Input ? this.Input + e.Input : this.Input, + }, _ => null, }; } diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/StoppedState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/StoppedState.cs index 257dc42fe..7153e7733 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/StoppedState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/StoppedState.cs @@ -5,8 +5,6 @@ namespace PubnubApi.EventEngine.Presence.States { public class StoppedState : APresenceState { - public PNStatus reason { get; set; } - // TODO: Dummy Invocation until we have real ones public override IEnumerable OnEntry => DummyInvocations(); public override IEnumerable OnExit => DummyInvocations(); @@ -16,6 +14,10 @@ public override TransitionResult Transition(Transition transition) { return e switch { + Events.JoinedEvent e => new StoppedState() + { + Input = e.Input != this.Input ? this.Input + e.Input : this.Input, + }, _ => null, }; } From f61a79a28c0e22ad4d8950a94803ff8f6f13c62a Mon Sep 17 00:00:00 2001 From: Xavrax Date: Tue, 23 Jan 2024 11:18:16 +0100 Subject: [PATCH 06/32] Left event --- .../EventEngine/Presence/Common/PresenceInput.cs | 9 +++++++++ .../EventEngine/Presence/States/CooldownState.cs | 11 ++++++++++- .../EventEngine/Presence/States/FailedState.cs | 10 ++++++++++ .../EventEngine/Presence/States/HeartBeatingState.cs | 10 ++++++++++ .../EventEngine/Presence/States/ReconnectingState.cs | 12 +++++++++++- .../EventEngine/Presence/States/StoppedState.cs | 12 +++++++++++- 6 files changed, 61 insertions(+), 3 deletions(-) diff --git a/src/Api/PubnubApi/EventEngine/Presence/Common/PresenceInput.cs b/src/Api/PubnubApi/EventEngine/Presence/Common/PresenceInput.cs index adacee656..b3b296305 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/Common/PresenceInput.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/Common/PresenceInput.cs @@ -14,6 +14,15 @@ public class PresenceInput }; } + public static PresenceInput operator -(PresenceInput a, PresenceInput b) + { + return new PresenceInput + { + Channels = a.Channels?.Except(b.Channels ?? new string[0]).ToArray(), + ChannelGroups = a.ChannelGroups?.Except(b.ChannelGroups ?? new string[0]).ToArray(), + }; + } + public bool IsEmpty() { return (Channels == null && ChannelGroups == null) diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/CooldownState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/CooldownState.cs index dd73d721b..e4ded9fe4 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/CooldownState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/CooldownState.cs @@ -18,9 +18,18 @@ public override TransitionResult Transition(Transition transition) { Input = e.Input != this.Input ? this.Input + e.Input : this.Input, }, + Events.LeftEvent e => () => { + var newInput = this.Input - e.Input; + + return newInput.IsEmpty() + ? new InactiveState() + : new HeartbeatingState() + { + Input = newInput, + }; + }, _ => null, }; } } - } diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/FailedState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/FailedState.cs index e1b55f990..3798a7c73 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/FailedState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/FailedState.cs @@ -20,6 +20,16 @@ public override TransitionResult Transition(Transition transition) { Input = e.Input != this.Input ? this.Input + e.Input : this.Input, }, + Events.LeftEvent e => () => { + var newInput = this.Input - e.Input; + + return newInput.IsEmpty() + ? new InactiveState() + : new HeartbeatingState() + { + Input = newInput, + }; + }, _ => null, }; } diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/HeartBeatingState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/HeartBeatingState.cs index c55a34184..0a20d615a 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/HeartBeatingState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/HeartBeatingState.cs @@ -18,6 +18,16 @@ public override TransitionResult Transition(Transition transition) { Input = e.Input != this.Input ? this.Input + e.Input : this.Input, }, + Events.LeftEvent e => () => { + var newInput = this.Input - e.Input; + + return newInput.IsEmpty() + ? new InactiveState() + : new HeartbeatingState() + { + Input = newInput, + }; + }, _ => null, }; } diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/ReconnectingState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/ReconnectingState.cs index 7fc6b0247..7e2380909 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/ReconnectingState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/ReconnectingState.cs @@ -20,7 +20,17 @@ public override TransitionResult Transition(Transition transition) { Input = e.Input != this.Input ? this.Input + e.Input : this.Input, }, - _ => null, + Events.LeftEvent e => () => { + var newInput = this.Input - e.Input; + + return newInput.IsEmpty() + ? new InactiveState() + : new HeartbeatingState() + { + Input = newInput, + }; + }, + _ => null, }; } } diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/StoppedState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/StoppedState.cs index 7153e7733..a9cf19661 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/StoppedState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/StoppedState.cs @@ -18,7 +18,17 @@ public override TransitionResult Transition(Transition transition) { Input = e.Input != this.Input ? this.Input + e.Input : this.Input, }, - _ => null, + Events.LeftEvent e => () => { + var newInput = this.Input - e.Input; + + return newInput.IsEmpty() + ? new InactiveState() + : new StoppedState() + { + Input = newInput, + }; + }, + _ => null, }; } } From 3798d8b9a084409a5ef02bb6f422b61565e2d6b4 Mon Sep 17 00:00:00 2001 From: Xavrax Date: Tue, 23 Jan 2024 11:20:54 +0100 Subject: [PATCH 07/32] left all --- src/Api/PubnubApi/EventEngine/Presence/States/CooldownState.cs | 1 + src/Api/PubnubApi/EventEngine/Presence/States/FailedState.cs | 1 + .../PubnubApi/EventEngine/Presence/States/HeartBeatingState.cs | 1 + .../PubnubApi/EventEngine/Presence/States/ReconnectingState.cs | 1 + src/Api/PubnubApi/EventEngine/Presence/States/StoppedState.cs | 1 + 5 files changed, 5 insertions(+) diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/CooldownState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/CooldownState.cs index e4ded9fe4..8b613130a 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/CooldownState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/CooldownState.cs @@ -28,6 +28,7 @@ public override TransitionResult Transition(Transition transition) Input = newInput, }; }, + Events.LeftAllEvent e => new InactiveState(), _ => null, }; } diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/FailedState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/FailedState.cs index 3798a7c73..f0382f0c4 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/FailedState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/FailedState.cs @@ -30,6 +30,7 @@ public override TransitionResult Transition(Transition transition) Input = newInput, }; }, + Events.LeftAllEvent e => new InactiveState(), _ => null, }; } diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/HeartBeatingState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/HeartBeatingState.cs index 0a20d615a..4f4672ed3 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/HeartBeatingState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/HeartBeatingState.cs @@ -28,6 +28,7 @@ public override TransitionResult Transition(Transition transition) Input = newInput, }; }, + Events.LeftAllEvent e => new InactiveState(), _ => null, }; } diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/ReconnectingState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/ReconnectingState.cs index 7e2380909..fbc22b058 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/ReconnectingState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/ReconnectingState.cs @@ -30,6 +30,7 @@ public override TransitionResult Transition(Transition transition) Input = newInput, }; }, + Events.LeftAllEvent e => new InactiveState(), _ => null, }; } diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/StoppedState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/StoppedState.cs index a9cf19661..a8603f9e1 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/StoppedState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/StoppedState.cs @@ -28,6 +28,7 @@ public override TransitionResult Transition(Transition transition) Input = newInput, }; }, + Events.LeftAllEvent e => new InactiveState(), _ => null, }; } From 13b22a86323cc18b2882dd057fd6d86df4721aea Mon Sep 17 00:00:00 2001 From: Xavrax Date: Tue, 23 Jan 2024 11:23:01 +0100 Subject: [PATCH 08/32] fix function param --- src/Api/PubnubApi/EventEngine/Presence/States/CooldownState.cs | 2 +- src/Api/PubnubApi/EventEngine/Presence/States/FailedState.cs | 2 +- .../PubnubApi/EventEngine/Presence/States/HeartBeatingState.cs | 2 +- src/Api/PubnubApi/EventEngine/Presence/States/InactiveState.cs | 2 +- .../PubnubApi/EventEngine/Presence/States/ReconnectingState.cs | 2 +- src/Api/PubnubApi/EventEngine/Presence/States/StoppedState.cs | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/CooldownState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/CooldownState.cs index 8b613130a..89fdb4ac6 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/CooldownState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/CooldownState.cs @@ -10,7 +10,7 @@ public class CooldownState : APresenceState public override IEnumerable OnExit => DummyInvocations(); // TODO: transitions - public override TransitionResult Transition(Transition transition) + public override TransitionResult Transition(IEvent e) { return e switch { diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/FailedState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/FailedState.cs index f0382f0c4..2170bab30 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/FailedState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/FailedState.cs @@ -12,7 +12,7 @@ public class FailedState : APresenceState public override IEnumerable OnExit => DummyInvocations(); // TODO: transitions - public override TransitionResult Transition(Transition transition) + public override TransitionResult Transition(IEvent e) { return e switch { diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/HeartBeatingState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/HeartBeatingState.cs index 4f4672ed3..25698b0ef 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/HeartBeatingState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/HeartBeatingState.cs @@ -10,7 +10,7 @@ public class HeartbeatingState : APresenceState public override IEnumerable OnExit => DummyInvocations(); // TODO: transitions - public override TransitionResult Transition(Transition transition) + public override TransitionResult Transition(IEvent e) { return e switch { diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/InactiveState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/InactiveState.cs index cf2eae9a7..b5fb8012f 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/InactiveState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/InactiveState.cs @@ -15,7 +15,7 @@ public InactiveState() public override IEnumerable OnExit => DummyInvocations(); // TODO: transitions - public override TransitionResult Transition(Transition transition) + public override TransitionResult Transition(IEvent e) { return e switch { diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/ReconnectingState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/ReconnectingState.cs index fbc22b058..818bfe6ea 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/ReconnectingState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/ReconnectingState.cs @@ -12,7 +12,7 @@ public class ReconnectingState : APresenceState public override IEnumerable OnExit => DummyInvocations(); // TODO: transitions - public override TransitionResult Transition(Transition transition) + public override TransitionResult Transition(IEvent e) { return e switch { diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/StoppedState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/StoppedState.cs index a8603f9e1..6b8776e16 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/StoppedState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/StoppedState.cs @@ -10,7 +10,7 @@ public class StoppedState : APresenceState public override IEnumerable OnExit => DummyInvocations(); // TODO: transitions - public override TransitionResult Transition(Transition transition) + public override TransitionResult Transition(IEvent e) { return e switch { From edc602a35c392f1248a93408457240812b52a09b Mon Sep 17 00:00:00 2001 From: Xavrax Date: Tue, 23 Jan 2024 12:05:23 +0100 Subject: [PATCH 09/32] hb fail + transition fix --- .../Presence/Events/PresenceEvents.cs | 2 +- .../Presence/States/CooldownState.cs | 7 ++++++- .../Presence/States/FailedState.cs | 2 +- .../Presence/States/HeartBeatingState.cs | 14 ++++++++++++- .../Presence/States/ReconnectingState.cs | 21 +++++++++++++++++-- .../Presence/States/StoppedState.cs | 2 +- 6 files changed, 41 insertions(+), 7 deletions(-) diff --git a/src/Api/PubnubApi/EventEngine/Presence/Events/PresenceEvents.cs b/src/Api/PubnubApi/EventEngine/Presence/Events/PresenceEvents.cs index 87458fef2..598d1a018 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/Events/PresenceEvents.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/Events/PresenceEvents.cs @@ -1,5 +1,5 @@ using System.Collections.Generic; -using PubnubApi.Model.Consumer.PNStatus; +using PubnubApi; using PubnubApi.EventEngine.Presence.Common; namespace PubnubApi.EventEngine.Presence.Events { diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/CooldownState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/CooldownState.cs index 89fdb4ac6..0b89796b8 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/CooldownState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/CooldownState.cs @@ -1,3 +1,4 @@ +using PubnubApi; using PubnubApi.EventEngine.Presence.Invocations; using PubnubApi.EventEngine.Core; @@ -28,7 +29,11 @@ public override TransitionResult Transition(IEvent e) Input = newInput, }; }, - Events.LeftAllEvent e => new InactiveState(), + Events.LeftAllEvent => new InactiveState(), + Events.HeartbeatSuccessEvent => new CooldownState() + { + Input = this.Input, + }, _ => null, }; } diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/FailedState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/FailedState.cs index 2170bab30..144dd931e 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/FailedState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/FailedState.cs @@ -30,7 +30,7 @@ public override TransitionResult Transition(IEvent e) Input = newInput, }; }, - Events.LeftAllEvent e => new InactiveState(), + Events.LeftAllEvent => new InactiveState(), _ => null, }; } diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/HeartBeatingState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/HeartBeatingState.cs index 25698b0ef..d01886c07 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/HeartBeatingState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/HeartBeatingState.cs @@ -28,7 +28,19 @@ public override TransitionResult Transition(IEvent e) Input = newInput, }; }, - Events.LeftAllEvent e => new InactiveState(), + Events.LeftAllEvent => new InactiveState(), + Events.HeartbeatFailureEvent e => () => { + // Request cancellation shouldn't cause any transition because there + // will be another event after this. + return e.Status.Category == PNStatusCategory.PNCancelledCategory + ? null + : new ReconnectingState() + { + Input = this.Input, + RetryCount = 1, + Reason = e.Status, + }; + }, _ => null, }; } diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/ReconnectingState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/ReconnectingState.cs index 818bfe6ea..2358a28f0 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/ReconnectingState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/ReconnectingState.cs @@ -6,6 +6,7 @@ namespace PubnubApi.EventEngine.Presence.States public class ReconnectingState : APresenceState { public short RetryCount { get; set; } + public PNStatus Reason { get; set; } // TODO: Dummy Invocation until we have real ones public override IEnumerable OnEntry => DummyInvocations(); @@ -30,8 +31,24 @@ public override TransitionResult Transition(IEvent e) Input = newInput, }; }, - Events.LeftAllEvent e => new InactiveState(), - _ => null, + Events.LeftAllEvent => new InactiveState(), + Events.HeartbeatSuccessEvent => new CooldownState() + { + Input = this.Input, + }, + Events.HeartbeatFailureEvent e => () => { + // Request cancellation shouldn't cause any transition because there + // will be another event after this. + return e.Status.Category == PNStatusCategory.PNCancelledCategory + ? null + : new ReconnectingState() + { + Input = this.Input, + RetryCount = this.RetryCount + 1, + Reason = e.Status, + }; + }, + _ => null, }; } } diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/StoppedState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/StoppedState.cs index 6b8776e16..f003ae2be 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/StoppedState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/StoppedState.cs @@ -28,7 +28,7 @@ public override TransitionResult Transition(IEvent e) Input = newInput, }; }, - Events.LeftAllEvent e => new InactiveState(), + Events.LeftAllEvent => new InactiveState(), _ => null, }; } From 3f4ce7273d4a4ba0649429860957d46c29edd1e6 Mon Sep 17 00:00:00 2001 From: Xavrax Date: Tue, 23 Jan 2024 12:06:12 +0100 Subject: [PATCH 10/32] give up --- .../EventEngine/Presence/States/ReconnectingState.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/ReconnectingState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/ReconnectingState.cs index 2358a28f0..be9029bc9 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/ReconnectingState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/ReconnectingState.cs @@ -48,6 +48,11 @@ public override TransitionResult Transition(IEvent e) Reason = e.Status, }; }, + Events.HeartbeatGiveUpEvent => new FailedState() + { + Input = this.Input, + Reason = this.Reason, + }, _ => null, }; } From 3881560f814a64dd5b8cd49a30181c6341f6dcce Mon Sep 17 00:00:00 2001 From: Xavrax Date: Tue, 23 Jan 2024 12:08:28 +0100 Subject: [PATCH 11/32] reconnect --- src/Api/PubnubApi/EventEngine/Presence/States/FailedState.cs | 4 ++++ src/Api/PubnubApi/EventEngine/Presence/States/StoppedState.cs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/FailedState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/FailedState.cs index 144dd931e..f43b36fba 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/FailedState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/FailedState.cs @@ -31,6 +31,10 @@ public override TransitionResult Transition(IEvent e) }; }, Events.LeftAllEvent => new InactiveState(), + Events.ReconnectEvent => new HeartbeatingState() + { + Input = this.Input, + }, _ => null, }; } diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/StoppedState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/StoppedState.cs index f003ae2be..38b5cb20c 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/StoppedState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/StoppedState.cs @@ -29,6 +29,10 @@ public override TransitionResult Transition(IEvent e) }; }, Events.LeftAllEvent => new InactiveState(), + Events.ReconnectEvent => new HeartbeatingState() + { + Input = this.Input, + }, _ => null, }; } From d0a12d346f26a3fcee1e5df04dc4c92c80f0aa21 Mon Sep 17 00:00:00 2001 From: Xavrax Date: Tue, 23 Jan 2024 12:10:41 +0100 Subject: [PATCH 12/32] disconnect --- .../PubnubApi/EventEngine/Presence/States/CooldownState.cs | 4 ++++ src/Api/PubnubApi/EventEngine/Presence/States/FailedState.cs | 4 ++++ .../EventEngine/Presence/States/HeartBeatingState.cs | 4 ++++ .../EventEngine/Presence/States/ReconnectingState.cs | 4 ++++ 4 files changed, 16 insertions(+) diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/CooldownState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/CooldownState.cs index 0b89796b8..cce78111b 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/CooldownState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/CooldownState.cs @@ -34,6 +34,10 @@ public override TransitionResult Transition(IEvent e) { Input = this.Input, }, + Events.DisconnectEvent => new StoppedState() + { + Input = this.Input, + }, _ => null, }; } diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/FailedState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/FailedState.cs index f43b36fba..88a633025 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/FailedState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/FailedState.cs @@ -35,6 +35,10 @@ public override TransitionResult Transition(IEvent e) { Input = this.Input, }, + Events.DisconnectEvent => new StoppedState() + { + Input = this.Input, + }, _ => null, }; } diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/HeartBeatingState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/HeartBeatingState.cs index d01886c07..ce47a7d22 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/HeartBeatingState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/HeartBeatingState.cs @@ -41,6 +41,10 @@ public override TransitionResult Transition(IEvent e) Reason = e.Status, }; }, + Events.DisconnectEvent => new StoppedState() + { + Input = this.Input, + }, _ => null, }; } diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/ReconnectingState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/ReconnectingState.cs index be9029bc9..26524b4be 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/ReconnectingState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/ReconnectingState.cs @@ -53,6 +53,10 @@ public override TransitionResult Transition(IEvent e) Input = this.Input, Reason = this.Reason, }, + Events.DisconnectEvent => new StoppedState() + { + Input = this.Input, + }, _ => null, }; } From d4c7a1e287190bd97d9e8cb560dcee21bde92cef Mon Sep 17 00:00:00 2001 From: Xavrax Date: Tue, 23 Jan 2024 12:12:21 +0100 Subject: [PATCH 13/32] timeup --- .../PubnubApi/EventEngine/Presence/States/CooldownState.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/CooldownState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/CooldownState.cs index cce78111b..b7ab2be16 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/CooldownState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/CooldownState.cs @@ -38,6 +38,10 @@ public override TransitionResult Transition(IEvent e) { Input = this.Input, }, + Events.TimesUpEvent => new HeartbeatingState() + { + Input = this.Input, + }, _ => null, }; } From 384ef5dd3829bea69e39458c0af7d926d80fa0b2 Mon Sep 17 00:00:00 2001 From: Xavrax Date: Tue, 23 Jan 2024 12:14:07 +0100 Subject: [PATCH 14/32] missing enumerable --- src/Api/PubnubApi/EventEngine/Presence/States/CooldownState.cs | 1 + src/Api/PubnubApi/EventEngine/Presence/States/FailedState.cs | 1 + .../PubnubApi/EventEngine/Presence/States/HeartBeatingState.cs | 1 + src/Api/PubnubApi/EventEngine/Presence/States/InactiveState.cs | 1 + .../PubnubApi/EventEngine/Presence/States/ReconnectingState.cs | 1 + src/Api/PubnubApi/EventEngine/Presence/States/StoppedState.cs | 1 + 6 files changed, 6 insertions(+) diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/CooldownState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/CooldownState.cs index b7ab2be16..e9dabcb2c 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/CooldownState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/CooldownState.cs @@ -1,6 +1,7 @@ using PubnubApi; using PubnubApi.EventEngine.Presence.Invocations; using PubnubApi.EventEngine.Core; +using System.Collections.Generic; namespace PubnubApi.EventEngine.Presence.States { diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/FailedState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/FailedState.cs index 88a633025..7cc728a82 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/FailedState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/FailedState.cs @@ -1,5 +1,6 @@ using PubnubApi.EventEngine.Presence.Invocations; using PubnubApi.EventEngine.Core; +using System.Collections.Generic; namespace PubnubApi.EventEngine.Presence.States { diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/HeartBeatingState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/HeartBeatingState.cs index ce47a7d22..e76624df5 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/HeartBeatingState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/HeartBeatingState.cs @@ -1,5 +1,6 @@ using PubnubApi.EventEngine.Presence.Invocations; using PubnubApi.EventEngine.Core; +using System.Collections.Generic; namespace PubnubApi.EventEngine.Presence.States { diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/InactiveState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/InactiveState.cs index b5fb8012f..457d60ec4 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/InactiveState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/InactiveState.cs @@ -1,5 +1,6 @@ using PubnubApi.EventEngine.Presence.Invocations; using PubnubApi.EventEngine.Core; +using System.Collections.Generic; namespace PubnubApi.EventEngine.Presence.States { diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/ReconnectingState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/ReconnectingState.cs index 26524b4be..8073bb8ce 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/ReconnectingState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/ReconnectingState.cs @@ -1,5 +1,6 @@ using PubnubApi.EventEngine.Presence.Invocations; using PubnubApi.EventEngine.Core; +using System.Collections.Generic; namespace PubnubApi.EventEngine.Presence.States { diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/StoppedState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/StoppedState.cs index 38b5cb20c..ae304483b 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/StoppedState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/StoppedState.cs @@ -1,5 +1,6 @@ using PubnubApi.EventEngine.Presence.Invocations; using PubnubApi.EventEngine.Core; +using System.Collections.Generic; namespace PubnubApi.EventEngine.Presence.States { From e371d5985146f43f4a1e3d927acc1b9ee7c1169e Mon Sep 17 00:00:00 2001 From: Xavrax Date: Tue, 23 Jan 2024 13:28:17 +0100 Subject: [PATCH 15/32] building should work --- .../Presence/Common/PresenceInput.cs | 19 ++++--- .../EventEngine/Presence/Invocations/Dummy.cs | 6 -- .../Presence/States/APresenceState.cs | 12 ++++ .../Presence/States/CooldownState.cs | 28 ++++------ .../Presence/States/FailedState.cs | 26 +++------ .../Presence/States/HeartBeatingState.cs | 49 +++++++---------- .../Presence/States/InactiveState.cs | 9 +-- .../Presence/States/ReconnectingState.cs | 55 ++++++++----------- .../Presence/States/StoppedState.cs | 38 +++++++------ 9 files changed, 113 insertions(+), 129 deletions(-) diff --git a/src/Api/PubnubApi/EventEngine/Presence/Common/PresenceInput.cs b/src/Api/PubnubApi/EventEngine/Presence/Common/PresenceInput.cs index b3b296305..2478ae4b1 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/Common/PresenceInput.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/Common/PresenceInput.cs @@ -1,16 +1,19 @@ +using System.Collections.Generic; +using System.Linq; + namespace PubnubApi.EventEngine.Presence.Common { public class PresenceInput { - public string[] Channels { get; set; } - public string[] ChannelGroups { get; set; } + public List Channels { get; set; } + public List ChannelGroups { get; set; } public static PresenceInput operator +(PresenceInput a, PresenceInput b) { return new PresenceInput { - Channels = a.Channels?.Union(b.Channels ?? new string[0]).ToArray(), - ChannelGroups = a.ChannelGroups?.Union(b.ChannelGroups ?? new string[0]).ToArray(), + Channels = a.Channels?.Union(b.Channels ?? new List()).ToList(), + ChannelGroups = a.ChannelGroups?.Union(b.ChannelGroups ?? new List()).ToList(), }; } @@ -18,16 +21,16 @@ public class PresenceInput { return new PresenceInput { - Channels = a.Channels?.Except(b.Channels ?? new string[0]).ToArray(), - ChannelGroups = a.ChannelGroups?.Except(b.ChannelGroups ?? new string[0]).ToArray(), + Channels = a.Channels?.Except(b.Channels ?? new List()).ToList(), + ChannelGroups = a.ChannelGroups?.Except(b.ChannelGroups ?? new List()).ToList(), }; } public bool IsEmpty() { return (Channels == null && ChannelGroups == null) - || ((Channels != null && Channels.Count() == 0) - && (ChannelGroups != null && ChannelGroups.Count() == 0)); + || ((Channels != null && Channels.Count == 0) + && (ChannelGroups != null && ChannelGroups.Count == 0)); } } } diff --git a/src/Api/PubnubApi/EventEngine/Presence/Invocations/Dummy.cs b/src/Api/PubnubApi/EventEngine/Presence/Invocations/Dummy.cs index db39ac82a..0e6059c0b 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/Invocations/Dummy.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/Invocations/Dummy.cs @@ -1,10 +1,4 @@ // TODO: Dummy Invocation until we have real ones namespace PubnubApi.EventEngine.Presence.Invocations { public class DummyInvocation : Core.IEffectInvocation {} - - DummyInvocation[] DummyInvocations() { - return new DummyInvocation[] { - new DummyInvocation(), - }; - } } diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/APresenceState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/APresenceState.cs index dfc82407c..18d4453c9 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/APresenceState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/APresenceState.cs @@ -11,5 +11,17 @@ public bool IsEmpty() { return Input.IsEmpty(); } + + protected TransitionResult HandleLeftEvent(Events.LeftEvent e) + { + var newInput = this.Input - e.Input; + + return newInput.IsEmpty() + ? (TransitionResult)new InactiveState() + : (TransitionResult)new HeartbeatingState() + { + Input = newInput, + }; + } } } diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/CooldownState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/CooldownState.cs index e9dabcb2c..57f8bd81a 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/CooldownState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/CooldownState.cs @@ -2,44 +2,36 @@ using PubnubApi.EventEngine.Presence.Invocations; using PubnubApi.EventEngine.Core; using System.Collections.Generic; +using System; namespace PubnubApi.EventEngine.Presence.States { public class CooldownState : APresenceState { // TODO: Dummy Invocation until we have real ones - public override IEnumerable OnEntry => DummyInvocations(); - public override IEnumerable OnExit => DummyInvocations(); + public override IEnumerable OnEntry => new DummyInvocation().AsArray(); + public override IEnumerable OnExit => new DummyInvocation().AsArray(); // TODO: transitions - public override TransitionResult Transition(IEvent e) + public override TransitionResult Transition(IEvent ev) { - return e switch + return ev switch { Events.JoinedEvent e => new HeartbeatingState() { Input = e.Input != this.Input ? this.Input + e.Input : this.Input, }, - Events.LeftEvent e => () => { - var newInput = this.Input - e.Input; - - return newInput.IsEmpty() - ? new InactiveState() - : new HeartbeatingState() - { - Input = newInput, - }; - }, - Events.LeftAllEvent => new InactiveState(), - Events.HeartbeatSuccessEvent => new CooldownState() + Events.LeftEvent e => HandleLeftEvent(e), + Events.LeftAllEvent e => new InactiveState(), + Events.HeartbeatSuccessEvent e => new CooldownState() { Input = this.Input, }, - Events.DisconnectEvent => new StoppedState() + Events.DisconnectEvent e => new StoppedState() { Input = this.Input, }, - Events.TimesUpEvent => new HeartbeatingState() + Events.TimesUpEvent e => new HeartbeatingState() { Input = this.Input, }, diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/FailedState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/FailedState.cs index 7cc728a82..8eefb7245 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/FailedState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/FailedState.cs @@ -1,6 +1,7 @@ using PubnubApi.EventEngine.Presence.Invocations; using PubnubApi.EventEngine.Core; using System.Collections.Generic; +using System; namespace PubnubApi.EventEngine.Presence.States { @@ -9,34 +10,25 @@ public class FailedState : APresenceState public PNStatus Reason { get; set; } // TODO: Dummy Invocation until we have real ones - public override IEnumerable OnEntry => DummyInvocations(); - public override IEnumerable OnExit => DummyInvocations(); + public override IEnumerable OnEntry => new DummyInvocation().AsArray(); + public override IEnumerable OnExit => new DummyInvocation().AsArray(); // TODO: transitions - public override TransitionResult Transition(IEvent e) + public override TransitionResult Transition(IEvent ev) { - return e switch + return ev switch { Events.JoinedEvent e => new HeartbeatingState() { Input = e.Input != this.Input ? this.Input + e.Input : this.Input, }, - Events.LeftEvent e => () => { - var newInput = this.Input - e.Input; - - return newInput.IsEmpty() - ? new InactiveState() - : new HeartbeatingState() - { - Input = newInput, - }; - }, - Events.LeftAllEvent => new InactiveState(), - Events.ReconnectEvent => new HeartbeatingState() + Events.LeftEvent e => HandleLeftEvent(e), + Events.LeftAllEvent e => new InactiveState(), + Events.ReconnectEvent e => new HeartbeatingState() { Input = this.Input, }, - Events.DisconnectEvent => new StoppedState() + Events.DisconnectEvent e => new StoppedState() { Input = this.Input, }, diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/HeartBeatingState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/HeartBeatingState.cs index e76624df5..b461cbced 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/HeartBeatingState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/HeartBeatingState.cs @@ -1,54 +1,47 @@ using PubnubApi.EventEngine.Presence.Invocations; using PubnubApi.EventEngine.Core; using System.Collections.Generic; +using System; namespace PubnubApi.EventEngine.Presence.States { public class HeartbeatingState : APresenceState { // TODO: Dummy Invocation until we have real ones - public override IEnumerable OnEntry => DummyInvocations(); - public override IEnumerable OnExit => DummyInvocations(); + public override IEnumerable OnEntry => new DummyInvocation().AsArray(); + public override IEnumerable OnExit => new DummyInvocation().AsArray(); // TODO: transitions - public override TransitionResult Transition(IEvent e) + public override TransitionResult Transition(IEvent ev) { - return e switch + return ev switch { Events.JoinedEvent e => new HeartbeatingState() { Input = e.Input != this.Input ? this.Input + e.Input : this.Input, }, - Events.LeftEvent e => () => { - var newInput = this.Input - e.Input; - - return newInput.IsEmpty() - ? new InactiveState() - : new HeartbeatingState() - { - Input = newInput, - }; - }, - Events.LeftAllEvent => new InactiveState(), - Events.HeartbeatFailureEvent e => () => { - // Request cancellation shouldn't cause any transition because there - // will be another event after this. - return e.Status.Category == PNStatusCategory.PNCancelledCategory - ? null - : new ReconnectingState() - { - Input = this.Input, - RetryCount = 1, - Reason = e.Status, - }; - }, - Events.DisconnectEvent => new StoppedState() + Events.LeftEvent e => HandleLeftEvent(e), + Events.LeftAllEvent e => new InactiveState(), + Events.HeartbeatFailureEvent e => HandleHeartbeatFailureEvent(e), + Events.DisconnectEvent e => new StoppedState() { Input = this.Input, }, _ => null, }; } + + private TransitionResult HandleHeartbeatFailureEvent(Events.HeartbeatFailureEvent e) + { + return e.Status.Category == PNStatusCategory.PNCancelledCategory + ? (TransitionResult)null + : (TransitionResult)new ReconnectingState() + { + Input = this.Input, + RetryCount = 1, + Reason = e.Status, + }; + } } } diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/InactiveState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/InactiveState.cs index 457d60ec4..74f4f238c 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/InactiveState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/InactiveState.cs @@ -1,6 +1,7 @@ using PubnubApi.EventEngine.Presence.Invocations; using PubnubApi.EventEngine.Core; using System.Collections.Generic; +using System; namespace PubnubApi.EventEngine.Presence.States { @@ -12,13 +13,13 @@ public InactiveState() } // TODO: Dummy Invocation until we have real ones - public override IEnumerable OnEntry => DummyInvocations(); - public override IEnumerable OnExit => DummyInvocations(); + public override IEnumerable OnEntry => new DummyInvocation().AsArray(); + public override IEnumerable OnExit => new DummyInvocation().AsArray(); // TODO: transitions - public override TransitionResult Transition(IEvent e) + public override TransitionResult Transition(IEvent ev) { - return e switch + return ev switch { Events.JoinedEvent e => new HeartbeatingState() { diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/ReconnectingState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/ReconnectingState.cs index 8073bb8ce..4ef39e747 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/ReconnectingState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/ReconnectingState.cs @@ -1,66 +1,59 @@ using PubnubApi.EventEngine.Presence.Invocations; using PubnubApi.EventEngine.Core; using System.Collections.Generic; +using System; namespace PubnubApi.EventEngine.Presence.States { public class ReconnectingState : APresenceState { - public short RetryCount { get; set; } + public int RetryCount { get; set; } public PNStatus Reason { get; set; } // TODO: Dummy Invocation until we have real ones - public override IEnumerable OnEntry => DummyInvocations(); - public override IEnumerable OnExit => DummyInvocations(); + public override IEnumerable OnEntry => new DummyInvocation().AsArray(); + public override IEnumerable OnExit => new DummyInvocation().AsArray(); // TODO: transitions - public override TransitionResult Transition(IEvent e) + public override TransitionResult Transition(IEvent ev) { - return e switch + return ev switch { Events.JoinedEvent e => new HeartbeatingState() { Input = e.Input != this.Input ? this.Input + e.Input : this.Input, }, - Events.LeftEvent e => () => { - var newInput = this.Input - e.Input; - - return newInput.IsEmpty() - ? new InactiveState() - : new HeartbeatingState() - { - Input = newInput, - }; - }, - Events.LeftAllEvent => new InactiveState(), - Events.HeartbeatSuccessEvent => new CooldownState() + Events.LeftEvent e => HandleLeftEvent(e), + Events.LeftAllEvent e => new InactiveState(), + Events.HeartbeatSuccessEvent e => new CooldownState() { Input = this.Input, }, - Events.HeartbeatFailureEvent e => () => { - // Request cancellation shouldn't cause any transition because there - // will be another event after this. - return e.Status.Category == PNStatusCategory.PNCancelledCategory - ? null - : new ReconnectingState() - { - Input = this.Input, - RetryCount = this.RetryCount + 1, - Reason = e.Status, - }; - }, - Events.HeartbeatGiveUpEvent => new FailedState() + Events.HeartbeatFailureEvent e => HandleHeartbeatFailureEvent(e), + Events.HeartbeatGiveUpEvent e => new FailedState() { Input = this.Input, Reason = this.Reason, }, - Events.DisconnectEvent => new StoppedState() + Events.DisconnectEvent e => new StoppedState() { Input = this.Input, }, _ => null, }; } + + private TransitionResult HandleHeartbeatFailureEvent(Events.HeartbeatFailureEvent e) + { + return e.Status.Category == PNStatusCategory.PNCancelledCategory + ? (TransitionResult)null + : (TransitionResult)new ReconnectingState() + { + Input = this.Input, + RetryCount = this.RetryCount + 1, + Reason = e.Status, + }; + } } } diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/StoppedState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/StoppedState.cs index ae304483b..5e8751b43 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/StoppedState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/StoppedState.cs @@ -1,42 +1,46 @@ using PubnubApi.EventEngine.Presence.Invocations; using PubnubApi.EventEngine.Core; using System.Collections.Generic; +using System; namespace PubnubApi.EventEngine.Presence.States { public class StoppedState : APresenceState { - // TODO: Dummy Invocation until we have real ones - public override IEnumerable OnEntry => DummyInvocations(); - public override IEnumerable OnExit => DummyInvocations(); + // TODO: Dummy Invocation until we have real ones + public override IEnumerable OnEntry => new DummyInvocation().AsArray(); + public override IEnumerable OnExit => new DummyInvocation().AsArray(); // TODO: transitions - public override TransitionResult Transition(IEvent e) + public override TransitionResult Transition(IEvent ev) { - return e switch + return ev switch { Events.JoinedEvent e => new StoppedState() { Input = e.Input != this.Input ? this.Input + e.Input : this.Input, }, - Events.LeftEvent e => () => { - var newInput = this.Input - e.Input; - - return newInput.IsEmpty() - ? new InactiveState() - : new StoppedState() - { - Input = newInput, - }; - }, - Events.LeftAllEvent => new InactiveState(), - Events.ReconnectEvent => new HeartbeatingState() + Events.LeftEvent e => HandleLeftEvent(e), + Events.LeftAllEvent e => new InactiveState(), + Events.ReconnectEvent e => new HeartbeatingState() { Input = this.Input, }, _ => null, }; } + + protected TransitionResult HandleLeftEvent(Events.LeftEvent e) + { + var newInput = this.Input - e.Input; + + return newInput.IsEmpty() + ? (TransitionResult)new InactiveState() + : (TransitionResult)new StoppedState() + { + Input = newInput, + }; + } } } From c6bcba0140875734b7134c58461a5c24a1186afd Mon Sep 17 00:00:00 2001 From: Xavrax Date: Tue, 23 Jan 2024 14:03:18 +0100 Subject: [PATCH 16/32] enumerable instead of list --- .../EventEngine/Presence/Common/PresenceInput.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Api/PubnubApi/EventEngine/Presence/Common/PresenceInput.cs b/src/Api/PubnubApi/EventEngine/Presence/Common/PresenceInput.cs index 2478ae4b1..d1023f128 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/Common/PresenceInput.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/Common/PresenceInput.cs @@ -5,15 +5,15 @@ namespace PubnubApi.EventEngine.Presence.Common { public class PresenceInput { - public List Channels { get; set; } - public List ChannelGroups { get; set; } + public IEnumerable Channels { get; set; } + public IEnumerable ChannelGroups { get; set; } public static PresenceInput operator +(PresenceInput a, PresenceInput b) { return new PresenceInput { - Channels = a.Channels?.Union(b.Channels ?? new List()).ToList(), - ChannelGroups = a.ChannelGroups?.Union(b.ChannelGroups ?? new List()).ToList(), + Channels = a.Channels?.Union(b.Channels ?? new string[0]), + ChannelGroups = a.ChannelGroups?.Union(b.ChannelGroups ?? new string[0]), }; } @@ -21,16 +21,16 @@ public class PresenceInput { return new PresenceInput { - Channels = a.Channels?.Except(b.Channels ?? new List()).ToList(), - ChannelGroups = a.ChannelGroups?.Except(b.ChannelGroups ?? new List()).ToList(), + Channels = a.Channels?.Except(b.Channels ?? new string[0]), + ChannelGroups = a.ChannelGroups?.Except(b.ChannelGroups ?? new string[0]), }; } public bool IsEmpty() { return (Channels == null && ChannelGroups == null) - || ((Channels != null && Channels.Count == 0) - && (ChannelGroups != null && ChannelGroups.Count == 0)); + || ((Channels != null && Channels.Count() == 0) + && (ChannelGroups != null && ChannelGroups.Count() == 0)); } } } From 9cb95a5275fdd3824ebe946f395f23d231886064 Mon Sep 17 00:00:00 2001 From: Xavrax Date: Tue, 23 Jan 2024 14:55:37 +0100 Subject: [PATCH 17/32] add UT --- .../EventEngine/Presence/CooldownState.cs | 70 +++++++++++++++++ .../EventEngine/Presence/FailedState.cs | 70 +++++++++++++++++ .../EventEngine/Presence/HeartbeatingState.cs | 70 +++++++++++++++++ .../EventEngine/Presence/InactiveState.cs | 65 ++++++++++++++++ .../EventEngine/Presence/ReconnectingState.cs | 75 +++++++++++++++++++ .../EventEngine/Presence/StoppedState.cs | 70 +++++++++++++++++ 6 files changed, 420 insertions(+) create mode 100644 src/UnitTests/PubnubApi.Tests/EventEngine/Presence/CooldownState.cs create mode 100644 src/UnitTests/PubnubApi.Tests/EventEngine/Presence/FailedState.cs create mode 100644 src/UnitTests/PubnubApi.Tests/EventEngine/Presence/HeartbeatingState.cs create mode 100644 src/UnitTests/PubnubApi.Tests/EventEngine/Presence/InactiveState.cs create mode 100644 src/UnitTests/PubnubApi.Tests/EventEngine/Presence/ReconnectingState.cs create mode 100644 src/UnitTests/PubnubApi.Tests/EventEngine/Presence/StoppedState.cs diff --git a/src/UnitTests/PubnubApi.Tests/EventEngine/Presence/CooldownState.cs b/src/UnitTests/PubnubApi.Tests/EventEngine/Presence/CooldownState.cs new file mode 100644 index 000000000..41a920608 --- /dev/null +++ b/src/UnitTests/PubnubApi.Tests/EventEngine/Presence/CooldownState.cs @@ -0,0 +1,70 @@ +using NUnit.Framework; +using PubnubApi.EventEngine.Core; +using PubnubApi.EventEngine.Presence.Common; +using PubnubApi.EventEngine.Presence.Events; +using PubnubApi.EventEngine.Presence.States; + +namespace PubnubApi.Tests.EventEngine.Presence +{ + internal class CooldownTransitions + { + private static readonly object[] testCases = { + new object[] { + new CooldownState(), + new JoinedEvent() { Input = new PresenceInput() { Channels = new [] { "a" } } }, + new HeartbeatingState() { Input = new PresenceInput() { Channels = new [] { "a" } } }, + }, + new object[] { + new CooldownState() { Input = new PresenceInput() { Channels = new [] { "a", "b" } } }, + new LeftEvent() { Input = new PresenceInput() { Channels = new [] { "b" } } }, + new HeartbeatingState() { Input = new PresenceInput() { Channels = new [] { "a" } } }, + }, + new object[] { + new CooldownState() { Input = new PresenceInput() { Channels = new [] { "a" } } }, + new LeftEvent() { Input = new PresenceInput() { Channels = new [] { "a" } } }, + new InactiveState(), + }, + new object[] { + new CooldownState(), + new LeftAllEvent(), + new InactiveState(), + }, + new object[] { + new CooldownState(), + new HeartbeatSuccessEvent(), + null, + }, + new object[] { + new CooldownState(), + new HeartbeatFailureEvent() { Status = new PNStatus() }, + null, + }, + new object[] { + new CooldownState(), + new HeartbeatGiveUpEvent() { Status = new PNStatus() { Category = PNStatusCategory.PNCancelledCategory } }, + null, + }, + new object[] { + new CooldownState(), + new ReconnectEvent(), + null, + }, + new object[] { + new CooldownState(), + new DisconnectEvent(), + new StoppedState(), + }, + new object[] { + new CooldownState(), + new TimesUpEvent(), + new HeartbeatingState(), + }, + }; + + [TestCasesSource(nameof(testCases))] + public void TestTransition(State @sut, IEvent @ev, State @expected) + { + Assert.AreEqual(expected, sut.Transition(ev)); + } + } +} diff --git a/src/UnitTests/PubnubApi.Tests/EventEngine/Presence/FailedState.cs b/src/UnitTests/PubnubApi.Tests/EventEngine/Presence/FailedState.cs new file mode 100644 index 000000000..11a173ca0 --- /dev/null +++ b/src/UnitTests/PubnubApi.Tests/EventEngine/Presence/FailedState.cs @@ -0,0 +1,70 @@ +using NUnit.Framework; +using PubnubApi.EventEngine.Core; +using PubnubApi.EventEngine.Presence.Common; +using PubnubApi.EventEngine.Presence.Events; +using PubnubApi.EventEngine.Presence.States; + +namespace PubnubApi.Tests.EventEngine.Presence +{ + internal class FailedStateTransitions + { + private static readonly object[] testCases = { + new object[] { + new FailedState(), + new JoinedEvent() { Input = new PresenceInput() { Channels = new [] { "a" } } }, + new HeartbeatingState() { Input = new PresenceInput() { Channels = new [] { "a" } } }, + }, + new object[] { + new FailedState() { Input = new PresenceInput() { Channels = new [] { "a", "b" } } }, + new LeftEvent() { Input = new PresenceInput() { Channels = new [] { "b" } } }, + new HeartbeatingState() { Input = new PresenceInput() { Channels = new [] { "a" } } }, + }, + new object[] { + new FailedState() { Input = new PresenceInput() { Channels = new [] { "a" } } }, + new LeftEvent() { Input = new PresenceInput() { Channels = new [] { "a" } } }, + new InactiveState(), + }, + new object[] { + new FailedState(), + new LeftAllEvent(), + new InactiveState(), + }, + new object[] { + new FailedState(), + new HeartbeatSuccessEvent(), + null, + }, + new object[] { + new FailedState(), + new HeartbeatFailureEvent() { Status = new PNStatus() }, + null, + }, + new object[] { + new FailedState(), + new HeartbeatGiveUpEvent() { Status = new PNStatus() { Category = PNStatusCategory.PNCancelledCategory } }, + null, + }, + new object[] { + new FailedState(), + new ReconnectEvent(), + new HeartbeatingState(), + }, + new object[] { + new FailedState(), + new DisconnectEvent(), + new StoppedState(), + }, + new object[] { + new FailedState(), + new TimesUpEvent(), + null, + }, + }; + + [TestCasesSource(nameof(testCases))] + public void TestTransition(State @sut, IEvent @ev, State @expected) + { + Assert.AreEqual(expected, sut.Transition(ev)); + } + } +} diff --git a/src/UnitTests/PubnubApi.Tests/EventEngine/Presence/HeartbeatingState.cs b/src/UnitTests/PubnubApi.Tests/EventEngine/Presence/HeartbeatingState.cs new file mode 100644 index 000000000..2286b0c1b --- /dev/null +++ b/src/UnitTests/PubnubApi.Tests/EventEngine/Presence/HeartbeatingState.cs @@ -0,0 +1,70 @@ +using NUnit.Framework; +using PubnubApi.EventEngine.Core; +using PubnubApi.EventEngine.Presence.Common; +using PubnubApi.EventEngine.Presence.Events; +using PubnubApi.EventEngine.Presence.States; + +namespace PubnubApi.Tests.EventEngine.Presence +{ + internal class HeartbeatingStateTransitions + { + private static readonly object[] testCases = { + new object[] { + new HeartbeatingState(), + new JoinedEvent() { Input = new PresenceInput() { Channels = new [] { "a" } } }, + new HeartbeatingState() { Input = new PresenceInput() { Channels = new [] { "a" } } }, + }, + new object[] { + new HeartbeatingState() { Input = new PresenceInput() { Channels = new [] { "a", "b" } } }, + new LeftEvent() { Input = new PresenceInput() { Channels = new [] { "b" } } }, + new HeartbeatingState() { Input = new PresenceInput() { Channels = new [] { "a" } } }, + }, + new object[] { + new HeartbeatingState() { Input = new PresenceInput() { Channels = new [] { "a" } } }, + new LeftEvent() { Input = new PresenceInput() { Channels = new [] { "a" } } }, + new InactiveState(), + }, + new object[] { + new HeartbeatingState(), + new LeftAllEvent(), + new InactiveState(), + }, + new object[] { + new HeartbeatingState(), + new HeartbeatSuccessEvent(), + new CooldownState(), + }, + new object[] { + new HeartbeatingState(), + new HeartbeatFailureEvent() { Status = new PNStatus() }, + new ReconnectingState(), + }, + new object[] { + new HeartbeatingState(), + new HeartbeatGiveUpEvent() { Status = new PNStatus() { Category = PNStatusCategory.PNCancelledCategory } }, + null, + }, + new object[] { + new HeartbeatingState(), + new ReconnectEvent(), + null, + }, + new object[] { + new HeartbeatingState(), + new DisconnectEvent(), + new StoppedState(), + }, + new object[] { + new HeartbeatingState(), + new TimesUpEvent(), + null, + }, + }; + + [TestCasesSource(nameof(testCases))] + public void TestTransition(State @sut, IEvent @ev, State @expected) + { + Assert.AreEqual(expected, sut.Transition(ev)); + } + } +} diff --git a/src/UnitTests/PubnubApi.Tests/EventEngine/Presence/InactiveState.cs b/src/UnitTests/PubnubApi.Tests/EventEngine/Presence/InactiveState.cs new file mode 100644 index 000000000..a2760d6fb --- /dev/null +++ b/src/UnitTests/PubnubApi.Tests/EventEngine/Presence/InactiveState.cs @@ -0,0 +1,65 @@ +using NUnit.Framework; +using PubnubApi.EventEngine.Core; +using PubnubApi.EventEngine.Presence.Common; +using PubnubApi.EventEngine.Presence.Events; +using PubnubApi.EventEngine.Presence.States; + +namespace PubnubApi.Tests.EventEngine.Presence +{ + internal class InactiveStateTransitions + { + private static readonly object[] testCases = { + new object[] { + new InactiveState(), + new JoinedEvent() { Input = new PresenceInput() { Channels = new [] { "a" } } }, + new HeartbeatingState() { Input = new PresenceInput() { Channels = new [] { "a" } } }, + }, + new object[] { + new InactiveState(), + new LeftEvent() { Input = new PresenceInput() { Channels = new [] { "a" } } }, + null, + }, + new object[] { + new InactiveState(), + new LeftAllEvent(), + null, + }, + new object[] { + new InactiveState(), + new HeartbeatSuccessEvent(), + null, + }, + new object[] { + new InactiveState(), + new HeartbeatFailureEvent() { Status = new PNStatus() }, + null, + }, + new object[] { + new InactiveState(), + new HeartbeatGiveUpEvent() { Status = new PNStatus() { Category = PNStatusCategory.PNCancelledCategory } }, + null, + }, + new object[] { + new InactiveState(), + new ReconnectEvent(), + null, + }, + new object[] { + new InactiveState(), + new DisconnectEvent(), + null, + }, + new object[] { + new InactiveState(), + new TimesUpEvent(), + null, + }, + }; + + [TestCasesSource(nameof(testCases))] + public void TestTransition(State @sut, IEvent @ev, State @expected) + { + Assert.AreEqual(expected, sut.Transition(ev)); + } + } +} diff --git a/src/UnitTests/PubnubApi.Tests/EventEngine/Presence/ReconnectingState.cs b/src/UnitTests/PubnubApi.Tests/EventEngine/Presence/ReconnectingState.cs new file mode 100644 index 000000000..f068a66ae --- /dev/null +++ b/src/UnitTests/PubnubApi.Tests/EventEngine/Presence/ReconnectingState.cs @@ -0,0 +1,75 @@ +using NUnit.Framework; +using PubnubApi.EventEngine.Core; +using PubnubApi.EventEngine.Presence.Common; +using PubnubApi.EventEngine.Presence.Events; +using PubnubApi.EventEngine.Presence.States; + +namespace PubnubApi.Tests.EventEngine.Presence +{ + internal class ReconnectingStateTransitions + { + private static readonly object[] testCases = { + new object[] { + new ReconnectingState(), + new JoinedEvent() { Input = new PresenceInput() { Channels = new [] { "a" } } }, + new HeartbeatingState() { Input = new PresenceInput() { Channels = new [] { "a" } } }, + }, + new object[] { + new ReconnectingState() { Input = new PresenceInput() { Channels = new [] { "a", "b" } } }, + new LeftEvent() { Input = new PresenceInput() { Channels = new [] { "b" } } }, + new HeartbeatingState() { Input = new PresenceInput() { Channels = new [] { "a" } } }, + }, + new object[] { + new ReconnectingState() { Input = new PresenceInput() { Channels = new [] { "a" } } }, + new LeftEvent() { Input = new PresenceInput() { Channels = new [] { "a" } } }, + new InactiveState(), + }, + new object[] { + new ReconnectingState(), + new LeftAllEvent(), + new InactiveState(), + }, + new object[] { + new ReconnectingState(), + new HeartbeatSuccessEvent(), + new CooldownState(), + }, + new object[] { + new ReconnectingState() { RetryCount = 1 }, + new HeartbeatFailureEvent(), + new ReconnectingState() { RetryCount = 2 }, + }, + new object[] { + new ReconnectingState(), + new HeartbeatFailureEvent() { Status = new PNStatus() { Category = PNStatusCategory.PNCancelledCategory} }, + null, + }, + new object[] { + new ReconnectingState(), + new HeartbeatGiveUpEvent(), + new FailedState(), + }, + new object[] { + new ReconnectingState(), + new ReconnectEvent(), + null, + }, + new object[] { + new ReconnectingState(), + new DisconnectEvent(), + new StoppedState(), + }, + new object[] { + new ReconnectingState(), + new TimesUpEvent(), + null, + }, + }; + + [TestCasesSource(nameof(testCases))] + public void TestTransition(State @sut, IEvent @ev, State @expected) + { + Assert.AreEqual(expected, sut.Transition(ev)); + } + } +} diff --git a/src/UnitTests/PubnubApi.Tests/EventEngine/Presence/StoppedState.cs b/src/UnitTests/PubnubApi.Tests/EventEngine/Presence/StoppedState.cs new file mode 100644 index 000000000..7e7c0cffc --- /dev/null +++ b/src/UnitTests/PubnubApi.Tests/EventEngine/Presence/StoppedState.cs @@ -0,0 +1,70 @@ +using NUnit.Framework; +using PubnubApi.EventEngine.Core; +using PubnubApi.EventEngine.Presence.Common; +using PubnubApi.EventEngine.Presence.Events; +using PubnubApi.EventEngine.Presence.States; + +namespace PubnubApi.Tests.EventEngine.Presence +{ + internal class StoppedStateTransitions + { + private static readonly object[] testCases = { + new object[] { + new StoppedState(), + new JoinedEvent() { Input = new PresenceInput() { Channels = new [] { "a" } } }, + new StoppedState(), + }, + new object[] { + new StoppedState() { Input = new PresenceInput() { Channels = new [] { "a", "b" } } }, + new LeftEvent() { Input = new PresenceInput() { Channels = new [] { "b" } } }, + new StoppedState() { Input = new PresenceInput() { Channels = new [] { "a" } } }, + }, + new object[] { + new StoppedState() { Input = new PresenceInput() { Channels = new [] { "a" } } }, + new LeftEvent() { Input = new PresenceInput() { Channels = new [] { "a" } } }, + new InactiveState(), + }, + new object[] { + new StoppedState(), + new LeftAllEvent(), + new InactiveState(), + }, + new object[] { + new StoppedState(), + new HeartbeatSuccessEvent(), + null, + }, + new object[] { + new StoppedState(), + new HeartbeatFailureEvent() { Status = new PNStatus() }, + null, + }, + new object[] { + new StoppedState(), + new HeartbeatGiveUpEvent() { Status = new PNStatus() { Category = PNStatusCategory.PNCancelledCategory } }, + null, + }, + new object[] { + new StoppedState(), + new ReconnectEvent(), + new HeartbeatingState(), + }, + new object[] { + new StoppedState(), + new DisconnectEvent(), + null, + }, + new object[] { + new StoppedState(), + new TimesUpEvent(), + null, + }, + }; + + [TestCasesSource(nameof(testCases))] + public void TestTransition(State @sut, IEvent @ev, State @expected) + { + Assert.AreEqual(expected, sut.Transition(ev)); + } + } +} From 3427cbcaaefe3f276f3e122c7618f21d53d379e4 Mon Sep 17 00:00:00 2001 From: Mohit Tejani Date: Thu, 25 Jan 2024 00:36:52 +0530 Subject: [PATCH 18/32] fix/build: missing reference links for effect handlers --- src/Api/PubnubApiPCL/PubnubApiPCL.csproj | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Api/PubnubApiPCL/PubnubApiPCL.csproj b/src/Api/PubnubApiPCL/PubnubApiPCL.csproj index bc14ab3e8..ca0450a59 100644 --- a/src/Api/PubnubApiPCL/PubnubApiPCL.csproj +++ b/src/Api/PubnubApiPCL/PubnubApiPCL.csproj @@ -234,6 +234,8 @@ + + @@ -246,6 +248,7 @@ + HttpUtility\HttpUtility.cs From 2581fa91bfeae9a8c7149f5d626aabea5ba48e2b Mon Sep 17 00:00:00 2001 From: Mohit Tejani Date: Thu, 25 Jan 2024 00:46:03 +0530 Subject: [PATCH 19/32] attempt to fix UWP project build errors --- src/Api/PubnubApiUWP/PubnubApiUWP.csproj | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Api/PubnubApiUWP/PubnubApiUWP.csproj b/src/Api/PubnubApiUWP/PubnubApiUWP.csproj index 59b40e332..729d09fc5 100644 --- a/src/Api/PubnubApiUWP/PubnubApiUWP.csproj +++ b/src/Api/PubnubApiUWP/PubnubApiUWP.csproj @@ -345,6 +345,8 @@ + + @@ -363,6 +365,7 @@ + HttpUtility\HttpUtility.cs From 56ebedd5571a1851a317e70b3985d8d0708b6481 Mon Sep 17 00:00:00 2001 From: Mohit Tejani Date: Thu, 25 Jan 2024 00:55:53 +0530 Subject: [PATCH 20/32] fix CSC : error CS1617: error for language version --- src/Api/PubnubApi/PubnubApi.csproj | 2 +- src/Api/PubnubApiPCL/PubnubApiPCL.csproj | 2 +- src/Api/PubnubApiUWP/PubnubApiUWP.csproj | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Api/PubnubApi/PubnubApi.csproj b/src/Api/PubnubApi/PubnubApi.csproj index b1ebf5097..710f16c77 100644 --- a/src/Api/PubnubApi/PubnubApi.csproj +++ b/src/Api/PubnubApi/PubnubApi.csproj @@ -2,7 +2,7 @@ net35;net40;net45;net461;net48 - 8.0 + latest True pubnub.snk False diff --git a/src/Api/PubnubApiPCL/PubnubApiPCL.csproj b/src/Api/PubnubApiPCL/PubnubApiPCL.csproj index ca0450a59..369ae84c1 100644 --- a/src/Api/PubnubApiPCL/PubnubApiPCL.csproj +++ b/src/Api/PubnubApiPCL/PubnubApiPCL.csproj @@ -2,7 +2,7 @@ netstandard1.0;netstandard1.3;netstandard1.4;netstandard1.1;netstandard2.0;net6.0 - 8.0 + latest true True pubnub.snk diff --git a/src/Api/PubnubApiUWP/PubnubApiUWP.csproj b/src/Api/PubnubApiUWP/PubnubApiUWP.csproj index 729d09fc5..b7781292c 100644 --- a/src/Api/PubnubApiUWP/PubnubApiUWP.csproj +++ b/src/Api/PubnubApiUWP/PubnubApiUWP.csproj @@ -4,7 +4,7 @@ uap10.0 - 8.0 + latest True pubnub.snk False From 19eb3f3e35e03a7556370b5e5dd6a310e1726949 Mon Sep 17 00:00:00 2001 From: Mohit Tejani Date: Thu, 25 Jan 2024 14:44:17 +0530 Subject: [PATCH 21/32] updating language version to 9 suppoerted by VS2019 --- src/Api/PubnubApi/PubnubApi.csproj | 2 +- src/Api/PubnubApiPCL/PubnubApiPCL.csproj | 2 +- src/Api/PubnubApiUWP/PubnubApiUWP.csproj | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Api/PubnubApi/PubnubApi.csproj b/src/Api/PubnubApi/PubnubApi.csproj index 710f16c77..d73f33cb2 100644 --- a/src/Api/PubnubApi/PubnubApi.csproj +++ b/src/Api/PubnubApi/PubnubApi.csproj @@ -2,7 +2,7 @@ net35;net40;net45;net461;net48 - latest + 9.0 True pubnub.snk False diff --git a/src/Api/PubnubApiPCL/PubnubApiPCL.csproj b/src/Api/PubnubApiPCL/PubnubApiPCL.csproj index 369ae84c1..be39c6cb5 100644 --- a/src/Api/PubnubApiPCL/PubnubApiPCL.csproj +++ b/src/Api/PubnubApiPCL/PubnubApiPCL.csproj @@ -2,7 +2,7 @@ netstandard1.0;netstandard1.3;netstandard1.4;netstandard1.1;netstandard2.0;net6.0 - latest + 9.0 true True pubnub.snk diff --git a/src/Api/PubnubApiUWP/PubnubApiUWP.csproj b/src/Api/PubnubApiUWP/PubnubApiUWP.csproj index b7781292c..0563a6aaf 100644 --- a/src/Api/PubnubApiUWP/PubnubApiUWP.csproj +++ b/src/Api/PubnubApiUWP/PubnubApiUWP.csproj @@ -4,7 +4,7 @@ uap10.0 - latest + 9.0 True pubnub.snk False From 9b2637594dc6f6f2864c15e852c9665da6835364 Mon Sep 17 00:00:00 2001 From: Mohit Tejani Date: Thu, 25 Jan 2024 14:56:37 +0530 Subject: [PATCH 22/32] updated LangVersion to `preview` --- src/Api/PubnubApi/PubnubApi.csproj | 2 +- src/Api/PubnubApiPCL/PubnubApiPCL.csproj | 2 +- src/Api/PubnubApiUWP/PubnubApiUWP.csproj | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Api/PubnubApi/PubnubApi.csproj b/src/Api/PubnubApi/PubnubApi.csproj index d73f33cb2..900059200 100644 --- a/src/Api/PubnubApi/PubnubApi.csproj +++ b/src/Api/PubnubApi/PubnubApi.csproj @@ -2,7 +2,7 @@ net35;net40;net45;net461;net48 - 9.0 + preview True pubnub.snk False diff --git a/src/Api/PubnubApiPCL/PubnubApiPCL.csproj b/src/Api/PubnubApiPCL/PubnubApiPCL.csproj index be39c6cb5..95a572af4 100644 --- a/src/Api/PubnubApiPCL/PubnubApiPCL.csproj +++ b/src/Api/PubnubApiPCL/PubnubApiPCL.csproj @@ -2,7 +2,7 @@ netstandard1.0;netstandard1.3;netstandard1.4;netstandard1.1;netstandard2.0;net6.0 - 9.0 + preview true True pubnub.snk diff --git a/src/Api/PubnubApiUWP/PubnubApiUWP.csproj b/src/Api/PubnubApiUWP/PubnubApiUWP.csproj index 0563a6aaf..15d7f3f94 100644 --- a/src/Api/PubnubApiUWP/PubnubApiUWP.csproj +++ b/src/Api/PubnubApiUWP/PubnubApiUWP.csproj @@ -4,7 +4,7 @@ uap10.0 - 9.0 + preview True pubnub.snk False From dc61a26c0274a6cef57b00d2d9e2e8cde0bd1217 Mon Sep 17 00:00:00 2001 From: Mohit Tejani Date: Thu, 25 Jan 2024 15:12:33 +0530 Subject: [PATCH 23/32] take-4/fix language version. `default` --- src/Api/PubnubApi/PubnubApi.csproj | 2 +- src/Api/PubnubApiPCL/PubnubApiPCL.csproj | 2 +- src/Api/PubnubApiUWP/PubnubApiUWP.csproj | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Api/PubnubApi/PubnubApi.csproj b/src/Api/PubnubApi/PubnubApi.csproj index 900059200..fe08ad075 100644 --- a/src/Api/PubnubApi/PubnubApi.csproj +++ b/src/Api/PubnubApi/PubnubApi.csproj @@ -2,7 +2,7 @@ net35;net40;net45;net461;net48 - preview + default True pubnub.snk False diff --git a/src/Api/PubnubApiPCL/PubnubApiPCL.csproj b/src/Api/PubnubApiPCL/PubnubApiPCL.csproj index 95a572af4..06621541b 100644 --- a/src/Api/PubnubApiPCL/PubnubApiPCL.csproj +++ b/src/Api/PubnubApiPCL/PubnubApiPCL.csproj @@ -2,7 +2,7 @@ netstandard1.0;netstandard1.3;netstandard1.4;netstandard1.1;netstandard2.0;net6.0 - preview + default true True pubnub.snk diff --git a/src/Api/PubnubApiUWP/PubnubApiUWP.csproj b/src/Api/PubnubApiUWP/PubnubApiUWP.csproj index 15d7f3f94..efa7a430b 100644 --- a/src/Api/PubnubApiUWP/PubnubApiUWP.csproj +++ b/src/Api/PubnubApiUWP/PubnubApiUWP.csproj @@ -4,7 +4,7 @@ uap10.0 - preview + default True pubnub.snk False From abd432717b75b9bd0e5b640acbacb28885b750ac Mon Sep 17 00:00:00 2001 From: Mohit Tejani Date: Thu, 25 Jan 2024 15:20:04 +0530 Subject: [PATCH 24/32] take-5: reverting LangVersion to `latest` --- src/Api/PubnubApi/PubnubApi.csproj | 2 +- src/Api/PubnubApiPCL/PubnubApiPCL.csproj | 2 +- src/Api/PubnubApiUWP/PubnubApiUWP.csproj | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Api/PubnubApi/PubnubApi.csproj b/src/Api/PubnubApi/PubnubApi.csproj index fe08ad075..710f16c77 100644 --- a/src/Api/PubnubApi/PubnubApi.csproj +++ b/src/Api/PubnubApi/PubnubApi.csproj @@ -2,7 +2,7 @@ net35;net40;net45;net461;net48 - default + latest True pubnub.snk False diff --git a/src/Api/PubnubApiPCL/PubnubApiPCL.csproj b/src/Api/PubnubApiPCL/PubnubApiPCL.csproj index 06621541b..369ae84c1 100644 --- a/src/Api/PubnubApiPCL/PubnubApiPCL.csproj +++ b/src/Api/PubnubApiPCL/PubnubApiPCL.csproj @@ -2,7 +2,7 @@ netstandard1.0;netstandard1.3;netstandard1.4;netstandard1.1;netstandard2.0;net6.0 - default + latest true True pubnub.snk diff --git a/src/Api/PubnubApiUWP/PubnubApiUWP.csproj b/src/Api/PubnubApiUWP/PubnubApiUWP.csproj index efa7a430b..b7781292c 100644 --- a/src/Api/PubnubApiUWP/PubnubApiUWP.csproj +++ b/src/Api/PubnubApiUWP/PubnubApiUWP.csproj @@ -4,7 +4,7 @@ uap10.0 - default + latest True pubnub.snk False From 491d5c9491ed7642820aff5de14362fd89fc8038 Mon Sep 17 00:00:00 2001 From: Mohit Tejani Date: Sun, 28 Jan 2024 19:48:47 +0530 Subject: [PATCH 25/32] removed `` overrides --- src/Api/PubnubApi/PubnubApi.csproj | 2 +- src/Api/PubnubApiPCL/PubnubApiPCL.csproj | 2 +- src/Api/PubnubApiUWP/PubnubApiUWP.csproj | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Api/PubnubApi/PubnubApi.csproj b/src/Api/PubnubApi/PubnubApi.csproj index 710f16c77..f460a6433 100644 --- a/src/Api/PubnubApi/PubnubApi.csproj +++ b/src/Api/PubnubApi/PubnubApi.csproj @@ -2,7 +2,7 @@ net35;net40;net45;net461;net48 - latest + True pubnub.snk False diff --git a/src/Api/PubnubApiPCL/PubnubApiPCL.csproj b/src/Api/PubnubApiPCL/PubnubApiPCL.csproj index 369ae84c1..bb5895ead 100644 --- a/src/Api/PubnubApiPCL/PubnubApiPCL.csproj +++ b/src/Api/PubnubApiPCL/PubnubApiPCL.csproj @@ -2,7 +2,7 @@ netstandard1.0;netstandard1.3;netstandard1.4;netstandard1.1;netstandard2.0;net6.0 - latest + true True pubnub.snk diff --git a/src/Api/PubnubApiUWP/PubnubApiUWP.csproj b/src/Api/PubnubApiUWP/PubnubApiUWP.csproj index b7781292c..2b839d0ba 100644 --- a/src/Api/PubnubApiUWP/PubnubApiUWP.csproj +++ b/src/Api/PubnubApiUWP/PubnubApiUWP.csproj @@ -4,7 +4,7 @@ uap10.0 - latest + True pubnub.snk False From 3fff0d17d86fd580adf24916b6163d7161331895 Mon Sep 17 00:00:00 2001 From: Mohit Tejani Date: Sun, 28 Jan 2024 19:55:41 +0530 Subject: [PATCH 26/32] reverted 491d5c9 --- src/Api/PubnubApi/PubnubApi.csproj | 2 +- src/Api/PubnubApiPCL/PubnubApiPCL.csproj | 2 +- src/Api/PubnubApiUWP/PubnubApiUWP.csproj | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Api/PubnubApi/PubnubApi.csproj b/src/Api/PubnubApi/PubnubApi.csproj index f460a6433..710f16c77 100644 --- a/src/Api/PubnubApi/PubnubApi.csproj +++ b/src/Api/PubnubApi/PubnubApi.csproj @@ -2,7 +2,7 @@ net35;net40;net45;net461;net48 - + latest True pubnub.snk False diff --git a/src/Api/PubnubApiPCL/PubnubApiPCL.csproj b/src/Api/PubnubApiPCL/PubnubApiPCL.csproj index bb5895ead..369ae84c1 100644 --- a/src/Api/PubnubApiPCL/PubnubApiPCL.csproj +++ b/src/Api/PubnubApiPCL/PubnubApiPCL.csproj @@ -2,7 +2,7 @@ netstandard1.0;netstandard1.3;netstandard1.4;netstandard1.1;netstandard2.0;net6.0 - + latest true True pubnub.snk diff --git a/src/Api/PubnubApiUWP/PubnubApiUWP.csproj b/src/Api/PubnubApiUWP/PubnubApiUWP.csproj index 2b839d0ba..b7781292c 100644 --- a/src/Api/PubnubApiUWP/PubnubApiUWP.csproj +++ b/src/Api/PubnubApiUWP/PubnubApiUWP.csproj @@ -4,7 +4,7 @@ uap10.0 - + latest True pubnub.snk False From c6b03c643a4d479041580db21f42349714160263 Mon Sep 17 00:00:00 2001 From: Mohit Tejani <60129002+mohitpubnub@users.noreply.github.com> Date: Thu, 1 Feb 2024 15:50:45 +0530 Subject: [PATCH 27/32] Update run-tests.yml --- .github/workflows/run-tests.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 08e9a6ed3..d34ec8e5c 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -29,8 +29,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v3 with: - dotnet-version: | - 2.1.519 + dotnet-version: | 5.0.x 6.0.x - name: Build packages From 39d45f151ee6c8235ebe4a1de0052db5174ebaf6 Mon Sep 17 00:00:00 2001 From: Mohit Tejani <60129002+mohitpubnub@users.noreply.github.com> Date: Thu, 1 Feb 2024 15:58:46 +0530 Subject: [PATCH 28/32] take-2 --- src/Api/PubnubApi/global.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Api/PubnubApi/global.json b/src/Api/PubnubApi/global.json index de3243048..2cb2ac9bd 100644 --- a/src/Api/PubnubApi/global.json +++ b/src/Api/PubnubApi/global.json @@ -1,5 +1,5 @@ { "sdk": { - "version": "2.1.519" + "version": "5.0.100" } } \ No newline at end of file From eae330116a7fcfb6ca7ada58c849733e83b9b671 Mon Sep 17 00:00:00 2001 From: Mohit Tejani <60129002+mohitpubnub@users.noreply.github.com> Date: Thu, 1 Feb 2024 16:05:46 +0530 Subject: [PATCH 29/32] take-3 --- src/Api/PubnubApi/global.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Api/PubnubApi/global.json b/src/Api/PubnubApi/global.json index 2cb2ac9bd..a0ee6a660 100644 --- a/src/Api/PubnubApi/global.json +++ b/src/Api/PubnubApi/global.json @@ -1,5 +1,5 @@ { "sdk": { - "version": "5.0.100" + "version": "5.0" } } \ No newline at end of file From e03a01f80accd93988b8526cc4307b4bf544686a Mon Sep 17 00:00:00 2001 From: Xavrax Date: Mon, 5 Feb 2024 19:19:20 +0100 Subject: [PATCH 30/32] fix state switches --- .../PubnubApi/EventEngine/Presence/States/CooldownState.cs | 4 ---- .../EventEngine/Presence/States/HeartBeatingState.cs | 4 ++++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/CooldownState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/CooldownState.cs index 57f8bd81a..997548867 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/CooldownState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/CooldownState.cs @@ -23,10 +23,6 @@ public override TransitionResult Transition(IEvent ev) }, Events.LeftEvent e => HandleLeftEvent(e), Events.LeftAllEvent e => new InactiveState(), - Events.HeartbeatSuccessEvent e => new CooldownState() - { - Input = this.Input, - }, Events.DisconnectEvent e => new StoppedState() { Input = this.Input, diff --git a/src/Api/PubnubApi/EventEngine/Presence/States/HeartBeatingState.cs b/src/Api/PubnubApi/EventEngine/Presence/States/HeartBeatingState.cs index b461cbced..b995cc152 100644 --- a/src/Api/PubnubApi/EventEngine/Presence/States/HeartBeatingState.cs +++ b/src/Api/PubnubApi/EventEngine/Presence/States/HeartBeatingState.cs @@ -22,6 +22,10 @@ public override TransitionResult Transition(IEvent ev) }, Events.LeftEvent e => HandleLeftEvent(e), Events.LeftAllEvent e => new InactiveState(), + Events.HeartbeatSuccessEvent e => new CooldownState() + { + Input = this.Input, + }, Events.HeartbeatFailureEvent e => HandleHeartbeatFailureEvent(e), Events.DisconnectEvent e => new StoppedState() { From b2233492d62d9bd7502640a4c37ec778a3b8e14d Mon Sep 17 00:00:00 2001 From: Xavrax Date: Mon, 5 Feb 2024 19:39:34 +0100 Subject: [PATCH 31/32] wip for ci --- .../Subscribe/Effects/EmitStatusEffectHandler.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Api/PubnubApi/EventEngine/Subscribe/Effects/EmitStatusEffectHandler.cs b/src/Api/PubnubApi/EventEngine/Subscribe/Effects/EmitStatusEffectHandler.cs index 1f207894d..16baff877 100644 --- a/src/Api/PubnubApi/EventEngine/Subscribe/Effects/EmitStatusEffectHandler.cs +++ b/src/Api/PubnubApi/EventEngine/Subscribe/Effects/EmitStatusEffectHandler.cs @@ -22,7 +22,16 @@ public EmitStatusEffectHandler(Pubnub pn, Action statusEmitter public override async Task Run(EmitStatusInvocation invocation) { + if (invocation.Status == null) + throw new Exception("Status is null"); + + if (this.statusEmitterFunction == null) + throw new Exception("StatusEmitterFunction is null"); + + if (this.pubnubInstance == null) + throw new Exception("PubnubInstance is null"); + this.statusEmitterFunction(this.pubnubInstance, invocation.Status); } } -} \ No newline at end of file +} From 8db56214b980838beec3bc3bc9f70533eea1764a Mon Sep 17 00:00:00 2001 From: Xavrax Date: Mon, 5 Feb 2024 19:41:06 +0100 Subject: [PATCH 32/32] leave this branch as is - new branch for testing --- .../Subscribe/Effects/EmitStatusEffectHandler.cs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/Api/PubnubApi/EventEngine/Subscribe/Effects/EmitStatusEffectHandler.cs b/src/Api/PubnubApi/EventEngine/Subscribe/Effects/EmitStatusEffectHandler.cs index 16baff877..e644a7d11 100644 --- a/src/Api/PubnubApi/EventEngine/Subscribe/Effects/EmitStatusEffectHandler.cs +++ b/src/Api/PubnubApi/EventEngine/Subscribe/Effects/EmitStatusEffectHandler.cs @@ -22,15 +22,6 @@ public EmitStatusEffectHandler(Pubnub pn, Action statusEmitter public override async Task Run(EmitStatusInvocation invocation) { - if (invocation.Status == null) - throw new Exception("Status is null"); - - if (this.statusEmitterFunction == null) - throw new Exception("StatusEmitterFunction is null"); - - if (this.pubnubInstance == null) - throw new Exception("PubnubInstance is null"); - this.statusEmitterFunction(this.pubnubInstance, invocation.Status); } }