add method

dynamic add(
  1. dynamic obj
)

Implementation

add(obj) {
  dynamic packet;
  if (obj is String) {
    packet = decodeString(obj);
    if (binaryEventValue == packet['type'] ||
        binaryAckValue == packet['type']) {
      reconstructor = BinaryReconstructor(packet);

      if (reconstructor.reconPack['attachments'] == 0) {
        emit('decoded', packet);
      }
    } else {
      emit('decoded', packet);
    }
  } else if ((obj != null && obj is ByteBuffer) ||
      obj is Uint8List ||
      obj is Map && obj['base64'] != null) {
    if (reconstructor == null) {
      throw UnsupportedError(
          'got binary data when not reconstructing a packet');
    } else {
      packet = reconstructor.takeBinaryData(obj);
      if (packet != null) {
        reconstructor = null;
        emit('decoded', packet);
      }
    }
  } else {
    throw UnsupportedError('Unknown type: ' + obj);
  }
}