ws update

This commit is contained in:
Gordon 2023-03-23 14:18:33 +08:00
parent be3c866dc0
commit 889e6b0d84
3 changed files with 6 additions and 14 deletions

View File

@ -16,7 +16,7 @@ import (
) )
func (s *Server) InitServer(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) error { func (s *Server) InitServer(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) error {
s.notification = notification.NewCheck(client) s.LongConnServer.SetMessageHandler(notification.NewCheck(client))
msggateway.RegisterMsgGatewayServer(server, s) msggateway.RegisterMsgGatewayServer(server, s)
return nil return nil
} }
@ -42,8 +42,8 @@ func (s *Server) Notification() *notification.Check {
return s.notification return s.notification
} }
func NewServer(rpcPort int) *Server { func NewServer(rpcPort int, longConnServer LongConnServer) *Server {
return &Server{rpcPort: rpcPort, pushTerminal: []int{constant.IOSPlatformID, constant.AndroidPlatformID}} return &Server{rpcPort: rpcPort, LongConnServer: longConnServer, pushTerminal: []int{constant.IOSPlatformID, constant.AndroidPlatformID}}
} }
func (s *Server) OnlinePushMsg(context context.Context, req *msggateway.OnlinePushMsgReq) (*msggateway.OnlinePushMsgResp, error) { func (s *Server) OnlinePushMsg(context context.Context, req *msggateway.OnlinePushMsgReq) (*msggateway.OnlinePushMsgResp, error) {

View File

@ -5,13 +5,10 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
"sync"
"time" "time"
) )
func RunWsAndServer(rpcPort, wsPort, prometheusPort int) error { func RunWsAndServer(rpcPort, wsPort, prometheusPort int) error {
var wg sync.WaitGroup
wg.Add(1)
log.NewPrivateLog(constant.LogFileName) log.NewPrivateLog(constant.LogFileName)
fmt.Println("start rpc/msg_gateway server, port: ", rpcPort, wsPort, prometheusPort, ", OpenIM version: ", config.Version) fmt.Println("start rpc/msg_gateway server, port: ", rpcPort, wsPort, prometheusPort, ", OpenIM version: ", config.Version)
longServer, err := NewWsServer( longServer, err := NewWsServer(
@ -22,14 +19,8 @@ func RunWsAndServer(rpcPort, wsPort, prometheusPort int) error {
if err != nil { if err != nil {
return err return err
} }
hubServer := NewServer(rpcPort) hubServer := NewServer(rpcPort, longServer)
go hubServer.Start() go hubServer.Start()
if hubServer.Notification() == nil { hubServer.LongConnServer.Run()
panic("notification is nil")
}
longServer.SetMessageHandler(hubServer.Notification())
hubServer.SetLongConnServer(longServer)
go hubServer.LongConnServer.Run()
wg.Wait()
return nil return nil
} }

View File

@ -21,6 +21,7 @@ type LongConnServer interface {
GetUserAllCons(userID string) ([]*Client, bool) GetUserAllCons(userID string) ([]*Client, bool)
GetUserPlatformCons(userID string, platform int) ([]*Client, bool, bool) GetUserPlatformCons(userID string, platform int) ([]*Client, bool, bool)
Validate(s interface{}) error Validate(s interface{}) error
SetMessageHandler(rpcClient *notification.Check)
UnRegister(c *Client) UnRegister(c *Client)
Compressor Compressor
Encoder Encoder