Files
screego/ws/event_clientice.go
Jannis Mattheis a0f3c37498 fix: race condition
In client.go

    if room, ok := message.(outgoing.Room); ok {
            c.info.RoomID = room.ID
    }

this part isn't thread safe. It could happen that user disconnected but
wasn't removed from a room, because the disconnecting go routine
couldn't see the roomID yet.
2024-10-11 15:11:07 +02:00

39 lines
667 B
Go

package ws
import (
"fmt"
"github.com/rs/zerolog/log"
"github.com/screego/server/ws/outgoing"
)
func init() {
register("clientice", func() Event {
return &ClientICE{}
})
}
type ClientICE outgoing.P2PMessage
func (e *ClientICE) Execute(rooms *Rooms, current ClientInfo) error {
room, err := rooms.CurrentRoom(current)
if err != nil {
return err
}
session, ok := room.Sessions[e.SID]
if !ok {
log.Debug().Str("id", e.SID.String()).Msg("unknown session")
return nil
}
if session.Client != current.ID {
return fmt.Errorf("permission denied for session %s", e.SID)
}
room.Users[session.Host].Write <- outgoing.ClientICE(*e)
return nil
}