|
| 1 | +import { BsFillTelephoneXFill } from 'react-icons/bs'; |
| 2 | + |
| 3 | +import { useChannelActionStore } from '@/stores/channelAction'; |
| 4 | +import { useChannelInfoStore } from '@/stores/channelInfo'; |
| 5 | +import { useGuildInfoStore } from '@/stores/guildInfo'; |
| 6 | +import { useWebRTCStore } from '@/stores/webRTCStore'; |
| 7 | +import { tokenAxios } from '@/utils/axios'; |
| 8 | + |
| 9 | +import VoiceChannelActions from '../VoiceChannelActions'; |
| 10 | + |
| 11 | +import * as S from './styles'; |
| 12 | + |
| 13 | +const VoiceChannelController = () => { |
| 14 | + const { selectedChannel } = useChannelInfoStore(); |
| 15 | + const { setIsInVoiceChannel } = useChannelActionStore(); |
| 16 | + const { guildName } = useGuildInfoStore(); |
| 17 | + const { setIsStompConnected, disconnectStomp } = useWebRTCStore(); |
| 18 | + |
| 19 | + const roomId = useChannelInfoStore((state) => state.selectedChannel?.name); |
| 20 | + |
| 21 | + const handleLeaveRoom = async () => { |
| 22 | + setIsInVoiceChannel(false); |
| 23 | + |
| 24 | + if (!roomId) { |
| 25 | + alert('방 ID를 입력해주세요!'); |
| 26 | + return; |
| 27 | + } |
| 28 | + |
| 29 | + try { |
| 30 | + const response = await tokenAxios.delete(`https://api.jungeunjipi.com/room/${roomId}/leave`); |
| 31 | + console.log('방 나가기 성공: ', response); |
| 32 | + |
| 33 | + setIsStompConnected(false); |
| 34 | + |
| 35 | + disconnectStomp(); |
| 36 | + } catch (error) { |
| 37 | + console.error('🚨 방 나가기 오류:', error); |
| 38 | + } |
| 39 | + }; |
| 40 | + |
| 41 | + return ( |
| 42 | + <S.VoiceChannelController> |
| 43 | + <S.ConnectStatusWrapper> |
| 44 | + <S.InfoText> |
| 45 | + <S.ConnectStatusText>음성 연결됨</S.ConnectStatusText> |
| 46 | + <S.ChannelInfoText> |
| 47 | + {selectedChannel?.name} / {guildName} |
| 48 | + </S.ChannelInfoText> |
| 49 | + </S.InfoText> |
| 50 | + <BsFillTelephoneXFill size={20} onClick={handleLeaveRoom} /> |
| 51 | + </S.ConnectStatusWrapper> |
| 52 | + <VoiceChannelActions /> |
| 53 | + </S.VoiceChannelController> |
| 54 | + ); |
| 55 | +}; |
| 56 | + |
| 57 | +export default VoiceChannelController; |
0 commit comments