MCPcopy Create free account
hub / github.com/tiann/hapi / sendToSubscription

Method sendToSubscription

hub/src/push/pushService.ts:51–78  ·  view source on GitHub ↗
(
        namespace: string,
        subscription: StoredSubscription,
        body: string
    )

Source from the content-addressed store, hash-verified

49 }
50
51 private async sendToSubscription(
52 namespace: string,
53 subscription: StoredSubscription,
54 body: string
55 ): Promise<void> {
56 const pushSubscription: PushSubscription = {
57 endpoint: subscription.endpoint,
58 keys: {
59 p256dh: subscription.p256dh,
60 auth: subscription.auth
61 }
62 }
63
64 try {
65 await webPush.sendNotification(pushSubscription, body)
66 } catch (error) {
67 const statusCode = typeof (error as { statusCode?: unknown }).statusCode === 'number'
68 ? (error as { statusCode: number }).statusCode
69 : null
70
71 if (statusCode === 410) {
72 this.store.push.removePushSubscription(namespace, subscription.endpoint)
73 return
74 }
75
76 console.error('[PushService] Failed to send notification:', error)
77 }
78 }
79}

Callers 1

sendToNamespaceMethod · 0.95

Calls 3

errorMethod · 0.80
sendNotificationMethod · 0.45

Tested by

no test coverage detected