sendAndWaitMessage function

Future<SocketData?> sendAndWaitMessage(
  1. WebSocketListener socketListener,
  2. SocketData socketData, {
  3. String? waitingID,
  4. String? waitingType,
  5. bool anyID = false,
  6. bool anyType = false,
  7. Function? onError,
  8. Function? onTimeout,
})

Send and wait message with defined web socket

Implementation

Future<SocketData?> sendAndWaitMessage(
    WebSocketListener socketListener, SocketData socketData,
    {String? waitingID,
    String? waitingType,
    bool anyID = false,
    bool anyType = false,
    Function? onError,
    Function? onTimeout}) async {
  try {
    // print("SEND AND WAIT MESSAGE IN : ${socketData.fullData}");
    sendMessage(socketListener.client, socketData, onError: onError);
  } on Exception {
    //TODO: ADD ERROR
    return null;
  }
  return waitMessage(
    socketListener.socketBroadcast,
    id: waitingID != null
        ? waitingID
        : anyID
            ? null
            : socketData.messageId,
    type: waitingType != null
        ? waitingType
        : anyType
            ? null
            : socketData.type,
  );
}