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."); } }
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(); } }
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); } }
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."); } }
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."); } }); }
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."); } }); }
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."); } }
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(); }
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); } }
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); } }
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); }
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!"); } }
public void HandleDisconnect() { try { FizzService.Instance.Close(); } catch { FizzLogger.E("Unable to disconnect to Fizz!"); } }
private void SafeInvoke(Action callback) { try { callback.Invoke(); } catch (Exception ex) { FizzLogger.E("Dispatched action threw except:\n" + ex.StackTrace); } }
protected virtual void OnDisable() { try { FizzService.Instance.OnConnected -= HandleOnConnected; FizzService.Instance.OnDisconnected -= HandleOnDisconnected; } catch { FizzLogger.E("Something went wrong while binding event of FizzService."); } }
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); } }
protected override void OnDisable() { base.OnDisable(); try { FizzService.Instance.OnChannelSubscribed -= HandleOnChannelSubscribe; FizzService.Instance.OnChannelUnsubscribed -= HandleOnChannelUnsubscribe; } catch { FizzLogger.E("Unable to call FizzService."); } }
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); } }
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); }
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); } }
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; }); }); }
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(); } }); }
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."); } }
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."); } }
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); }
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); }
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); } }