handle unpublish track
This commit is contained in:
+12
-3
@@ -24,6 +24,7 @@ type DataTrack struct {
|
||||
lock sync.RWMutex
|
||||
once sync.Once
|
||||
msgChan chan livekit.DataMessage
|
||||
onClose func()
|
||||
|
||||
// map of target participantId -> DownDataChannel
|
||||
subscribers map[string]*DownDataChannel
|
||||
@@ -46,6 +47,13 @@ func NewDataTrack(trackId, participantId string, dc *webrtc.DataChannel) *DataTr
|
||||
t.msgChan <- dm
|
||||
})
|
||||
|
||||
dc.OnClose(func() {
|
||||
t.RemoveAllSubscribers()
|
||||
if t.onClose != nil {
|
||||
t.onClose()
|
||||
}
|
||||
})
|
||||
|
||||
return t
|
||||
}
|
||||
|
||||
@@ -72,6 +80,10 @@ func (t *DataTrack) IsMuted() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (t *DataTrack) OnClose(f func()) {
|
||||
t.onClose = f
|
||||
}
|
||||
|
||||
func (t *DataTrack) AddSubscriber(participant types.Participant) error {
|
||||
label := PackDataTrackLabel(t.participantId, t.ID(), t.dataChannel.Label())
|
||||
downChannel, err := participant.PeerConnection().CreateDataChannel(label, t.dataChannelOptions())
|
||||
@@ -116,9 +128,6 @@ func (t *DataTrack) RemoveAllSubscribers() {
|
||||
|
||||
func (t *DataTrack) forwardWorker() {
|
||||
defer Recover()
|
||||
defer func() {
|
||||
t.RemoveAllSubscribers()
|
||||
}()
|
||||
|
||||
for {
|
||||
msg := <-t.msgChan
|
||||
|
||||
Reference in New Issue
Block a user