@trtc/calls-uikit-vue 4.4.9 → 4.5.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trtc/calls-uikit-vue",
3
- "version": "4.4.9",
3
+ "version": "4.5.0",
4
4
  "main": "./tuicall-uikit-vue.umd.js",
5
5
  "module": "./tuicall-uikit-vue.es.js",
6
6
  "types": "./types/index.d.ts",
@@ -14,8 +14,8 @@
14
14
  },
15
15
  "dependencies": {
16
16
  "@tencentcloud/lite-chat": "^1.6.3",
17
- "@tencentcloud/tui-core-lite": "~1.0.0",
18
- "@trtc/call-engine-lite-js": "~3.5.8"
17
+ "@tencentcloud/tui-core-lite": "~1.0.1",
18
+ "@trtc/call-engine-lite-js": "~4.0.0"
19
19
  },
20
20
  "bugs": {
21
21
  "url": "https://github.com/tencentyun/TUICallKit/issues"
@@ -0,0 +1,182 @@
1
+ /**
2
+ * BackgroundHandler - Mini Program background detection and auto hangup handler
3
+ *
4
+ * When mini program goes to background for more than 4s, automatically hang up the call
5
+ * to avoid issues caused by WeChat disconnecting WebSocket after 5s.
6
+ */
7
+
8
+ import { CallStatus, CallRole, StoreName, NAME } from '../const/index';
9
+ import TuiStore from '../TUIStore/tuiStore';
10
+ import { ITUIStore } from '../interface/index';
11
+ const TUIStore: ITUIStore = TuiStore.getInstance();
12
+
13
+ export interface IBackgroundConfig {
14
+ enableAutoHangup: boolean; // Enable auto hangup on background (default: true)
15
+ hangupTimeout: number; // Auto hangup timeout in ms (default: 4000)
16
+ }
17
+ const DEFAULT_BACKGROUND_CONFIG: IBackgroundConfig = {
18
+ enableAutoHangup: true,
19
+ hangupTimeout: 4000, // 4s auto hangup (before ws disconnects at 5s)
20
+ };
21
+
22
+ export default class BackgroundHandler {
23
+ private _callService: any;
24
+ private _hangupTimer: ReturnType<typeof setTimeout> | null = null;
25
+ private _backgroundTimestamp: number = 0;
26
+ private _isInBackground: boolean = false;
27
+ private _config: IBackgroundConfig = { ...DEFAULT_BACKGROUND_CONFIG };
28
+ private _isInitialized: boolean = false;
29
+
30
+ constructor(callService: any) {
31
+ this._callService = callService;
32
+ }
33
+
34
+ // Initialize background detection for mini program; Listen to wx.onAppHide/onAppShow events
35
+ public initBackgroundDetection(): void {
36
+ if (this._isInitialized) return;
37
+
38
+ try {
39
+ // @ts-ignore
40
+ if (typeof wx !== 'undefined' && wx.onAppHide && wx.onAppShow) {
41
+ // @ts-ignore
42
+ wx.onAppHide(this._handleAppHide);
43
+ // @ts-ignore
44
+ wx.onAppShow(this._handleAppShow);
45
+ this._isInitialized = true;
46
+ console.log('[TUICallKit] BackgroundHandler initialized');
47
+ }
48
+ } catch (error) {
49
+ console.warn('[TUICallKit] BackgroundHandler init failed:', error);
50
+ }
51
+ }
52
+
53
+ // Destroy background detection; Remove event listeners and clear timers
54
+ public destroyBackgroundDetection(): void {
55
+ if (!this._isInitialized) return;
56
+
57
+ try {
58
+ // @ts-ignore
59
+ if (typeof wx !== 'undefined' && wx.offAppHide && wx.offAppShow) {
60
+ // @ts-ignore
61
+ wx.offAppHide(this._handleAppHide);
62
+ // @ts-ignore
63
+ wx.offAppShow(this._handleAppShow);
64
+ }
65
+ this._clearTimers();
66
+ this._isInitialized = false;
67
+ console.log('[TUICallKit] BackgroundHandler destroyed');
68
+ } catch (error) {
69
+ console.warn('[TUICallKit] BackgroundHandler destroy failed:', error);
70
+ }
71
+ }
72
+
73
+ // Handle app hide event (going to background)
74
+ private _handleAppHide = (): void => {
75
+ const callStatus = TUIStore.getData(StoreName.CALL, NAME.CALL_STATUS) || CallStatus.IDLE;
76
+ const callRole = TUIStore.getData(StoreName.CALL, NAME.CALL_ROLE) || CallRole.UNKNOWN;
77
+
78
+ // Only handle when in connected state (as per requirement: only for connected calls)
79
+ if ((callStatus !== CallStatus.CONNECTED) || !this._config.enableAutoHangup) return;
80
+
81
+ this._isInBackground = true;
82
+ this._backgroundTimestamp = Date.now();
83
+ this._callService?._tuiCallEngine?.reportLog?.({
84
+ name: 'TUICallkit.background.appHide',
85
+ data: { callStatus, callRole, timestamp: this._backgroundTimestamp, config: this._config },
86
+ });
87
+
88
+ this._hangupTimer = setTimeout(() => {
89
+ this._handleBackgroundTimeout();
90
+ }, this._config.hangupTimeout);
91
+ };
92
+
93
+ // Handle app show event (returning from background)
94
+ private _handleAppShow = (): void => {
95
+ if (!this._isInBackground) return;
96
+
97
+ const backgroundDuration = Date.now() - this._backgroundTimestamp;
98
+ const callStatus = TUIStore.getData(StoreName.CALL, NAME.CALL_STATUS) || CallStatus.IDLE;
99
+ const callRole = TUIStore.getData(StoreName.CALL, NAME.CALL_ROLE) || CallRole.UNKNOWN;
100
+
101
+ this._callService?._tuiCallEngine?.reportLog?.({
102
+ name: 'TUICallkit.background.appShow',
103
+ data: { callStatus, callRole, backgroundDuration, timestamp: Date.now() },
104
+ });
105
+
106
+ this._isInBackground = false;
107
+ this._clearTimers();
108
+
109
+ // If background time exceeded hangup timeout, show toast to explain why call ended
110
+ if (backgroundDuration >= this._config.hangupTimeout) {
111
+ this._showToast('后台超时,通话已结束');
112
+ this._checkCallStatusAfterBackground();
113
+ }
114
+ };
115
+
116
+ // Show toast - compatible with both UniApp and native mini program
117
+ private _showToast(title: string): void {
118
+ try {
119
+ // @ts-ignore - UniApp API
120
+ if (typeof uni !== 'undefined' && uni?.showToast) {
121
+ // @ts-ignore
122
+ uni.showToast({ title, icon: 'none', duration: 2500 });
123
+ // @ts-ignore - Native mini program API
124
+ } else if (typeof wx !== 'undefined' && wx?.showToast) {
125
+ // @ts-ignore
126
+ wx.showToast({ title, icon: 'none', duration: 2500 });
127
+ }
128
+ } catch (error) {}
129
+ }
130
+
131
+ // Handle background timeout - auto hangup
132
+ private async _handleBackgroundTimeout(): Promise<void> {
133
+ try {
134
+ const callStatus = TUIStore.getData(StoreName.CALL, NAME.CALL_STATUS) || CallStatus.IDLE;
135
+ const callRole = TUIStore.getData(StoreName.CALL, NAME.CALL_ROLE) || CallRole.UNKNOWN;
136
+ const backgroundDuration = Date.now() - this._backgroundTimestamp;
137
+
138
+ // Report timeout event before hangup
139
+ this._callService?._tuiCallEngine?.reportLog?.({
140
+ name: 'TUICallkit.background.timeout',
141
+ data: { callStatus, callRole, backgroundDuration, hangupTimeout: this._config.hangupTimeout },
142
+ });
143
+
144
+ // Only handle CONNECTED state (CALLING state is filtered in _handleAppHide)
145
+ if (callStatus === CallStatus.CONNECTED) {
146
+ this._callService?._tuiCallEngine?.reportLog?.({
147
+ name: 'TUICallkit.background.hangup',
148
+ data: { callStatus, callRole, action: 'hangup' },
149
+ });
150
+ await this._callService?.hangup?.();
151
+ }
152
+ } catch (error) {
153
+ this._callService?._tuiCallEngine?.reportLog?.({
154
+ name: 'TUICallkit.background.hangup.fail',
155
+ data: { error: String(error) },
156
+ });
157
+ }
158
+ }
159
+
160
+ // Check call status after returning from long background; Handle case where call should have ended
161
+ private _checkCallStatusAfterBackground(): void {
162
+ try {
163
+ const callStatus = TUIStore.getData(StoreName.CALL, NAME.CALL_STATUS) || CallStatus.IDLE;
164
+ // If still in call state after exceeding timeout, something went wrong
165
+ // The call should have been ended by _handleBackgroundTimeout
166
+ if (callStatus !== CallStatus.IDLE) {
167
+ // Force reset if needed
168
+ this._callService?._resetCallStore?.();
169
+ }
170
+ } catch (error) {
171
+ console.warn('[TUICallKit] Check call status after background failed:', error);
172
+ }
173
+ }
174
+
175
+ // Clear hangup timer
176
+ private _clearTimers(): void {
177
+ if (this._hangupTimer) {
178
+ clearTimeout(this._hangupTimer);
179
+ this._hangupTimer = null;
180
+ }
181
+ }
182
+ }
@@ -27,7 +27,7 @@ const TUIGlobal: ITUIGlobal = TuiGlobal.getInstance();
27
27
  const TUIStore: ITUIStore = TuiStore.getInstance();
28
28
  const uiDesign = UIDesign.getInstance();
29
29
  uiDesign.setTUIStore(TUIStore);
30
- const version = '4.4.9';
30
+ const version = '4.5.0';
31
31
  import AIAssistant from './AIAssistant'; // 仅 web 支持 AI 实时字幕
32
32
  const frameWork = 'vue3';
33
33
  export { TUIGlobal, TUIStore, uiDesign };
package/src/index.ts CHANGED
@@ -37,7 +37,7 @@ const TUICallType = {
37
37
  AUDIO_CALL: 1,
38
38
  VIDEO_CALL: 2,
39
39
  };
40
- const Version = '4.4.9'; // basic-demo 原来上报使用
40
+ const Version = '4.5.0'; // basic-demo 原来上报使用
41
41
 
42
42
  // 输出产物
43
43
  export {