capacitor-messenger-notifications 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -12
- package/android/src/main/java/com/codecraft_studio/messenger/notifications/EncryptedMessageNotifier.java +264 -123
- package/android/src/main/java/com/codecraft_studio/messenger/notifications/FcmFetchBackgroundService.java +0 -1
- package/android/src/main/java/com/codecraft_studio/messenger/notifications/FcmFetchForegroundService.java +12 -17
- package/android/src/main/java/com/codecraft_studio/messenger/notifications/FcmFetchManager.java +67 -26
- package/android/src/main/java/com/codecraft_studio/messenger/notifications/FcmJobService.java +6 -14
- package/android/src/main/java/com/codecraft_studio/messenger/notifications/FcmTokenRegistrar.java +10 -20
- package/android/src/main/java/com/codecraft_studio/messenger/notifications/GmsHelper.java +1 -0
- package/android/src/main/java/com/codecraft_studio/messenger/notifications/MessageFlowLogger.java +151 -0
- package/android/src/main/java/com/codecraft_studio/messenger/notifications/MessengerNotificationsPlugin.java +18 -8
- package/android/src/main/java/com/codecraft_studio/messenger/notifications/NativeCrypto.java +58 -9
- package/android/src/main/java/com/codecraft_studio/messenger/notifications/NotificationHelper.java +264 -121
- package/android/src/main/java/com/codecraft_studio/messenger/notifications/PersistentSocketService.java +43 -37
- package/android/src/main/java/com/codecraft_studio/messenger/notifications/TemporarySocketSessionManager.java +268 -37
- package/android/src/main/java/com/codecraft_studio/messenger/notifications/UnreadMessagesFetcher.java +59 -19
- package/dist/esm/definitions.d.ts +2 -1
- package/dist/esm/definitions.js.map +1 -1
- package/ios/Sources/MessengerNotificationsPlugin/EncryptedMessageNotifier.swift +91 -0
- package/ios/Sources/MessengerNotificationsPlugin/FcmTokenRegistrar.swift +170 -36
- package/ios/Sources/MessengerNotificationsPlugin/MessengerNotificationsPlugin.swift +4 -7
- package/ios/Sources/MessengerNotificationsPlugin/NativeCrypto.swift +6 -5
- package/ios/Sources/MessengerNotificationsPlugin/NotificationHelper.swift +492 -27
- package/ios/Sources/MessengerNotificationsPlugin/SafeStorageStore.swift +228 -4
- package/ios/Sources/MessengerNotificationsPlugin/TemporarySocketSessionManager.swift +1709 -67
- package/ios/Sources/MessengerNotificationsPlugin/UnreadMessagesFetcher.swift +217 -17
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ Capacitor plugin for managing messenger-style notifications with WebSocket suppo
|
|
|
15
15
|
- [Clear a Room's Notifications](#clear-a-rooms-notifications)
|
|
16
16
|
- [Cold-Start Navigation](#cold-start-navigation)
|
|
17
17
|
- [Persistent Socket (Android)](#persistent-socket-android)
|
|
18
|
-
- [
|
|
18
|
+
- [Push token / OneSignal registration](#push-token--onesignal-registration)
|
|
19
19
|
- [Native Integration](#native-integration)
|
|
20
20
|
- [Setup by Platform](#setup-by-platform)
|
|
21
21
|
- [Android](#android)
|
|
@@ -42,7 +42,9 @@ Capacitor plugin for managing messenger-style notifications with WebSocket suppo
|
|
|
42
42
|
- **Notification Deduplication**: In-memory + persisted message ID tracking prevents showing the same message twice across socket and FCM paths.
|
|
43
43
|
- **Dynamic Resources**: All icon, app name, and notification group key lookups are resolved from the host app at runtime — no hardcoded app-specific values.
|
|
44
44
|
- **`window.Notification` Polyfill (Android)**: Injects a polyfill into the WebView so the JS app's `new Notification(...)` calls route through the native plugin.
|
|
45
|
-
- **
|
|
45
|
+
- **Push registration**: **Android** — registers the FCM token via `POST …/api/users/fcm-token` (or your `fcmTokenEndpoint` override). **iOS** — can register **both**: FCM token to the same endpoint when `fcmToken` is in `safe_storage` (e.g. from Firebase), and the OneSignal subscription id via `POST …/api/push/register` when `onesignalPlayerId` is set (`FcmTokenRegistrar.updateOneSignalPlayerId(_:)` / `updateFcmToken(_:)`).
|
|
46
|
+
- **Message flow logging (optional)**: **Android** — `MessageFlowLogger` POSTs structured steps to `{backend}/api/message-flow-logs/ingest`. **iOS** — `MessageFlowLogger` in the plugin sends the same style of events over HTTPS.
|
|
47
|
+
- **App Group storage (iOS)**: `SafeStorageStore` can mirror `safe_storage` into a shared App Group when you set the `MessengerNotificationsAppGroup` key in Info.plist (for extensions / NSE).
|
|
46
48
|
|
|
47
49
|
---
|
|
48
50
|
|
|
@@ -106,7 +108,7 @@ await MessengerNotifications.clearRoomNotification({ roomId: 101 });
|
|
|
106
108
|
|
|
107
109
|
### Cold-Start Navigation
|
|
108
110
|
|
|
109
|
-
|
|
111
|
+
Notification tap intents include a `roomId` extra on Android. The plugin exposes `getPendingRoomId()` for JS; on **Android** you should also forward the launch intent room into native storage if you use a custom activity, e.g. `NotificationHelper.setPendingRoomId(roomId)` when handling `onNewIntent` / `onCreate`. On **iOS**, set `MessengerNotificationsPlugin.pendingRoomId = roomId` from your `AppDelegate` / OneSignal click handler when the user opens a chat from a notification.
|
|
110
112
|
|
|
111
113
|
```typescript
|
|
112
114
|
const { roomId } = await MessengerNotifications.getPendingRoomId();
|
|
@@ -131,15 +133,16 @@ await MessengerNotifications.stopPersistentSocket();
|
|
|
131
133
|
|
|
132
134
|
> On GMS devices the socket is only opened for the duration of each incoming FCM push. `startPersistentSocket` stores the credentials but does not start the service.
|
|
133
135
|
|
|
134
|
-
###
|
|
136
|
+
### Push token / OneSignal registration
|
|
135
137
|
|
|
136
|
-
After the user logs in,
|
|
138
|
+
After the user logs in, call:
|
|
137
139
|
|
|
138
140
|
```typescript
|
|
139
141
|
await MessengerNotifications.registerFcmToken();
|
|
140
142
|
```
|
|
141
143
|
|
|
142
|
-
|
|
144
|
+
- **Android**: Reads `fcmToken`, JWT, and backend URL from `safe_storage`, then `POST {base}/api/users/fcm-token` with `{ "fcmToken": "..." }` (or your `fcmTokenEndpoint` override). Skips when `fcmTokenRegistered` is already true.
|
|
145
|
+
- **iOS**: Runs **both** registrations when the prerequisites exist (each is independent). **FCM**: `fcmToken` + JWT + base URL → `POST {base}/api/users/fcm-token` (or `fcmTokenEndpoint`); skips when `fcmTokenRegistered` is true. **OneSignal**: `onesignalPlayerId` + JWT + base URL → `POST {base}/api/push/register` with `{ "playerId": "...", "platform": "ios" }`; skips when `onesignalPlayerIdRegistered` is true. From Swift use `FcmTokenRegistrar.updateFcmToken(_:)` / `updateOneSignalPlayerId(_:)` when tokens change.
|
|
143
146
|
|
|
144
147
|
### Native Integration
|
|
145
148
|
|
|
@@ -174,6 +177,8 @@ The plugin reads credentials from `SharedPreferences` file `"safe_storage"`. You
|
|
|
174
177
|
| `socketUrl` | WebSocket server URL |
|
|
175
178
|
| `backendBaseUrl` / `serverUrl` / ... | HTTP base URL for the unread messages API |
|
|
176
179
|
| `fcmToken` | FCM registration token (written by Firebase) |
|
|
180
|
+
| `fcmTokenRegistered` | Set by the plugin to true after a successful `POST` to the FCM endpoint |
|
|
181
|
+
| `fcmTokenEndpoint` | Optional path override (default `/api/users/fcm-token`) |
|
|
177
182
|
| `roomDecryptedKeys` | JSON map of room E2EE private keys |
|
|
178
183
|
| `memberDecryptedKeys` | JSON map of member E2EE private keys |
|
|
179
184
|
|
|
@@ -220,9 +225,20 @@ In Xcode, enable the following for your app target:
|
|
|
220
225
|
- **Push Notifications**
|
|
221
226
|
- **Background Modes** → check *Remote notifications* and *Background fetch*
|
|
222
227
|
|
|
223
|
-
#### 2.
|
|
228
|
+
#### 2. Info.plist (App Group, optional)
|
|
224
229
|
|
|
225
|
-
|
|
230
|
+
If you use a Notification Service Extension or shared storage with the main app, set your App Group identifier:
|
|
231
|
+
|
|
232
|
+
```xml
|
|
233
|
+
<key>MessengerNotificationsAppGroup</key>
|
|
234
|
+
<string>group.your.bundle.app</string>
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
If omitted, the plugin uses only `UserDefaults.standard` for the `safe_storage` dictionary.
|
|
238
|
+
|
|
239
|
+
#### 3. AppDelegate
|
|
240
|
+
|
|
241
|
+
Forward remote notifications to the plugin when you handle data/silent payloads. When the user taps a notification and you know the `roomId`, assign `MessengerNotificationsPlugin.pendingRoomId = roomId` so JavaScript can read it via `getPendingRoomId()`.
|
|
226
242
|
|
|
227
243
|
```swift
|
|
228
244
|
import UIKit
|
|
@@ -243,16 +259,20 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
|
|
243
259
|
}
|
|
244
260
|
```
|
|
245
261
|
|
|
246
|
-
####
|
|
262
|
+
#### 4. Safe Storage Keys
|
|
247
263
|
|
|
248
|
-
The plugin reads from `UserDefaults` suite `"safe_storage"
|
|
264
|
+
The plugin reads from `UserDefaults` suite `"safe_storage"` (and mirrors to the App Group suite when configured). Write the following keys from your JS app:
|
|
249
265
|
|
|
250
266
|
| Key | Description |
|
|
251
267
|
| --- | --- |
|
|
252
268
|
| `token` / `authToken` | User's JWT |
|
|
253
269
|
| `socketUrl` | WebSocket server URL |
|
|
254
270
|
| `backendBaseUrl` / `serverUrl` / ... | HTTP base URL |
|
|
255
|
-
| `
|
|
271
|
+
| `onesignalPlayerId` / `onesignalSubscriptionId` | OneSignal subscription id (`POST /api/push/register`) |
|
|
272
|
+
| `onesignalPlayerIdRegistered` | `"true"` after OneSignal id is ACKed by your backend (plugin sets this) |
|
|
273
|
+
| `fcmToken` | FCM registration token from Firebase (optional; `POST /api/users/fcm-token` same as Android) |
|
|
274
|
+
| `fcmTokenRegistered` | `"true"` after FCM token is ACKed (plugin sets this) |
|
|
275
|
+
| `fcmTokenEndpoint` | Optional path override for FCM registration (default `/api/users/fcm-token`) |
|
|
256
276
|
| `roomDecryptedKeys` | JSON map of room E2EE private keys |
|
|
257
277
|
| `memberDecryptedKeys` | JSON map of member E2EE private keys |
|
|
258
278
|
|
|
@@ -365,7 +385,7 @@ Prompts the user for notification permission.
|
|
|
365
385
|
|
|
366
386
|
### `registerFcmToken()`
|
|
367
387
|
|
|
368
|
-
|
|
388
|
+
**Android**: Registers `fcmToken` with `{base}/api/users/fcm-token` (or `fcmTokenEndpoint`). **iOS**: Registers **FCM** (`fcmToken` → same endpoint/shape as Android) and **OneSignal** (`onesignalPlayerId` → `{base}/api/push/register`) when each is present and not yet marked registered. Reads JWT and backend URL from `safe_storage`.
|
|
369
389
|
|
|
370
390
|
---
|
|
371
391
|
|