Merge branch 'danxuliu-fix-subscribers-not-closed-when-publisher-is-closed-in-janus-1.x'

This commit is contained in:
Joachim Bauch 2025-05-06 15:08:36 +02:00
commit 8ceab4f8ce
No known key found for this signature in database
GPG key ID: 77C1D22D53E15F02

View file

@ -47,6 +47,23 @@ func (p *mcuJanusSubscriber) handleEvent(event *janus.EventMsg) {
case "destroyed":
log.Printf("Subscriber %d: associated room has been destroyed, closing", p.handleId)
go p.Close(ctx)
case "updated":
streams, ok := getPluginValue(event.Plugindata, pluginVideoRoom, "streams").([]interface{})
if !ok || len(streams) == 0 {
// The streams list will be empty if no stream was changed.
return
}
for _, stream := range streams {
if stream, ok := stream.(map[string]interface{}); ok {
if (stream["type"] == "audio" || stream["type"] == "video") && stream["active"] != false {
return
}
}
}
log.Printf("Subscriber %d: received updated event with no active media streams, closing", p.handleId)
go p.Close(ctx)
case "event":
// Handle renegotiations, but ignore other events like selected
// substream / temporal layer.