close method

  1. @VoltronMethod(funcClose)
void close(
  1. VoltronMap params,
  2. Promise promise
)

Implementation

@VoltronMethod(funcClose)
void close(VoltronMap params, final Promise promise) {
  var socketId = params.get<int>('id');
  if (socketId == null) {
    LogUtils.d(kWebSocketModuleName, "close: ERROR: no socket id specified");
    return;
  }
  var socketClient = mWebSocketConnections[socketId];
  if (socketClient == null || !socketClient.isConnected) {
    LogUtils.d(
        kWebSocketModuleName, "send: ERROR: specified socket not found, or not connected yet");
    return;
  }
  var code = params.get<int>('code') ?? 0;
  var reason = params.get<String>('reason') ?? '';
  socketClient.requestClose(code, reason);
}