golang-im聊天
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

1234567891011121314151617181920212223242526272829303132
  1. package connect
  2. import (
  3. "context"
  4. "gim/pkg/grpclib"
  5. "gim/pkg/logger"
  6. "gim/pkg/pb"
  7. "go.uber.org/zap"
  8. )
  9. type ConnIntServer struct{}
  10. // DeliverMessage 投递消息
  11. func (s *ConnIntServer) DeliverMessage(ctx context.Context, req *pb.DeliverMessageReq) (*pb.Empty, error) {
  12. resp := &pb.Empty{}
  13. // 获取设备对应的TCP连接
  14. conn := GetConn(req.DeviceId)
  15. if conn == nil {
  16. logger.Logger.Warn("GetConn warn", zap.Int64("device_id", req.DeviceId))
  17. return resp, nil
  18. }
  19. if conn.DeviceId != req.DeviceId {
  20. logger.Logger.Warn("GetConn warn", zap.Int64("device_id", req.DeviceId))
  21. return resp, nil
  22. }
  23. conn.Send(pb.PackageType_PT_MESSAGE, grpclib.GetCtxRequestId(ctx), req.MessageSend, nil)
  24. return resp, nil
  25. }