mirror of
https://github.com/screego/server.git
synced 2025-09-27 04:26:34 +08:00
39 lines
672 B
Go
39 lines
672 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].WriteTimeout(outgoing.ClientICE(*e))
|
|
|
|
return nil
|
|
}
|