customer-chat-sdk 1.0.74 → 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/core/ScreenshotManager.d.ts.map +1 -1
- package/dist/customer-sdk.cjs.js +198 -48
- package/dist/customer-sdk.esm.js +198 -49
- 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/WHmP2YUUtQjhiBV4jqsIoJKJJbOC8ZLHFCczhl75UWXvCFuPUDiBXV5TGeWlhXIzALCx9m6Ni3RqfeRL71PJZVYEAChfYdayDc1klSkXBCRr9caxooQsTuIccG4qbiddxsKjQnbvAlDwNVzf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y6AAAAABJRU5ErkJggg==';
|
|
3
3
|
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
|
/**
|
|
@@ -15201,9 +15248,9 @@ class ScreenshotManager {
|
|
|
15201
15248
|
: (isMobile ? 0.5 : 0.6), // 用户未配置,使用默认值
|
|
15202
15249
|
useCORS: this.options.enableCORS,
|
|
15203
15250
|
allowTaint: !this.options.enableCORS, // 如果启用 CORS,不允许 taint
|
|
15204
|
-
logging: !this.options.silentMode,
|
|
15205
|
-
foreignObjectRendering: true,
|
|
15206
|
-
removeContainer: true, //
|
|
15251
|
+
logging: !this.options.silentMode, // 使用配置的静默模式
|
|
15252
|
+
// foreignObjectRendering: true, // ❌ 移除:可能导致跨域图片不显示
|
|
15253
|
+
// removeContainer: true, // ❌ 移除:移到后面,避免重复定义
|
|
15207
15254
|
// 不设置 width 和 height,让 html2canvas 自动计算
|
|
15208
15255
|
// width: finalWidth, // ❌ 移除,会导致宽度不正确
|
|
15209
15256
|
// height: finalHeight, // ❌ 移除,会导致高度不正确
|
|
@@ -15393,11 +15440,37 @@ class ScreenshotManager {
|
|
|
15393
15440
|
const cachedDataUrl = this.getCachedImage(originalSrc);
|
|
15394
15441
|
if (cachedDataUrl) {
|
|
15395
15442
|
img.src = cachedDataUrl;
|
|
15443
|
+
if (!this.options.silentMode) {
|
|
15444
|
+
console.log(`📸 使用缓存的图片: ${originalSrc.substring(0, 50)}...`);
|
|
15445
|
+
}
|
|
15396
15446
|
return;
|
|
15397
15447
|
}
|
|
15398
|
-
// 对于跨域图片,使用代理 URL
|
|
15399
|
-
//
|
|
15400
|
-
|
|
15448
|
+
// 对于跨域图片,使用代理 URL 替换
|
|
15449
|
+
// 构建代理 URL
|
|
15450
|
+
try {
|
|
15451
|
+
if (!this.options.proxyUrl) {
|
|
15452
|
+
if (!this.options.silentMode) {
|
|
15453
|
+
console.warn(`📸 ⚠️ 未配置代理 URL,跨域图片可能无法显示: ${originalSrc}`);
|
|
15454
|
+
}
|
|
15455
|
+
return;
|
|
15456
|
+
}
|
|
15457
|
+
const params = new URLSearchParams({
|
|
15458
|
+
url: originalSrc,
|
|
15459
|
+
});
|
|
15460
|
+
let baseUrl = this.options.proxyUrl.trim();
|
|
15461
|
+
// 移除末尾的 ? 或 &(如果有)
|
|
15462
|
+
baseUrl = baseUrl.replace(/[?&]$/, '');
|
|
15463
|
+
const proxyUrl = `${baseUrl}?${params.toString()}`;
|
|
15464
|
+
img.src = proxyUrl;
|
|
15465
|
+
if (!this.options.silentMode) {
|
|
15466
|
+
console.log(`📸 使用代理 URL 替换跨域图片: ${originalSrc.substring(0, 50)}... -> ${proxyUrl.substring(0, 50)}...`);
|
|
15467
|
+
}
|
|
15468
|
+
}
|
|
15469
|
+
catch (error) {
|
|
15470
|
+
if (!this.options.silentMode) {
|
|
15471
|
+
console.warn(`📸 ⚠️ 处理图片 URL 失败: ${originalSrc}`, error);
|
|
15472
|
+
}
|
|
15473
|
+
}
|
|
15401
15474
|
});
|
|
15402
15475
|
};
|
|
15403
15476
|
}
|
|
@@ -20581,27 +20654,47 @@ class CustomerServiceSDK {
|
|
|
20581
20654
|
this.screenshotManager = null;
|
|
20582
20655
|
this.config = null;
|
|
20583
20656
|
this.isInitialized = false;
|
|
20657
|
+
this.initResult = null; // 保存初始化结果
|
|
20658
|
+
this.debug = false; // debug 模式标志
|
|
20584
20659
|
}
|
|
20585
20660
|
/**
|
|
20586
20661
|
* 初始化 SDK
|
|
20587
20662
|
* @param config SDK配置
|
|
20588
20663
|
* @param options UI选项(可选)
|
|
20664
|
+
* @returns 返回初始化信息(包含设备ID等)
|
|
20589
20665
|
*/
|
|
20590
20666
|
async init(config, options) {
|
|
20591
20667
|
if (this.isInitialized) {
|
|
20592
|
-
|
|
20593
|
-
|
|
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');
|
|
20594
20676
|
}
|
|
20595
20677
|
this.config = config;
|
|
20678
|
+
this.debug = config.debug ?? false;
|
|
20596
20679
|
try {
|
|
20597
20680
|
// 获取设备指纹ID
|
|
20598
20681
|
const deviceId = await this.getDeviceId();
|
|
20599
|
-
|
|
20682
|
+
if (this.debug) {
|
|
20683
|
+
console.log('Device ID:', deviceId);
|
|
20684
|
+
}
|
|
20600
20685
|
// 构建iframe URL(带参数)
|
|
20601
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
|
+
};
|
|
20602
20695
|
// 创建悬浮图标管理器(支持自定义位置)
|
|
20603
20696
|
const iconPosition = options?.iconPosition || undefined;
|
|
20604
|
-
this.iconManager = new IconManager(iconPosition);
|
|
20697
|
+
this.iconManager = new IconManager(iconPosition, this.debug);
|
|
20605
20698
|
await this.iconManager.show();
|
|
20606
20699
|
// 创建iframe管理器(自动检测设备类型)
|
|
20607
20700
|
this.iframeManager = new IframeManager({
|
|
@@ -20610,6 +20703,7 @@ class CustomerServiceSDK {
|
|
|
20610
20703
|
width: 400,
|
|
20611
20704
|
height: 600,
|
|
20612
20705
|
allowClose: true,
|
|
20706
|
+
debug: this.debug, // 传递 debug 标志
|
|
20613
20707
|
onMessage: (messageType, _data) => {
|
|
20614
20708
|
// 处理来自iframe的消息
|
|
20615
20709
|
if (messageType === 'new-message') {
|
|
@@ -20637,18 +20731,32 @@ class CustomerServiceSDK {
|
|
|
20637
20731
|
// 默认截图目标为 document.body,可以通过配置自定义
|
|
20638
20732
|
const targetElement = document.body;
|
|
20639
20733
|
// 传入发送消息到 iframe 的回调函数
|
|
20640
|
-
|
|
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) => {
|
|
20641
20740
|
// 通过 IframeManager 发送消息到 iframe
|
|
20642
20741
|
this.iframeManager?.sendToIframe(data);
|
|
20643
20742
|
});
|
|
20644
20743
|
// 自动启用截图功能(用于测试,实际使用时需要通过 iframe 消息启用)
|
|
20645
20744
|
this.screenshotManager.enable(true);
|
|
20646
|
-
|
|
20745
|
+
if (this.debug) {
|
|
20746
|
+
console.log('CustomerSDK screenshot manager initialized and enabled');
|
|
20747
|
+
}
|
|
20647
20748
|
}
|
|
20648
20749
|
this.isInitialized = true;
|
|
20649
|
-
|
|
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;
|
|
20650
20757
|
}
|
|
20651
20758
|
catch (error) {
|
|
20759
|
+
// 错误始终输出
|
|
20652
20760
|
console.error('Failed to initialize CustomerSDK:', error);
|
|
20653
20761
|
throw error;
|
|
20654
20762
|
}
|
|
@@ -20717,7 +20825,9 @@ class CustomerServiceSDK {
|
|
|
20717
20825
|
*/
|
|
20718
20826
|
showNotification(badgeCount = 1, options = {}) {
|
|
20719
20827
|
if (!this.iconManager) {
|
|
20720
|
-
|
|
20828
|
+
if (this.debug) {
|
|
20829
|
+
console.warn('SDK not initialized');
|
|
20830
|
+
}
|
|
20721
20831
|
return;
|
|
20722
20832
|
}
|
|
20723
20833
|
this.iconManager.showNotification({
|
|
@@ -20749,7 +20859,9 @@ class CustomerServiceSDK {
|
|
|
20749
20859
|
*/
|
|
20750
20860
|
async captureScreenshot(force = false) {
|
|
20751
20861
|
if (!this.screenshotManager) {
|
|
20752
|
-
|
|
20862
|
+
if (this.debug) {
|
|
20863
|
+
console.warn('截图功能未启用');
|
|
20864
|
+
}
|
|
20753
20865
|
return false;
|
|
20754
20866
|
}
|
|
20755
20867
|
return await this.screenshotManager.captureOnce(force);
|
|
@@ -20759,11 +20871,15 @@ class CustomerServiceSDK {
|
|
|
20759
20871
|
*/
|
|
20760
20872
|
enableScreenshot(enabled) {
|
|
20761
20873
|
if (!this.screenshotManager) {
|
|
20762
|
-
|
|
20874
|
+
if (this.debug) {
|
|
20875
|
+
console.warn('截图管理器未初始化');
|
|
20876
|
+
}
|
|
20763
20877
|
return;
|
|
20764
20878
|
}
|
|
20765
20879
|
this.screenshotManager.enable(enabled);
|
|
20766
|
-
|
|
20880
|
+
if (this.debug) {
|
|
20881
|
+
console.log(`📸 截图功能已${enabled ? '启用' : '禁用'}`);
|
|
20882
|
+
}
|
|
20767
20883
|
}
|
|
20768
20884
|
/**
|
|
20769
20885
|
* 获取截图状态
|
|
@@ -20777,11 +20893,15 @@ class CustomerServiceSDK {
|
|
|
20777
20893
|
*/
|
|
20778
20894
|
updateScreenshotOptions(options) {
|
|
20779
20895
|
if (!this.screenshotManager) {
|
|
20780
|
-
|
|
20896
|
+
if (this.debug) {
|
|
20897
|
+
console.warn('截图管理器未初始化,无法更新配置');
|
|
20898
|
+
}
|
|
20781
20899
|
return;
|
|
20782
20900
|
}
|
|
20783
20901
|
this.screenshotManager.updateOptions(options);
|
|
20784
|
-
|
|
20902
|
+
if (this.debug) {
|
|
20903
|
+
console.log('📸 截图配置已更新:', options);
|
|
20904
|
+
}
|
|
20785
20905
|
}
|
|
20786
20906
|
/**
|
|
20787
20907
|
* 销毁 SDK
|
|
@@ -20794,27 +20914,47 @@ class CustomerServiceSDK {
|
|
|
20794
20914
|
this.iframeManager = null;
|
|
20795
20915
|
this.screenshotManager = null;
|
|
20796
20916
|
this.config = null;
|
|
20917
|
+
this.initResult = null;
|
|
20797
20918
|
this.isInitialized = false;
|
|
20798
|
-
|
|
20919
|
+
if (this.debug) {
|
|
20920
|
+
console.log('CustomerSDK destroyed');
|
|
20921
|
+
}
|
|
20922
|
+
}
|
|
20923
|
+
/**
|
|
20924
|
+
* 获取初始化信息(设备ID等)
|
|
20925
|
+
*/
|
|
20926
|
+
getInitResult() {
|
|
20927
|
+
return this.initResult;
|
|
20799
20928
|
}
|
|
20800
20929
|
/**
|
|
20801
20930
|
* 获取设备指纹ID
|
|
20802
20931
|
*/
|
|
20803
20932
|
async getDeviceId() {
|
|
20804
|
-
|
|
20933
|
+
if (this.debug) {
|
|
20934
|
+
console.log('🔍 Starting to get device fingerprint...');
|
|
20935
|
+
}
|
|
20805
20936
|
try {
|
|
20806
|
-
|
|
20937
|
+
if (this.debug) {
|
|
20938
|
+
console.log('📦 Loading FingerprintJS...');
|
|
20939
|
+
}
|
|
20807
20940
|
const fp = await index$1.load();
|
|
20808
|
-
|
|
20941
|
+
if (this.debug) {
|
|
20942
|
+
console.log('🎯 Getting device fingerprint...');
|
|
20943
|
+
}
|
|
20809
20944
|
const result = await fp.get();
|
|
20810
|
-
|
|
20811
|
-
|
|
20945
|
+
if (this.debug) {
|
|
20946
|
+
console.log('✅ FingerprintJS result:', result);
|
|
20947
|
+
console.log('🆔 Device ID obtained:', result.visitorId);
|
|
20948
|
+
}
|
|
20812
20949
|
return result.visitorId;
|
|
20813
20950
|
}
|
|
20814
20951
|
catch (error) {
|
|
20952
|
+
// 错误始终输出
|
|
20815
20953
|
console.warn('❌ Failed to get device fingerprint, using fallback:', error);
|
|
20816
20954
|
const fallbackId = 'device_' + Date.now() + '_' + Math.random().toString(36).substr(2, 9);
|
|
20817
|
-
|
|
20955
|
+
if (this.debug) {
|
|
20956
|
+
console.log('🆔 Fallback Device ID:', fallbackId);
|
|
20957
|
+
}
|
|
20818
20958
|
return fallbackId;
|
|
20819
20959
|
}
|
|
20820
20960
|
}
|
|
@@ -20845,12 +20985,13 @@ let globalSDKInstance = null;
|
|
|
20845
20985
|
* 初始化 Customer SDK
|
|
20846
20986
|
* @param config SDK配置
|
|
20847
20987
|
* @param options UI选项(可选)
|
|
20988
|
+
* @returns 返回初始化信息(包含设备ID等)
|
|
20848
20989
|
*/
|
|
20849
20990
|
const init = async (config, options) => {
|
|
20850
20991
|
if (!globalSDKInstance) {
|
|
20851
20992
|
globalSDKInstance = new CustomerServiceSDK();
|
|
20852
20993
|
}
|
|
20853
|
-
await globalSDKInstance.init(config, options);
|
|
20994
|
+
return await globalSDKInstance.init(config, options);
|
|
20854
20995
|
};
|
|
20855
20996
|
/**
|
|
20856
20997
|
* 获取全局SDK实例
|
|
@@ -20913,6 +21054,13 @@ const getConnectionStatus = () => {
|
|
|
20913
21054
|
const sdk = getInstance();
|
|
20914
21055
|
return sdk.getConnectionStatus();
|
|
20915
21056
|
};
|
|
21057
|
+
/**
|
|
21058
|
+
* 获取初始化信息(设备ID等)
|
|
21059
|
+
*/
|
|
21060
|
+
const getInitResult = () => {
|
|
21061
|
+
const sdk = getInstance();
|
|
21062
|
+
return sdk.getInitResult();
|
|
21063
|
+
};
|
|
20916
21064
|
/**
|
|
20917
21065
|
* 消息通知API
|
|
20918
21066
|
*/
|
|
@@ -20956,6 +21104,7 @@ const updateScreenshotOptions = (options) => {
|
|
|
20956
21104
|
var index = {
|
|
20957
21105
|
init,
|
|
20958
21106
|
getInstance,
|
|
21107
|
+
getInitResult,
|
|
20959
21108
|
showIcon,
|
|
20960
21109
|
hideIcon,
|
|
20961
21110
|
setIconPosition,
|
|
@@ -20976,4 +21125,4 @@ var index = {
|
|
|
20976
21125
|
destroy
|
|
20977
21126
|
};
|
|
20978
21127
|
|
|
20979
|
-
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 };
|