コード例 #1
0
        private void OnConnDisconnected(int connId, object sender, MqttClientDisconnectedEventArgs args)
        {
            if (_connection != null && _connection.Id != connId)
            {
                FizzLogger.W("Received disconnected event for old connection.");
            }

            FizzLogger.D("MQTT - OnDisconnected: " + args.ClientWasConnected.ToString());

            if (OnDisconnected != null)
            {
                if (args.Exception == null)
                {
                    OnDisconnected.Invoke(null);
                }
                else
                {
                    if (args.Exception.GetType() == typeof(MQTTnet.Adapter.MqttConnectingFailedException))
                    {
                        OnDisconnected.Invoke(ERROR_AUTH_FAILED);
                        if (_sessionRepo != null)
                        {
                            _sessionRepo.FetchToken(null);
                        }
                    }
                    else
                    {
                        OnDisconnected.Invoke(ERROR_CONNECTION_FAILED);
                    }
                }
            }
        }
コード例 #2
0
        public void SubscribeChannel(FizzChannelMeta channelMeta)
        {
            if (Client.State == FizzClientState.Closed)
            {
                FizzLogger.W("FizzClient should be opened before subscribing channel.");
                return;
            }

            if (channelMeta == null)
            {
                FizzLogger.E("FizzClient unable to subscribe, channel meta is null.");
                return;
            }

            if (channelLookup.ContainsKey(channelMeta.Id))
            {
                FizzLogger.W("FizzClient channel is already subscribed.");
                return;
            }

            FizzChannelModel channel = new FizzChannelModel(channelMeta);

            Channels.Add(channel);
            channelLookup.Add(channel.Id, channel);
            channel.SubscribeAndQueryLatest();
        }
コード例 #3
0
        public bool SetChannel(string channelId)
        {
            if (!_initialized)
            {
                Initialize();
            }

            FizzChannelModel channel = GetChannelById(channelId);

            if (channel == null)
            {
                return(false);
            }

            if (_channelsLookup.ContainsKey(channel.Id))
            {
                HandleChannelSelected(channel);
                return(true);
            }
            else
            {
                FizzLogger.W("FizzChatView: Unable to set channel, add channel first");
                return(false);
            }
        }
コード例 #4
0
        public void UnsubscribeUserNotifications(Action <FizzException> cb)
        {
            if (Client.State == FizzClientState.Closed)
            {
                FizzLogger.W("FizzClient should be opened before unsubscribing user.");
                return;
            }

            try
            {
                Client.Chat.UserNotifications.Unsubscribe(ex =>
                {
                    if (ex == null)
                    {
                        if (OnUserNotificationsUnsubscribed != null)
                        {
                            OnUserNotificationsUnsubscribed.Invoke();
                        }
                    }

                    FizzUtils.DoCallback(ex, cb);
                });
            }
            catch (Exception e)
            {
                FizzLogger.E(e);
            }
        }
コード例 #5
0
        public void AddChannel(string channelId, bool select = false)
        {
            if (!_initialized)
            {
                Initialize();
            }

            FizzChannelModel channel = GetChannelById(channelId);

            if (channel == null)
            {
                if (!_channelWatchList.Contains(channelId))
                {
                    _channelWatchList.Add(channelId);
                }
                FizzLogger.W("Channel not found, please add channel [" + channelId + "] to FizzService first.");
                return;
            }

            if (!_channelsLookup.ContainsKey(channel.Id))
            {
                AddChannelInternal(channel);
            }

            if (_channelsLookup.ContainsKey(channel.Id) && select)
            {
                HandleChannelSelected(channel);
            }
        }
コード例 #6
0
        public void Open(string userId, long curServerTS, IFizzAuthRestClient client)
        {
            IfClosed(() =>
            {
                if (_userId != null)
                {
                    FizzLogger.W("Please close instance before re-opening");
                    return;
                }

                if (userId == null)
                {
                    throw FizzException.ERROR_INVALID_USER_ID;
                }
                if (client == null)
                {
                    throw ERROR_INVALID_CLIENT;
                }

                _client     = client;
                _userId     = userId;
                _timeOffset = FizzUtils.Now() - curServerTS;
                _startTime  = FizzUtils.Now() + _timeOffset;
                _sessionId  = Guid.NewGuid().ToString();

                ClosePreviousSession();
                SessionStarted();

                _interval.Enable();
                _onLogEmpty = () => { };
            });
        }
コード例 #7
0
        public void Unsubscribe(Action <FizzException> cb)
        {
            if (Client.State == FizzClientState.Closed)
            {
                FizzLogger.W("FizzClient should be opened before unsubscribing user.");
                return;
            }

            try
            {
                Client.Chat.Users.Unsubscribe(Id, ex =>
                {
                    if (ex == null)
                    {
                        IsSubscribed = false;
                    }

                    FizzUtils.DoCallback(ex, cb);
                });
            }
            catch (Exception e)
            {
                FizzLogger.E(e);
            }
        }
コード例 #8
0
        public void UnsubscribeChannel(string channelId)
        {
            if (Client.State == FizzClientState.Closed)
            {
                FizzLogger.W("FizzClient should be opened before unsubscribing channel.");
                return;
            }

            if (string.IsNullOrEmpty(channelId))
            {
                FizzLogger.E("FizzClient unable to unsubscribe, channelId is null or empty.");
                return;
            }

            if (!channelLookup.ContainsKey(channelId))
            {
                FizzLogger.W("FizzService unable to remove, channel [" + channelId + "] does not exist. ");
                return;
            }

            FizzChannelModel channel = channelLookup[channelId];

            channelLookup.Remove(channelId);
            Channels.Remove(channel);
            channel.Unsubscribe(null);
        }
コード例 #9
0
        public void SubscribeChannel(FizzChannelMeta meta)
        {
            if (!_isIntialized)
            {
                Initialize();
            }

            if (Client.State == FizzClientState.Closed)
            {
                FizzLogger.W("FizzClient should be opened before subscribing channel.");
                return;
            }

            if (meta == null)
            {
                FizzLogger.E("FizzClient unable to subscribe, channel meta is null.");
                return;
            }

            if (channelLoopup.ContainsKey(meta.Id))
            {
                FizzLogger.W("FizzClient channel is already subscribed.");
                return;
            }

            FizzChannel fizzChannel = AddChannelToList(meta);

            if (IsConnected && fizzChannel != null)
            {
                fizzChannel.SubscribeAndQuery();
            }
        }
コード例 #10
0
        public void Put(FizzEvent item)
        {
            if (item == null)
            {
                FizzLogger.W("Empty item put in log");
                return;
            }

            log.Add(item.Id, item);
        }
コード例 #11
0
        public void Post(Action action)
        {
            if (action == null)
            {
                FizzLogger.W("Empty action scheduled posted");
                return;
            }

            Delay(0, action);
        }
コード例 #12
0
 private void IfClosed(Action callback)
 {
     if (_restClient == null)
     {
         FizzUtils.DoCallback(callback);
     }
     else
     {
         FizzLogger.W("Moderation client should be closed before opening.");
     }
 }
コード例 #13
0
 private void IfClosed(Action callback)
 {
     if (_client == null)
     {
         FizzUtils.DoCallback(callback);
     }
     else
     {
         FizzLogger.W("Client should have been closed.");
     }
 }
コード例 #14
0
 private void IfOpened(Action onInit)
 {
     if (string.IsNullOrEmpty(_userId))
     {
         FizzLogger.W("Ingestion must be opened before use.");
     }
     else
     {
         onInit.Invoke();
     }
 }
コード例 #15
0
 private void IfClosed(Action callback)
 {
     if (string.IsNullOrEmpty(_userId))
     {
         FizzUtils.DoCallback(callback);
     }
     else
     {
         FizzLogger.W("Chat client should be closed before opening.");
     }
 }
コード例 #16
0
 private void IfOpened(Action callback)
 {
     if (_restClient != null)
     {
         FizzUtils.DoCallback(callback);
     }
     else
     {
         FizzLogger.W("Moderation client should be opened before usage.");
     }
 }
コード例 #17
0
 private void IfClosed(Action onClose)
 {
     if (string.IsNullOrEmpty(_userId))
     {
         onClose.Invoke();
     }
     else
     {
         FizzLogger.W("Ingestion is already opened");
     }
 }
コード例 #18
0
 private void IfOpened(Action callback)
 {
     if (_restClient != null)
     {
         FizzUtils.DoCallback(callback);
     }
     else
     {
         FizzLogger.W("Client should have been opened.");
     }
 }
コード例 #19
0
 public void Delay(int delayMS, Action action)
 {
     if (action == null || delayMS < 0)
     {
         FizzLogger.W("Invalid timer scheduled");
         return;
     }
     lock (synclock)
     {
         timers.Add(FizzUtils.Now() + delayMS, action);
     }
 }
コード例 #20
0
 FizzChannelModel GetChannelById(string channelId)
 {
     try
     {
         return(FizzService.Instance.GetChannel(channelId));
     }
     catch (Exception)
     {
         FizzLogger.W("ChannelList unable to get channel with id " + channelId);
     }
     return(null);
 }
コード例 #21
0
        public void RemoveGroup(string groupId, Action <FizzException> cb)
        {
            if (Client.State == FizzClientState.Closed)
            {
                FizzLogger.W("FizzClient should be opened before removing group.");
                return;
            }

            Client.Chat.Users.RemoveGroup(UserId, groupId, ex =>
            {
                FizzUtils.DoCallback(ex, cb);
            });
        }
コード例 #22
0
        private void OnConnConnected(int connId, object sender, MqttClientConnectedEventArgs args)
        {
            if (_connection != null && _connection.Id != connId)
            {
                FizzLogger.W("Received conneced event for old connection.");
            }

            FizzLogger.D("MQTT - OnConnected: " + args.IsSessionPresent.ToString());

            if (OnConnected != null)
            {
                OnConnected.Invoke(!args.IsSessionPresent);
            }
        }
コード例 #23
0
        private void OnConnConnected(object sender, bool sessionPresent)
        {
            if (_connection != null)
            {
                FizzLogger.W("Received connected event for old connection.");
            }

            FizzLogger.D("MQTT - OnConnected: " + sessionPresent);

            if (OnConnected != null)
            {
                OnConnected.Invoke(!sessionPresent);
            }
        }
コード例 #24
0
        public void Flush()
        {
            if (_flushInProgress)
            {
                FizzUtils.DoCallback(_onLogEmpty);
                return;
            }

            _flushInProgress = true;
            _eventLog.Read(128, items =>
            {
                if (items.Count <= 0)
                {
                    _flushInProgress = false;
                    FizzUtils.DoCallback(_onLogEmpty);
                    return;
                }

                PostEvents(items, (response, ex) =>
                {
                    bool rollLog = true;

                    if (ex != null)
                    {
                        if (ex.Code == FizzError.ERROR_REQUEST_FAILED)
                        {
                            FizzLogger.W("Failed to submit events to service");
                            rollLog = false;
                        }
                        else
                        if (ex.Code == FizzError.ERROR_INVALID_REQUEST)
                        {
                            FizzLogger.E("Submission of some events failed: " + ex.Message);
                        }
                    }

                    if (rollLog)
                    {
                        _eventLog.RollTo(items[items.Count - 1]);
                    }

                    FizzUtils.DoCallback(_onLogEmpty);
                    _flushInProgress = false;
                });
            });
        }
コード例 #25
0
        public void Subscribe(Action <FizzException> cb)
        {
            if (Client.State == FizzClientState.Closed)
            {
                FizzLogger.W("FizzClient should be opened before subscribing user.");
                return;
            }

            Client.Chat.Users.Subscribe(Id, ex =>
            {
                if (ex == null)
                {
                    IsSubscribed = true;
                }

                FizzUtils.DoCallback(ex, cb);
            });
        }
コード例 #26
0
        public bool SetGroup(FizzGroupModel group)
        {
            if (!_initialized)
            {
                Initialize();
            }

            if (_channelsLookup.ContainsKey(group.Channel.Id))
            {
                HandleChannelSelected(group.Channel);
                return(true);
            }
            else
            {
                FizzLogger.W("FizzChatView: Unable to set group");
                return(false);
            }
        }
コード例 #27
0
        public void UpdateGroup(string groupId, Action <FizzException> cb)
        {
            if (Client.State == FizzClientState.Closed)
            {
                FizzLogger.W("FizzClient should be opened before joining group.");
                return;
            }

            Client.Chat.Users.UpdateGroup(UserId, groupId, null, null, ex =>
            {
                if (ex == null)
                {
                    GroupInvites.Remove(groupId);
                    groupLookup[groupId].Channel.SubscribeAndQueryLatest();
                }
                FizzUtils.DoCallback(ex, cb);
            });
        }
コード例 #28
0
        private void OnMessage(object sender, byte[] messagePayload)
        {
            try
            {
                string           payload = Encoding.UTF8.GetString(messagePayload);
                FizzTopicMessage message = new FizzTopicMessage(payload);

                FizzLogger.D("OnMessage with id: " + message.Id);

                switch (message.Type)
                {
                case "CMSGP":
                    if (OnMessagePublished != null)
                    {
                        OnMessagePublished.Invoke(AdaptTo(message));
                    }
                    break;

                case "CMSGU":
                    if (OnMessageUpdated != null)
                    {
                        OnMessageUpdated.Invoke(AdaptTo(message));
                    }
                    break;

                case "CMSGD":
                    if (OnMessageDeleted != null)
                    {
                        OnMessageDeleted.Invoke(AdaptTo(message));
                    }
                    break;

                default:
                    FizzLogger.W("unrecognized packet received: " + payload);
                    break;
                }
            }
            catch
            {
                FizzLogger.W("received invalid message: " + messagePayload);
            }
        }
コード例 #29
0
        private void SubscribeNotificationsAndFetchGroups()
        {
            if (Client.State == FizzClientState.Closed)
            {
                FizzLogger.W("FizzClient should be opened before subscribing user.");
                return;
            }

            Client.Chat.UserNotifications.Subscribe(ex =>
            {
                if (ex == null)
                {
                    if (ex == null)
                    {
                        IFizzFetchUserGroupsQuery groupFetchQuery = Client.Chat.Users.BuildFetchUserGroupsQuery(UserId);
                        FetchUserGroups(groupFetchQuery, new List <IFizzUserGroup>());
                    }
                }
            });
        }
コード例 #30
0
        public void GetUser(string userId, Action <FizzUserModel, FizzException> cb)
        {
            if (Client.State == FizzClientState.Closed)
            {
                FizzLogger.W("FizzClient should be opened before fetching user.");
                return;
            }

            if (userId == null)
            {
                FizzLogger.E("FizzClient unable to fetch, userId is null.");
                return;
            }

            requestQueue.Enqueue(new GetUserRequest(userId, cb));
            if (requestQueue.Count > 1)
            {
                return;
            }
            GetUser(requestQueue.Peek());
        }