tuya

package
v1.9.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 14, 2025 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AvailableRegions = []Region{
	{"eu-central", "protect-eu.ismartlife.me", "Central Europe", "EU"},
	{"eu-east", "protect-we.ismartlife.me", "East Europe", "EU"},
	{"us-west", "protect-us.ismartlife.me", "West America", "AZ"},
	{"us-east", "protect-ue.ismartlife.me", "East America", "AZ"},
	{"china", "protect.ismartlife.me", "China", "AY"},
	{"india", "protect-in.ismartlife.me", "India", "IN"},
}

Functions

func CreateHTTPClientWithSession

func CreateHTTPClientWithSession() *http.Client

func Dial

func Dial(rawURL string) (core.Producer, error)

func EncryptPassword

func EncryptPassword(password, pbKey string) (string, error)

func IsEmailAddress

func IsEmailAddress(input string) bool

Types

type Allocate

type Allocate struct {
	URL string `json:"url"`
}

type AllocateRequest

type AllocateRequest struct {
	Type string `json:"type"`
}

type AllocateResponse

type AllocateResponse struct {
	Success bool     `json:"success"`
	Result  Allocate `json:"result"`
	Msg     string   `json:"msg,omitempty"`
}

type AnswerFrame

type AnswerFrame struct {
	Mode string `json:"mode"`
	Sdp  string `json:"sdp"`
}

type AppInfo

type AppInfo struct {
	AppId    int    `json:"appId"`
	AppName  string `json:"appName"`
	ClientId string `json:"clientId"`
	Icon     string `json:"icon"`
}

type AppInfoResponse

type AppInfoResponse struct {
	Result  AppInfo `json:"result"`
	T       int64   `json:"t"`
	Success bool    `json:"success"`
	Msg     string  `json:"errorMsg,omitempty"`
}

type AudioAttributes

type AudioAttributes struct {
	CallMode           []int `json:"call_mode"`           // 1 = one way, 2 = two way
	HardwareCapability []int `json:"hardware_capability"` // 1 = mic, 2 = speaker
}

type AudioSkill

type AudioSkill struct {
	Channels   int `json:"channels"`
	DataBit    int `json:"dataBit"`
	CodecType  int `json:"codecType"`
	SampleRate int `json:"sampleRate"`
}

type CandidateFrame

type CandidateFrame struct {
	Mode      string `json:"mode"`
	Candidate string `json:"candidate"`
}

type Client

type Client struct {
	// contains filtered or unexported fields
}

func (*Client) AddTrack

func (c *Client) AddTrack(media *core.Media, codec *core.Codec, track *core.Receiver) error

func (*Client) Close

func (c *Client) Close(err error) error

func (*Client) GetMedias

func (c *Client) GetMedias() []*core.Media

func (*Client) GetTrack

func (c *Client) GetTrack(media *core.Media, codec *core.Codec) (*core.Receiver, error)

func (*Client) MarshalJSON

func (c *Client) MarshalJSON() ([]byte, error)

func (*Client) Start

func (c *Client) Start() error

func (*Client) Stop

func (c *Client) Stop() error

type DataChannelMessage

type DataChannelMessage struct {
	Type string `json:"type"` // "codec", "start", "recv", "complete"
	Msg  string `json:"msg"`
}

type Device

type Device struct {
	Category            string `json:"category"`
	DeviceId            string `json:"deviceId"`
	DeviceName          string `json:"deviceName"`
	P2pType             int    `json:"p2pType"`
	ProductId           string `json:"productId"`
	SupportCloudStorage bool   `json:"supportCloudStorage"`
	Uuid                string `json:"uuid"`
}

type DisconnectFrame

type DisconnectFrame struct {
	Mode string `json:"mode"`
}

type Domain

type Domain struct {
	AispeechHttpsUrl    string `json:"aispeechHttpsUrl"`
	AispeechQuicUrl     string `json:"aispeechQuicUrl"`
	DeviceHttpUrl       string `json:"deviceHttpUrl"`
	DeviceHttpsPskUrl   string `json:"deviceHttpsPskUrl"`
	DeviceHttpsUrl      string `json:"deviceHttpsUrl"`
	DeviceMediaMqttUrl  string `json:"deviceMediaMqttUrl"`
	DeviceMediaMqttsUrl string `json:"deviceMediaMqttsUrl"`
	DeviceMqttsPskUrl   string `json:"deviceMqttsPskUrl"`
	DeviceMqttsUrl      string `json:"deviceMqttsUrl"`
	GwApiUrl            string `json:"gwApiUrl"`
	GwMqttUrl           string `json:"gwMqttUrl"`
	HttpPort            int    `json:"httpPort"`
	HttpsPort           int    `json:"httpsPort"`
	HttpsPskPort        int    `json:"httpsPskPort"`
	MobileApiUrl        string `json:"mobileApiUrl"`
	MobileMediaMqttUrl  string `json:"mobileMediaMqttUrl"`
	MobileMqttUrl       string `json:"mobileMqttUrl"`
	MobileMqttsUrl      string `json:"mobileMqttsUrl"`
	MobileQuicUrl       string `json:"mobileQuicUrl"`
	MqttPort            int    `json:"mqttPort"`
	MqttQuicUrl         string `json:"mqttQuicUrl"`
	MqttsPort           int    `json:"mqttsPort"`
	MqttsPskPort        int    `json:"mqttsPskPort"`
	RegionCode          string `json:"regionCode"`
}

type Extras

type Extras struct {
	HomeId    string `json:"homeId"`
	SceneType string `json:"sceneType"`
}

type Home

type Home struct {
	Admin            bool    `json:"admin"`
	Background       string  `json:"background"`
	DealStatus       int     `json:"dealStatus"`
	DisplayOrder     int     `json:"displayOrder"`
	GeoName          string  `json:"geoName"`
	Gid              int     `json:"gid"`
	GmtCreate        int64   `json:"gmtCreate"`
	GmtModified      int64   `json:"gmtModified"`
	GroupId          int     `json:"groupId"`
	GroupUserId      int     `json:"groupUserId"`
	Id               int     `json:"id"`
	Lat              float64 `json:"lat"`
	Lon              float64 `json:"lon"`
	ManagementStatus bool    `json:"managementStatus"`
	Name             string  `json:"name"`
	OwnerId          string  `json:"ownerId"`
	Role             int     `json:"role"`
	Status           bool    `json:"status"`
	Uid              string  `json:"uid"`
}

type HomeListResponse

type HomeListResponse struct {
	Result  []Home `json:"result"`
	T       int64  `json:"t"`
	Success bool   `json:"success"`
	Msg     string `json:"errorMsg,omitempty"`
}

type ICEServer

type ICEServer struct {
	Urls       string `json:"urls"`
	Username   string `json:"username,omitempty"`
	Credential string `json:"credential,omitempty"`
	TTL        int    `json:"ttl,omitempty"`
}

type LoginResult

type LoginResult struct {
	Attribute          int    `json:"attribute"`
	ClientId           string `json:"clientId"`
	DataVersion        int    `json:"dataVersion"`
	Domain             Domain `json:"domain"`
	Ecode              string `json:"ecode"`
	Email              string `json:"email"`
	Extras             Extras `json:"extras"`
	HeadPic            string `json:"headPic"`
	ImproveCompanyInfo bool   `json:"improveCompanyInfo"`
	Nickname           string `json:"nickname"`
	PartnerIdentity    string `json:"partnerIdentity"`
	PhoneCode          string `json:"phoneCode"`
	Receiver           string `json:"receiver"`
	RegFrom            int    `json:"regFrom"`
	Sid                string `json:"sid"`
	SnsNickname        string `json:"snsNickname"`
	TempUnit           int    `json:"tempUnit"`
	Timezone           string `json:"timezone"`
	TimezoneId         string `json:"timezoneId"`
	Uid                string `json:"uid"`
	UserType           int    `json:"userType"`
	Username           string `json:"username"`
}

type LoginToken

type LoginToken struct {
	Token     string `json:"token"`
	Exponent  string `json:"exponent"`
	PublicKey string `json:"publicKey"`
	PbKey     string `json:"pbKey"`
}

type LoginTokenRequest

type LoginTokenRequest struct {
	CountryCode string `json:"countryCode"`
	Username    string `json:"username"`
	IsUid       bool   `json:"isUid"`
}

type LoginTokenResponse

type LoginTokenResponse struct {
	Result  LoginToken `json:"result"`
	Success bool       `json:"success"`
	Msg     string     `json:"errorMsg,omitempty"`
}

type MQTTConfig

type MQTTConfig struct {
	Url            string `json:"url"`
	PublishTopic   string `json:"publish_topic"`
	SubscribeTopic string `json:"subscribe_topic"`
	ClientID       string `json:"client_id"`
	Username       string `json:"username"`
	Password       string `json:"password"`
}

type MQTTConfigResponse

type MQTTConfigResponse struct {
	Result  SmartApiMQTTConfig `json:"result"`
	Success bool               `json:"success"`
	Msg     string             `json:"errorMsg,omitempty"`
}

type MqttFrame

type MqttFrame struct {
	Header  MqttFrameHeader `json:"header"`
	Message json.RawMessage `json:"msg"`
}

type MqttFrameHeader

type MqttFrameHeader struct {
	Type          string `json:"type"`
	From          string `json:"from"`
	To            string `json:"to"`
	SubDevID      string `json:"sub_dev_id"`
	SessionID     string `json:"sessionid"`
	MotoID        string `json:"moto_id"`
	TransactionID string `json:"tid"`
}

type MqttLowPowerMessage

type MqttLowPowerMessage struct {
	Protocol int    `json:"protocol"`
	T        int    `json:"t"`
	S        int    `json:"s,omitempty"`
	Type     string `json:"type,omitempty"`
	Data     struct {
		DevID                string                 `json:"devId,omitempty"`
		Online               bool                   `json:"online,omitempty"`
		LastOnlineChangeTime int64                  `json:"lastOnlineChangeTime,omitempty"`
		GwID                 string                 `json:"gwId,omitempty"`
		Cmd                  string                 `json:"cmd,omitempty"`
		Dps                  map[string]interface{} `json:"dps,omitempty"`
	} `json:"data"`
}

type MqttMessage

type MqttMessage struct {
	Protocol int       `json:"protocol"`
	Pv       string    `json:"pv"`
	T        int64     `json:"t"`
	Data     MqttFrame `json:"data"`
}

type OfferFrame

type OfferFrame struct {
	Mode              string      `json:"mode"`
	Sdp               string      `json:"sdp"`
	StreamType        int         `json:"stream_type"` // 0: mainStream(HD), 1: substream(SD)
	Auth              string      `json:"auth"`
	DatachannelEnable bool        `json:"datachannel_enable"` // true for HEVC, false for H264
	Token             []ICEServer `json:"token"`
}

type OpenIoTHubConfig

type OpenIoTHubConfig struct {
	Url       string `json:"url"`
	ClientID  string `json:"client_id"`
	Username  string `json:"username"`
	Password  string `json:"password"`
	SinkTopic struct {
		IPC string `json:"ipc"`
	} `json:"sink_topic"`
	SourceSink struct {
		IPC string `json:"ipc"`
	} `json:"source_topic"`
	ExpireTime int `json:"expire_time"`
}

type OpenIoTHubConfigRequest

type OpenIoTHubConfigRequest struct {
	UID      string `json:"uid"`
	UniqueID string `json:"unique_id"`
	LinkType string `json:"link_type"`
	Topics   string `json:"topics"`
}

type OpenIoTHubConfigResponse

type OpenIoTHubConfigResponse struct {
	Timestamp int              `json:"t"`
	Success   bool             `json:"success"`
	Result    OpenIoTHubConfig `json:"result"`
	Msg       string           `json:"msg,omitempty"`
	Code      int              `json:"code,omitempty"`
}

type P2PConfig

type P2PConfig struct {
	Ices []ICEServer `json:"ices"`
}

type PasswordLoginRequest

type PasswordLoginRequest struct {
	CountryCode string `json:"countryCode"`
	Email       string `json:"email,omitempty"`
	Mobile      string `json:"mobile,omitempty"`
	Passwd      string `json:"passwd"`
	Token       string `json:"token"`
	IfEncrypt   int    `json:"ifencrypt"`
	Options     string `json:"options"`
}

type PasswordLoginResponse

type PasswordLoginResponse struct {
	Result   LoginResult `json:"result"`
	Success  bool        `json:"success"`
	Status   string      `json:"status"`
	ErrorMsg string      `json:"errorMsg,omitempty"`
}

type RecvMessage

type RecvMessage struct {
	Video struct {
		SSRC uint32 `json:"ssrc"`
	} `json:"video"`
	Audio struct {
		SSRC uint32 `json:"ssrc"`
	} `json:"audio"`
}

RecvMessage contains SSRC values for video/audio streams

type Region

type Region struct {
	Name        string `json:"name"`
	Host        string `json:"host"`
	Description string `json:"description"`
	Continent   string `json:"continent"`
}

type ResolutionFrame

type ResolutionFrame struct {
	Mode  string `json:"mode"`
	Value int    `json:"cmdValue"` // 0: HD, 1: SD
}

type Room

type Room struct {
	DeviceCount int      `json:"deviceCount"`
	DeviceList  []Device `json:"deviceList"`
	RoomId      string   `json:"roomId"`
	RoomName    string   `json:"roomName"`
}

type RoomListRequest

type RoomListRequest struct {
	HomeId string `json:"homeId"`
}

type RoomListResponse

type RoomListResponse struct {
	Result  []Room `json:"result"`
	T       int64  `json:"t"`
	Success bool   `json:"success"`
	Msg     string `json:"errorMsg,omitempty"`
}

type SharedHome

type SharedHome struct {
	SecurityWebCShareInfoList []struct {
		DeviceInfoList []Device `json:"deviceInfoList"`
		Nickname       string   `json:"nickname"`
		Username       string   `json:"username"`
	} `json:"securityWebCShareInfoList"`
}

type SharedHomeListResponse

type SharedHomeListResponse struct {
	Result  SharedHome `json:"result"`
	T       int64      `json:"t"`
	Success bool       `json:"success"`
	Msg     string     `json:"errorMsg,omitempty"`
}

type Skill

type Skill struct {
	WebRTC   int          `json:"webrtc"`             // Bit flags: bit 4=speaker, bit 5=clarity, bit 6=record
	LowPower int          `json:"lowPower,omitempty"` // 1 = battery-powered camera
	Audios   []AudioSkill `json:"audios"`
	Videos   []VideoSkill `json:"videos"`
}

type SmartApiMQTTConfig

type SmartApiMQTTConfig struct {
	Msid     string `json:"msid"`
	Password string `json:"password"`
}

type SmartApiWebRTCConfig

type SmartApiWebRTCConfig struct {
	AudioAttributes     AudioAttributes `json:"audioAttributes"`
	Auth                string          `json:"auth"`
	GatewayId           string          `json:"gatewayId"`
	Id                  string          `json:"id"`
	LocalKey            string          `json:"localKey"`
	MotoId              string          `json:"motoId"`
	NodeId              string          `json:"nodeId"`
	P2PConfig           P2PConfig       `json:"p2pConfig"`
	ProtocolVersion     string          `json:"protocolVersion"`
	Skill               string          `json:"skill"`
	Sub                 bool            `json:"sub"`
	SupportWebrtcRecord bool            `json:"supportWebrtcRecord"`
	SupportsPtz         bool            `json:"supportsPtz"`
	SupportsWebrtc      bool            `json:"supportsWebrtc"`
	VedioClarity        int             `json:"vedioClarity"`
	VedioClaritys       []int           `json:"vedioClaritys"`
	VideoClarity        int             `json:"videoClarity"`
}

type SmartApiWebRTCConfigRequest

type SmartApiWebRTCConfigRequest struct {
	DevId         string `json:"devId"`
	ClientTraceId string `json:"clientTraceId"`
}

type SmartApiWebRTCConfigResponse

type SmartApiWebRTCConfigResponse struct {
	Result  SmartApiWebRTCConfig `json:"result"`
	Success bool                 `json:"success"`
	Msg     string               `json:"errorMsg,omitempty"`
}

type SpeakerFrame

type SpeakerFrame struct {
	Mode  string `json:"mode"`
	Value int    `json:"cmdValue"` // 0: off, 1: on
}

type Token

type Token struct {
	UID          string `json:"uid"`
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
	ExpireTime   int64  `json:"expire_time"`
}

type TokenResponse

type TokenResponse struct {
	Timestamp int64  `json:"t"`
	Success   bool   `json:"success"`
	Result    Token  `json:"result"`
	Msg       string `json:"msg,omitempty"`
	Code      int    `json:"code,omitempty"`
}

type TuyaAPI

type TuyaAPI interface {
	GetMqtt() *TuyaMqttClient

	GetStreamType(streamResolution string) int
	IsHEVC(streamType int) bool

	GetVideoCodecs() []*core.Codec
	GetAudioCodecs() []*core.Codec

	GetStreamUrl(streamUrl string) (string, error)
	GetICEServers() []pionWebrtc.ICEServer

	Init() error
	Close()
}

type TuyaClient

type TuyaClient struct {
	TuyaAPI
	// contains filtered or unexported fields
}

func (*TuyaClient) Close

func (c *TuyaClient) Close()

func (*TuyaClient) GetAudioCodecs

func (c *TuyaClient) GetAudioCodecs() []*core.Codec

func (*TuyaClient) GetICEServers

func (c *TuyaClient) GetICEServers() []pionWebrtc.ICEServer

func (*TuyaClient) GetMqtt

func (c *TuyaClient) GetMqtt() *TuyaMqttClient

func (*TuyaClient) GetStreamType

func (c *TuyaClient) GetStreamType(streamResolution string) int

GetStreamType returns the Skill StreamType for the requested resolution Returns Skill values (2 or 4), not MQTT values (0 or 1) - "hd" → highest resolution streamType (usually 2 = mainStream) - "sd" → lowest resolution streamType (usually 4 = substream)

These values must be mapped before sending to MQTT: - streamType 2 → MQTT stream_type 0 - streamType 4 → MQTT stream_type 1

func (*TuyaClient) GetVideoCodecs

func (c *TuyaClient) GetVideoCodecs() []*core.Codec

func (*TuyaClient) IsHEVC

func (c *TuyaClient) IsHEVC(streamType int) bool

IsHEVC checks if the given streamType uses H265 (HEVC) codec HEVC cameras use DataChannel, H264 cameras use RTP tracks - codecType 4 = H265 (HEVC) → DataChannel mode - codecType 2 = H264 → Normal RTP mode

type TuyaCloudApiClient

type TuyaCloudApiClient struct {
	TuyaClient
	// contains filtered or unexported fields
}

func NewTuyaCloudApiClient

func NewTuyaCloudApiClient(baseUrl, uid, deviceId, clientId, clientSecret string) (*TuyaCloudApiClient, error)

func (*TuyaCloudApiClient) GetStreamUrl

func (c *TuyaCloudApiClient) GetStreamUrl(streamType string) (streamUrl string, err error)

func (*TuyaCloudApiClient) Init

func (c *TuyaCloudApiClient) Init() error

WebRTC Flow

type TuyaMqttClient

type TuyaMqttClient struct {
	// contains filtered or unexported fields
}

func NewTuyaMqttClient

func NewTuyaMqttClient(deviceId string) *TuyaMqttClient

func (*TuyaMqttClient) SendCandidate

func (c *TuyaMqttClient) SendCandidate(candidate string) error

func (*TuyaMqttClient) SendDisconnect

func (c *TuyaMqttClient) SendDisconnect() error

func (*TuyaMqttClient) SendOffer

func (c *TuyaMqttClient) SendOffer(sdp string, streamResolution string, streamType int, isHEVC bool) error

func (*TuyaMqttClient) SendResolution

func (c *TuyaMqttClient) SendResolution(resolution int) error

func (*TuyaMqttClient) SendSpeaker

func (c *TuyaMqttClient) SendSpeaker(speaker int) error

func (*TuyaMqttClient) Start

func (c *TuyaMqttClient) Start(hubConfig *MQTTConfig, webrtcConfig *WebRTCConfig, webrtcVersion int) error

func (*TuyaMqttClient) Stop

func (c *TuyaMqttClient) Stop()

func (*TuyaMqttClient) WakeUp

func (c *TuyaMqttClient) WakeUp(localKey string) error

WakeUp sends a wake-up signal to battery-powered cameras (LowPower mode). The camera wakes up and starts responding immediately - we don't wait for dps[149]. Note: LowPower cameras sleep after ~3 minutes of inactivity.

type TuyaSmartApiClient

type TuyaSmartApiClient struct {
	TuyaClient
	// contains filtered or unexported fields
}

func NewTuyaSmartApiClient

func NewTuyaSmartApiClient(httpClient *http.Client, baseUrl, email, password, deviceId string) (*TuyaSmartApiClient, error)

func (*TuyaSmartApiClient) GetAppInfo

func (c *TuyaSmartApiClient) GetAppInfo() (*AppInfoResponse, error)

func (*TuyaSmartApiClient) GetHomeList

func (c *TuyaSmartApiClient) GetHomeList() (*HomeListResponse, error)

func (*TuyaSmartApiClient) GetRoomList

func (c *TuyaSmartApiClient) GetRoomList(homeId string) (*RoomListResponse, error)

func (*TuyaSmartApiClient) GetSharedHomeList

func (c *TuyaSmartApiClient) GetSharedHomeList() (*SharedHomeListResponse, error)

func (*TuyaSmartApiClient) GetStreamUrl

func (c *TuyaSmartApiClient) GetStreamUrl(streamType string) (streamUrl string, err error)

func (*TuyaSmartApiClient) Init

func (c *TuyaSmartApiClient) Init() error

WebRTC Flow

type VideoSkill

type VideoSkill struct {
	StreamType int    `json:"streamType"` // 2 = main stream (HD), 4 = sub stream (SD)
	CodecType  int    `json:"codecType"`  // 2 = H264, 4 = H265 (HEVC)
	Width      int    `json:"width"`
	Height     int    `json:"height"`
	SampleRate int    `json:"sampleRate"`
	ProfileId  string `json:"profileId,omitempty"`
}

type WebICE

type WebICE struct {
	Urls       string `json:"urls"`
	Username   string `json:"username,omitempty"`
	Credential string `json:"credential,omitempty"`
}

type WebRTCConfig

type WebRTCConfig struct {
	AudioAttributes      AudioAttributes `json:"audio_attributes"`
	Auth                 string          `json:"auth"`
	ID                   string          `json:"id"`
	LocalKey             string          `json:"local_key,omitempty"`
	MotoID               string          `json:"moto_id"`
	P2PConfig            P2PConfig       `json:"p2p_config"`
	ProtocolVersion      string          `json:"protocol_version"`
	Skill                string          `json:"skill"`
	SupportsWebRTCRecord bool            `json:"supports_webrtc_record"`
	SupportsWebRTC       bool            `json:"supports_webrtc"`
	VedioClaritiy        int             `json:"vedio_clarity"`
	VideoClaritiy        int             `json:"video_clarity"`
	VideoClarities       []int           `json:"video_clarities"`
}

type WebRTCConfigResponse

type WebRTCConfigResponse struct {
	Timestamp int64        `json:"t"`
	Success   bool         `json:"success"`
	Result    WebRTCConfig `json:"result"`
	Msg       string       `json:"msg,omitempty"`
	Code      int          `json:"code,omitempty"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL