cometchat-angular-v5-push
Web push notifications for a CometChat Angular app — the Notifications product, FCM registration, the service worker, and token lifecycle. Docs-first: fetches the current notifications docs rather than baking a version-specific recipe. Triggers: 'add push notifications to my angular app', 'notify users when the app is closed', 'fcm setup', 'register push token'.
- License 许可
- MIT
- 最近更新
- 2026-11-14
- Stars
- ★ 1.6k
- Forks
- 491
01 前言 Front Matter
- name
- cometchat-angular-v5-push
- license
- MIT
- metadata
- { "tags": "cometchat angular push v5 notifications fcm firebase service-worker", "author": "CometChat", "version": "1.0.0" }
- description
- Web push notifications for a CometChat Angular app — the Notifications product, FCM registration, the service worker, and token lifecycle. Docs-first: fetches the current notifications docs rather than baking a version-specific recipe. Triggers: 'add push notifications to my angular app', 'notify users when the app is closed', 'fcm setup', 'register push token'.
- compatibility
- @cometchat/chat-sdk-javascript ^4.1.13; Angular 17-21; requires the CometChat Notifications product
03 SKILL.md 正文
Ground truth: push is the CometChat Notifications product, not a UI Kit component — this skill is THIN and docs-first. Registration, payload shape and provider setup are FETCHED from the notifications docs via
cometchat-angular-v5-core/references/docs-map.md; nothing about them is baked here. Live delivery cannot be auto-smoked — say so honestly rather than claiming verification.
Companion skills (read first)
cometchat-angular-v5-core— install, credentials,init→login→render. Assumed.
Use this skill when
Delivering notifications while the app is closed or backgrounded.
This skill is deliberately THIN — fetch the docs
Push spans a product (CometChat Notifications), a third-party provider (Firebase/FCM), a service worker, and browser permission rules. Every one of those changes independently, so a baked recipe goes stale fast.
Start here: {SDK_DOCS_BASE}/notifications/overview.md, then the web push integration page. Discover the current pages from the SDK index (cometchat-angular-v5-core/references/docs-map.md). Read before writing.
Angular's own docs cover push only inside {DOCS_BASE}/ui-kit/angular/campaigns.md — there is no dedicated Angular push page. That is a known docs gap; the product-level notifications docs are the source of truth.
What is true regardless of version
1. Push is a separate product. It must be enabled and configured for the app in the dashboard, with provider credentials added there. No client code substitutes for that step.
2. It is not the UI Kit. Registration is SDK-level (CometChatNotifications), not a component. There is nothing to render.
3. It needs a service worker at origin root. firebase-messaging-sw.js must be served from /, not from a nested path. In Angular, add it to the app's assets in angular.json so it lands at the root of dist/, and confirm it is reachable at /firebase-messaging-sw.js after build — a 404 there is the single most common cause of "push does nothing".
4. Permission requires a user gesture. Call the permission request from a click. Browsers block it on load, and repeated silent blocks poison the origin.
5. Token lifecycle is yours. Register the FCM token after login; unregister on logout. Skipping the unregister sends the next user's notifications to the previous device.
6. iOS Safari is PWA-only. Web push on iOS requires the site installed to the home screen. Not a bug; set expectations.
Angular specifics
- Register the token after
login()resolves — see core's guarded-login pattern. - Put registration in a service, not a component, so it does not re-run per route.
- If the app is SSR, guard all of it with
isPlatformBrowser(cometchat-angular-v5-patterns). - Unregister in the same place you call
CometChatUIKit.logout().
Verify it works
Push cannot be verified in a headless browser: it needs a real device or browser profile, a live provider, and a backgrounded app. Expect to test by hand:
- Load over HTTPS, grant permission from a click.
- Confirm
/firebase-messaging-sw.jsreturns 200. - Background the tab; send a message from a second account.
- Notification arrives; tapping it focuses the app.
- Log out; confirm notifications stop.
Common pitfalls
- Notifications not enabled in the dashboard — nothing works, no error.
- Service worker not at origin root — silent failure.
- Permission requested on load — blocked.
- Token registered before login — no user to attach it to.
- No unregister on logout — notifications follow the wrong user.
- Expecting iOS Safari to work outside a PWA.
- Baking a recipe from memory — fetch the docs; this area moves.
04 同仓库更多 Skills
worktable-review-with-annotations
Create, inspect, reply to, update, or resolve situated Worktable annotations. Use when feedback belongs to a Doc section, block, text range, or HTML Doc, or when the user asks to address existing review feedback and coordinate a requested artifact edit.
worktable-find-and-synthesize-context
Find, assess, and synthesize context from Worktable Docs and Records. Use when the user asks what a workspace contains, wants workspace-backed research, needs current facts reconciled across artifacts, or requests a cited synthesis without changing workspace state.
worktable-create-or-update-docs
Create, edit, rename, or maintain narrative Worktable Docs. Use for plans, decisions, briefs, notes, research syntheses, and other durable prose when the user requests a new artifact or a safe update to an existing one.
worktable-create-or-manage-records
Organize repeated structured information as durable Worktable Records. Use for research datasets, inventories, directories, pipelines, trackers, and other collections whose items need identity, fields, filtering, links, validation, or individual updates.
worktable-create-or-manage-interactive-html
Create or improve durable visual and interactive artifacts in Worktable. Use for dashboards, trackers, calculators, mini apps, slide presentations, and other requests that benefit from a polished HTML Doc.
worktable-collaborate-threads
Read, answer, and hand off messages through durable Worktable threads with users or other authenticated participants. Use when the user asks to check addressed messages, reply to a participant, continue a thread, request another agent's help, wait briefly for a response, or watch for comments and messages sent to the agent.