Code refactoring for Nest RTSP source
This commit is contained in:
+6
-12
@@ -120,21 +120,11 @@ func (a *API) GetDevices(projectID string) ([]DeviceInfo, error) {
|
|||||||
devices := make([]DeviceInfo, 0, len(resv.Devices))
|
devices := make([]DeviceInfo, 0, len(resv.Devices))
|
||||||
|
|
||||||
for _, device := range resv.Devices {
|
for _, device := range resv.Devices {
|
||||||
|
// only RTSP and WEB_RTC available (both supported)
|
||||||
if len(device.Traits.SdmDevicesTraitsCameraLiveStream.SupportedProtocols) == 0 {
|
if len(device.Traits.SdmDevicesTraitsCameraLiveStream.SupportedProtocols) == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
supported := false
|
|
||||||
for _, protocol := range device.Traits.SdmDevicesTraitsCameraLiveStream.SupportedProtocols {
|
|
||||||
if protocol == "WEB_RTC" || protocol == "RTSP" {
|
|
||||||
supported = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !supported {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
i := strings.LastIndexByte(device.Name, '/')
|
i := strings.LastIndexByte(device.Name, '/')
|
||||||
if i <= 0 {
|
if i <= 0 {
|
||||||
continue
|
continue
|
||||||
@@ -146,7 +136,11 @@ func (a *API) GetDevices(projectID string) ([]DeviceInfo, error) {
|
|||||||
name = device.ParentRelations[0].DisplayName
|
name = device.ParentRelations[0].DisplayName
|
||||||
}
|
}
|
||||||
|
|
||||||
devices = append(devices, DeviceInfo{Name: name, DeviceID: device.Name[i+1:], Protocols: device.Traits.SdmDevicesTraitsCameraLiveStream.SupportedProtocols})
|
devices = append(devices, DeviceInfo{
|
||||||
|
Name: name,
|
||||||
|
DeviceID: device.Name[i+1:],
|
||||||
|
Protocols: device.Traits.SdmDevicesTraitsCameraLiveStream.SupportedProtocols,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return devices, nil
|
return devices, nil
|
||||||
|
|||||||
+5
-14
@@ -33,12 +33,6 @@ func Dial(rawURL string) (core.Producer, error) {
|
|||||||
refreshToken := query.Get("refresh_token")
|
refreshToken := query.Get("refresh_token")
|
||||||
projectID := query.Get("project_id")
|
projectID := query.Get("project_id")
|
||||||
deviceID := query.Get("device_id")
|
deviceID := query.Get("device_id")
|
||||||
protocols := strings.Split(query.Get("protocols"), ",")
|
|
||||||
|
|
||||||
// Default to WEB_RTC for backwards compataiility
|
|
||||||
if len(protocols) == 0 {
|
|
||||||
protocols = append(protocols, "WEB_RTC")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cliendID == "" || cliendSecret == "" || refreshToken == "" || projectID == "" || deviceID == "" {
|
if cliendID == "" || cliendSecret == "" || refreshToken == "" || projectID == "" || deviceID == "" {
|
||||||
return nil, errors.New("nest: wrong query")
|
return nil, errors.New("nest: wrong query")
|
||||||
@@ -49,16 +43,13 @@ func Dial(rawURL string) (core.Producer, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pick the first supported protocol in order of priority (WEB_RTC, RTSP)
|
protocols := strings.Split(query.Get("protocols"), ",")
|
||||||
for _, proto := range protocols {
|
if len(protocols) > 0 && protocols[0] == "RTSP" {
|
||||||
if proto == "WEB_RTC" {
|
return rtspConn(nestAPI, rawURL, projectID, deviceID)
|
||||||
return rtcConn(nestAPI, rawURL, projectID, deviceID)
|
|
||||||
} else if proto == "RTSP" {
|
|
||||||
return rtspConn(nestAPI, rawURL, projectID, deviceID)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, errors.New("nest: unsupported camera")
|
// Default to WEB_RTC for backwards compataiility
|
||||||
|
return rtcConn(nestAPI, rawURL, projectID, deviceID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *WebRTCClient) GetMedias() []*core.Media {
|
func (c *WebRTCClient) GetMedias() []*core.Media {
|
||||||
|
|||||||
Reference in New Issue
Block a user