Skip to content

Commit

Permalink
uni-app稳定版迁移 (#1210)
Browse files Browse the repository at this point in the history
feat: 更新小程序 calling 版本,提升稳定性
  • Loading branch information
jonyttang authored Jul 22, 2022
1 parent c56cb11 commit a5f2c7a
Show file tree
Hide file tree
Showing 78 changed files with 1,917 additions and 16,221 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ class TRTCCallingDelegate {
}

// 抛出用户接听
onUserAccept(userID) {
onUserAccept(userID, userList) {
this._emitter.emit(EVENT.USER_ACCEPT, {
userID,
userList,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,35 @@ export const EVENT = {

HANG_UP: 'HANG_UP',
ERROR: 'ERROR', // 组件内部抛出的错误
};
}

export const CALL_STATUS = {
IDLE: 'idle',
CALLING: 'calling',
CONNECTED: 'connected',
};
IDLE: 'idle', // 默认
CALLING: 'calling', //呼叫中/被呼叫中
CONNECTED: 'connected', //接通中
}

export const ACTION_TYPE = {
INVITE: 1, // 邀请方发起邀请
CANCEL_INVITE: 2, // 邀请方取消邀请
ACCEPT_INVITE: 3, // 被邀请方同意邀请
REJECT_INVITE: 4, // 被邀请方拒绝邀请
INVITE_TIMEOUT: 5, // 被邀请方超时未回复
};
}

export const BUSINESS_ID = {
SIGNAL: 1, // 信令
};
}

export const CALL_TYPE = {
AUDIO: 1,
VIDEO: 2,
};
}

export const CMD_TYPE_LIST = ['', 'audioCall', 'videoCall'];
export const CMD_TYPE_LIST = ['', 'audioCall', 'videoCall']

// audio视频切音频;video:音频切视频
export const MODE_TYPE = {
AUDIO: 'audio',
VIDEO: 'video',
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import TSignaling from './node_module/tsignaling-wx';
import TRTC from './node_module/trtc-wx'
import TIM from './node_module/tim-wx-sdk';


export {
TSignaling,
TRTC,
TIM
}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ class EventEmitter {
}
}

module.exports = EventEmitter
export default EventEmitter
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import TRTCCalling from './TRTCCalling/TRTCCalling.js';


const TAG_NAME = 'TUICalling';
// 组件旨在跨终端维护一个通话状态管理机,以事件发布机制驱动上层进行管理,并通过API调用进行状态变更。
// 组件设计思路将UI和状态管理分离。您可以通过修改`component`文件夹下的文件,适配您的业务场景,
// 在UI展示上,您可以通过属性的方式,将上层的用户头像,名称等数据传入组件内部,`static`下的icon和默认头像图片,
// 只是为了展示基础的效果,您需要根据业务场景进行修改。

// eslint-disable-next-line no-undef
Component({
properties: {
config: {
Expand Down Expand Up @@ -37,8 +35,10 @@ Component({
remoteUsers: [], // 远程用户资料
screen: 'pusher', // 视屏通话中,显示大屏幕的流(只限1v1聊天
soundMode: 'speaker', // 声音模式 听筒/扬声器
userList: null, //接受邀请的用户信息
},


methods: {
initCall() {
// 收起键盘
Expand All @@ -62,6 +62,7 @@ Component({
console.log(`${TAG_NAME}, handleUserAccept, event${JSON.stringify(event)}`);
this.setData({
callStatus: 'connection',
userList: event.data.userList,
});
},

Expand Down Expand Up @@ -109,34 +110,49 @@ Component({
// 用户拒绝
handleInviteeReject(event) {
console.log(`${TAG_NAME}, handleInviteeReject, event${JSON.stringify(event)}`);
if (this.data.playerList.length===0) {
this.reset();
}
wx.showToast({
title: `${this.handleCallingUser([event.data.invitee])}已拒绝`,
});
},
// 用户不在线
handleNoResponse(event) {
console.log(`${TAG_NAME}, handleNoResponse, event${JSON.stringify(event)}`);
if (this.data.playerList.length===0) {
this.reset();
}
wx.showToast({
title: `${this.handleCallingUser(event.data.timeoutUserList)}不在线`,
});
},
// 用户忙线
handleLineBusy(event) {
console.log(`${TAG_NAME}, handleLineBusy, event${JSON.stringify(event)}`);
if (this.data.playerList.length===0) {
this.reset();
}
wx.showToast({
title: `${this.handleCallingUser([event.data.invitee])}忙线中`,
});
},
// 用户取消
handleCallingCancel(event) {
console.log(`${TAG_NAME}, handleCallingCancel, event${JSON.stringify(event)}`);
if (this.data.playerList.length===0) {
this.reset();
}
wx.showToast({
title: `${this.handleCallingUser([event.data.invitee])}取消通话`,
});
},
// 通话超时未应答
handleCallingTimeout(event) {
console.log(`${TAG_NAME}, handleCallingTimeout, event${JSON.stringify(event)}`);
if (this.data.playerList.length===0) {
this.reset();
}
wx.showToast({
title: `${this.handleCallingUser(event.data.timeoutUserList)}超时无应答`,
});
Expand Down Expand Up @@ -183,6 +199,7 @@ Component({
// 切换通话模式
handleCallMode(event) {
this.data.config.type = event.data.type;
this.toggleSoundMode();
this.setData({
config: this.data.config,
});
Expand Down Expand Up @@ -261,6 +278,10 @@ Component({
*/
async call(params) {
this.initCall();
if (this.data.callStatus !== 'idle') {
console.warn(`${TAG_NAME}, call callStatus isn't idle`);
return;
}
wx.$TRTCCalling.call({ userID: params.userID, type: params.type }).then((res) => {
this.data.config.type = params.type;
this.getUserProfile([params.userID]);
Expand All @@ -285,6 +306,10 @@ Component({
*/
async groupCall(params) {
this.initCall();
if (this.data.callStatus !== 'idle') {
console.warn(`${TAG_NAME}, groupCall callStatus isn't idle`);
return;
}
wx.$TRTCCalling.groupCall({ userIDList: params.userIDList, type: params.type, groupID: params.groupID }).then((res) => {
this.data.config.type = params.type;
this.getUserProfile(params.userIDList);
Expand All @@ -301,6 +326,7 @@ Component({
*/
async accept() {
wx.$TRTCCalling.accept().then((res) => {
console.log('accept', res);
this.setData({
pusher: res.pusher,
callStatus: 'connection',
Expand Down Expand Up @@ -348,6 +374,7 @@ Component({
this.setData({
callStatus: 'idle',
isSponsor: false,
soundMode: 'speaker',
pusher: {}, // TRTC 本地流
playerList: [], // TRTC 远端流
});
Expand All @@ -371,6 +398,7 @@ Component({
case 'switchAudioCall':
wx.$TRTCCalling.switchAudioCall().then((res) => {
this.data.config.type = wx.$TRTCCalling.CALL_TYPE.AUDIO;
this.toggleSoundMode();
this.setData({
config: this.data.config,
});
Expand Down Expand Up @@ -426,7 +454,8 @@ Component({
break;
case 'switchAudioCall':
wx.$TRTCCalling.switchAudioCall().then((res) => {
this.data.config.type = 1;
this.data.config.type = wx.$TRTCCalling.CALL_TYPE.AUDIO;
this.toggleSoundMode();
this.setData({
config: this.data.config,
});
Expand All @@ -453,12 +482,12 @@ Component({
},
// 初始化TRTCCalling
async init() {
this._addTSignalingEvent();
try {
const res = await wx.$TRTCCalling.login({
userID: this.data.config.userID,
userSig: this.data.config.userSig,
});
this._addTSignalingEvent();
return res;
} catch (error) {
throw new Error('TRTCCalling login failure', error);
Expand Down Expand Up @@ -488,7 +517,7 @@ Component({
if (!wx.$TRTCCalling) {
wx.$TRTCCalling = new TRTCCalling({
sdkAppID: this.data.config.sdkAppID,
tim: this.data.config.tim,
tim: wx.$tim,
});
}
wx.$TRTCCalling.initData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
remoteUsers="{{remoteUsers}}"
bind:callingEvent="handleCallingEvent"
></TUI-Calling>
<TUI-Connected
<TUI-Connected
wx:if="{{callStatus === 'connection'}}"
playerList="{{playerList}}"
userList="{{userList}}"
pusher="{{pusher}}"
callType="{{config.type}}"
soundMode="{{soundMode}}"
screen="{{screen}}"
bind:connectedEvent="handleConnectedEvent"
></TUI-Connected>
</view>
</view>
</view>
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// components/tui-calling/TUICalling/component/calling.js
// eslint-disable-next-line no-undef
Component({
/**
* 组件的属性列表
Expand Down Expand Up @@ -27,6 +26,25 @@ Component({

},

/**
* 生命周期方法
*/
lifetimes: {
created() {

},
attached() {
},
ready() {
wx.createLivePusherContext().startPreview()
},
detached() {
wx.createLivePusherContext().stopPreview()
},
error() {
},
},

/**
* 组件的方法列表
*/
Expand Down
Loading

0 comments on commit a5f2c7a

Please sign in to comment.