XData middleware to support Push Notifications

Not entirely sure how this would work, but I imagine it would involve a middleware component where you can provide VAPID keys and support for the functions needed to make use of them.

Hi @AndrewSimard, of course we can consider this feature, but we need more details about it. Why a middleware? How XData can help compared to simply implementing it in a service operation?

The idea with the middleware is that we could have a place to add in the VAPID public/private keys as well as the e-mail address that is needed. This is a bit like adding the JWT middleware and specifying the secret.

I realize that the "middleware" in the push case isn't really doing anything - there's no need to process incoming or outgoing data like what you're doing with JWTs, just more of a "where can I put this value" sort of thing, a complement to the TWebPushNotifications component where just the public VAPID key is entered.

I agree that using service endpoints is likely all that is required, but there is more behind-the-scenes stuff about sending the actual notification. In the recent (maybe not yet published) post I wrote, I used a NodeJS library, web-push, to handle all this so I don't even know all that is required. In the TMS WEB Core demos, there is also a PushNotificationServer which similarly handles all this kind of thing, but the source code for that isn't available. Maybe that was created using XData? Not sure.

In any event, this "feature request" might best materialize as both a middleware component and a new "XData app template" that has the endpoints already set up to correspond to those available in the TWebPushNotifications component. And the supporting functions for whatever the "sendnotification" does - calling the endpoint in the subscription and applying the necessary encrpytion.

Maybe the middleware thing is unnecessary and the values can just be supplied to the service endpoints in some other way. Ultimately I'd just want to import them from a JSON file or something. I just thought the middleware would make it consistent with other aspects of XData.

Overall, the idea is that this is likely to be a pretty common thing to want to do, so why not make a template or whatever can be done to make it easy? Naturally, we'd want the ability to customize it, so saving the subscriptions in the database of our choice, etc. All stuff that XData does remarkably well already :+1:

That's what I thought.

But ok, I understand your request is to have something "ready-to-use" in XData to handle push notifications, I guess?

Yes, as closely aligned with the TWebPushNotifications component as is sensible.

You presumably can track down the source code to the PushNotificationsServer.exe example which I think has everything needed, just no clue as to whether that was an XData project or not.

1 Like