identify method

Future<void> identify(
  1. HatangUser user
)

Attaches an identity. Resolves once the gateway acknowledged it (or, on a merge, once the new session bootstrapped).

Implementation

Future<void> identify(HatangUser user) async {
  if (user.isEmpty) return;
  final socket = _socket;
  if (socket == null) throw const HatangException.closed();
  final reply = await socket.request(
    ClientFrame.identify(
      userId: user.userId,
      email: user.email,
      name: user.name,
      phone: user.phone,
      hash: user.hash,
      data: user.data,
    ),
    timeout: const Duration(seconds: 15),
  );
  if (reply is SessionFrame) return; // _onSession already restarted.
  _emit(
    _state.copyWith(
      visitorEmail: user.email ?? _state.visitorEmail,
      visitorName: user.name ?? _state.visitorName,
      needsEmail: false,
    ),
  );
  await _persist(_stored.copyWith(email: user.email, name: user.name));
}