private void OnReceived(string msg_type, object body) { DebugUtils.Assert(msg_type == kMulticastMsgType); string channel_id = ""; if (encoding_ == FunEncoding.kJson) { DebugUtils.Assert(body is Dictionary <string, object>); Dictionary <string, object> msg = body as Dictionary <string, object>; channel_id = msg[kChannelId] as string; lock (channel_lock_) { if (!channels_.ContainsKey(channel_id)) { DebugUtils.Log("You are not in the channel: {0}", channel_id); return; } ChannelReceiveHandler h = channels_[channel_id]; h(channel_id, body); } } else { DebugUtils.Assert(body is FunMessage); FunMessage msg = body as FunMessage; object obj = network_.GetMessage(msg, MessageType.multicast); DebugUtils.Assert(obj != null); FunMulticastMessage mcast_msg = obj as FunMulticastMessage; channel_id = mcast_msg.channel; lock (channel_lock_) { if (!channels_.ContainsKey(channel_id)) { DebugUtils.Log("You are not in the channel: {0}", channel_id); return; } ChannelReceiveHandler h = channels_[channel_id]; h(channel_id, mcast_msg); } } }
public bool JoinChannel(string channel_id, ChannelReceiveHandler handler) { if (!Connected) { DebugUtils.Log("Not connected. First connect before join a multicast channel."); return false; } lock (channel_lock_) { if (channels_.ContainsKey(channel_id)) { DebugUtils.Log("Already joined the channel: {0}", channel_id); return false; } channels_.Add (channel_id, handler); } if (encoding_ == FunEncoding.kJson) { Dictionary<string, object> mcast_msg = new Dictionary<string, object>(); mcast_msg[kChannelId] = channel_id; mcast_msg[kJoin] = true; network_.SendMessage(kMulticastMsgType, mcast_msg); } else { FunMulticastMessage mcast_msg = new FunMulticastMessage (); mcast_msg.channel = channel_id; mcast_msg.join = true; FunMessage fun_msg = network_.CreateFunMessage(mcast_msg, MessageType.multicast); network_.SendMessage (kMulticastMsgType, fun_msg); } return true; }
public bool JoinChannel(string channel_id, ChannelReceiveHandler handler) { if (!Connected) { DebugUtils.Log("Not connected. First connect before join a multicast channel."); return(false); } lock (channel_lock_) { if (channels_.ContainsKey(channel_id)) { DebugUtils.Log("Already joined the channel: {0}", channel_id); return(false); } channels_.Add(channel_id, handler); } if (encoding_ == FunEncoding.kJson) { Dictionary <string, object> mcast_msg = new Dictionary <string, object>(); mcast_msg[kChannelId] = channel_id; mcast_msg[kJoin] = true; network_.SendMessage(kMulticastMsgType, mcast_msg); } else { FunMulticastMessage mcast_msg = new FunMulticastMessage(); mcast_msg.channel = channel_id; mcast_msg.join = true; FunMessage fun_msg = network_.CreateFunMessage(mcast_msg, MessageType.multicast); network_.SendMessage(kMulticastMsgType, fun_msg); } return(true); }
public bool JoinChannel(string channel_id, ChannelReceiveHandler handler) { lock (lock_) { if (network_ == null || !network_.Started) { Debug.Log ("Not connected. First connect before join a multicast channel."); return false; } if (channels_.ContainsKey(channel_id)) { Debug.Log ("Already joined the channel: " + channel_id); return false; } channels_.Add (channel_id, handler); } FunMulticastMessage mcast_msg = new FunMulticastMessage (); mcast_msg.channel = channel_id; mcast_msg.join = true; FunMessage fun_msg = network_.CreateFunMessage(mcast_msg, MessageType.multicast); network_.SendMessage (kMulticastMsgType, fun_msg); return true; }