diff --git a/examples/server-tls/main.go b/examples/server-tls/main.go index 6dbcd403..890a2a77 100644 --- a/examples/server-tls/main.go +++ b/examples/server-tls/main.go @@ -2,7 +2,6 @@ package main import ( "crypto/tls" - "fmt" "log" "sync" @@ -78,10 +77,10 @@ func (sh *serverHandler) OnAnnounce(ctx *gortsplib.ServerHandlerOnAnnounceCtx) ( sh.mutex.Lock() defer sh.mutex.Unlock() + // disconnect existing publisher if sh.stream != nil { - return &base.Response{ - StatusCode: base.StatusBadRequest, - }, fmt.Errorf("someone is already publishing") + sh.stream.Close() + sh.publisher.Close() } // create the stream and save the publisher diff --git a/examples/server/main.go b/examples/server/main.go index 9f399bac..2c3cbea4 100644 --- a/examples/server/main.go +++ b/examples/server/main.go @@ -1,7 +1,6 @@ package main import ( - "fmt" "log" "sync" @@ -77,10 +76,10 @@ func (sh *serverHandler) OnAnnounce(ctx *gortsplib.ServerHandlerOnAnnounceCtx) ( sh.mutex.Lock() defer sh.mutex.Unlock() + // disconnect existing publisher if sh.stream != nil { - return &base.Response{ - StatusCode: base.StatusBadRequest, - }, fmt.Errorf("someone is already publishing") + sh.stream.Close() + sh.publisher.Close() } // create the stream and save the publisher