connection 도 room을 알고 있게 됨
This commit is contained in:
@ -13,14 +13,17 @@ type room struct {
|
||||
outChan chan *wsconn
|
||||
messageChan chan *UpstreamMessage
|
||||
name string
|
||||
destroyChan chan<- string
|
||||
}
|
||||
|
||||
func makeRoom(name string) *room {
|
||||
// 만약 destroyChan가 nil이면 room이 비어도 파괴되지 않는다. 영구 유지되는 room
|
||||
func makeRoom(name string, destroyChan chan<- string) *room {
|
||||
return &room{
|
||||
inChan: make(chan *wsconn, 10),
|
||||
outChan: make(chan *wsconn, 10),
|
||||
messageChan: make(chan *UpstreamMessage, 100),
|
||||
name: name,
|
||||
destroyChan: destroyChan,
|
||||
}
|
||||
}
|
||||
|
||||
@ -28,12 +31,14 @@ func (r *room) broadcast(msg *UpstreamMessage) {
|
||||
r.messageChan <- msg
|
||||
}
|
||||
|
||||
func (r *room) in(conn *wsconn) {
|
||||
func (r *room) in(conn *wsconn) *room {
|
||||
r.inChan <- conn
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *room) out(conn *wsconn) {
|
||||
func (r *room) out(conn *wsconn) *room {
|
||||
r.outChan <- conn
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *room) start(ctx context.Context) {
|
||||
@ -66,6 +71,10 @@ func (r *room) loop(ctx context.Context, conns *map[string]*wsconn) (normalEnd b
|
||||
|
||||
case conn := <-r.outChan:
|
||||
delete((*conns), conn.sender.Accid.Hex())
|
||||
if len(*conns) == 0 && r.destroyChan != nil {
|
||||
r.destroyChan <- r.name
|
||||
return true
|
||||
}
|
||||
|
||||
case msg := <-r.messageChan:
|
||||
ds := DownstreamMessage{
|
||||
|
||||
Reference in New Issue
Block a user