Closed dplewis closed 1 month ago
I've added Parse.Installation support https://github.com/parse-community/Parse-SDK-JS/pull/2119 to the JS SDK. The user can now save a deviceToken and deviceType however their is no way to use Parse.Push with this.
deviceToken
deviceType
Parse.Push
I've tested this in production and it works great!
Client
const register = await navigator.serviceWorker.register('./worker.js', { scope: '/' }); const subscription = await register.pushManager.subscribe({ userVisibleOnly: true, applicationServerKey: publicVapidKey, }); const currentInstallation = await Parse.Installation.currentInstallation(); currentInstallation.set('deviceType', 'web'); currentInstallation.set('deviceToken', JSON.stringify(subscription)); await currentInstallation.save();
Service Worker (worker.js)
self.addEventListener('push', (e) => { const data = e.data.json(); self.registration.showNotification(data.alert, {}); });
Server
const PushAdapter = require('@parse/push-adapter').default; const parseServerOptions = { push: { adapter: new PushAdapter({ web: { /* [options](https://github.com/web-push-libs/web-push#api-reference) */ vapidDetails: { subject: 'test@example.com', publicKey: 'publicVapidKey', privateKey: 'privateKey', }, }, }) }, /* Other Parse Server options */ }; const query = new Parse.Query(Parse.Installation); query.equalTo('deviceType', 'web'); await Parse.Push.send({ where: query, data: { alert: 'Hello World!', }, }, { useMasterKey: true });
Closes: #123
@mtrezza Codecov is broken
🎉 This change has been released in version 6.1.0
New Pull Request Checklist
Issue Description
I've added Parse.Installation support https://github.com/parse-community/Parse-SDK-JS/pull/2119 to the JS SDK. The user can now save a
deviceToken
anddeviceType
however their is no way to useParse.Push
with this.Approach
I've tested this in production and it works great!
Client
Service Worker (worker.js)
Server
TODOs before merging