format
This commit is contained in:
+6
-6
@@ -202,7 +202,7 @@ func (c *TuyaClient) Close() {
|
||||
c.httpClient.CloseIdleConnections()
|
||||
}
|
||||
|
||||
func(c *TuyaClient) Request(method string, url string, body any) ([]byte, error) {
|
||||
func (c *TuyaClient) Request(method string, url string, body any) ([]byte, error) {
|
||||
var bodyReader io.Reader
|
||||
if body != nil {
|
||||
jsonBody, err := json.Marshal(body)
|
||||
@@ -249,7 +249,7 @@ func(c *TuyaClient) Request(method string, url string, body any) ([]byte, error)
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func(c *TuyaClient) InitToken() (err error) {
|
||||
func (c *TuyaClient) InitToken() (err error) {
|
||||
url := fmt.Sprintf("https://%s/v1.0/token?grant_type=1", c.apiURL)
|
||||
|
||||
c.accessToken = ""
|
||||
@@ -277,7 +277,7 @@ func(c *TuyaClient) InitToken() (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
func(c *TuyaClient) InitDevice() (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)
|
||||
@@ -409,7 +409,7 @@ func(c *TuyaClient) InitDevice() (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
func(c *TuyaClient) GetStreamUrl(streamType string) (err error) {
|
||||
func (c *TuyaClient) GetStreamUrl(streamType string) (err error) {
|
||||
url := fmt.Sprintf("https://%s/v1.0/devices/%s/stream/actions/allocate", c.apiURL, c.deviceId)
|
||||
|
||||
request := &AllocateRequest{
|
||||
@@ -443,7 +443,7 @@ func(c *TuyaClient) GetStreamUrl(streamType string) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
func(c *TuyaClient) LoadHubConfig() (config *OpenIoTHubConfig, err error) {
|
||||
func (c *TuyaClient) LoadHubConfig() (config *OpenIoTHubConfig, err error) {
|
||||
url := fmt.Sprintf("https://%s/v2.0/open-iot-hub/access/config", c.apiURL)
|
||||
|
||||
request := &OpenIoTHubConfigRequest{
|
||||
@@ -513,7 +513,7 @@ func (c *TuyaClient) getStreamType(streamChoice string) uint32 {
|
||||
}
|
||||
}
|
||||
|
||||
func(c *TuyaClient) calBusinessSign(ts int64) string {
|
||||
func (c *TuyaClient) calBusinessSign(ts int64) string {
|
||||
data := fmt.Sprintf("%s%s%s%d", c.clientId, c.accessToken, c.clientSecret, ts)
|
||||
val := md5.Sum([]byte(data))
|
||||
res := fmt.Sprintf("%X", val)
|
||||
|
||||
+12
-12
@@ -71,7 +71,7 @@ type MqttMessage struct {
|
||||
Data MqttFrame `json:"data"`
|
||||
}
|
||||
|
||||
func(c *TuyaClient) StartMQTT() error {
|
||||
func (c *TuyaClient) StartMQTT() error {
|
||||
hubConfig, err := c.LoadHubConfig()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -106,14 +106,14 @@ func(c *TuyaClient) StartMQTT() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func(c *TuyaClient) StopMQTT() {
|
||||
func (c *TuyaClient) StopMQTT() {
|
||||
if c.mqtt.client != nil {
|
||||
c.sendDisconnect()
|
||||
c.mqtt.client.Disconnect(1000)
|
||||
}
|
||||
}
|
||||
|
||||
func(c *TuyaClient) onConnect(client mqtt.Client) {
|
||||
func (c *TuyaClient) onConnect(client mqtt.Client) {
|
||||
if token := client.Subscribe(c.mqtt.subscribeTopic, 1, c.consume); token.Wait() && token.Error() != nil {
|
||||
c.mqtt.waiter.Done(token.Error())
|
||||
return
|
||||
@@ -122,7 +122,7 @@ func(c *TuyaClient) onConnect(client mqtt.Client) {
|
||||
c.mqtt.waiter.Done(nil)
|
||||
}
|
||||
|
||||
func(c *TuyaClient) consume(client mqtt.Client, msg mqtt.Message) {
|
||||
func (c *TuyaClient) consume(client mqtt.Client, msg mqtt.Message) {
|
||||
var rmqtt MqttMessage
|
||||
if err := json.Unmarshal(msg.Payload(), &rmqtt); err != nil {
|
||||
c.mqtt.onError(fmt.Errorf("unmarshal mqtt message fail: %s, payload: %s", err.Error(), string(msg.Payload())))
|
||||
@@ -143,7 +143,7 @@ func(c *TuyaClient) consume(client mqtt.Client, msg mqtt.Message) {
|
||||
}
|
||||
}
|
||||
|
||||
func(c *TuyaMQTT) onMqttAnswer(msg *MqttMessage) {
|
||||
func (c *TuyaMQTT) onMqttAnswer(msg *MqttMessage) {
|
||||
var answerFrame AnswerFrame
|
||||
if err := json.Unmarshal(msg.Data.Message, &answerFrame); err != nil {
|
||||
c.onError(fmt.Errorf("unmarshal mqtt answer frame fail: %s, session: %s, frame: %s",
|
||||
@@ -156,7 +156,7 @@ func(c *TuyaMQTT) onMqttAnswer(msg *MqttMessage) {
|
||||
c.onAnswer(answerFrame)
|
||||
}
|
||||
|
||||
func(c *TuyaMQTT) onMqttCandidate(msg *MqttMessage) {
|
||||
func (c *TuyaMQTT) onMqttCandidate(msg *MqttMessage) {
|
||||
var candidateFrame CandidateFrame
|
||||
if err := json.Unmarshal(msg.Data.Message, &candidateFrame); err != nil {
|
||||
c.onError(fmt.Errorf("unmarshal mqtt candidate frame fail: %s, session: %s, frame: %s",
|
||||
@@ -173,30 +173,30 @@ func(c *TuyaMQTT) onMqttCandidate(msg *MqttMessage) {
|
||||
c.onCandidate(candidateFrame)
|
||||
}
|
||||
|
||||
func(c *TuyaMQTT) onMqttDisconnect() {
|
||||
func (c *TuyaMQTT) onMqttDisconnect() {
|
||||
c.closed = true
|
||||
c.onDisconnect()
|
||||
}
|
||||
|
||||
func(c *TuyaMQTT) onAnswer(answer AnswerFrame) {
|
||||
func (c *TuyaMQTT) onAnswer(answer AnswerFrame) {
|
||||
if c.handleAnswer != nil {
|
||||
c.handleAnswer(answer)
|
||||
}
|
||||
}
|
||||
|
||||
func(c *TuyaMQTT) onCandidate(candidate CandidateFrame) {
|
||||
func (c *TuyaMQTT) onCandidate(candidate CandidateFrame) {
|
||||
if c.handleCandidate != nil {
|
||||
c.handleCandidate(candidate)
|
||||
}
|
||||
}
|
||||
|
||||
func(c *TuyaMQTT) onDisconnect() {
|
||||
func (c *TuyaMQTT) onDisconnect() {
|
||||
if c.handleDisconnect != nil {
|
||||
c.handleDisconnect()
|
||||
}
|
||||
}
|
||||
|
||||
func(c *TuyaMQTT) onError(err error) {
|
||||
func (c *TuyaMQTT) onError(err error) {
|
||||
if c.handleError != nil {
|
||||
c.handleError(err)
|
||||
}
|
||||
@@ -225,7 +225,7 @@ func (c *TuyaClient) sendResolution(resolution int) {
|
||||
})
|
||||
}
|
||||
|
||||
func(c *TuyaClient) sendDisconnect() {
|
||||
func (c *TuyaClient) sendDisconnect() {
|
||||
c.sendMqttMessage("disconnect", 302, "", DisconnectFrame{
|
||||
Mode: "webrtc",
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user