server: allow to associate user data to sessions (#50)

This commit is contained in:
aler9
2022-11-03 12:02:38 +01:00
parent d3c23a849c
commit 08a16e7b38
2 changed files with 13 additions and 0 deletions

View File

@@ -163,6 +163,7 @@ type ServerSession struct {
ctx context.Context
ctxCancel func()
userData interface{}
conns map[*ServerConn]struct{}
state ServerSessionState
setuppedTracks map[int]*ServerSessionSetuppedTrack
@@ -242,6 +243,16 @@ func (ss *ServerSession) AnnouncedTracks() Tracks {
return ss.announcedTracks
}
// SetUserData sets some user data associated to the session.
func (ss *ServerSession) SetUserData(v interface{}) {
ss.userData = v
}
// UserData returns some user data associated to the session.
func (ss *ServerSession) UserData() interface{} {
return ss.userData
}
func (ss *ServerSession) checkState(allowed map[ServerSessionState]struct{}) error {
if _, ok := allowed[ss.state]; ok {
return nil