diff --git a/TUIKit/components/TUIChat/message-input-toolbar/call-view/index.vue b/TUIKit/components/TUIChat/message-input-toolbar/call-view/index.vue
index 3379516..027abd6 100644
--- a/TUIKit/components/TUIChat/message-input-toolbar/call-view/index.vue
+++ b/TUIKit/components/TUIChat/message-input-toolbar/call-view/index.vue
@@ -1,106 +1,102 @@
-
-
-
+
+
-
+
-
+
\ No newline at end of file
diff --git a/pages.json b/pages.json
index e259bfc..a9ed9a1 100644
--- a/pages.json
+++ b/pages.json
@@ -444,14 +444,14 @@
{
"path": "pages/room/room",
"style": {
- "navigationBarTitleText": "拨打电话",
+ "navigationBarTitleText": "拨打视频",
"navigationStyle": "custom"
}
},
{
"path": "pages/room/incom",
"style": {
- "navigationBarTitleText": "拨打视频",
+ "navigationBarTitleText": "拨打电话",
"navigationStyle": "custom"
}
},
diff --git a/pages/room/room.nvue b/pages/room/room.nvue
index f010f5e..c939d28 100644
--- a/pages/room/room.nvue
+++ b/pages/room/room.nvue
@@ -150,24 +150,16 @@
},
onUnload() {
call.hangup()
- // this.removeAllListeners()
},
onHide() {
const session = call.getCurrentCallSession()
if (session) {
call.hangup()
}
- // this.removeAllListeners()
+ uni.$off('OnCallDisconnected')
+ uni.$off('OnCallConnected')
},
methods: {
- removeAllListeners(){
- //移除监听-接收到通话呼入
- call.removeRemoteUserJoinedListener();
- // 移除监听-通话已结束
- call.removeCallDisconnectedListener();
- // 移除监听-通话出现错误的回调
- call.removeErrorListener();
- },
changeMediaType() {
if (this.mediaTypeCur == 'video') {
this.mediaTypeCur = 'audio'
@@ -284,9 +276,9 @@
hangup() {
this.isSelf = true
call.hangup()
- uni.navigateBack({
- delta: 1
- })
+ // uni.navigateBack({
+ // delta: 1
+ // })
},
accept() {
call.accept()
@@ -324,12 +316,61 @@
)
}
},
-
onCallConnected() {
let context = this
console.log('oncallconnected接收了')
+ console.log('call: ',call);
+ // 使用 Promise 确保 call 对象完全初始化
+ this.initializeCall(call)
+ .then(() => {
+ this.processCallSession()
+ })
+ .catch(error => {
+ console.error('初始化通话失败:', error)
+ })
+ },
+ async initializeCall(callObj) {
+ // 等待 call 对象就绪
+ await this.waitForCallReady(callObj)
+
+ // 设置扬声器
+ if (callObj.enableSpeaker && typeof callObj.enableSpeaker === 'function') {
+ try {
+ callObj.enableSpeaker(true)
+ } catch (error) {
+ console.warn('设置扬声器失败:', error)
+ }
+ }
+
+ return callObj
+ },
+
+ waitForCallReady(callObj, timeout = 2000) {
+ return new Promise((resolve, reject) => {
+ const startTime = Date.now()
+
+ const check = () => {
+ const now = Date.now()
+
+ if (callObj &&
+ callObj.enableSpeaker &&
+ callObj.getCurrentCallSession &&
+ typeof callObj.getCurrentCallSession === 'function') {
+ resolve(callObj)
+ } else if (now - startTime > timeout) {
+ reject(new Error('call 对象初始化超时'))
+ } else {
+ setTimeout(check, 50)
+ }
+ }
+
+ check()
+ })
+ },
+
+ processCallSession(){
+ // call.enableSpeaker(true)
this.mediaTypeCur = this.mediaType
- call.enableSpeaker(true)
this.currentCallSession = call.getCurrentCallSession()
this.callWay = this.currentCallSession.callType
this.users = this.currentCallSession.users
@@ -347,6 +388,7 @@
) {
//视频是两个的时候
if (this.currentCallSession.users.length <= 2) {
+ console.log("视频是两个的时候");
setTimeout(() => {
this.systemInfoSync(
this.currentCallSession.mine.userId,
@@ -397,6 +439,7 @@
}
}
},
+
systemInfoSync(userId, ref, isZOrderOnTop) {
switch (uni.getSystemInfoSync().platform) {
case 'android':