registerFunction method

RawNetworkerPipe registerFunction(
  1. int function, {
  2. bool canRunLocally = false,
  3. RpcNetworkerMode mode = RpcNetworkerMode.authority,
})
inherited

Implementation

RawNetworkerPipe registerFunction(
  int function, {
  bool canRunLocally = false,
  RpcNetworkerMode mode = RpcNetworkerMode.authority,
}) {
  if (_functions.containsKey(function)) return _functions[function]!.pipe;
  final pipe = RawNetworkerPipe();
  final rpcFunction = RpcFunction(
    canRunLocally: canRunLocally,
    mode: mode,
    pipe: pipe,
  );
  _functions[function] = rpcFunction;
  pipe.write.listen((packet) => sendMessage(
      RpcNetworkerPacket(
        function: function,
        data: packet.data,
        channel: isServer ? defaultReceiverChannel : packet.channel,
      ),
      isServer ? packet.channel : defaultReceiverChannel));
  return pipe;
}