Files
go2rtc/pkg/streamer/helpers.go
2022-12-05 00:47:46 +03:00

50 lines
723 B
Go

package streamer
import (
"strings"
)
const (
JSONType = "type"
JSONRemoteAddr = "remote_addr"
JSONUserAgent = "user_agent"
JSONReceive = "receive"
JSONSend = "send"
)
func Between(s, sub1, sub2 string) string {
i := strings.Index(s, sub1)
if i < 0 {
return ""
}
s = s[i+len(sub1):]
if len(sub2) == 1 {
i = strings.IndexByte(s, sub2[0])
} else {
i = strings.Index(s, sub2)
}
if i >= 0 {
return s[:i]
}
return s
}
func Contains(medias []*Media, media *Media, codec *Codec) bool {
var ok1, ok2 bool
for _, m := range medias {
if m == media {
ok1 = true
break
}
}
for _, c := range media.Codecs {
if c == codec {
ok2 = true
break
}
}
return ok1 && ok2
}