setTransport method

void setTransport(
  1. Transport transport
)

Attaches handlers for the given transport.

Implementation

void setTransport(Transport transport) {
  var onError = this.onError;
  var onPacket = this.onPacket;
  flush(_) => this.flush();
  onClose(_) {
    this.onClose('transport close');
  }

  this.transport = transport;
  this.transport.once('error', onError);
  this.transport.on('packet', onPacket);
  this.transport.on('drain', flush);
  this.transport.once('close', onClose);
  // this function will manage packet events (also message callbacks)
  setupSendCallback();

  cleanupFn.add(() {
    transport.off('error', onError);
    transport.off('packet', onPacket);
    transport.off('drain', flush);
    transport.off('close', onClose);
  });
}