PlayifyRpc 1.4.2
See the version list below for details.
dotnet add package PlayifyRpc --version 1.4.2
NuGet\Install-Package PlayifyRpc -Version 1.4.2
<PackageReference Include="PlayifyRpc" Version="1.4.2" />
<PackageVersion Include="PlayifyRpc" Version="1.4.2" />
<PackageReference Include="PlayifyRpc" />
paket add PlayifyRpc --version 1.4.2
#r "nuget: PlayifyRpc, 1.4.2"
#:package PlayifyRpc@1.4.2
#addin nuget:?package=PlayifyRpc&version=1.4.2
#tool nuget:?package=PlayifyRpc&version=1.4.2
This library allows calling functions across different devices. It works for:
Web Interface
You can access http://127.0.0.1:4590/rpc to get to a simple web interface, where you can evaluate simple RPC calls
directly from the browser (and the browser devtools).
Additionally, you can call functions directly using http://127.0.0.1:4590/rpc/EXPRESSION.
For example, if you want to call Rpc.getRegistrations(), you can
access http://127.0.0.1:4590/rpc/Rpc.getRegistrations() and get the return value from the HTTP response.
Using http://127.0.0.1:4590/rpc/EXPRESSION/pretty you can get a prettified JSON back.
Using http://127.0.0.1:4590/rpc/EXPRESSION/void you don't get any response
back (HTTP Status Code 204).
Server
The RPC Server is only available for C#, clients are available in other languages as well. The server should run on a device that is reachable by all its clients. Clients can only communicate with each other if they are connected to the server, direct connections between clients are not supported.
Installation (Server)
Make sure dotnet 6 (or above) is installed.
Install the server files into an empty directory using one of the following commands.
Linux:
curl -sSL https://raw.githubusercontent.com/Playify/PlayifyRpc_CSharp/master/_run/get-rpc.sh | bash
Windows:
powershell "irm https://raw.githubusercontent.com/Playify/PlayifyRpc_CSharp/master/_run/get-rpc.ps1|iex"
Now you can use the rpc.sh or the rpc.bat script to run the RPC server.
Security
When the server sets the RPC_TOKEN environment variable to some arbitrary passphrase, only clients that also have
the RPC_TOKEN set to the same passphrase are accepted.
- Web clients need the
RPC_TOKENcookie. - NodeJs clients need to define the
RPC_TOKENenvironment variable. - C# clients either need to define the
RPC_TOKENenvironment variable or pass it intoRpc.Connect. - PlatformIO clients need to pass it into
Rpc::connect.
Nginx
If you want to use Nginx (e.g., for HTTPS or having multiple web pages on a single server), you should use the following location block:
location ~ ^/rpc {
proxy_http_version 1.1;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://127.0.0.1:4590;
}
PlayifyRpc needs access to /rpc.js, /rpc.js.map, /rpc (HTTP & WebSockets), and /rpc/*.
Client
Call Rpc.connect() to connect to a server. By default, it uses the RPC_URL and RPC_TOKEN environment variables,
but you can specify them as well.
Calling Functions
Functions can be called using Rpc.CallFunction or using the RpcFunction class.
When calling a function, you get a PendingCall, which acts like a Task<?>. It can be cast to a Task of any
supported data type.
A PendingCall has a Cancel() method to signal to the other end that the operation should be cancelled. This is only
useful if the executing end also handles the cancellation, otherwise, nothing will happen.
A PendingCall also has a SendMessage() method, which is used to send arbitrary messages to the executor. Using
the AddMessageListener() method, you can listen to messages that get sent by the executor. Alternatively, you can use
the PendingCall as an IAsyncEnumerable to consume the messages within an await foreach loop.
Registering Types
Using Rpc.RegisterType(), you can register a:
- Type (using
typeof(XXX)) to make a static class accessible to others. - Instance (using
new XXX). - Invoker, preferably
DictionaryInvoker, to register methods one by one.
You can also use the RpcProviderAttribute to register a static class.
Receiving Function Calls
A method on a registered type can have any number of parameters, even params is supported. The parameters should be
any of the supported types. The return type should be a Task, Task<?>, a supported type, or void.
When a function gets executed, you can use Rpc.GetContext() (before any await statement) to get access to
RPC-specific features, as they are not available through method parameters. The resulting FunctionCallContext can be
used similarly to the PendingCall.
It has a SendMessage() and AddMessageListener() method and can also be used as an IAsyncEnumerable. It also has
access to a CancellationToken that should be used whenever possible.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Framework | net48 is compatible. net481 was computed. |
-
.NETFramework 4.8
- AsyncFriendlyStackTrace (>= 1.7.0)
- PlayifyUtility (>= 1.3.0)
-
net6.0
- PlayifyUtility (>= 1.3.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.9.5 | 112 | 3/2/2026 |
| 1.9.4 | 100 | 3/2/2026 |
| 1.9.3 | 325 | 8/25/2025 |
| 1.9.2 | 199 | 7/9/2025 |
| 1.9.1 | 231 | 3/18/2025 |
| 1.9.0 | 172 | 1/28/2025 |
| 1.8.1 | 185 | 11/12/2024 |
| 1.8.0 | 179 | 11/12/2024 |
| 1.7.0 | 221 | 9/9/2024 |
| 1.6.0 | 206 | 9/6/2024 |
| 1.5.1 | 202 | 9/1/2024 |
| 1.5.0 | 200 | 9/1/2024 |
| 1.4.2 | 216 | 8/14/2024 |
| 1.4.1 | 170 | 7/24/2024 |
| 1.4.0 | 216 | 7/9/2024 |
| 1.3.3 | 199 | 6/27/2024 |
| 1.3.2 | 183 | 5/28/2024 |
| 1.3.1 | 209 | 5/22/2024 |
| 1.3.0 | 199 | 5/19/2024 |
| 1.2.0 | 278 | 1/14/2024 |