void onMulticastError(string channel_id, FunMulticastMessage.ErrorCode code) { if (code == FunMulticastMessage.ErrorCode.EC_CLOSED) { // If the server is closed, try to rejoin the channel. if (multicast_ != null && multicast_.Connected) { multicast_.JoinChannel(kChannelName, onMulticastChannelReceived); } } }
void onError(string channel_id, FunMulticastMessage.ErrorCode code) { if (code != FunMulticastMessage.ErrorCode.EC_ALREADY_JOINED) { lock (chat_channel_lock_) { if (chat_channels_.ContainsKey(channel_id)) { chat_channels_.Remove(channel_id); } } } }
void onError(string channel_id, FunMulticastMessage.ErrorCode code) { if (code == FunMulticastMessage.ErrorCode.EC_FULL_MEMBER || code == FunMulticastMessage.ErrorCode.EC_ALREADY_LEFT || code == FunMulticastMessage.ErrorCode.EC_CLOSED) { lock (chat_channel_lock_) { if (chat_channels_.ContainsKey(channel_id)) { chat_channels_.Remove(channel_id); } } } }
void onError(string channel_id, FunMulticastMessage.ErrorCode code) { FunDebug.LogWarning("[Multicast] error occurred. channel:{0} error:{1}", channel_id, code); if (code == FunMulticastMessage.ErrorCode.EC_CLOSED) { // This error occurs when the server is closed. // If the session is connected, tries to rejoin the channel. if (Connected && InChannel(channel_id)) { string token = null; lock (token_lock_) { if (tokens_.ContainsKey(channel_id)) { token = tokens_[channel_id]; } } requestToJoin(channel_id, token); return; } } if (code != FunMulticastMessage.ErrorCode.EC_ALREADY_JOINED) { lock (channel_lock_) { if (channels_.ContainsKey(channel_id)) { channels_.Remove(channel_id); } } } if (ErrorCallback != null) { ErrorCallback(channel_id, code); } }
void onReceived(string msg_type, object body) { string channel_id = ""; string sender = ""; bool join = false; bool leave = false; int error_code = 0; if (encoding_ == FunEncoding.kJson) { if (json_helper_.HasField(body, kChannelId)) { channel_id = json_helper_.GetStringField(body, kChannelId); } if (json_helper_.HasField(body, kSender)) { sender = json_helper_.GetStringField(body, kSender); } if (json_helper_.HasField(body, kErrorCode)) { error_code = (int)json_helper_.GetIntegerField(body, kErrorCode); } if (json_helper_.HasField(body, kChannelList)) { if (ChannelListCallback != null) { object list = json_helper_.GetObject(body, kChannelList); ChannelListCallback(list); } return; } else if (json_helper_.HasField(body, kJoin)) { join = json_helper_.GetBooleanField(body, kJoin); } else if (json_helper_.HasField(body, kLeave)) { leave = json_helper_.GetBooleanField(body, kLeave); } } else { FunMessage msg = body as FunMessage; FunMulticastMessage mcast_msg = FunapiMessage.GetMessage <FunMulticastMessage>(msg, MessageType.multicast); if (mcast_msg == null) { return; } if (mcast_msg.channelSpecified) { channel_id = mcast_msg.channel; } if (mcast_msg.senderSpecified) { sender = mcast_msg.sender; } if (mcast_msg.error_codeSpecified) { error_code = (int)mcast_msg.error_code; } if (mcast_msg.channels.Count > 0 || (channel_id == "" && sender == "")) { if (ChannelListCallback != null) { ChannelListCallback(mcast_msg.channels); } return; } else if (mcast_msg.joinSpecified) { join = mcast_msg.join; } else if (mcast_msg.leaveSpecified) { leave = mcast_msg.leave; } body = mcast_msg; } if (error_code != 0) { FunMulticastMessage.ErrorCode code = (FunMulticastMessage.ErrorCode)error_code; FunDebug.LogWarning("Multicast.onReceived - channel: {0} error: {1}", channel_id, code); if (code != FunMulticastMessage.ErrorCode.EC_ALREADY_JOINED) { lock (channel_lock_) { if (channels_.ContainsKey(channel_id)) { channels_.Remove(channel_id); } } } if (ErrorCallback != null) { ErrorCallback(channel_id, code); } return; } lock (channel_lock_) { if (!channels_.ContainsKey(channel_id)) { FunDebug.LogWarning("Multicast.onReceived - You are not in the '{0} channel.", channel_id); return; } } if (join) { onUserJoined(channel_id, sender); } else if (leave) { onUserLeft(channel_id, sender); } else { lock (channel_lock_) { if (channels_.ContainsKey(channel_id)) { channels_[channel_id](channel_id, sender, body); } } } }