Ends current call in response to a client hangup request (msg).
(from string, msg *ClientComMessage, callDidTimeout bool)
| 375 | |
| 376 | // Ends current call in response to a client hangup request (msg). |
| 377 | func (t *Topic) maybeEndCallInProgress(from string, msg *ClientComMessage, callDidTimeout bool) { |
| 378 | if t.currentCall == nil { |
| 379 | return |
| 380 | } |
| 381 | t.callEstablishmentTimer.Stop() |
| 382 | originatorUid, _ := t.getCallOriginator() |
| 383 | var replaceWith string |
| 384 | var callDuration int64 |
| 385 | if from != "" && len(t.currentCall.parties) == 2 { |
| 386 | // This is a call in progress. |
| 387 | replaceWith = constCallMsgFinished |
| 388 | callDuration = time.Since(t.currentCall.acceptedAt).Milliseconds() |
| 389 | } else { |
| 390 | if from != "" { |
| 391 | // User originated hang-up. |
| 392 | if from == originatorUid.UserId() { |
| 393 | // Originator/caller requested event. |
| 394 | replaceWith = constCallMsgMissed |
| 395 | } else { |
| 396 | // Callee requested event. |
| 397 | replaceWith = constCallMsgDeclined |
| 398 | } |
| 399 | } else { |
| 400 | // Server initiated disconnect. |
| 401 | // Call hasn't been established. Just drop it. |
| 402 | if callDidTimeout { |
| 403 | replaceWith = constCallMsgMissed |
| 404 | } else { |
| 405 | replaceWith = constCallMsgDisconnected |
| 406 | } |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | // Send a message indicating the call has ended. |
| 411 | msgCopy := *msg |
| 412 | msgCopy.AsUser = originatorUid.UserId() |
| 413 | var origHead map[string]any |
| 414 | if msgCopy.Pub != nil { |
| 415 | origHead = msgCopy.Pub.Head |
| 416 | } // else fetch the original message from store and use its head. |
| 417 | head := t.currentCall.messageHead(origHead, replaceWith, int(callDuration)) |
| 418 | if err := t.saveAndBroadcastMessage(&msgCopy, originatorUid, false, nil, head, t.currentCall.content); err != nil { |
| 419 | logs.Err.Printf("topic[%s]: failed to write finalizing message for call seq id %d - '%s'", t.name, t.currentCall.seq, err) |
| 420 | } |
| 421 | |
| 422 | // Send {info} hangup event to the subscribed sessions. |
| 423 | t.broadcastToSessions(t.currentCall.infoMessage(constCallEventHangUp)) |
| 424 | |
| 425 | // Let all other sessions know the call is over. |
| 426 | for tgt := range t.perUser { |
| 427 | t.infoCallSubsOffline(from, tgt, constCallEventHangUp, t.currentCall.seq, nil, "", true) |
| 428 | } |
| 429 | t.currentCall = nil |
| 430 | } |
| 431 | |
| 432 | // Server initiated call termination. |
| 433 | func (t *Topic) terminateCallInProgress(callDidTimeout bool) { |
no test coverage detected