matrix-org / matrix-js-sdk

Matrix Client-Server SDK for JavaScript
Apache License 2.0
1.54k stars 580 forks source link

Push notifications #648

Open Christilut opened 6 years ago

Christilut commented 6 years ago

I'm trying to figure out how to get push notifications working. It is my understanding so far that the client decides which Sygnal server to use, but I can find no reference to anything related to Sygnal or push notifications in the SDK.

Does the JS SDK support this? What is the suggested way to get push notifications working, if possible at all?

krombel commented 6 years ago

Push notifications are currently not supported.

Christilut commented 6 years ago

Would it be possible to run the sync command inside a serviceworker and display a notification from there? That seems like the easiest option, if possible.

t3chguy commented 6 years ago

Sure is possible

Christilut commented 6 years ago

Hmm I tried to get this working but BackgroundSync wouldn't update the matrix client. Creating a backend solution for push notifications now, and maybe abusing some Synapse endpoints to get the right information.

oliverjanik commented 5 years ago

I have a standalone Matrix Synapse deployment and a custom Push Gateway (my own service) how do I tell Synapse to use my gateway?

I thought it was done via this SDK.

krombel commented 5 years ago

the SDK is meant to have a constant connection to your server via a /sync poll loop. So notifications would be calculated that way. As you have a constant connection, you have no need for a dedicated push gateway. And therefore you cannot configure that

oliverjanik commented 5 years ago

Found it: http://matrix-org.github.io/matrix-js-sdk/0.11.0/module-client-MatrixClient.html

There's a setPusher method, which is very poorly documented. The parameters it takes are described in the protocol spec here: https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0- pushers-set

One of the args is the gateway URL. So obviously @krombel obviously talking nonsense.

When I run this in cordova the user can kill my app any time. Same thing in the browser I want to notify users via webpush or APNS or GCM.

All of this are legitimate use-cases.

krombel commented 5 years ago

Ohh. Sorry... You are right there is setPusher(pusher, callback) which accepts a pusher object as defined here. I was referring to Riot which does not implement some push API but uses an ever running /sync loop. And because it is not used there I somehow thought it is not part of the underlying js-sdk... Thanks for proving me false @oliverjanik. I have simply not thought of that possibility...