RustPlusApi.Fcm
1.2.1
dotnet add package RustPlusApi.Fcm --version 1.2.1
NuGet\Install-Package RustPlusApi.Fcm -Version 1.2.1
<PackageReference Include="RustPlusApi.Fcm" Version="1.2.1" />
paket add RustPlusApi.Fcm --version 1.2.1
#r "nuget: RustPlusApi.Fcm, 1.2.1"
// Install RustPlusApi.Fcm as a Cake Addin #addin nuget:?package=RustPlusApi.Fcm&version=1.2.1 // Install RustPlusApi.Fcm as a Cake Tool #tool nuget:?package=RustPlusApi.Fcm&version=1.2.1
RustPlusApi.Fcm
This is a C# client for the Rust+ websocket. It allows you to receive notification via FCM.
Prerequisites
- .NET 8 or later
Sumary
The library provides two classes to interact with the Rust+ API: RustPlusFcmListenerClient
and RustPlusFcmListener
.
RustPlusFcmListenerClient
is the base client to interact with FCM.RustPlusFcmListener
is a new implementation that own more events.
Since RustPlusFcmListener
inherit from RustPlusFcmListenerClient
, you can use both classes to interact with FCM. The RustPlus
class is recommended for new projects, as it provides more events.
RustPlusFcmListenerClient
First, instantiate the RustPlusFcmListenerClient
class with the necessary parameters:
var rustPlusFcmListenerClient = new RustPlusFcmListenerClient(credentials, notificationIds);
Parameters:
credentials
: The FCM credentials*.notificationIds
: The notification ids to mark as read.
* See the Credentials section for more information.
Then, connect to the FCM server:
await rustPlusFcmListenerClient.ConnectAsync();
To listen to the FCM notifications, you can use the OnNotificationReceived
event:
rustPlusFcmListenerClient.OnNotificationReceived += (sender, e) =>
{
Console.WriteLine($"Notification received: {e.Notification}");
};
Don't forget to disconnect from the FCM server when you're done:
rustPlusFcmListenerClient.Disconnect();
RustPlusFcmListener
The RustPlusFcmListener
inherits from RustPlusFcmListenerClient
and provides more events.
Such as RustPlusFcmListenerClient
you need to instantiate the RustPlusFcmListener
class with the necessary parameters:
var rustPlusFcmListener = new RustPlusFcmListener(credentials, notificationIds);
Then you can connect to the FCM server:
await rustPlusFcmListener.ConnectAsync();
You can subscribe to events to handle specific actions:
rustPlusFcmListener.OnServerPairing += (sender, e) =>
{
Console.WriteLine($"Server pairing: {e.ServerPairing}");
};
rustPlusFcmListener.OnEntityParing += (sender, e) =>
{
Console.WriteLine($"Entity pairing: {e.EntityPairing}");
};
rustPlusFcmListener.OnAlarmTriggered += (sender, e) =>
{
Console.WriteLine($"Alarm triggered: {e.Alarm}");
};
Don't forget to disconnect from the FCM server when you're done:
rustPlusFcmListener.Disconnect();
Credentials
Currenlty, there is not simple way to get the FCM credentials & keys using .NET. I've planned to implement a solution but it's not ready yet.
To use this library, you need to get the FCM credentials manually. To do so I recommand you to use this project to get the credentials.
I'm sorry for the inconvenience but since the API is not fully complete it's the easiest way.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. 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. |
-
net8.0
- BouncyCastle.Cryptography (>= 2.4.0)
- Newtonsoft.Json (>= 13.0.3)
- protobuf-net (>= 3.2.30)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.