fix: harden group lifecycle and registration writes

This commit is contained in:
richjohnrambo
2026-09-14 12:04:10 +08:00
parent 990526647c
commit 4854e090ef
9 changed files with 182 additions and 28 deletions
+23 -4
View File
@@ -298,6 +298,24 @@ func callContentString(content any, key string) string {
return callPayloadString(content, key)
}
func normalizeCallEvent(event string) string {
switch strings.ToLower(strings.TrimSpace(event)) {
case "hangup", "hang_up", "hang-up", "finish", "finished", "end", "ended", "disconnect", "disconnected":
return constCallEventHangUp
default:
return strings.TrimSpace(event)
}
}
func isDetachedCallEvent(event string) bool {
switch normalizeCallEvent(event) {
case constCallEventRinging, constCallEventHangUp, constCallEventAccept:
return true
default:
return false
}
}
func (call *videoCall) matchesPayload(payload any) bool {
payloadCallID := callPayloadString(payload, "callId")
return payloadCallID == "" || payloadCallID == call.callID
@@ -536,7 +554,8 @@ func (t *Topic) handleCallEvent(msg *ClientComMessage) {
return
}
switch call.Event {
event := normalizeCallEvent(call.Event)
switch event {
case constCallEventRinging, constCallEventAccept:
// Invariants:
// 1. Call has been initiated but not been established yet.
@@ -554,10 +573,10 @@ func (t *Topic) handleCallEvent(msg *ClientComMessage) {
return
}
// Prepare a {info} message to forward to the call originator.
forwardMsg := t.currentCall.infoMessage(call.Event)
forwardMsg := t.currentCall.infoMessage(event)
forwardMsg.Info.From = msg.AsUser
forwardMsg.Info.Topic = t.original(originatorUid)
if call.Event == constCallEventAccept {
if event == constCallEventAccept {
// The call has been accepted.
// Send a replacement {data} message to the topic.
msgCopy := *msg
@@ -582,7 +601,7 @@ func (t *Topic) handleCallEvent(msg *ClientComMessage) {
t.auditCallAccept(t.currentCall, t.currentCall.acceptedAt)
// Notify other clients that the call has been accepted.
t.infoCallSubsOffline(msg.AsUser, asUid, call.Event, t.currentCall.seq, call.Payload, msg.sess.sid, false)
t.infoCallSubsOffline(msg.AsUser, asUid, event, t.currentCall.seq, call.Payload, msg.sess.sid, false)
t.callEstablishmentTimer.Stop()
}
originator.queueOut(forwardMsg)