From be93b242a577cdaaf9187bd0930e85a388da43fc Mon Sep 17 00:00:00 2001 From: aler9 <46489434+aler9@users.noreply.github.com> Date: Sun, 20 Nov 2022 22:16:16 +0100 Subject: [PATCH] examples: disconnect allow overriding publishers in server --- examples/server-tls/main.go | 7 +++---- examples/server/main.go | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) 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