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
package/dist/customer-sdk.esm.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// 直接使用base64字符串,避免打包后路径问题
|
|
2
2
|
const iconImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHgAAAB4CAYAAAA5ZDbSAAAACXBIWXMAABYlAAAWJQFJUiTwAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAArKSURBVHgB7Z1NbFTXFcf/93mwaGyEabLoIgFTqWRFMZUitSoIu80ial01SFWrKgsGKXYpWdRtFilRK4xUgbKICosmCKIySKCo2UAE6i61XVroDuOoi2YT02RZVFNwQTAzN+e8N88ej9+8j5n3ce5wf5JhPvyY4f3f/9xzz73vXoUeYKish6oljCiFYQ2MaAebVR3D/Jzf1xpDUPTTggIW6feXoOlH0Q9wS9exRK/Pl6qYX6qoJRiOgoEMvqpHWUjlYJ9iQeEJmTb07y6y2CT6HP99/z01C8MwQmB26OMSyuTIH9LTkSA35oLn9FmKCB/WHmP2YUUtQjhiBV4jqsIoJKJJbOC8ZLHFCczhl75UWXvCFuPUDiBXV5TGeWlhXIzALCx9m6Ni3RqfeRL71PJZVYEAChfYdayDc1klSkXBCRr9caxooQsTuIccG4qbiddxsKjQnbvAlDwNVzfgXK8L2wq30ZSMHcs7GctV4IFX9ZTy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
class IconManager {
|
|
4
|
-
constructor(position) {
|
|
4
|
+
constructor(position, debug = false) {
|
|
5
5
|
this.iconElement = null;
|
|
6
6
|
this.badgeElement = null;
|
|
7
7
|
this.onClickCallback = null;
|
|
@@ -14,7 +14,9 @@ class IconManager {
|
|
|
14
14
|
this.dragMoveHandler = null;
|
|
15
15
|
this.dragEndHandler = null;
|
|
16
16
|
this.iconPosition = null; // 图标位置配置
|
|
17
|
+
this.debug = false; // debug 模式标志
|
|
17
18
|
this.iconPosition = position || null;
|
|
19
|
+
this.debug = debug;
|
|
18
20
|
}
|
|
19
21
|
/**
|
|
20
22
|
* 显示悬浮图标
|
|
@@ -82,7 +84,9 @@ class IconManager {
|
|
|
82
84
|
iconImg.alt = 'Customer Service';
|
|
83
85
|
// 添加图片加载成功处理
|
|
84
86
|
iconImg.onload = () => {
|
|
85
|
-
|
|
87
|
+
if (this.debug) {
|
|
88
|
+
console.log('Icon image loaded successfully');
|
|
89
|
+
}
|
|
86
90
|
if (this.iconElement) {
|
|
87
91
|
// 确保图片可见
|
|
88
92
|
iconImg.style.opacity = '1';
|
|
@@ -91,6 +95,7 @@ class IconManager {
|
|
|
91
95
|
};
|
|
92
96
|
// 添加图片加载错误处理
|
|
93
97
|
iconImg.onerror = (e) => {
|
|
98
|
+
// 错误始终输出
|
|
94
99
|
console.error('Failed to load icon image', e);
|
|
95
100
|
// 只记录错误,不使用默认样式,必须使用外部提供的图片
|
|
96
101
|
};
|
|
@@ -112,7 +117,9 @@ class IconManager {
|
|
|
112
117
|
this.setupDragEvents();
|
|
113
118
|
// 添加到页面
|
|
114
119
|
document.body.appendChild(this.iconElement);
|
|
115
|
-
|
|
120
|
+
if (this.debug) {
|
|
121
|
+
console.log('CustomerSDK icon displayed');
|
|
122
|
+
}
|
|
116
123
|
}
|
|
117
124
|
/**
|
|
118
125
|
* 强制清理所有拖动事件监听器
|
|
@@ -125,7 +132,9 @@ class IconManager {
|
|
|
125
132
|
document.removeEventListener('touchmove', this.dragMoveHandler);
|
|
126
133
|
}
|
|
127
134
|
catch (e) {
|
|
128
|
-
|
|
135
|
+
if (this.debug) {
|
|
136
|
+
console.warn('Error removing drag move listeners:', e);
|
|
137
|
+
}
|
|
129
138
|
}
|
|
130
139
|
}
|
|
131
140
|
if (this.dragEndHandler) {
|
|
@@ -134,7 +143,9 @@ class IconManager {
|
|
|
134
143
|
document.removeEventListener('touchend', this.dragEndHandler);
|
|
135
144
|
}
|
|
136
145
|
catch (e) {
|
|
137
|
-
|
|
146
|
+
if (this.debug) {
|
|
147
|
+
console.warn('Error removing drag end listeners:', e);
|
|
148
|
+
}
|
|
138
149
|
}
|
|
139
150
|
}
|
|
140
151
|
// 重置拖动状态
|
|
@@ -157,7 +168,9 @@ class IconManager {
|
|
|
157
168
|
this.onClickCallback = null;
|
|
158
169
|
this.dragMoveHandler = null;
|
|
159
170
|
this.dragEndHandler = null;
|
|
160
|
-
|
|
171
|
+
if (this.debug) {
|
|
172
|
+
console.log('CustomerSDK icon hidden');
|
|
173
|
+
}
|
|
161
174
|
}
|
|
162
175
|
}
|
|
163
176
|
/**
|
|
@@ -214,7 +227,9 @@ class IconManager {
|
|
|
214
227
|
*/
|
|
215
228
|
showNotification(options) {
|
|
216
229
|
if (!this.iconElement) {
|
|
217
|
-
|
|
230
|
+
if (this.debug) {
|
|
231
|
+
console.warn('Icon not displayed, cannot show notification');
|
|
232
|
+
}
|
|
218
233
|
return;
|
|
219
234
|
}
|
|
220
235
|
const { showBadge = true, badgeCount = 0, badgeText = '', pulse = false } = options;
|
|
@@ -226,7 +241,9 @@ class IconManager {
|
|
|
226
241
|
if (this.notificationCallback) {
|
|
227
242
|
this.notificationCallback({ badgeCount, badgeText, pulse });
|
|
228
243
|
}
|
|
229
|
-
|
|
244
|
+
if (this.debug) {
|
|
245
|
+
console.log('Notification shown:', { badgeCount, badgeText });
|
|
246
|
+
}
|
|
230
247
|
}
|
|
231
248
|
/**
|
|
232
249
|
* 清除消息订阅
|
|
@@ -236,7 +253,9 @@ class IconManager {
|
|
|
236
253
|
this.badgeElement.remove();
|
|
237
254
|
this.badgeElement = null;
|
|
238
255
|
}
|
|
239
|
-
|
|
256
|
+
if (this.debug) {
|
|
257
|
+
console.log('Notification cleared');
|
|
258
|
+
}
|
|
240
259
|
}
|
|
241
260
|
/**
|
|
242
261
|
* 设置拖动和点击事件
|
|
@@ -460,6 +479,7 @@ class IframeManager {
|
|
|
460
479
|
this.containerElement = null; // 包装容器,包含iframe和关闭按钮
|
|
461
480
|
this.isOpen = false;
|
|
462
481
|
this.isCreated = false;
|
|
482
|
+
this.debug = false; // debug 模式标志
|
|
463
483
|
this.config = {
|
|
464
484
|
src: '',
|
|
465
485
|
mode: 'auto', // 默认自动检测设备类型
|
|
@@ -468,6 +488,7 @@ class IframeManager {
|
|
|
468
488
|
allowClose: true,
|
|
469
489
|
...config
|
|
470
490
|
};
|
|
491
|
+
this.debug = config.debug ?? false;
|
|
471
492
|
this.setupMessageListener();
|
|
472
493
|
}
|
|
473
494
|
/**
|
|
@@ -479,9 +500,12 @@ class IframeManager {
|
|
|
479
500
|
// 创建隐藏的iframe(预连接到SSE)
|
|
480
501
|
this.createIframe();
|
|
481
502
|
this.isCreated = true;
|
|
482
|
-
|
|
503
|
+
if (this.debug) {
|
|
504
|
+
console.log('CustomerSDK iframe initialized (hidden, SSE connected)');
|
|
505
|
+
}
|
|
483
506
|
}
|
|
484
507
|
catch (error) {
|
|
508
|
+
// 错误始终输出
|
|
485
509
|
console.error('Failed to initialize iframe:', error);
|
|
486
510
|
throw error;
|
|
487
511
|
}
|
|
@@ -532,9 +556,12 @@ class IframeManager {
|
|
|
532
556
|
}
|
|
533
557
|
}
|
|
534
558
|
this.isOpen = true;
|
|
535
|
-
|
|
559
|
+
if (this.debug) {
|
|
560
|
+
console.log('CustomerSDK iframe shown');
|
|
561
|
+
}
|
|
536
562
|
}
|
|
537
563
|
catch (error) {
|
|
564
|
+
// 错误始终输出
|
|
538
565
|
console.error('Failed to show iframe:', error);
|
|
539
566
|
}
|
|
540
567
|
}
|
|
@@ -570,7 +597,9 @@ class IframeManager {
|
|
|
570
597
|
this.preventBodyScroll(false);
|
|
571
598
|
}
|
|
572
599
|
this.isOpen = false;
|
|
573
|
-
|
|
600
|
+
if (this.debug) {
|
|
601
|
+
console.log('CustomerSDK iframe hidden (SSE still connected)');
|
|
602
|
+
}
|
|
574
603
|
// 触发关闭回调
|
|
575
604
|
if (this.config.onClose) {
|
|
576
605
|
this.config.onClose();
|
|
@@ -593,7 +622,9 @@ class IframeManager {
|
|
|
593
622
|
this.iframeElement = null;
|
|
594
623
|
}
|
|
595
624
|
this.isCreated = false;
|
|
596
|
-
|
|
625
|
+
if (this.debug) {
|
|
626
|
+
console.log('CustomerSDK container destroyed');
|
|
627
|
+
}
|
|
597
628
|
}
|
|
598
629
|
/**
|
|
599
630
|
* 检查是否已打开
|
|
@@ -744,7 +775,9 @@ class IframeManager {
|
|
|
744
775
|
});
|
|
745
776
|
// 添加到body(预连接SSE,但不显示)
|
|
746
777
|
document.body.appendChild(this.containerElement);
|
|
747
|
-
|
|
778
|
+
if (this.debug) {
|
|
779
|
+
console.log('CustomerSDK container created (hidden, ready for SSE)');
|
|
780
|
+
}
|
|
748
781
|
}
|
|
749
782
|
/**
|
|
750
783
|
* 向iframe注入移动端优化样式(隐藏滚动条)
|
|
@@ -796,12 +829,16 @@ class IframeManager {
|
|
|
796
829
|
`;
|
|
797
830
|
// 注入样式
|
|
798
831
|
iframeDoc.head?.appendChild(style);
|
|
799
|
-
|
|
832
|
+
if (this.debug) {
|
|
833
|
+
console.log('CustomerSDK mobile styles injected successfully');
|
|
834
|
+
}
|
|
800
835
|
}
|
|
801
836
|
}
|
|
802
837
|
catch (error) {
|
|
803
838
|
// 跨域限制时静默忽略
|
|
804
|
-
|
|
839
|
+
if (this.debug) {
|
|
840
|
+
console.log('Cannot inject styles due to cross-origin restrictions:', error);
|
|
841
|
+
}
|
|
805
842
|
}
|
|
806
843
|
}
|
|
807
844
|
/**
|
|
@@ -868,7 +905,9 @@ class IframeManager {
|
|
|
868
905
|
* 处理来自iframe的消息
|
|
869
906
|
*/
|
|
870
907
|
handleIframeMessage(data) {
|
|
871
|
-
|
|
908
|
+
if (this.debug) {
|
|
909
|
+
console.log('Message from iframe:', data);
|
|
910
|
+
}
|
|
872
911
|
// 判断data是字符串还是对象,兼容两种格式
|
|
873
912
|
let messageType;
|
|
874
913
|
if (typeof data === 'string') {
|
|
@@ -878,13 +917,17 @@ class IframeManager {
|
|
|
878
917
|
messageType = data.type;
|
|
879
918
|
}
|
|
880
919
|
else {
|
|
881
|
-
|
|
920
|
+
if (this.debug) {
|
|
921
|
+
console.log('Unknown message format:', data);
|
|
922
|
+
}
|
|
882
923
|
return;
|
|
883
924
|
}
|
|
884
925
|
// 根据消息类型处理不同的操作
|
|
885
926
|
switch (messageType) {
|
|
886
927
|
case 'iframe_ready':
|
|
887
|
-
|
|
928
|
+
if (this.debug) {
|
|
929
|
+
console.log('Iframe is ready');
|
|
930
|
+
}
|
|
888
931
|
break;
|
|
889
932
|
case 'close_iframe':
|
|
890
933
|
case 'close':
|
|
@@ -898,14 +941,18 @@ class IframeManager {
|
|
|
898
941
|
break;
|
|
899
942
|
case 'new-message':
|
|
900
943
|
// 新消息通知 - 触发回调让外层处理
|
|
901
|
-
|
|
944
|
+
if (this.debug) {
|
|
945
|
+
console.log('Received new message notification');
|
|
946
|
+
}
|
|
902
947
|
if (this.config.onMessage) {
|
|
903
948
|
this.config.onMessage(messageType, data);
|
|
904
949
|
}
|
|
905
950
|
break;
|
|
906
951
|
default:
|
|
907
952
|
// 可以在这里添加自定义消息处理
|
|
908
|
-
|
|
953
|
+
if (this.debug) {
|
|
954
|
+
console.log('Custom message:', data);
|
|
955
|
+
}
|
|
909
956
|
}
|
|
910
957
|
}
|
|
911
958
|
/**
|
|
@@ -20607,27 +20654,47 @@ class CustomerServiceSDK {
|
|
|
20607
20654
|
this.screenshotManager = null;
|
|
20608
20655
|
this.config = null;
|
|
20609
20656
|
this.isInitialized = false;
|
|
20657
|
+
this.initResult = null; // 保存初始化结果
|
|
20658
|
+
this.debug = false; // debug 模式标志
|
|
20610
20659
|
}
|
|
20611
20660
|
/**
|
|
20612
20661
|
* 初始化 SDK
|
|
20613
20662
|
* @param config SDK配置
|
|
20614
20663
|
* @param options UI选项(可选)
|
|
20664
|
+
* @returns 返回初始化信息(包含设备ID等)
|
|
20615
20665
|
*/
|
|
20616
20666
|
async init(config, options) {
|
|
20617
20667
|
if (this.isInitialized) {
|
|
20618
|
-
|
|
20619
|
-
|
|
20668
|
+
if (this.debug) {
|
|
20669
|
+
console.warn('CustomerSDK already initialized');
|
|
20670
|
+
}
|
|
20671
|
+
// 如果已经初始化,返回之前保存的初始化信息
|
|
20672
|
+
if (this.initResult) {
|
|
20673
|
+
return this.initResult;
|
|
20674
|
+
}
|
|
20675
|
+
throw new Error('SDK already initialized but cannot retrieve initialization info');
|
|
20620
20676
|
}
|
|
20621
20677
|
this.config = config;
|
|
20678
|
+
this.debug = config.debug ?? false;
|
|
20622
20679
|
try {
|
|
20623
20680
|
// 获取设备指纹ID
|
|
20624
20681
|
const deviceId = await this.getDeviceId();
|
|
20625
|
-
|
|
20682
|
+
if (this.debug) {
|
|
20683
|
+
console.log('Device ID:', deviceId);
|
|
20684
|
+
}
|
|
20626
20685
|
// 构建iframe URL(带参数)
|
|
20627
20686
|
const iframeUrl = this.buildIframeUrl(config, deviceId);
|
|
20687
|
+
// 准备返回的初始化信息
|
|
20688
|
+
const initResult = {
|
|
20689
|
+
deviceId,
|
|
20690
|
+
iframeUrl,
|
|
20691
|
+
referrer: document.referrer,
|
|
20692
|
+
agent: config.agent,
|
|
20693
|
+
timestamp: Date.now()
|
|
20694
|
+
};
|
|
20628
20695
|
// 创建悬浮图标管理器(支持自定义位置)
|
|
20629
20696
|
const iconPosition = options?.iconPosition || undefined;
|
|
20630
|
-
this.iconManager = new IconManager(iconPosition);
|
|
20697
|
+
this.iconManager = new IconManager(iconPosition, this.debug);
|
|
20631
20698
|
await this.iconManager.show();
|
|
20632
20699
|
// 创建iframe管理器(自动检测设备类型)
|
|
20633
20700
|
this.iframeManager = new IframeManager({
|
|
@@ -20636,6 +20703,7 @@ class CustomerServiceSDK {
|
|
|
20636
20703
|
width: 400,
|
|
20637
20704
|
height: 600,
|
|
20638
20705
|
allowClose: true,
|
|
20706
|
+
debug: this.debug, // 传递 debug 标志
|
|
20639
20707
|
onMessage: (messageType, _data) => {
|
|
20640
20708
|
// 处理来自iframe的消息
|
|
20641
20709
|
if (messageType === 'new-message') {
|
|
@@ -20663,18 +20731,32 @@ class CustomerServiceSDK {
|
|
|
20663
20731
|
// 默认截图目标为 document.body,可以通过配置自定义
|
|
20664
20732
|
const targetElement = document.body;
|
|
20665
20733
|
// 传入发送消息到 iframe 的回调函数
|
|
20666
|
-
|
|
20734
|
+
// 将 debug 配置传递给截图管理器(通过 silentMode 的相反值)
|
|
20735
|
+
const screenshotOptions = {
|
|
20736
|
+
...config.screenshot,
|
|
20737
|
+
silentMode: !this.debug // debug=true 时 silentMode=false(显示日志),debug=false 时 silentMode=true(隐藏日志)
|
|
20738
|
+
};
|
|
20739
|
+
this.screenshotManager = new ScreenshotManager(targetElement, screenshotOptions, (data) => {
|
|
20667
20740
|
// 通过 IframeManager 发送消息到 iframe
|
|
20668
20741
|
this.iframeManager?.sendToIframe(data);
|
|
20669
20742
|
});
|
|
20670
20743
|
// 自动启用截图功能(用于测试,实际使用时需要通过 iframe 消息启用)
|
|
20671
20744
|
this.screenshotManager.enable(true);
|
|
20672
|
-
|
|
20745
|
+
if (this.debug) {
|
|
20746
|
+
console.log('CustomerSDK screenshot manager initialized and enabled');
|
|
20747
|
+
}
|
|
20673
20748
|
}
|
|
20674
20749
|
this.isInitialized = true;
|
|
20675
|
-
|
|
20750
|
+
// 保存初始化结果,以便后续获取
|
|
20751
|
+
this.initResult = initResult;
|
|
20752
|
+
if (this.debug) {
|
|
20753
|
+
console.log('CustomerSDK initialized successfully (iframe pre-connected to SSE)');
|
|
20754
|
+
}
|
|
20755
|
+
// 返回初始化信息
|
|
20756
|
+
return initResult;
|
|
20676
20757
|
}
|
|
20677
20758
|
catch (error) {
|
|
20759
|
+
// 错误始终输出
|
|
20678
20760
|
console.error('Failed to initialize CustomerSDK:', error);
|
|
20679
20761
|
throw error;
|
|
20680
20762
|
}
|
|
@@ -20743,7 +20825,9 @@ class CustomerServiceSDK {
|
|
|
20743
20825
|
*/
|
|
20744
20826
|
showNotification(badgeCount = 1, options = {}) {
|
|
20745
20827
|
if (!this.iconManager) {
|
|
20746
|
-
|
|
20828
|
+
if (this.debug) {
|
|
20829
|
+
console.warn('SDK not initialized');
|
|
20830
|
+
}
|
|
20747
20831
|
return;
|
|
20748
20832
|
}
|
|
20749
20833
|
this.iconManager.showNotification({
|
|
@@ -20775,7 +20859,9 @@ class CustomerServiceSDK {
|
|
|
20775
20859
|
*/
|
|
20776
20860
|
async captureScreenshot(force = false) {
|
|
20777
20861
|
if (!this.screenshotManager) {
|
|
20778
|
-
|
|
20862
|
+
if (this.debug) {
|
|
20863
|
+
console.warn('截图功能未启用');
|
|
20864
|
+
}
|
|
20779
20865
|
return false;
|
|
20780
20866
|
}
|
|
20781
20867
|
return await this.screenshotManager.captureOnce(force);
|
|
@@ -20785,11 +20871,15 @@ class CustomerServiceSDK {
|
|
|
20785
20871
|
*/
|
|
20786
20872
|
enableScreenshot(enabled) {
|
|
20787
20873
|
if (!this.screenshotManager) {
|
|
20788
|
-
|
|
20874
|
+
if (this.debug) {
|
|
20875
|
+
console.warn('截图管理器未初始化');
|
|
20876
|
+
}
|
|
20789
20877
|
return;
|
|
20790
20878
|
}
|
|
20791
20879
|
this.screenshotManager.enable(enabled);
|
|
20792
|
-
|
|
20880
|
+
if (this.debug) {
|
|
20881
|
+
console.log(`📸 截图功能已${enabled ? '启用' : '禁用'}`);
|
|
20882
|
+
}
|
|
20793
20883
|
}
|
|
20794
20884
|
/**
|
|
20795
20885
|
* 获取截图状态
|
|
@@ -20803,11 +20893,15 @@ class CustomerServiceSDK {
|
|
|
20803
20893
|
*/
|
|
20804
20894
|
updateScreenshotOptions(options) {
|
|
20805
20895
|
if (!this.screenshotManager) {
|
|
20806
|
-
|
|
20896
|
+
if (this.debug) {
|
|
20897
|
+
console.warn('截图管理器未初始化,无法更新配置');
|
|
20898
|
+
}
|
|
20807
20899
|
return;
|
|
20808
20900
|
}
|
|
20809
20901
|
this.screenshotManager.updateOptions(options);
|
|
20810
|
-
|
|
20902
|
+
if (this.debug) {
|
|
20903
|
+
console.log('📸 截图配置已更新:', options);
|
|
20904
|
+
}
|
|
20811
20905
|
}
|
|
20812
20906
|
/**
|
|
20813
20907
|
* 销毁 SDK
|
|
@@ -20820,27 +20914,47 @@ class CustomerServiceSDK {
|
|
|
20820
20914
|
this.iframeManager = null;
|
|
20821
20915
|
this.screenshotManager = null;
|
|
20822
20916
|
this.config = null;
|
|
20917
|
+
this.initResult = null;
|
|
20823
20918
|
this.isInitialized = false;
|
|
20824
|
-
|
|
20919
|
+
if (this.debug) {
|
|
20920
|
+
console.log('CustomerSDK destroyed');
|
|
20921
|
+
}
|
|
20922
|
+
}
|
|
20923
|
+
/**
|
|
20924
|
+
* 获取初始化信息(设备ID等)
|
|
20925
|
+
*/
|
|
20926
|
+
getInitResult() {
|
|
20927
|
+
return this.initResult;
|
|
20825
20928
|
}
|
|
20826
20929
|
/**
|
|
20827
20930
|
* 获取设备指纹ID
|
|
20828
20931
|
*/
|
|
20829
20932
|
async getDeviceId() {
|
|
20830
|
-
|
|
20933
|
+
if (this.debug) {
|
|
20934
|
+
console.log('🔍 Starting to get device fingerprint...');
|
|
20935
|
+
}
|
|
20831
20936
|
try {
|
|
20832
|
-
|
|
20937
|
+
if (this.debug) {
|
|
20938
|
+
console.log('📦 Loading FingerprintJS...');
|
|
20939
|
+
}
|
|
20833
20940
|
const fp = await index$1.load();
|
|
20834
|
-
|
|
20941
|
+
if (this.debug) {
|
|
20942
|
+
console.log('🎯 Getting device fingerprint...');
|
|
20943
|
+
}
|
|
20835
20944
|
const result = await fp.get();
|
|
20836
|
-
|
|
20837
|
-
|
|
20945
|
+
if (this.debug) {
|
|
20946
|
+
console.log('✅ FingerprintJS result:', result);
|
|
20947
|
+
console.log('🆔 Device ID obtained:', result.visitorId);
|
|
20948
|
+
}
|
|
20838
20949
|
return result.visitorId;
|
|
20839
20950
|
}
|
|
20840
20951
|
catch (error) {
|
|
20952
|
+
// 错误始终输出
|
|
20841
20953
|
console.warn('❌ Failed to get device fingerprint, using fallback:', error);
|
|
20842
20954
|
const fallbackId = 'device_' + Date.now() + '_' + Math.random().toString(36).substr(2, 9);
|
|
20843
|
-
|
|
20955
|
+
if (this.debug) {
|
|
20956
|
+
console.log('🆔 Fallback Device ID:', fallbackId);
|
|
20957
|
+
}
|
|
20844
20958
|
return fallbackId;
|
|
20845
20959
|
}
|
|
20846
20960
|
}
|
|
@@ -20871,12 +20985,13 @@ let globalSDKInstance = null;
|
|
|
20871
20985
|
* 初始化 Customer SDK
|
|
20872
20986
|
* @param config SDK配置
|
|
20873
20987
|
* @param options UI选项(可选)
|
|
20988
|
+
* @returns 返回初始化信息(包含设备ID等)
|
|
20874
20989
|
*/
|
|
20875
20990
|
const init = async (config, options) => {
|
|
20876
20991
|
if (!globalSDKInstance) {
|
|
20877
20992
|
globalSDKInstance = new CustomerServiceSDK();
|
|
20878
20993
|
}
|
|
20879
|
-
await globalSDKInstance.init(config, options);
|
|
20994
|
+
return await globalSDKInstance.init(config, options);
|
|
20880
20995
|
};
|
|
20881
20996
|
/**
|
|
20882
20997
|
* 获取全局SDK实例
|
|
@@ -20939,6 +21054,13 @@ const getConnectionStatus = () => {
|
|
|
20939
21054
|
const sdk = getInstance();
|
|
20940
21055
|
return sdk.getConnectionStatus();
|
|
20941
21056
|
};
|
|
21057
|
+
/**
|
|
21058
|
+
* 获取初始化信息(设备ID等)
|
|
21059
|
+
*/
|
|
21060
|
+
const getInitResult = () => {
|
|
21061
|
+
const sdk = getInstance();
|
|
21062
|
+
return sdk.getInitResult();
|
|
21063
|
+
};
|
|
20942
21064
|
/**
|
|
20943
21065
|
* 消息通知API
|
|
20944
21066
|
*/
|
|
@@ -20982,6 +21104,7 @@ const updateScreenshotOptions = (options) => {
|
|
|
20982
21104
|
var index = {
|
|
20983
21105
|
init,
|
|
20984
21106
|
getInstance,
|
|
21107
|
+
getInitResult,
|
|
20985
21108
|
showIcon,
|
|
20986
21109
|
hideIcon,
|
|
20987
21110
|
setIconPosition,
|
|
@@ -21002,4 +21125,4 @@ var index = {
|
|
|
21002
21125
|
destroy
|
|
21003
21126
|
};
|
|
21004
21127
|
|
|
21005
|
-
export { CustomerServiceSDK, captureScreenshot, clearNotification, closeChat, index as default, destroy, enableScreenshot, getConnectionStatus, getInstance, getScreenshotState, hideIcon, init, isChatOpen, openChat, sendToIframe, setIconCoordinates, setIconPosition, setIconStyle, setScreenshotTarget, showIcon, showNotification, updateScreenshotOptions };
|
|
21128
|
+
export { CustomerServiceSDK, captureScreenshot, clearNotification, closeChat, index as default, destroy, enableScreenshot, getConnectionStatus, getInitResult, getInstance, getScreenshotState, hideIcon, init, isChatOpen, openChat, sendToIframe, setIconCoordinates, setIconPosition, setIconStyle, setScreenshotTarget, showIcon, showNotification, updateScreenshotOptions };
|