|
@@ -21,18 +21,20 @@ export const checkDevice = async () => {
|
|
|
item['value'] = item.deviceId;
|
|
|
});
|
|
|
if (microphoneItems?.length) {
|
|
|
- rtcStore.setAudioDeviceId(microphoneItems[0].deviceId);
|
|
|
+ rtcStore.setAudioDeviceId(
|
|
|
+ microphoneItems[0].deviceId || microphoneItems[0].groupId || 'default',
|
|
|
+ );
|
|
|
} else {
|
|
|
rtcStore.setAudioDeviceId('');
|
|
|
}
|
|
|
|
|
|
const camerasItems = await TRTC.getCameras();
|
|
|
-
|
|
|
+ console.log('camerasItems', camerasItems);
|
|
|
camerasItems.forEach((item) => {
|
|
|
item['value'] = item.deviceId;
|
|
|
});
|
|
|
if (camerasItems?.length) {
|
|
|
- rtcStore.setVideoDeviceId(camerasItems[0].deviceId || camerasItems[0].groupId);
|
|
|
+ rtcStore.setVideoDeviceId(camerasItems[0].deviceId || camerasItems[0].groupId || 'default');
|
|
|
} else {
|
|
|
rtcStore.setVideoDeviceId('');
|
|
|
}
|
|
@@ -46,9 +48,6 @@ const checkSystemRequirements = async () => {
|
|
|
console.log('result', result);
|
|
|
const isSmallStreamSupported = await TRTC.isSmallStreamSupported();
|
|
|
console.log('isSmallStreamSupported', isSmallStreamSupported);
|
|
|
- // if (!isSmallStreamSupported) {
|
|
|
- // alert('You browser does not support opening small streams.');
|
|
|
- // }
|
|
|
};
|
|
|
|
|
|
// interface UseRtcSdkType {
|
|
@@ -58,29 +57,39 @@ const checkSystemRequirements = async () => {
|
|
|
async function createLocalStream() {
|
|
|
try {
|
|
|
const rtcStore = useRtcStore();
|
|
|
- const enableVideo = rtcStore.isLeader && rtcStore.videoDeviceId.length > 0;
|
|
|
+ const enableVideo = rtcStore.isLeader && rtcStore.videoDeviceId?.length > 0;
|
|
|
+ console.warn('enableVideo', enableVideo);
|
|
|
localStream = TRTC.createStream({
|
|
|
userId: rtcStore.userId,
|
|
|
audio: true,
|
|
|
video: enableVideo,
|
|
|
+ cameraId: rtcStore.videoDeviceId,
|
|
|
microphoneId: rtcStore.audioDeviceId,
|
|
|
});
|
|
|
//开大小流
|
|
|
- await localClient.enableSmallStream();
|
|
|
- localClient.setSmallStreamProfile({
|
|
|
- width: 160,
|
|
|
- height: 90,
|
|
|
- bitrate: 100,
|
|
|
- frameRate: 15,
|
|
|
- });
|
|
|
+ const isSmallStreamSupported = TRTC.isSmallStreamSupported();
|
|
|
+ if (isSmallStreamSupported) {
|
|
|
+ await localClient.enableSmallStream();
|
|
|
+ localClient.setSmallStreamProfile({
|
|
|
+ width: 160,
|
|
|
+ height: 90,
|
|
|
+ bitrate: 100,
|
|
|
+ frameRate: 15,
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ localStream.setVideoProfile('360p');
|
|
|
+ }
|
|
|
+
|
|
|
//
|
|
|
await localStream.initialize();
|
|
|
+ return Promise.resolve();
|
|
|
|
|
|
// if (rtcStore.audioMuted) {
|
|
|
// localStream.muteAudio();
|
|
|
// }
|
|
|
} catch (error) {
|
|
|
console.log(error, 'createStream');
|
|
|
+ return Promise.reject(error);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -119,18 +128,32 @@ async function handleJoin() {
|
|
|
|
|
|
await createLocalStream();
|
|
|
await handlePublish();
|
|
|
- await localStream
|
|
|
- .play('local')
|
|
|
- .then(() => {
|
|
|
- consola.info({
|
|
|
- message: '音采源',
|
|
|
- tag: 'rtc:audio',
|
|
|
+ //
|
|
|
+ // setTimeout(() => {
|
|
|
+ const playLocal = () => {
|
|
|
+ localStream
|
|
|
+ .play('local')
|
|
|
+ .then(() => {
|
|
|
+ consola.info({
|
|
|
+ message: '本地采集成功!',
|
|
|
+ tag: 'rtc:audio',
|
|
|
+ });
|
|
|
+ rtcStore.setIsRTCJoined(true);
|
|
|
+ })
|
|
|
+ .catch((error) => {
|
|
|
+ consola.info({
|
|
|
+ message: '本地采集失败!' + error,
|
|
|
+ tag: 'rtc:audio',
|
|
|
+ });
|
|
|
+ setTimeout(() => {
|
|
|
+ console.log('再次播放');
|
|
|
+ playLocal();
|
|
|
+ }, 500);
|
|
|
});
|
|
|
- })
|
|
|
- .catch((error) => {
|
|
|
- console.log('play-local-error', error);
|
|
|
- });
|
|
|
- rtcStore.setIsRTCJoined(true);
|
|
|
+ };
|
|
|
+
|
|
|
+ playLocal();
|
|
|
+ // }, 1000);
|
|
|
|
|
|
localStream.on('error', (error) => {
|
|
|
if (error.getCode() === 0x4043) {
|
|
@@ -278,7 +301,9 @@ function uninstallEventHandlers() {
|
|
|
|
|
|
function handleMuteVideo(event) {
|
|
|
console.log(`[${event.userId}] mute video`);
|
|
|
- if (event.userId.indexOf('leader') > -1) {
|
|
|
+ const rtcStore = useRtcStore();
|
|
|
+ const roomLeader = rtcStore.getRoomLeader();
|
|
|
+ if (event.userId === roomLeader?.UserId) {
|
|
|
muteVideoLeader.value = true;
|
|
|
}
|
|
|
}
|
|
@@ -292,7 +317,9 @@ function handleMuteAudio(event) {
|
|
|
|
|
|
function handleUnmuteVideo(event) {
|
|
|
console.log(`[${event.userId}] unmute video`);
|
|
|
- if (event.userId.indexOf('leader') > -1) {
|
|
|
+ const rtcStore = useRtcStore();
|
|
|
+ const roomLeader = rtcStore.getRoomLeader();
|
|
|
+ if (event.userId === roomLeader?.UserId) {
|
|
|
muteVideoLeader.value = false;
|
|
|
}
|
|
|
}
|
|
@@ -367,19 +394,60 @@ async function handleStreamSubscribed(event) {
|
|
|
// debugger
|
|
|
}
|
|
|
await nextTick();
|
|
|
- setTimeout(async () => {
|
|
|
- try {
|
|
|
- consola.info({
|
|
|
- message: '客音源-->' + remoteId,
|
|
|
- tag: 'rtc:audio',
|
|
|
- });
|
|
|
- consola.info({
|
|
|
- message: rtcStore.remoteStreams,
|
|
|
- tag: 'rtc:audio',
|
|
|
+ const playRemote = () => {
|
|
|
+ remoteStream
|
|
|
+ .play(remoteId)
|
|
|
+ .then(() => {
|
|
|
+ consola.info({
|
|
|
+ message: '远端采集成功!' + remoteId,
|
|
|
+ tag: 'rtc:audio',
|
|
|
+ });
|
|
|
+ })
|
|
|
+ .catch((error) => {
|
|
|
+ consola.info({
|
|
|
+ message: '远端采集失败!' + error,
|
|
|
+ tag: 'rtc:audio',
|
|
|
+ });
|
|
|
+ setTimeout(() => {
|
|
|
+ console.log('远端再次播放' + remoteId);
|
|
|
+ playRemote();
|
|
|
+ }, 500);
|
|
|
});
|
|
|
- await remoteStream.play(remoteId);
|
|
|
- } catch (error) { }
|
|
|
- }, 200);
|
|
|
+ };
|
|
|
+ playRemote();
|
|
|
+ remoteStream.on('error', (error) => {
|
|
|
+ if (error.getCode() === 0x4043) {
|
|
|
+ // 自动播放受限导致播放失败,此时引导用户点击页面。
|
|
|
+ // 在点击事件的回调函数中,执行 stream.resume();
|
|
|
+ const rtcStore = useRtcStore();
|
|
|
+ const { t } = useI18n();
|
|
|
+ rtcStore.showBaseDialog(
|
|
|
+ {
|
|
|
+ title: t('base.tips'),
|
|
|
+ desc: t('base.audioPermission'),
|
|
|
+ okTxt: t('base.confirm'),
|
|
|
+ closeTxt: t('base.cancel'),
|
|
|
+ },
|
|
|
+ () => {
|
|
|
+ remoteStream.resume();
|
|
|
+ },
|
|
|
+ );
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // setTimeout(async () => {
|
|
|
+ // try {
|
|
|
+ // consola.info({
|
|
|
+ // message: '客音源-->' + remoteId,
|
|
|
+ // tag: 'rtc:audio',
|
|
|
+ // });
|
|
|
+ // consola.info({
|
|
|
+ // message: rtcStore.remoteStreams,
|
|
|
+ // tag: 'rtc:audio',
|
|
|
+ // });
|
|
|
+ // await remoteStream.play(remoteId);
|
|
|
+ // } catch (error) {}
|
|
|
+ // }, 200);
|
|
|
}
|
|
|
|
|
|
function handleStreamRemoved(event) {
|
|
@@ -425,6 +493,7 @@ export function useRtcSdk() {
|
|
|
handleJoin,
|
|
|
handleLeave,
|
|
|
localStream,
|
|
|
+ muteVideoLeader,
|
|
|
invitedRemoteStreams,
|
|
|
client: localClient,
|
|
|
};
|