當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript web-push.sendNotification函數代碼示例

本文整理匯總了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
				});
			}
		});
	});
開發者ID:ha-dai,項目名稱:Misskey,代碼行數:26,代碼來源:push-sw.ts

示例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',
    },
  });
}
開發者ID:madhu-amrit,項目名稱:mobile-toolkit,代碼行數:9,代碼來源:push.ts

示例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))
  });
}
開發者ID:SuperSoe,項目名稱:mobile-toolkit,代碼行數:9,代碼來源:push.ts

示例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
開發者ID:Jeremy-F,項目名稱:DefinitelyTyped,代碼行數:31,代碼來源:web-push-tests.ts

示例5: function

 app.post(route + 'sendNotification', function (req, res : express.Response) {
     webPush.sendNotification(req.query.endpoint, 0).then(function () {
         res.status(201).end();
     });
 });
開發者ID:isra-fel,項目名稱:push-demo,代碼行數:5,代碼來源:pushts.ts


注:本文中的web-push.sendNotification函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。