Update WebRTC type in info JSON

This commit is contained in:
Alexey Khit
2023-03-08 17:33:00 +03:00
parent 775b1818d1
commit 1fc2cf3175
9 changed files with 67 additions and 14 deletions
+23
View File
@@ -5,6 +5,29 @@ import (
"time"
)
type Mode byte
const (
ModeActiveProducer Mode = iota + 1 // typical source (client)
ModePassiveConsumer
ModePassiveProducer
ModeActiveConsumer
)
func (m Mode) String() string {
switch m {
case ModeActiveProducer:
return "active producer"
case ModePassiveConsumer:
return "passive consumer"
case ModePassiveProducer:
return "passive producer"
case ModeActiveConsumer:
return "active consumer"
}
return "unknown"
}
type Info struct {
Type string `json:"type,omitempty"`
URL string `json:"url,omitempty"`
+2
View File
@@ -10,6 +10,8 @@ type Conn struct {
streamer.Element
UserAgent string
Desc string
Mode streamer.Mode
pc *webrtc.PeerConnection
+1 -1
View File
@@ -113,7 +113,7 @@ func (c *Conn) AddTrack(media *streamer.Media, track *streamer.Track) *streamer.
func (c *Conn) MarshalJSON() ([]byte, error) {
info := &streamer.Info{
Type: "WebRTC",
Type: c.Desc + " " + c.Mode.String(),
RemoteAddr: c.remote,
UserAgent: c.UserAgent,
Medias: c.medias,
+2
View File
@@ -15,6 +15,8 @@ import (
func NewClient(tracker, share, pwd string, pc *pion.PeerConnection) (*webrtc.Conn, error) {
// 1. Create WebRTC producer
prod := webrtc.NewConn(pc)
prod.Desc = "WebRTC/WebTorrent sync"
prod.Mode = streamer.ModeActiveProducer
medias := []*streamer.Media{
{Kind: streamer.KindVideo, Direction: streamer.DirectionRecvonly},