change hls url and query and add more checks

This commit is contained in:
seydx
2025-05-12 13:31:45 +02:00
parent b797a2fcd1
commit a7e76db464
2 changed files with 130 additions and 118 deletions
+1 -1
View File
@@ -398,7 +398,7 @@ func(c *TuyaClient) GetStreamUrl(streamType string) (err error) {
c.rtspURL = allosResponse.Result.URL
fmt.Printf("RTSP URL: %s\n", c.rtspURL)
case "hls":
c.hlsURL = "ffmpeg:" + allosResponse.Result.URL + "#video=copy"
c.hlsURL = allosResponse.Result.URL
fmt.Printf("HLS URL: %s\n", c.hlsURL)
default:
return fmt.Errorf("unsupported stream type: %s", streamType)
+23 -11
View File
@@ -41,13 +41,31 @@ func Dial(rawURL string) (core.Producer, error) {
clientID := query.Get("client_id")
secret := query.Get("secret")
resolution := query.Get("resolution")
useRTSP := query.Get("rtsp") == "1"
useHLS := query.Get("hls") == "1"
streamType := query.Get("type")
useRTSP := streamType == "rtsp"
useHLS := streamType == "hls"
useWebRTC := streamType == "webrtc" || streamType == ""
// check if host is correct
switch u.Hostname() {
case DefaultCnURL:
case DefaultWestUsURL:
case DefaultEastUsURL:
case DefaultCentralEuURL:
case DefaultWestEuURL:
case DefaultInURL:
default:
return nil, fmt.Errorf("tuya: wrong host %s", u.Hostname())
}
if deviceID == "" || uid == "" || clientID == "" || secret == "" {
return nil, errors.New("tuya: wrong query")
}
if !useRTSP && !useHLS && !useWebRTC {
return nil, errors.New("tuya: wrong stream type")
}
// Initialize Tuya API client
tuyaAPI, err := NewTuyaClient(u.Hostname(), deviceID, uid, clientID, secret, useRTSP, useHLS)
if err != nil {
@@ -59,24 +77,17 @@ func Dial(rawURL string) (core.Producer, error) {
done: make(chan struct{}),
}
// RTSP
if useRTSP {
if client.api.rtspURL == "" {
return nil, errors.New("tuya: no rtsp url")
}
return streams.GetProducer(client.api.rtspURL)
}
// HLS
if useHLS {
} else if useHLS {
if client.api.hlsURL == "" {
return nil, errors.New("tuya: no hls url")
}
return streams.GetProducer(client.api.hlsURL)
}
// Default to WebRTC
} else {
conf := pion.Configuration{
ICEServers: client.api.iceServers,
ICETransportPolicy: pion.ICETransportPolicyAll,
@@ -194,6 +205,7 @@ func Dial(rawURL string) (core.Producer, error) {
return client, nil
}
}
func (c *Client) GetMedias() []*core.Media {
return c.prod.GetMedias()