本文整理汇总了TypeScript中web-push.sendNotification函数的典型用法代码示例。如果您正苦于以下问题:TypeScript sendNotification函数的具体用法?TypeScript sendNotification怎么用?TypeScript sendNotification使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sendNotification函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
subscriptions.forEach(subscription => {
const pushSubscription = {
endpoint: subscription.endpoint,
keys: {
auth: subscription.auth,
p256dh: subscription.publickey
}
};
push.sendNotification(pushSubscription, JSON.stringify({
type, body
})).catch((err: any) => {
//console.log(err.statusCode);
//console.log(err.headers);
//console.log(err.body);
if (err.statusCode == 410) {
Subscription.remove({
userId: userId,
endpoint: subscription.endpoint,
auth: subscription.auth,
publickey: subscription.publickey
});
}
});
});
示例2: sendPush
export function sendPush(subscription: any, payload?: Object): Promise<any> {
return push.sendNotification(subscription, JSON.stringify(payload), {
vapidDetails: {
subject: 'mailto:test@angular.io',
publicKey: 'BLRl_fG1TCTc1D2JwzOpdZjaRcJucXtG8TAd5g9vuYjl6KUUDxgoRjQPCgjZfY-_Rusd_qtjNvanHXeFvOFlxH4',
privateKey: 't3JtFOflouvPUxFKeSSmZdjuVidnD_0dNGFM1v-N4PI',
},
});
}
示例3: sendPush
export function sendPush(reg: any, payload?: Object): Promise<any> {
let endpoint = reg.url;
return push.sendNotification(endpoint, {
userPublicKey: reg.key,
userAuth: reg.auth,
payload: new Buffer(JSON.stringify(payload))
});
}
示例4: sendNotification
// $ExpectType "POST"
requestDetails.method;
// $ExpectType Headers
requestDetails.headers;
// $ExpectType Buffer
requestDetails.body;
// $ExpectType string
requestDetails.endpoint;
// $ExpectType string | undefined
requestDetails.proxy;
// ====================
// sendNotification()
// ====================
// $ExpectType Promise<SendResult>
sendNotification(pushSubscription, 'payload', requestOptions);
// Buffers are also supported
// $ExpectType Promise<SendResult>
sendNotification(pushSubscription, buffer);
// $ExpectType Promise<SendResult>
sendNotification(pushSubscription, buffer, requestOptions);
// Payload can be absent or null
// $ExpectType Promise<SendResult>
sendNotification(pushSubscription);
// $ExpectType Promise<SendResult>
sendNotification(pushSubscription, null, requestOptions);
// PushSubscription must have all its values
// $ExpectError
示例5: function
app.post(route + 'sendNotification', function (req, res : express.Response) {
webPush.sendNotification(req.query.endpoint, 0).then(function () {
res.status(201).end();
});
});