-
-
Notifications
You must be signed in to change notification settings - Fork 173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Notifications are not working in version 13.x+ #1578
Comments
Do you get any logs if you start the API with debug? Why are there two connections to firebase, are you running two instances with the same token? I would expect there to only be a single connection (the connections are not per-device). Are you subscribing to |
One of those connections was from a Google process, not sure which one. I only have one:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
Yes, I am subscribed to that onRefreshTokenUpdated. This has worked great for 2-3 years, but I was on the 12.X version, and when notifications stopped, I upgraded to 13.2.1 to hopefully get the notifications working again. So this has been good, and even with 12.x, I am able to get snapshots and video clips, just unable to get the motion or ding events... |
Firebase killed the legacy API for push notification back in July and Ring moved to a new message format around that same time as required by the new push API, so I'm completely surprised that it stayed working since Firebase de-commissioned most of the old push infrastructure around Sept, based on my understanding. Because of this, the chance of v12 working is very low. However, v13 ring-client-api has been deployed for a long time now and, while there were some issues with early versions due to instability in upstream push-receiver, and with the move to use native fetch, the more recent releases have proven to be very stable, so I'm not sure what more can be suggested. I saw 1-2 reports of a similar issue with ring-mqtt on the Home Assistant forums, but these cases were corrected with various account setting changes, not anything from a code perspective. If you are completely stopping the client, deleting it from Ring Control Center, generating an entirely new, unique token, and restarting the process on this single instance (sharing tokens to different instances is good way to make this break), keeping every refresh token along the way, then there's not much I can help with. In the end, the overall process is simple, push-receiver registers with FCM and creates the socket connection, which it appears is successful in your case, ring-client-api takes the FCM token and registers it with Ring API. This token must stay persistent after this point as it can't be changed after initial registration, and this is why storing refresh tokens for every refresh is critical. After that, Ring sends messages to FCM, which sends it to the client connected with that token. The messages either arrive or do not, there's not much that can be done if they do not, other than attempting to dig into the API and compare to the client. However, every single case where a user has complained of this issue and shared their account with me, it has worked fine for me, which indicates to me that the code is not at fault. But, of course, all the source code is there, you are welcome to dig into it and send a PR if you can improve it. |
I still am unable to determine why this isn't working. I have noticed that the authorized device, with 12.x, had a name ring_client_api, but now it say "Device name not found". Is this expected? |
There are no changes around API handling in v13 regarding devince, so I would expect it to be the same. Ideally, you would set the device name to something uniquely identifying via the I also noticed that you are not generating and passing a persistent system ID, I remember there being some issues in the past with notifications when this isn't done, so maybe that's a problem? Ring-mqtt, ring-homebridge, and Ring io.broker projects all generate and store their own persistent systemId. |
Just to add to this. I am also unable to get any motion events for cameras. I am running this test program: import { RingApi, PushNotificationAction } from 'ring-client-api'
const ringApi = new RingApi({
refreshToken: 'TOKEN',
})
const locations = await ringApi.getLocations()
const location = locations[0]
const camera = location.cameras[0]
console.log(`Subscribing to camera ${camera.name}`)
camera.onNewNotification.subscribe((notification) => {
const action = notification.android_config.category,
event =
action === PushNotificationAction.Motion
? 'Motion detected'
: action === PushNotificationAction.Ding
? 'Doorbell pressed'
: `Video started (${action})`
console.log(
`${event} on ${camera.name} camera. Ding id ${
notification.data.event.ding.id
}. Received at ${new Date()}`,
)
})
camera.onMotionDetected.subscribe((test) => {
console.log(`Motion detected on ${camera.name} camera. Received at ${new Date()} - ${test}`)
})
setInterval(() => {}, 1000); The only notification I see coming back is an initial "On motion detected" as false and then I never see anything else. The ring app gives me a push but nothing comes through from firebase (I verified there is a connection open) |
I used npx -p ring-client-api ring-auth-cli, and connected - it also shows up in my Ring control center as "Device name not found"... |
I copied your example code to test.js, acquired a token and ran it and it worked perfectly:
It's important to note that the code as written will only work the very first time it is used with a newly generated refresh token, where the device was completely removed from Ring Control Center, because you are not saving updated refresh tokens, which is critical for future use. Again, I would also highly recommend generating and saving a persistent systemId and sending that as part of the API connection config as well. Examples on how to do this are available in ring-homebridge and ring-mqtt. |
Please, can you tell what you did differently here? This has been attempted on more than one ring acount, clearing out the Ring Control Center each time. I also can confirm when I did it it does call the onMotionDetected callback a single time with 'false', but then never again. Can you provide the test.js program you used? I'm sure I'm missing something here...Oh, and how do I run the typescript examples in this repo? |
Immediately after authentication it will show as "Device name not found", however, once you use the token to connect to the API, it should change to 'ring-client-api'. I just tested this exact flow again, using the example code posted by @spencerfairchild and it worked exactly as I described. Again, you can make it show whatever name you want using Unfortunately, the fact that all tests work fine for me, I don't really have any other way to help you out. I can't force Ring to send messages to your endpoint and I know of no reason why it would not do so. I suppose if you are willing to give me your Ring account credentials, I can test it myself. I know that's intrusive, but there's not really any other option that I see as I can't fix a non-reproducible problem. One thing I did notice, your FCM endpoints appear to be in US west coast, is that your location? |
As I already said, it's just the code @spencerfairchild posted above. I just copied and pasted it exactly, saved it as test.js, replaced the token with my freshly generated token, it worked, no issues. |
Yes, this is the correct location. We are in Utah. I just managed to get mine to work using the test code: node test.js It seems to be hit-or-miss |
I'm not really sure what this means, push notifications are the same notifications you receive on your phone/device or the Ring web console, they cannot be any more hit-or-miss than the Ring app itself as it is 100% identical in process. Glad you got it to work. |
I borrowed some code from the ring-client-api refresh-token and utils, and I have a test program that works every time. This indicates something is wrong in the logic of my main program. By the way, this only works one time. In order to get it to work a second time, you must go in to the control center and removed the authorized device 'Ring Events Tester' For reference, I include the test program here in case anyone else runs into something similar:
|
Because you have to monitor for token updates and save them for future re-use, as I've mentioned multiple times and is covered completely in the wiki. |
I have the same issue despite using ringApi.onRefreshTokenUpdated.subscribe which is what is recommended to handle update of refresh tokens
|
@mahdirahman1 I ran your code exactly as you posted and it works fine, and the code in this library is leveraged in products used by more than 10,000 users. If you are having an issue, you have to troubleshoot your specific case. I've already written everything I can ever write about it multiple times, and I just don't have patience to type the same information again. One thing important to note, especially if you have multiple cameras, the code above just randomly monitors the first camera returned in the array, this might not be consistent between runs. In the end, all source code is here, if you find something wrong with it, we welcome a PR, but I don't know what else to do, the problems are always the same as what has already been covered. |
@tsightler Thanks for your reply, I was on version 12.x of the api, upgraded to v13.x and all good! |
Thanks for confirming. Ring API changes multiple times a year, it's always critical to keep the API updated to the latest released versions if you expect things to work correctly. |
@tsightler As you know, we have had problems getting this library to work in our own system. We could run the test programs and it would work, but when run as part of our larger system, it would not work. Today, finally, we figured out why it wasn't working. In our main application (the one that executes 3rd-party integrations like ring), we for some reason were overriding the global fetch with 'node-fetch', which apparently by default reuses connections. const fetch = require('node-fetch'); By removing this override, now the new version of this ring-client-api lib works great within our application. Thanks for your time and help as we worked through this problem. |
It definitely doesn't require an update as overriding a global capability with a completely alternate implementation would not be considered proper practice and it's completely unrealistic to expect 3rd party dependencies to work as expected in this case. Thanks for sharing what you found for your case. |
Is there an existing issue for this?
Describe The Bug
I have followed all of the steps for troubleshooting:
tcp4 0 0 10.0.0.86.60023 74.125.137.188.5228 ESTABLISHED
tcp4 0 0 10.0.0.86.55387 142.251.2.188.5228 ESTABLISHED
When I push the doorbell button or create motion, I see it in the ring app. My phone gets the notification, however I never get any kind of event in my code.
in my code:
with these handlers:
The logs do show:
Found doorbell: Back Door
and it seems to make a call to the callback a single time:
Doorbell Motion: false
but then nothing after that...
To Reproduce
Authenticate using email and password, followed by the 2fa code. Save the refresh token, and use it in further communication.
Register for motion and ding events (and even the generic notifications)
Press the doorbell button or make movement - note the ring app and phone receive notifications, but there is nothing sent to the ring-client-api application.
Expected behavior
I expect to receive a notification whenever there is motion or the doorbell is dinged
Relevant log output
Screenshots
No response
Additional context
No response
OS
macOs and Linux
Node.js Version
v20.18.0
NPM Version
v10.8.2
ring-client-api
v13.2.1
Operating System
macOS and Linux
The text was updated successfully, but these errors were encountered: