Ejemplo n.º 1
0
        private void WebSocketClient_OnMessage(string obj)
        {
            try
            {
                var estimatedData = Json.Parse(obj) as IDictionary <string, object>;
                var validator     = AVIMNotice.IsValidLeanCloudProtocol(estimatedData);
                if (validator)
                {
                    var notice = new AVIMNotice(estimatedData);
                    m_NoticeReceived?.Invoke(this, notice);
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    PrintLog(ex.InnerException.Source);
                }
                if (ex.Source != null)
                {
                    PrintLog(ex.Source);
                }

                PrintLog(ex.Message);
            }
        }
Ejemplo n.º 2
0
        public void OnNoticeReceived(AVIMNotice notice)
        {
            ICollection <IAVIMMessage> patchedMessages = new List <IAVIMMessage>();
            var msgObjs = notice.RawData["patches"] as IList <object>;

            if (msgObjs != null)
            {
                foreach (var msgObj in msgObjs)
                {
                    var msgData = msgObj as IDictionary <string, object>;
                    if (msgData != null)
                    {
                        var msgStr  = msgData["data"] as string;
                        var message = AVRealtime.FreeStyleMessageClassingController.Instantiate(msgStr, msgData);
                        patchedMessages.Add(message);
                    }
                }
            }
            if (OnReceived != null)
            {
                if (patchedMessages.Count > 0)
                {
                    this.OnReceived(patchedMessages);
                }
            }
        }
        public void OnNoticeReceived(AVIMNotice notice)
        {
            var code = 0;

            if (notice.RawData.ContainsKey("code"))
            {
                int.TryParse(notice.RawData["code"].ToString(), out code);
            }

            var reason = "";

            if (notice.RawData.ContainsKey("reason"))
            {
                reason = notice.RawData["reason"].ToString();
            }

            var detail = "";

            if (notice.RawData.ContainsKey("detail"))
            {
                detail = notice.RawData["detail"].ToString();
            }

            if (_onSessionClosed != null)
            {
                _onSessionClosed(code, reason, detail);
            }
        }
 public void OnNoticeReceived(AVIMNotice notice)
 {
     lock (mutex)
     {
         if (notice.RawData.ContainsKey("convs"))
         {
             var unreadRawData = notice.RawData["convs"] as List <object>;
             if (notice.RawData.ContainsKey("notifTime"))
             {
                 float.TryParse(notice.RawData["notifTime"].ToString(), out NotifTime);
             }
             foreach (var data in unreadRawData)
             {
                 var dataMap = data as IDictionary <string, object>;
                 if (dataMap != null)
                 {
                     var convId      = dataMap["cid"].ToString();
                     var unreadCount = 0;
                     Int32.TryParse(dataMap["unread"].ToString(), out unreadCount);
                     #region restore last message for the conversation
                     var msgStr     = dataMap["data"].ToString();
                     var messageObj = AVRealtime.FreeStyleMessageClassingController.Instantiate(msgStr, dataMap);
                     #endregion
                     var ucn = new UnreadConversationNotice()
                     {
                         ConvId            = convId,
                         LastUnreadMessage = messageObj,
                         UnreadCount       = unreadCount
                     };
                     UnreadConversations.Add(ucn);
                 }
             }
         }
     }
 }
Ejemplo n.º 5
0
 public virtual bool ProtocolHook(AVIMNotice notice)
 {
     if (notice.CommandName != "direct")
     {
         return(false);
     }
     try
     {
         var msg = Json.Parse(notice.RawData["msg"].ToString()) as IDictionary <string, object>;
         if (!msg.Keys.Contains(AVIMProtocol.LCTYPE))
         {
             return(false);
         }
         var typInt = 0;
         int.TryParse(msg[AVIMProtocol.LCTYPE].ToString(), out typInt);
         if (typInt != -1)
         {
             return(false);
         }
         return(true);
     }
     catch (ArgumentException)
     {
     }
     return(false);
 }
Ejemplo n.º 6
0
        //public void On(string eventName, Action<IDictionary<string, object>> data)
        //{

        //}

        private void WebSocketClient_OnMessage(string obj)
        {
            AVRealtime.PrintLog("websocket<=" + obj);
            var estimatedData = Json.Parse(obj) as IDictionary <string, object>;
            var notice        = new AVIMNotice(estimatedData);

            m_NoticeReceived?.Invoke(this, notice);
        }
Ejemplo n.º 7
0
 internal bool ConversationIdHook(AVIMNotice notice)
 {
     if (!notice.RawData.ContainsKey("cid"))
     {
         return(false);
     }
     return(notice.RawData["cid"].ToString() == this.ConversationId);
 }
Ejemplo n.º 8
0
 public virtual void OnNoticeReceived(AVIMNotice notice)
 {
     if (m_OnTextMessageReceived != null)
     {
         var textMessage = new AVIMTextMessage();
         textMessage.Deserialize(notice.RawData["msg"].ToString());
         m_OnTextMessageReceived(this, new AVIMTextMessageEventArgs(textMessage));
     }
 }
 public void OnNoticeReceived(AVIMNotice notice)
 {
     if (m_OnOfflineMessageReceived != null)
     {
         var msgStr   = notice.RawData["msg"].ToString();
         var iMessage = AVRealtime.FreeStyleMessageClassingController.Instantiate(msgStr, notice.RawData);
         var args     = new AVIMMessageEventArgs(iMessage);
         m_OnOfflineMessageReceived.Invoke(this, args);
     }
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Protocols the hook.
 /// </summary>
 /// <returns><c>true</c>, if hook was protocoled, <c>false</c> otherwise.</returns>
 /// <param name="notice">Notice.</param>
 public virtual bool ProtocolHook(AVIMNotice notice)
 {
     if (notice.CommandName != "direct")
     {
         return(false);
     }
     if (notice.RawData.ContainsKey("offline"))
     {
         return(false);
     }
     return(true);
 }
 public bool ProtocolHook(AVIMNotice notice)
 {
     if (notice.CommandName != "conv")
     {
         return(false);
     }
     if (!this.IsCommandNameListening(notice.CommandName))
     {
         return(false);
     }
     return(true);
 }
Ejemplo n.º 12
0
 internal virtual void OnMessage(AVIMNotice notice)
 {
     if (m_OnMessageReceived != null)
     {
         var msgStr   = notice.RawData["msg"].ToString();
         var iMessage = AVRealtime.FreeStyleMessageClassingController.Instantiate(msgStr, notice.RawData);
         //var messageNotice = new AVIMMessageNotice(notice.RawData);
         //var messaegObj = AVIMMessage.Create(messageNotice);
         var args = new AVIMMessageEventArgs(iMessage);
         m_OnMessageReceived.Invoke(this, args);
     }
 }
 public void OnNoticeReceived(AVIMNotice notice)
 {
     if (m_OnKicked != null)
     {
         var kickcdBy      = notice.RawData["initBy"].ToString();
         var conersationId = notice.RawData["cid"].ToString();
         var args          = new AVIMOnKickedEventArgs()
         {
             ConversationId = conersationId,
             KickedBy       = kickcdBy,
         };
         m_OnKicked.Invoke(this, args);
     }
 }
Ejemplo n.º 14
0
 public bool ProtocolHook(AVIMNotice notice)
 {
     if (notice.CommandName != "patch")
     {
         return(false);
     }
     if (!notice.RawData.ContainsKey("op"))
     {
         return(false);
     }
     if (notice.RawData["op"].ToString() != "modify")
     {
         return(false);
     }
     return(true);
 }
 public virtual void OnNoticeReceived(AVIMNotice notice)
 {
     if (m_OnMembersLeft != null)
     {
         var leftMembers   = AVDecoder.Instance.DecodeList <string>(notice.RawData["m"]);
         var kickedBy      = notice.RawData["initBy"].ToString();
         var conersationId = notice.RawData["cid"].ToString();
         var args          = new AVIMOnMembersLeftEventArgs()
         {
             ConversationId = conersationId,
             KickedBy       = kickedBy,
             LeftMembers    = leftMembers
         };
         m_OnMembersLeft.Invoke(this, args);
     }
 }
 public virtual void OnNoticeReceived(AVIMNotice notice)
 {
     if (m_OnMembersJoined != null)
     {
         var joinedMembers = AVDecoder.Instance.DecodeList <string>(notice.RawData["m"]);
         var ivitedBy      = notice.RawData["initBy"].ToString();
         var conersationId = notice.RawData["cid"].ToString();
         var args          = new AVIMOnMembersJoinedEventArgs()
         {
             ConversationId = conersationId,
             InvitedBy      = ivitedBy,
             JoinedMembers  = joinedMembers
         };
         m_OnMembersJoined.Invoke(this, args);
     }
 }
        public bool ProtocolHook(AVIMNotice notice)
        {
            if (notice.CommandName != "session")
            {
                return(false);
            }
            if (!notice.RawData.ContainsKey("op"))
            {
                return(false);
            }
            if (notice.RawData["op"].ToString() != "closed")
            {
                return(false);
            }

            return(true);
        }
        public bool ProtocolHook(AVIMNotice notice)
        {
            if (notice.CommandName != "conv")
            {
                return(false);
            }
            if (!notice.RawData.ContainsKey("op"))
            {
                return(false);
            }
            var op = notice.RawData["op"].ToString();

            if (!op.Equals("left"))
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 19
0
        public void OnNoticeReceived(AVIMNotice notice)
        {
            ICollection <IAVIMMessage> recalled = new List <IAVIMMessage>();
            ICollection <IAVIMMessage> modified = new List <IAVIMMessage>();
            var msgObjs = notice.RawData["patches"] as IList <object>;

            if (msgObjs != null)
            {
                foreach (var msgObj in msgObjs)
                {
                    var msgData = msgObj as IDictionary <string, object>;
                    if (msgData != null)
                    {
                        var msgStr  = msgData["data"] as string;
                        var message = AVRealtime.FreeStyleMessageClassingController.Instantiate(msgStr, msgData);
                        if (msgData.ContainsKey("recall"))
                        {
                            var recall = false;
                            bool.TryParse(msgData["recall"].ToString(), out recall);
                            if (recall)
                            {
                                recalled.Add(message);
                            }
                            else
                            {
                                modified.Add(message);
                            }
                        }
                    }
                }
            }
            if (OnReceived != null)
            {
                if (recalled.Count > 0)
                {
                    this.OnReceived(true, recalled);
                }
                if (modified.Count > 0)
                {
                    this.OnReceived(false, recalled);
                }
            }
        }
Ejemplo n.º 20
0
 public void OnNoticeReceived(AVIMNotice notice)
 {
     // TODO 退出并清理路由缓存
     onGoAway?.Invoke();
 }
 public bool ProtocolHook(AVIMNotice notice)
 {
     return(notice.CommandName == "unread");
 }
        public void OnNoticeReceived(AVIMNotice notice)
        {
            var cid          = notice.RawData["cid"].ToString();
            var conversation = new AVIMConversation(cid);

            var args = new AVIMOnMembersChangedEventArgs()
            {
            };

            var generators = new Func <AVIMNotice, AVIMOnMembersChangedEventArgs>[]
            {
                (e) =>
                {
                    return(new AVIMOnMembersChangedEventArgs()
                    {
                        Conversation = conversation,
                        AffectedType = AVIMConversationEventType.Joined,
                        Oprator = e.RawData["initBy"].ToString(),
                        OpratedTime = DateTime.Now
                    });
                },
                (e) =>
                {
                    return(new AVIMOnMembersChangedEventArgs()
                    {
                        Conversation = conversation,
                        AffectedType = AVIMConversationEventType.Left,
                        Oprator = e.RawData["initBy"].ToString(),
                        OpratedTime = DateTime.Now
                    });
                },
                (e) =>
                {
                    return(new AVIMOnMembersChangedEventArgs()
                    {
                        Conversation = conversation,
                        AffectedType = AVIMConversationEventType.MembersJoined,
                        Oprator = e.RawData["initBy"].ToString(),
                        AffectedMembers = new List <string>(e.RawData["m"] as string[])
                    });
                },
                (e) =>
                {
                    return(new AVIMOnMembersChangedEventArgs()
                    {
                        Conversation = conversation,
                        AffectedType = AVIMConversationEventType.MembersLeft,
                        Oprator = e.RawData["initBy"].ToString(),
                        AffectedMembers = new List <string>(e.RawData["m"] as string[]),
                        OpratedTime = DateTime.Now
                    });
                },
                (e) =>
                {
                    var rtn = new AVIMOnMembersChangedEventArgs()
                    {
                        Conversation    = conversation,
                        AffectedType    = AVIMConversationEventType.Invited,
                        AffectedMembers = new List <string>(e.RawData["m"] as string[]),
                        OpratedTime     = DateTime.Now
                    };
                    return(rtn);
                },
                (e) =>
                {
                    var rtn = new AVIMOnMembersChangedEventArgs()
                    {
                        Conversation    = conversation,
                        AffectedType    = AVIMConversationEventType.Kicked,
                        AffectedMembers = new List <string>(e.RawData["m"] as string[]),
                        OpratedTime     = DateTime.Now
                    };

                    return(rtn);
                }
            };

            var op      = notice.RawData["op"].ToString();
            int ssIndex = Array.IndexOf(listeningCommandNames, op);
            var action  = generators[ssIndex];

            args = action(notice);
            if (m_OnConversationMembersChanged != null)
            {
                m_OnConversationMembersChanged(this, args);
            }
        }
Ejemplo n.º 23
0
 /// <summary>
 /// Ons the notice received.
 /// </summary>
 /// <param name="notice">Notice.</param>
 public virtual void OnNoticeReceived(AVIMNotice notice)
 {
     this.OnMessage(notice);
 }
Ejemplo n.º 24
0
 public bool ProtocolHook(AVIMNotice notice)
 {
     return(notice.CommandName == "goaway");
 }