예제 #1
0
        private void HandleSendData(Dictionary <string, string> data)
        {
            if (data == null)
            {
                return;
            }

            if (ChannelsView.CurrentSelectedChannel == null)
            {
                return;
            }

            FizzChannel channel = ChannelsView.CurrentSelectedChannel;

            try
            {
                long now = FizzUtils.Now();
                data.Add(FizzMessageCellModel.KEY_CLIENT_ID, now + "");

                FizzMessageCellModel model = new FizzMessageCellModel(
                    now,
                    FizzService.Instance.UserId,
                    FizzService.Instance.UserName,
                    channel.Id,
                    string.Empty,
                    data,
                    null,
                    now)
                {
                    DeliveryState = FizzChatCellDeliveryState.Pending
                };

                MessagesView.AddMessage(model);

                FizzService.Instance.Client.Chat.PublishMessage(
                    channel.Id,
                    FizzService.Instance.UserName,
                    string.Empty,
                    data,
                    FizzService.Instance.IsTranslationEnabled,
                    channel.Meta.FilterContent,
                    channel.Meta.PersistMessages,
                    exception =>
                {
                    if (exception == null)
                    {
                        model.DeliveryState = FizzChatCellDeliveryState.Sent;
                        MessagesView.AddMessage(model);


                        string dataStr = Utils.GetDictionaryToString(data, FizzMessageCellModel.KEY_CLIENT_ID);
                        FizzService.Instance.Client.Ingestion.TextMessageSent(channel.Id, dataStr, FizzService.Instance.UserName);
                    }
                });
            }
            catch
            {
                FizzLogger.E("Something went wrong while calling PublishMessage of FizzService.");
            }
        }
예제 #2
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();
            }
        }
예제 #3
0
        private void SyncViewState()
        {
            try
            {
                foreach (FizzChannelModel channel in FizzService.Instance.Channels)
                {
                    if (_channelWatchList.Contains(channel.Id) && !_channelsLookup.ContainsKey(channel.Id))
                    {
                        AddChannelInternal(channel);
                        _channelWatchList.Remove(channel.Id);
                    }
                }

                foreach (FizzGroupModel group in FizzService.Instance.GroupRepository.Groups)
                {
                    if (!_channelsLookup.ContainsKey(group.Channel.Id))
                    {
                        AddChannelInternal(group.Channel);
                    }
                }

                foreach (string channelId in _channelsLookup.Keys)
                {
                    if (FizzService.Instance.GetChannel(channelId) == null)
                    {
                        RemoveChannelInternal(channelId);
                    }
                }
            }
            catch (Exception ex)
            {
                FizzLogger.E("Something went wrong while calling Channels of FizzService." + ex);
            }
        }
예제 #4
0
        private void UpdateStatus(string status)
        {
            if (_message == null)
            {
                return;
            }

            // Update message with updated data
            try
            {
                Dictionary <string, string> data = _message.Data;
                data[CustomCellSample.KEY_DATA_STATUS] = status;
                FizzService.Instance.Client.Chat.UpdateMessage(_message.To, _message.Id, _message.Nick, _message.Body, string.Empty, data, false, false, true, ex =>
                {
                    if (ex == null)
                    {
                        FizzLogger.D("Status Updated");
                    }
                });
            }
            catch
            {
                FizzLogger.E("Something went wrong while calling UpdateMessage of FizzService.");
            }
        }
예제 #5
0
        private void OnDisconnected(bool clientConnected, Exception ex)
        {
            if (Disconnected != null)
            {
                _dispatcher.Post(() => Disconnected.Invoke(this, new FizzMqttDisconnectedArgs(clientConnected, ex)));
            }

            if (_manualDisconnect)
            {
                return;
            }

            if (!_retry)
            {
                return;
            }

            _dispatcher.Delay(RETRY_DELAY_MS, () => {
                try
                {
                    if (_client != null && !_manualDisconnect)
                    {
                        ConnectInternal();
                    }
                }
                catch
                {
                    FizzLogger.E("Unable to reconnect to Fizz event service.");
                }
            });
        }
예제 #6
0
        private void OnDisconnected(object sender, MqttClientDisconnectedEventArgs args)
        {
            if (Disconnected != null)
            {
                _dispatcher.Post(() => Disconnected.Invoke(_id, sender, args));
            }

            if (_manualDisconnect)
            {
                _manualDisconnect = false;
                return;
            }
            if (!_retry)
            {
                return;
            }

            _dispatcher.Delay(RETRY_DELAY_MS, () =>
            {
                try
                {
                    if (_client != null)
                    {
                        _client.ConnectAsync(_options);
                    }
                }
                catch
                {
                    FizzLogger.E("Unable to reconnect to Fizz event service.");
                }
            });
        }
예제 #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);
            }
        }
        public void SetChannel(string channelId)
        {
            Reset();

            if (!_isInitialized)
            {
                Initialize();
            }

            _channel = GetChannelById(channelId);

            if (_channel != null)
            {
                LoadChatAsync(true);
            }

            try
            {
                _userId = FizzService.Instance.UserId;
            }
            catch
            {
                FizzLogger.E("Something went wrong while calling FizzService.");
            }
        }
예제 #9
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();
        }
예제 #10
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);
            }
        }
예제 #11
0
        private FizzEvent BuildEvent(string sessionId, FizzEventType type, long timestamp, JSONNode fields)
        {
            try
            {
                UnityEngine.PlayerPrefs.SetString(KEY_SESSION_UPDATE_TS, (FizzUtils.Now() + _timeOffset).ToString());
                UnityEngine.PlayerPrefs.Save();

                return(new FizzEvent(
                           _userId,
                           type,
                           EVENT_VER,
                           sessionId,
                           timestamp,
                           PLATFORM,
                           BuildVer,
                           CustomDimesion01, CustomDimesion02, CustomDimesion03,
                           fields
                           ));
            }
            catch (Exception ex)
            {
                FizzLogger.E("Invalid event encountered: " + ex.Message);
                return(null);
            }
        }
예제 #12
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);
        }
예제 #13
0
        public void HandleConnect()
        {
            try
            {
                if (FizzService.Instance.IsConnected)
                {
                    return;
                }

                FizzService.Instance.Open(
                    userIdInputField.text,                                  //UserId
                    userNameInputField.text,                                //UserName
                    FizzLanguageCodes.AllLanguages[langCodeDropDown.value], //LanguageCode
                    FizzServices.All,
                    translationToggle.isOn,                                 //Translation
                    (success) =>
                {
                    if (success)
                    {
                        FizzLogger.D("FizzClient Opened Successfully!!");

                        FizzService.Instance.SubscribeChannel(hypercasualInputChannel);
                    }
                });
            }
            catch { FizzLogger.E("Unable to connect to Fizz!"); }
        }
예제 #14
0
 public void HandleDisconnect()
 {
     try
     {
         FizzService.Instance.Close();
     }
     catch { FizzLogger.E("Unable to disconnect to Fizz!"); }
 }
예제 #15
0
 private void SafeInvoke(Action callback)
 {
     try
     {
         callback.Invoke();
     }
     catch (Exception ex)
     {
         FizzLogger.E("Dispatched action threw except:\n" + ex.StackTrace);
     }
 }
예제 #16
0
 protected virtual void OnDisable()
 {
     try
     {
         FizzService.Instance.OnConnected    -= HandleOnConnected;
         FizzService.Instance.OnDisconnected -= HandleOnDisconnected;
     }
     catch
     {
         FizzLogger.E("Something went wrong while binding event of FizzService.");
     }
 }
예제 #17
0
 void RemoveInternalListeners()
 {
     try
     {
         Client.Chat.Listener.OnConnected       -= Listener_OnConnected;
         Client.Chat.Listener.OnDisconnected    -= Listener_OnDisconnected;
         Client.Chat.UserListener.OnUserUpdated -= Listener_OnUserUpdated;
     }
     catch (FizzException ex)
     {
         FizzLogger.E("Unable to unbind group listeners. " + ex.Message);
     }
 }
예제 #18
0
        protected override void OnDisable()
        {
            base.OnDisable();

            try
            {
                FizzService.Instance.OnChannelSubscribed   -= HandleOnChannelSubscribe;
                FizzService.Instance.OnChannelUnsubscribed -= HandleOnChannelUnsubscribe;
            }
            catch
            {
                FizzLogger.E("Unable to call FizzService.");
            }
        }
예제 #19
0
        public override void SubscribeAndQueryLatest()
        {
            try
            {
                if (FizzService.Instance.GroupRepository.GroupInvites.ContainsKey(GroupId))
                {
                    // Can't fetch messages of group with pending membership
                    return;
                }

                Subscribe(subEx =>
                {
                    if (subEx != null)
                    {
                        FizzLogger.E("Subscribe Error " + Id + " ex " + subEx.Message);
                    }
                    else
                    {
                        FizzLogger.D("Subscribed " + Id);

                        FizzService.Instance.Client.Chat.Groups.QueryLatest(GroupId, _channelMeta.InitialQueryMessageCount, (msgs, qEx) =>
                        {
                            if (qEx == null)
                            {
                                Reset();

                                if (msgs != null && msgs.Count > 0)
                                {
                                    AddMessages(msgs);
                                }

                                if (FizzService.Instance.OnChannelMessagesAvailable != null)
                                {
                                    FizzService.Instance.OnChannelMessagesAvailable.Invoke(Id);
                                }
                            }
                            else
                            {
                                FizzLogger.E("QueryLatest " + qEx.Message);
                            }
                        });
                    }
                });
            }
            catch (FizzException ex)
            {
                FizzLogger.E("SubscribeAndQuery ex " + ex.Message);
            }
        }
예제 #20
0
 void RemoveInternalListeners()
 {
     try
     {
         Client.Chat.Listener.OnConnected        -= Listener_OnConnected;
         Client.Chat.Listener.OnDisconnected     -= Listener_OnDisconnected;
         Client.Chat.Listener.OnMessageUpdated   -= Listener_OnMessageUpdated;
         Client.Chat.Listener.OnMessageDeleted   -= Listener_OnMessageDeleted;
         Client.Chat.Listener.OnMessagePublished -= Listener_OnMessagePublished;
     }
     catch (FizzException ex)
     {
         FizzLogger.E("Unable to unbind chat listeners. " + ex.Message);
     }
 }
 public void RollTo(FizzEvent item)
 {
     try
     {
         int index = log.IndexOfValue(item);
         for (int i = index; i >= 0; i--)
         {
             log.RemoveAt(i);
         }
     }
     catch (Exception e)
     {
         FizzLogger.E("Fizz Event Log RollTo " + e);
     }
 }
        private string GetLanguageCode()
        {
            string langCode = FizzLanguageCodes.English.Code;

            try
            {
                langCode = FizzService.Instance.Language.Code;
            }
            catch (Exception)
            {
                FizzLogger.E("Unable to get LanguageCode");
            }

            return(langCode);
        }
예제 #23
0
 void AddInternalListeners()
 {
     try
     {
         Client.Chat.Listener.OnConnected               += Listener_OnConnected;
         Client.Chat.Listener.OnDisconnected            += Listener_OnDisconnected;
         Client.Chat.GroupListener.OnGroupUpdated       += Listener_OnGroupUpdated;
         Client.Chat.GroupListener.OnGroupMemberAdded   += Listener_OnGroupMemberAdded;
         Client.Chat.GroupListener.OnGroupMemberRemoved += Listener_OnGroupMemberRemoved;
         Client.Chat.GroupListener.OnGroupMemberUpdated += Listener_OnGroupMemberUpdated;
     }
     catch (FizzException ex)
     {
         FizzLogger.E("Unable to bind group listeners. " + ex.Message);
     }
 }
예제 #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 Open(string userId, string userName, IFizzLanguageCode lang, FizzServices services, bool tranlation, Action <bool> onDone)
        {
            if (!_isIntialized)
            {
                Initialize();
            }

            if (string.IsNullOrEmpty(userId))
            {
                FizzLogger.E("FizzService can not open client with null of empty userId.");
                return;
            }

            if (string.IsNullOrEmpty(userName))
            {
                FizzLogger.E("FizzService can not open client with null of empty userName.");
                return;
            }

            if (lang == null)
            {
                FizzLogger.E("FizzService can not open client with null language code.");
                return;
            }

            UserId               = userId;
            UserName             = userName;
            Language             = lang;
            IsTranslationEnabled = tranlation;
            Client.Open(userId, lang, services, ex =>
            {
                if (onDone != null)
                {
                    onDone(ex == null);
                }

                if (ex != null)
                {
                    FizzLogger.E("Something went wrong while connecting to FizzClient. " + ex);
                }
                else
                {
                    AddInternalListeners();
                }
            });
        }
예제 #26
0
 private void OnRejectButtonPressed()
 {
     // Reject Group Invite
     try
     {
         FizzService.Instance.GroupRepository.RemoveGroup(_groupId, ex =>
         {
             if (ex == null)
             {
                 FizzLogger.D("Invite Rejected");
             }
         });
     }
     catch
     {
         FizzLogger.E("Something went wrong while calling Reject Group of FizzService.");
     }
 }
예제 #27
0
 private void OnAcceptButtonPressed()
 {
     // Accept Group Invite
     try
     {
         FizzService.Instance.GroupRepository.UpdateGroup(_groupId, ex =>
         {
             if (ex == null)
             {
                 FizzLogger.D("Invite Accepted");
             }
         });
     }
     catch
     {
         FizzLogger.E("Something went wrong while calling Join Group of FizzService.");
     }
 }
예제 #28
0
        private void RemoveListeners()
        {
            try
            {
                FizzService.Instance.OnConnected    -= OnConnected;
                FizzService.Instance.OnDisconnected -= OnDisconnected;
            }
            catch
            {
                FizzLogger.E("Something went wrong with binding events with FizzService.");
            }

            userNameInputField.onEndEdit.RemoveListener(HandleUserCradChange);
            userNameInputField.onEndEdit.RemoveListener(HandleUserCradChange);

            langCodeDropDown.onValueChanged.RemoveListener(HandleLangCodeChange);
            translationToggle.onValueChanged.RemoveListener(HandleTranslationToggleChange);
        }
예제 #29
0
        public bool FetchHistory(Action complete)
        {
            long beforeId = -1;

            if (_messageList.Count > 0)
            {
                beforeId = _messageList.First().Value.Id;
            }

            if (beforeId == -1)
            {
                return(false);
            }

            try
            {
                FizzService.Instance.Client.Chat.QueryLatest(Id, _channelMeta.InitialQueryMessageCount, beforeId, (msgs, qEx) =>
                {
                    if (qEx == null)
                    {
                        if (msgs != null && msgs.Count > 0)
                        {
                            AddMessages(msgs);
                        }

                        if (FizzService.Instance.OnChannelMessagesAvailable != null)
                        {
                            FizzService.Instance.OnChannelMessagesAvailable.Invoke(Id);
                        }
                    }

                    if (complete != null)
                    {
                        complete.Invoke();
                    }
                });
            }
            catch (FizzException ex)
            {
                FizzLogger.E("FetchHistory ex " + ex.Message);
            }

            return(true);
        }
예제 #30
0
        public void SubscribeAndQuery()
        {
            try
            {
                Subscribe(subEx =>
                {
                    if (subEx != null)
                    {
                        FizzLogger.E("Subscribe Error " + Id + " ex " + subEx.Message);
                    }
                    else
                    {
                        FizzLogger.D("Subscribed " + Id);

                        FizzService.Instance.Client.Chat.QueryLatest(Id, _channelMeta.InitialQueryMessageCount, (msgs, qEx) =>
                        {
                            if (qEx == null)
                            {
                                Reset();

                                if (msgs != null && msgs.Count > 0)
                                {
                                    AddMessages(msgs);
                                }

                                if (FizzService.Instance.OnChannelMessagesAvailable != null)
                                {
                                    FizzService.Instance.OnChannelMessagesAvailable.Invoke(Id);
                                }
                            }
                            else
                            {
                                FizzLogger.E("QueryLatest " + qEx.Message);
                            }
                        });
                    }
                });
            }
            catch (FizzException ex)
            {
                FizzLogger.E("SubscribeAndQuery ex " + ex.Message);
            }
        }