send method
Implementation
Future<WsEvent?> send(WsRequest request) async {
if (appState.currentUser == null) {
//NOTE: some test cases execute async socket data
logger.e('sendCommand: connection is requred');
throw ConnectionRequiredError();
}
try {
await ConnectionManager.readyToExecuteWSRequest();
} catch (e) {
_ackTimers.remove(request.requestId)?.cancel();
rethrow;
}
try {
webSocket?.send(request.encoded);
} catch (e) {
_ackTimers.remove(request.requestId)?.cancel();
rethrow;
}
final reqId = request.requestId;
if (request.isAckRequired && reqId != null) {
final timer = Timer(Duration(seconds: sdk.options.websocketTimeout), () {
logger.e('sendCommand: did not receive ack in time');
throw AckTimeoutError();
});
_ackTimers[reqId] = timer;
final completer = Completer<WsEvent>();
_completers2[reqId] = completer;
return completer.future;
} else {
return null;
}
}