diff --git a/cmd/main.go b/cmd/main.go index 18bab9b..5c87763 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -16,6 +16,13 @@ import ( log "github.com/xuexihuang/new_log15" ) +const ( + MaxMsgLen = 1024 * 1024 * 10 + MaxConnNum = 100 * 100 * 10 + HTTPTimeout = 10 * time.Second + WriterChanLen = 1000 +) + var Processor = tjson.NewProcessor() type GateNet struct { @@ -27,17 +34,8 @@ type GateNet struct { // Initsever initializes a new GateNet instance with the given WebSocket port and default configurations. func Initsever(wsPort int) *GateNet { gatenet := new(GateNet) - gatenet.Gate = &gate.Gate{ - MaxConnNum: 100, - PendingWriteNum: 200, - MaxMsgLen: 20000, - WSAddr: ":" + fmt.Sprintf("%d", wsPort), - HTTPTimeout: 10 * time.Second, - CertFile: "", - KeyFile: "", - LenMsgLen: 2, - Processor: Processor, - } + gatenet.Gate = gate.NewGate(MaxConnNum, MaxMsgLen, + Processor, ":"+fmt.Sprintf("%d", wsPort), HTTPTimeout, WriterChanLen) gatenet.CloseSig = make(chan bool, 1) return gatenet } diff --git a/core_func/ws_conversation_msg.go b/core_func/ws_conversation_msg.go index 96c8ddb..3c66eab 100644 --- a/core_func/ws_conversation_msg.go +++ b/core_func/ws_conversation_msg.go @@ -305,3 +305,13 @@ func (f *FuncRouter) SearchLocalMessages(operationID string, args ...any) { func (f *FuncRouter) SetMessageLocalEx(operationID string, args ...any) { f.call(operationID, f.userForSDK.Conversation().SetMessageLocalEx, args...) } + +// SearchConversation retrieves a conversation based on search criteria. +func (f *FuncRouter) SearchConversation(operationID string, args ...any) { + f.call(operationID, f.userForSDK.Conversation().SearchConversation, args...) +} + +// SetOneConversationEx sets server extension data for a conversation. +func (f *FuncRouter) SetOneConversationEx(operationID string, args ...any) { + f.call(operationID, f.userForSDK.Conversation().SetOneConversationEx, args...) +} diff --git a/core_func/ws_friend.go b/core_func/ws_friend.go index 1cd414b..29a90d5 100644 --- a/core_func/ws_friend.go +++ b/core_func/ws_friend.go @@ -35,6 +35,11 @@ func (f *FuncRouter) SetFriendRemark(operationID string, args ...any) { f.call(operationID, f.userForSDK.Friend().SetFriendRemark, args...) } +// PinFriends pins friends to the top of the friend list. +func (f *FuncRouter) PinFriends(operationID string, args ...any) { + f.call(operationID, f.userForSDK.Friend().PinFriends, args...) +} + // DeleteFriend removes a user from the friend list. func (f *FuncRouter) DeleteFriend(operationID string, args ...any) { f.call(operationID, f.userForSDK.Friend().DeleteFriend, args...) @@ -74,3 +79,8 @@ func (f *FuncRouter) GetBlackList(operationID string) { func (f *FuncRouter) RemoveBlack(operationID string, args ...any) { f.call(operationID, f.userForSDK.Friend().RemoveBlack, args...) } + +// SetFriendsEx sets the friend ex info. +func (f *FuncRouter) SetFriendsEx(operationID string, args ...any) { + f.call(operationID, f.userForSDK.Friend().SetFriendsEx, args...) +} diff --git a/core_func/ws_user.go b/core_func/ws_user.go index 2e913e6..29983a1 100644 --- a/core_func/ws_user.go +++ b/core_func/ws_user.go @@ -20,6 +20,11 @@ func (f *FuncRouter) SetSelfInfo(operationID string, args ...any) { f.call(operationID, f.userForSDK.User().SetSelfInfo, args...) } +// SetSelfInfoEx updates the current user's information. +func (f *FuncRouter) SetSelfInfoEx(operationID string, args ...any) { + f.call(operationID, f.userForSDK.User().SetSelfInfoEx, args...) +} + // SetGlobalRecvMessageOpt sets the global option for receiving messages for the user. func (f *FuncRouter) SetGlobalRecvMessageOpt(operationID string, args ...any) { f.call(operationID, f.userForSDK.User().SetGlobalRecvMessageOpt, args...) diff --git a/gate/gate.go b/gate/gate.go index fd0f951..dbdeef6 100644 --- a/gate/gate.go +++ b/gate/gate.go @@ -33,6 +33,12 @@ type Gate struct { FuncMsgRecv func(interface{}, Agent) } +func NewGate(maxConnNum int, maxMsgLen uint32, processor network.Processor, WSAddr string, + HTTPTimeout time.Duration, writerChanLen int) *Gate { + return &Gate{MaxConnNum: maxConnNum, MaxMsgLen: maxMsgLen, Processor: processor, WSAddr: WSAddr, + HTTPTimeout: HTTPTimeout, PendingWriteNum: writerChanLen} +} + // SetFun sets the functions for handling new agents, closing agents, and receiving messages. func (gate *Gate) SetFun(Fun1 func(Agent), Fun2 func(Agent), Fun3 func(interface{}, Agent)) { gate.FunNewAgent = Fun1 diff --git a/go.mod b/go.mod index 6c61b75..e0f6e3c 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/OpenIMSDK/tools v0.0.16 github.com/bwmarrin/snowflake v0.3.0 github.com/gorilla/websocket v1.5.0 - github.com/openimsdk/openim-sdk-core/v3 v3.3.1-rc.7 + github.com/openimsdk/openim-sdk-core/v3 v3.5.0 github.com/stretchr/testify v1.8.3 github.com/xuexihuang/new_log15 v1.0.0 ) @@ -19,16 +19,16 @@ require ( github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect github.com/tencentyun/qcloud-cos-sts-sdk v0.0.0-20220106031843-2efeb10ca2f6 // indirect - golang.org/x/image v0.9.0 // indirect - golang.org/x/net v0.11.0 // indirect - golang.org/x/text v0.11.0 // indirect + golang.org/x/image v0.14.0 // indirect + golang.org/x/net v0.19.0 // indirect + golang.org/x/text v0.14.0 // indirect google.golang.org/grpc v1.56.2 // indirect gorm.io/driver/sqlite v1.3.6 // indirect nhooyr.io/websocket v1.8.7 // indirect ) require ( - github.com/OpenIMSDK/protocol v0.0.23 // indirect + github.com/OpenIMSDK/protocol v0.0.40 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/golang/protobuf v1.5.3 // indirect github.com/jinzhu/inflection v1.0.0 // indirect @@ -46,7 +46,7 @@ require ( go.uber.org/atomic v1.7.0 // indirect go.uber.org/multierr v1.6.0 // indirect go.uber.org/zap v1.24.0 // indirect - golang.org/x/sys v0.13.0 // indirect + golang.org/x/sys v0.15.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20231030173426-d783a09b4405 // indirect google.golang.org/protobuf v1.31.0 // indirect gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect diff --git a/go.sum b/go.sum index 0827de3..72ac6e1 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/OpenIMSDK/protocol v0.0.23 h1:L545aRQez6Ro+AaJB1Z6Mz7ojnDtp41WqASxYveCkcE= -github.com/OpenIMSDK/protocol v0.0.23/go.mod h1:F25dFrwrIx3lkNoiuf6FkCfxuwf8L4Z8UIsdTHP/r0Y= +github.com/OpenIMSDK/protocol v0.0.40 h1:1/Oij6RSAaePCPrWGwp9Cyz976/8Uxr94hM5M5FXzlg= +github.com/OpenIMSDK/protocol v0.0.40/go.mod h1:F25dFrwrIx3lkNoiuf6FkCfxuwf8L4Z8UIsdTHP/r0Y= github.com/OpenIMSDK/tools v0.0.16 h1:te/GIq2imCMsrRPgU9OObYKbzZ3rT08Lih/o+3QFIz0= github.com/OpenIMSDK/tools v0.0.16/go.mod h1:eg+q4A34Qmu73xkY0mt37FHGMCMfC6CtmOnm0kFEGFI= github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= @@ -83,8 +83,8 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ= github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8= -github.com/openimsdk/openim-sdk-core/v3 v3.3.1-rc.7 h1:P1CG3011qeUKKMKUtFZtG1B64VbNV6shhW3hOqvjN84= -github.com/openimsdk/openim-sdk-core/v3 v3.3.1-rc.7/go.mod h1:8cQJEanYxUxMdPuiPxHPrw1RkiDtIny5eGNyYfNFdWM= +github.com/openimsdk/openim-sdk-core/v3 v3.5.0 h1:wsmQ0a50GyWtooUJzCW/g7I1eMkoxcHRuq0owO740aU= +github.com/openimsdk/openim-sdk-core/v3 v3.5.0/go.mod h1:5zQe7SU7tlw2/A6ODSPlCG4mEMOnD2VottVRKzTSQ4I= github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ= github.com/petermattis/goid v0.0.0-20230904192822-1876fd5063bc h1:8bQZVK1X6BJR/6nYUPxQEP+ReTsceJTKizeuwjWOPUA= github.com/petermattis/goid v0.0.0-20230904192822-1876fd5063bc/go.mod h1:pxMtw7cyUw6B2bRH0ZBANSPg+AoSud1I1iyJHI69jH4= @@ -106,7 +106,6 @@ github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLY github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU= github.com/xuexihuang/new_log15 v1.0.0 h1:rIfjUeC4dgkjDYvbb6zv3q4Jk/aSvBo03UJ1mJCyJvg= github.com/xuexihuang/new_log15 v1.0.0/go.mod h1:psqerkM8mBbXXWN8DG3NUo33C3Hyr9RsaRjq8VfyA2c= -github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI= @@ -115,49 +114,21 @@ go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9i go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60= go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg= golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.10.0 h1:LKqV2xt9+kDzSTfOhx4FrkEBcMrAgHSYgzywV9zcGmM= -golang.org/x/image v0.9.0 h1:QrzfX26snvCM20hIhBwuHI/ThTg18b/+kcKdXHvnR+g= -golang.org/x/image v0.9.0/go.mod h1:jtrku+n79PfroUbvDdeUWMAI+heR786BofxrbiSF+J0= -golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/net v0.11.0 h1:Gi2tvZIJyBtO9SDr1q9h5hEQCp/4L2RQ+ar0qjx2oNU= -golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY= +golang.org/x/image v0.14.0 h1:tNgSxAFe3jC4uYqvZdTr84SZoM1KfwdC9SKIFrLjFn4= +golang.org/x/image v0.14.0/go.mod h1:HUYqC05R2ZcZ3ejNQsIHQDQiwWM4JBqmm6MKANTp4LE= +golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c= +golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= -golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= +golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4= -golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/genproto/googleapis/rpc v0.0.0-20231030173426-d783a09b4405 h1:AB/lmRny7e2pLhFEYIbl5qkDAUt2h0ZRO4wGPhZf+ik= google.golang.org/genproto/googleapis/rpc v0.0.0-20231030173426-d783a09b4405/go.mod h1:67X1fPuzjcrkymZzZV1vvkFeTn2Rvc6lYF9MYFGCcwE= diff --git a/network/ws_client.go b/network/ws_client.go index dd74ced..d6d7040 100644 --- a/network/ws_client.go +++ b/network/ws_client.go @@ -13,6 +13,7 @@ const ( MaxMsgLen = 1024 * 1024 * 10 ) +// WSClient just for client dial to websocket server type WSClient struct { sync.Mutex Addr string