更新token
This commit is contained in:
parent
3b79abb8ee
commit
d10fdd1d5c
|
|
@ -25,6 +25,7 @@ import { getKeyOpenChildWindow, setKeyOpenChildWindow } from '@/utils/package/pu
|
||||||
import MeetingDisconnected from '@/components/MeetingDisconnected';
|
import MeetingDisconnected from '@/components/MeetingDisconnected';
|
||||||
import SingIn from '@/components/SingIn';
|
import SingIn from '@/components/SingIn';
|
||||||
import UserName from '@/components/UserName';
|
import UserName from '@/components/UserName';
|
||||||
|
import { GetRoomRtcToken } from '@/api/Home/Index';
|
||||||
const { setTimeout, setInterval, clearTimeout, clearInterval } = require('timers');
|
const { setTimeout, setInterval, clearTimeout, clearInterval } = require('timers');
|
||||||
const { confirm } = Modal;
|
const { confirm } = Modal;
|
||||||
const { exec } = require('child_process');
|
const { exec } = require('child_process');
|
||||||
|
|
@ -1155,6 +1156,16 @@ const Meeting: React.FC = () => {
|
||||||
key: 'cameraTemporarily'
|
key: 'cameraTemporarily'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
onTokenPrivilegeWillExpire: async (connection: RtcConnection, _token: string) => {
|
||||||
|
await GetRoomRtcToken(connection.channelId || '').then(res => {
|
||||||
|
if (res.code === 200) {
|
||||||
|
agora.refreshToken({
|
||||||
|
token: res.data.token,
|
||||||
|
connection,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if (state.enableCamera) {
|
if (state.enableCamera) {
|
||||||
|
|
|
||||||
|
|
@ -153,7 +153,7 @@ export const agora = {
|
||||||
}, 1000);
|
}, 1000);
|
||||||
},
|
},
|
||||||
// 事件回调
|
// 事件回调
|
||||||
registerEventHandler: ({ onJoinChannelSuccess, onUserJoined, onUserOffline, onAudioVolumeIndication, onNetworkQuality, onRtcStats, onConnectionStateChanged, onLocalVideoStateChanged, onConnectionLost }: any) => {
|
registerEventHandler: ({ onJoinChannelSuccess, onUserJoined, onUserOffline, onAudioVolumeIndication, onNetworkQuality, onRtcStats, onConnectionStateChanged, onLocalVideoStateChanged, onConnectionLost, onTokenPrivilegeWillExpire }: any) => {
|
||||||
rtcEngine.registerEventHandler({
|
rtcEngine.registerEventHandler({
|
||||||
// 监听本地用户加入频道事件
|
// 监听本地用户加入频道事件
|
||||||
onJoinChannelSuccess: async (connection: RtcConnection, elapsed: number) => {
|
onJoinChannelSuccess: async (connection: RtcConnection, elapsed: number) => {
|
||||||
|
|
@ -202,9 +202,19 @@ export const agora = {
|
||||||
// 网络连接中断,且 SDK 无法在 10 秒内连接服务器回调。
|
// 网络连接中断,且 SDK 无法在 10 秒内连接服务器回调。
|
||||||
onConnectionLost: (_connection: RtcConnection) => {
|
onConnectionLost: (_connection: RtcConnection) => {
|
||||||
onConnectionLost?.()
|
onConnectionLost?.()
|
||||||
|
},
|
||||||
|
// Token 即将在 30s 内过期回调。
|
||||||
|
onTokenPrivilegeWillExpire: (connection: RtcConnection, token: string) => {
|
||||||
|
onTokenPrivilegeWillExpire?.(connection, token)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
// 刷新token
|
||||||
|
refreshToken: async (data: any) => {
|
||||||
|
await rtcEngine.updateChannelMediaOptionsEx({
|
||||||
|
token: data.token,
|
||||||
|
}, data.connection);
|
||||||
|
},
|
||||||
// 获取视图模式
|
// 获取视图模式
|
||||||
getRrenderMode: (uid: number) => {
|
getRrenderMode: (uid: number) => {
|
||||||
if (String(uid).length === 9) {
|
if (String(uid).length === 9) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue