本文整理匯總了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();
});
});