message receiver 시그니쳐 변경
This commit is contained in:
@ -409,13 +409,15 @@ type groupContainer struct {
|
|||||||
|
|
||||||
type groupInMemory struct {
|
type groupInMemory struct {
|
||||||
*groupConfig
|
*groupConfig
|
||||||
groupDocSync func(groupID, []byte) error
|
groupDocSync func(groupID, []byte) error
|
||||||
memberSync func(groupID, accountID, ticketID, *memberDoc, bool) error
|
memberSync func(groupID, accountID, ticketID, *memberDoc, bool) error
|
||||||
rpcCall func([]byte) error
|
rpcCall func([]byte) error
|
||||||
hasConn func(accountID) *connection
|
hasConn func(accountID) *connection
|
||||||
sendUpstreamMessage func(*wshandler.UpstreamMessage)
|
sendUpstreamMessage func(*wshandler.UpstreamMessage)
|
||||||
sendCloseMessage func(accountID, string)
|
sendEnterRoomMessage func(groupID, accountID)
|
||||||
groups groupContainer
|
sendLeaveRoomMessage func(groupID, accountID)
|
||||||
|
sendCloseMessage func(accountID, string)
|
||||||
|
groups groupContainer
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gc *groupContainer) add(id groupID, doc *groupDoc) {
|
func (gc *groupContainer) add(id groupID, doc *groupDoc) {
|
||||||
@ -615,7 +617,7 @@ func (gm *groupInMemory) Invite(gid groupID, mid accountID, inviterDoc bson.M, i
|
|||||||
if rconn == nil {
|
if rconn == nil {
|
||||||
// mid가 있는 곳에서 처리를 해야 접속 끊겼을 때 콜백을 먼저 등록할 수 있다.
|
// mid가 있는 곳에서 처리를 해야 접속 끊겼을 때 콜백을 먼저 등록할 수 있다.
|
||||||
// 콜백이 rconn에 먼저 등록되지 않으면 좀비 group이 생길 가능성이 생긴다.
|
// 콜백이 rconn에 먼저 등록되지 않으면 좀비 group이 생길 가능성이 생긴다.
|
||||||
return "", rpc.Make(gm).To(targetid).Call(gid, mid, inviteeDoc, inviterDoc)
|
return gid.Hex(), rpc.Make(gm).To(targetid).Call(gid, mid, inviteeDoc, inviterDoc)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 이제 여기는 mid가 InCharge이면서 rconn이 존재
|
// 이제 여기는 mid가 InCharge이면서 rconn이 존재
|
||||||
@ -633,6 +635,8 @@ func (gm *groupInMemory) Invite(gid groupID, mid accountID, inviterDoc bson.M, i
|
|||||||
}
|
}
|
||||||
gm.groupDocSync(gid, bt)
|
gm.groupDocSync(gid, bt)
|
||||||
gm.memberSync(gid, mid, tid, newdoc, true)
|
gm.memberSync(gid, mid, tid, newdoc, true)
|
||||||
|
// 내가 wshandler room에 입장
|
||||||
|
gm.sendEnterRoomMessage(gid, mid)
|
||||||
} else {
|
} else {
|
||||||
// targetid가 이미 멤버인지 미리 확인 가능
|
// targetid가 이미 멤버인지 미리 확인 가능
|
||||||
if !gd.ticket(targetid).IsZero() {
|
if !gd.ticket(targetid).IsZero() {
|
||||||
@ -670,6 +674,7 @@ func (gm *groupInMemory) AcceptInvitation(gid groupID, mid accountID, tid ticket
|
|||||||
|
|
||||||
result, isNew := gd.addMember(mid, &tid, member)
|
result, isNew := gd.addMember(mid, &tid, member)
|
||||||
if result != nil {
|
if result != nil {
|
||||||
|
gm.sendEnterRoomMessage(gid, mid)
|
||||||
return gid, gm.memberSync(gid, mid, tid, result, isNew)
|
return gid, gm.memberSync(gid, mid, tid, result, isNew)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -726,11 +731,11 @@ func (gm *groupInMemory) DropPausedMember(gid primitive.ObjectID, mid primitive.
|
|||||||
// 드랍해야 한다.
|
// 드랍해야 한다.
|
||||||
if gd.InCharge == mid {
|
if gd.InCharge == mid {
|
||||||
// 내가 방장인 경우
|
// 내가 방장인 경우
|
||||||
gm.groupDocSync(gid, nil)
|
return gm.groupDocSync(gid, nil)
|
||||||
} else {
|
} else {
|
||||||
// 내가 방장이 아닌 경우
|
// 내가 방장이 아닌 경우
|
||||||
gd.removeMember(mid, &tid)
|
gd.removeMember(mid, &tid)
|
||||||
gm.memberSync(gid, mid, tid, nil, false)
|
return gm.memberSync(gid, mid, tid, nil, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -852,6 +857,7 @@ func (gm *groupInMemory) Leave(gid groupID, mid accountID, tid ticketID) error {
|
|||||||
Target: "@" + mid.Hex(),
|
Target: "@" + mid.Hex(),
|
||||||
Body: makeTypeMessage(FullGroupDoc{Gid: gid}),
|
Body: makeTypeMessage(FullGroupDoc{Gid: gid}),
|
||||||
})
|
})
|
||||||
|
gm.sendLeaveRoomMessage(gid, targetmid)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -963,6 +969,12 @@ func (cfg *groupConfig) prepareInMemory(ctx context.Context, typename string, su
|
|||||||
sendUpstreamMessage: func(msg *wshandler.UpstreamMessage) {
|
sendUpstreamMessage: func(msg *wshandler.UpstreamMessage) {
|
||||||
wsh.SendUpstreamMessage(region, msg)
|
wsh.SendUpstreamMessage(region, msg)
|
||||||
},
|
},
|
||||||
|
sendEnterRoomMessage: func(gid groupID, accid accountID) {
|
||||||
|
wsh.EnterRoom(region, gid.Hex(), accid)
|
||||||
|
},
|
||||||
|
sendLeaveRoomMessage: func(gid groupID, accid accountID) {
|
||||||
|
wsh.LeaveRoom(region, gid.Hex(), accid)
|
||||||
|
},
|
||||||
sendCloseMessage: func(target accountID, text string) {
|
sendCloseMessage: func(target accountID, text string) {
|
||||||
wsh.SendCloseMessage(region, target.Hex(), text)
|
wsh.SendCloseMessage(region, target.Hex(), text)
|
||||||
},
|
},
|
||||||
|
|||||||
@ -185,21 +185,22 @@ func (tv *Tavern) Cleanup() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tv *Tavern) SocketMessageReceived(accid primitive.ObjectID, alias string, messageType wshandler.WebSocketMessageType, body io.Reader) {
|
// func (tv *Tavern) SocketMessageReceived(accid primitive.ObjectID, alias string, messageType wshandler.WebSocketMessageType, body io.Reader) {
|
||||||
switch messageType {
|
// switch messageType {
|
||||||
case wshandler.Connected:
|
// case wshandler.Connected:
|
||||||
case wshandler.Disconnected:
|
|
||||||
}
|
// case wshandler.Disconnected:
|
||||||
// gidtype := msg.Conn.GetTag("gid")
|
// }
|
||||||
// if len(gidtype) > 0 {
|
// // gidtype := msg.Conn.GetTag("gid")
|
||||||
// tokens := strings.SplitN(gidtype, "@", 2)
|
// // if len(gidtype) > 0 {
|
||||||
// gidobj, _ := primitive.ObjectIDFromHex(tokens[0])
|
// // tokens := strings.SplitN(gidtype, "@", 2)
|
||||||
// gtype := tokens[1]
|
// // gidobj, _ := primitive.ObjectIDFromHex(tokens[0])
|
||||||
// group := sub.groups[gtype]
|
// // gtype := tokens[1]
|
||||||
// if group != nil {
|
// // group := sub.groups[gtype]
|
||||||
// group.PauseMember(gidobj, msg.Alias, msg.Conn)
|
// // if group != nil {
|
||||||
// }
|
// // group.PauseMember(gidobj, msg.Alias, msg.Conn)
|
||||||
}
|
// // }
|
||||||
|
// }
|
||||||
|
|
||||||
func (tv *Tavern) prepare(ctx context.Context) error {
|
func (tv *Tavern) prepare(ctx context.Context) error {
|
||||||
redisClient, err := gocommon.NewRedisClient(config.RedisURL, 0)
|
redisClient, err := gocommon.NewRedisClient(config.RedisURL, 0)
|
||||||
@ -275,11 +276,11 @@ func (tv *Tavern) RegisterHandlers(ctx context.Context, serveMux *http.ServeMux,
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sub *subTavern) clientMessageReceived(accid primitive.ObjectID, alias string, messageType wshandler.WebSocketMessageType, body io.Reader) {
|
func (sub *subTavern) clientMessageReceived(sender *wshandler.Sender, messageType wshandler.WebSocketMessageType, body io.Reader) {
|
||||||
if messageType == wshandler.Connected {
|
if messageType == wshandler.Connected {
|
||||||
sub.cm.add(accid, alias)
|
sub.cm.add(sender.Accid, sender.Alias)
|
||||||
} else if messageType == wshandler.Disconnected {
|
} else if messageType == wshandler.Disconnected {
|
||||||
sub.cm.remove(accid)
|
sub.cm.remove(sender.Accid)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
2
go.mod
2
go.mod
@ -5,7 +5,7 @@ go 1.19
|
|||||||
require (
|
require (
|
||||||
github.com/go-redis/redis/v8 v8.11.5
|
github.com/go-redis/redis/v8 v8.11.5
|
||||||
go.mongodb.org/mongo-driver v1.11.7
|
go.mongodb.org/mongo-driver v1.11.7
|
||||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230710053024-a842845685ee
|
repositories.action2quare.com/ayo/gocommon v0.0.0-20230711005604-a42eb2888e97
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
|||||||
4
go.sum
4
go.sum
@ -104,3 +104,7 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
|||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230710053024-a842845685ee h1:Aau1j/b9wI4nyvrM7m1Q+2xkcW1Qo7i3q+QBD4Umnzg=
|
repositories.action2quare.com/ayo/gocommon v0.0.0-20230710053024-a842845685ee h1:Aau1j/b9wI4nyvrM7m1Q+2xkcW1Qo7i3q+QBD4Umnzg=
|
||||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230710053024-a842845685ee/go.mod h1:ng62uGMGXyQSeuxePG5gJAMtip4Rnspu5Tu7hgvaXns=
|
repositories.action2quare.com/ayo/gocommon v0.0.0-20230710053024-a842845685ee/go.mod h1:ng62uGMGXyQSeuxePG5gJAMtip4Rnspu5Tu7hgvaXns=
|
||||||
|
repositories.action2quare.com/ayo/gocommon v0.0.0-20230711003621-3bb985d0b617 h1:91mBIGIyxzcnvOaIdegUuV+i9xs8YTSRcmyRaIytzx8=
|
||||||
|
repositories.action2quare.com/ayo/gocommon v0.0.0-20230711003621-3bb985d0b617/go.mod h1:ng62uGMGXyQSeuxePG5gJAMtip4Rnspu5Tu7hgvaXns=
|
||||||
|
repositories.action2quare.com/ayo/gocommon v0.0.0-20230711005604-a42eb2888e97 h1:ARzXt3HBmiAUDyACfNm5Kvz1JMTn7+ryE03kB8x/km0=
|
||||||
|
repositories.action2quare.com/ayo/gocommon v0.0.0-20230711005604-a42eb2888e97/go.mod h1:ng62uGMGXyQSeuxePG5gJAMtip4Rnspu5Tu7hgvaXns=
|
||||||
|
|||||||
Reference in New Issue
Block a user