更新device时关闭定时器

This commit is contained in:
dexter
2021-10-07 08:53:44 +08:00
parent 65c1864d5b
commit 86f7effd47
2 changed files with 6 additions and 1 deletions

View File

@@ -51,6 +51,7 @@ type Device struct {
CallID string
Timeout time.Time
}
qTimer *time.Timer
}
func (d *Device) addChannel(channel *Channel) {
@@ -190,7 +191,7 @@ func (d *Device) Query() {
}
if response.Code != 200 {
fmt.Printf("device %s send Catalog : %d\n", d.ID, response.Code)
time.AfterFunc(time.Second*5, d.Query)
d.qTimer = time.AfterFunc(time.Second*5, d.Query)
} else {
d.Subscribe()
}

View File

@@ -352,11 +352,15 @@ func listenMedia() {
func onRegister(s *transaction.Core, config *transaction.Config, d *Device) {
if old, ok := Devices.Load(d.ID); ok {
oldD := old.(*Device)
if oldD.qTimer != nil {
oldD.qTimer.Stop()
}
d.RegisterTime = oldD.RegisterTime
d.channelMap = oldD.channelMap
d.Channels = oldD.Channels
d.UpdateChannelsDevice()
d.Status = oldD.Status
go d.Query()
}
Devices.Store(d.ID, d)
}