diff --git a/README.md b/README.md index ed2b96d2..05d940fd 100644 --- a/README.md +++ b/README.md @@ -575,9 +575,9 @@ Tested: KD110, KC200, KC401, KC420WS, EC71. - `webrtc` - WebRTC stream (default) - `rtsp` - RTSP stream _(if available)_ - `hls` - HLS stream _(if available)_ -- Use `role` parameter to select the stream: - - `main` - Main stream (default) - - `sub` - Sub stream +- Use `resolution` parameter to select the stream: + - `hd` - HD stream (default) + - `sd` - SD stream ```yaml 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 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_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) tuya_rtsp: tuya://openapi.tuyaus.com?device_id=XXX&client_id=XXX&client_secret=XXX&mode=rtsp diff --git a/pkg/tuya/README.md b/pkg/tuya/README.md index f5cbc814..137bd155 100644 --- a/pkg/tuya/README.md +++ b/pkg/tuya/README.md @@ -3,4 +3,5 @@ - https://developer.tuya.com/en/docs/iot/webrtc?id=Kacsd4x2hl0se - 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://ipc-us.ismartlife.me/ \ No newline at end of file +- https://ipc-us.ismartlife.me/ +- https://protect-us.ismartlife.me/ \ No newline at end of file diff --git a/pkg/tuya/api.go b/pkg/tuya/api.go index 3842ed02..3fb72c62 100644 --- a/pkg/tuya/api.go +++ b/pkg/tuya/api.go @@ -73,7 +73,7 @@ type AudioSkill 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"` CodecType int `json:"codecType"` // 2 = H264, 4 = H265 Width int `json:"width"` @@ -157,7 +157,7 @@ type OpenIoTHubConfigResponse struct { 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{ httpClient: &http.Client{Timeout: 5 * time.Second}, 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) } } else { - if err := client.InitDevice(streamRole); err != nil { + if err := client.InitDevice(); err != nil { return nil, fmt.Errorf("failed to initialize device: %w", err) } @@ -227,7 +227,7 @@ func (c *TuyaClient) InitToken() (err error) { 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) 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 defaultStreamType := 1 @@ -479,10 +479,10 @@ func (c *TuyaClient) getStreamType(streamRole string) int { } // Return the streamType based on the selection - switch streamRole { - case "main": + switch streamResolution { + case "hd": return highestResType - case "sub": + case "sd": return lowestResType default: return defaultStreamType diff --git a/pkg/tuya/client.go b/pkg/tuya/client.go index c67f8c47..5a865690 100644 --- a/pkg/tuya/client.go +++ b/pkg/tuya/client.go @@ -61,11 +61,11 @@ func Dial(rawURL string) (core.Producer, error) { uid := query.Get("uid") clientId := query.Get("client_id") clientSecret := query.Get("client_secret") - streamRole := query.Get("role") + streamResolution := query.Get("resolution") streamMode := query.Get("mode") - if streamRole == "" || (streamRole != "main" && streamRole != "sub") { - streamRole = "main" + if streamResolution == "" || (streamResolution != "hd" && streamResolution != "sd") { + streamResolution = "hd" } useRTSP := streamMode == "rtsp" @@ -97,7 +97,7 @@ func Dial(rawURL string) (core.Producer, error) { } // 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 { return nil, fmt.Errorf("tuya: %w", err) } @@ -118,7 +118,7 @@ func Dial(rawURL string) (core.Producer, error) { } return streams.GetProducer(client.api.hlsURL) } else { - client.isHEVC = client.api.isHEVC(client.api.getStreamType(streamRole)) + client.isHEVC = client.api.isHEVC(client.api.getStreamType(streamResolution)) // Create a new PeerConnection conf := pion.Configuration{ @@ -311,7 +311,7 @@ func Dial(rawURL string) (core.Producer, error) { offer = re.ReplaceAllString(offer, "") // Send offer - if err := client.api.sendOffer(offer, streamRole); err != nil { + if err := client.api.sendOffer(offer, streamResolution); err != nil { client.Stop() return nil, fmt.Errorf("tuya: %w", err) } diff --git a/pkg/tuya/mqtt.go b/pkg/tuya/mqtt.go index ebc27894..6fd3d4a0 100644 --- a/pkg/tuya/mqtt.go +++ b/pkg/tuya/mqtt.go @@ -202,13 +202,13 @@ func (c *TuyaMQTT) onError(err error) { } } -func (c *TuyaClient) sendOffer(sdp string, streamRole string) error { - streamType := c.getStreamType(streamRole) +func (c *TuyaClient) sendOffer(sdp string, streamResolution string) error { + streamType := c.getStreamType(streamResolution) isHEVC := c.isHEVC(streamType) if isHEVC { - // On HEVC we use streamType 0 for main stream and 1 for sub stream - if streamRole == "main" { + // On HEVC we use streamType 0 for main stream (hd) and 1 for sub stream (sd) + if streamResolution == "hd" { streamType = 0 } else { streamType = 1