-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
announce.go
83 lines (66 loc) · 1.92 KB
/
announce.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package moqt
import (
"io"
"log/slog"
"github.com/OkutaniDaichi0106/gomoqt/internal/message"
)
// type InterestHandler interface {
// HandleInterest(Interest, AnnounceSender)
// }
const (
ENDED AnnounceStatus = AnnounceStatus(message.ENDED)
ACTIVE AnnounceStatus = AnnounceStatus(message.ACTIVE)
LIVE AnnounceStatus = AnnounceStatus(message.LIVE)
)
type AnnounceStatus message.AnnounceStatus
type Announcement struct {
/***/
status AnnounceStatus
/***/
TrackPathSuffix string
/***/
AuthorizationInfo string
Parameters Parameters
}
func readAnnouncement(r io.Reader) (Announcement, error) {
slog.Debug("reading an announcement")
// Read an ANNOUNCE message
var am message.AnnounceMessage
err := am.Decode(r)
if err != nil {
slog.Error("failed to read an ANNOUNCE message", slog.String("error", err.Error()))
return Announcement{}, err
}
// Initialize an Announcement
announcement := Announcement{
status: AnnounceStatus(am.AnnounceStatus),
TrackPathSuffix: am.TrackPathSuffix,
Parameters: Parameters(am.Parameters),
}
//
authInfo, ok := getAuthorizationInfo(announcement.Parameters)
if ok {
announcement.AuthorizationInfo = authInfo
}
return announcement, nil
}
func writeAnnouncement(w io.Writer, announcement Announcement) error {
slog.Debug("writing an announcement")
// Add AUTHORIZATION_INFO parameter
if announcement.AuthorizationInfo != "" {
announcement.Parameters.Add(AUTHORIZATION_INFO, announcement.AuthorizationInfo)
}
// Initialize an ANNOUNCE message
am := message.AnnounceMessage{
TrackPathSuffix: announcement.TrackPathSuffix,
Parameters: message.Parameters(announcement.Parameters),
}
// Encode the ANNOUNCE message
err := am.Encode(w)
if err != nil {
slog.Error("failed to send an ANNOUNCE message.", slog.String("error", err.Error()))
return err
}
slog.Info("Successfully announced", slog.Any("announcement", announcement))
return nil
}