broadcast.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package broadcast
  2. import (
  3. "context"
  4. "go-common/app/interface/main/app-resource/conf"
  5. broaddao "go-common/app/interface/main/app-resource/dao/broadcast"
  6. "go-common/app/interface/main/app-resource/model"
  7. "go-common/app/interface/main/app-resource/model/broadcast"
  8. warden "go-common/app/service/main/broadcast/api/grpc/v1"
  9. "go-common/library/log"
  10. )
  11. type Service struct {
  12. c *conf.Config
  13. dao *broaddao.Dao
  14. }
  15. func New(c *conf.Config) (s *Service) {
  16. s = &Service{
  17. c: c,
  18. dao: broaddao.New(c),
  19. }
  20. return
  21. }
  22. // ServerList warden server list
  23. func (s *Service) ServerList(c context.Context, plat int8) (res *broadcast.ServerListReply, err error) {
  24. var (
  25. data *warden.ServerListReply
  26. platform string
  27. )
  28. if model.IsIOS(plat) {
  29. platform = "ios"
  30. } else if model.IsAndroid(plat) {
  31. platform = "android"
  32. }
  33. if data, err = s.dao.ServerList(c, platform); err != nil {
  34. log.Error("ServerList s.dao.ServerList error(%v)", err)
  35. err = nil
  36. res = &broadcast.ServerListReply{
  37. Domain: "broadcast.chat.bilibili.com",
  38. TCPPort: 7821,
  39. WsPort: 7822,
  40. WssPort: 7823,
  41. Heartbeat: 30,
  42. HeartbeatMax: 3,
  43. Nodes: []string{"broadcast.chat.bilibili.com"},
  44. Backoff: &broadcast.Backoff{
  45. MaxDelay: 120,
  46. BaseDelay: 3,
  47. Factor: 1.6,
  48. Jitter: 0.2,
  49. },
  50. }
  51. return
  52. }
  53. res = &broadcast.ServerListReply{}
  54. res.ServerListChange(data)
  55. return
  56. }