@tencentcloud/web-push 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/CHANGELOG.md +5 -0
- package/README.md +89 -3
- package/index.esm.js +10 -15550
- package/index.umd.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -21,20 +21,54 @@ A web-based push notification SDK built on modern Web APIs including Service Wor
|
|
|
21
21
|
|
|
22
22
|
## Integration Step
|
|
23
23
|
|
|
24
|
-
### Step 1:
|
|
24
|
+
### Step 1: Install Web Push SDK
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
**Option 1: NPM Installation**
|
|
27
27
|
|
|
28
28
|
```bash
|
|
29
29
|
npm install @tencentcloud/web-push --save
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
or
|
|
33
33
|
|
|
34
34
|
```bash
|
|
35
35
|
yarn add @tencentcloud/web-push
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
+
**Option 2: CDN Integration (UMD)**
|
|
39
|
+
|
|
40
|
+
Include directly via `<script>` tag:
|
|
41
|
+
|
|
42
|
+
```html
|
|
43
|
+
<!-- Include TencentCloudChat SDK (Professional Edition) -->
|
|
44
|
+
<script src="https://unpkg.com/@tencentcloud/lite-chat/professional.js"></script>
|
|
45
|
+
|
|
46
|
+
<!-- Include Web Push SDK -->
|
|
47
|
+
<script src="https://unpkg.com/@tencentcloud/web-push/index.umd.js"></script>
|
|
48
|
+
|
|
49
|
+
<script>
|
|
50
|
+
// SDK will be mounted to global variable WebPushSDK
|
|
51
|
+
const webPush = WebPushSDK.webPush;
|
|
52
|
+
|
|
53
|
+
// Usage is the same as ES6 modules
|
|
54
|
+
webPush.registerPush({
|
|
55
|
+
SDKAppID: 1400000000,
|
|
56
|
+
appKey: 'your-app-key',
|
|
57
|
+
userID: 'test-user-001',
|
|
58
|
+
});
|
|
59
|
+
</script>
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Or download and use locally:
|
|
63
|
+
|
|
64
|
+
```html
|
|
65
|
+
<!-- Include Chat SDK -->
|
|
66
|
+
<script src="./path/to/chat-sdk.js"></script>
|
|
67
|
+
|
|
68
|
+
<!-- Include Web Push SDK -->
|
|
69
|
+
<script src="./dist/index.umd.js"></script>
|
|
70
|
+
```
|
|
71
|
+
|
|
38
72
|
### Step 2: Configure the Service Worker File
|
|
39
73
|
|
|
40
74
|
After integrating `@tencentcloud/web-push`, copy the **Service Worker (sw.js)** to your project's **root directory**. After website deployment, ensure this file can be accessed through `https://your-domain.com/sw.js`. Otherwise, the browser will be unable to register the **Service Worker**.
|
|
@@ -122,6 +156,58 @@ WebPush.addPushListener(WebPush.EVENT.NOTIFICATION_CLICKED, (data) => {
|
|
|
122
156
|
});
|
|
123
157
|
```
|
|
124
158
|
|
|
159
|
+
### UMD Usage (Script Tag)
|
|
160
|
+
|
|
161
|
+
> **Important**: When using UMD integration, you must include the TencentCloudChat SDK (Professional Edition) first, otherwise you'll encounter "Cannot read properties of undefined (reading 'create')" error.
|
|
162
|
+
|
|
163
|
+
If you're using UMD integration, here's an example:
|
|
164
|
+
|
|
165
|
+
```html
|
|
166
|
+
<!DOCTYPE html>
|
|
167
|
+
<html>
|
|
168
|
+
<head>
|
|
169
|
+
<title>Web Push SDK UMD Example</title>
|
|
170
|
+
</head>
|
|
171
|
+
<body>
|
|
172
|
+
<!-- Include TencentCloudChat SDK (Professional Edition) -->
|
|
173
|
+
<script src="https://unpkg.com/@tencentcloud/lite-chat/professional.js"></script>
|
|
174
|
+
|
|
175
|
+
<!-- Include Web Push SDK -->
|
|
176
|
+
<script src="https://unpkg.com/@tencentcloud/web-push/index.umd.js"></script>
|
|
177
|
+
|
|
178
|
+
<script>
|
|
179
|
+
// Get SDK instance
|
|
180
|
+
const webPush = WebPushSDK.webPush;
|
|
181
|
+
|
|
182
|
+
// Configuration parameters
|
|
183
|
+
const SDKAppID = 1400000000; // Your SDKAppID
|
|
184
|
+
const appKey = 'your-app-key'; // Client key
|
|
185
|
+
const userID = 'test-user-001'; // User ID
|
|
186
|
+
|
|
187
|
+
// Register push service
|
|
188
|
+
webPush
|
|
189
|
+
.registerPush({ SDKAppID, appKey, userID })
|
|
190
|
+
.then((registrationID) => {
|
|
191
|
+
console.log('Registration successful:', registrationID);
|
|
192
|
+
})
|
|
193
|
+
.catch((error) => {
|
|
194
|
+
console.error('Registration failed:', error);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
// Listen to push messages
|
|
198
|
+
webPush.addPushListener(webPush.EVENT.MESSAGE_RECEIVED, (message) => {
|
|
199
|
+
console.log('Received push message:', message);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
// Listen to notification click
|
|
203
|
+
webPush.addPushListener(webPush.EVENT.NOTIFICATION_CLICKED, (data) => {
|
|
204
|
+
console.log('Notification clicked:', data);
|
|
205
|
+
});
|
|
206
|
+
</script>
|
|
207
|
+
</body>
|
|
208
|
+
</html>
|
|
209
|
+
```
|
|
210
|
+
|
|
125
211
|
## API Reference
|
|
126
212
|
|
|
127
213
|
### Methods
|