Skip to content

Only send gateway_ingest_stream_closed on client disconnects #3485

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 3 additions & 1 deletion media/whip_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
allowedCodecs func(*webrtc.API)
interceptors func(*webrtc.API)
settings func(*webrtc.API)

ICEDisconnect = errors.New("ICE connection state closed")
)

// Generate a random ID for new resources
Expand Down Expand Up @@ -108,7 +110,7 @@
if connectionState == webrtc.ICEConnectionStateFailed {
mediaState.CloseError(errors.New("ICE connection state failed"))
} else if connectionState == webrtc.ICEConnectionStateClosed {
// Business logic when PeerConnection done
mediaState.CloseError(ICEDisconnect)

Check warning on line 113 in media/whip_server.go

View check run for this annotation

Codecov / codecov/patch

media/whip_server.go#L113

Added line #L113 was not covered by tests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the gateway itself closes the connection will we get to this state as well? We might wanna differentiate the cases where the user happily closes it or the server does it for some reason (like errors)

}
})

Expand Down
27 changes: 15 additions & 12 deletions server/ai_mediaserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -840,19 +840,22 @@
}()
err := whipConn.AwaitClose()
if err != nil {
sendErrorEvent(err)
if errors.Is(err, media.ICEDisconnect) {
monitor.SendQueueEventAsync("stream_trace", map[string]interface{}{
"type": "gateway_ingest_stream_closed",
"timestamp": time.Now().UnixMilli(),
"stream_id": streamID,
"pipeline_id": pipelineID,
"request_id": requestID,
"orchestrator_info": map[string]interface{}{
"address": "",
"url": "",
},
})
} else {
sendErrorEvent(err)
}

Check warning on line 857 in server/ai_mediaserver.go

View check run for this annotation

Codecov / codecov/patch

server/ai_mediaserver.go#L843-L857

Added lines #L843 - L857 were not covered by tests
}
monitor.SendQueueEventAsync("stream_trace", map[string]interface{}{
"type": "gateway_ingest_stream_closed",
"timestamp": time.Now().UnixMilli(),
"stream_id": streamID,
"pipeline_id": pipelineID,
"request_id": requestID,
"orchestrator_info": map[string]interface{}{
"address": "",
"url": "",
},
})
}()

if monitor.Enabled {
Expand Down
Loading