cmd method

void cmd(
  1. String cmdStr,
  2. {IOWebSocketChannel channelK,
  3. Map params = const {},
  4. int id = 1,
  5. MessageCallback callback}
)

Implementation

void cmd(
  String cmdStr, {
  IOWebSocketChannel channelK,
  Map params = const {},
  int id = 1,
  MessageCallback callback,
}) {
  try {
    channel.sink.add(
      json.encode({
        'cmd': cmdStr,
        'params': params,
        'id': id++,
      }),
    );
    if (!isListening) {
      isListening = true;
      channel.stream.listen(callback ?? onMessage);
    }
  } catch (e) {
    if (channel == null)
      throw 'Initalize ZeroNet Api First before calling any method';
  }
}