Ejemplo n.º 1
0
        // publish a message to a channel
        public void publish_channel(publish p)
        {
            if (protocol.pubsub != null)
            {
                // attempt to pull the channel from pubsub
                PubSub_Channel c = protocol.pubsub.GetChannel(p.channel_name_or_uri);

                // make sure channel exists
                if (c != null)
                {
                    // create the pubsub event
                    PubSub_Event e = new PubSub_Event(p.message);

                    // add the event to the channel
                    c.add_event(e);

                    // generate event object
                    _event ev = new _event(p.channel_name_or_uri, e);

                    // setup subscribers list
                    List<WS3V_Client> subscribers;

                    if (p.echo)
                        // blast the event to all subscribed
                        subscribers = protocol.WS3V_Clients.Select(g => g.Value).Where(s => s.subscriptions != null && s.subscriptions.Any(y => y.channel_name_or_uri == p.channel_name_or_uri)).ToList();

                    else
                        // blast the event to all subscribed except current client
                        subscribers = protocol.WS3V_Clients.Select(g => g.Value).Where(s => s.protocol.clientID != protocol.clientID && s.subscriptions != null && s.subscriptions.Any(y => y.channel_name_or_uri == p.channel_name_or_uri)).ToList();

                    // serialize event
                    string msg = ev.ToString();

                    // loop over clients and send message blast
                    for (int i = 0; i < subscribers.Count; i++)
                        subscribers[i].SocketSend(msg);
                }

            }
        }
Ejemplo n.º 2
0
        // publish a message to a channel
        public void publish_channel(string[] message)
        {
            // extract publish information
            publish p = new publish(message);

            // process
            publish_channel(p);
        }
Ejemplo n.º 3
0
        // publish a message to a channel
        public void publish_channel(string channel_name_or_uri, string message, bool echo)
        {
            // build publish object
            publish p = new publish();
            p.channel_name_or_uri = channel_name_or_uri;
            p.message = message;
            p.echo = echo;

            // process
            publish_channel(p);
        }
Ejemplo n.º 4
0
        public void publish()
        {
            // documentation example 1
            string input = "[15,\"\\/public\\/chatrooms\\/A\\/22\",\"best day ever was when I first heard phil on the radio\"]";
            string[] message = JSONDecoders.DecodeJSONArray(input);
            Assert.AreEqual(message[0], "15");

            publish p = new publish(message);
            Assert.AreEqual(p.channel_name_or_uri, "/public/chatrooms/A/22");
            Assert.AreEqual(p.message, "best day ever was when I first heard phil on the radio");
            Assert.AreEqual(p.echo, false);

            // documentation example 2
            input = "[15,\"\\/public\\/chatrooms\\/A\\/22\",{\"message\":\"best day ever was when I first heard phil on the radio\",\"priority\":\"urgent\"},true]";
            message = JSONDecoders.DecodeJSONArray(input);
            Assert.AreEqual(message[0], "15");

            p = new publish(message);
            Assert.AreEqual(p.channel_name_or_uri, "/public/chatrooms/A/22");
            Assert.AreEqual(p.message, "{\"message\":\"best day ever was when I first heard phil on the radio\",\"priority\":\"urgent\"}");
            Assert.AreEqual(p.echo, true);
        }