Beispiel #1
0
        public IRealtimeChannel Get(string name, ChannelOptions options)
        {
            // if the channel cannot be found
            if (!Channels.TryGetValue(name, out var result))
            {
                // create a new instance using the passed in option
                var channel = new RealtimeChannel(name, _realtimeClient.Options.GetClientId(), _realtimeClient, options);
                result = Channels.AddOrUpdate(name, channel, (s, realtimeChannel) =>
                {
                    if (options != null)
                    {
                        realtimeChannel.Options = options;
                    }

                    return(realtimeChannel);
                });
            }
            else
            {
                if (options != null)
                {
                    result.Options = options;
                }
            }

            return(result);
        }
        public IRealtimeChannel Get(string name, ChannelOptions options)
        {
            RealtimeChannel result = null;

            if (!_channels.TryGetValue(name, out result))
            {
                var channel = new RealtimeChannel(name, _realtimeClient.Options.GetClientId(), _realtimeClient, options);
                result = _channels.AddOrUpdate(name, channel, (s, realtimeChannel) =>
                {
                    if (options != null)
                    {
                        realtimeChannel.Options = options;
                    }
                    return(realtimeChannel);
                });
            }
            else
            {
                if (options != null)
                {
                    result.Options = options;
                }
            }
            return(result);
        }
Beispiel #3
0
        /// <inheritdoc/>
        public IRealtimeChannel Get(string name, ChannelOptions options)
        {
            // if the channel cannot be found
            if (!Channels.TryGetValue(name, out var result))
            {
                // create a new instance using the passed in option
                var channel = new RealtimeChannel(name, _realtimeClient.Options.GetClientId(), _realtimeClient, options, _mobileDevice);
                result = Channels.AddOrUpdate(name, channel, (s, realtimeChannel) =>
                {
                    if (options != null)
                    {
                        realtimeChannel.Options = options;
                    }

                    return(realtimeChannel);
                });
                _orderedChannels.Add(result);
            }
            else
            {
                if (options != null)
                {
                    if (result.ShouldReAttach(options))
                    {
                        throw new AblyException(new ErrorInfo("Channels.Get() cannot be used to set channel options that would cause the channel to reattach. Please, use Channel.SetOptions() instead.", ErrorCodes.BadRequest, HttpStatusCode.BadRequest));
                    }

                    result.SetOptions(options);
                }
            }

            return(result);
        }
Beispiel #4
0
 internal Presence(IConnectionManager connection, RealtimeChannel channel, string cliendId)
 {
     Map             = new PresenceMap(channel.Name);
     pendingPresence = new List <QueuedPresenceMessage>();
     this.connection = connection;
     _channel        = channel;
     _channel.InternalStateChanged += OnChannelStateChanged;
     _clientId = cliendId;
 }
Beispiel #5
0
 public ChannelAwaiter(IRealtimeChannel channel, ChannelState awaitedState, ILogger logger = null, Action onTimeout = null)
 {
     Logger        = logger ?? DefaultLogger.LoggerInstance;
     _name         = $"#{channel.Name}:{awaitedState} awaiter";
     _channel      = channel as RealtimeChannel;
     _awaitedState = awaitedState;
     _timer        = new CountdownTimer(_name + " timer", logger);
     _onTimeout    = onTimeout;
     AttachListener();
 }
Beispiel #6
0
 internal Presence(IConnectionManager connection, RealtimeChannel channel, string cliendId, ILogger logger)
 {
     Logger           = logger;
     Map              = new PresenceMap(channel.Name, logger);
     _pendingPresence = new List <QueuedPresenceMessage>();
     _connection      = connection;
     _channel         = channel;
     _channel.InternalStateChanged += OnChannelStateChanged;
     _clientId = cliendId;
 }
Beispiel #7
0
 internal Presence(IConnectionManager connection, RealtimeChannel channel, string clientId, ILogger logger)
 {
     Logger               = logger;
     Map                  = new PresenceMap(channel.Name, logger);
     InternalMap          = new PresenceMap(channel.Name, logger);
     PendingPresenceQueue = new ConcurrentQueue <QueuedPresenceMessage>();
     _connection          = connection;
     _channel             = channel;
     _clientId            = clientId;
 }
Beispiel #8
0
 private void HandleInitialiseFailedChannelsCommand(RealtimeChannel channel)
 {
     switch (_realtimeClient.Connection.State)
     {
     case ConnectionState.Closed:
     case ConnectionState.Failed:
         /* (RTN11d)
          * If the [Connection] state is FAILED,
          * transitions all the channels to INITIALIZED */
         channel.SetChannelState(ChannelState.Initialized);
         break;
     }
 }
Beispiel #9
0
        public bool Release(string name)
        {
            if (Logger.IsDebug)
            {
                Logger.Debug($"Releasing channel #{name}");
            }
            RealtimeChannel channel = null;

            if (Channels.TryGetValue(name, out channel))
            {
                EventHandler <ChannelStateChange> eventHandler = null;
                eventHandler = (s, args) =>
                {
                    var detachedChannel = (RealtimeChannel)s;
                    if (args.Current == ChannelState.Detached || args.Current == ChannelState.Failed)
                    {
                        if (Logger.IsDebug)
                        {
                            Logger.Debug($"Channel #{name} was removed from Channel list. State {args.Current}");
                        }
                        detachedChannel.InternalStateChanged -= eventHandler;

                        RealtimeChannel removedChannel;
                        if (Channels.TryRemove(name, out removedChannel))
                        {
                            removedChannel.Dispose();
                        }
                    }
                    else
                    {
                        if (Logger.IsDebug)
                        {
                            Logger.Debug($"Waiting to remove Channel #{name}. State {args.Current}");
                        }
                    }
                };

                channel.InternalStateChanged += eventHandler;
                channel.Detach();
                return(true);
            }

            return(false);
        }
Beispiel #10
0
 public ChannelAwaiter(IRealtimeChannel channel, ChannelState awaitedState)
 {
     _channel      = channel as RealtimeChannel;
     _awaitedState = awaitedState;
 }