-
-
Notifications
You must be signed in to change notification settings - Fork 620
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
How to setup properly just for web? #665
Comments
I am setting up only the Web push too and somehow not sure how exactly to set up.
|
For the api endpoints to register the device you need to add the url's from the rest package. from rest_framework.routers import SimpleRouter
from push_notifications.api.rest_framework import WebPushDeviceViewSet
....
api_router = SimpleRouter()
api_router.register(r'push/web', WebPushDeviceViewSet, basename='web_push')
...
urlpatterns += [
# Api
re_path('api/v1/', include(api_router.urls)),
...
] On the client/Device you can now send the data for registration with a POST Method to your django. Something like: ....
}).then(function (sub) {
var endpointParts = sub.endpoint.split('/');
var registration_id = endpointParts[endpointParts.length - 1];
var data = {
'browser': browser.name.toUpperCase(),
'p256dh': btoa(String.fromCharCode.apply(null, new Uint8Array(sub.getKey('p256dh')))),
'auth': btoa(String.fromCharCode.apply(null, new Uint8Array(sub.getKey('auth')))),
'name': 'XXXXX',
'registration_id': registration_id
};
console.log(data);
requestPOSTToServer(data); <---------
})
....
function requestPOSTToServer(data) {
let xhr = new XMLHttpRequest();
xhr.open("POST", "https://<YOUR_ADDRESS/push/web/");
xhr.setRequestHeader("Accept", "application/json");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.onload = () => console.log(xhr.responseText);
xhr.send(data);
} Then your devices are registered |
Thank you. That's basically what I ended up doing. Just wondering why was this so hard for me to do? Will try to share the concepts using the library. |
@gagamil @viktorisacenko @saileshkush95 |
Fixed by #674 |
I want to setup push notification for website. I just follwed as described in documenation but Unfurtunately it is now working.
Here is my settings.
and here is my client side code
and here is error snippets.
I don't know what I'm missing??.
The text was updated successfully, but these errors were encountered: