Files
zyt/TUICallKit-Vue3/TUIKit/states/DeviceState.ts
T
2026-03-11 09:49:47 +08:00

61 lines
1.7 KiB
TypeScript

import { ref } from 'vue';
import { AudioPlayBackDevice } from '@trtc/call-engine-lite-wx';
import {
TUIStore,
StoreName,
TUICallKitServer,
NAME,
} from './TUICallService/index';
import { DeviceStatus } from '../constants/call';
const microphoneStatus = ref<DeviceStatus>(DeviceStatus.OFF);
const cameraStatus = ref<DeviceStatus>(DeviceStatus.OFF);
const isFrontCamera = ref<boolean>(true);
const currentAudioRoute = ref<string>(AudioPlayBackDevice.EAR);
// const localVideoQuality = ref();
const openLocalCamera = async () => await TUICallKitServer.openCamera('localVideo');
const closeLocalCamera = async () => await TUICallKitServer.closeCamera();
const switchCamera = async () => await TUICallKitServer.switchCamera();
const openLocalMicrophone = async () => await TUICallKitServer.openMicrophone();
const closeLocalMicrophone = async () => await TUICallKitServer.closeMicrophone();
const setAudioRoute = async () => await TUICallKitServer.setSoundMode();
TUIStore?.watch(StoreName.CALL, {
[NAME.CAMERA_POSITION]: _handleCameraPositionChange,
[NAME.IS_EAR_PHONE]: _handleIsEarPhoneChange,
});
function _handleCameraPositionChange(value: boolean) {
isFrontCamera.value = value;
}
function _handleIsEarPhoneChange(value: boolean) {
currentAudioRoute.value = value ? AudioPlayBackDevice.EAR : AudioPlayBackDevice.SPEAKER;
}
function useDeviceState() {
return {
// state
microphoneStatus,
cameraStatus,
// localVideoQuality,
isFrontCamera,
currentAudioRoute,
// captureVolume,
// networkInfo,
// actions
openLocalMicrophone,
closeLocalMicrophone,
openLocalCamera,
closeLocalCamera,
switchCamera,
setAudioRoute,
};
}
export { useDeviceState };