capacitor-push-signal 0.0.1 → 0.0.3
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 +57 -3
- package/android/src/main/java/com/antonseagull/cap/push/signal/PushSignalPlugin.kt +47 -1
- package/dist/docs.json +65 -0
- package/dist/esm/definitions.d.ts +16 -2
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/pushSignal.d.ts +3 -1
- package/dist/esm/pushSignal.js +6 -0
- package/dist/esm/pushSignal.js.map +1 -1
- package/dist/esm/types.d.ts +4 -0
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/web.d.ts +4 -1
- package/dist/esm/web.js +26 -0
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +34 -0
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +34 -0
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/PushSignalPlugin/PushSignalPlugin.swift +40 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# capacitor-push-signal
|
|
2
2
|
|
|
3
|
-
Get device credentials for your server and listen for incoming notifications or taps. The plugin does not send pushes — your backend talks to APNs and FCM.
|
|
3
|
+
Get device credentials for your server and listen for incoming notifications or taps. The plugin does not send pushes — your backend talks to APNs and FCM.
|
|
4
4
|
|
|
5
|
-
The public JS API matches [`react-native-push-signal`](https://github.com/AntonSeagull/react-native-push-signal): `initialize`, `getCredentials`, `onMessage`, `onNotificationPress`.
|
|
5
|
+
The public JS API matches [`react-native-push-signal`](https://github.com/AntonSeagull/react-native-push-signal): `initialize`, `getCredentials`, `checkPermissions`, `requestPermissions`, `onMessage`, `onNotificationPress`.
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
@@ -15,10 +15,12 @@ npx cap sync
|
|
|
15
15
|
|
|
16
16
|
```ts
|
|
17
17
|
import {
|
|
18
|
+
checkPermissions,
|
|
18
19
|
getCredentials,
|
|
19
20
|
initialize,
|
|
20
21
|
onMessage,
|
|
21
22
|
onNotificationPress,
|
|
23
|
+
requestPermissions,
|
|
22
24
|
} from 'capacitor-push-signal';
|
|
23
25
|
|
|
24
26
|
await initialize({
|
|
@@ -28,7 +30,13 @@ await initialize({
|
|
|
28
30
|
project_number: '123456789',
|
|
29
31
|
});
|
|
30
32
|
|
|
31
|
-
|
|
33
|
+
let permStatus = await checkPermissions();
|
|
34
|
+
if (permStatus.receive === 'prompt') {
|
|
35
|
+
permStatus = await requestPermissions();
|
|
36
|
+
}
|
|
37
|
+
if (permStatus.receive !== 'granted') {
|
|
38
|
+
throw new Error('User denied notification permissions');
|
|
39
|
+
}
|
|
32
40
|
|
|
33
41
|
const credentials = await getCredentials();
|
|
34
42
|
// POST credentials to your server: { platform, token, environment? }
|
|
@@ -124,6 +132,8 @@ If the host app already declares its own `FirebaseMessagingService`, only one se
|
|
|
124
132
|
|
|
125
133
|
* [`initialize(...)`](#initialize)
|
|
126
134
|
* [`getCredentials()`](#getcredentials)
|
|
135
|
+
* [`checkPermissions()`](#checkpermissions)
|
|
136
|
+
* [`requestPermissions()`](#requestpermissions)
|
|
127
137
|
* [`startListening()`](#startlistening)
|
|
128
138
|
* [`addListener('onMessage', ...)`](#addlisteneronmessage-)
|
|
129
139
|
* [`addListener('onNotificationPress', ...)`](#addlisteneronnotificationpress-)
|
|
@@ -163,6 +173,38 @@ Returns APNs (iOS) or FCM (Android) credentials for your server.
|
|
|
163
173
|
--------------------
|
|
164
174
|
|
|
165
175
|
|
|
176
|
+
### checkPermissions()
|
|
177
|
+
|
|
178
|
+
```typescript
|
|
179
|
+
checkPermissions() => Promise<PermissionStatus>
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
Check permission to receive push notifications.
|
|
183
|
+
|
|
184
|
+
On Android 12 and below the status is always granted because you can always
|
|
185
|
+
receive push notifications.
|
|
186
|
+
|
|
187
|
+
**Returns:** <code>Promise<<a href="#permissionstatus">PermissionStatus</a>></code>
|
|
188
|
+
|
|
189
|
+
--------------------
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
### requestPermissions()
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
requestPermissions() => Promise<PermissionStatus>
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
Request permission to receive push notifications.
|
|
199
|
+
|
|
200
|
+
On Android 12 and below it does not prompt for permission because you can
|
|
201
|
+
always receive push notifications.
|
|
202
|
+
|
|
203
|
+
**Returns:** <code>Promise<<a href="#permissionstatus">PermissionStatus</a>></code>
|
|
204
|
+
|
|
205
|
+
--------------------
|
|
206
|
+
|
|
207
|
+
|
|
166
208
|
### startListening()
|
|
167
209
|
|
|
168
210
|
```typescript
|
|
@@ -228,6 +270,13 @@ addListener(eventName: 'onNotificationPress', listenerFunc: (message: PushMessag
|
|
|
228
270
|
| **`environment`** | <code><a href="#pushenvironment">PushEnvironment</a></code> |
|
|
229
271
|
|
|
230
272
|
|
|
273
|
+
#### PermissionStatus
|
|
274
|
+
|
|
275
|
+
| Prop | Type |
|
|
276
|
+
| ------------- | ----------------------------------------------------------- |
|
|
277
|
+
| **`receive`** | <code><a href="#permissionstate">PermissionState</a></code> |
|
|
278
|
+
|
|
279
|
+
|
|
231
280
|
#### PluginListenerHandle
|
|
232
281
|
|
|
233
282
|
| Prop | Type |
|
|
@@ -258,6 +307,11 @@ addListener(eventName: 'onNotificationPress', listenerFunc: (message: PushMessag
|
|
|
258
307
|
<code>'sandbox' | 'production'</code>
|
|
259
308
|
|
|
260
309
|
|
|
310
|
+
#### PermissionState
|
|
311
|
+
|
|
312
|
+
<code>'prompt' | 'prompt-with-rationale' | 'granted' | 'denied'</code>
|
|
313
|
+
|
|
314
|
+
|
|
261
315
|
#### Record
|
|
262
316
|
|
|
263
317
|
Construct a type with a set of properties K of type T
|
|
@@ -1,14 +1,31 @@
|
|
|
1
1
|
package com.antonseagull.cap.push.signal
|
|
2
2
|
|
|
3
|
+
import android.Manifest
|
|
4
|
+
import android.os.Build
|
|
3
5
|
import com.getcapacitor.JSObject
|
|
6
|
+
import com.getcapacitor.PermissionState
|
|
4
7
|
import com.getcapacitor.Plugin
|
|
5
8
|
import com.getcapacitor.PluginCall
|
|
6
9
|
import com.getcapacitor.PluginMethod
|
|
7
10
|
import com.getcapacitor.annotation.CapacitorPlugin
|
|
11
|
+
import com.getcapacitor.annotation.Permission
|
|
12
|
+
import com.getcapacitor.annotation.PermissionCallback
|
|
8
13
|
import java.util.concurrent.Executors
|
|
9
14
|
|
|
10
|
-
@CapacitorPlugin(
|
|
15
|
+
@CapacitorPlugin(
|
|
16
|
+
name = "PushSignal",
|
|
17
|
+
permissions = [
|
|
18
|
+
Permission(
|
|
19
|
+
strings = [Manifest.permission.POST_NOTIFICATIONS],
|
|
20
|
+
alias = PushSignalPlugin.PUSH_NOTIFICATIONS,
|
|
21
|
+
),
|
|
22
|
+
],
|
|
23
|
+
)
|
|
11
24
|
class PushSignalPlugin : Plugin() {
|
|
25
|
+
companion object {
|
|
26
|
+
const val PUSH_NOTIFICATIONS = "receive"
|
|
27
|
+
}
|
|
28
|
+
|
|
12
29
|
@Volatile
|
|
13
30
|
private var listening = false
|
|
14
31
|
|
|
@@ -56,6 +73,35 @@ class PushSignalPlugin : Plugin() {
|
|
|
56
73
|
}
|
|
57
74
|
}
|
|
58
75
|
|
|
76
|
+
@PluginMethod
|
|
77
|
+
override fun checkPermissions(call: PluginCall) {
|
|
78
|
+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
|
|
79
|
+
val result = JSObject()
|
|
80
|
+
result.put("receive", "granted")
|
|
81
|
+
call.resolve(result)
|
|
82
|
+
} else {
|
|
83
|
+
super.checkPermissions(call)
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
@PluginMethod
|
|
88
|
+
override fun requestPermissions(call: PluginCall) {
|
|
89
|
+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU ||
|
|
90
|
+
getPermissionState(PUSH_NOTIFICATIONS) == PermissionState.GRANTED
|
|
91
|
+
) {
|
|
92
|
+
val result = JSObject()
|
|
93
|
+
result.put("receive", "granted")
|
|
94
|
+
call.resolve(result)
|
|
95
|
+
} else {
|
|
96
|
+
requestPermissionForAlias(PUSH_NOTIFICATIONS, call, "permissionsCallback")
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
@PermissionCallback
|
|
101
|
+
private fun permissionsCallback(call: PluginCall) {
|
|
102
|
+
checkPermissions(call)
|
|
103
|
+
}
|
|
104
|
+
|
|
59
105
|
@PluginMethod
|
|
60
106
|
fun startListening(call: PluginCall) {
|
|
61
107
|
if (!listening) {
|
package/dist/docs.json
CHANGED
|
@@ -35,6 +35,30 @@
|
|
|
35
35
|
],
|
|
36
36
|
"slug": "getcredentials"
|
|
37
37
|
},
|
|
38
|
+
{
|
|
39
|
+
"name": "checkPermissions",
|
|
40
|
+
"signature": "() => Promise<PermissionStatus>",
|
|
41
|
+
"parameters": [],
|
|
42
|
+
"returns": "Promise<PermissionStatus>",
|
|
43
|
+
"tags": [],
|
|
44
|
+
"docs": "Check permission to receive push notifications.\n\nOn Android 12 and below the status is always granted because you can always\nreceive push notifications.",
|
|
45
|
+
"complexTypes": [
|
|
46
|
+
"PermissionStatus"
|
|
47
|
+
],
|
|
48
|
+
"slug": "checkpermissions"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"name": "requestPermissions",
|
|
52
|
+
"signature": "() => Promise<PermissionStatus>",
|
|
53
|
+
"parameters": [],
|
|
54
|
+
"returns": "Promise<PermissionStatus>",
|
|
55
|
+
"tags": [],
|
|
56
|
+
"docs": "Request permission to receive push notifications.\n\nOn Android 12 and below it does not prompt for permission because you can\nalways receive push notifications.",
|
|
57
|
+
"complexTypes": [
|
|
58
|
+
"PermissionStatus"
|
|
59
|
+
],
|
|
60
|
+
"slug": "requestpermissions"
|
|
61
|
+
},
|
|
38
62
|
{
|
|
39
63
|
"name": "startListening",
|
|
40
64
|
"signature": "() => Promise<void>",
|
|
@@ -168,6 +192,24 @@
|
|
|
168
192
|
}
|
|
169
193
|
]
|
|
170
194
|
},
|
|
195
|
+
{
|
|
196
|
+
"name": "PermissionStatus",
|
|
197
|
+
"slug": "permissionstatus",
|
|
198
|
+
"docs": "",
|
|
199
|
+
"tags": [],
|
|
200
|
+
"methods": [],
|
|
201
|
+
"properties": [
|
|
202
|
+
{
|
|
203
|
+
"name": "receive",
|
|
204
|
+
"tags": [],
|
|
205
|
+
"docs": "",
|
|
206
|
+
"complexTypes": [
|
|
207
|
+
"PermissionState"
|
|
208
|
+
],
|
|
209
|
+
"type": "PermissionState"
|
|
210
|
+
}
|
|
211
|
+
]
|
|
212
|
+
},
|
|
171
213
|
{
|
|
172
214
|
"name": "PluginListenerHandle",
|
|
173
215
|
"slug": "pluginlistenerhandle",
|
|
@@ -256,6 +298,29 @@
|
|
|
256
298
|
}
|
|
257
299
|
]
|
|
258
300
|
},
|
|
301
|
+
{
|
|
302
|
+
"name": "PermissionState",
|
|
303
|
+
"slug": "permissionstate",
|
|
304
|
+
"docs": "",
|
|
305
|
+
"types": [
|
|
306
|
+
{
|
|
307
|
+
"text": "'prompt'",
|
|
308
|
+
"complexTypes": []
|
|
309
|
+
},
|
|
310
|
+
{
|
|
311
|
+
"text": "'prompt-with-rationale'",
|
|
312
|
+
"complexTypes": []
|
|
313
|
+
},
|
|
314
|
+
{
|
|
315
|
+
"text": "'granted'",
|
|
316
|
+
"complexTypes": []
|
|
317
|
+
},
|
|
318
|
+
{
|
|
319
|
+
"text": "'denied'",
|
|
320
|
+
"complexTypes": []
|
|
321
|
+
}
|
|
322
|
+
]
|
|
323
|
+
},
|
|
259
324
|
{
|
|
260
325
|
"name": "Record",
|
|
261
326
|
"slug": "record",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { PluginListenerHandle } from '@capacitor/core';
|
|
2
|
-
import type { AndroidFirebaseConfig, PushCredentials, PushMessage } from './types';
|
|
3
|
-
export type { AndroidFirebaseConfig, OnMessageListener, PushCredentials, PushEnvironment, PushMessage, PushPlatform, } from './types';
|
|
2
|
+
import type { AndroidFirebaseConfig, PermissionStatus, PushCredentials, PushMessage } from './types';
|
|
3
|
+
export type { AndroidFirebaseConfig, OnMessageListener, PermissionStatus, PushCredentials, PushEnvironment, PushMessage, PushPlatform, } from './types';
|
|
4
4
|
export interface PushSignalPlugin {
|
|
5
5
|
/**
|
|
6
6
|
* Bootstrap Android Firebase from client fields (no-op on iOS / incomplete config).
|
|
@@ -10,6 +10,20 @@ export interface PushSignalPlugin {
|
|
|
10
10
|
* Returns APNs (iOS) or FCM (Android) credentials for your server.
|
|
11
11
|
*/
|
|
12
12
|
getCredentials(): Promise<PushCredentials>;
|
|
13
|
+
/**
|
|
14
|
+
* Check permission to receive push notifications.
|
|
15
|
+
*
|
|
16
|
+
* On Android 12 and below the status is always granted because you can always
|
|
17
|
+
* receive push notifications.
|
|
18
|
+
*/
|
|
19
|
+
checkPermissions(): Promise<PermissionStatus>;
|
|
20
|
+
/**
|
|
21
|
+
* Request permission to receive push notifications.
|
|
22
|
+
*
|
|
23
|
+
* On Android 12 and below it does not prompt for permission because you can
|
|
24
|
+
* always receive push notifications.
|
|
25
|
+
*/
|
|
26
|
+
requestPermissions(): Promise<PermissionStatus>;
|
|
13
27
|
/**
|
|
14
28
|
* Start delivering native message / press events to JS listeners.
|
|
15
29
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\n\nimport type { AndroidFirebaseConfig, PushCredentials, PushMessage } from './types';\n\nexport type {\n AndroidFirebaseConfig,\n OnMessageListener,\n PushCredentials,\n PushEnvironment,\n PushMessage,\n PushPlatform,\n} from './types';\n\nexport interface PushSignalPlugin {\n /**\n * Bootstrap Android Firebase from client fields (no-op on iOS / incomplete config).\n */\n initialize(config?: AndroidFirebaseConfig): Promise<void>;\n\n /**\n * Returns APNs (iOS) or FCM (Android) credentials for your server.\n */\n getCredentials(): Promise<PushCredentials>;\n\n /**\n * Start delivering native message / press events to JS listeners.\n */\n startListening(): Promise<void>;\n\n addListener(\n eventName: 'onMessage',\n listenerFunc: (message: PushMessage) => void,\n ): Promise<PluginListenerHandle>;\n\n addListener(\n eventName: 'onNotificationPress',\n listenerFunc: (message: PushMessage) => void,\n ): Promise<PluginListenerHandle>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\n\nimport type { AndroidFirebaseConfig, PermissionStatus, PushCredentials, PushMessage } from './types';\n\nexport type {\n AndroidFirebaseConfig,\n OnMessageListener,\n PermissionStatus,\n PushCredentials,\n PushEnvironment,\n PushMessage,\n PushPlatform,\n} from './types';\n\nexport interface PushSignalPlugin {\n /**\n * Bootstrap Android Firebase from client fields (no-op on iOS / incomplete config).\n */\n initialize(config?: AndroidFirebaseConfig): Promise<void>;\n\n /**\n * Returns APNs (iOS) or FCM (Android) credentials for your server.\n */\n getCredentials(): Promise<PushCredentials>;\n\n /**\n * Check permission to receive push notifications.\n *\n * On Android 12 and below the status is always granted because you can always\n * receive push notifications.\n */\n checkPermissions(): Promise<PermissionStatus>;\n\n /**\n * Request permission to receive push notifications.\n *\n * On Android 12 and below it does not prompt for permission because you can\n * always receive push notifications.\n */\n requestPermissions(): Promise<PermissionStatus>;\n\n /**\n * Start delivering native message / press events to JS listeners.\n */\n startListening(): Promise<void>;\n\n addListener(\n eventName: 'onMessage',\n listenerFunc: (message: PushMessage) => void,\n ): Promise<PluginListenerHandle>;\n\n addListener(\n eventName: 'onNotificationPress',\n listenerFunc: (message: PushMessage) => void,\n ): Promise<PluginListenerHandle>;\n}\n"]}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export type { AndroidFirebaseConfig, OnMessageListener, PushCredentials, PushEnvironment, PushMessage, PushPlatform, PushSignalPlugin, } from './definitions';
|
|
2
|
-
export { getCredentials, initialize, onMessage, onNotificationPress, PushSignal } from './pushSignal';
|
|
1
|
+
export type { AndroidFirebaseConfig, OnMessageListener, PermissionStatus, PushCredentials, PushEnvironment, PushMessage, PushPlatform, PushSignalPlugin, } from './definitions';
|
|
2
|
+
export { checkPermissions, getCredentials, initialize, onMessage, onNotificationPress, PushSignal, requestPermissions, } from './pushSignal';
|
package/dist/esm/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { getCredentials, initialize, onMessage, onNotificationPress, PushSignal } from './pushSignal';
|
|
1
|
+
export { checkPermissions, getCredentials, initialize, onMessage, onNotificationPress, PushSignal, requestPermissions, } from './pushSignal';
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAUA,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,UAAU,EACV,SAAS,EACT,mBAAmB,EACnB,UAAU,EACV,kBAAkB,GACnB,MAAM,cAAc,CAAC","sourcesContent":["export type {\n AndroidFirebaseConfig,\n OnMessageListener,\n PermissionStatus,\n PushCredentials,\n PushEnvironment,\n PushMessage,\n PushPlatform,\n PushSignalPlugin,\n} from './definitions';\nexport {\n checkPermissions,\n getCredentials,\n initialize,\n onMessage,\n onNotificationPress,\n PushSignal,\n requestPermissions,\n} from './pushSignal';\n"]}
|
package/dist/esm/pushSignal.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { PushSignalPlugin } from './definitions';
|
|
2
|
-
import type { AndroidFirebaseConfig, OnMessageListener, PushCredentials, PushMessage } from './types';
|
|
2
|
+
import type { AndroidFirebaseConfig, OnMessageListener, PermissionStatus, PushCredentials, PushMessage } from './types';
|
|
3
3
|
declare const PushSignal: PushSignalPlugin;
|
|
4
4
|
export declare function initialize(config?: AndroidFirebaseConfig): Promise<void>;
|
|
5
5
|
export declare function getCredentials(): Promise<PushCredentials>;
|
|
6
|
+
export declare function checkPermissions(): Promise<PermissionStatus>;
|
|
7
|
+
export declare function requestPermissions(): Promise<PermissionStatus>;
|
|
6
8
|
export declare function onMessage(listener: OnMessageListener): () => void;
|
|
7
9
|
export declare function onNotificationPress(listener: (message: PushMessage) => void): () => void;
|
|
8
10
|
export { PushSignal };
|
package/dist/esm/pushSignal.js
CHANGED
|
@@ -57,6 +57,12 @@ export function initialize(config = {}) {
|
|
|
57
57
|
export function getCredentials() {
|
|
58
58
|
return PushSignal.getCredentials().then(normalizeCredentials);
|
|
59
59
|
}
|
|
60
|
+
export function checkPermissions() {
|
|
61
|
+
return PushSignal.checkPermissions();
|
|
62
|
+
}
|
|
63
|
+
export function requestPermissions() {
|
|
64
|
+
return PushSignal.requestPermissions();
|
|
65
|
+
}
|
|
60
66
|
export function onMessage(listener) {
|
|
61
67
|
bindNativeCallbacks();
|
|
62
68
|
messageListeners.add(listener);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pushSignal.js","sourceRoot":"","sources":["../../src/pushSignal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"pushSignal.js","sourceRoot":"","sources":["../../src/pushSignal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAajD,MAAM,UAAU,GAAG,cAAc,CAAmB,YAAY,EAAE;IAChE,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAA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AG,EAAE;QACV,gBAAgB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IACpC,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,QAAwC;IAC1E,mBAAmB,EAAE,CAAC;IACtB,cAAc,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC7B,OAAO,GAAG,EAAE;QACV,cAAc,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAClC,CAAC,CAAC;AACJ,CAAC;AAED,mBAAmB,EAAE,CAAC;AAEtB,OAAO,EAAE,UAAU,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { PushSignalPlugin } from './definitions';\nimport type {\n AndroidFirebaseConfig,\n OnMessageListener,\n PermissionStatus,\n PushCredentials,\n PushEnvironment,\n PushMessage,\n PushPlatform,\n} from './types';\n\nconst PushSignal = registerPlugin<PushSignalPlugin>('PushSignal', {\n web: () => import('./web').then((m) => new m.PushSignalWeb()),\n});\n\nconst messageListeners = new Set<OnMessageListener>();\nconst pressListeners = new Set<(message: PushMessage) => void>();\nlet nativeCallbacksBound = false;\n\nfunction normalizeMessage(raw: {\n id?: string;\n title?: string;\n body?: string;\n data?: Record<string, unknown> | object;\n}): PushMessage {\n const data: Record<string, string> = {};\n if (raw.data && typeof raw.data === 'object') {\n for (const [key, value] of Object.entries(raw.data as Record<string, unknown>)) {\n if (value == null) {\n continue;\n }\n data[key] = typeof value === 'string' ? value : String(value);\n }\n }\n\n return {\n id: raw.id,\n title: raw.title,\n body: raw.body,\n data,\n };\n}\n\nfunction normalizeCredentials(raw: {\n platform: string;\n token: string;\n environment?: string;\n}): PushCredentials {\n return {\n platform: raw.platform as PushPlatform,\n token: raw.token,\n environment: raw.environment as PushEnvironment | undefined,\n };\n}\n\nfunction bindNativeCallbacks(): void {\n if (nativeCallbacksBound) {\n return;\n }\n\n nativeCallbacksBound = true;\n\n void PushSignal.addListener('onMessage', (raw) => {\n const message = normalizeMessage(raw);\n for (const listener of [...messageListeners]) {\n try {\n Promise.resolve(listener(message)).then(\n () => undefined,\n () => undefined,\n );\n } catch {\n // Ignore listener failures so one bad subscriber cannot break delivery.\n }\n }\n });\n\n void PushSignal.addListener('onNotificationPress', (raw) => {\n const message = normalizeMessage(raw);\n pressListeners.forEach((listener) => listener(message));\n });\n\n void PushSignal.startListening();\n}\n\nexport function initialize(config: AndroidFirebaseConfig = {}): Promise<void> {\n return PushSignal.initialize(config);\n}\n\nexport function getCredentials(): Promise<PushCredentials> {\n return PushSignal.getCredentials().then(normalizeCredentials);\n}\n\nexport function checkPermissions(): Promise<PermissionStatus> {\n return PushSignal.checkPermissions();\n}\n\nexport function requestPermissions(): Promise<PermissionStatus> {\n return PushSignal.requestPermissions();\n}\n\nexport function onMessage(listener: OnMessageListener): () => void {\n bindNativeCallbacks();\n messageListeners.add(listener);\n return () => {\n messageListeners.delete(listener);\n };\n}\n\nexport function onNotificationPress(listener: (message: PushMessage) => void): () => void {\n bindNativeCallbacks();\n pressListeners.add(listener);\n return () => {\n pressListeners.delete(listener);\n };\n}\n\nbindNativeCallbacks();\n\nexport { PushSignal };\n"]}
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
import type { PermissionState } from '@capacitor/core';
|
|
1
2
|
export type PushPlatform = 'ios' | 'android';
|
|
2
3
|
export type PushEnvironment = 'sandbox' | 'production';
|
|
4
|
+
export interface PermissionStatus {
|
|
5
|
+
receive: PermissionState;
|
|
6
|
+
}
|
|
3
7
|
export interface PushCredentials {
|
|
4
8
|
platform: PushPlatform;
|
|
5
9
|
token: string;
|
package/dist/esm/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"","sourcesContent":["
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { PermissionState } from '@capacitor/core';\n\nexport type PushPlatform = 'ios' | 'android';\nexport type PushEnvironment = 'sandbox' | 'production';\n\nexport interface PermissionStatus {\n receive: PermissionState;\n}\n\nexport interface PushCredentials {\n platform: PushPlatform;\n token: string;\n environment?: PushEnvironment;\n}\n\nexport interface PushMessage {\n id?: string;\n title?: string;\n body?: string;\n data: Record<string, string>;\n}\n\nexport type OnMessageListener = (message: PushMessage) => void | Promise<void>;\n\nexport interface AndroidFirebaseConfig {\n project_id?: string;\n mobilesdk_app_id?: string;\n current_key?: string;\n project_number?: string;\n}\n"]}
|
package/dist/esm/web.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { WebPlugin } from '@capacitor/core';
|
|
2
2
|
import type { PushSignalPlugin } from './definitions';
|
|
3
|
-
import type { AndroidFirebaseConfig, PushCredentials } from './types';
|
|
3
|
+
import type { AndroidFirebaseConfig, PermissionStatus, PushCredentials } from './types';
|
|
4
4
|
export declare class PushSignalWeb extends WebPlugin implements PushSignalPlugin {
|
|
5
5
|
initialize(config?: AndroidFirebaseConfig): Promise<void>;
|
|
6
6
|
getCredentials(): Promise<PushCredentials>;
|
|
7
|
+
checkPermissions(): Promise<PermissionStatus>;
|
|
8
|
+
requestPermissions(): Promise<PermissionStatus>;
|
|
7
9
|
startListening(): Promise<void>;
|
|
10
|
+
private mapNotificationPermission;
|
|
8
11
|
}
|
package/dist/esm/web.js
CHANGED
|
@@ -6,8 +6,34 @@ export class PushSignalWeb extends WebPlugin {
|
|
|
6
6
|
async getCredentials() {
|
|
7
7
|
throw this.unimplemented('Push credentials are not supported on web');
|
|
8
8
|
}
|
|
9
|
+
async checkPermissions() {
|
|
10
|
+
if (typeof Notification === 'undefined') {
|
|
11
|
+
return { receive: 'denied' };
|
|
12
|
+
}
|
|
13
|
+
return { receive: this.mapNotificationPermission(Notification.permission) };
|
|
14
|
+
}
|
|
15
|
+
async requestPermissions() {
|
|
16
|
+
if (typeof Notification === 'undefined') {
|
|
17
|
+
return { receive: 'denied' };
|
|
18
|
+
}
|
|
19
|
+
if (Notification.permission === 'default') {
|
|
20
|
+
const permission = await Notification.requestPermission();
|
|
21
|
+
return { receive: this.mapNotificationPermission(permission) };
|
|
22
|
+
}
|
|
23
|
+
return { receive: this.mapNotificationPermission(Notification.permission) };
|
|
24
|
+
}
|
|
9
25
|
async startListening() {
|
|
10
26
|
return;
|
|
11
27
|
}
|
|
28
|
+
mapNotificationPermission(permission) {
|
|
29
|
+
switch (permission) {
|
|
30
|
+
case 'granted':
|
|
31
|
+
return 'granted';
|
|
32
|
+
case 'denied':
|
|
33
|
+
return 'denied';
|
|
34
|
+
default:
|
|
35
|
+
return 'prompt';
|
|
36
|
+
}
|
|
37
|
+
}
|
|
12
38
|
}
|
|
13
39
|
//# sourceMappingURL=web.js.map
|
package/dist/esm/web.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAO5C,MAAM,OAAO,aAAc,SAAQ,SAAS;IAC1C,KAAK,CAAC,UAAU,CAAC,MAA8B;QAC7C,KAAK,MAAM,CAAC;IACd,CAAC;IAED,KAAK,CAAC,cAAc;QAClB,MAAM,IAAI,CAAC,aAAa,CAAC,2CAA2C,CAAC,CAAC;IACxE,CAAC;IAED,KAAK,CAAC,gBAAgB;QACpB,IAAI,OAAO,YAAY,KAAK,WAAW,EAAE,CAAC;YACxC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;QAC/B,CAAC;QAED,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,yBAAyB,CAAC,YAAY,CAAC,UAAU,CAAC,EAAE,CAAC;IAC9E,CAAC;IAED,KAAK,CAAC,kBAAkB;QACtB,IAAI,OAAO,YAAY,KAAK,WAAW,EAAE,CAAC;YACxC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;QAC/B,CAAC;QAED,IAAI,YAAY,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;YAC1C,MAAM,UAAU,GAAG,MAAM,YAAY,CAAC,iBAAiB,EAAE,CAAC;YAC1D,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,yBAAyB,CAAC,UAAU,CAAC,EAAE,CAAC;QACjE,CAAC;QAED,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,yBAAyB,CAAC,YAAY,CAAC,UAAU,CAAC,EAAE,CAAC;IAC9E,CAAC;IAED,KAAK,CAAC,cAAc;QAClB,OAAO;IACT,CAAC;IAEO,yBAAyB,CAAC,UAAkC;QAClE,QAAQ,UAAU,EAAE,CAAC;YACnB,KAAK,SAAS;gBACZ,OAAO,SAAS,CAAC;YACnB,KAAK,QAAQ;gBACX,OAAO,QAAQ,CAAC;YAClB;gBACE,OAAO,QAAQ,CAAC;QACpB,CAAC;IACH,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type { PermissionState } from '@capacitor/core';\n\nimport type { PushSignalPlugin } from './definitions';\nimport type { AndroidFirebaseConfig, PermissionStatus, PushCredentials } from './types';\n\nexport class PushSignalWeb extends WebPlugin implements PushSignalPlugin {\n async initialize(config?: AndroidFirebaseConfig): Promise<void> {\n void config;\n }\n\n async getCredentials(): Promise<PushCredentials> {\n throw this.unimplemented('Push credentials are not supported on web');\n }\n\n async checkPermissions(): Promise<PermissionStatus> {\n if (typeof Notification === 'undefined') {\n return { receive: 'denied' };\n }\n\n return { receive: this.mapNotificationPermission(Notification.permission) };\n }\n\n async requestPermissions(): Promise<PermissionStatus> {\n if (typeof Notification === 'undefined') {\n return { receive: 'denied' };\n }\n\n if (Notification.permission === 'default') {\n const permission = await Notification.requestPermission();\n return { receive: this.mapNotificationPermission(permission) };\n }\n\n return { receive: this.mapNotificationPermission(Notification.permission) };\n }\n\n async startListening(): Promise<void> {\n return;\n }\n\n private mapNotificationPermission(permission: NotificationPermission): PermissionState {\n switch (permission) {\n case 'granted':\n return 'granted';\n case 'denied':\n return 'denied';\n default:\n return 'prompt';\n }\n }\n}\n"]}
|
package/dist/plugin.cjs.js
CHANGED
|
@@ -60,6 +60,12 @@ function initialize(config = {}) {
|
|
|
60
60
|
function getCredentials() {
|
|
61
61
|
return PushSignal.getCredentials().then(normalizeCredentials);
|
|
62
62
|
}
|
|
63
|
+
function checkPermissions() {
|
|
64
|
+
return PushSignal.checkPermissions();
|
|
65
|
+
}
|
|
66
|
+
function requestPermissions() {
|
|
67
|
+
return PushSignal.requestPermissions();
|
|
68
|
+
}
|
|
63
69
|
function onMessage(listener) {
|
|
64
70
|
bindNativeCallbacks();
|
|
65
71
|
messageListeners.add(listener);
|
|
@@ -82,9 +88,35 @@ class PushSignalWeb extends core.WebPlugin {
|
|
|
82
88
|
async getCredentials() {
|
|
83
89
|
throw this.unimplemented('Push credentials are not supported on web');
|
|
84
90
|
}
|
|
91
|
+
async checkPermissions() {
|
|
92
|
+
if (typeof Notification === 'undefined') {
|
|
93
|
+
return { receive: 'denied' };
|
|
94
|
+
}
|
|
95
|
+
return { receive: this.mapNotificationPermission(Notification.permission) };
|
|
96
|
+
}
|
|
97
|
+
async requestPermissions() {
|
|
98
|
+
if (typeof Notification === 'undefined') {
|
|
99
|
+
return { receive: 'denied' };
|
|
100
|
+
}
|
|
101
|
+
if (Notification.permission === 'default') {
|
|
102
|
+
const permission = await Notification.requestPermission();
|
|
103
|
+
return { receive: this.mapNotificationPermission(permission) };
|
|
104
|
+
}
|
|
105
|
+
return { receive: this.mapNotificationPermission(Notification.permission) };
|
|
106
|
+
}
|
|
85
107
|
async startListening() {
|
|
86
108
|
return;
|
|
87
109
|
}
|
|
110
|
+
mapNotificationPermission(permission) {
|
|
111
|
+
switch (permission) {
|
|
112
|
+
case 'granted':
|
|
113
|
+
return 'granted';
|
|
114
|
+
case 'denied':
|
|
115
|
+
return 'denied';
|
|
116
|
+
default:
|
|
117
|
+
return 'prompt';
|
|
118
|
+
}
|
|
119
|
+
}
|
|
88
120
|
}
|
|
89
121
|
|
|
90
122
|
var web = /*#__PURE__*/Object.freeze({
|
|
@@ -93,8 +125,10 @@ var web = /*#__PURE__*/Object.freeze({
|
|
|
93
125
|
});
|
|
94
126
|
|
|
95
127
|
exports.PushSignal = PushSignal;
|
|
128
|
+
exports.checkPermissions = checkPermissions;
|
|
96
129
|
exports.getCredentials = getCredentials;
|
|
97
130
|
exports.initialize = initialize;
|
|
98
131
|
exports.onMessage = onMessage;
|
|
99
132
|
exports.onNotificationPress = onNotificationPress;
|
|
133
|
+
exports.requestPermissions = requestPermissions;
|
|
100
134
|
//# sourceMappingURL=plugin.cjs.js.map
|
package/dist/plugin.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.cjs.js","sources":["esm/pushSignal.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst PushSignal = registerPlugin('PushSignal', {\n web: () => import('./web').then((m) => new m.PushSignalWeb()),\n});\nconst messageListeners = new Set();\nconst pressListeners = new Set();\nlet nativeCallbacksBound = false;\nfunction normalizeMessage(raw) {\n const data = {};\n if (raw.data && typeof raw.data === 'object') {\n for (const [key, value] of Object.entries(raw.data)) {\n if (value == null) {\n continue;\n }\n data[key] = typeof value === 'string' ? value : String(value);\n }\n }\n return {\n id: raw.id,\n title: raw.title,\n body: raw.body,\n data,\n };\n}\nfunction normalizeCredentials(raw) {\n return {\n platform: raw.platform,\n token: raw.token,\n environment: raw.environment,\n };\n}\nfunction bindNativeCallbacks() {\n if (nativeCallbacksBound) {\n return;\n }\n nativeCallbacksBound = true;\n void PushSignal.addListener('onMessage', (raw) => {\n const message = normalizeMessage(raw);\n for (const listener of [...messageListeners]) {\n try {\n Promise.resolve(listener(message)).then(() => undefined, () => undefined);\n }\n catch (_a) {\n // Ignore listener failures so one bad subscriber cannot break delivery.\n }\n }\n });\n void PushSignal.addListener('onNotificationPress', (raw) => {\n const message = normalizeMessage(raw);\n pressListeners.forEach((listener) => listener(message));\n });\n void PushSignal.startListening();\n}\nexport function initialize(config = {}) {\n return PushSignal.initialize(config);\n}\nexport function getCredentials() {\n return PushSignal.getCredentials().then(normalizeCredentials);\n}\nexport function onMessage(listener) {\n bindNativeCallbacks();\n messageListeners.add(listener);\n return () => {\n messageListeners.delete(listener);\n };\n}\nexport function onNotificationPress(listener) {\n bindNativeCallbacks();\n pressListeners.add(listener);\n return () => {\n pressListeners.delete(listener);\n };\n}\nbindNativeCallbacks();\nexport { PushSignal };\n//# sourceMappingURL=pushSignal.js.map","import { WebPlugin } from '@capacitor/core';\nexport class PushSignalWeb extends WebPlugin {\n async initialize(config) {\n void config;\n }\n async getCredentials() {\n throw this.unimplemented('Push credentials are not supported on web');\n }\n async startListening() {\n return;\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,UAAU,GAAGA,mBAAc,CAAC,YAAY,EAAE;AAChD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,aAAa,EAAE,CAAC;AACjE,CAAC;AACD,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAE;AAClC,MAAM,cAAc,GAAG,IAAI,GAAG,EAAE;AAChC,IAAI,oBAAoB,GAAG,KAAK;AAChC,SAAS,gBAAgB,CAAC,GAAG,EAAE;AAC/B,IAAI,MAAM,IAAI,GAAG,EAAE;AACnB,IAAI,IAAI,GAAG,CAAC,IAAI,IAAI,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ,EAAE;AAClD,QAAQ,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;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Q,MAAM,OAAO,GAAG,gBAAgB,CAAC,GAAG,CAAC;AAC7C,QAAQ,cAAc,CAAC,OAAO,CAAC,CAAC,QAAQ,KAAK,QAAQ,CAAC,OAAO,CAAC,CAAC;AAC/D,IAAI,CAAC,CAAC;AACN,IAAI,KAAK,UAAU,CAAC,cAAc,EAAE;AACpC;AACO,SAAS,UAAU,CAAC,MAAM,GAAG,EAAE,EAAE;AACxC,IAAI,OAAO,UAAU,CAAC,UAAU,CAAC,MAAM,CAAC;AACxC;AACO,SAAS,cAAc,GAAG;AACjC,IAAI,OAAO,UAAU,CAAC,cAAc,EAAE,CAAC,IAAI,CAAC,oBAAoB,CAAC;AACjE;AACO,SAAS,SAAS,CAAC,QAAQ,EAAE;AACpC,IAAI,mBAAmB,EAAE;AACzB,IAAI,gBAAgB,CAAC,GAAG,CAAC,QAAQ,CAAC;AAClC,IAAI,OAAO,MAAM;AACjB,QAAQ,gBAAgB,CAAC,MAAM,CAAC,QAAQ,CAAC;AACzC,IAAI,CAAC;AACL;AACO,SAAS,mBAAmB,CAAC,QAAQ,EAAE;AAC9C,IAAI,mBAAmB,EAAE;AACzB,IAAI,cAAc,CAAC,GAAG,CAAC,QAAQ,CAAC;AAChC,IAAI,OAAO,MAAM;AACjB,QAAQ,cAAc,CAAC,MAAM,CAAC,QAAQ,CAAC;AACvC,IAAI,CAAC;AACL;AACA,mBAAmB,EAAE;;
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["esm/pushSignal.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst PushSignal = registerPlugin('PushSignal', {\n web: () => import('./web').then((m) => new m.PushSignalWeb()),\n});\nconst messageListeners = new Set();\nconst pressListeners = new Set();\nlet nativeCallbacksBound = false;\nfunction normalizeMessage(raw) {\n const data = {};\n if (raw.data && typeof raw.data === 'object') {\n for (const [key, value] of Object.entries(raw.data)) {\n if (value == null) {\n continue;\n }\n data[key] = typeof value === 'string' ? value : String(value);\n }\n }\n return {\n id: raw.id,\n title: raw.title,\n body: raw.body,\n data,\n };\n}\nfunction normalizeCredentials(raw) {\n return {\n platform: raw.platform,\n token: raw.token,\n environment: raw.environment,\n };\n}\nfunction bindNativeCallbacks() {\n if (nativeCallbacksBound) {\n return;\n }\n nativeCallbacksBound = true;\n void PushSignal.addListener('onMessage', (raw) => {\n const message = normalizeMessage(raw);\n for (const listener of [...messageListeners]) {\n try {\n Promise.resolve(listener(message)).then(() => undefined, () => undefined);\n }\n catch (_a) {\n // Ignore listener failures so one bad subscriber cannot break delivery.\n }\n }\n });\n void PushSignal.addListener('onNotificationPress', (raw) => {\n const message = normalizeMessage(raw);\n pressListeners.forEach((listener) => listener(message));\n });\n void PushSignal.startListening();\n}\nexport function initialize(config = {}) {\n return PushSignal.initialize(config);\n}\nexport function getCredentials() {\n return PushSignal.getCredentials().then(normalizeCredentials);\n}\nexport function checkPermissions() {\n return PushSignal.checkPermissions();\n}\nexport function requestPermissions() {\n return PushSignal.requestPermissions();\n}\nexport function onMessage(listener) {\n bindNativeCallbacks();\n messageListeners.add(listener);\n return () => {\n messageListeners.delete(listener);\n };\n}\nexport function onNotificationPress(listener) {\n bindNativeCallbacks();\n pressListeners.add(listener);\n return () => {\n pressListeners.delete(listener);\n };\n}\nbindNativeCallbacks();\nexport { PushSignal };\n//# sourceMappingURL=pushSignal.js.map","import { WebPlugin } from '@capacitor/core';\nexport class PushSignalWeb extends WebPlugin {\n async initialize(config) {\n void config;\n }\n async getCredentials() {\n throw this.unimplemented('Push credentials are not supported on web');\n }\n async checkPermissions() {\n if (typeof Notification === 'undefined') {\n return { receive: 'denied' };\n }\n return { receive: this.mapNotificationPermission(Notification.permission) };\n }\n async requestPermissions() {\n if (typeof Notification === 'undefined') {\n return { receive: 'denied' };\n }\n if (Notification.permission === 'default') {\n const permission = await Notification.requestPermission();\n return { receive: this.mapNotificationPermission(permission) };\n }\n return { receive: this.mapNotificationPermission(Notification.permission) };\n }\n async startListening() {\n return;\n }\n mapNotificationPermission(permission) {\n switch (permission) {\n case 'granted':\n return 'granted';\n case 'denied':\n return 'denied';\n default:\n return 'prompt';\n }\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,UAAU,GAAGA,mBAAc,CAAC,YAAY,EAAE;AAChD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,aAAa,EAAE,CAAC;AACjE,CAAC;AACD,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAE;AAClC,MAAM,cAAc,GAAG,IAAI,GAAG,EAAE;AAChC,IAAI,oBAAoB,GAAG,KAAK;AAChC,SAAS,gBAAgB,CAAC,GAAG,EAAE;AAC/B,IAAI,MAAM,IAAI,GAAG,EAAE;AACnB,IAAI,IAAI,GAAG,CAAC,IAAI,IAAI,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ,EAAE;AAClD,QAAQ,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;AAC7D,YAAY,IAAI,KAAK,IAAI,IAAI,EAAE;AAC/B,gBAAgB;AAChB,YAAY;AACZ,YAAY,IAAI,CAAC,GAAG,CAAC,GAAG,OAAO,KAAK,KAAK,QAAQ,GAAG,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;AACzE,QAAQ;AACR,IAAI;AACJ,IAAI,OAAO;AACX,QAAQ,EAAE,EAAE,GAAG,CAAC,EAAE;AAClB,QAAQ,KAAK,EAAE,GAAG,CAAC,KAAK;AACxB,QAAQ,IAAI,EAAE,GAAG,CAAC,IAAI;AACtB,QAAQ,IAAI;AACZ,KAAK;AACL;AACA,SAAS,oBAAoB,CAAC,GAAG,EAAE;AACnC,IAAI,OAAO;AACX,QAAQ,QAAQ,EAAE,GAAG,CAAC,QAAQ;AAC9B,QAAQ,KAAK,EAAE,GAAG,CAAC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AO,EAAE,IAAI,CAAC,yBAAyB,CAAC,UAAU,CAAC,EAAE;AAC1E,QAAQ;AACR,QAAQ,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,yBAAyB,CAAC,YAAY,CAAC,UAAU,CAAC,EAAE;AACnF,IAAI;AACJ,IAAI,MAAM,cAAc,GAAG;AAC3B,QAAQ;AACR,IAAI;AACJ,IAAI,yBAAyB,CAAC,UAAU,EAAE;AAC1C,QAAQ,QAAQ,UAAU;AAC1B,YAAY,KAAK,SAAS;AAC1B,gBAAgB,OAAO,SAAS;AAChC,YAAY,KAAK,QAAQ;AACzB,gBAAgB,OAAO,QAAQ;AAC/B,YAAY;AACZ,gBAAgB,OAAO,QAAQ;AAC/B;AACA,IAAI;AACJ;;;;;;;;;;;;;"}
|
package/dist/plugin.js
CHANGED
|
@@ -59,6 +59,12 @@ var capacitorPushSignal = (function (exports, core) {
|
|
|
59
59
|
function getCredentials() {
|
|
60
60
|
return PushSignal.getCredentials().then(normalizeCredentials);
|
|
61
61
|
}
|
|
62
|
+
function checkPermissions() {
|
|
63
|
+
return PushSignal.checkPermissions();
|
|
64
|
+
}
|
|
65
|
+
function requestPermissions() {
|
|
66
|
+
return PushSignal.requestPermissions();
|
|
67
|
+
}
|
|
62
68
|
function onMessage(listener) {
|
|
63
69
|
bindNativeCallbacks();
|
|
64
70
|
messageListeners.add(listener);
|
|
@@ -81,9 +87,35 @@ var capacitorPushSignal = (function (exports, core) {
|
|
|
81
87
|
async getCredentials() {
|
|
82
88
|
throw this.unimplemented('Push credentials are not supported on web');
|
|
83
89
|
}
|
|
90
|
+
async checkPermissions() {
|
|
91
|
+
if (typeof Notification === 'undefined') {
|
|
92
|
+
return { receive: 'denied' };
|
|
93
|
+
}
|
|
94
|
+
return { receive: this.mapNotificationPermission(Notification.permission) };
|
|
95
|
+
}
|
|
96
|
+
async requestPermissions() {
|
|
97
|
+
if (typeof Notification === 'undefined') {
|
|
98
|
+
return { receive: 'denied' };
|
|
99
|
+
}
|
|
100
|
+
if (Notification.permission === 'default') {
|
|
101
|
+
const permission = await Notification.requestPermission();
|
|
102
|
+
return { receive: this.mapNotificationPermission(permission) };
|
|
103
|
+
}
|
|
104
|
+
return { receive: this.mapNotificationPermission(Notification.permission) };
|
|
105
|
+
}
|
|
84
106
|
async startListening() {
|
|
85
107
|
return;
|
|
86
108
|
}
|
|
109
|
+
mapNotificationPermission(permission) {
|
|
110
|
+
switch (permission) {
|
|
111
|
+
case 'granted':
|
|
112
|
+
return 'granted';
|
|
113
|
+
case 'denied':
|
|
114
|
+
return 'denied';
|
|
115
|
+
default:
|
|
116
|
+
return 'prompt';
|
|
117
|
+
}
|
|
118
|
+
}
|
|
87
119
|
}
|
|
88
120
|
|
|
89
121
|
var web = /*#__PURE__*/Object.freeze({
|
|
@@ -92,10 +124,12 @@ var capacitorPushSignal = (function (exports, core) {
|
|
|
92
124
|
});
|
|
93
125
|
|
|
94
126
|
exports.PushSignal = PushSignal;
|
|
127
|
+
exports.checkPermissions = checkPermissions;
|
|
95
128
|
exports.getCredentials = getCredentials;
|
|
96
129
|
exports.initialize = initialize;
|
|
97
130
|
exports.onMessage = onMessage;
|
|
98
131
|
exports.onNotificationPress = onNotificationPress;
|
|
132
|
+
exports.requestPermissions = requestPermissions;
|
|
99
133
|
|
|
100
134
|
return exports;
|
|
101
135
|
|
package/dist/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sources":["esm/pushSignal.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst PushSignal = registerPlugin('PushSignal', {\n web: () => import('./web').then((m) => new m.PushSignalWeb()),\n});\nconst messageListeners = new Set();\nconst pressListeners = new Set();\nlet nativeCallbacksBound = false;\nfunction normalizeMessage(raw) {\n const data = {};\n if (raw.data && typeof raw.data === 'object') {\n for (const [key, value] of Object.entries(raw.data)) {\n if (value == null) {\n continue;\n }\n data[key] = typeof value === 'string' ? value : String(value);\n }\n }\n return {\n id: raw.id,\n title: raw.title,\n body: raw.body,\n data,\n };\n}\nfunction normalizeCredentials(raw) {\n return {\n platform: raw.platform,\n token: raw.token,\n environment: raw.environment,\n };\n}\nfunction bindNativeCallbacks() {\n if (nativeCallbacksBound) {\n return;\n }\n nativeCallbacksBound = true;\n void PushSignal.addListener('onMessage', (raw) => {\n const message = normalizeMessage(raw);\n for (const listener of [...messageListeners]) {\n try {\n Promise.resolve(listener(message)).then(() => undefined, () => undefined);\n }\n catch (_a) {\n // Ignore listener failures so one bad subscriber cannot break delivery.\n }\n }\n });\n void PushSignal.addListener('onNotificationPress', (raw) => {\n const message = normalizeMessage(raw);\n pressListeners.forEach((listener) => listener(message));\n });\n void PushSignal.startListening();\n}\nexport function initialize(config = {}) {\n return PushSignal.initialize(config);\n}\nexport function getCredentials() {\n return PushSignal.getCredentials().then(normalizeCredentials);\n}\nexport function onMessage(listener) {\n bindNativeCallbacks();\n messageListeners.add(listener);\n return () => {\n messageListeners.delete(listener);\n };\n}\nexport function onNotificationPress(listener) {\n bindNativeCallbacks();\n pressListeners.add(listener);\n return () => {\n pressListeners.delete(listener);\n };\n}\nbindNativeCallbacks();\nexport { PushSignal };\n//# sourceMappingURL=pushSignal.js.map","import { WebPlugin } from '@capacitor/core';\nexport class PushSignalWeb extends WebPlugin {\n async initialize(config) {\n void config;\n }\n async getCredentials() {\n throw this.unimplemented('Push credentials are not supported on web');\n }\n async startListening() {\n return;\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,UAAU,GAAGA,mBAAc,CAAC,YAAY,EAAE;IAChD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,aAAa,EAAE,CAAC;IACjE,CAAC;IACD,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAE;IAClC,MAAM,cAAc,GAAG,IAAI,GAAG,EAAE;IAChC,IAAI,oBAAoB,GAA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in } from '@capacitor/core';\nconst PushSignal = registerPlugin('PushSignal', {\n web: () => import('./web').then((m) => new m.PushSignalWeb()),\n});\nconst messageListeners = new Set();\nconst pressListeners = new Set();\nlet nativeCallbacksBound = false;\nfunction normalizeMessage(raw) {\n const data = {};\n if (raw.data && typeof raw.data === 'object') {\n for (const [key, value] of Object.entries(raw.data)) {\n if (value == null) {\n continue;\n }\n data[key] = typeof value === 'string' ? value : String(value);\n }\n }\n return {\n id: raw.id,\n title: raw.title,\n body: raw.body,\n data,\n };\n}\nfunction normalizeCredentials(raw) {\n return {\n platform: raw.platform,\n token: raw.token,\n environment: raw.environment,\n };\n}\nfunction bindNativeCallbacks() {\n if (nativeCallbacksBound) {\n return;\n }\n nativeCallbacksBound = true;\n void PushSignal.addListener('onMessage', (raw) => {\n const message = normalizeMessage(raw);\n for (const listener of [...messageListeners]) {\n try {\n Promise.resolve(listener(message)).then(() => undefined, () => undefined);\n }\n catch (_a) {\n // Ignore listener failures so one bad subscriber cannot break delivery.\n }\n }\n });\n void PushSignal.addListener('onNotificationPress', (raw) => {\n const message = normalizeMessage(raw);\n pressListeners.forEach((listener) => listener(message));\n });\n void PushSignal.startListening();\n}\nexport function initialize(config = {}) {\n return PushSignal.initialize(config);\n}\nexport function getCredentials() {\n return PushSignal.getCredentials().then(normalizeCredentials);\n}\nexport function checkPermissions() {\n return PushSignal.checkPermissions();\n}\nexport function requestPermissions() {\n return PushSignal.requestPermissions();\n}\nexport function onMessage(listener) {\n bindNativeCallbacks();\n messageListeners.add(listener);\n return () => {\n messageListeners.delete(listener);\n };\n}\nexport function onNotificationPress(listener) {\n bindNativeCallbacks();\n pressListeners.add(listener);\n return () => {\n pressListeners.delete(listener);\n };\n}\nbindNativeCallbacks();\nexport { PushSignal };\n//# sourceMappingURL=pushSignal.js.map","import { WebPlugin } from '@capacitor/core';\nexport class PushSignalWeb extends WebPlugin {\n async initialize(config) {\n void config;\n }\n async getCredentials() {\n throw this.unimplemented('Push credentials are not supported on web');\n }\n async checkPermissions() {\n if (typeof Notification === 'undefined') {\n return { receive: 'denied' };\n }\n return { receive: this.mapNotificationPermission(Notification.permission) };\n }\n async requestPermissions() {\n if (typeof Notification === 'undefined') {\n return { receive: 'denied' };\n }\n if (Notification.permission === 'default') {\n const permission = await Notification.requestPermission();\n return { receive: this.mapNotificationPermission(permission) };\n }\n return { receive: this.mapNotificationPermission(Notification.permission) };\n }\n async startListening() {\n return;\n }\n mapNotificationPermission(permission) {\n switch (permission) {\n case 'granted':\n return 'granted';\n case 'denied':\n return 'denied';\n default:\n return 'prompt';\n }\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,UAAU,GAAGA,mBAAc,CAAC,YAAY,EAAE;IAChD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,aAAa,EAAE,CAAC;IACjE,CAAC;IACD,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAE;IAClC,MAAM,cAAc,GAAG,IAAI,GAAG,EAAE;IAChC,IAAI,oBAAoB,GAAG,KAAK;IAChC,SAAS,gBAAgB,CAAC,GAAG,EAAE;IAC/B,IAAI,MAAM,IAAI,GAAG,EAAE;IACnB,IAAI,IAAI,GAAG,CAAC,IAAI,IAAI,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ,EAAE;IAClD,QAAQ,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;IAC7D,YAAY,IAAI,KAAK,IAAI,IAAI,EAAE;IAC/B,gBAAgB;IAChB,YAAY;IACZ,YAAY,IAAI,CAAC,GAAG,CAAC,GAAG,OAAO,KAAK,KAAK,QAAQ,GAAG,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;IACzE,QAAQ;IACR,IAAI;IACJ,IAAI,OAAO;IACX,QAAQ,EAAE,EAAE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I,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,IAAI,OAAO,YAAY,KAAK,WAAW,EAAE;IACjD,YAAY,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE;IACxC,QAAQ;IACR,QAAQ,IAAI,YAAY,CAAC,UAAU,KAAK,SAAS,EAAE;IACnD,YAAY,MAAM,UAAU,GAAG,MAAM,YAAY,CAAC,iBAAiB,EAAE;IACrE,YAAY,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,yBAAyB,CAAC,UAAU,CAAC,EAAE;IAC1E,QAAQ;IACR,QAAQ,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,yBAAyB,CAAC,YAAY,CAAC,UAAU,CAAC,EAAE;IACnF,IAAI;IACJ,IAAI,MAAM,cAAc,GAAG;IAC3B,QAAQ;IACR,IAAI;IACJ,IAAI,yBAAyB,CAAC,UAAU,EAAE;IAC1C,QAAQ,QAAQ,UAAU;IAC1B,YAAY,KAAK,SAAS;IAC1B,gBAAgB,OAAO,SAAS;IAChC,YAAY,KAAK,QAAQ;IACzB,gBAAgB,OAAO,QAAQ;IAC/B,YAAY;IACZ,gBAAgB,OAAO,QAAQ;IAC/B;IACA,IAAI;IACJ;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import Foundation
|
|
2
2
|
import Capacitor
|
|
3
|
+
import UserNotifications
|
|
3
4
|
#if canImport(PushSignalCore)
|
|
4
5
|
import PushSignalCore
|
|
5
6
|
#endif
|
|
6
7
|
|
|
8
|
+
private enum PushSignalPermissions: String {
|
|
9
|
+
case prompt
|
|
10
|
+
case denied
|
|
11
|
+
case granted
|
|
12
|
+
}
|
|
13
|
+
|
|
7
14
|
@objc(PushSignalPlugin)
|
|
8
15
|
public class PushSignalPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
9
16
|
public let identifier = "PushSignalPlugin"
|
|
@@ -11,6 +18,8 @@ public class PushSignalPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
11
18
|
public let pluginMethods: [CAPPluginMethod] = [
|
|
12
19
|
CAPPluginMethod(name: "initialize", returnType: CAPPluginReturnPromise),
|
|
13
20
|
CAPPluginMethod(name: "getCredentials", returnType: CAPPluginReturnPromise),
|
|
21
|
+
CAPPluginMethod(name: "checkPermissions", returnType: CAPPluginReturnPromise),
|
|
22
|
+
CAPPluginMethod(name: "requestPermissions", returnType: CAPPluginReturnPromise),
|
|
14
23
|
CAPPluginMethod(name: "startListening", returnType: CAPPluginReturnPromise)
|
|
15
24
|
]
|
|
16
25
|
|
|
@@ -35,6 +44,37 @@ public class PushSignalPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
35
44
|
)
|
|
36
45
|
}
|
|
37
46
|
|
|
47
|
+
@objc override public func requestPermissions(_ call: CAPPluginCall) {
|
|
48
|
+
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in
|
|
49
|
+
if let error = error {
|
|
50
|
+
call.reject(error.localizedDescription)
|
|
51
|
+
return
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
let result: PushSignalPermissions = granted ? .granted : .denied
|
|
55
|
+
call.resolve(["receive": result.rawValue])
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@objc override public func checkPermissions(_ call: CAPPluginCall) {
|
|
60
|
+
UNUserNotificationCenter.current().getNotificationSettings { settings in
|
|
61
|
+
var result: PushSignalPermissions = .prompt
|
|
62
|
+
|
|
63
|
+
switch settings.authorizationStatus {
|
|
64
|
+
case .notDetermined:
|
|
65
|
+
result = .prompt
|
|
66
|
+
case .denied:
|
|
67
|
+
result = .denied
|
|
68
|
+
case .ephemeral, .authorized, .provisional:
|
|
69
|
+
result = .granted
|
|
70
|
+
@unknown default:
|
|
71
|
+
result = .prompt
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
call.resolve(["receive": result.rawValue])
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
38
78
|
@objc func startListening(_ call: CAPPluginCall) {
|
|
39
79
|
if !listening {
|
|
40
80
|
listening = true
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "capacitor-push-signal",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Capacitor push credentials and notification listeners (APNs / FCM)",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -77,4 +77,4 @@
|
|
|
77
77
|
"src": "android"
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
|
-
}
|
|
80
|
+
}
|