🔌 Socket + RabbitMQ setup for download-client touched folders/files

This commit is contained in:
2021-09-18 09:25:59 -07:00
parent 476a55614e
commit be43c163dc
13 changed files with 265 additions and 86 deletions

View File

@@ -0,0 +1,37 @@
import React, { createContext } from "react";
import io, { Socket } from "socket.io-client";
import { SOCKET_BASE_URI } from "../../constants/endpoints";
import { useDispatch } from "react-redux";
import { RMQ_SOCKET_CONNECTED } from "../../constants/action-types";
const WebSocketContext = createContext(null);
export const WebSocketProvider = ({ children }) => {
let socket: Socket;
let ws;
const dispatch = useDispatch();
if (!socket) {
socket = io(SOCKET_BASE_URI);
socket.on("connect", () => {
dispatch({
type: RMQ_SOCKET_CONNECTED,
isSocketConnected: true,
socketId: socket.id,
});
});
socket.on("disconnect", () => {
console.log(`disconnect`);
});
ws = {
socket: socket,
};
}
return (
<WebSocketContext.Provider value={ws}>{children}</WebSocketContext.Provider>
);
};
export { WebSocketContext };
export default WebSocketProvider;