subscribeModuleChannel<T> method

Future<bool?> subscribeModuleChannel<T>(
  1. String channelName,
  2. T dataType,
  3. DataReceiverCallback<T> callback
)

Implementation

Future<bool?> subscribeModuleChannel<T>(String channelName, T dataType, DataReceiverCallback<T> callback) async
{
  RemoteFunction<bool> function = mapMiddlewareFunction<bool>("add_loose_direct_subscription", false, [LooseDirectChannelSubscription()]);

  LooseDirectChannelSubscription subscription = LooseDirectChannelSubscription();
  subscription.subscribedModule = mappedModuleId;
  subscription.subscribedChannel = channelName;
  subscription.subscriberRuntime = Runtime.RUNTIME_DART;
  subscription.subscriberEntity = entityName;

  String id = _makeLooseDirectSubscriptionId(subscription);
  Mutator<T> mutator = TypeMapping().getMutator(dataType);
  DataReceiver<T> receiver = DataReceiver<T>(mutator, callback);

  _looseDirectSubscriptionCallbacks[id] = receiver;

  return function.executeWithParameters([subscription]);
}