-
Notifications
You must be signed in to change notification settings - Fork 3
/
models.go
58 lines (48 loc) · 1.4 KB
/
models.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
package main
import (
"log"
"time"
"github.com/nareix/joy4/av/pubsub"
"github.com/nareix/joy4/format/rtmp"
)
type ConnStats struct {
TxBytes uint64 `json:"txBytes"`
RxBytes uint64 `json:"rxBytes"`
Bitrate float64 `json:"bitrate"`
}
type EventMsg struct {
Level string `json:"level"`
Message string `json:"msg"`
Timestamp int64 `json:"time"`
}
type Endpoint struct {
Name string `json:"name"`
URL string `json:"url"`
Dest *rtmp.Conn `json:"-"`
Connected bool `json:"connected"`
ConnErr error `json:"connectErr,omitempty"`
Stats ConnStats `json:"stats"`
}
func (self *Endpoint) Update(new Endpoint) {
self.Name = new.Name
self.URL = new.URL
}
type Restream struct {
ID string `json:"id"`
Name string `json:"name"`
Endpoints map[string]*Endpoint `json:"endpoints"`
Channel chan string `json:"-"`
Origin *rtmp.Conn `json:"-"`
Queue *pubsub.Queue `json:"-"`
Streaming bool `json:"streaming"`
Stats ConnStats `json:"stats"`
Events []EventMsg `json:"events"`
}
func (self *Restream) AddEvent(level, message string) {
log.Printf("%s][%s] %s", self.Name, level, message)
self.Events = append(self.Events, EventMsg{
Level: level,
Message: message,
Timestamp: time.Now().UnixNano(),
})
}