onMessage method

  1. @override
void onMessage(
  1. Uint8List data, [
  2. Channel channel = kAnyChannel
])
override

Implementation

@override
void onMessage(Uint8List data, [Channel channel = kAnyChannel]) {
  super.onMessage(data);
  final packet = decode(data);
  final receiver = packet.channel.abs();
  final newPacket = packet.withChannel(channel);
  if (validate &&
      !isValidCall(newPacket.function, channel, receiver)) {
    return;
  }
  if (!(filter?.call(newPacket, receiver) ?? true)) {
    return;
  }
  if (receiver == kAuthorityChannel || receiver == kAnyChannel) {
    runFunction(newPacket);
  }
  if (receiver != kAuthorityChannel) {
    sendMessage(newPacket, receiver == kAnyChannel ? -channel : receiver);
  }
}