-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4295001
commit 7cdc839
Showing
13 changed files
with
588 additions
and
268 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using PubnubApi.EventEngine.Common; | ||
using PubnubApi.EventEngine.Subscribe.Common; | ||
|
||
namespace PubnubApi | ||
{ | ||
public abstract class SubscribeCapable | ||
{ | ||
public abstract List<string> ChannelNames { get; set; } | ||
public abstract List<string> ChannelGroupNames { get; set; } | ||
public abstract Pubnub Pubnub { get; set; } | ||
public abstract EventEmitter EventEmitter { get; set; } | ||
public abstract SubscriptionOptions Options { get; set; } | ||
public abstract SubscribeCallbackExt Listener { get; set; } | ||
|
||
public Action<Pubnub, PNPresenceEventResult> OnPresence { | ||
set { | ||
Listener.presenceAction = value; | ||
} | ||
} | ||
public Action<Pubnub, PNObjectEventResult> OnObjects { | ||
set { | ||
Listener.objectEventAction = value; | ||
} | ||
} | ||
public Action<Pubnub, PNFileEventResult> OnFile { | ||
set { | ||
Listener.fileAction = value; | ||
} | ||
} | ||
public Action<Pubnub, PNMessageActionEventResult> OnMessageAction { | ||
set { | ||
Listener.messageAction = value; | ||
} | ||
} | ||
public Action<Pubnub, PNMessageResult<object>> OnMessage { | ||
set { | ||
Listener.subscribeAction = value; | ||
} | ||
} | ||
public Action<Pubnub, PNSignalResult<object>> OnSignal { | ||
set { | ||
Listener.signalAction = value; | ||
} | ||
} | ||
|
||
public void Subscribe<T>(SubscriptionCursor cursor = null) | ||
{ | ||
var subscription = this.Pubnub.Subscribe<T>().Channels(this.ChannelNames.ToArray()).ChannelGroups(this.ChannelGroupNames.ToArray()); | ||
if (cursor is not null && cursor.Timetoken != 0) { | ||
var timetoken = cursor.Timetoken ?? 0; | ||
subscription.WithTimetoken(timetoken).Execute(); | ||
|
||
} else { | ||
subscription.Execute(); | ||
} | ||
} | ||
|
||
public void AddListener(SubscribeCallbackExt listener) | ||
{ | ||
this.EventEmitter.AddListener(listener, this.ChannelNames.ToArray(), this.ChannelGroupNames.ToArray()); | ||
} | ||
|
||
public void RemoveListener(SubscribeCallbackExt listener) | ||
{ | ||
this.EventEmitter.RemoveListener(listener, this.ChannelNames.ToArray(), this.ChannelGroupNames.ToArray()); | ||
} | ||
|
||
public void UnSubscribe<T>() | ||
{ | ||
this.Pubnub.Unsubscribe<T>().Channels(ChannelNames.ToArray()).ChannelGroups(ChannelGroupNames.ToArray()).Execute(); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,34 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using PubnubApi.EventEngine.Common; | ||
|
||
namespace PubnubApi | ||
{ | ||
public class Subscription | ||
public class Subscription : SubscribeCapable | ||
{ | ||
public string[] Names { get; set; } = new string[] { }; | ||
private Pubnub Pubnub { get; set; } | ||
private EventEmitter EventEmitter { get; set; } | ||
public override List<string> ChannelNames { get; set; } = new List<string>(); | ||
public override List<string> ChannelGroupNames { get; set; } = new List<string>(); | ||
public override Pubnub Pubnub { get; set; } | ||
public override EventEmitter EventEmitter { get; set; } | ||
public override SubscriptionOptions Options { get; set; } | ||
public override SubscribeCallbackExt Listener { get; set; } = new SubscribeCallbackExt(); | ||
|
||
public Subscription(string name, SubscriptionOptions options, Pubnub pubnub, EventEmitter eventEmitter) | ||
public Subscription(string[] channels, string[] channelGroups, SubscriptionOptions options, Pubnub pubnub, EventEmitter eventEmitter) | ||
{ | ||
Names.ToList().Add(name); | ||
if (options == SubscriptionOptions.ReceivePresenceEvents) { | ||
Names.ToList().Add($"{name}-pnpres"); | ||
} | ||
this.ChannelNames = channels.ToList(); | ||
this.ChannelGroupNames = channelGroups.ToList(); | ||
this.Pubnub = pubnub; | ||
this.EventEmitter = eventEmitter; | ||
this.Options = options; | ||
this.EventEmitter.AddListener(Listener, channels, channelGroups); | ||
} | ||
|
||
SubscriptionSet AddSubscription(Subscription subscription) | ||
public SubscriptionSet Add(Subscription subscription) | ||
{ | ||
return new SubscriptionSet(); | ||
this.ChannelNames.AddRange(subscription.ChannelNames); | ||
this.ChannelGroupNames.AddRange(subscription.ChannelGroupNames); | ||
return new SubscriptionSet(this.ChannelNames.ToArray(),this.ChannelGroupNames.ToArray() , this.Options, this.Pubnub, this.EventEmitter); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.