UNPKG

6.62 kBSource Map (JSON)View Raw
1{"version":3,"file":"ExponentNotifications.web.js","sourceRoot":"","sources":["../../src/Notifications/ExponentNotifications.web.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,MAAM,MAAM,SAAS,CAAC;AAE7B,OAAO,EACL,eAAe,EACf,yBAAyB,EACzB,uBAAuB,GACxB,MAAM,mCAAmC,CAAC;AAG3C,oDAAoD;AACpD,OAAO,gCAAgC,CAAC;AAExC,IAAI,kBAAkB,GAAG,CAAC,CAAC;AAE3B,SAAS,0BAA0B,CACjC,YAA+B,EAC/B,GAAW;IAEX,MAAM,EAAE,GAAG,GAAG,EAAE,EAAE,GAAG,oBAAoB,EAAE,GAAG,YAAY,CAAC;IAC3D,GAAG,GAAG,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC;IACrB,MAAM,kBAAkB,GAAG;QACzB,GAAG,oBAAoB;QACvB,GAAG;QACH,GAAG,GAAG;QACN,sDAAsD;QACtD,QAAQ,EAAE,IAAI;KACf,CAAC;IACF,OAAO,CAAC,kBAAkB,CAAC,KAAK,EAAE,kBAAkB,CAAC,CAAC;AACxD,CAAC;AAED,KAAK,UAAU,oBAAoB;IACjC,eAAe,EAAE,CAAC;IAClB,MAAM,YAAY,GAAG,MAAM,SAAS,CAAC,aAAa,CAAC,eAAe,EAAE,CAAC;IACrE,IAAI,CAAC,YAAY,EAAE;QACjB,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;KAC7D;IACD,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,KAAK,UAAU,qBAAqB,CAAC,GAAY;IAC/C,MAAM,YAAY,GAAG,MAAM,oBAAoB,EAAE,CAAC;IAClD,MAAM,aAAa,GAAG,MAAM,YAAY,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IACrF,OAAO,aAAa,CAAC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YAAY,CAAC,KAAK,EAAE,CAAC;SACtB;IACH,CAAC;IACD,KAAK,CAAC,uBAAuB;QAC3B,IAAI,CAAC,mBAAmB,EAAE,CAAC;IAC7B,CAAC;IACD,KAAK,CAAC,gCAAgC,CAAC,cAAsB;QAC3D,IAAI,CAAC,mBAAmB,CAAC,cAAc,CAAC,CAAC;IAC3C,CAAC;IACD,KAAK,CAAC,oCAAoC;QACxC,IAAI,CAAC,mBAAmB,EAAE,CAAC;IAC7B,CAAC;IAED,KAAK,CAAC,yBAAyB;QAC7B,OAAO,MAAM,yBAAyB,EAAE,CAAC;IAC3C,CAAC;IAED,KAAK,CAAC,uBAAuB;QAC3B,OAAO,MAAM,uBAAuB,EAAE,CAAC;IACzC,CAAC;IAED,KAAK,CAAC,mBAAmB;QACvB,OAAO,kBAAkB,CAAC;IAC5B,CAAC;IAED,KAAK,CAAC,mBAAmB,CAAC,WAAmB;QAC3C,kBAAkB,GAAG,WAAW,CAAC;QACjC,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IAC1B,CAAC;CACF,CAAC","sourcesContent":["import * as badgin from 'badgin';\nimport uuidv4 from 'uuid/v4';\n\nimport {\n guardPermission,\n getExponentPushTokenAsync,\n getDevicePushTokenAsync,\n} from './ExponentNotificationsHelper.web';\nimport { LocalNotification, LocalNotificationId } from './Notifications.types';\n\n// Register `message`'s event listener (side-effect)\nimport './ExponentNotifications.fx.web';\n\nlet currentBadgeNumber = 0;\n\nfunction transformLocalNotification(\n notification: LocalNotification,\n tag: string\n): [string, NotificationOptions] {\n const { web = {}, ...abstractNotification } = notification;\n tag = web.tag || tag;\n const nativeNotification = {\n ...abstractNotification,\n tag,\n ...web,\n // Show that this notification is a local notification\n _isLocal: true,\n };\n return [nativeNotification.title, nativeNotification];\n}\n\nasync function getRegistrationAsync(): Promise<ServiceWorkerRegistration> {\n guardPermission();\n const registration = await navigator.serviceWorker.getRegistration();\n if (!registration) {\n throw new Error('Failed to get notification registration!');\n }\n return registration;\n}\n\nasync function getNotificationsAsync(tag?: string): Promise<Notification[]> {\n const registration = await getRegistrationAsync();\n const notifications = await registration.getNotifications(tag ? { tag } : undefined);\n return notifications;\n}\n\nexport default {\n async presentLocalNotification(notification: LocalNotification): Promise<LocalNotificationId> {\n const registration = await getRegistrationAsync();\n const tag = uuidv4();\n registration.showNotification(...transformLocalNotification(notification, tag));\n return tag;\n },\n async scheduleLocalNotification(\n notification: any,\n options: {\n time?: Date | number;\n repeat?: 'minute' | 'hour' | 'day' | 'week' | 'month' | 'year';\n intervalMs?: number;\n } = {}\n ): Promise<string> {\n if (options.intervalMs) {\n const registration = await getRegistrationAsync();\n const tag = uuidv4();\n setTimeout(() => {\n registration.showNotification(...transformLocalNotification(notification, tag));\n }, options.intervalMs);\n return tag;\n } else if (options.time) {\n const intervalMs = (options.time as number) - Date.now();\n if (intervalMs < 0) {\n throw new Error(\n 'Expo.Notifications.scheduleLocalNotification(): options.time must be some time in the future.'\n );\n }\n return this.scheduleLocalNotification(notification, {\n intervalMs,\n });\n }\n throw new Error(\n `Expo.Notifications.scheduleLocalNotification() options ${JSON.stringify(\n options,\n null,\n 2\n )} are not supported yet.`\n );\n },\n\n async dismissNotification(notificationId?: string): Promise<void> {\n const notifications = await getNotificationsAsync(notificationId);\n for (const notification of notifications) {\n notification.close();\n }\n },\n async dismissAllNotifications(): Promise<void> {\n this.dismissNotification();\n },\n async cancelScheduledNotificationAsync(notificationId: string): Promise<void> {\n this.dismissNotification(notificationId);\n },\n async cancelAllScheduledNotificationsAsync(): Promise<void> {\n this.dismissNotification();\n },\n\n async getExponentPushTokenAsync(): Promise<string> {\n return await getExponentPushTokenAsync();\n },\n\n async getDevicePushTokenAsync(): Promise<{ type: string; data: object }> {\n return await getDevicePushTokenAsync();\n },\n\n async getBadgeNumberAsync(): Promise<number> {\n return currentBadgeNumber;\n },\n\n async setBadgeNumberAsync(badgeNumber: number): Promise<void> {\n currentBadgeNumber = badgeNumber;\n badgin.set(badgeNumber);\n },\n};\n"]}
\No newline at end of file