liamcottle / rustplus.js

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

Is there an event to get a list of already paired devices? #13

Closed drewlane-dev closed 3 years ago

drewlane-dev commented 3 years ago

Hello, first I just want to say thank you for this code, I am in the process of porting it to c# :D The one thing I am missing is finding a list of already paired device ids. it seems i have to have pair.js running while I pair them to get the ID. am i missing something?

liamcottle commented 3 years ago

Hi, thanks for the feedback!

If you're referring to the Smart Alarms etc you have already paired with on your phone, this is not possible. When you "pair" with a device in-game, all it actually does, is sends a notification to all of the phones you have connected to the rust+ companion api. This notification sends the smart alarm entity id, it's entity type and which server it is on etc.

Your phone then saves that entity id locally in it's app database, and can then interact with it. When you delete the smart alarm on your phone, it removes it from the local phone database. Nothing on the server is updated list wise.

What you'll have to do, is re-pair with all of the devices in-game when you are running the pair.js script in this repo, so you can capture the notifications that are sent so you can get the entity ids.

Hope this is helpful. Feel free to open this issue if I misread your issue and it's about something else.

drewlane-dev commented 3 years ago

You understood correctly! I'm reading through pair.js now. it seems if I want an all inclusive socket based app that automatically adds devices I am going to need to have two event listeners, one for that fcm thing (not sure what that is) and one subscribed to the server socket that sends in game events

liamcottle commented 3 years ago

Yeah, you'll need to have a connection to FCM, which is Firebase Cloud Messaging (formerly GCM, Google Cloud Messaging) in order to receive notifications when you pair in-game.

The Rust+ app is designed for Android and iOS, hence the reliance on the mobile notification systems to receive pairing notifications.

Android devices register the apps "GCM sender id" with FCM, which returns a unique notification id, this is then passed on to expo (the framework Rust+ uses to host their react native app). Expo then gives us their own version of a notification token, which is then used to send notifications to your android device from the Rust+ companion api server.

There's some more docs on how the pairing flow works in docs/PairingFlow.md

I'm unaware of any C# libraries that have implemented the websocket connection to GCM to receive android notifications, so you may have to build one yourself if there's none available. Just note that the push-receiver library used in this project has actually reverse engineered the Chromium Web Push client, in order to receive FCM notifications.