Esempio n. 1
0
        private void SetListenToTopic(bool listen, PubSubTopic topic)
        {
            string nonce;

            do
            {
                nonce = GenerateNonce();
            } while (!parser.AddNonce(nonce, topic.Topic));

            var jObj = new JObject(
                new JProperty("type", listen ? "LISTEN" : "UNLISTEN"),
                new JProperty("nonce", nonce),
                new JProperty("data",
                              new JObject(
                                  new JProperty("topics",
                                                new JArray(
                                                    new JValue(topic.Topic)
                                                    )
                                                )
                                  )
                              )
                );

            if (topic.IsAuthorized)
            {
                if (string.IsNullOrEmpty(topic.OAuthToken))
                {
                    throw new ArgumentException("Topic cannot have null or empty token if it needs authorization",
                                                nameof(topic));
                }
                ((JObject)jObj.SelectToken("data")).Add(new JProperty("auth_token", topic.OAuthToken));
            }

            socket.Send(jObj.ToString());
        }
Esempio n. 2
0
 /// <summary>
 /// Stops listening to a topic
 /// </summary>
 /// <param name="topic">the topic to stop listening to</param>
 public void Unlisten(PubSubTopic topic)
 {
     ThrowIfDisposed();
     if (topic == null)
     {
         throw new ArgumentNullException(nameof(topic));
     }
     SetListenToTopic(false, topic);
 }