useTRTC.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import consola from "consola";
  2. import TRTC from "trtc-js-sdk";
  3. import { useRtcStore } from "/@/store/modules/rtc";
  4. import Dialog from '/@/components/basic/dialog'
  5. export const updateDevice = async () => {
  6. console.log("updateDevice");
  7. const microphoneItems = await TRTC.getMicrophones();
  8. microphoneItems.forEach((item) => {
  9. console.log('item', item)
  10. });
  11. }
  12. const checkoutIsExistAudioInput = async () => {
  13. const result = await TRTC.checkSystemRequirements()
  14. console.log('result', result)
  15. }
  16. // interface UseRtcSdkType {
  17. // createRTCSocket: () => Promise<void>
  18. // }
  19. async function createRTCSocket(): Promise<void> {
  20. try {
  21. console.log('Dialog', Dialog)
  22. // Dialog.alert("该场景正在计算中,请稍后再试");
  23. const rtcStore = useRtcStore()
  24. await checkoutIsExistAudioInput();
  25. const microphoneItems = await TRTC.getMicrophones();
  26. // debugger
  27. if (microphoneItems?.length) {
  28. const localStream = TRTC.createStream({
  29. userId: rtcStore.userId,
  30. audio: true,
  31. video: false,
  32. // microphoneId: store.getters["rtc/audioDeviceId"],
  33. microphoneId: rtcStore.audioDeviceId
  34. });
  35. console.log('localStream', localStream)
  36. }
  37. } catch (error) {
  38. consola.error({
  39. tag: 'createRTCSocket',
  40. message: error
  41. })
  42. }
  43. }
  44. export function useRtcSdk() {
  45. return {
  46. createRTCSocket
  47. }
  48. }