-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FE] 사용자는 게임방에 입장하면 실시간 음성 통화를 할 수 있다. (#68)
* feat: 마이크 권한 요청 기능 구현 * feat: WebRTC 실시간 음성 통화 기능 구현 * chore: 시그널링 서버 URL 변경
- Loading branch information
1 parent
aabdeca
commit 63d6959
Showing
5 changed files
with
337 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
}; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.