-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
184 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,40 @@ | ||
using RustPlusApi.Fcm; | ||
using Newtonsoft.Json; | ||
|
||
using RustPlusApi.Fcm; | ||
using RustPlusApi.Fcm.Data; | ||
|
||
var credentials = new Credentials | ||
{ | ||
Keys = new Keys | ||
{ | ||
PrivateKey = "", | ||
PublicKey = "", | ||
AuthSecret = "", | ||
PrivateKey = "PNo-juMIoy8nh45ap7CcOjmvCcXG71zxo1Kf6sG75yI", | ||
PublicKey = "BMLRwfGJ3poc2ih6eIQpf-7xwkP9z98K8vh-bWzxypDERTUIyAqpulccHR6WBVP8jgoecNtYePTYvSc-sHGhWcY", | ||
AuthSecret = "3_stBv0R105hCQJgJ_Oqag", | ||
}, | ||
Fcm = new FcmCredentials | ||
{ | ||
Token = "", | ||
PushSet = "", | ||
Token = "de0gThSZW5A:APA91bEpz3S-tIVNV4uoKKNc_UCA_8tcg5lxEWiXkx-zFb0-H6FG5ltQvkGYzfxcfm3GxNihFgfRvH7Ps0_IdvRpOvjVREsm8uJwhkt8ztaoOZ886osG-bvGGVfV2jt1rPDG1_22NoMm", | ||
PushSet = "dEhc-sLR9LY", | ||
}, | ||
Gcm = new GcmCredentials | ||
{ | ||
Token = "", | ||
AndroidId = 0, | ||
SecurityToken = 0, | ||
AppId = "", | ||
Token = "ctMfS0V2BB0:APA91bG5LKmV_pe27v7Drm4OBYMkZS8eItKHUX-wG5eUw1WmKFTSkwYr4hw43AQmP7oBwHzeKbMRDEmaml0lh2CBvh0s3pXxrDSng6au3t-iE1FkEhpBOwaDh74Hk2z6Y8GcFTcaPsA2", | ||
AndroidId = 5198350057269518718, | ||
SecurityToken = 726893779159876265, | ||
AppId = "wp:receiver.push.com#46616054-1728-4be7-9dc6-740f3e76d9f4", | ||
} | ||
}; | ||
|
||
var listener = new FcmListener(credentials, []); | ||
var listener = new FcmListener(credentials); | ||
|
||
listener.NotificationReceived += (_, message) => | ||
{ | ||
Console.WriteLine(message); | ||
Console.WriteLine($"{DateTime.Now}:\n{message}"); | ||
}; | ||
|
||
listener.ErrorOccurred += (_, error) => | ||
{ | ||
Console.WriteLine($"[ERROR]: {error}"); | ||
}; | ||
|
||
await listener.ConnectAsync(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
using RustPlusApi.Fcm; | ||
using Newtonsoft.Json; | ||
|
||
var senderId = "976529667804"; | ||
// NOT WORKING, NEEDS TO BE FIXED | ||
return; | ||
|
||
/* var senderId = "976529667804"; | ||
var credentials = await FcmRegister.RegisterAsync(senderId); | ||
Console.WriteLine(JsonConvert.SerializeObject(credentials, Formatting.Indented)); | ||
Console.WriteLine(JsonConvert.SerializeObject(credentials, Formatting.Indented));*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# RustPlusApi.Fcm | ||
|
||
This is a C# client for the Rust+ websocket. It allows you to receive notification via FCM. | ||
|
||
## Prerequisites | ||
|
||
- **.NET 8** or later | ||
|
||
## Usage | ||
|
||
First, instantiate the `FcmListener` class with the necessary parameters: | ||
|
||
```csharp | ||
var fcmListener = new FcmListener(credentials, persistentIds); | ||
``` | ||
|
||
Parameters: | ||
|
||
- `credentials`: The `Credentials`* object containing the FCM & GCM credentials + the keys to decrypt the notification. | ||
- `persistentIds`: A list of notification IDs that should be ignored. Default is null. | ||
|
||
\* Go to the next section to see how to create a `Credentials` object. | ||
|
||
Then, connect to the FCM socket: | ||
|
||
```csharp | ||
await fcmListener.ConnectAsync(); | ||
``` | ||
|
||
You can subscribe to events to handle connection, disconnection, errors, and received messages: | ||
|
||
```csharp | ||
fcmListener.Connecting += (sender, e) => { /* handle connecting event */ }; | ||
fcmListener.Connected += (sender, e) => { /* handle connected event */ }; | ||
fcmListener.Disconnected += (sender, e) => { /* handle disconnected event */ }; | ||
fcmListener.ErrorOccurred += (sender, e) => { /* handle error event */ }; | ||
fcmListener.MessageReceived += (sender, e) => { /* handle received message event */ }; | ||
``` | ||
|
||
Remember to dispose the `FcmListener` instance when you're done: | ||
|
||
```csharp | ||
fcmListener.Dispose(); | ||
``` | ||
|
||
## Credentials | ||
|
||
Currenlty, there is not simple way to get the FCM & GCM credentials 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 & GCM credentials manually. | ||
To do so I recommand you to use [this project](https://github.com/liamcottle/rustplus.js) to get the credentials. | ||
|
||
I'm sorry for the inconvenience but since the API is not fully complete it's the easiest way. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters