0.12.47 fix push messages
This commit is contained in:
@@ -30,6 +30,26 @@ const showNotAllowed = (message) => {
|
||||
button.setAttribute('disabled', 'true');
|
||||
};
|
||||
|
||||
|
||||
|
||||
// urlB64ToUint8Array is a magic function that will encode the base64 public key
|
||||
// to Array buffer which is needed by the subscription option
|
||||
function urlB64ToUint8Array2(base64String) {
|
||||
const padding = '='.repeat((4 - (base64String.length % 4)) % 4)
|
||||
const base64 = (base64String + padding).replace(/\-/g, '+').replace(/_/g, '/')
|
||||
const rawData = atob(base64)
|
||||
const outputArray = new Uint8Array(rawData.length)
|
||||
for (let i = 0; i < rawData.length; ++i) {
|
||||
outputArray[i] = rawData.charCodeAt(i)
|
||||
}
|
||||
return outputArray
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function urlB64ToUint8Array(base64String) {
|
||||
const padding = '='.repeat((4 - base64String.length % 4) % 4);
|
||||
const base64 = (base64String + padding)
|
||||
@@ -55,7 +75,7 @@ const subscribe = async (reg) => {
|
||||
const options = {
|
||||
userVisibleOnly: true,
|
||||
// if key exists, create applicationServerKey property
|
||||
...(key && {applicationServerKey: urlB64ToUint8Array(key)})
|
||||
...(key && {applicationServerKey: urlB64ToUint8Array2(key)})
|
||||
};
|
||||
|
||||
const sub = await reg.pushManager.subscribe(options);
|
||||
|
||||
Reference in New Issue
Block a user