use context to detect when channel is properly closed
This commit is contained in:
@@ -99,7 +99,6 @@ func (w *TrackWriter) writeOgg() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert seconds to Milliseconds, Sleep doesn't accept floats
|
|
||||||
time.Sleep(sampleDuration)
|
time.Sleep(sampleDuration)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,8 +60,8 @@ type SimpleForwarder struct {
|
|||||||
onClose func(forwarder Forwarder)
|
onClose func(forwarder Forwarder)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSimpleForwarder(rtcpCh chan []rtcp.Packet, track *sfu.DownTrack, pb PacketBuffer) *SimpleForwarder {
|
func NewSimpleForwarder(ctx context.Context, rtcpCh chan []rtcp.Packet, track *sfu.DownTrack, pb PacketBuffer) *SimpleForwarder {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(ctx)
|
||||||
f := &SimpleForwarder{
|
f := &SimpleForwarder{
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
cancel: cancel,
|
cancel: cancel,
|
||||||
|
|||||||
+4
-1
@@ -1,6 +1,7 @@
|
|||||||
package rtc
|
package rtc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"io"
|
"io"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@@ -22,6 +23,7 @@ var (
|
|||||||
|
|
||||||
// Track represents a remoteTrack that needs to be forwarded
|
// Track represents a remoteTrack that needs to be forwarded
|
||||||
type Track struct {
|
type Track struct {
|
||||||
|
ctx context.Context
|
||||||
id string
|
id string
|
||||||
participantId string
|
participantId string
|
||||||
// source remoteTrack
|
// source remoteTrack
|
||||||
@@ -37,6 +39,7 @@ type Track struct {
|
|||||||
|
|
||||||
func NewTrack(pId string, rtcpCh chan []rtcp.Packet, track *webrtc.TrackRemote, receiver *Receiver) *Track {
|
func NewTrack(pId string, rtcpCh chan []rtcp.Packet, track *webrtc.TrackRemote, receiver *Receiver) *Track {
|
||||||
t := &Track{
|
t := &Track{
|
||||||
|
ctx: context.Background(),
|
||||||
id: utils.NewGuid(utils.TrackPrefix),
|
id: utils.NewGuid(utils.TrackPrefix),
|
||||||
participantId: pId,
|
participantId: pId,
|
||||||
remoteTrack: track,
|
remoteTrack: track,
|
||||||
@@ -96,7 +99,7 @@ func (t *Track) AddSubscriber(participant *Participant) error {
|
|||||||
//})
|
//})
|
||||||
participant.addDownTrack(t.StreamID(), outTrack)
|
participant.addDownTrack(t.StreamID(), outTrack)
|
||||||
|
|
||||||
forwarder := NewSimpleForwarder(t.rtcpCh, outTrack, t.receiver)
|
forwarder := NewSimpleForwarder(t.ctx, t.rtcpCh, outTrack, t.receiver)
|
||||||
forwarder.OnClose(func(f Forwarder) {
|
forwarder.OnClose(func(f Forwarder) {
|
||||||
t.lock.Lock()
|
t.lock.Lock()
|
||||||
delete(t.forwarders, participant.ID())
|
delete(t.forwarders, participant.ID())
|
||||||
|
|||||||
Reference in New Issue
Block a user