customer-chat-sdk 1.0.75 → 1.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/dist/core/IconManager.d.ts +2 -1
- package/dist/core/IconManager.d.ts.map +1 -1
- package/dist/core/IframeManager.d.ts +2 -0
- package/dist/core/IframeManager.d.ts.map +1 -1
- package/dist/customer-sdk.cjs.js +166 -42
- package/dist/customer-sdk.esm.js +166 -43
- package/dist/customer-sdk.min.js +2 -2
- package/dist/index.d.ts +18 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IconManager.d.ts","sourceRoot":"","sources":["../../src/core/IconManager.ts"],"names":[],"mappings":"AAGA,UAAU,mBAAmB;IAC3B,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB;AAED,UAAU,YAAY;IACpB,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACnB,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CACpB;AAED,qBAAa,WAAW;IACtB,OAAO,CAAC,WAAW,CAA2B;IAC9C,OAAO,CAAC,YAAY,CAA2B;IAC/C,OAAO,CAAC,eAAe,CAA4B;IACnD,OAAO,CAAC,oBAAoB,CAAqC;IACjE,OAAO,CAAC,UAAU,CAAQ;IAC1B,OAAO,CAAC,UAAU,CAAI;IACtB,OAAO,CAAC,UAAU,CAAI;IACtB,OAAO,CAAC,UAAU,CAAI;IACtB,OAAO,CAAC,UAAU,CAAI;IACtB,OAAO,CAAC,eAAe,CAAsD;IAC7E,OAAO,CAAC,cAAc,CAAsD;IAC5E,OAAO,CAAC,YAAY,CAA4B;
|
|
1
|
+
{"version":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AI;IAInC;;OAEG;IACH,cAAc,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI,GAAG,IAAI;IAInD;;OAEG;IACH,gBAAgB,CAAC,OAAO,EAAE,mBAAmB,GAAG,IAAI;IA8BpD;;OAEG;IACH,iBAAiB,IAAI,IAAI;IAUzB;;OAEG;IACH,OAAO,CAAC,eAAe;IAYvB;;OAEG;IACH,OAAO,CAAC,eAAe;IAqEvB;;OAEG;IACH,OAAO,CAAC,cAAc;IA+DtB;;OAEG;IACH,OAAO,CAAC,aAAa;IAwBrB;;OAEG;IACH,OAAO,CAAC,WAAW;IAMnB;;OAEG;IACH,OAAO,CAAC,WAAW;CAmDpB"}
|
|
@@ -8,6 +8,7 @@ interface IframeOptions {
|
|
|
8
8
|
allowClose?: boolean;
|
|
9
9
|
onMessage?: (messageType: string, data: any) => void;
|
|
10
10
|
onClose?: () => void;
|
|
11
|
+
debug?: boolean;
|
|
11
12
|
}
|
|
12
13
|
export declare class IframeManager {
|
|
13
14
|
private config;
|
|
@@ -16,6 +17,7 @@ export declare class IframeManager {
|
|
|
16
17
|
private containerElement;
|
|
17
18
|
private isOpen;
|
|
18
19
|
private isCreated;
|
|
20
|
+
private debug;
|
|
19
21
|
constructor(config?: IframeOptions);
|
|
20
22
|
/**
|
|
21
23
|
* 初始化iframe(隐藏状态)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IframeManager.d.ts","sourceRoot":"","sources":["../../src/core/IframeManager.ts"],"names":[],"mappings":"AACA,UAAU,aAAa;IACrB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,MAAM,GAAG,YAAY,GAAG,OAAO,CAAA;IACtC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,UAAU,CAAC,EAAE,OAAO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AO;IAIvB;;OAEG;IACH,YAAY,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI;IAM7B;;OAEG;IACH,OAAO,CAAC,aAAa;IA8BrB;;OAEG;IACH,OAAO,CAAC,YAAY;IAyHpB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IA8D1B;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAoCzB;;OAEG;IACH,OAAO,CAAC,cAAc;IAKtB;;OAEG;IACH,OAAO,CAAC,aAAa;IAOrB;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAS5B;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAoD3B;;OAEG;IACH,OAAO,CAAC,YAAY;CAMrB"}
|
package/dist/customer-sdk.cjs.js
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
// 直接使用base64字符串,避免打包后路径问题
|
|
6
6
|
const iconImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHgAAAB4CAYAAAA5ZDbSAAAACXBIWXMAABYlAAAWJQFJUiTwAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAArKSURBVHgB7Z1NbFTXFcf/93mwaGyEabLoIgFTqWRFMZUitSoIu80ial01SFWrKgsGKXYpWdRtFilRK4xUgbKICosmCKIySKCo2UAE6i61XVroDuOoi2YT02RZVFNwQTAzN+e8N88ej9+8j5n3ce5wf5JhPvyY4f3f/9xzz73vXoUeYKish6oljCiFYQ2MaAebVR3D/Jzf1xpDUPTTggIW6feXoOlH0Q9wS9exRK/Pl6qYX6qoJRiOgoEMvqpHWUjlYJ9iQeEJmTb07y6y2CT6HP99/z01C8MwQmB26OMSyuTIH9LTkSA35oLn9FmKCB/WHmP2YUUtQjhiBV4jqsIoJKJJbOC8ZLHFCczhl75UWXvCFuPUDiBXV5TGeWlhXIzALCx9m6Ni3RqfeRL71PJZVYEAChfYdayDc1klSkXBCRr9caxooQsTuIccG4qbiddxsKjQnbvAlDwNVzf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y6AAAAABJRU5ErkJggg==';
|
|
7
7
|
class IconManager {
|
|
8
|
-
constructor(position) {
|
|
8
|
+
constructor(position, debug = false) {
|
|
9
9
|
this.iconElement = null;
|
|
10
10
|
this.badgeElement = null;
|
|
11
11
|
this.onClickCallback = null;
|
|
@@ -18,7 +18,9 @@ class IconManager {
|
|
|
18
18
|
this.dragMoveHandler = null;
|
|
19
19
|
this.dragEndHandler = null;
|
|
20
20
|
this.iconPosition = null; // 图标位置配置
|
|
21
|
+
this.debug = false; // debug 模式标志
|
|
21
22
|
this.iconPosition = position || null;
|
|
23
|
+
this.debug = debug;
|
|
22
24
|
}
|
|
23
25
|
/**
|
|
24
26
|
* 显示悬浮图标
|
|
@@ -86,7 +88,9 @@ class IconManager {
|
|
|
86
88
|
iconImg.alt = 'Customer Service';
|
|
87
89
|
// 添加图片加载成功处理
|
|
88
90
|
iconImg.onload = () => {
|
|
89
|
-
|
|
91
|
+
if (this.debug) {
|
|
92
|
+
console.log('Icon image loaded successfully');
|
|
93
|
+
}
|
|
90
94
|
if (this.iconElement) {
|
|
91
95
|
// 确保图片可见
|
|
92
96
|
iconImg.style.opacity = '1';
|
|
@@ -95,6 +99,7 @@ class IconManager {
|
|
|
95
99
|
};
|
|
96
100
|
// 添加图片加载错误处理
|
|
97
101
|
iconImg.onerror = (e) => {
|
|
102
|
+
// 错误始终输出
|
|
98
103
|
console.error('Failed to load icon image', e);
|
|
99
104
|
// 只记录错误,不使用默认样式,必须使用外部提供的图片
|
|
100
105
|
};
|
|
@@ -116,7 +121,9 @@ class IconManager {
|
|
|
116
121
|
this.setupDragEvents();
|
|
117
122
|
// 添加到页面
|
|
118
123
|
document.body.appendChild(this.iconElement);
|
|
119
|
-
|
|
124
|
+
if (this.debug) {
|
|
125
|
+
console.log('CustomerSDK icon displayed');
|
|
126
|
+
}
|
|
120
127
|
}
|
|
121
128
|
/**
|
|
122
129
|
* 强制清理所有拖动事件监听器
|
|
@@ -129,7 +136,9 @@ class IconManager {
|
|
|
129
136
|
document.removeEventListener('touchmove', this.dragMoveHandler);
|
|
130
137
|
}
|
|
131
138
|
catch (e) {
|
|
132
|
-
|
|
139
|
+
if (this.debug) {
|
|
140
|
+
console.warn('Error removing drag move listeners:', e);
|
|
141
|
+
}
|
|
133
142
|
}
|
|
134
143
|
}
|
|
135
144
|
if (this.dragEndHandler) {
|
|
@@ -138,7 +147,9 @@ class IconManager {
|
|
|
138
147
|
document.removeEventListener('touchend', this.dragEndHandler);
|
|
139
148
|
}
|
|
140
149
|
catch (e) {
|
|
141
|
-
|
|
150
|
+
if (this.debug) {
|
|
151
|
+
console.warn('Error removing drag end listeners:', e);
|
|
152
|
+
}
|
|
142
153
|
}
|
|
143
154
|
}
|
|
144
155
|
// 重置拖动状态
|
|
@@ -161,7 +172,9 @@ class IconManager {
|
|
|
161
172
|
this.onClickCallback = null;
|
|
162
173
|
this.dragMoveHandler = null;
|
|
163
174
|
this.dragEndHandler = null;
|
|
164
|
-
|
|
175
|
+
if (this.debug) {
|
|
176
|
+
console.log('CustomerSDK icon hidden');
|
|
177
|
+
}
|
|
165
178
|
}
|
|
166
179
|
}
|
|
167
180
|
/**
|
|
@@ -218,7 +231,9 @@ class IconManager {
|
|
|
218
231
|
*/
|
|
219
232
|
showNotification(options) {
|
|
220
233
|
if (!this.iconElement) {
|
|
221
|
-
|
|
234
|
+
if (this.debug) {
|
|
235
|
+
console.warn('Icon not displayed, cannot show notification');
|
|
236
|
+
}
|
|
222
237
|
return;
|
|
223
238
|
}
|
|
224
239
|
const { showBadge = true, badgeCount = 0, badgeText = '', pulse = false } = options;
|
|
@@ -230,7 +245,9 @@ class IconManager {
|
|
|
230
245
|
if (this.notificationCallback) {
|
|
231
246
|
this.notificationCallback({ badgeCount, badgeText, pulse });
|
|
232
247
|
}
|
|
233
|
-
|
|
248
|
+
if (this.debug) {
|
|
249
|
+
console.log('Notification shown:', { badgeCount, badgeText });
|
|
250
|
+
}
|
|
234
251
|
}
|
|
235
252
|
/**
|
|
236
253
|
* 清除消息订阅
|
|
@@ -240,7 +257,9 @@ class IconManager {
|
|
|
240
257
|
this.badgeElement.remove();
|
|
241
258
|
this.badgeElement = null;
|
|
242
259
|
}
|
|
243
|
-
|
|
260
|
+
if (this.debug) {
|
|
261
|
+
console.log('Notification cleared');
|
|
262
|
+
}
|
|
244
263
|
}
|
|
245
264
|
/**
|
|
246
265
|
* 设置拖动和点击事件
|
|
@@ -464,6 +483,7 @@ class IframeManager {
|
|
|
464
483
|
this.containerElement = null; // 包装容器,包含iframe和关闭按钮
|
|
465
484
|
this.isOpen = false;
|
|
466
485
|
this.isCreated = false;
|
|
486
|
+
this.debug = false; // debug 模式标志
|
|
467
487
|
this.config = {
|
|
468
488
|
src: '',
|
|
469
489
|
mode: 'auto', // 默认自动检测设备类型
|
|
@@ -472,6 +492,7 @@ class IframeManager {
|
|
|
472
492
|
allowClose: true,
|
|
473
493
|
...config
|
|
474
494
|
};
|
|
495
|
+
this.debug = config.debug ?? false;
|
|
475
496
|
this.setupMessageListener();
|
|
476
497
|
}
|
|
477
498
|
/**
|
|
@@ -483,9 +504,12 @@ class IframeManager {
|
|
|
483
504
|
// 创建隐藏的iframe(预连接到SSE)
|
|
484
505
|
this.createIframe();
|
|
485
506
|
this.isCreated = true;
|
|
486
|
-
|
|
507
|
+
if (this.debug) {
|
|
508
|
+
console.log('CustomerSDK iframe initialized (hidden, SSE connected)');
|
|
509
|
+
}
|
|
487
510
|
}
|
|
488
511
|
catch (error) {
|
|
512
|
+
// 错误始终输出
|
|
489
513
|
console.error('Failed to initialize iframe:', error);
|
|
490
514
|
throw error;
|
|
491
515
|
}
|
|
@@ -536,9 +560,12 @@ class IframeManager {
|
|
|
536
560
|
}
|
|
537
561
|
}
|
|
538
562
|
this.isOpen = true;
|
|
539
|
-
|
|
563
|
+
if (this.debug) {
|
|
564
|
+
console.log('CustomerSDK iframe shown');
|
|
565
|
+
}
|
|
540
566
|
}
|
|
541
567
|
catch (error) {
|
|
568
|
+
// 错误始终输出
|
|
542
569
|
console.error('Failed to show iframe:', error);
|
|
543
570
|
}
|
|
544
571
|
}
|
|
@@ -574,7 +601,9 @@ class IframeManager {
|
|
|
574
601
|
this.preventBodyScroll(false);
|
|
575
602
|
}
|
|
576
603
|
this.isOpen = false;
|
|
577
|
-
|
|
604
|
+
if (this.debug) {
|
|
605
|
+
console.log('CustomerSDK iframe hidden (SSE still connected)');
|
|
606
|
+
}
|
|
578
607
|
// 触发关闭回调
|
|
579
608
|
if (this.config.onClose) {
|
|
580
609
|
this.config.onClose();
|
|
@@ -597,7 +626,9 @@ class IframeManager {
|
|
|
597
626
|
this.iframeElement = null;
|
|
598
627
|
}
|
|
599
628
|
this.isCreated = false;
|
|
600
|
-
|
|
629
|
+
if (this.debug) {
|
|
630
|
+
console.log('CustomerSDK container destroyed');
|
|
631
|
+
}
|
|
601
632
|
}
|
|
602
633
|
/**
|
|
603
634
|
* 检查是否已打开
|
|
@@ -748,7 +779,9 @@ class IframeManager {
|
|
|
748
779
|
});
|
|
749
780
|
// 添加到body(预连接SSE,但不显示)
|
|
750
781
|
document.body.appendChild(this.containerElement);
|
|
751
|
-
|
|
782
|
+
if (this.debug) {
|
|
783
|
+
console.log('CustomerSDK container created (hidden, ready for SSE)');
|
|
784
|
+
}
|
|
752
785
|
}
|
|
753
786
|
/**
|
|
754
787
|
* 向iframe注入移动端优化样式(隐藏滚动条)
|
|
@@ -800,12 +833,16 @@ class IframeManager {
|
|
|
800
833
|
`;
|
|
801
834
|
// 注入样式
|
|
802
835
|
iframeDoc.head?.appendChild(style);
|
|
803
|
-
|
|
836
|
+
if (this.debug) {
|
|
837
|
+
console.log('CustomerSDK mobile styles injected successfully');
|
|
838
|
+
}
|
|
804
839
|
}
|
|
805
840
|
}
|
|
806
841
|
catch (error) {
|
|
807
842
|
// 跨域限制时静默忽略
|
|
808
|
-
|
|
843
|
+
if (this.debug) {
|
|
844
|
+
console.log('Cannot inject styles due to cross-origin restrictions:', error);
|
|
845
|
+
}
|
|
809
846
|
}
|
|
810
847
|
}
|
|
811
848
|
/**
|
|
@@ -872,7 +909,9 @@ class IframeManager {
|
|
|
872
909
|
* 处理来自iframe的消息
|
|
873
910
|
*/
|
|
874
911
|
handleIframeMessage(data) {
|
|
875
|
-
|
|
912
|
+
if (this.debug) {
|
|
913
|
+
console.log('Message from iframe:', data);
|
|
914
|
+
}
|
|
876
915
|
// 判断data是字符串还是对象,兼容两种格式
|
|
877
916
|
let messageType;
|
|
878
917
|
if (typeof data === 'string') {
|
|
@@ -882,13 +921,17 @@ class IframeManager {
|
|
|
882
921
|
messageType = data.type;
|
|
883
922
|
}
|
|
884
923
|
else {
|
|
885
|
-
|
|
924
|
+
if (this.debug) {
|
|
925
|
+
console.log('Unknown message format:', data);
|
|
926
|
+
}
|
|
886
927
|
return;
|
|
887
928
|
}
|
|
888
929
|
// 根据消息类型处理不同的操作
|
|
889
930
|
switch (messageType) {
|
|
890
931
|
case 'iframe_ready':
|
|
891
|
-
|
|
932
|
+
if (this.debug) {
|
|
933
|
+
console.log('Iframe is ready');
|
|
934
|
+
}
|
|
892
935
|
break;
|
|
893
936
|
case 'close_iframe':
|
|
894
937
|
case 'close':
|
|
@@ -902,14 +945,18 @@ class IframeManager {
|
|
|
902
945
|
break;
|
|
903
946
|
case 'new-message':
|
|
904
947
|
// 新消息通知 - 触发回调让外层处理
|
|
905
|
-
|
|
948
|
+
if (this.debug) {
|
|
949
|
+
console.log('Received new message notification');
|
|
950
|
+
}
|
|
906
951
|
if (this.config.onMessage) {
|
|
907
952
|
this.config.onMessage(messageType, data);
|
|
908
953
|
}
|
|
909
954
|
break;
|
|
910
955
|
default:
|
|
911
956
|
// 可以在这里添加自定义消息处理
|
|
912
|
-
|
|
957
|
+
if (this.debug) {
|
|
958
|
+
console.log('Custom message:', data);
|
|
959
|
+
}
|
|
913
960
|
}
|
|
914
961
|
}
|
|
915
962
|
/**
|
|
@@ -20611,27 +20658,47 @@ class CustomerServiceSDK {
|
|
|
20611
20658
|
this.screenshotManager = null;
|
|
20612
20659
|
this.config = null;
|
|
20613
20660
|
this.isInitialized = false;
|
|
20661
|
+
this.initResult = null; // 保存初始化结果
|
|
20662
|
+
this.debug = false; // debug 模式标志
|
|
20614
20663
|
}
|
|
20615
20664
|
/**
|
|
20616
20665
|
* 初始化 SDK
|
|
20617
20666
|
* @param config SDK配置
|
|
20618
20667
|
* @param options UI选项(可选)
|
|
20668
|
+
* @returns 返回初始化信息(包含设备ID等)
|
|
20619
20669
|
*/
|
|
20620
20670
|
async init(config, options) {
|
|
20621
20671
|
if (this.isInitialized) {
|
|
20622
|
-
|
|
20623
|
-
|
|
20672
|
+
if (this.debug) {
|
|
20673
|
+
console.warn('CustomerSDK already initialized');
|
|
20674
|
+
}
|
|
20675
|
+
// 如果已经初始化,返回之前保存的初始化信息
|
|
20676
|
+
if (this.initResult) {
|
|
20677
|
+
return this.initResult;
|
|
20678
|
+
}
|
|
20679
|
+
throw new Error('SDK already initialized but cannot retrieve initialization info');
|
|
20624
20680
|
}
|
|
20625
20681
|
this.config = config;
|
|
20682
|
+
this.debug = config.debug ?? false;
|
|
20626
20683
|
try {
|
|
20627
20684
|
// 获取设备指纹ID
|
|
20628
20685
|
const deviceId = await this.getDeviceId();
|
|
20629
|
-
|
|
20686
|
+
if (this.debug) {
|
|
20687
|
+
console.log('Device ID:', deviceId);
|
|
20688
|
+
}
|
|
20630
20689
|
// 构建iframe URL(带参数)
|
|
20631
20690
|
const iframeUrl = this.buildIframeUrl(config, deviceId);
|
|
20691
|
+
// 准备返回的初始化信息
|
|
20692
|
+
const initResult = {
|
|
20693
|
+
deviceId,
|
|
20694
|
+
iframeUrl,
|
|
20695
|
+
referrer: document.referrer,
|
|
20696
|
+
agent: config.agent,
|
|
20697
|
+
timestamp: Date.now()
|
|
20698
|
+
};
|
|
20632
20699
|
// 创建悬浮图标管理器(支持自定义位置)
|
|
20633
20700
|
const iconPosition = options?.iconPosition || undefined;
|
|
20634
|
-
this.iconManager = new IconManager(iconPosition);
|
|
20701
|
+
this.iconManager = new IconManager(iconPosition, this.debug);
|
|
20635
20702
|
await this.iconManager.show();
|
|
20636
20703
|
// 创建iframe管理器(自动检测设备类型)
|
|
20637
20704
|
this.iframeManager = new IframeManager({
|
|
@@ -20640,6 +20707,7 @@ class CustomerServiceSDK {
|
|
|
20640
20707
|
width: 400,
|
|
20641
20708
|
height: 600,
|
|
20642
20709
|
allowClose: true,
|
|
20710
|
+
debug: this.debug, // 传递 debug 标志
|
|
20643
20711
|
onMessage: (messageType, _data) => {
|
|
20644
20712
|
// 处理来自iframe的消息
|
|
20645
20713
|
if (messageType === 'new-message') {
|
|
@@ -20667,18 +20735,32 @@ class CustomerServiceSDK {
|
|
|
20667
20735
|
// 默认截图目标为 document.body,可以通过配置自定义
|
|
20668
20736
|
const targetElement = document.body;
|
|
20669
20737
|
// 传入发送消息到 iframe 的回调函数
|
|
20670
|
-
|
|
20738
|
+
// 将 debug 配置传递给截图管理器(通过 silentMode 的相反值)
|
|
20739
|
+
const screenshotOptions = {
|
|
20740
|
+
...config.screenshot,
|
|
20741
|
+
silentMode: !this.debug // debug=true 时 silentMode=false(显示日志),debug=false 时 silentMode=true(隐藏日志)
|
|
20742
|
+
};
|
|
20743
|
+
this.screenshotManager = new ScreenshotManager(targetElement, screenshotOptions, (data) => {
|
|
20671
20744
|
// 通过 IframeManager 发送消息到 iframe
|
|
20672
20745
|
this.iframeManager?.sendToIframe(data);
|
|
20673
20746
|
});
|
|
20674
20747
|
// 自动启用截图功能(用于测试,实际使用时需要通过 iframe 消息启用)
|
|
20675
20748
|
this.screenshotManager.enable(true);
|
|
20676
|
-
|
|
20749
|
+
if (this.debug) {
|
|
20750
|
+
console.log('CustomerSDK screenshot manager initialized and enabled');
|
|
20751
|
+
}
|
|
20677
20752
|
}
|
|
20678
20753
|
this.isInitialized = true;
|
|
20679
|
-
|
|
20754
|
+
// 保存初始化结果,以便后续获取
|
|
20755
|
+
this.initResult = initResult;
|
|
20756
|
+
if (this.debug) {
|
|
20757
|
+
console.log('CustomerSDK initialized successfully (iframe pre-connected to SSE)');
|
|
20758
|
+
}
|
|
20759
|
+
// 返回初始化信息
|
|
20760
|
+
return initResult;
|
|
20680
20761
|
}
|
|
20681
20762
|
catch (error) {
|
|
20763
|
+
// 错误始终输出
|
|
20682
20764
|
console.error('Failed to initialize CustomerSDK:', error);
|
|
20683
20765
|
throw error;
|
|
20684
20766
|
}
|
|
@@ -20747,7 +20829,9 @@ class CustomerServiceSDK {
|
|
|
20747
20829
|
*/
|
|
20748
20830
|
showNotification(badgeCount = 1, options = {}) {
|
|
20749
20831
|
if (!this.iconManager) {
|
|
20750
|
-
|
|
20832
|
+
if (this.debug) {
|
|
20833
|
+
console.warn('SDK not initialized');
|
|
20834
|
+
}
|
|
20751
20835
|
return;
|
|
20752
20836
|
}
|
|
20753
20837
|
this.iconManager.showNotification({
|
|
@@ -20779,7 +20863,9 @@ class CustomerServiceSDK {
|
|
|
20779
20863
|
*/
|
|
20780
20864
|
async captureScreenshot(force = false) {
|
|
20781
20865
|
if (!this.screenshotManager) {
|
|
20782
|
-
|
|
20866
|
+
if (this.debug) {
|
|
20867
|
+
console.warn('截图功能未启用');
|
|
20868
|
+
}
|
|
20783
20869
|
return false;
|
|
20784
20870
|
}
|
|
20785
20871
|
return await this.screenshotManager.captureOnce(force);
|
|
@@ -20789,11 +20875,15 @@ class CustomerServiceSDK {
|
|
|
20789
20875
|
*/
|
|
20790
20876
|
enableScreenshot(enabled) {
|
|
20791
20877
|
if (!this.screenshotManager) {
|
|
20792
|
-
|
|
20878
|
+
if (this.debug) {
|
|
20879
|
+
console.warn('截图管理器未初始化');
|
|
20880
|
+
}
|
|
20793
20881
|
return;
|
|
20794
20882
|
}
|
|
20795
20883
|
this.screenshotManager.enable(enabled);
|
|
20796
|
-
|
|
20884
|
+
if (this.debug) {
|
|
20885
|
+
console.log(`📸 截图功能已${enabled ? '启用' : '禁用'}`);
|
|
20886
|
+
}
|
|
20797
20887
|
}
|
|
20798
20888
|
/**
|
|
20799
20889
|
* 获取截图状态
|
|
@@ -20807,11 +20897,15 @@ class CustomerServiceSDK {
|
|
|
20807
20897
|
*/
|
|
20808
20898
|
updateScreenshotOptions(options) {
|
|
20809
20899
|
if (!this.screenshotManager) {
|
|
20810
|
-
|
|
20900
|
+
if (this.debug) {
|
|
20901
|
+
console.warn('截图管理器未初始化,无法更新配置');
|
|
20902
|
+
}
|
|
20811
20903
|
return;
|
|
20812
20904
|
}
|
|
20813
20905
|
this.screenshotManager.updateOptions(options);
|
|
20814
|
-
|
|
20906
|
+
if (this.debug) {
|
|
20907
|
+
console.log('📸 截图配置已更新:', options);
|
|
20908
|
+
}
|
|
20815
20909
|
}
|
|
20816
20910
|
/**
|
|
20817
20911
|
* 销毁 SDK
|
|
@@ -20824,27 +20918,47 @@ class CustomerServiceSDK {
|
|
|
20824
20918
|
this.iframeManager = null;
|
|
20825
20919
|
this.screenshotManager = null;
|
|
20826
20920
|
this.config = null;
|
|
20921
|
+
this.initResult = null;
|
|
20827
20922
|
this.isInitialized = false;
|
|
20828
|
-
|
|
20923
|
+
if (this.debug) {
|
|
20924
|
+
console.log('CustomerSDK destroyed');
|
|
20925
|
+
}
|
|
20926
|
+
}
|
|
20927
|
+
/**
|
|
20928
|
+
* 获取初始化信息(设备ID等)
|
|
20929
|
+
*/
|
|
20930
|
+
getInitResult() {
|
|
20931
|
+
return this.initResult;
|
|
20829
20932
|
}
|
|
20830
20933
|
/**
|
|
20831
20934
|
* 获取设备指纹ID
|
|
20832
20935
|
*/
|
|
20833
20936
|
async getDeviceId() {
|
|
20834
|
-
|
|
20937
|
+
if (this.debug) {
|
|
20938
|
+
console.log('🔍 Starting to get device fingerprint...');
|
|
20939
|
+
}
|
|
20835
20940
|
try {
|
|
20836
|
-
|
|
20941
|
+
if (this.debug) {
|
|
20942
|
+
console.log('📦 Loading FingerprintJS...');
|
|
20943
|
+
}
|
|
20837
20944
|
const fp = await index$1.load();
|
|
20838
|
-
|
|
20945
|
+
if (this.debug) {
|
|
20946
|
+
console.log('🎯 Getting device fingerprint...');
|
|
20947
|
+
}
|
|
20839
20948
|
const result = await fp.get();
|
|
20840
|
-
|
|
20841
|
-
|
|
20949
|
+
if (this.debug) {
|
|
20950
|
+
console.log('✅ FingerprintJS result:', result);
|
|
20951
|
+
console.log('🆔 Device ID obtained:', result.visitorId);
|
|
20952
|
+
}
|
|
20842
20953
|
return result.visitorId;
|
|
20843
20954
|
}
|
|
20844
20955
|
catch (error) {
|
|
20956
|
+
// 错误始终输出
|
|
20845
20957
|
console.warn('❌ Failed to get device fingerprint, using fallback:', error);
|
|
20846
20958
|
const fallbackId = 'device_' + Date.now() + '_' + Math.random().toString(36).substr(2, 9);
|
|
20847
|
-
|
|
20959
|
+
if (this.debug) {
|
|
20960
|
+
console.log('🆔 Fallback Device ID:', fallbackId);
|
|
20961
|
+
}
|
|
20848
20962
|
return fallbackId;
|
|
20849
20963
|
}
|
|
20850
20964
|
}
|
|
@@ -20875,12 +20989,13 @@ let globalSDKInstance = null;
|
|
|
20875
20989
|
* 初始化 Customer SDK
|
|
20876
20990
|
* @param config SDK配置
|
|
20877
20991
|
* @param options UI选项(可选)
|
|
20992
|
+
* @returns 返回初始化信息(包含设备ID等)
|
|
20878
20993
|
*/
|
|
20879
20994
|
const init = async (config, options) => {
|
|
20880
20995
|
if (!globalSDKInstance) {
|
|
20881
20996
|
globalSDKInstance = new CustomerServiceSDK();
|
|
20882
20997
|
}
|
|
20883
|
-
await globalSDKInstance.init(config, options);
|
|
20998
|
+
return await globalSDKInstance.init(config, options);
|
|
20884
20999
|
};
|
|
20885
21000
|
/**
|
|
20886
21001
|
* 获取全局SDK实例
|
|
@@ -20943,6 +21058,13 @@ const getConnectionStatus = () => {
|
|
|
20943
21058
|
const sdk = getInstance();
|
|
20944
21059
|
return sdk.getConnectionStatus();
|
|
20945
21060
|
};
|
|
21061
|
+
/**
|
|
21062
|
+
* 获取初始化信息(设备ID等)
|
|
21063
|
+
*/
|
|
21064
|
+
const getInitResult = () => {
|
|
21065
|
+
const sdk = getInstance();
|
|
21066
|
+
return sdk.getInitResult();
|
|
21067
|
+
};
|
|
20946
21068
|
/**
|
|
20947
21069
|
* 消息通知API
|
|
20948
21070
|
*/
|
|
@@ -20986,6 +21108,7 @@ const updateScreenshotOptions = (options) => {
|
|
|
20986
21108
|
var index = {
|
|
20987
21109
|
init,
|
|
20988
21110
|
getInstance,
|
|
21111
|
+
getInitResult,
|
|
20989
21112
|
showIcon,
|
|
20990
21113
|
hideIcon,
|
|
20991
21114
|
setIconPosition,
|
|
@@ -21014,6 +21137,7 @@ exports.default = index;
|
|
|
21014
21137
|
exports.destroy = destroy;
|
|
21015
21138
|
exports.enableScreenshot = enableScreenshot;
|
|
21016
21139
|
exports.getConnectionStatus = getConnectionStatus;
|
|
21140
|
+
exports.getInitResult = getInitResult;
|
|
21017
21141
|
exports.getInstance = getInstance;
|
|
21018
21142
|
exports.getScreenshotState = getScreenshotState;
|
|
21019
21143
|
exports.hideIcon = hideIcon;
|