mbnotify-app 1.0.4 โ 1.0.5
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 +291 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
|
|
2
|
+
---
|
|
3
|
+
|
|
4
|
+
# ๐ mbnotify Ecosystem
|
|
5
|
+
|
|
6
|
+
A **real-time push notification system** for web & mobile apps powered by MQTT.
|
|
7
|
+
|
|
8
|
+
This ecosystem consists of two packages:
|
|
9
|
+
|
|
10
|
+
* ๐ฆ **mbnotify** โ Send notifications (Backend / Server)
|
|
11
|
+
* ๐ฑ **mbnotify-app** โ Receive notifications (Expo / React Native)
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
# ๐ฆ 1. mbnotify (Server / Sender)
|
|
16
|
+
|
|
17
|
+
Send push notifications to devices instantly.
|
|
18
|
+
|
|
19
|
+
## ๐ฅ Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install mbnotify
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## โก Usage
|
|
26
|
+
|
|
27
|
+
```js
|
|
28
|
+
import { sendNotification } from "mbnotify";
|
|
29
|
+
|
|
30
|
+
await sendNotification({
|
|
31
|
+
appName: "myapp",
|
|
32
|
+
token: "dev_xxxxxxxxxxxxx",
|
|
33
|
+
|
|
34
|
+
title: "Order Shipped ๐",
|
|
35
|
+
body: "Your order has been shipped!",
|
|
36
|
+
|
|
37
|
+
icon: "https://cdn-icons-png.flaticon.com/512/1827/1827392.png",
|
|
38
|
+
image: "https://images.unsplash.com/photo-1586528116311-ad8dd3c8310d?w=1200",
|
|
39
|
+
|
|
40
|
+
url: "https://google.com",
|
|
41
|
+
|
|
42
|
+
data: {
|
|
43
|
+
orderId: "12345"
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
console.log("โ
Notification sent");
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## ๐งพ Payload Options
|
|
53
|
+
|
|
54
|
+
| Field | Type | Description |
|
|
55
|
+
| ------- | ------ | -------------------- |
|
|
56
|
+
| appName | string | App identifier |
|
|
57
|
+
| token | string | Device token |
|
|
58
|
+
| title | string | Notification title |
|
|
59
|
+
| body | string | Notification message |
|
|
60
|
+
| icon | string | Small icon URL |
|
|
61
|
+
| image | string | Large image URL |
|
|
62
|
+
| url | string | Deep link / redirect |
|
|
63
|
+
| data | object | Custom payload |
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## ๐ฏ Features
|
|
68
|
+
|
|
69
|
+
* โก Real-time delivery
|
|
70
|
+
* ๐ Works globally via MQTT
|
|
71
|
+
* ๐ฆ Lightweight API
|
|
72
|
+
* ๐ Supports deep linking
|
|
73
|
+
* ๐ง Custom data payloads
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
# ๐ฑ 2. mbnotify-app (Client / Receiver)
|
|
78
|
+
|
|
79
|
+
Receive notifications inside your **Expo / React Native app**.
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## ๐ฅ Installation
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
npm install mbnotify-app
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Also install Expo notifications:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
npx expo install expo-notifications
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## โ๏ธ Setup
|
|
98
|
+
|
|
99
|
+
### โ
Required Fix (VERY IMPORTANT)
|
|
100
|
+
|
|
101
|
+
React Native doesn't support some Node modules by default:
|
|
102
|
+
|
|
103
|
+
```js
|
|
104
|
+
import { Buffer } from "buffer";
|
|
105
|
+
import process from "process";
|
|
106
|
+
|
|
107
|
+
global.Buffer = Buffer;
|
|
108
|
+
global.process = process;
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## ๐ Basic Usage
|
|
114
|
+
|
|
115
|
+
```js
|
|
116
|
+
import { useEffect, useState } from "react";
|
|
117
|
+
import { Text, View } from "react-native";
|
|
118
|
+
import * as Notifications from "expo-notifications";
|
|
119
|
+
|
|
120
|
+
import { requestPermission, getToken } from "mbnotify-app";
|
|
121
|
+
|
|
122
|
+
// Show notifications in foreground
|
|
123
|
+
Notifications.setNotificationHandler({
|
|
124
|
+
handleNotification: async () => ({
|
|
125
|
+
shouldShowAlert: true,
|
|
126
|
+
shouldPlaySound: true,
|
|
127
|
+
shouldSetBadge: false,
|
|
128
|
+
}),
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
export default function App() {
|
|
132
|
+
|
|
133
|
+
const [token, setToken] = useState(null);
|
|
134
|
+
const [status, setStatus] = useState("Initializing...");
|
|
135
|
+
|
|
136
|
+
useEffect(() => {
|
|
137
|
+
|
|
138
|
+
async function init() {
|
|
139
|
+
|
|
140
|
+
try {
|
|
141
|
+
setStatus("Requesting permission...");
|
|
142
|
+
|
|
143
|
+
const granted = await requestPermission();
|
|
144
|
+
|
|
145
|
+
if (!granted) {
|
|
146
|
+
setStatus("โ Permission denied");
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
setStatus("Connecting...");
|
|
151
|
+
|
|
152
|
+
const deviceToken = await getToken("myapp");
|
|
153
|
+
|
|
154
|
+
setToken(deviceToken);
|
|
155
|
+
setStatus("โ
Connected");
|
|
156
|
+
|
|
157
|
+
console.log("๐ฑ Device token:", deviceToken);
|
|
158
|
+
|
|
159
|
+
} catch (err) {
|
|
160
|
+
console.error(err);
|
|
161
|
+
setStatus("โ Error initializing");
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
init();
|
|
167
|
+
|
|
168
|
+
}, []);
|
|
169
|
+
|
|
170
|
+
return (
|
|
171
|
+
<View>
|
|
172
|
+
<Text>{status}</Text>
|
|
173
|
+
{token && <Text>{token}</Text>}
|
|
174
|
+
</View>
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
## ๐ Functions
|
|
182
|
+
|
|
183
|
+
### `requestPermission()`
|
|
184
|
+
|
|
185
|
+
```js
|
|
186
|
+
const granted = await requestPermission();
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
* Requests notification permission
|
|
190
|
+
* Returns `true` / `false`
|
|
191
|
+
|
|
192
|
+
---
|
|
193
|
+
|
|
194
|
+
### `getToken(appName)`
|
|
195
|
+
|
|
196
|
+
```js
|
|
197
|
+
const token = await getToken("myapp");
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
* Connects to MQTT
|
|
201
|
+
* Returns a **unique device token**
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
## ๐ฒ Flow Overview
|
|
206
|
+
|
|
207
|
+
```text
|
|
208
|
+
[mbnotify-app] โ Generates Token
|
|
209
|
+
โ
|
|
210
|
+
[Your Server] โ Stores Token
|
|
211
|
+
โ
|
|
212
|
+
[mbnotify] โ Sends Notification
|
|
213
|
+
โ
|
|
214
|
+
[Device] โ Receives Notification ๐
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
## ๐ฅ Features
|
|
220
|
+
|
|
221
|
+
* ๐ก Real-time notifications (MQTT)
|
|
222
|
+
* ๐ฑ Expo compatible
|
|
223
|
+
* ๐ Foreground + Background support
|
|
224
|
+
* ๐ Unique device tokens
|
|
225
|
+
* โก Fast & lightweight
|
|
226
|
+
|
|
227
|
+
---
|
|
228
|
+
|
|
229
|
+
## โ ๏ธ Common Issues
|
|
230
|
+
|
|
231
|
+
### โ MQTT Errors in React Native
|
|
232
|
+
|
|
233
|
+
Fix:
|
|
234
|
+
|
|
235
|
+
```js
|
|
236
|
+
global.Buffer = require("buffer").Buffer;
|
|
237
|
+
global.process = require("process");
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
---
|
|
241
|
+
|
|
242
|
+
### โ Notifications not showing
|
|
243
|
+
|
|
244
|
+
Make sure:
|
|
245
|
+
|
|
246
|
+
* Permission is granted
|
|
247
|
+
* `Notifications.setNotificationHandler` is configured
|
|
248
|
+
* App is not restricted by OS battery settings
|
|
249
|
+
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
## ๐ก Best Practices
|
|
253
|
+
|
|
254
|
+
* Store tokens securely in DB
|
|
255
|
+
* Use meaningful `appName`
|
|
256
|
+
* Avoid sending too many notifications
|
|
257
|
+
* Use `data` for deep linking/navigation
|
|
258
|
+
|
|
259
|
+
---
|
|
260
|
+
|
|
261
|
+
## ๐งช Example Use Case
|
|
262
|
+
|
|
263
|
+
* ๐ E-commerce โ Order updates
|
|
264
|
+
* ๐ฌ Chat app โ New messages
|
|
265
|
+
* ๐ฆ Delivery โ Status tracking
|
|
266
|
+
* ๐ SaaS โ Alerts & updates
|
|
267
|
+
|
|
268
|
+
---
|
|
269
|
+
|
|
270
|
+
## ๐จโ๐ป Author
|
|
271
|
+
|
|
272
|
+
**Manoj Gowda B R**
|
|
273
|
+
Full Stack Developer (MERN)
|
|
274
|
+
|
|
275
|
+
---
|
|
276
|
+
|
|
277
|
+
## ๐ Support
|
|
278
|
+
|
|
279
|
+
If you like this project:
|
|
280
|
+
|
|
281
|
+
โญ Star the repo
|
|
282
|
+
๐ Report issues
|
|
283
|
+
๐ Contribute improvements
|
|
284
|
+
|
|
285
|
+
---
|
|
286
|
+
|
|
287
|
+
## ๐ License
|
|
288
|
+
|
|
289
|
+
MIT License
|
|
290
|
+
|
|
291
|
+
---
|