openInteraction method
void
openInteraction()
Implementation
void openInteraction() {
if (socket == null || !socket!.connected) {
Logs.warning("Cannot open interaction - socket not connected",
tag: 'socket');
return;
}
// 🔥 FIX: Prevent multiple rapid calls (debounce)
final now = DateTime.now();
if (_lastOpenInteractionTime != null) {
final diff = now.difference(_lastOpenInteractionTime!);
if (diff.inSeconds < 3) {
Logs.warning(
"openInteraction called too soon (${diff.inSeconds}s ago), ignoring to prevent spam",
tag: 'socket');
return;
}
}
// 🔥 FIX: Prevent duplicate calls in same session
if (_openInteractionCalled) {
Logs.warning(
"openInteraction already called for this socket session, ignoring duplicate",
tag: 'socket');
return;
}
_lastOpenInteractionTime = now;
_openInteractionCalled = true;
Logs.info("Opening interaction - Socket ID: ${socket!.id}", tag: 'message');
Logs.debug(
"Payload: open-interaction => ${{
"participantId": user.participantId,
"offset": 0,
"eventType": 'open-interactions',
"appId": config.appId,
"fcm_token": user.fcmToken
}}",
tag: 'message');
socket!.emit('event', {
"participantId": user.participantId,
"offset": 0,
"eventType": 'open-interactions',
"appId": config.appId,
"fcm_token": user.fcmToken
});
}