mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
unsubscribe listeners on shutdown.
This commit is contained in:
parent
f05889bd56
commit
5d66dcdb7b
@ -31,6 +31,7 @@ type WebRTCManagerCtx struct {
|
||||
logger zerolog.Logger
|
||||
videoTracks map[string]*webrtc.TrackLocalStaticSample
|
||||
audioTrack *webrtc.TrackLocalStaticSample
|
||||
unsubscribe []func()
|
||||
defaultVideoID string
|
||||
audioCodec codec.RTPCodec
|
||||
desktop types.DesktopManager
|
||||
@ -48,10 +49,15 @@ func (manager *WebRTCManagerCtx) Start() {
|
||||
manager.logger.Panic().Err(err).Msg("unable to create audio track")
|
||||
}
|
||||
|
||||
audio.AddListener(func(sample types.Sample) {
|
||||
listener := func(sample types.Sample) {
|
||||
if err := manager.audioTrack.WriteSample(media.Sample(sample)); err != nil && err != io.ErrClosedPipe {
|
||||
manager.logger.Warn().Err(err).Msg("audio pipeline failed to write")
|
||||
}
|
||||
}
|
||||
|
||||
audio.AddListener(listener)
|
||||
manager.unsubscribe = append(manager.unsubscribe, func(){
|
||||
audio.RemoveListener(listener)
|
||||
})
|
||||
|
||||
videoIDs := manager.capture.VideoIDs()
|
||||
@ -70,10 +76,15 @@ func (manager *WebRTCManagerCtx) Start() {
|
||||
manager.logger.Panic().Err(err).Str("videoID", videoID).Msg("unable to create video track")
|
||||
}
|
||||
|
||||
video.AddListener(func(sample types.Sample) {
|
||||
listener := func(sample types.Sample) {
|
||||
if err := track.WriteSample(media.Sample(sample)); err != nil && err != io.ErrClosedPipe {
|
||||
manager.logger.Warn().Err(err).Str("videoID", videoID).Msg("vide pipeline failed to write")
|
||||
}
|
||||
}
|
||||
|
||||
video.AddListener(listener)
|
||||
manager.unsubscribe = append(manager.unsubscribe, func(){
|
||||
video.RemoveListener(listener)
|
||||
})
|
||||
|
||||
manager.videoTracks[videoID] = track
|
||||
@ -90,6 +101,11 @@ func (manager *WebRTCManagerCtx) Start() {
|
||||
|
||||
func (manager *WebRTCManagerCtx) Shutdown() error {
|
||||
manager.logger.Info().Msgf("webrtc shutting down")
|
||||
|
||||
for _, unsubscribe := range manager.unsubscribe {
|
||||
unsubscribe()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user