public GenesysNotifications(IGenesysTopicSubscriptions subscriptions, ILogger logger) { _subscriptions = subscriptions; _websocket = new GenesysWebsocketClient(_subscriptions); _messageReceivedSubscription = _websocket.MessageReceived.Subscribe(HandleMessage); _logger = logger; }
internal static StartResponse Create(IGenesysTopicSubscriptions subscriptions) => new StartResponse { Expires = subscriptions.Expires, ChannelId = subscriptions.ChannelId, Topics = subscriptions.Items.Keys.ToArray() };
public GenesysWebsocketClient(IGenesysTopicSubscriptions topicSubscriptions) : base(new System.Uri(topicSubscriptions.ChannelURI)) { }
internal static bool TryHandle(GenesysMessage message, ISubject <object> subject, IGenesysTopicSubscriptions topics) { var topicName = message.TopicName(); if (topics.Items.ContainsKey(topicName)) { var topicType = topics.Items[topicName]; if (topicType.IsGenericType && topicType.GetGenericTypeDefinition() == typeof(NotificationData <>)) { var data = JsonSerializer.Deserialize(message.Raw, topicType, _options.Value); if (data != null) { subject.OnNext(data); } } else { var body = message.EventBody(); var data = JsonSerializer.Deserialize(body.Value.GetRawText(), topics.Items[topicName], _options.Value); if (data != null) { subject.OnNext(data); } } return(true); } return(false); }