onClose method

void onClose(
  1. dynamic reason, [
  2. dynamic description
])

Called upon transport considered closed. Possible reasons: ping timeout, client error, parse error, transport error, server close, transport close

Implementation

void onClose(reason, [description]) {
  if ('closed' != readyState) {
    readyState = 'closed';
    pingTimeoutTimer?.cancel();
    checkIntervalTimer?.cancel();
    checkIntervalTimer = null;
    upgradeTimeoutTimer?.cancel();

    // clean writeBuffer in next tick, so developers can still
    // grab the writeBuffer on 'close' event
    scheduleMicrotask(() {
      writeBuffer = [];
    });
    packetsFn = [];
    sentCallbackFn = [];
    clearTransport();
    emit('close', [reason, description]);
  }
}