|
@@ -12,11 +12,11 @@ const invitedRemoteStreams = ref<RemoteStream[]>([]);
|
|
|
const muteAudioLeader = ref(false);
|
|
|
const muteVideoLeader = ref(false);
|
|
|
|
|
|
-export const updateDevice = async () => {
|
|
|
+export const checkDevice = async () => {
|
|
|
try {
|
|
|
- console.log('updateDevice');
|
|
|
const rtcStore = useRtcStore();
|
|
|
const microphoneItems = await TRTC.getMicrophones();
|
|
|
+ console.log('microphoneItems', microphoneItems);
|
|
|
microphoneItems.forEach((item) => {
|
|
|
item['value'] = item.deviceId;
|
|
|
});
|
|
@@ -25,12 +25,30 @@ export const updateDevice = async () => {
|
|
|
} else {
|
|
|
rtcStore.setAudioDeviceId('');
|
|
|
}
|
|
|
- } catch (error) {}
|
|
|
+
|
|
|
+ const camerasItems = await TRTC.getCameras();
|
|
|
+
|
|
|
+ camerasItems.forEach((item) => {
|
|
|
+ item['value'] = item.deviceId;
|
|
|
+ });
|
|
|
+ if (camerasItems?.length) {
|
|
|
+ rtcStore.setVideoDeviceId(camerasItems[0].deviceId || camerasItems[0].groupId);
|
|
|
+ } else {
|
|
|
+ rtcStore.setVideoDeviceId('');
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.log('error', error);
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
-const checkoutIsExistAudioInput = async () => {
|
|
|
+const checkSystemRequirements = async () => {
|
|
|
const result = await TRTC.checkSystemRequirements();
|
|
|
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 {
|
|
@@ -40,18 +58,27 @@ const checkoutIsExistAudioInput = async () => {
|
|
|
async function createLocalStream() {
|
|
|
try {
|
|
|
const rtcStore = useRtcStore();
|
|
|
+ const enableVideo = rtcStore.isLeader && rtcStore.videoDeviceId.length > 0;
|
|
|
localStream = TRTC.createStream({
|
|
|
userId: rtcStore.userId,
|
|
|
audio: true,
|
|
|
- video: false,
|
|
|
+ video: enableVideo,
|
|
|
microphoneId: rtcStore.audioDeviceId,
|
|
|
});
|
|
|
-
|
|
|
+ //开大小流
|
|
|
+ await localClient.enableSmallStream();
|
|
|
+ localClient.setSmallStreamProfile({
|
|
|
+ width: 160,
|
|
|
+ height: 90,
|
|
|
+ bitrate: 100,
|
|
|
+ frameRate: 15,
|
|
|
+ });
|
|
|
+ //
|
|
|
await localStream.initialize();
|
|
|
|
|
|
- if (rtcStore.audioMuted) {
|
|
|
- localStream.muteAudio();
|
|
|
- }
|
|
|
+ // if (rtcStore.audioMuted) {
|
|
|
+ // localStream.muteAudio();
|
|
|
+ // }
|
|
|
} catch (error) {
|
|
|
console.log(error, 'createStream');
|
|
|
}
|
|
@@ -60,14 +87,9 @@ async function createLocalStream() {
|
|
|
async function createRTCSocket(): Promise<void> {
|
|
|
try {
|
|
|
const rtcStore = useRtcStore();
|
|
|
- await checkoutIsExistAudioInput();
|
|
|
- await updateDevice();
|
|
|
- console.log('rtcStore', rtcStore);
|
|
|
- // const microphoneItems = await TRTC.getMicrophones();
|
|
|
-
|
|
|
- // if (microphoneItems?.length) {
|
|
|
-
|
|
|
- // }
|
|
|
+ await checkSystemRequirements();
|
|
|
+ await checkDevice();
|
|
|
+ console.log('createRTCSocket', rtcStore.videoDeviceId);
|
|
|
await handleJoin();
|
|
|
} catch (error) {
|
|
|
consola.error({
|
|
@@ -129,19 +151,6 @@ async function handleJoin() {
|
|
|
localStream.resume();
|
|
|
},
|
|
|
);
|
|
|
- // Dialog.confirm({
|
|
|
- // showCloseIcon: false,
|
|
|
- // okText: '确定',
|
|
|
- // content:
|
|
|
- // "<span style='font-size: 16px; line-height: 1.5;'>在用户与网页产生交互(例如点击、触摸页面等)之前,网页将被禁止播放带有声音的媒体。点击恢复播放<span/>",
|
|
|
- // title: '隐私条款:',
|
|
|
- // single: true,
|
|
|
- // func: (state) => {
|
|
|
- // if (state == 'ok') {
|
|
|
- // localStream.resume();
|
|
|
- // }
|
|
|
- // },
|
|
|
- // });
|
|
|
}
|
|
|
});
|
|
|
}
|
|
@@ -371,71 +380,8 @@ async function handleStreamSubscribed(event) {
|
|
|
tag: 'rtc:audio',
|
|
|
});
|
|
|
await remoteStream.play(remoteId);
|
|
|
- } catch (error) {
|
|
|
- // remoteStream.resume();
|
|
|
- // rtcStore.showBaseDialog(
|
|
|
- // {
|
|
|
- // title: t('base.tips'),
|
|
|
- // desc: t('base.audioPermission'),
|
|
|
- // okTxt: t('base.confirm'),
|
|
|
- // closeTxt: t('base.cancel'),
|
|
|
- // },
|
|
|
- // () => {
|
|
|
- // consola.info({
|
|
|
- // message: 'resume',
|
|
|
- // tag: 'rtc:audio',
|
|
|
- // });
|
|
|
- // remoteStream.resume();
|
|
|
- // },
|
|
|
- // );
|
|
|
- // Dialog.confirm({
|
|
|
- // showCloseIcon: false,
|
|
|
- // okText: '确定',
|
|
|
- // content:
|
|
|
- // "<span style='font-size: 16px; line-height: 1.5;'>继续访问该页面需要获取您摄像头及麦克风的权限。<span/>",
|
|
|
- // title: '温馨提示:',
|
|
|
- // single: true,
|
|
|
- // func: (state) => {
|
|
|
- // if (state == 'ok') {
|
|
|
- // remoteStream.resume();
|
|
|
- // }
|
|
|
- // },
|
|
|
- // });
|
|
|
- }
|
|
|
+ } catch (error) {}
|
|
|
}, 200);
|
|
|
- // console.info(
|
|
|
- // remoteStream.userId_,
|
|
|
- // rtcStore,
|
|
|
- // "handleStreamSubscribedhandleStreamSubscribed.value"
|
|
|
- // );
|
|
|
-
|
|
|
- // if (
|
|
|
- // !invitedRemoteStreams.value.some(
|
|
|
- // (item) => item.userId_ == remoteStream.userId_
|
|
|
- // )
|
|
|
- // ) {
|
|
|
- // debugger
|
|
|
- // invitedRemoteStreams.value.push(remoteStream);
|
|
|
- // }
|
|
|
-
|
|
|
- // console.log(invitedRemoteStreams.value, "invitedRemoteStreams.value");
|
|
|
-
|
|
|
- // await nextTick();
|
|
|
- // setTimeout(() => {
|
|
|
- // console.log(remoteStream.userId_, "remoteStream.getId()");
|
|
|
- // remoteStream
|
|
|
- // .play(remoteStream.userId_)
|
|
|
- // .then(() => {
|
|
|
- // console.log(`RemoteStream play success`, 88888888888888888888);
|
|
|
- // })
|
|
|
- // .catch((error) => {
|
|
|
- // console.log(`RemoteStream play failed: error: ${error.message_}`);
|
|
|
- // });
|
|
|
- // }, 100);
|
|
|
-
|
|
|
- // const remoteStream = event.stream;
|
|
|
- // const userId = remoteStream.getUserId();
|
|
|
- // console.log(`RemoteStream subscribed: [${userId}]`);
|
|
|
}
|
|
|
|
|
|
function handleStreamRemoved(event) {
|