Clear stale unanswered calls before new invite

This commit is contained in:
richjohnrambo
2026-09-04 18:16:26 +08:00
parent 4ad6ca00b4
commit b4d3fbe359
4 changed files with 53 additions and 2 deletions
+10
View File
@@ -95,6 +95,8 @@ type videoCall struct {
callID string
// Product-level call type: audio or video.
callType string
// Time when the invite was accepted by the server.
startedAt time.Time
// Time when the call was accepted.
acceptedAt time.Time
}
@@ -168,6 +170,13 @@ func (call *videoCall) matchesPayload(payload any) bool {
return payloadCallID == "" || payloadCallID == call.callID
}
func (call *videoCall) isStaleUnanswered(now time.Time, timeoutSeconds int) bool {
if call == nil || len(call.parties) != 1 || call.startedAt.IsZero() || timeoutSeconds <= 0 {
return false
}
return now.Sub(call.startedAt) > time.Duration(timeoutSeconds)*time.Second
}
func (t *Topic) auditCallCreate(call *videoCall, caller types.Uid) {
if store.Calls == nil || call == nil || call.callID == "" || caller.IsZero() {
return
@@ -350,6 +359,7 @@ func (t *Topic) handleCallInvite(msg *ClientComMessage, asUid types.Uid) {
contentMime: msg.Pub.Head["mime"],
callID: callContentString(msg.Pub.Content, "callId"),
callType: callContentString(msg.Pub.Content, "callType"),
startedAt: types.TimeNow(),
}
t.currentCall.parties[msg.sess.sid] = callPartyData{
uid: asUid,