From cb97c3651b0e91ce6a3e7b41811b8b0d63f88f84 Mon Sep 17 00:00:00 2001 From: cloudwebrtc Date: Sat, 20 Mar 2021 09:40:47 +0800 Subject: [PATCH] Cancel register-refresh goroutine after un-registered. --- examples/register/main.go | 2 +- pkg/ua/register.go | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/register/main.go b/examples/register/main.go index 332bf03..b8d9862 100644 --- a/examples/register/main.go +++ b/examples/register/main.go @@ -53,7 +53,7 @@ func main() { Password: "100", Realm: "b2bua", }, - 30, + 1800, stack, ) diff --git a/pkg/ua/register.go b/pkg/ua/register.go index d4ad7e5..225ac5a 100644 --- a/pkg/ua/register.go +++ b/pkg/ua/register.go @@ -50,7 +50,7 @@ func (r *Register) SendRegister(expires uint32) error { contact := profile.Contact() - if r.request == nil { + if r.request == nil || expires == 0 { request, err := ua.buildRequest(sip.REGISTER, from, to, contact, recipient, nil) if err != nil { ua.Log().Errorf("Register: err = %v", err) @@ -138,6 +138,7 @@ func (r *Register) SendRegister(expires uint32) error { r.timer.Stop() r.timer = nil } + r.cancel() } ua.RegisterStateHandler(state) }