Skip to content

Commit e73c752

Browse files
committed
Add sendfunction to rpc
1 parent e0bff15 commit e73c752

File tree

1 file changed

+15
-1
lines changed
  • packages/networker/networker/lib/src/plugin

1 file changed

+15
-1
lines changed

packages/networker/networker/lib/src/plugin/rpc.dart

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ final class RpcNetworkerPacket {
2626
this.channel = kAnyChannel,
2727
});
2828

29+
RpcNetworkerPacket.named({
30+
required RpcFunctionName name,
31+
required this.data,
32+
this.channel = kAnyChannel,
33+
}) : function = name.index;
34+
2935
factory RpcNetworkerPacket.fromBytes(RpcConfig config, Uint8List bytes) {
3036
var function = bytes[0];
3137
int currentOffset = 1;
@@ -70,7 +76,7 @@ final class RpcFunction {
7076
});
7177

7278
bool shouldRun(Channel sender, Channel receiver, {bool forceLocal = false}) {
73-
if (!forceLocal && !canRunLocally && sender != kAnyChannel) return false;
79+
if (!forceLocal && !canRunLocally && sender == kAnyChannel) return false;
7480
return switch (mode) {
7581
RpcNetworkerMode.authority => sender == kAuthorityChannel,
7682
RpcNetworkerMode.selected => true,
@@ -115,6 +121,10 @@ final class RpcNetworkerPipe
115121
return pipe;
116122
}
117123

124+
void sendFunction(int function, Uint8List data,
125+
{Channel channel = kAnyChannel, bool forceLocal = false}) =>
126+
getFunction(function)?.sendMessage(data, channel);
127+
118128
RawNetworkerPipe? getFunction(int function) => functions[function]?.pipe;
119129

120130
bool unregisterFunction(int function) => functions.remove(function) != null;
@@ -166,6 +176,10 @@ base mixin NamedRpcNetworkerPipe<T extends RpcFunctionName>
166176
bool isValidNamedCall(T name, Channel sender,
167177
[Channel receiver = kAnyChannel]) =>
168178
isValidCall(name.index, sender, receiver);
179+
180+
void sendNamedFunction(T name, Uint8List data,
181+
{Channel channel = kAnyChannel, bool forceLocal = false}) =>
182+
getNamedFunction(name)?.sendMessage(data, channel);
169183
}
170184

171185
final class RpcClientNetworkerPipe extends RpcNetworkerPipe {

0 commit comments

Comments
 (0)