@rivium/push-web 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Rivium
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,276 @@
1
+ # RiviumPush Web SDK
2
+
3
+ Real-time push notifications for browsers. No Firebase dependency.
4
+
5
+ ## Features
6
+
7
+ - Real-time push notifications via WebSocket
8
+ - Web Push (VAPID) for background notifications when browser is closed
9
+ - Rich notifications (images, action buttons, badges, deep links)
10
+ - Topic subscriptions
11
+ - Auto-reconnection with exponential backoff
12
+ - Network and visibility state monitoring
13
+ - Badge management (Badge API + favicon fallback)
14
+ - Localization support
15
+ - Analytics tracking
16
+ - TypeScript support
17
+ - Works with any framework (React, Vue, Angular, vanilla JS)
18
+
19
+ ## Installation
20
+
21
+ ### NPM
22
+
23
+ ```bash
24
+ npm install @rivium/push-web
25
+ ```
26
+
27
+ ### CDN (UMD)
28
+
29
+ ```html
30
+ <script src="https://unpkg.com/@rivium/push-web/dist/index.umd.js"></script>
31
+ ```
32
+
33
+ ### CDN (ES Module)
34
+
35
+ ```html
36
+ <script type="module">
37
+ import RiviumPush from 'https://unpkg.com/@rivium/push-web/dist/index.esm.js';
38
+ </script>
39
+ ```
40
+
41
+ ## Service Worker Setup
42
+
43
+ Copy the service worker file to your public directory:
44
+
45
+ ```bash
46
+ # NPM
47
+ cp node_modules/@rivium/push-web/service-worker.js public/rivium-push-sw.js
48
+
49
+ # CDN
50
+ curl -o public/rivium-push-sw.js https://unpkg.com/@rivium/push-web/service-worker.js
51
+ ```
52
+
53
+ ## Quick Start
54
+
55
+ ```typescript
56
+ import RiviumPush from '@rivium/push-web';
57
+
58
+ // Initialize
59
+ const riviumPush = new RiviumPush({
60
+ apiKey: 'rv_live_your_api_key', // Get from Rivium Console
61
+ });
62
+
63
+ // Set up callbacks
64
+ riviumPush.onMessage((message) => {
65
+ console.log('Title:', message.title);
66
+ console.log('Body:', message.body);
67
+ console.log('Data:', message.data);
68
+ });
69
+
70
+ riviumPush.onConnectionState((state) => {
71
+ console.log('Connection:', state); // 'connected' | 'disconnected' | 'connecting'
72
+ });
73
+
74
+ riviumPush.onRegistered((deviceId) => {
75
+ console.log('Device ID:', deviceId);
76
+ });
77
+
78
+ // Register device (requests notification permission automatically)
79
+ const deviceId = await riviumPush.register({ userId: 'user_123' });
80
+ ```
81
+
82
+ ## Configuration
83
+
84
+ ```typescript
85
+ const riviumPush = new RiviumPush({
86
+ apiKey: 'rv_live_...', // Required - from Rivium Console
87
+ serviceWorkerPath: '/rivium-push-sw.js', // Optional - service worker path
88
+ autoRegisterServiceWorker: true, // Optional - auto register SW (default: true)
89
+ mqttQos: 1, // Optional - MQTT QoS level (default: 1)
90
+ maxReconnectAttempts: 10, // Optional - max reconnect attempts (default: 10)
91
+ logLevel: RiviumPushLogLevel.ERROR, // Optional - log level
92
+ });
93
+ ```
94
+
95
+ ## Callbacks
96
+
97
+ All event handlers return an unsubscribe function.
98
+
99
+ ```typescript
100
+ // Receive messages (foreground)
101
+ const unsub = riviumPush.onMessage((message) => {
102
+ console.log(message.title, message.body);
103
+ });
104
+
105
+ // Connection state
106
+ riviumPush.onConnectionState((state) => {
107
+ // 'connecting' | 'connected' | 'disconnected' | 'error'
108
+ });
109
+
110
+ // Registration complete
111
+ riviumPush.onRegistered((deviceId) => {});
112
+
113
+ // Background notification click
114
+ riviumPush.onNotificationClick((message, action) => {
115
+ if (message.deepLink) {
116
+ window.location.href = message.deepLink;
117
+ }
118
+ });
119
+
120
+ // Action button click
121
+ riviumPush.onActionClicked((actionId, message) => {
122
+ console.log('Action:', actionId);
123
+ });
124
+
125
+ // Errors
126
+ riviumPush.onError((error) => {});
127
+ riviumPush.onDetailedError((error) => {
128
+ console.log('Code:', error.code, 'Message:', error.message);
129
+ });
130
+
131
+ // Reconnection
132
+ riviumPush.onReconnecting((state) => {
133
+ console.log('Attempt:', state.retryAttempt, 'Next in:', state.nextRetryMs, 'ms');
134
+ });
135
+
136
+ // Network state
137
+ riviumPush.onNetworkState((state) => {
138
+ console.log('Online:', state.isAvailable, 'Type:', state.networkType);
139
+ });
140
+
141
+ // App visibility
142
+ riviumPush.onAppState((state) => {
143
+ console.log('Visible:', state.isVisible);
144
+ });
145
+
146
+ // Clean up
147
+ unsub();
148
+ ```
149
+
150
+ ## Topics
151
+
152
+ ```typescript
153
+ await riviumPush.subscribeTopic('news');
154
+ await riviumPush.subscribeTopic('promotions');
155
+ await riviumPush.unsubscribeTopic('promotions');
156
+ ```
157
+
158
+ ## User Management
159
+
160
+ ```typescript
161
+ // Set user ID after login
162
+ await riviumPush.setUserId('user_123');
163
+
164
+ // Clear user ID on logout
165
+ riviumPush.clearUserId();
166
+
167
+ // Register with user ID
168
+ await riviumPush.register({ userId: 'user_123' });
169
+ ```
170
+
171
+ ## Badge Management
172
+
173
+ ```typescript
174
+ riviumPush.setBadgeCount(5);
175
+ riviumPush.clearBadge();
176
+ const count = riviumPush.getBadgeCount();
177
+ ```
178
+
179
+ ## Analytics
180
+
181
+ ```typescript
182
+ riviumPush.setAnalyticsHandler((event, properties) => {
183
+ // Send to your analytics service
184
+ analytics.track(`rivium_push_${event}`, properties);
185
+ });
186
+
187
+ riviumPush.disableAnalytics();
188
+ ```
189
+
190
+ ## Log Levels
191
+
192
+ ```typescript
193
+ import { RiviumPushLogLevel } from '@rivium/push-web';
194
+
195
+ riviumPush.setLogLevel(RiviumPushLogLevel.DEBUG); // Development
196
+ riviumPush.setLogLevel(RiviumPushLogLevel.ERROR); // Production
197
+
198
+ // Available: NONE, ERROR, WARNING, INFO, DEBUG, VERBOSE
199
+ ```
200
+
201
+ ## Utilities
202
+
203
+ ```typescript
204
+ const connected = riviumPush.isConnected();
205
+ const deviceId = riviumPush.getDeviceId();
206
+ const network = riviumPush.getNetworkState();
207
+ const appState = riviumPush.getAppState();
208
+ const initialMessage = riviumPush.getInitialMessage();
209
+
210
+ // Static methods
211
+ RiviumPush.isSupported();
212
+ RiviumPush.getPermissionStatus();
213
+
214
+ // Unregister
215
+ await riviumPush.unregister();
216
+ ```
217
+
218
+ ## CDN Usage (HTML)
219
+
220
+ ```html
221
+ <!DOCTYPE html>
222
+ <html>
223
+ <head>
224
+ <title>My App</title>
225
+ </head>
226
+ <body>
227
+ <script src="https://unpkg.com/@rivium/push-web/dist/index.umd.js"></script>
228
+ <script>
229
+ const riviumPush = new RiviumPushWeb.default({
230
+ apiKey: 'rv_live_your_api_key',
231
+ });
232
+
233
+ riviumPush.onMessage(function(message) {
234
+ console.log('Received:', message.title);
235
+ });
236
+
237
+ riviumPush.onConnectionState(function(state) {
238
+ console.log('Connection:', state);
239
+ });
240
+
241
+ riviumPush.register().then(function(deviceId) {
242
+ console.log('Registered:', deviceId);
243
+ });
244
+ </script>
245
+ </body>
246
+ </html>
247
+ ```
248
+
249
+ ## Browser Support
250
+
251
+ - Chrome 50+ (Desktop & Android)
252
+ - Firefox 44+
253
+ - Edge 17+
254
+ - Safari 16+ (macOS only, iOS does not support Web Push)
255
+ - Opera 37+
256
+
257
+ ## Requirements
258
+
259
+ - HTTPS required (localhost works for development)
260
+ - Service worker file must be in the public root directory
261
+
262
+ ## Example
263
+
264
+ See the [web_example](web_example/) directory for a complete interactive demo with all features.
265
+
266
+ The Push SDK works independently without VoIP.
267
+
268
+ ## Links
269
+
270
+ - [Rivium Push](https://rivium.co/cloud/rivium-push) - Learn more about Rivium Push
271
+ - [Documentation](https://rivium.co/cloud/rivium-push/docs/quick-start) - Full documentation and guides
272
+ - [Rivium Console](https://console.rivium.co) - Manage your push notifications
273
+
274
+ ## License
275
+
276
+ MIT License - see [LICENSE](LICENSE) for details.