json, gob 둘다 지원
This commit is contained in:
@ -6,12 +6,13 @@ import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"repositories.action2quare.com/ayo/gocommon/logger"
|
||||
)
|
||||
|
||||
type room struct {
|
||||
inChan chan *wsconn
|
||||
outChan chan *wsconn
|
||||
outChan chan primitive.ObjectID
|
||||
messageChan chan *UpstreamMessage
|
||||
name string
|
||||
destroyChan chan<- string
|
||||
@ -22,7 +23,7 @@ type room struct {
|
||||
func makeRoom(name string, destroyChan chan<- string, sendMsgChan chan<- send_msg_queue_elem) *room {
|
||||
return &room{
|
||||
inChan: make(chan *wsconn, 10),
|
||||
outChan: make(chan *wsconn, 10),
|
||||
outChan: make(chan primitive.ObjectID, 10),
|
||||
messageChan: make(chan *UpstreamMessage, 100),
|
||||
name: name,
|
||||
destroyChan: destroyChan,
|
||||
@ -39,8 +40,8 @@ func (r *room) in(conn *wsconn) *room {
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *room) out(conn *wsconn) *room {
|
||||
r.outChan <- conn
|
||||
func (r *room) out(accid primitive.ObjectID) *room {
|
||||
r.outChan <- accid
|
||||
return r
|
||||
}
|
||||
|
||||
@ -72,8 +73,8 @@ func (r *room) loop(ctx context.Context, conns *map[string]*wsconn) (normalEnd b
|
||||
case conn := <-r.inChan:
|
||||
(*conns)[conn.sender.Accid.Hex()] = conn
|
||||
|
||||
case conn := <-r.outChan:
|
||||
delete((*conns), conn.sender.Accid.Hex())
|
||||
case accid := <-r.outChan:
|
||||
delete((*conns), accid.Hex())
|
||||
if len(*conns) == 0 && r.destroyChan != nil {
|
||||
r.destroyChan <- r.name
|
||||
return true
|
||||
|
||||
Reference in New Issue
Block a user