change hls url and query and add more checks
This commit is contained in:
+1
-1
@@ -398,7 +398,7 @@ func(c *TuyaClient) GetStreamUrl(streamType string) (err error) {
|
|||||||
c.rtspURL = allosResponse.Result.URL
|
c.rtspURL = allosResponse.Result.URL
|
||||||
fmt.Printf("RTSP URL: %s\n", c.rtspURL)
|
fmt.Printf("RTSP URL: %s\n", c.rtspURL)
|
||||||
case "hls":
|
case "hls":
|
||||||
c.hlsURL = "ffmpeg:" + allosResponse.Result.URL + "#video=copy"
|
c.hlsURL = allosResponse.Result.URL
|
||||||
fmt.Printf("HLS URL: %s\n", c.hlsURL)
|
fmt.Printf("HLS URL: %s\n", c.hlsURL)
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("unsupported stream type: %s", streamType)
|
return fmt.Errorf("unsupported stream type: %s", streamType)
|
||||||
|
|||||||
+23
-11
@@ -41,13 +41,31 @@ func Dial(rawURL string) (core.Producer, error) {
|
|||||||
clientID := query.Get("client_id")
|
clientID := query.Get("client_id")
|
||||||
secret := query.Get("secret")
|
secret := query.Get("secret")
|
||||||
resolution := query.Get("resolution")
|
resolution := query.Get("resolution")
|
||||||
useRTSP := query.Get("rtsp") == "1"
|
streamType := query.Get("type")
|
||||||
useHLS := query.Get("hls") == "1"
|
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 == "" {
|
if deviceID == "" || uid == "" || clientID == "" || secret == "" {
|
||||||
return nil, errors.New("tuya: wrong query")
|
return nil, errors.New("tuya: wrong query")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !useRTSP && !useHLS && !useWebRTC {
|
||||||
|
return nil, errors.New("tuya: wrong stream type")
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize Tuya API client
|
// Initialize Tuya API client
|
||||||
tuyaAPI, err := NewTuyaClient(u.Hostname(), deviceID, uid, clientID, secret, useRTSP, useHLS)
|
tuyaAPI, err := NewTuyaClient(u.Hostname(), deviceID, uid, clientID, secret, useRTSP, useHLS)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -59,24 +77,17 @@ func Dial(rawURL string) (core.Producer, error) {
|
|||||||
done: make(chan struct{}),
|
done: make(chan struct{}),
|
||||||
}
|
}
|
||||||
|
|
||||||
// RTSP
|
|
||||||
if useRTSP {
|
if useRTSP {
|
||||||
if client.api.rtspURL == "" {
|
if client.api.rtspURL == "" {
|
||||||
return nil, errors.New("tuya: no rtsp url")
|
return nil, errors.New("tuya: no rtsp url")
|
||||||
}
|
}
|
||||||
|
|
||||||
return streams.GetProducer(client.api.rtspURL)
|
return streams.GetProducer(client.api.rtspURL)
|
||||||
}
|
} else if useHLS {
|
||||||
|
|
||||||
// HLS
|
|
||||||
if useHLS {
|
|
||||||
if client.api.hlsURL == "" {
|
if client.api.hlsURL == "" {
|
||||||
return nil, errors.New("tuya: no hls url")
|
return nil, errors.New("tuya: no hls url")
|
||||||
}
|
}
|
||||||
return streams.GetProducer(client.api.hlsURL)
|
return streams.GetProducer(client.api.hlsURL)
|
||||||
}
|
} else {
|
||||||
|
|
||||||
// Default to WebRTC
|
|
||||||
conf := pion.Configuration{
|
conf := pion.Configuration{
|
||||||
ICEServers: client.api.iceServers,
|
ICEServers: client.api.iceServers,
|
||||||
ICETransportPolicy: pion.ICETransportPolicyAll,
|
ICETransportPolicy: pion.ICETransportPolicyAll,
|
||||||
@@ -193,6 +204,7 @@ func Dial(rawURL string) (core.Producer, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return client, nil
|
return client, nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) GetMedias() []*core.Media {
|
func (c *Client) GetMedias() []*core.Media {
|
||||||
|
|||||||
Reference in New Issue
Block a user