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
|
||||
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
@@ -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,
|
||||
@@ -193,6 +204,7 @@ func Dial(rawURL string) (core.Producer, error) {
|
||||
}
|
||||
|
||||
return client, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) GetMedias() []*core.Media {
|
||||
|
||||
Reference in New Issue
Block a user