Skip to content

Commit

Permalink
[FE] 사용자는 게임방에 입장하면 실시간 음성 통화를 할 수 있다. (#68)
Browse files Browse the repository at this point in the history
* feat: 마이크 권한 요청 기능 구현

* feat: WebRTC 실시간 음성 통화 기능 구현

* chore: 시그널링 서버 URL 변경
  • Loading branch information
studioOwol authored Nov 7, 2024
1 parent aabdeca commit 63d6959
Show file tree
Hide file tree
Showing 5 changed files with 337 additions and 114 deletions.
60 changes: 60 additions & 0 deletions fe/src/services/audioRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { AudioStreamSetup } from '@/types/audioTypes';

export const requestAudioStream = async (): Promise<MediaStream> => {
try {
const stream = await navigator.mediaDevices.getUserMedia({
audio: {
echoCancellation: true,
noiseSuppression: true,
autoGainControl: true,
sampleRate: 48000,
channelCount: 1,
},
video: false,
});
return stream;
} catch (error) {
console.error('Error accessing microphone:', error);
if (error instanceof DOMException) {
if (error.name === 'NotAllowedError') {
throw new Error(
'마이크 사용 권한이 거부되었습니다. 권한을 허용해주세요.'
);
} else if (error.name === 'NotFoundError') {
throw new Error(
'마이크를 찾을 수 없습니다. 마이크가 연결되어 있는지 확인해주세요.'
);
}
}
throw new Error('마이크 접근에 실패했습니다.');
}
};

export const cleanupAudioStream = (stream: MediaStream) => {
stream.getTracks().forEach((track) => track.stop());
};

export const setupAudioStream = async (
stream: MediaStream
): Promise<AudioStreamSetup> => {
try {
const audioContext = new AudioContext();
const source = audioContext.createMediaStreamSource(stream);
const gainNode = audioContext.createGain();

source.connect(gainNode);
gainNode.connect(audioContext.destination);

// 기본 볼륨 설정
gainNode.gain.value = 0.5;

return {
audioContext,
source,
gainNode,
};
} catch (error) {
console.error('Error setting up audio stream:', error);
throw error;
}
};
113 changes: 0 additions & 113 deletions fe/src/services/gameSocket.ts

This file was deleted.

Loading

0 comments on commit 63d6959

Please sign in to comment.