on method

void on(
  1. String methodName,
  2. MethodInvocationFunc newMethod
)

Registers a handler that will be invoked when the hub method with the specified method name is invoked.

Implementation

void on(String methodName, MethodInvocationFunc newMethod) {
  if (methodName.isEmpty) {
    return;
  }

  methodName = methodName.toLowerCase();
  if (_methods[methodName] == null) {
    _methods[methodName] = [];
  }

  // Preventing adding the same handler multiple times.
  if (_methods[methodName]!.contains(newMethod)) {
    return;
  }

  _methods[methodName]!.add(newMethod);
}