Update SendOffer to include token and fix mqtt close
This commit is contained in:
+15
-12
@@ -21,6 +21,7 @@ type TuyaMqttClient struct {
|
|||||||
publishTopic string
|
publishTopic string
|
||||||
subscribeTopic string
|
subscribeTopic string
|
||||||
auth string
|
auth string
|
||||||
|
iceServers []ICEServer
|
||||||
uid string
|
uid string
|
||||||
motoId string
|
motoId string
|
||||||
deviceId string
|
deviceId string
|
||||||
@@ -49,11 +50,12 @@ type MqttFrame struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type OfferFrame struct {
|
type OfferFrame struct {
|
||||||
Mode string `json:"mode"`
|
Mode string `json:"mode"`
|
||||||
Sdp string `json:"sdp"`
|
Sdp string `json:"sdp"`
|
||||||
StreamType int `json:"stream_type"`
|
StreamType int `json:"stream_type"`
|
||||||
Auth string `json:"auth"`
|
Auth string `json:"auth"`
|
||||||
DatachannelEnable bool `json:"datachannel_enable"`
|
DatachannelEnable bool `json:"datachannel_enable"`
|
||||||
|
Token []ICEServer `json:"token"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AnswerFrame struct {
|
type AnswerFrame struct {
|
||||||
@@ -115,6 +117,7 @@ func (c *TuyaMqttClient) Start(hubConfig *MQTTConfig, webrtcConfig *WebRTCConfig
|
|||||||
c.webrtcVersion = webrtcVersion
|
c.webrtcVersion = webrtcVersion
|
||||||
c.motoId = webrtcConfig.MotoID
|
c.motoId = webrtcConfig.MotoID
|
||||||
c.auth = webrtcConfig.Auth
|
c.auth = webrtcConfig.Auth
|
||||||
|
c.iceServers = webrtcConfig.P2PConfig.Ices
|
||||||
|
|
||||||
c.publishTopic = hubConfig.PublishTopic
|
c.publishTopic = hubConfig.PublishTopic
|
||||||
c.subscribeTopic = hubConfig.SubscribeTopic
|
c.subscribeTopic = hubConfig.SubscribeTopic
|
||||||
@@ -150,15 +153,16 @@ func (c *TuyaMqttClient) Start(hubConfig *MQTTConfig, webrtcConfig *WebRTCConfig
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *TuyaMqttClient) Stop() {
|
func (c *TuyaMqttClient) Stop() {
|
||||||
c.closed = true
|
|
||||||
c.waiter.Done(errors.New("mqtt: stopped"))
|
c.waiter.Done(errors.New("mqtt: stopped"))
|
||||||
c.wakeupWaiter.Done(errors.New("mqtt: stopped"))
|
c.wakeupWaiter.Done(errors.New("mqtt: stopped"))
|
||||||
c.speakerWaiter.Done(errors.New("mqtt: stopped"))
|
c.speakerWaiter.Done(errors.New("mqtt: stopped"))
|
||||||
|
|
||||||
if c.client != nil {
|
if c.client != nil {
|
||||||
_ = c.SendDisconnect()
|
_ = c.SendDisconnect()
|
||||||
c.client.Disconnect(1000)
|
c.client.Disconnect(100)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.closed = true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *TuyaMqttClient) WakeUp(localKey string) error {
|
func (c *TuyaMqttClient) WakeUp(localKey string) error {
|
||||||
@@ -217,6 +221,7 @@ func (c *TuyaMqttClient) SendOffer(sdp string, streamResolution string, streamTy
|
|||||||
StreamType: mqttStreamType,
|
StreamType: mqttStreamType,
|
||||||
Auth: c.auth,
|
Auth: c.auth,
|
||||||
DatachannelEnable: isHEVC,
|
DatachannelEnable: isHEVC,
|
||||||
|
Token: c.iceServers,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,18 +247,16 @@ func (c *TuyaMqttClient) SendResolution(resolution int) error {
|
|||||||
|
|
||||||
func (c *TuyaMqttClient) SendSpeaker(speaker int) error {
|
func (c *TuyaMqttClient) SendSpeaker(speaker int) error {
|
||||||
// Protocol 312 is used for speaker
|
// Protocol 312 is used for speaker
|
||||||
if err := c.sendMqttMessage("speaker", 312, "", SpeakerFrame{
|
return c.sendMqttMessage("speaker", 312, "", SpeakerFrame{
|
||||||
Mode: "webrtc",
|
Mode: "webrtc",
|
||||||
Value: speaker,
|
Value: speaker,
|
||||||
}); err != nil {
|
})
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// if err := c.speakerWaiter.Wait(); err != nil {
|
// if err := c.speakerWaiter.Wait(); err != nil {
|
||||||
// return fmt.Errorf("speaker wait failed: %w", err)
|
// return fmt.Errorf("speaker wait failed: %w", err)
|
||||||
// }
|
// }
|
||||||
|
|
||||||
return nil
|
// return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *TuyaMqttClient) SendDisconnect() error {
|
func (c *TuyaMqttClient) SendDisconnect() error {
|
||||||
|
|||||||
Reference in New Issue
Block a user