| REACT_APP_BASE_API_URL=https://trampa-api-test.dilig.net/ | |||||
| REACT_APP_BASE_API_URL=http://192.168.88.143:3001/ |
| import { useSelector } from "react-redux"; | import { useSelector } from "react-redux"; | ||||
| import i18next from "i18next"; | import i18next from "i18next"; | ||||
| import { selectUserId } from "./store/selectors/loginSelectors"; | |||||
| import { selectJwtToken, selectUserId } from "./store/selectors/loginSelectors"; | |||||
| import history from "./store/utils/history"; | import history from "./store/utils/history"; | ||||
| import AppRoutes from "./AppRoutes"; | import AppRoutes from "./AppRoutes"; | ||||
| import { socketInit } from "./socket/socket"; | import { socketInit } from "./socket/socket"; | ||||
| const App = () => { | const App = () => { | ||||
| const userId = useSelector(selectUserId); | const userId = useSelector(selectUserId); | ||||
| const token = useSelector(selectJwtToken); | |||||
| useEffect(() => { | useEffect(() => { | ||||
| socketInit(userId); | |||||
| }, [userId]); | |||||
| socketInit(userId, token); | |||||
| }, [userId, token]); | |||||
| return ( | return ( | ||||
| <Router history={history}> | <Router history={history}> | ||||
| <Helmet> | <Helmet> |
| import { addNewMessage } from "../../../../store/actions/chat/chatActions"; | import { addNewMessage } from "../../../../store/actions/chat/chatActions"; | ||||
| import { convertLocalDateToUTCDate } from "../../../../util/helpers/dateHelpers"; | import { convertLocalDateToUTCDate } from "../../../../util/helpers/dateHelpers"; | ||||
| import requesterStatus from "../../../../constants/requesterStatus"; | import requesterStatus from "../../../../constants/requesterStatus"; | ||||
| import { selectJwtToken } from "../../../../store/selectors/loginSelectors"; | |||||
| const RequestExchangeMessage = (props) => { | const RequestExchangeMessage = (props) => { | ||||
| const { t } = useTranslation(); | const { t } = useTranslation(); | ||||
| const dispatch = useDispatch(); | const dispatch = useDispatch(); | ||||
| const exchange = useSelector(selectExchange); | const exchange = useSelector(selectExchange); | ||||
| const requester = useSelector(selectRequester); | const requester = useSelector(selectRequester); | ||||
| const token = useSelector(selectJwtToken) | |||||
| const handleAcceptExchangeSuccess = () => { | const handleAcceptExchangeSuccess = () => { | ||||
| console.log("accept salje i prima 3 POZVANA RESPONSE FUNKCIJA"); | console.log("accept salje i prima 3 POZVANA RESPONSE FUNKCIJA"); | ||||
| props.chatId, | props.chatId, | ||||
| props.userId, | props.userId, | ||||
| props.interlocutorUserId, | props.interlocutorUserId, | ||||
| token, | |||||
| () => { | () => { | ||||
| console.log("accept salje i prima 4 SOCKET FUNKCIJA"); | console.log("accept salje i prima 4 SOCKET FUNKCIJA"); | ||||
| dispatch( | dispatch( |
| import SkeletonDirectChat from "./SkeletonDirectChat/SkeletonDirectChat"; | import SkeletonDirectChat from "./SkeletonDirectChat/SkeletonDirectChat"; | ||||
| import { selectIsLoadingByActionType } from "../../store/selectors/loadingSelectors"; | import { selectIsLoadingByActionType } from "../../store/selectors/loadingSelectors"; | ||||
| import { CHAT_SCOPE } from "../../store/actions/chat/chatActionConstants"; | import { CHAT_SCOPE } from "../../store/actions/chat/chatActionConstants"; | ||||
| import { selectUserId } from "../../store/selectors/loginSelectors"; | |||||
| import { | |||||
| selectJwtToken, | |||||
| selectUserId, | |||||
| } from "../../store/selectors/loginSelectors"; | |||||
| import { | import { | ||||
| acceptExchangeSocket, | acceptExchangeSocket, | ||||
| addMessageListener, | addMessageListener, | ||||
| const location = useLocation(); | const location = useLocation(); | ||||
| const dispatch = useDispatch(); | const dispatch = useDispatch(); | ||||
| const { t } = useTranslation(); | const { t } = useTranslation(); | ||||
| const token = useSelector(selectJwtToken); | |||||
| const exchange = useSelector(selectExchange); | const exchange = useSelector(selectExchange); | ||||
| const requester = useSelector(selectRequester); | const requester = useSelector(selectRequester); | ||||
| chat?._id, | chat?._id, | ||||
| userId, | userId, | ||||
| chat?.participants[interlocutor]._id, | chat?.participants[interlocutor]._id, | ||||
| token, | |||||
| () => { | () => { | ||||
| dispatch( | dispatch( | ||||
| addNewMessage({ | addNewMessage({ | ||||
| ); | ); | ||||
| }; | }; | ||||
| const handleAcceptExchange = () => { | const handleAcceptExchange = () => { | ||||
| console.log("accept salje i prima 1 POZVANA FUNKCIJA") | |||||
| console.log("accept salje i prima 1 POZVANA FUNKCIJA"); | |||||
| dispatch( | dispatch( | ||||
| acceptExchange({ | acceptExchange({ | ||||
| exchangeId: exchange._id, | exchangeId: exchange._id, |
| import { useDispatch } from "react-redux"; | import { useDispatch } from "react-redux"; | ||||
| import { sendMessage } from "../../../socket/socket"; | import { sendMessage } from "../../../socket/socket"; | ||||
| import { useSelector } from "react-redux"; | import { useSelector } from "react-redux"; | ||||
| import { selectUserId } from "../../../store/selectors/loginSelectors"; | |||||
| import { selectJwtToken, selectUserId } from "../../../store/selectors/loginSelectors"; | |||||
| import { | import { | ||||
| addNewMessage, | addNewMessage, | ||||
| startNewChat, | startNewChat, | ||||
| const { t } = useTranslation(); | const { t } = useTranslation(); | ||||
| const location = useLocation(); | const location = useLocation(); | ||||
| const history = useHistory(); | const history = useHistory(); | ||||
| const token = useSelector(selectJwtToken) | |||||
| const userId = useSelector(selectUserId); | const userId = useSelector(selectUserId); | ||||
| const handleSend = useCallback( | const handleSend = useCallback( | ||||
| (newChatId = undefined) => { | (newChatId = undefined) => { | ||||
| if (typedValue?.length === 0) return; | if (typedValue?.length === 0) return; | ||||
| if (props?.chat?._id) { | if (props?.chat?._id) { | ||||
| const chatId = props.chat?._id || newChatId; | const chatId = props.chat?._id || newChatId; | ||||
| sendMessage(chatId, userId, typedValue, props.interlocutor._id); | |||||
| sendMessage(chatId, userId, typedValue, props.interlocutor._id, token); | |||||
| dispatch( | dispatch( | ||||
| addNewMessage({ | addNewMessage({ | ||||
| _id: chatId, | _id: chatId, | ||||
| if (props?.chat?.offer?._deleted) { | if (props?.chat?.offer?._deleted) { | ||||
| return <NotAllowedChat />; | return <NotAllowedChat />; | ||||
| } | } | ||||
| if (props?.interlocutor?._blocked) { | |||||
| return <NotAllowedChat blocked />; | |||||
| } | |||||
| // if (props?.interlocutor?._blocked) { | |||||
| // return <NotAllowedChat blocked />; | |||||
| // } | |||||
| return ( | return ( | ||||
| <> | <> | ||||
| <DirectChatNewMessageContainer> | <DirectChatNewMessageContainer> |
| import io from "socket.io-client"; | import io from "socket.io-client"; | ||||
| // export const socket = io("https://trampa-api-test.dilig.net/", { | // export const socket = io("https://trampa-api-test.dilig.net/", { | ||||
| // export const socket = io("http://localhost:3001/", { | |||||
| export const socket = io(process.env.REACT_APP_BASE_API_URL, { | |||||
| // export const socket = io("http://localhost:3001/", { | |||||
| export const socket = io(process.env.REACT_APP_BASE_API_URL, { | |||||
| transports: ["websocket"], | transports: ["websocket"], | ||||
| reconnectionAttempts: 5, | reconnectionAttempts: 5, | ||||
| }); | }); | ||||
| export const socketInit = (userId) => { | |||||
| export const socketInit = (userId, token) => { | |||||
| if (socket.connected) socket.disconnect(); | if (socket.connected) socket.disconnect(); | ||||
| socket.auth = { | socket.auth = { | ||||
| userId, | userId, | ||||
| token, | |||||
| }; | }; | ||||
| socket.connect(); | socket.connect(); | ||||
| }; | }; | ||||
| receiverUserId, | receiverUserId, | ||||
| message: { | message: { | ||||
| user: { | user: { | ||||
| _id: userId | |||||
| _id: userId, | |||||
| }, | }, | ||||
| isAcceptRequest: true, | isAcceptRequest: true, | ||||
| text: "", | text: "", |
| } from "../actions/exchange/exchangeActions"; | } from "../actions/exchange/exchangeActions"; | ||||
| import { selectSelectedChat } from "../selectors/chatSelectors"; | import { selectSelectedChat } from "../selectors/chatSelectors"; | ||||
| import { selectExchange } from "../selectors/exchangeSelector"; | import { selectExchange } from "../selectors/exchangeSelector"; | ||||
| import { selectUserId } from "../selectors/loginSelectors"; | |||||
| import { selectJwtToken, selectUserId } from "../selectors/loginSelectors"; | |||||
| import { sendMessage as SendMessageSocket } from "../../socket/socket"; | import { sendMessage as SendMessageSocket } from "../../socket/socket"; | ||||
| import { KEY_PAGE, KEY_SIZE } from "../../constants/queryStringConstants"; | import { KEY_PAGE, KEY_SIZE } from "../../constants/queryStringConstants"; | ||||
| import { setQueryStringRedux } from "../actions/queryString/queryStringActions"; | import { setQueryStringRedux } from "../actions/queryString/queryStringActions"; | ||||
| userId, | userId, | ||||
| }); | }); | ||||
| const queryString = yield select(selectQueryString); | const queryString = yield select(selectQueryString); | ||||
| const token = yield select(selectJwtToken); | |||||
| const data = yield call(attemptFetchChats, { userId, queryString }); | const data = yield call(attemptFetchChats, { userId, queryString }); | ||||
| yield put(setChats([...data.data.chats])); | yield put(setChats([...data.data.chats])); | ||||
| yield put(setChatsTotal(data.data.total)); | yield put(setChatsTotal(data.data.total)); | ||||
| newChatData.data.chatId, | newChatData.data.chatId, | ||||
| userId, | userId, | ||||
| payload.payload.message, | payload.payload.message, | ||||
| payload.payload.interlocutorUserId | |||||
| payload.payload.interlocutorUserId, | |||||
| token | |||||
| ); | ); | ||||
| yield put( | yield put( | ||||
| addNewMessage({ | addNewMessage({ |
| loginSelector, | loginSelector, | ||||
| (state) => state.jwtToken.roles | (state) => state.jwtToken.roles | ||||
| ); | ); | ||||
| export const selectJwtToken = createSelector( | |||||
| loginSelector, | |||||
| (state) => state.jwtToken.token | |||||
| ); |