golang-im聊天
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

80 rivejä
2.4 KiB

  1. package api
  2. import (
  3. "context"
  4. "gim/internal/logic/app"
  5. "gim/pkg/logger"
  6. "gim/pkg/pb"
  7. )
  8. type LogicIntServer struct{}
  9. // ConnSignIn 设备登录
  10. func (*LogicIntServer) ConnSignIn(ctx context.Context, req *pb.ConnSignInReq) (*pb.Empty, error) {
  11. return &pb.Empty{},
  12. app.DeviceApp.SignIn(ctx, req.UserId, req.DeviceId, req.Token, req.ConnAddr, req.ClientAddr)
  13. }
  14. // Sync 设备同步消息
  15. func (*LogicIntServer) Sync(ctx context.Context, req *pb.SyncReq) (*pb.SyncResp, error) {
  16. return app.MessageApp.Sync(ctx, req.UserId, req.Seq)
  17. }
  18. // MessageACK 设备收到消息ack
  19. func (*LogicIntServer) MessageACK(ctx context.Context, req *pb.MessageACKReq) (*pb.Empty, error) {
  20. return &pb.Empty{}, app.MessageApp.MessageAck(ctx, req.UserId, req.DeviceId, req.DeviceAck)
  21. }
  22. // Offline 设备离线
  23. func (*LogicIntServer) Offline(ctx context.Context, req *pb.OfflineReq) (*pb.Empty, error) {
  24. return &pb.Empty{}, app.DeviceApp.Offline(ctx, req.DeviceId, req.ClientAddr)
  25. }
  26. func (s *LogicIntServer) SubscribeRoom(ctx context.Context, req *pb.SubscribeRoomReq) (*pb.Empty, error) {
  27. return &pb.Empty{}, app.RoomApp.SubscribeRoom(ctx, req)
  28. }
  29. // SendMessage 发送消息
  30. func (*LogicIntServer) SendMessage(ctx context.Context, req *pb.SendMessageReq) (*pb.SendMessageResp, error) {
  31. sender := pb.Sender{
  32. SenderType: pb.SenderType_ST_BUSINESS,
  33. SenderId: 0,
  34. DeviceId: 0,
  35. }
  36. seq, err := app.MessageApp.SendMessage(ctx, &sender, req)
  37. if err != nil {
  38. return nil, err
  39. }
  40. return &pb.SendMessageResp{Seq: seq}, nil
  41. }
  42. // PushRoom 推送房间
  43. func (s *LogicIntServer) PushRoom(ctx context.Context, req *pb.PushRoomReq) (*pb.Empty, error) {
  44. return &pb.Empty{}, app.RoomApp.Push(ctx, &pb.Sender{
  45. SenderType: pb.SenderType_ST_BUSINESS,
  46. }, req)
  47. }
  48. // PushAll 全服推送
  49. func (s *LogicIntServer) PushAll(ctx context.Context, req *pb.PushAllReq) (*pb.Empty, error) {
  50. return &pb.Empty{}, app.MessageApp.PushAll(ctx, req)
  51. }
  52. // GetDevice 获取设备信息
  53. func (*LogicIntServer) GetDevice(ctx context.Context, req *pb.GetDeviceReq) (*pb.GetDeviceResp, error) {
  54. device, err := app.DeviceApp.GetDevice(ctx, req.DeviceId)
  55. return &pb.GetDeviceResp{Device: device}, err
  56. }
  57. // ServerStop 服务停止
  58. func (s *LogicIntServer) ServerStop(ctx context.Context, in *pb.ServerStopReq) (*pb.Empty, error) {
  59. go func() {
  60. err := app.DeviceApp.ServerStop(ctx, in.ConnAddr)
  61. if err != nil {
  62. logger.Sugar.Error(err)
  63. }
  64. }()
  65. return &pb.Empty{}, nil
  66. }