Example #1
0
        public bool SendText(string channel_id, string text)
        {
            if (!Connected)
            {
                return(false);
            }

            if (encoding_ == FunEncoding.kJson)
            {
                Dictionary <string, object> mcast_msg = new Dictionary <string, object>();
                mcast_msg[kChannelId] = channel_id;
                mcast_msg[kBounce]    = true;
                mcast_msg[kMessage]   = text;

                SendToChannel(mcast_msg);
            }
            else
            {
                FunChatMessage chat_msg = new FunChatMessage();
                chat_msg.text = text;

                FunMulticastMessage mcast_msg = FunapiMessage.CreateFunMessage(chat_msg, MulticastMessageType.chat);
                mcast_msg.channel = channel_id;
                mcast_msg.bounce  = true;

                SendToChannel(mcast_msg);
            }

            return(true);
        }
Example #2
0
        private void OnMulticastingReceived(string chat_channel, object data)
        {
            KeyValuePair <string, OnChannelMessage> p;

            lock (channel_lock_)
            {
                if (!channel_info_.TryGetValue(chat_channel, out p))
                {
                    DebugUtils.Log("You are not in the chat channel: {0}", chat_channel);
                    return;
                }
            }

            if (encoding_ == FunEncoding.kJson)
            {
                DebugUtils.Assert(data is Dictionary <string, object>);
                Dictionary <string, object> mcast_msg = data as Dictionary <string, object>;

                p.Value(chat_channel, mcast_msg["sender"] as string, mcast_msg["text"] as string);
            }
            else
            {
                DebugUtils.Assert(data is FunMulticastMessage);
                FunMulticastMessage mcast_msg = data as FunMulticastMessage;
                FunChatMessage      chat_msg  = Extensible.GetValue <FunChatMessage> (mcast_msg, (int)MulticastMessageType.chat);

                p.Value(chat_channel, chat_msg.sender, chat_msg.text);
            }
        }
Example #3
0
        void onReceived(string channel_id, string sender, object data)
        {
            if (encoding_ == FunEncoding.kJson)
            {
                string text = json_helper_.GetStringField(data, kMessage);

                lock (chat_channel_lock_)
                {
                    if (chat_channels_.ContainsKey(channel_id))
                    {
                        chat_channels_[channel_id](channel_id, sender, text);
                    }
                }
            }
            else
            {
                FunDebug.Assert(data is FunMulticastMessage);
                FunMulticastMessage mcast_msg = data as FunMulticastMessage;

                object         obj      = FunapiMessage.GetMessage(mcast_msg, MulticastMessageType.chat);
                FunChatMessage chat_msg = obj as FunChatMessage;

                lock (chat_channel_lock_)
                {
                    if (chat_channels_.ContainsKey(channel_id))
                    {
                        chat_channels_[channel_id](channel_id, sender, chat_msg.text);
                    }
                }
            }
        }
Example #4
0
        public bool SendText(string chat_channel, string text)
        {
            if (!Connected)
            {
                return(false);
            }

            KeyValuePair <string, OnChannelMessage> p;

            lock (channel_lock_)
            {
                if (!channel_info_.TryGetValue(chat_channel, out p))
                {
                    DebugUtils.Log("You are not in the chat channel: {0}", chat_channel);
                    return(false);
                }
            }

            if (encoding_ == FunEncoding.kJson)
            {
                Dictionary <string, object> mcast_msg = new Dictionary <string, object>();
                mcast_msg["_channel"] = chat_channel;
                mcast_msg["_bounce"]  = true;

                mcast_msg["sender"] = p.Key;
                mcast_msg["text"]   = text;

                multicasting_.SendToChannel(mcast_msg);
            }
            else
            {
                FunChatMessage chat_msg = new FunChatMessage();
                chat_msg.sender = p.Key;
                chat_msg.text   = text;

                FunMulticastMessage mcast_msg = new FunMulticastMessage();
                mcast_msg.channel = chat_channel;
                mcast_msg.bounce  = true;
                Extensible.AppendValue(mcast_msg, (int)MulticastMessageType.chat, chat_msg);

                multicasting_.SendToChannel(mcast_msg);
            }

            return(true);
        }
        protected override void onMessageCallback(string channel_id, string user_id, object message)
        {
            if (encoding_ == FunEncoding.kJson)
            {
                string text = json_helper_.GetStringField(message, kMessage);

                base.onMessageCallback(channel_id, user_id, text);
            }
            else
            {
                FunMulticastMessage mcast = message as FunMulticastMessage;
                FunChatMessage      chat  = FunapiMessage.GetMulticastMessage <FunChatMessage>(mcast, MulticastMessageType.chat);
                if (chat == null)
                {
                    return;
                }

                base.onMessageCallback(channel_id, user_id, chat.text);
            }
        }
Example #6
0
        public bool SendText(string chat_channel, string text)
        {
            if (!Connected)
            {
                return false;
            }

            KeyValuePair<string, OnChannelMessage> p;
            lock (channel_lock_)
            {
                if (!channel_info_.TryGetValue(chat_channel, out p))
                {
                    DebugUtils.Log("You are not in the chat channel: {0}", chat_channel);
                    return false;
                }
            }

            if (encoding_ == FunEncoding.kJson)
            {
                Dictionary<string, object> mcast_msg = new Dictionary<string, object>();
                mcast_msg["_channel"] = chat_channel;
                mcast_msg["_bounce"] = true;

                mcast_msg["sender"] = p.Key;
                mcast_msg["text"] = text;

                multicasting_.SendToChannel(mcast_msg);
            }
            else
            {
                FunChatMessage chat_msg = new FunChatMessage ();
                chat_msg.sender = p.Key;
                chat_msg.text = text;

                FunMulticastMessage mcast_msg = new FunMulticastMessage ();
                mcast_msg.channel = chat_channel;
                mcast_msg.bounce = true;
                Extensible.AppendValue (mcast_msg, (int)MulticastMessageType.chat, chat_msg);

                multicasting_.SendToChannel(mcast_msg);
            }

            return true;
        }
        public bool SendText(string chat_channel, string text)
        {
            if (multicasting_ == null || !multicasting_.Connected)
            {
                return false;
            }

            KeyValuePair<string, OnChannelMessage> p;
            lock (lock_)
            {
                if (!channel_info_.TryGetValue(chat_channel, out p))
                {
                    Debug.Log("You are not in the chat channel: " + chat_channel);
                    return false;
                }
            }

            FunChatMessage chat_msg = new FunChatMessage ();
            chat_msg.sender = p.Key;
            chat_msg.text = text;

            FunMulticastMessage mcast_msg = new FunMulticastMessage ();
            mcast_msg.channel = chat_channel;
            mcast_msg.bounce = true;
            Extensible.AppendValue (mcast_msg, (int)MulticastMessageType.chat, chat_msg);

            multicasting_.SendToChannel (mcast_msg);
            return true;
        }
        public bool SendText (string channel_id, string text)
        {
            if (!Connected)
                return false;

            if (encoding_ == FunEncoding.kJson)
            {
                Dictionary<string, object> mcast_msg = new Dictionary<string, object>();
                mcast_msg[kChannelId] = channel_id;
                mcast_msg[kBounce] = true;
                mcast_msg[kMessage] = text;

                SendToChannel(mcast_msg);
            }
            else
            {
                FunChatMessage chat_msg = new FunChatMessage ();
                chat_msg.text = text;

                FunMulticastMessage mcast_msg = new FunMulticastMessage ();
                mcast_msg.channel = channel_id;
                mcast_msg.bounce = true;
                Extensible.AppendValue (mcast_msg, (int)MulticastMessageType.chat, chat_msg);

                SendToChannel(mcast_msg);
            }

            return true;
        }
Example #9
0
 public static void AppendExtension_chat(this FunMulticastMessage message, FunChatMessage value)
 {
     ProtoBuf.Extensible.AppendValue(message, (int)ExtendedMessageFieldNumber.FunMulticastMessage_chat, value);
 }
Example #10
0
 public static bool TryGetExtension_chat(this FunMulticastMessage message, out FunChatMessage value)
 {
     return(ProtoBuf.Extensible.TryGetValue(message, (int)ExtendedMessageFieldNumber.FunMulticastMessage_chat, out value));
 }