-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
session.go
55 lines (43 loc) · 1.1 KB
/
session.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package moqt
import (
"log/slog"
"github.com/OkutaniDaichi0106/gomoqt/internal/transport"
)
type SessionStream transport.Stream //TODO:
type session struct {
conn transport.Connection
stream SessionStream
publisherManager *publisherManager
subscriberManager *subscriberManager
}
func (sess *session) Publisher() *Publisher {
return &Publisher{
sess: sess,
publisherManager: sess.publisherManager,
}
}
func (sess *session) Subscriber() *Subscriber {
return &Subscriber{
sess: sess,
subscriberManager: sess.subscriberManager,
}
}
func (sess *session) Terminate(err error) {
slog.Info("Terminating a session", slog.String("reason", err.Error()))
var tererr TerminateError
if err == nil {
tererr = NoErrTerminate
} else {
var ok bool
tererr, ok = err.(TerminateError)
if !ok {
tererr = ErrInternalError
}
}
err = sess.conn.CloseWithError(transport.SessionErrorCode(tererr.TerminateErrorCode()), err.Error())
if err != nil {
slog.Error("failed to close the Connection", slog.String("error", err.Error()))
return
}
slog.Info("Terminated a session")
}