registerFunction method

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

Implementation

RawNetworkerPipe registerFunction(
  int function, {
  String? name,
  bool canRunLocally = false,
  RpcNetworkerMode mode = RpcNetworkerMode.authority,
}) {
  if (_functionNames.contains((function, name))) {
    throw ArgumentError('Function $function already registered');
  }
  final pipe = RawNetworkerPipe();
  final rpcFunction = RpcFunction(
    canRunLocally: canRunLocally,
    mode: mode,
    pipe: pipe,
  );
  functions[function] = rpcFunction;
  if (name != null) {
    _functionNames.add((function, name));
  }
  pipe.write.listen((packet) => sendMessage(RpcNetworkerPacket(
        function: function,
        data: packet.data,
        channel: packet.channel,
      )));
  return pipe;
}