RustPlusApi.Fcm 1.2.0

dotnet add package RustPlusApi.Fcm --version 1.2.0
NuGet\Install-Package RustPlusApi.Fcm -Version 1.2.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="RustPlusApi.Fcm" Version="1.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add RustPlusApi.Fcm --version 1.2.0
#r "nuget: RustPlusApi.Fcm, 1.2.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install RustPlusApi.Fcm as a Cake Addin
#addin nuget:?package=RustPlusApi.Fcm&version=1.2.0

// Install RustPlusApi.Fcm as a Cake Tool
#tool nuget:?package=RustPlusApi.Fcm&version=1.2.0

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.2.0 74 6/4/2024