screego-server/ws/event_hostice.go
2024-12-07 12:15:44 +01:00

39 lines
662 B
Go

package ws
import (
"fmt"
"github.com/rs/zerolog/log"
"github.com/screego/server/ws/outgoing"
)
func init() {
register("hostice", func() Event {
return &HostICE{}
})
}
type HostICE outgoing.P2PMessage
func (e *HostICE) 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.Host != current.ID {
return fmt.Errorf("permission denied for session %s", e.SID)
}
room.Users[session.Client].WriteTimeout(outgoing.HostICE(*e))
return nil
}