Files
screego/ws/event_stop_share.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

37 lines
653 B
Go

package ws
import (
"bytes"
"github.com/screego/server/ws/outgoing"
)
func init() {
register("stopshare", func() Event {
return &StopShare{}
})
}
type StopShare struct{}
func (e *StopShare) Execute(rooms *Rooms, current ClientInfo) error {
room, err := rooms.CurrentRoom(current)
if err != nil {
return err
}
room.Users[current.ID].Streaming = false
for id, session := range room.Sessions {
if bytes.Equal(session.Host.Bytes(), current.ID.Bytes()) {
client, ok := room.Users[session.Client]
if ok {
client.Write <- outgoing.EndShare(id)
}
room.closeSession(rooms, id)
}
}
room.notifyInfoChanged()
return nil
}