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.

methodName: The name of the hub method to define. newMethod: The handler that will be raised when the hub method is invoked.

Implementation

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

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

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

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