registerCall method
Registers a call so that its hold-status is observed.
When the call transitions to held it is added to heldCalls; when it
transitions away from held it is removed. This mirrors the
registerCall / hold-status-observer pattern in the Android SDK.
Idempotent: calling this multiple times for the same callId will only
wire up the state-change listener once. This is important because the
same Call object flows through both the invite handler (registered on
receive) and acceptCall (re-registered on accept); without this guard,
onCallStateChanged would be wrapped multiple times and
_onCallStateChanged would fire N times per state transition.
Implementation
void registerCall(Call call) {
final callId = call.callId;
if (_registeredCallIds.contains(callId)) {
GlobalLogger().d(
'CallManager.registerCall: callId=$callId already registered, skipping',
);
return;
}
_registeredCallIds.add(callId);
// Listen for state changes. When the call transitions to/from held we
// update the held-calls list.
// We attach a listener via the existing CallHandler callback chain by
// wrapping the existing callback.
final originalCallback = call.callHandler.onCallStateChanged;
call.callHandler.onCallStateChanged = (CallState state) {
originalCallback(state);
_onCallStateChanged(call, state);
};
}