chore(mochi): device last Will message
This commit is contained in:
parent
0d48cb2d36
commit
a3ef451e5d
|
|
@ -225,6 +225,7 @@ func (h *MyHook) Provides(b byte) bool {
|
||||||
return bytes.Contains([]byte{
|
return bytes.Contains([]byte{
|
||||||
mqtt.OnSubscribed,
|
mqtt.OnSubscribed,
|
||||||
mqtt.OnDisconnect,
|
mqtt.OnDisconnect,
|
||||||
|
mqtt.OnClientExpired,
|
||||||
}, []byte{b})
|
}, []byte{b})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -233,6 +234,10 @@ func (h *MyHook) Init(config any) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *MyHook) OnClientExpired(cl *mqtt.Client) {
|
||||||
|
log.Printf("Client id %s expired", cl.ID)
|
||||||
|
}
|
||||||
|
|
||||||
func (h *MyHook) OnDisconnect(cl *mqtt.Client, err error, expire bool) {
|
func (h *MyHook) OnDisconnect(cl *mqtt.Client, err error, expire bool) {
|
||||||
var clUser string
|
var clUser string
|
||||||
if len(cl.Properties.Props.User) > 0 {
|
if len(cl.Properties.Props.User) > 0 {
|
||||||
|
|
@ -257,6 +262,10 @@ func (h *MyHook) OnSubscribed(cl *mqtt.Client, pk packets.Packet, reasonCodes []
|
||||||
}
|
}
|
||||||
|
|
||||||
if clUser != "" {
|
if clUser != "" {
|
||||||
|
cl.Properties.Will = mqtt.Will{
|
||||||
|
Qos: 1,
|
||||||
|
Payload: []byte(clUser),
|
||||||
|
}
|
||||||
log.Println("new device:", clUser)
|
log.Println("new device:", clUser)
|
||||||
err := server.Publish("oktopus/devices", []byte(clUser), false, 1)
|
err := server.Publish("oktopus/devices", []byte(clUser), false, 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user