@tencentcloud/web-push 1.0.1 → 1.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.
Files changed (47) hide show
  1. package/README.md +149 -136
  2. package/dist/index.d.ts +259 -0
  3. package/dist/index.esm.js +6857 -0
  4. package/dist/index.umd.js +1 -0
  5. package/dist/src/components/message-popup.d.ts +63 -0
  6. package/{src → dist/src}/core/web-push-sdk.d.ts +23 -1
  7. package/{src → dist/src}/index.d.ts +1 -0
  8. package/{src → dist/src}/types/inner.d.ts +2 -10
  9. package/dist/src/types/outer.d.ts +120 -0
  10. package/{src → dist/src}/utils/logger.d.ts +6 -0
  11. package/{src → dist/src}/utils/validator.d.ts +0 -13
  12. package/dist/sw.js +1 -0
  13. package/package.json +47 -9
  14. package/src/__tests__/index.test.ts +120 -0
  15. package/src/__tests__/integration.test.ts +285 -0
  16. package/src/__tests__/setup.ts +210 -0
  17. package/src/__tests__/types.test.ts +303 -0
  18. package/src/__tests__/web-push-sdk.test.ts +257 -0
  19. package/src/components/message-popup.ts +1007 -0
  20. package/src/core/event-emitter.ts +61 -0
  21. package/src/core/service-worker-manager.ts +614 -0
  22. package/src/core/web-push-sdk.ts +690 -0
  23. package/src/debug/GenerateTestUserSig.js +37 -0
  24. package/src/debug/index.d.ts +6 -0
  25. package/src/debug/index.js +1 -0
  26. package/src/debug/lib-generate-test-usersig-es.min.js +2 -0
  27. package/src/index.ts +9 -0
  28. package/src/service-worker/sw.ts +494 -0
  29. package/src/types/index.ts +2 -0
  30. package/src/types/inner.ts +44 -0
  31. package/src/types/outer.ts +142 -0
  32. package/src/utils/browser-support.ts +412 -0
  33. package/src/utils/logger.ts +66 -0
  34. package/src/utils/storage.ts +51 -0
  35. package/src/utils/validator.ts +267 -0
  36. package/CHANGELOG.md +0 -50
  37. package/index.d.ts +0 -110
  38. package/index.esm.js +0 -21437
  39. package/index.umd.js +0 -1
  40. package/src/types/outer.d.ts +0 -66
  41. package/sw.js +0 -1
  42. /package/{src → dist/src}/core/event-emitter.d.ts +0 -0
  43. /package/{src → dist/src}/core/service-worker-manager.d.ts +0 -0
  44. /package/{src → dist/src}/service-worker/sw.d.ts +0 -0
  45. /package/{src → dist/src}/types/index.d.ts +0 -0
  46. /package/{src → dist/src}/utils/browser-support.d.ts +0 -0
  47. /package/{src → dist/src}/utils/storage.d.ts +0 -0
package/README.md CHANGED
@@ -1,57 +1,75 @@
1
- # Tencent Cloud Web Push SDK
1
+ # Web Push SDK
2
2
 
3
- A web-based push notification SDK built on modern Web APIs including Service Worker, Push API, and Notification API.
3
+ 基于 Web 技术栈的推送服务 SDK,核心使用 Service WorkerPush API Notification API 实现网页推送功能。
4
4
 
5
- ## Features
5
+ ## 特性
6
6
 
7
- - 🚀 Built on modern Web standard APIs
8
- - 📱 Cross-platform push notification support
9
- - 🔧 TypeScript support
10
- - 📊 Built-in analytics functionality
11
- - 🎯 Event-driven architecture
12
- - 💾 Local state persistence
13
- - 🔒 Secure VAPID authentication
7
+ - 🚀 基于现代 Web 标准 API
8
+ - 📱 支持跨平台推送通知
9
+ - 💬 **在线推送弹窗**:应用内消息实时弹窗显示
10
+ - 🎨 **自定义弹窗样式**:支持位置、样式、行为全方位自定义
11
+ - 🔧 TypeScript 支持
12
+ - 📊 内置数据统计功能
13
+ - 🎯 事件驱动架构
14
+ - 💾 本地状态持久化
15
+ - 🔒 安全的 VAPID 认证
14
16
 
15
- ## Browser Support
17
+ ## 浏览器支持
16
18
 
17
19
  - Chrome 50+
18
20
  - Firefox 44+
19
21
  - Safari 16+
20
22
  - Edge 17+
21
23
 
22
- ## Integration Step
24
+ ## 安装
23
25
 
24
- ### Step 1: Integrating @Tencentcloud/Web-Push
25
-
26
- 【npm】
26
+ ### 方式一:NPM 安装
27
27
 
28
28
  ```bash
29
- npm install @tencentcloud/web-push --save
29
+ npm install @tencentcloud/web-push
30
30
  ```
31
31
 
32
- 【yarn】
32
+ ### 方式二:CDN 引入(UMD)
33
33
 
34
- ```bash
35
- yarn add @tencentcloud/web-push
34
+ 通过 `<script>` 标签直接引入使用:
35
+
36
+ ```html
37
+ <!-- 引入 TencentCloudChat SDK (专业版) -->
38
+ <script src="https://unpkg.com/@tencentcloud/lite-chat/professional.js"></script>
39
+
40
+ <!-- 引入 Web Push SDK -->
41
+ <script src="https://unpkg.com/@tencentcloud/web-push/index.umd.js"></script>
42
+
43
+ <script>
44
+ // SDK 会自动挂载到全局变量 WebPushSDK
45
+ const webPush = WebPushSDK.webPush;
46
+
47
+ // 使用方式与 ES6 模块相同
48
+ webPush.registerPush({
49
+ SDKAppID: 0,
50
+ appKey: '',
51
+ userID: '',
52
+ });
53
+ </script>
36
54
  ```
37
55
 
38
- ### Step 2: Configure the Service Worker File
56
+ ### 步骤2:配置 Service Worker 文件
39
57
 
40
- 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**.
58
+ 集成 `@tencentcloud/web-push` 后,需要将 **Service Workersw.js)**复制到您项目**的根目录**。网站部署后,确保该文件可以通过 `https://your-domain.com/sw.js` 的路径被访问到。否则浏览器将无法注册 **Service Worker**。
41
59
 
42
- > **Note:**
60
+ > **说明:**
43
61
  >
44
- > - The sw.js file **must be placed in the website's root directory** to work properly due to browser security restrictions.
45
- > - The sw.js file can only be registered successfully under **HTTPS connection (or local development environment localhost)**. Ensure your live production environment website supports **HTTPS**.
62
+ > - sw.js 文件**必须放在网站的根目录**才能正常工作,这是浏览器的安全限制。
63
+ > - sw.js 只有在 **HTTPS 连接(或本地开发环境 localhost)**下才能被注册成功。请确保您的生产环境网站支持 **HTTPS**。
46
64
 
47
- **Role of the public directory**: In modern front-end projects (such as Vue, React, Next.js, etc.), **the public directory is a unique directory whose content will not be compiled or renamed during build**. Files placed in the public directory will be copied to the website's root directory as-is.
65
+ **public 目录的作用**:在现代前端项目(如 Vue, React, Next.js 等)中,**public 目录是一个特殊目录,它的内容在构建时不会被编译或改名**。放置在 public 目录的文件会原封不动地被复制到网站的根目录。
48
66
 
49
- > **Note:**
67
+ > **注意:**
50
68
  >
51
- > - Place sw.js in the src or other directories, and it may be compiled or renamed (such as changed into sw.123abcde.js) by packaging tools (Webpack/Vite), thereby failing to register correctly.
52
- > - If your project **does not have a public directory** (such as old-style HTML projects), place **sw.js** directly in the same directory as **index.html** to ensure it is located in the root directory after build output.
69
+ > - sw.js 放在 src 或其他目录,它可能会被打包工具(Webpack/Vite)编译、改名(例如变成 sw.123abcde.js),从而无法被正确注册。
70
+ > - 如果您的项目**没有 public 目录**(例如老式 HTML 项目),请直接将 **sw.js** 放在 **index.html** 所在的同级目录下,确保构建输出后位于根目录即可。
53
71
 
54
- macOS
72
+ MacOS
55
73
 
56
74
  ```bash
57
75
  cp node_modules/@tencentcloud/web-push/dist/sw.js public/sw.js
@@ -63,17 +81,17 @@ cp node_modules/@tencentcloud/web-push/dist/sw.js public/sw.js
63
81
  copy node_modules\@tencentcloud\web-push\dist\sw.js public\sw.js
64
82
  ```
65
83
 
66
- ### Step 3: **Register for Push Services**
84
+ ## 快速开始
67
85
 
68
- In your homepage (for example: `index.js`), add `@tencentcloud/web-push` and register.
86
+ 在您的主页面(例如:`index.js`)中,引入 `@tencentcloud/web-push` 并注册。
69
87
 
70
88
  <table>
71
89
  <tr>
72
- <td rowspan="1" colSpan="1" >Parameter</td>
90
+ <td rowspan="1" colSpan="1" >参数</td>
73
91
 
74
- <td rowspan="1" colSpan="1" >Type</td>
92
+ <td rowspan="1" colSpan="1" >类型</td>
75
93
 
76
- <td rowspan="1" colSpan="1" >Description</td>
94
+ <td rowspan="1" colSpan="1" >说明</td>
77
95
  </tr>
78
96
 
79
97
  <tr>
@@ -81,7 +99,7 @@ In your homepage (for example: `index.js`), add `@tencentcloud/web-push` and reg
81
99
 
82
100
  <td rowspan="1" colSpan="1" >Number</td>
83
101
 
84
- <td rowspan="1" colSpan="1" >The SDKAppID for the push service Push. </td>
102
+ <td rowspan="1" colSpan="1" >推送服务 Push SDKAppID。</td>
85
103
  </tr>
86
104
 
87
105
  <tr>
@@ -89,7 +107,7 @@ In your homepage (for example: `index.js`), add `@tencentcloud/web-push` and reg
89
107
 
90
108
  <td rowspan="1" colSpan="1" >String</td>
91
109
 
92
- <td rowspan="1" colSpan="1" >The client key for the push service Push.</td>
110
+ <td rowspan="1" colSpan="1" >推送服务 Push 的客户端密钥。</td>
93
111
  </tr>
94
112
 
95
113
  <tr>
@@ -97,51 +115,111 @@ In your homepage (for example: `index.js`), add `@tencentcloud/web-push` and reg
97
115
 
98
116
  <td rowspan="1" colSpan="1" >String</td>
99
117
 
100
- <td rowspan="1" colSpan="1" >Register the userID for push services. User's Unique Identifier, defined by you, can only include uppercase and lowercase letters (a-z, A-Z), numbers (0-9), underscores, and hyphens.</td>
118
+ <td rowspan="1" colSpan="1" >注册推送用户的 userID。用户的唯一标识符,由您定义,只能包含大小写字母(a-zA-Z)、数字(0-9)、下划线和连字符。</td>
101
119
  </tr>
102
120
  </table>
103
121
 
104
122
  ```javascript
105
- import WebPush from '@tencentcloud/web-push';
123
+ import webPush from '@tencentcloud/web-push';
106
124
 
107
- const SDKAppID = 0; // Your SDKAppID
108
- const appKey = ''; // client key
109
- const userID = ''; // user ID
125
+ const SDKAppID = 0; // 您的 SDKAppID
126
+ const appKey = ''; // 客户端密钥
127
+ const userID = ''; // 用户 ID
110
128
 
111
- // Register for push service
112
- await WebPush.registerPush({ SDKAppID, appKey, userID });
129
+ // 注册推送服务
130
+ await webPush.registerPush({ SDKAppID, appKey, userID });
113
131
 
114
- // Listen to push messages
115
- WebPush.addPushListener(WebPush.EVENT.MESSAGE_RECEIVED, (message) => {
116
- console.log('received push message:', message);
132
+ // 监听推送消息
133
+ webPush.addPushListener(webPush.EVENT.MESSAGE_RECEIVED, (message) => {
134
+ console.log('收到推送消息:', message);
117
135
  });
118
136
 
119
- // Listen to notification click
120
- WebPush.addPushListener(WebPush.EVENT.NOTIFICATION_CLICKED, (data) => {
121
- console.log('notification clicked:', data);
137
+ // 监听通知点击
138
+ webPush.addPushListener(webPush.EVENT.NOTIFICATION_CLICKED, (data) => {
139
+ console.log('通知被点击:', data);
122
140
  });
123
141
  ```
124
142
 
125
- ## API Reference
143
+ ### UMD 方式(Script 标签)
144
+
145
+ > **重要提示**: 使用 UMD 方式时,必须先引入 TencentCloudChat SDK (专业版),否则会出现 "Cannot read properties of undefined (reading 'create')" 错误。
146
+
147
+ 如果您使用 UMD 方式引入,可以参考以下示例:
148
+
149
+ ```html
150
+ <!DOCTYPE html>
151
+ <html>
152
+ <head>
153
+ <title>Web Push SDK UMD Example</title>
154
+ </head>
155
+ <body>
156
+ <!-- 引入 TencentCloudChat SDK (专业版) -->
157
+ <script src="https://unpkg.com/@tencentcloud/lite-chat/professional.js"></script>
158
+
159
+ <!-- 引入 Web Push SDK -->
160
+ <script src="https://unpkg.com/@tencentcloud/web-push/index.umd.js"></script>
161
+
162
+ <script>
163
+ // 获取 SDK 实例
164
+ const webPush = WebPushSDK.webPush;
165
+
166
+ // 配置参数
167
+ const SDKAppID = 0; // 您的 SDKAppID
168
+ const appKey = 'xxx'; // 客户端密钥
169
+ const userID = 'xxx'; // 用户 ID
170
+
171
+ // 注册推送服务
172
+ webPush
173
+ .registerPush({ SDKAppID, appKey, userID })
174
+ .then((registrationID) => {
175
+ console.log('注册成功:', registrationID);
176
+ })
177
+ .catch((error) => {
178
+ console.error('注册失败:', error);
179
+ });
180
+
181
+ // 监听推送消息
182
+ webPush.addPushListener(webPush.EVENT.MESSAGE_RECEIVED, (message) => {
183
+ console.log('收到推送消息:', message);
184
+ });
185
+
186
+ // 监听通知点击
187
+ webPush.addPushListener(webPush.EVENT.NOTIFICATION_CLICKED, (data) => {
188
+ console.log('通知被点击:', data);
189
+ });
190
+ </script>
191
+ </body>
192
+ </html>
193
+ ```
194
+
195
+ ## API 文档
126
196
 
127
- ### Methods
197
+ ### 接口说明
128
198
 
129
- | API | Parameters | Description |
130
- | -------------------- | --------------------------------------------------- | -------------------------- |
131
- | `registerPush` | `options: RegisterPushOptions` | Register push service |
132
- | `unRegisterPush` | - | Unregister push service |
133
- | `addPushListener` | `eventName: EVENT, listener: Function<EventResult>` | Add push event listener |
134
- | `removePushListener` | `eventName: EVENT, listener: Function<EventResult>` | Remove push event listener |
199
+ | API | 参数 | 描述 |
200
+ | -------------------- | --------------------------------------------------- | ------------------ |
201
+ | `registerPush` | `options: RegisterPushOptions` | 注册推送服务 |
202
+ | `unRegisterPush` | - | 反注册关闭推送服务 |
203
+ | `addPushListener` | `eventName: EVENT, listener: Function<EventResult>` | 添加推送监听器 |
204
+ | `removePushListener` | `eventName: EVENT, listener: Function<EventResult>` | 移除推送监听器 |
135
205
 
136
- ### Type Definitions
206
+ ### 类型定义
137
207
 
138
208
  ```typescript
139
209
  interface RegisterPushOptions {
140
210
  SDKAppID: number;
141
211
  appKey: string;
142
212
  userID: string;
143
- serviceWorkerPath?: string;
144
213
  chat?: any;
214
+ /**
215
+ * 日志级别:
216
+ * 0 - 普通级别,日志量较多,接入时建议使用
217
+ * 1 - release级别,SDK 输出关键信息,生产环境时建议使用(默认)
218
+ * 2 - 告警级别,SDK 只输出告警和错误级别的日志
219
+ * 3 - 错误级别,SDK 只输出错误级别的日志
220
+ * 4 - 无日志级别,SDK 将不打印任何日志
221
+ */
222
+ logLevel?: LogLevel;
145
223
  }
146
224
 
147
225
  enum EVENT {
@@ -149,93 +227,28 @@ enum EVENT {
149
227
  MESSAGE_REVOKED = 'message_revoked',
150
228
  NOTIFICATION_CLICKED = 'notification_clicked',
151
229
  }
152
-
153
- interface Message {
154
- ID: string;
155
- type:
156
- | 'TIMTextElem'
157
- | 'TIMImageElem'
158
- | 'TIMSoundElem'
159
- | 'TIMVideoFileElem'
160
- | 'TIMFileElem'
161
- | 'TIMCustomElem'
162
- | 'TIMRelayElem'
163
- | 'TIMLocationElem'
164
- | 'TIMFaceElem';
165
- payload: any;
166
- conversationID: string;
167
- conversationType: 'C2C' | 'GROUP';
168
- to: string;
169
- from: string;
170
- flow: string;
171
- time: number;
172
- status: string;
173
- isRevoked: boolean;
174
- nick: string;
175
- avatar: string;
176
- isPeerRead: boolean;
177
- nameCard: string;
178
- atUserList: string[];
179
- cloudCustomData: string;
180
- isDeleted: boolean;
181
- isModified: boolean;
182
- needReadReceipt: boolean;
183
- readReceiptInfo: any;
184
- isBroadcastMessage: boolean;
185
- isSupportExtension: boolean;
186
- receiverList?: string[];
187
- revoker: string;
188
- sequence: number;
189
- progress: number;
190
- revokerInfo: {
191
- userID: string;
192
- nick: string;
193
- avatar: string;
194
- };
195
- revokeReason: string;
196
- hasRiskContent: boolean;
197
- }
198
-
199
- interface MessageReceivedResult {
200
- message: Message;
201
- }
202
-
203
- interface MessageRevokedResult {
204
- messageID: string;
205
- }
206
-
207
- interface MessageNotificationClickedResult {
208
- ext: string;
209
- }
210
-
211
- interface EventResult {
212
- data:
213
- | MessageReceivedResult
214
- | MessageRevokedResult
215
- | MessageNotificationClickedResult;
216
- }
217
230
  ```
218
231
 
219
- ### Event Types
232
+ ### 事件类型
220
233
 
221
- - `MESSAGE_RECEIVED`: Received a push message
222
- - `MESSAGE_REVOKED`: Message was revoked
223
- - `NOTIFICATION_CLICKED`: Notification was clicked
234
+ - `MESSAGE_RECEIVED`: 接收到推送消息(包括所有类型:standard、html、custom)
235
+ - `MESSAGE_REVOKED`: 消息被撤回
236
+ - `NOTIFICATION_CLICKED`: 通知被点击
224
237
 
225
- ## Important Notes
238
+ ## 注意事项
226
239
 
227
- ### Service Worker Scope
240
+ ### Service Worker 作用域
228
241
 
229
- Service Workers must be placed in the website's root directory (e.g., `/sw.js`) to control push messages across the entire website. Placing them in subdirectories will not function correctly.
242
+ Service Worker 必须放在网站根目录下(如 `/sw.js`),这样才能控制整个网站的推送消息。如果放在子目录下,将无法正常工作。
230
243
 
231
- ### HTTPS Requirement
244
+ ### HTTPS 要求
232
245
 
233
- The Web Push API requires websites to use the HTTPS protocol (except for local development environments using localhost).
246
+ Web Push API 要求网站必须使用 HTTPS 协议(本地开发环境的 localhost 除外)。
234
247
 
235
- ### Browser Permissions
248
+ ### 浏览器权限
236
249
 
237
- Users need to authorize notification permissions upon first use. Please guide users to authorize permissions at appropriate times.
250
+ 用户首次使用时需要授权通知权限,请在合适的时机引导用户授权。
238
251
 
239
- ## License
252
+ ## 许可证
240
253
 
241
254
  MIT License
@@ -0,0 +1,259 @@
1
+ export declare interface CustomMessage {
2
+ id: string;
3
+ MsgType: 'custom';
4
+ MsgContent: {
5
+ Data: string | object;
6
+ };
7
+ Ext?: string;
8
+ }
9
+
10
+ export declare enum EVENT {
11
+ MESSAGE_RECEIVED = "message_received",
12
+ MESSAGE_REVOKED = "message_revoked",
13
+ NOTIFICATION_CLICKED = "notification_clicked",
14
+ CUSTOM_MESSAGE_RECEIVED = "custom_message_received"
15
+ }
16
+
17
+ export declare interface EventResult {
18
+ data: MessageReceivedResult | MessageRevokedResult | MessageNotificationClickedResult;
19
+ }
20
+
21
+ export declare interface HtmlMessage {
22
+ id: string;
23
+ MsgType: 'html';
24
+ MsgContent: {
25
+ Placement?: Placement;
26
+ Duration?: number;
27
+ Html: string;
28
+ };
29
+ Ext?: string;
30
+ }
31
+
32
+ export declare type LogLevel = 0 | 1 | 2 | 3 | 4;
33
+
34
+ export declare interface MessageNotificationClickedResult {
35
+ ext: String;
36
+ }
37
+
38
+ export declare class MessagePopup {
39
+ private container;
40
+ private popups;
41
+ private timers;
42
+ private messageHandlers;
43
+ private animationTimers;
44
+ private adjustHeightTimers;
45
+ private config;
46
+ private readonly defaultConfig;
47
+ constructor(config?: PopupConfig);
48
+ private init;
49
+ private createContainer;
50
+ private injectStyles;
51
+ show(message: StandardMessage | HtmlMessage): void;
52
+ private createStandardPopup;
53
+ private createHtmlPopup;
54
+ private addPopup;
55
+ private removeOldestPopup;
56
+ close(messageId: string): void;
57
+ /**
58
+ * 检查指定消息是否正在显示弹窗
59
+ * @param messageId 消息ID
60
+ * @returns 是否正在显示
61
+ */
62
+ hasMessage(messageId: string): boolean;
63
+ closeAll(): void;
64
+ updateConfig(newConfig: Partial<PopupConfig>): void;
65
+ destroy(): void;
66
+ /**
67
+ * 根据 Placement 值应用容器位置
68
+ * 0-中间,1-左上,2-上中,3-右上,4-右中,5-右下,6-下中,7-左下,8-左中
69
+ */
70
+ private applyPlacement;
71
+ /**
72
+ * 调整iframe高度以适应内容
73
+ */
74
+ private adjustIframeHeight;
75
+ /**
76
+ * 创建iframe的完整HTML文档
77
+ */
78
+ private createIframeHtml;
79
+ }
80
+
81
+ export declare interface MessageReceivedData {
82
+ content: string;
83
+ info: WebPushInfo;
84
+ extension: WebPushExt;
85
+ }
86
+
87
+ export declare interface MessageReceivedResult {
88
+ message: PushMessage | NotificationMessage;
89
+ }
90
+
91
+ export declare interface MessageRevokedResult {
92
+ messageID: String;
93
+ }
94
+
95
+ export declare interface NotificationMessage {
96
+ messageID: string;
97
+ title: string;
98
+ body: string;
99
+ icon?: string;
100
+ tag?: string;
101
+ data?: any;
102
+ timestamp: number;
103
+ }
104
+
105
+ export declare enum Placement {
106
+ CENTER = 0,// 中间
107
+ TOP_LEFT = 1,// 左上
108
+ TOP_CENTER = 2,// 上中
109
+ TOP_RIGHT = 3,// 右上
110
+ MIDDLE_RIGHT = 4,// 右中
111
+ BOTTOM_RIGHT = 5,// 右下
112
+ BOTTOM_CENTER = 6,// 下中
113
+ BOTTOM_LEFT = 7,// 左下
114
+ MIDDLE_LEFT = 8
115
+ }
116
+
117
+ declare interface PopupConfig {
118
+ /** 是否启用弹窗 */
119
+ enabled?: boolean;
120
+ /** 弹窗显示时长(毫秒),0 表示不自动关闭 */
121
+ duration?: number;
122
+ /** 弹窗位置 */
123
+ position?: 'center' | 'top-left' | 'top-center' | 'top-right' | 'right-center' | 'bottom-right' | 'bottom-center' | 'bottom-left' | 'left-center';
124
+ /** 最大显示数量 */
125
+ maxCount?: number;
126
+ /** 是否显示关闭按钮 */
127
+ showCloseButton?: boolean;
128
+ /** 是否允许点击弹窗 */
129
+ clickable?: boolean;
130
+ /** 自定义渲染函数 */
131
+ customRender?: (message: any, container: HTMLElement) => HTMLElement;
132
+ /** 点击回调 */
133
+ onClick?: (message: any, popup: HTMLElement) => void;
134
+ /** 关闭回调 */
135
+ onClose?: (message: any, popup: HTMLElement) => void;
136
+ }
137
+
138
+ export declare type PushMessage = StandardMessage | HtmlMessage | CustomMessage;
139
+
140
+ export declare interface RegisterPushOptions {
141
+ SDKAppID: number;
142
+ appKey: string;
143
+ userID: string;
144
+ serviceWorkerPath?: string;
145
+ chat?: any;
146
+ /**
147
+ * 日志级别:
148
+ * 0 - 普通级别,日志量较多,接入时建议使用
149
+ * 1 - release级别,SDK 输出关键信息,生产环境时建议使用(默认)
150
+ * 2 - 告警级别,SDK 只输出告警和错误级别的日志
151
+ * 3 - 错误级别,SDK 只输出错误级别的日志
152
+ * 4 - 无日志级别,SDK 将不打印任何日志
153
+ */
154
+ logLevel?: LogLevel;
155
+ }
156
+
157
+ export declare interface StandardMessage {
158
+ id: string;
159
+ MsgType: 'standard';
160
+ MsgContent: {
161
+ Text: {
162
+ Title: string;
163
+ Desc: string;
164
+ };
165
+ Image?: {
166
+ URL: string;
167
+ LinkURL: string;
168
+ };
169
+ Close: 0 | 1;
170
+ Placement?: Placement;
171
+ Duration?: number;
172
+ Button?: Array<{
173
+ Text: string;
174
+ Icon?: string;
175
+ Url: string;
176
+ }>;
177
+ };
178
+ Ext?: string;
179
+ }
180
+
181
+ declare const webPush: WebPushSDK_2;
182
+ export default webPush;
183
+ export { webPush }
184
+
185
+ export declare interface WebPushExt {
186
+ WebpushReportUrl: string;
187
+ OnlineClickExt: string;
188
+ TaskId: string;
189
+ }
190
+
191
+ export declare interface WebPushInfo {
192
+ Title: string;
193
+ Desc: string;
194
+ Icon: string;
195
+ Image: string;
196
+ URL: string;
197
+ }
198
+
199
+ export declare interface WebPushSDK {
200
+ registerPush(options?: RegisterPushOptions): Promise<any>;
201
+ unRegisterPush(): Promise<any>;
202
+ addPushListener(eventName: EVENT, listener: (data: EventResult) => void): any;
203
+ removePushListener(eventName: EVENT, listener: (data: EventResult) => void): any;
204
+ }
205
+
206
+ declare class WebPushSDK_2 implements WebPushSDK {
207
+ static instance: WebPushSDK_2;
208
+ private eventEmitter;
209
+ private serviceWorkerManager;
210
+ private messagePopup;
211
+ private isRegistered;
212
+ private registrationID;
213
+ private chat;
214
+ private SDKAppID;
215
+ private appKey;
216
+ private vapidPublicKey;
217
+ private pendingMessages;
218
+ EVENT: typeof EVENT;
219
+ VERSION: string;
220
+ constructor();
221
+ static getInstance(): WebPushSDK_2;
222
+ registerPush(options?: RegisterPushOptions): Promise<string>;
223
+ unRegisterPush(): Promise<boolean>;
224
+ addPushListener(eventName: EVENT, listener: Function): string;
225
+ /**
226
+ * 内部方法:向 Service Worker 发送日志级别配置
227
+ * @param logLevel 日志级别 0-4
228
+ */
229
+ private sendLogLevelToServiceWorker;
230
+ removePushListener(eventName: EVENT, listener: Function): boolean;
231
+ private checkBrowserSupport;
232
+ private requestNotificationPermission;
233
+ private pushLogin;
234
+ private onMessageReceived;
235
+ private onMessageRevoked;
236
+ private addChatListener;
237
+ private removeChatListener;
238
+ private getSystemPermissionMessage;
239
+ private showSystemPermissionAlert;
240
+ private getBrowserInstType;
241
+ private setToken;
242
+ private initializeBrowserCompatibility;
243
+ private setupVisibilityChangeListener;
244
+ private setupInternalListeners;
245
+ private pushStatistics;
246
+ private clearState;
247
+ /**
248
+ * 向 service-worker 发送通知消息,使用与 push 事件相同的数据格式
249
+ * @param webpushInfo webpush 信息,格式与 SW push 事件接收的数据一致
250
+ */
251
+ private sendNotificationToServiceWorker;
252
+ /**
253
+ * 向 service-worker 发送消息撤回请求
254
+ * @param messageID 要撤回的消息ID
255
+ */
256
+ private sendMessageRevokeToServiceWorker;
257
+ }
258
+
259
+ export { }