Пример #1
0
        protected override Base_Upload MakeUL(IMMsgForSend msg)
        {
            UL_Chat_sendPrivateMsg ul = new UL_Chat_sendPrivateMsg();

            ul.lastId = lastId;
            ul.msg    = msg;
            return(ul);
        }
Пример #2
0
        protected override Base_Upload MakeUL(IMMsgForSend msg)
        {
            UL_Chat_sendChannelMsg ul = new UL_Chat_sendChannelMsg();

            ul.lastId = im.GetSession(im.GetChannel(msg.recId)).lastId;
            ul.msg    = msg;
            return(ul);
        }
Пример #3
0
 public void Update()
 {
     if (!http.IsBusy())
     {
         while (sendingMsgs.Count > 0)
         {
             IMMsgForSend msg = sendingMsgs.Dequeue();
             if (!IsMsgValid(msg))
             {
                 msg.Distributed = false;
                 continue;
             }
             Base_Upload ul = MakeUL(msg);
             //Debug.Log(DateTime.Now + ": " + ul.GetType().Name);
             http.Send(ul, ctx => {
                 heartbeatTimeSpan = minHeartbeatTimeSpan;
                 heatbeatTime      = Time.realtimeSinceStartup + heartbeatTimeSpan;
                 OnSendDone(msg, ctx);
             });
             break;
         }
     }
     if (!http.IsBusy() && Time.realtimeSinceStartup > heatbeatTime)
     {
         Base_Upload ul = MakeHeatbeatUL();
         //Debug.Log(DateTime.Now + ": " + ul.GetType().Name);
         http.Send(ul, ctx => {
             if (OnHeatbeatDone(ctx))
             {
                 heartbeatTimeSpan = minHeartbeatTimeSpan;
             }
             else
             {
                 heartbeatTimeSpan = Mathf.Min(heartbeatTimeSpan + 1, maxHeartbeatTimeSpan);
             }
             heatbeatTime = Time.realtimeSinceStartup + heartbeatTimeSpan;
         });
     }
 }
Пример #4
0
 protected override void OnSendDone(IMMsgForSend msg, IMHttpContext ctx)
 {
     if (ctx.code != 0)
     {
         Debug.Log("发送聊天致命错误");
         msg.Distributed = false;
         im.SetOffline();
         return;
     }
     msg.Sent = true;
     try {
         if (!ctx.response.Contains("private"))
         {
             im.SetOffline();
             return;
         }
         SyncPrivateMsgs(ctx.response["private"].AsBonDocument);
     } catch (Exception e) {
         Debug.Log(e);
         im.SetOffline();
     }
 }
Пример #5
0
        protected override void OnSendDone(IMMsgForSend msg, IMHttpContext ctx)
        {
            IMChannel ch = im.GetChannel(msg.recId);

            if (ch == null)
            {
                return;
            }
            ClearInvalidChannels();
            if (ctx.code < 0)
            {
                Debug.Log("发送聊天致命错误");
                msg.Distributed = false;
                ClearAll();
                return;
            }
            if (ctx.code > 0)
            {
                Debug.Log("发送聊天错误");
                msg.Distributed = false;
                ch.SetOffline();
                return;
            }
            msg.Sent = true;
            try {
                BonDocument chd = ctx.response.GetBonDocument("channel");
                if (chd == null)
                {
                    msg.Distributed = false;
                    ch.SetOffline();
                    return;
                }
                SyncChannelMsgs(chd, ch);
            } catch (Exception e) {
                Debug.Log(e);
                msg.Distributed = false;
                ch.SetOffline();
            }
        }
Пример #6
0
 protected override bool IsMsgValid(IMMsgForSend msg)
 {
     ClearInvalidChannels();
     return(channels.Contains(msg.recId));
 }
Пример #7
0
 protected abstract bool IsMsgValid(IMMsgForSend msg);
Пример #8
0
 protected abstract void OnSendDone(IMMsgForSend msg, IMHttpContext ctx);
Пример #9
0
 protected abstract Base_Upload MakeUL(IMMsgForSend msg);
Пример #10
0
 protected override bool IsMsgValid(IMMsgForSend msg)
 {
     return(true);
 }
Пример #11
0
 public void AddMsg(IMMsgForSend msg)
 {
     msg.Distributed = true;
     sendingMsgs.Enqueue(msg);
 }