Je développe une application KaiOS avec une capacité de notification push Web.

Bien que le code suivant fonctionne sur Chrome et Mozilla actuel, il échoue sur KaiOS.

Code NodeJS:

const push = require('web-push');
const vapidKeys = {
  publicKey: 'PUBLIC_KEY',
  privateKey: 'PRIVATE_KEY',
};

push.setVapidDetails(
  'valid@email.com',
  vapidKeys.publicKey,
  vapidKeys.privateKey
);

const pushSub = {
  endpoint: 'https://push.kaiostech.com:8443/wpush/v2/gAAAAABgNqjxZulGGFU',
  keys: {
    auth: 'AUTH',
    p256dh: 'P256dH',
  },
};

KaiOS:

failed to send notification WebPushError: Received unexpected response code
    at IncomingMessage.<anonymous> (/Users/raiym/WebstormProjects/adele/adele-server/node_modules/web-push/src/web-push-lib.js:347:20)
    at IncomingMessage.emit (events.js:327:22)
    at endReadableNT (_stream_readable.js:1221:12)
    at processTicksAndRejections (internal/process/task_queues.js:84:21) {
  statusCode: 401,
  headers: {
    date: 'Thu, 25 Feb 2021 15:35:19 GMT',
    'content-length': '15',
    'content-type': 'text/plain; charset=utf-8',
    connection: 'close'
  },
  body: '{"errno":"109"}',
  endpoint: 'https://push.kaiostech.com:8443/wpush/v2/gAAAAABgNqjxZulGGFU-72vZJFv0avzqAZAdWd7FSwZBINZ8AvsEkxAU2J3AFcs0e4aEUIYxi8aSzCCn8ihUgof_nfLGyR8VBprtzgZEABf14rSb9RgGgwxQip6f2792pS0BcUawcerZbNstCotDYTXdNZ7jQvegfDHUEHvril1KeEeaMoi4nGk'
}

Mais sur Mozilla (avec les changements clés appropriés), la réponse est réussie. Idem sur Chrome.

notification response:  {
  statusCode: 201,
  body: '',
  headers: {
    'access-control-allow-headers': 'content-encoding,encryption,crypto-key,ttl,encryption-key,content-type,authorization',
    'access-control-allow-methods': 'POST',
    'access-control-allow-origin': '*',
    'access-control-expose-headers': 'location,www-authenticate',
    'content-type': 'text/html; charset=UTF-8',
    date: 'Wed, 24 Feb 2021 20:38:35 GMT',
    location: 'https://updates.push.services.mozilla.com/m/gAAAAABgNrlLgRnDfpaVmZjc6eqnAxoXkaYkTT4nKCTI1ZIBt62hfu2l3XvGr0F8HfvW54etByCQNSX89ubyBjd2VtXOTPqfsiC4-iDBWol9q9GRwiBSgjFc2M5-avDmrRpq9eCAsxlgGCzp2sRYRqvVDAQBHa8GznLzKmDE87rWZM6ItMiLS8PN0jqiSZFYMlqooeCK53QN',
    server: 'nginx',
    'strict-transport-security': 'max-age=31536000;includeSubDomains',
    ttl: '2419200',
    'content-length': '0',
    connection: 'Close'
  }
}

Voici le code du travailleur du service client:

self.addEventListener('push', (event) => {
  console.log('push event', event);
  const title = event.data.text();

  event.waitUntil(self.registration.showNotification(title));
});

Des idées, qu'est-ce qui pourrait être un problème?

0
raiym 25 févr. 2021 à 22:24

1 réponse

Meilleure réponse
push.sendNotification(pushSub, 'hello my name is me', {
    contentEncoding: 'aesgcm'
})
.then(function (res) {
    console.log('notification response: ', res);
})
.catch(function (err) {
    console.error('failed to send notification', err);
});

https://github.com/web-push-libs/web-push/issues/603

0
Penny Liu 6 mars 2021 à 04:06