Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions pkg/sfu/datachannel.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ type (
// The datachannels created will be negotiated on join to all peers that joins
// the SFU.
Datachannel struct {
Label string
middlewares []func(MessageProcessor) MessageProcessor
onMessage func(ctx context.Context, args ProcessArgs)
Label string
middlewares []func(MessageProcessor) MessageProcessor
onMessage func(ctx context.Context, args ProcessArgs)
onRemovePeer func(peer Peer)
}

ProcessArgs struct {
Expand Down Expand Up @@ -49,6 +50,10 @@ func (dc *Datachannel) OnMessage(fn func(ctx context.Context, args ProcessArgs))
dc.onMessage = fn
}

func (dc *Datachannel) OnRemovePeer(fn func(peer Peer)) {
dc.onRemovePeer = fn
}

func (p ProcessFunc) Process(ctx context.Context, args ProcessArgs) {
p(ctx, args)
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/sfu/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ func (s *Subscriber) AddDatachannel(peer Peer, dc *Datachannel) error {
DataChannel: ndc,
})
})
ndc.OnClose(func() {
if dc.onRemovePeer != nil {
dc.onRemovePeer(peer)
}
})

s.channels[dc.Label] = ndc

Expand Down