change query
This commit is contained in:
@@ -575,9 +575,9 @@ Tested: KD110, KC200, KC401, KC420WS, EC71.
|
|||||||
- `webrtc` - WebRTC stream (default)
|
- `webrtc` - WebRTC stream (default)
|
||||||
- `rtsp` - RTSP stream _(if available)_
|
- `rtsp` - RTSP stream _(if available)_
|
||||||
- `hls` - HLS stream _(if available)_
|
- `hls` - HLS stream _(if available)_
|
||||||
- Use `role` parameter to select the stream:
|
- Use `resolution` parameter to select the stream:
|
||||||
- `main` - Main stream (default)
|
- `hd` - HD stream (default)
|
||||||
- `sub` - Sub stream
|
- `sd` - SD stream
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
streams:
|
streams:
|
||||||
@@ -588,10 +588,10 @@ streams:
|
|||||||
tuya_webrtc_2: tuya://openapi.tuyaus.com?device_id=XXX&uid=XXX&client_id=XXX&client_secret=XXX&mode=webrtc
|
tuya_webrtc_2: tuya://openapi.tuyaus.com?device_id=XXX&uid=XXX&client_id=XXX&client_secret=XXX&mode=webrtc
|
||||||
|
|
||||||
# Tuya WebRTC stream (HD)
|
# Tuya WebRTC stream (HD)
|
||||||
tuya_webrtc_hd: tuya://openapi.tuyaus.com?device_id=XXX&uid=XXX&client_id=XXX&client_secret=XXX&role=main
|
tuya_webrtc_hd: tuya://openapi.tuyaus.com?device_id=XXX&uid=XXX&client_id=XXX&client_secret=XXX&resolution=hd
|
||||||
|
|
||||||
# Tuya WebRTC stream (SD)
|
# Tuya WebRTC stream (SD)
|
||||||
tuya_webrtc_sd: tuya://openapi.tuyaus.com?device_id=XXX&uid=XXX&client_id=XXX&client_secret=XXX&role=sub
|
tuya_webrtc_sd: tuya://openapi.tuyaus.com?device_id=XXX&uid=XXX&client_id=XXX&client_secret=XXX&resolution=sd
|
||||||
|
|
||||||
# Using RTSP when available (no "uid" required)
|
# Using RTSP when available (no "uid" required)
|
||||||
tuya_rtsp: tuya://openapi.tuyaus.com?device_id=XXX&client_id=XXX&client_secret=XXX&mode=rtsp
|
tuya_rtsp: tuya://openapi.tuyaus.com?device_id=XXX&client_id=XXX&client_secret=XXX&mode=rtsp
|
||||||
|
|||||||
@@ -4,3 +4,4 @@
|
|||||||
- https://github.com/tuya/webrtc-demo-go
|
- https://github.com/tuya/webrtc-demo-go
|
||||||
- https://github.com/bacco007/HomeAssistantConfig/blob/master/custom_components/xtend_tuya/multi_manager/tuya_iot/ipc/webrtc/xt_tuya_iot_webrtc_manager.py
|
- https://github.com/bacco007/HomeAssistantConfig/blob/master/custom_components/xtend_tuya/multi_manager/tuya_iot/ipc/webrtc/xt_tuya_iot_webrtc_manager.py
|
||||||
- https://ipc-us.ismartlife.me/
|
- https://ipc-us.ismartlife.me/
|
||||||
|
- https://protect-us.ismartlife.me/
|
||||||
+8
-8
@@ -73,7 +73,7 @@ type AudioSkill struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type VideoSkill struct {
|
type VideoSkill struct {
|
||||||
StreamType int `json:"streamType"` // 2 = main stream, 4 = sub stream
|
StreamType int `json:"streamType"` // 2 = main stream (hd), 4 = sub stream (sd)
|
||||||
ProfileId string `json:"profileId,omitempty"`
|
ProfileId string `json:"profileId,omitempty"`
|
||||||
CodecType int `json:"codecType"` // 2 = H264, 4 = H265
|
CodecType int `json:"codecType"` // 2 = H264, 4 = H265
|
||||||
Width int `json:"width"`
|
Width int `json:"width"`
|
||||||
@@ -157,7 +157,7 @@ type OpenIoTHubConfigResponse struct {
|
|||||||
Code int `json:"code,omitempty"`
|
Code int `json:"code,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTuyaClient(openAPIURL string, deviceId string, uid string, clientId string, clientSecret string, streamMode string, streamRole string) (*TuyaClient, error) {
|
func NewTuyaClient(openAPIURL string, deviceId string, uid string, clientId string, clientSecret string, streamMode string) (*TuyaClient, error) {
|
||||||
client := &TuyaClient{
|
client := &TuyaClient{
|
||||||
httpClient: &http.Client{Timeout: 5 * time.Second},
|
httpClient: &http.Client{Timeout: 5 * time.Second},
|
||||||
mqtt: &TuyaMQTT{waiter: core.Waiter{}},
|
mqtt: &TuyaMQTT{waiter: core.Waiter{}},
|
||||||
@@ -182,7 +182,7 @@ func NewTuyaClient(openAPIURL string, deviceId string, uid string, clientId stri
|
|||||||
return nil, fmt.Errorf("failed to get HLS URL: %w", err)
|
return nil, fmt.Errorf("failed to get HLS URL: %w", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if err := client.InitDevice(streamRole); err != nil {
|
if err := client.InitDevice(); err != nil {
|
||||||
return nil, fmt.Errorf("failed to initialize device: %w", err)
|
return nil, fmt.Errorf("failed to initialize device: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,7 +227,7 @@ func (c *TuyaClient) InitToken() (err error) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *TuyaClient) InitDevice(streamRole string) (err error) {
|
func (c *TuyaClient) InitDevice() (err error) {
|
||||||
url := fmt.Sprintf("https://%s/v1.0/users/%s/devices/%s/webrtc-configs", c.apiURL, c.uid, c.deviceId)
|
url := fmt.Sprintf("https://%s/v1.0/users/%s/devices/%s/webrtc-configs", c.apiURL, c.uid, c.deviceId)
|
||||||
|
|
||||||
body, err := c.Request("GET", url, nil)
|
body, err := c.Request("GET", url, nil)
|
||||||
@@ -448,7 +448,7 @@ func getAudioCodecName(audioSkill *AudioSkill) string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *TuyaClient) getStreamType(streamRole string) int {
|
func (c *TuyaClient) getStreamType(streamResolution string) int {
|
||||||
// Default streamType if nothing is found
|
// Default streamType if nothing is found
|
||||||
defaultStreamType := 1
|
defaultStreamType := 1
|
||||||
|
|
||||||
@@ -479,10 +479,10 @@ func (c *TuyaClient) getStreamType(streamRole string) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Return the streamType based on the selection
|
// Return the streamType based on the selection
|
||||||
switch streamRole {
|
switch streamResolution {
|
||||||
case "main":
|
case "hd":
|
||||||
return highestResType
|
return highestResType
|
||||||
case "sub":
|
case "sd":
|
||||||
return lowestResType
|
return lowestResType
|
||||||
default:
|
default:
|
||||||
return defaultStreamType
|
return defaultStreamType
|
||||||
|
|||||||
+6
-6
@@ -61,11 +61,11 @@ func Dial(rawURL string) (core.Producer, error) {
|
|||||||
uid := query.Get("uid")
|
uid := query.Get("uid")
|
||||||
clientId := query.Get("client_id")
|
clientId := query.Get("client_id")
|
||||||
clientSecret := query.Get("client_secret")
|
clientSecret := query.Get("client_secret")
|
||||||
streamRole := query.Get("role")
|
streamResolution := query.Get("resolution")
|
||||||
streamMode := query.Get("mode")
|
streamMode := query.Get("mode")
|
||||||
|
|
||||||
if streamRole == "" || (streamRole != "main" && streamRole != "sub") {
|
if streamResolution == "" || (streamResolution != "hd" && streamResolution != "sd") {
|
||||||
streamRole = "main"
|
streamResolution = "hd"
|
||||||
}
|
}
|
||||||
|
|
||||||
useRTSP := streamMode == "rtsp"
|
useRTSP := streamMode == "rtsp"
|
||||||
@@ -97,7 +97,7 @@ func Dial(rawURL string) (core.Producer, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Initialize Tuya API client
|
// Initialize Tuya API client
|
||||||
tuyaAPI, err := NewTuyaClient(u.Hostname(), deviceID, uid, clientId, clientSecret, streamMode, streamRole)
|
tuyaAPI, err := NewTuyaClient(u.Hostname(), deviceID, uid, clientId, clientSecret, streamMode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("tuya: %w", err)
|
return nil, fmt.Errorf("tuya: %w", err)
|
||||||
}
|
}
|
||||||
@@ -118,7 +118,7 @@ func Dial(rawURL string) (core.Producer, error) {
|
|||||||
}
|
}
|
||||||
return streams.GetProducer(client.api.hlsURL)
|
return streams.GetProducer(client.api.hlsURL)
|
||||||
} else {
|
} else {
|
||||||
client.isHEVC = client.api.isHEVC(client.api.getStreamType(streamRole))
|
client.isHEVC = client.api.isHEVC(client.api.getStreamType(streamResolution))
|
||||||
|
|
||||||
// Create a new PeerConnection
|
// Create a new PeerConnection
|
||||||
conf := pion.Configuration{
|
conf := pion.Configuration{
|
||||||
@@ -311,7 +311,7 @@ func Dial(rawURL string) (core.Producer, error) {
|
|||||||
offer = re.ReplaceAllString(offer, "")
|
offer = re.ReplaceAllString(offer, "")
|
||||||
|
|
||||||
// Send offer
|
// Send offer
|
||||||
if err := client.api.sendOffer(offer, streamRole); err != nil {
|
if err := client.api.sendOffer(offer, streamResolution); err != nil {
|
||||||
client.Stop()
|
client.Stop()
|
||||||
return nil, fmt.Errorf("tuya: %w", err)
|
return nil, fmt.Errorf("tuya: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -202,13 +202,13 @@ func (c *TuyaMQTT) onError(err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *TuyaClient) sendOffer(sdp string, streamRole string) error {
|
func (c *TuyaClient) sendOffer(sdp string, streamResolution string) error {
|
||||||
streamType := c.getStreamType(streamRole)
|
streamType := c.getStreamType(streamResolution)
|
||||||
isHEVC := c.isHEVC(streamType)
|
isHEVC := c.isHEVC(streamType)
|
||||||
|
|
||||||
if isHEVC {
|
if isHEVC {
|
||||||
// On HEVC we use streamType 0 for main stream and 1 for sub stream
|
// On HEVC we use streamType 0 for main stream (hd) and 1 for sub stream (sd)
|
||||||
if streamRole == "main" {
|
if streamResolution == "hd" {
|
||||||
streamType = 0
|
streamType = 0
|
||||||
} else {
|
} else {
|
||||||
streamType = 1
|
streamType = 1
|
||||||
|
|||||||
Reference in New Issue
Block a user