private Channel CreateChannel(string channelName) { ChannelTypes type = Channel.GetChannelType(channelName); Channel result; switch (type) { case ChannelTypes.Private: case ChannelTypes.PrivateEncrypted: AuthEndpointCheck(channelName); result = new PrivateChannel(channelName, this); break; case ChannelTypes.Presence: AuthEndpointCheck(channelName); result = new PresenceChannel(channelName, this); break; default: result = new Channel(channelName, this); break; } if (!Channels.TryAdd(channelName, result)) { result = Channels[channelName]; } return(result); }
private Channel SubscribeToChannel(ChannelTypes type, string channelName) { if (!Channels.ContainsKey(channelName)) { CreateChannel(type, channelName); } if (Connection.State != WebSocketState.Open) { return(Channels[channelName]); } if (type == ChannelTypes.Presence || type == ChannelTypes.Private) { var jsonAuth = Options.Authorizer.Authorize(channelName, Connection.SocketId); var message = Options.Serializer.Deserialize <SubscribeToChannelMessage>(jsonAuth); Connection.Send(Options.Serializer.Serialize(new { @event = Constants.CHANNEL_SUBSCRIBE, data = new { channel = channelName, message.auth, message.channel_data } })); } else { // no need for auth details just send subscribe event Connection.Send(Options.Serializer.Serialize(new { @event = Constants.CHANNEL_SUBSCRIBE, data = new { channel = channelName } })); } return(Channels[channelName]); }
public static string CreateUniqueChannelName(ChannelTypes channelType = ChannelTypes.Public) { string channelPrefix; switch (channelType) { case ChannelTypes.Private: channelPrefix = "private-"; break; case ChannelTypes.PrivateEncrypted: channelPrefix = "private-encrypted-"; break; case ChannelTypes.Presence: channelPrefix = "presence-"; break; default: channelPrefix = string.Empty; break; } var mockChannelName = $"{channelPrefix}-test-{Guid.NewGuid():N}"; return(mockChannelName); }
private void CreateChannel(ChannelTypes type, string channelName) { switch (type) { case ChannelTypes.Public: Channels[channelName] = new Channel(channelName, this); break; case ChannelTypes.Private: AuthEndpointCheck(); Channels[channelName] = new PrivateChannel(channelName, this); break; case ChannelTypes.Presence: AuthEndpointCheck(); Channel channel; if (_presenceChannelFactories.TryGetValue(channelName, out var factory)) { channel = factory.Item2(); } else { channel = new PresenceChannel(channelName, this); } Channels[channelName] = channel; break; } }
private static void ValidateChannel(Channel expectedChannel, ChannelTypes expectedChannelType, Channel actualChannel, bool isSubscribed) { Assert.IsNotNull(actualChannel); Assert.AreEqual(expectedChannel.Name, actualChannel.Name, nameof(Channel.Name)); Assert.AreEqual(isSubscribed, actualChannel.IsSubscribed, nameof(Channel.IsSubscribed)); Assert.AreEqual(expectedChannelType, actualChannel.ChannelType, nameof(Channel.ChannelType)); }
private Channel SubscribeToChannel(ChannelTypes type, string channelName) { if (!Channels.ContainsKey(channelName)) { CreateChannel(type, channelName); } if (State == ConnectionState.Connected) { if (type == ChannelTypes.Presence || type == ChannelTypes.Private) { string jsonAuth = _options.Authorizer.Authorize(channelName, _connection.SocketID); var template = new { auth = String.Empty, channel_data = String.Empty }; var message = JsonConvert.DeserializeAnonymousType(jsonAuth, template); _connection.Send(JsonConvert.SerializeObject(new { @event = Constants.CHANNEL_SUBSCRIBE, data = new { channel = channelName, auth = message.auth, channel_data = message.channel_data } })); } else { // No need for auth details. Just send subscribe event _connection.Send(JsonConvert.SerializeObject(new { @event = Constants.CHANNEL_SUBSCRIBE, data = new { channel = channelName } })); } } return(Channels[channelName]); }
public async Task TriggerNotSubscribedErrorTestAsync() { // Arrange ChannelTypes channelType = ChannelTypes.Private; Pusher localPusher = PusherFactory.GetPusher(channelType: ChannelTypes.Presence, saveTo: _clients); string testEventName = "client-pusher-event-test"; PusherEvent pusherEvent = CreatePusherEvent(channelType, testEventName); await localPusher.ConnectAsync().ConfigureAwait(false); Channel localChannel = await localPusher.SubscribeAsync(pusherEvent.ChannelName).ConfigureAwait(false); TriggerEventException exception = null; // Act await localPusher.UnsubscribeAllAsync().ConfigureAwait(false); try { await localChannel.TriggerAsync(testEventName, pusherEvent.Data); } catch (TriggerEventException error) { exception = error; } // Assert Assert.IsNotNull(exception, $"Expected a {nameof(TriggerEventException)}"); Assert.AreEqual(ErrorCodes.TriggerEventNotSubscribedError, exception.PusherCode); }
private static string GetChannelText(ChannelTypes channelType, PlayerInstance ch) { var attrib = channelType.GetAttribute <ChannelAttribute>(); if (attrib == null) { throw new InvalidOperationException(); } var minTrust = 0; var trustAttrib = channelType.GetAttribute <RequireTrustChannelAttribute>(); if (trustAttrib != null) { minTrust = GameConstants.GetConstant <int>(trustAttrib.TrustType); } if (attrib.Verify(channelType, ch, minTrust)) { var print = channelType.GetAttribute <ChannelPrintAttribute>(); if (print == null) { throw new InvalidOperationException("ChannelPrint attribute missing from ChannelType"); } return(!ch.Deaf.IsSet(channelType) ? print.On : print.Off); } return(string.Empty); }
public async Task PusherEventEmitterPrivateChannelUnbindListenerTestAsync() { ChannelTypes channelType = ChannelTypes.Private; await PusherEventEmitterUnbindTestAsync(channelType, listenersToUnbind : new List <int> { 3 }).ConfigureAwait(false); }
public async Task TextEventEmitterPresenceChannelUnbindListenerTestAsync() { ChannelTypes channelType = ChannelTypes.Presence; await TextEventEmitterUnbindTestAsync(channelType, listenersToUnbind : new List <int> { 2 }).ConfigureAwait(false); }
public async Task DynamicEventEmitterPrivateChannelUnbindAllTestAsync() { ChannelTypes channelType = ChannelTypes.Private; await DynamicEventEmitterUnbindTestAsync(channelType, listenersToUnbind : new List <int> { 0, 1, 2, 3 }).ConfigureAwait(false); }
public async Task DynamicEventEmitterPresenceChannelUnbindGeneralListenerTestAsync() { ChannelTypes channelType = ChannelTypes.Presence; await DynamicEventEmitterUnbindTestAsync(channelType, listenersToUnbind : new List <int> { 0 }).ConfigureAwait(false); }
public async Task TextEventEmitterPrivateChannelUnbindAllGeneralListenersTestAsync() { ChannelTypes channelType = ChannelTypes.Private; await TextEventEmitterUnbindTestAsync(channelType, listenersToUnbind : new List <int> { 0, 1 }).ConfigureAwait(false); }
public async Task PusherEventEmitterPresenceChannelUnbindAllTestAsync() { ChannelTypes channelType = ChannelTypes.Presence; await PusherEventEmitterUnbindTestAsync(channelType, listenersToUnbind : new List <int> { 0, 1, 2, 3 }).ConfigureAwait(false); }
public override bool Verify(ChannelTypes channelType, PlayerInstance ch, int minTrust = 0) { if (ch.PlayerData.Council == null) { return(false); } return(!NoNpc || !ch.IsNpc()); }
public static void SendToChat(CharacterInstance ch, string argument, ChannelTypes channel, string channelName) { if (CheckFunctions.CheckIfTrue(ch, ch.IsNotAuthorized(), "Huh?")) { return; } talk_channel(ch, argument, channel, channelName); }
public async Task PusherEventEmitterPrivateEncryptedChannelTestAsync() { // Arrange byte[] encryptionKey = GenerateEncryptionMasterKey(); var pusherServer = new PusherServer.Pusher(Config.AppId, Config.AppKey, Config.AppSecret, new PusherServer.PusherOptions { Cluster = Config.Cluster, EncryptionMasterKey = encryptionKey, }); ChannelTypes channelType = ChannelTypes.PrivateEncrypted; Pusher localPusher = PusherFactory.GetPusher(channelType: ChannelTypes.Presence, saveTo: _clients, encryptionKey: encryptionKey); string testEventName = "private-encrypted-event-test"; AutoResetEvent globalEventReceived = new AutoResetEvent(false); AutoResetEvent channelEventReceived = new AutoResetEvent(false); PusherEvent globalEvent = null; PusherEvent channelEvent = null; PusherEvent pusherEvent = CreatePusherEvent(channelType, testEventName); await localPusher.ConnectAsync().ConfigureAwait(false); Channel localChannel = await localPusher.SubscribeAsync(pusherEvent.ChannelName).ConfigureAwait(false); void GeneralListener(string eventName, PusherEvent eventData) { if (eventName == testEventName) { globalEvent = eventData; globalEventReceived.Set(); } } void Listener(PusherEvent eventData) { channelEvent = eventData; channelEventReceived.Set(); } EventTestData data = new EventTestData { TextField = ExpectedTextField, IntegerField = ExpectedIntegerField, }; // Act localPusher.BindAll(GeneralListener); localChannel.Bind(testEventName, Listener); await pusherServer.TriggerAsync(pusherEvent.ChannelName, testEventName, data).ConfigureAwait(false); // Assert Assert.IsTrue(globalEventReceived.WaitOne(TimeSpan.FromSeconds(5))); Assert.IsTrue(channelEventReceived.WaitOne(TimeSpan.FromSeconds(5))); AssertPusherEventsAreEqual(channelType, pusherEvent, globalEvent); AssertPusherEventsAreEqual(channelType, pusherEvent, channelEvent); }
private async Task SubscribeWithoutConnectingTestAsync(ChannelTypes channelType) { // Arrange Pusher pusher = PusherFactory.GetPusher(channelType: channelType, saveTo: _clients); string mockChannelName = ChannelNameFactory.CreateUniqueChannelName(channelType: channelType); // Act Channel subscribedChannel = await pusher.SubscribeAsync(mockChannelName).ConfigureAwait(false); // Assert ValidateDisconnectedChannel(pusher, mockChannelName, subscribedChannel, channelType); }
public bool SendMessage(NetOutgoingMessage message, NetDeliveryMethod method, ChannelTypes channelType) { if (_netClient.ConnectionStatus == NetConnectionStatus.Connected) { _netClient.SendMessage(message, method, (int)channelType); return true; } else { _packetCache.Add(new Tuple<NetOutgoingMessage, NetDeliveryMethod, ChannelTypes>(message, method, channelType)); return false; } }
/// <summary> /// Initializes a new instance of the ChannelInfo class that contain the values extracted from the given byte array. /// </summary> /// <param name="byteArray">The size of array need to be at least of 128 bytes.</param> public ChannelInfo(Byte[] byteArray) { _TypeOfChannel = ChannelTypes.Subbottom; _SubChannelNumber = 0; _CorrectionFlag = CorrectionFlags.Range; _Polarity = DataPolarity.Bipolar; _BytesPerSample = 0; _SamplesPerChannel = 0; _ChannelName = " "; _VoltScale = 0; _Frequency = 0; _HorizontalBeamAngle = 0; _TiltAngle = 0; _BeamWidth = 0; _OffsetX = 0; _OffsetY = 0; _OffsetZ = 0; _OffsetYaw = 0; _OffsetPitch = 0; _OffsetRoll = 0; _BeamsPerArray = 0; _Latency = 0; using (BinaryReader dp = new BinaryReader(ArrayToStream.BytesToMemory(byteArray))) { if (byteArray.Length >= 128) { _TypeOfChannel = (ChannelTypes)dp.ReadByte(); // 0 _SubChannelNumber = dp.ReadByte(); // 1 _CorrectionFlag = (CorrectionFlags)dp.ReadUInt16(); // 2-3 _Polarity = (DataPolarity)dp.ReadUInt16(); // 4-5 _BytesPerSample = dp.ReadUInt16(); // 6-7 _SamplesPerChannel = dp.ReadUInt32(); // 8-9-10-11 _ChannelName = new String(dp.ReadChars(16)); // 12-13-14-15-16-17-18-19-20-21-22-23-24-25-26-27 _VoltScale = dp.ReadSingle(); // 28-29-30-31 _Frequency = dp.ReadSingle(); // 32-33-34-35 _HorizontalBeamAngle = dp.ReadSingle(); // 36-37-38-39 _TiltAngle = dp.ReadSingle(); // 40-41-42-43 _BeamWidth = dp.ReadSingle(); // 44-45-46-47 _OffsetX = dp.ReadSingle(); // 48-49-50-51 _OffsetY = dp.ReadSingle(); // 52-53-54-55 _OffsetZ = dp.ReadSingle(); // 56-57-58-59 _OffsetYaw = dp.ReadSingle(); // 60-61-62-63 _OffsetPitch = dp.ReadSingle(); // 64-65-66-67 _OffsetRoll = dp.ReadSingle(); // 68-69-70-71 _BeamsPerArray = dp.ReadUInt16(); // 72-73 _Latency = dp.ReadSingle(); // 74-75-76-77 } } }
public override bool Verify(ChannelTypes channelType, PlayerInstance ch, int minTrust = 0) { if (ch.PlayerData.Clan == null) { return(false); } if (NoNpc && ch.IsNpc()) { return(false); } return(ClanType == ch.PlayerData.Clan.ClanType); }
public async Task PusherShouldErrorWhenSubscribeTimesOutAsync() { // Arrange AutoResetEvent errorEvent = new AutoResetEvent(false); PusherException exception = null; PusherException caughtException = null; ChannelTypes channelType = ChannelTypes.Presence; string channelName = ChannelNameFactory.CreateUniqueChannelName(channelType: channelType); var pusher = PusherFactory.GetPusher(channelType: channelType, saveTo: _clients); await pusher.ConnectAsync().ConfigureAwait(false); ((IPusher)pusher).PusherOptions.ClientTimeout = TimeSpan.FromMilliseconds(20); pusher.Error += (sender, error) => { exception = error; errorEvent.Set(); }; // Act // Try to generate the error multiple times as it does not always error the first time for (int attempt = 0; attempt < TimeoutRetryAttempts; attempt++) { try { await pusher.SubscribePresenceAsync <FakeUserInfo>(channelName).ConfigureAwait(false); } catch (Exception error) { caughtException = error as PusherException; } if (caughtException != null) { break; } } // Assert // This test does not always work on the build server, requires more than 2 CPU(s) for better reliability if (caughtException != null) { Assert.IsTrue(errorEvent.WaitOne(TimeSpan.FromSeconds(5))); Assert.IsNotNull(exception, $"Error expected to be {nameof(PusherException)}"); Assert.AreEqual(exception.Message, caughtException.Message); Assert.AreEqual(ErrorCodes.ClientTimeout, exception.PusherCode, "Unexpected error: " + exception.Message); } }
public async Task UnsubscribeAsync() { // Arrange ChannelTypes channelType = ChannelTypes.Presence; string channelName = ChannelNameFactory.CreateUniqueChannelName(channelType: channelType); Pusher pusher = PusherFactory.GetPusher(channelType: channelType, saveTo: _clients); Channel channel = await SubscribeAsync(connectBeforeSubscribing : true, pusher : pusher, channelName : channelName).ConfigureAwait(false); // Act await pusher.UnsubscribeAsync(channelName).ConfigureAwait(false); // Assert SubscriptionTest.ValidateUnsubscribedChannel(pusher, channel); }
/// <summary> /// Registers a callback to the specified channelType with the given channelID /// </summary> /// <param name="channel"></param> /// <param name="callback"></param> public void Subscribe(ChannelTypes channelType, int channelID, EventHandler <NetworkMessageContainer> callback) { _sub.Subscribe(channelType.ToString() + channelID.ToString(), (rc, rv) => { try { callback(this, SerializationUtilities.DeserializeMsgPack <NetworkMessageContainer>(rv)); } catch (Exception e) { ConsoleManager.WriteLine("Redis exception! " + e.Message, ConsoleMessageType.Error); ConsoleManager.WriteLine(e.StackTrace, ConsoleMessageType.Error); } }); }
private static ATTypes GetColorForChannelTalk(ChannelTypes channel) { switch (channel) { case ChannelTypes.RaceTalk: return(ATTypes.AT_RACETALK); case ChannelTypes.WarTalk: return(ATTypes.AT_WARTALK); case ChannelTypes.ImmTalk: case ChannelTypes.AvTalk: return(0); } return(ATTypes.AT_GOSSIP); }
/// <summary> /// </summary> /// <param name="channelType"></param> /// <exception cref="ArgumentOutOfRangeException">ChannelType not equal with exists channel groups</exception> /// <returns></returns> public static int GetPerPage(ChannelTypes channelType) { switch (channelType) { case ChannelTypes.Private: return(PrivateChannelOut.PRIVATE_PER_PAGE); case ChannelTypes.Group: return(GroupChannelOut.GROUP_PER_PAGE); case ChannelTypes.Alliance: return(AllianceChannelOut.ALLIANCE_PER_PAGE); default: throw new ArgumentOutOfRangeException(nameof(channelType), channelType, Error.NotEquals); } }
private static PusherEvent CreatePusherEvent(ChannelTypes channelType, string eventName) { EventTestData data = new EventTestData { TextField = ExpectedTextField, IntegerField = ExpectedIntegerField, }; Dictionary <string, object> properties = new Dictionary <string, object> { { "channel", ChannelNameFactory.CreateUniqueChannelName(channelType: channelType) }, { "event", eventName }, { "data", data }, }; PusherEvent result = new PusherEvent(properties, JsonConvert.SerializeObject(properties)); return(result); }
public static Pusher GetPusher(ChannelTypes channelType, string username = null, IList <Pusher> saveTo = null, byte[] encryptionKey = null) { Pusher result; switch (channelType) { case ChannelTypes.Private: case ChannelTypes.Presence: result = GetPusher(new FakeAuthoriser(username ?? UserNameFactory.CreateUniqueUserName(), encryptionKey), saveTo: saveTo); break; default: result = GetPusher(authorizer: null, saveTo: saveTo); break; } return(result); }
private async Task DynamicEventEmitterTestAsync(ChannelTypes channelType) { // Arrange Pusher localPusher = PusherFactory.GetPusher(channelType: ChannelTypes.Presence, saveTo: _clients); string testEventName = "client-dynamic-event-test"; AutoResetEvent globalEventReceived = new AutoResetEvent(false); AutoResetEvent channelEventReceived = new AutoResetEvent(false); dynamic globalEvent = null; dynamic channelEvent = null; dynamic dynamicEventData = CreateDynamicEventData(); string channelName = ChannelNameFactory.CreateUniqueChannelName(channelType: channelType); await localPusher.ConnectAsync().ConfigureAwait(false); Channel remoteChannel = await _remoteClient.SubscribeAsync(channelName).ConfigureAwait(false); Channel localChannel = await localPusher.SubscribeAsync(channelName).ConfigureAwait(false); void GeneralListener(string eventName, dynamic eventData) { if (eventName == testEventName) { globalEvent = eventData; globalEventReceived.Set(); } } void Listener(dynamic eventData) { channelEvent = eventData; channelEventReceived.Set(); } // Act localPusher.BindAll(GeneralListener); localChannel.Bind(testEventName, Listener); remoteChannel.Trigger(testEventName, dynamicEventData); // Assert Assert.IsTrue(globalEventReceived.WaitOne(TimeSpan.FromSeconds(5))); Assert.IsTrue(channelEventReceived.WaitOne(TimeSpan.FromSeconds(5))); ValidateDynamicEvent(channelName, testEventName, globalEvent); ValidateDynamicEvent(channelName, testEventName, channelEvent); }
private void CreateChannel(ChannelTypes type, string channelName) { switch (type) { case ChannelTypes.Public: Channels[channelName] = new Channel(channelName, this); break; case ChannelTypes.Private: AuthEndpointCheck(); Channels[channelName] = new PrivateChannel(channelName, this); break; case ChannelTypes.Presence: AuthEndpointCheck(); Channels[channelName] = new PresenceChannel(channelName, this); break; } }
private Channel SubscribeToChannel(ChannelTypes type, string channelName) { switch (type) { case ChannelTypes.Public: Channels.Add(channelName, new Channel(channelName, this)); break; case ChannelTypes.Private: AuthEndpointCheck(); Channels.Add(channelName, new PrivateChannel(channelName, this)); break; case ChannelTypes.Presence: AuthEndpointCheck(); Channels.Add(channelName, new PresenceChannel(channelName, this)); break; } if (type == ChannelTypes.Presence || type == ChannelTypes.Private) { Log("Calling auth for channel for: " + channelName); AuthorizeChannel(channelName); } else { // No need for auth details. Just send subscribe event _connection.Send(JsonHelper.Serialize(new Dictionary <string, object>() { { "event", Constants.CHANNEL_SUBSCRIBE }, { "data", new Dictionary <string, object>() { { "channel", channelName } } } })); } return(Channels[channelName]); }
private Channel SubscribeToChannel(ChannelTypes type, string channelName) { switch (type) { case ChannelTypes.Public: Channels.Add(channelName, new Channel(channelName, this)); break; case ChannelTypes.Private: AuthEndpointCheck(); Channels.Add(channelName, new PrivateChannel(channelName, this)); break; case ChannelTypes.Presence: AuthEndpointCheck(); Channels.Add(channelName, new PresenceChannel(channelName, this)); break; } if (type == ChannelTypes.Presence || type == ChannelTypes.Private) { string jsonAuth = _options.Authorizer.Authorize(channelName, _connection.SocketID); var template = new { auth = String.Empty, channel_data = String.Empty }; var message = JsonConvert.DeserializeAnonymousType(jsonAuth, template); _connection.Send(JsonConvert.SerializeObject(new { @event = Constants.CHANNEL_SUBSCRIBE, data = new { channel = channelName, auth = message.auth, channel_data = message.channel_data } })); } else { // No need for auth details. Just send subscribe event _connection.Send(JsonConvert.SerializeObject(new { @event = Constants.CHANNEL_SUBSCRIBE, data = new { channel = channelName } })); } return Channels[channelName]; }
private Channel SubscribeToChannel(ChannelTypes type, string channelName) { if (!Channels.ContainsKey(channelName)) CreateChannel(type, channelName); if (State == ConnectionState.Connected) { if (type == ChannelTypes.Presence || type == ChannelTypes.Private) { string jsonAuth = _options.Authorizer.Authorize(channelName, _connection.SocketID); var template = new { auth = String.Empty, channel_data = String.Empty }; var message = JsonConvert.DeserializeAnonymousType(jsonAuth, template); _connection.Send(JsonConvert.SerializeObject(new { @event = Constants.CHANNEL_SUBSCRIBE, data = new { channel = channelName, auth = message.auth, channel_data = message.channel_data } })); } else { // No need for auth details. Just send subscribe event _connection.Send(JsonConvert.SerializeObject(new { @event = Constants.CHANNEL_SUBSCRIBE, data = new { channel = channelName } })); } } return Channels[channelName]; }
private void CreateChannel(ChannelTypes type, string channelName) { switch (type) { case ChannelTypes.Public: Channels.Add(channelName, new Channel(channelName, this)); break; case ChannelTypes.Private: AuthEndpointCheck(); Channels.Add(channelName, new PrivateChannel(channelName, this)); break; case ChannelTypes.Presence: AuthEndpointCheck(); Channels.Add(channelName, new PresenceChannel(channelName, this)); break; } }
public void SendPacket(Packet packet, NetDeliveryMethod method, ChannelTypes type, bool checkPlayerLoaded = false) { foreach (var player in this.players) { if (checkPlayerLoaded) { if (!player.InMap) continue; } player.Connection.SendMessage(packet.Message, method, (int)type); } }
private Channel SubscribeToChannel(ChannelTypes type, string channelName) { switch (type) { case ChannelTypes.Public: Channels.Add(channelName, new Channel(channelName, this)); break; case ChannelTypes.Private: AuthEndpointCheck(); Channels.Add(channelName, new PrivateChannel(channelName, this)); break; case ChannelTypes.Presence: AuthEndpointCheck(); Channels.Add(channelName, new PresenceChannel(channelName, this)); break; } if (type == ChannelTypes.Presence || type == ChannelTypes.Private) { Log( "Calling auth for channel for: " + channelName ); AuthorizeChannel( channelName ); } else { // No need for auth details. Just send subscribe event _connection.Send(JsonHelper.Serialize(new Dictionary<string, object>() { { "event", Constants.CHANNEL_SUBSCRIBE }, { "data", new Dictionary<string,object>() { { "channel", channelName } } } })); } return Channels[channelName]; }
private Channel SubscribeToChannel(ChannelTypes type, string channelName) { Channel channel = null; switch (type) { case ChannelTypes.Public: channel = new Channel(channelName, this); Channels.Add(channelName, channel); break; case ChannelTypes.Private: AuthEndpointCheck(); channel = new PrivateChannel(channelName, this); Channels.Add(channelName, channel); break; case ChannelTypes.Presence: AuthEndpointCheck(); channel = new PresenceChannel(channelName, this); Channels.Add(channelName, channel); break; } if (type == ChannelTypes.Presence || type == ChannelTypes.Private) { Task.Factory.StartNew(() => // TODO: if failed, communicate it out { try { string jsonAuth = _options.Authorizer.Authorize(channelName, _connection.SocketID); var template = new { auth = String.Empty, channel_data = String.Empty }; var message = JsonConvert.DeserializeAnonymousType(jsonAuth, template); _connection.Send(JsonConvert.SerializeObject(new { @event = Constants.CHANNEL_SUBSCRIBE, data = new { channel = channelName, auth = message.auth, channel_data = message.channel_data } })); } catch(Exception ex) { channel.SubscriptionFailed(ErrorCodes.ConnectionFailed, ex.Message); } }); } else { try { // No need for auth details. Just send subscribe event _connection.Send(JsonConvert.SerializeObject(new { @event = Constants.CHANNEL_SUBSCRIBE, data = new { channel = channelName } })); } catch (Exception ex) { channel.SubscriptionFailed(ErrorCodes.ConnectionFailed, ex.Message); } } return Channels[channelName]; }