-
Notifications
You must be signed in to change notification settings - Fork 0
/
reporter.go
44 lines (39 loc) · 1.05 KB
/
reporter.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
package syncer
import (
pb "github.com/yindaheng98/dion/proto"
"google.golang.org/protobuf/types/known/timestamppb"
)
// qualityReporter describe an abstract SFU that can report the running quality
type qualityReporter struct {
t TransmissionReporter
c ComputationReporter
tCh chan *pb.TransmissionReport
cCh chan *pb.ComputationReport
}
func newQualityReporter(t TransmissionReporter, c ComputationReporter) *qualityReporter {
r := &qualityReporter{
t: t,
c: c,
tCh: make(chan *pb.TransmissionReport, 1),
cCh: make(chan *pb.ComputationReport, 1),
}
t.Bind(r.tCh)
c.Bind(r.cCh)
return r
}
// FetchReport fetch a quality report
// Block until return a new quality report
func (q *qualityReporter) FetchReport() *pb.QualityReport {
select {
case tr := <-q.tCh:
return &pb.QualityReport{
Timestamp: timestamppb.Now(),
Report: &pb.QualityReport_Transmission{Transmission: tr},
}
case cr := <-q.cCh:
return &pb.QualityReport{
Timestamp: timestamppb.Now(),
Report: &pb.QualityReport_Computation{Computation: cr},
}
}
}