This repository has been archived by the owner on Mar 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChannel.cs
67 lines (58 loc) · 1.93 KB
/
Channel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
namespace PusherClient
{
/// <summary>
/// Represents a Pusher channel that can be subscribed to
/// </summary>
public class Channel : EventEmitter
{
private readonly ITriggerChannels _pusher;
private bool _isSubscribed;
/// <summary>
/// Fired when the Channel has successfully been subscribed to
/// </summary>
public event SubscriptionEventHandler Subscribed;
/// <summary>
/// Gets whether the Channel is currently Subscribed
/// </summary>
public bool IsSubscribed => _isSubscribed;
/// <summary>
/// Gets the name of the Channel
/// </summary>
public string Name { get; }
/// <summary>
/// Ctor
/// </summary>
/// <param name="channelName">The name of the Channel</param>
/// <param name="pusher">The parent Pusher object</param>
internal Channel(string channelName, ITriggerChannels pusher)
{
_pusher = pusher;
Name = channelName;
}
internal virtual void SubscriptionSucceeded(string data)
{
if (_isSubscribed)
return;
_isSubscribed = true;
if(Subscribed != null)
Subscribed(this);
}
/// <summary>
/// Unsubscribe from the Channel named channel, if currently subscribed
/// </summary>
public void Unsubscribe()
{
_pusher.Unsubscribe(Name);
_isSubscribed = false;
}
/// <summary>
/// Trigger this channel with the provided information
/// </summary>
/// <param name="eventName">The name of the event to trigger</param>
/// <param name="obj">The object to send as the payload on the event</param>
public void Trigger(string eventName, object obj)
{
_pusher.Trigger(Name, eventName, obj);
}
}
}