liamcottle / rustplus.js

Unofficial NodeJS library for controlling Smart Switches in the PC game Rust
224 stars 46 forks source link

Why are past pairings showing up again? #44

Closed AsutoraGG closed 1 year ago

AsutoraGG commented 1 year ago

https://user-images.githubusercontent.com/76235964/192157288-c79ad769-f17c-4de9-b160-c6d2f211e65f.mp4

(using push-receiver)

liamcottle commented 1 year ago

Are you using push-receiver in your own code or using the cli pair tool in rustplus.js?

FCM will send unseen messages on each new connection to the websocket (when you call listen). You'll need to remember the persistent ids for each received push notification, and on your next connection to the websocket, you need to pass in this list of IDs so they can be marked as seen on the FCM server.

I don't think I do this in the pair tool itself, because it was originally designed to create a new fcm registration each time, however the cli tool was updated to save the fcm credentials to a config file so they can be reused. So I probably need to update the cli tool to prevent the duplicated notifications.

If you're using your own code, you can avoid the duplicated notifications by changing it from this:

// start listening for notifications
await listen(credentials, ({notification, persistentId}) => {
    // process your notification
});

to this:

// get your list of saved persistent ids
const persistentIds = [];

// start listening for notifications
await listen({...credentials, persistentIds}, ({notification, persistentId}) => {
    // process your notification and save the persistent id somewhere
});
AsutoraGG commented 1 year ago

difficult... Do you have a simple example? image i don't know from here

liamcottle commented 1 year ago

I don't have a simple example, but it's pretty straightforward.

You need to save your persistent ids to a database or a file. Not persistentIds.push, because when you run your script the next time, the data in your array is forgotten.

Replace persistentIds.push with some function that will save them to a database/file. Replace const persistentIds = [] with some function that will load them from a database/file.

Then, when you run your script next time, the ids that were saved will be sent to FCM via the listen call, which will prevent FCM from sending those notifications again.

AsutoraGG commented 1 year ago

Thank You!!!!!

https://user-images.githubusercontent.com/76235964/192366124-0d9c2200-4a78-499b-a7d0-ca22e34fca9f.mp4