mirror of
https://github.com/screego/server.git
synced 2025-03-14 10:17:16 +00:00
39 lines
662 B
Go
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
|
|
}
|