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);
        }
Ejemplo n.º 2
0
        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;
            }
        }
Ejemplo n.º 3
0
        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;
            }
        }
Ejemplo n.º 4
0
        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];
        }