Adds support RTSPtoWeb API (entity_id for zero config from Hass)

This commit is contained in:
Alexey Khit
2022-09-16 12:10:58 +03:00
parent 800ebb39be
commit ae3e1372c8
4 changed files with 116 additions and 73 deletions
+6
View File
@@ -38,6 +38,12 @@ func NewStream(source interface{}) *Stream {
return s
}
func (s *Stream) SetSource(source string) {
if len(s.producers) > 0 {
s.producers[0].url = source
}
}
func (s *Stream) AddConsumer(cons streamer.Consumer) (err error) {
ic := len(s.consumers)
+14 -1
View File
@@ -4,6 +4,7 @@ import (
"github.com/AlexxIT/go2rtc/cmd/app"
"github.com/AlexxIT/go2rtc/cmd/app/store"
"github.com/rs/zerolog"
"strings"
)
func Init() {
@@ -27,7 +28,6 @@ func Init() {
func Get(src string) *Stream {
if stream, ok := streams[src]; ok {
return stream
}
if !HasProducer(src) {
@@ -45,6 +45,19 @@ func Has(src string) bool {
}
func New(name string, source interface{}) {
switch source := source.(type) {
case string:
// check if new stream already link on our other stream
if strings.HasPrefix(source, "rtsp://") {
if i := strings.IndexByte(source[7:], '/'); i > 0 {
if stream, ok := streams[source[8+i:]]; ok {
streams[name] = stream
return
}
}
}
}
streams[name] = NewStream(source)
}