mirror of
https://github.com/bluenviron/mediamtx
synced 2024-12-12 09:44:59 +00:00
9c6ba7e2c7
This is a new authentication system that covers all the features exposed by the server, including playback, API, metrics and PPROF, improves internal authentication by adding permissions, improves HTTP-based authentication by adding the ability to exclude certain actions from being authenticated, adds an additional method (JWT-based authentication).
71 lines
1.2 KiB
Go
71 lines
1.2 KiB
Go
package conf
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
"github.com/bluenviron/gortsplib/v4"
|
|
)
|
|
|
|
// RTSPTransport is the rtspTransport parameter.
|
|
type RTSPTransport struct {
|
|
*gortsplib.Transport
|
|
}
|
|
|
|
// MarshalJSON implements json.Marshaler.
|
|
func (d RTSPTransport) MarshalJSON() ([]byte, error) {
|
|
var out string
|
|
|
|
if d.Transport == nil {
|
|
out = "automatic"
|
|
} else {
|
|
switch *d.Transport {
|
|
case gortsplib.TransportUDP:
|
|
out = "udp"
|
|
|
|
case gortsplib.TransportUDPMulticast:
|
|
out = "multicast"
|
|
|
|
default:
|
|
out = "tcp"
|
|
}
|
|
}
|
|
|
|
return json.Marshal(out)
|
|
}
|
|
|
|
// UnmarshalJSON implements json.Unmarshaler.
|
|
func (d *RTSPTransport) UnmarshalJSON(b []byte) error {
|
|
var in string
|
|
if err := json.Unmarshal(b, &in); err != nil {
|
|
return err
|
|
}
|
|
|
|
switch in {
|
|
case "udp":
|
|
v := gortsplib.TransportUDP
|
|
d.Transport = &v
|
|
|
|
case "multicast":
|
|
v := gortsplib.TransportUDPMulticast
|
|
d.Transport = &v
|
|
|
|
case "tcp":
|
|
v := gortsplib.TransportTCP
|
|
d.Transport = &v
|
|
|
|
case "automatic":
|
|
d.Transport = nil
|
|
|
|
default:
|
|
return fmt.Errorf("invalid protocol '%s'", in)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// UnmarshalEnv implements env.Unmarshaler.
|
|
func (d *RTSPTransport) UnmarshalEnv(_ string, v string) error {
|
|
return d.UnmarshalJSON([]byte(`"` + v + `"`))
|
|
}
|