This commit is contained in:
2022-03-17 15:55:27 +08:00
commit bd5a9fad97
92 changed files with 13861 additions and 0 deletions

44
comet/operation.go Normal file
View File

@@ -0,0 +1,44 @@
package comet
import (
"context"
"strconv"
"gitlab.33.cn/chat/im/api/comet/grpc"
"gitlab.33.cn/chat/im/dtask"
)
// Operate operate.
func (s *Comet) Operate(ctx context.Context, p *grpc.Proto, ch *Channel, tsk *dtask.Task) error {
switch p.Op {
case int32(grpc.Op_SendMsg):
//标明Ack的消息序列
p.Ack = p.Seq
err := s.Receive(ctx, ch.Key, p)
if err != nil {
//下层业务调用失败返回error的话会直接断开连接
return err
}
//p.Op = int32(grpc.Op_SendMsgReply)
case int32(grpc.Op_ReceiveMsgReply):
//从task中删除某一条
if j := tsk.Get(strconv.FormatInt(int64(p.Ack), 10)); j != nil {
j.Cancel()
}
err := s.Receive(ctx, ch.Key, p)
if err != nil {
//下层业务调用失败返回error的话会直接断开连接
return err
}
case int32(grpc.Op_SyncMsgReq):
err := s.Receive(ctx, ch.Key, p)
if err != nil {
//下层业务调用失败返回error的话会直接断开连接
return err
}
p.Op = int32(grpc.Op_SyncMsgReply)
default:
return s.Receive(ctx, ch.Key, p)
}
return nil
}