mirror of
https://github.com/aler9/gortsplib
synced 2025-09-30 04:52:12 +08:00
examples: disconnect allow overriding publishers in server
This commit is contained in:
@@ -2,7 +2,6 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
|
||||||
"log"
|
"log"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
@@ -78,10 +77,10 @@ func (sh *serverHandler) OnAnnounce(ctx *gortsplib.ServerHandlerOnAnnounceCtx) (
|
|||||||
sh.mutex.Lock()
|
sh.mutex.Lock()
|
||||||
defer sh.mutex.Unlock()
|
defer sh.mutex.Unlock()
|
||||||
|
|
||||||
|
// disconnect existing publisher
|
||||||
if sh.stream != nil {
|
if sh.stream != nil {
|
||||||
return &base.Response{
|
sh.stream.Close()
|
||||||
StatusCode: base.StatusBadRequest,
|
sh.publisher.Close()
|
||||||
}, fmt.Errorf("someone is already publishing")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// create the stream and save the publisher
|
// create the stream and save the publisher
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"log"
|
"log"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
@@ -77,10 +76,10 @@ func (sh *serverHandler) OnAnnounce(ctx *gortsplib.ServerHandlerOnAnnounceCtx) (
|
|||||||
sh.mutex.Lock()
|
sh.mutex.Lock()
|
||||||
defer sh.mutex.Unlock()
|
defer sh.mutex.Unlock()
|
||||||
|
|
||||||
|
// disconnect existing publisher
|
||||||
if sh.stream != nil {
|
if sh.stream != nil {
|
||||||
return &base.Response{
|
sh.stream.Close()
|
||||||
StatusCode: base.StatusBadRequest,
|
sh.publisher.Close()
|
||||||
}, fmt.Errorf("someone is already publishing")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// create the stream and save the publisher
|
// create the stream and save the publisher
|
||||||
|
Reference in New Issue
Block a user