mirror of
https://github.com/m1k1o/neko.git
synced 2025-05-24 14:37:05 +02:00
Refactor: session remove duplicate ID in endpoints.
This commit is contained in:
parent
e150203b54
commit
5c92b75cf7
7 changed files with 53 additions and 80 deletions
|
@ -43,8 +43,8 @@ func (h *MessageHandler) SessionConnected(session types.Session) error {
|
|||
}
|
||||
|
||||
// tell session there is a host
|
||||
host, ok := h.sessions.GetHost()
|
||||
if ok {
|
||||
host := h.sessions.GetHost()
|
||||
if host != nil {
|
||||
if err := session.Send(message.Control{
|
||||
Event: event.CONTROL_LOCKED,
|
||||
ID: host.ID(),
|
||||
|
@ -67,13 +67,14 @@ func (h *MessageHandler) SessionConnected(session types.Session) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (h *MessageHandler) SessionDestroyed(session types.Session) error {
|
||||
func (h *MessageHandler) SessionDestroyed(id string) error {
|
||||
// clear host if exists
|
||||
if session.IsHost() {
|
||||
host := h.sessions.GetHost()
|
||||
if host != nil && host.ID() == id {
|
||||
h.sessions.ClearHost()
|
||||
if err := h.sessions.Broadcast(message.Control{
|
||||
Event: event.CONTROL_RELEASE,
|
||||
ID: session.ID(),
|
||||
ID: id,
|
||||
}, nil); err != nil {
|
||||
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.CONTROL_RELEASE)
|
||||
}
|
||||
|
@ -83,7 +84,7 @@ func (h *MessageHandler) SessionDestroyed(session types.Session) error {
|
|||
if err := h.sessions.Broadcast(
|
||||
message.MemberDisconnected{
|
||||
Event: event.MEMBER_DISCONNECTED,
|
||||
ID: session.ID(),
|
||||
ID: id,
|
||||
}, nil); err != nil {
|
||||
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.MEMBER_DISCONNECTED)
|
||||
return err
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue