wip: v0.2.6
This commit is contained in:
@ -129,11 +129,13 @@ type roomController struct {
|
||||
sync.Mutex
|
||||
ctx context.Context
|
||||
//rooms map[string]map[string]*roomClient // map[room_id(remote-IP)][Id]
|
||||
pre map[string]*roomClient
|
||||
clients map[string]*roomClient
|
||||
}
|
||||
|
||||
var (
|
||||
RoomController = &roomController{
|
||||
pre: make(map[string]*roomClient),
|
||||
clients: make(map[string]*roomClient),
|
||||
}
|
||||
)
|
||||
@ -142,10 +144,9 @@ func (rc *roomController) Start(ctx context.Context) {
|
||||
rc.ctx = ctx
|
||||
}
|
||||
|
||||
func (rc *roomController) Register(conn *websocket.Conn, ip, userAgent string) *roomClient {
|
||||
func (rc *roomController) Register(ip, userAgent string) *roomClient {
|
||||
nrc := &roomClient{
|
||||
controller: rc,
|
||||
conn: conn,
|
||||
ClientType: ClientTypeDesktop,
|
||||
AppType: RoomAppTypeWeb,
|
||||
IP: ip,
|
||||
@ -163,16 +164,32 @@ func (rc *roomController) Register(conn *websocket.Conn, ip, userAgent string) *
|
||||
nrc.ClientType = ClientTypeTablet
|
||||
}
|
||||
|
||||
log.Debug("controller.room: registry client, IP = %s, Id = %s, Name = %s", nrc.IP, nrc.Id, nrc.Name)
|
||||
rc.Lock()
|
||||
defer rc.Unlock()
|
||||
|
||||
nrc.start(rc.ctx)
|
||||
rc.pre[nrc.Id] = nrc
|
||||
|
||||
nrc.msgChan <- map[string]any{"type": "register", "time": time.Now().UnixMilli(), "body": nrc}
|
||||
rc.Broadcast(map[string]any{"type": "enter", "time": time.Now().UnixMilli(), "body": nrc})
|
||||
return nrc
|
||||
}
|
||||
|
||||
func (rc *roomController) Enter(conn *websocket.Conn, id string) *roomClient {
|
||||
log.Debug("controller.room: registry client, id = %s", id)
|
||||
|
||||
rc.Lock()
|
||||
defer rc.Unlock()
|
||||
|
||||
nrc, ok := rc.pre[id]
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
nrc.conn = conn
|
||||
nrc.start(rc.ctx)
|
||||
|
||||
rc.Broadcast(map[string]any{"type": "enter", "time": time.Now().UnixMilli(), "body": nrc})
|
||||
|
||||
delete(rc.pre, nrc.Id)
|
||||
rc.clients[nrc.Id] = nrc
|
||||
rc.Unlock()
|
||||
|
||||
return nrc
|
||||
}
|
||||
|
Reference in New Issue
Block a user