MCPcopy Create free account
hub / github.com/GRVYDEV/Project-Lightspeed / socketReducer

Function socketReducer

frontend/src/context/SocketContext.jsx:6–40  ·  view source on GitHub ↗
(state, action)

Source from the content-addressed store, hash-verified

4export const SocketContext = createContext();
5
6const socketReducer = (state, action) => {
7 switch (action.type) {
8 case "initSocket": {
9 return {
10 ...state,
11 socket: new WebSocket(action.url),
12 url: action.url,
13 };
14 }
15 case "renewSocket": {
16 let timeout = state.wsTimeoutDuration * 2;
17 if (timeout > 10000) {
18 timeout = 10000;
19 }
20 return {
21 ...state,
22 socket: new WebSocket(state.url),
23 wsTimeoutDuration: timeout,
24 };
25 }
26 case "updateTimeout": {
27 return { ...state, connectTimeout: action.timeout };
28 }
29 case "clearTimeout": {
30 clearTimeout(state.connectTimeout);
31 return { ...state };
32 }
33 case "resetTimeoutDuration": {
34 return { ...state, wsTimeoutDuration: 250 };
35 }
36 default: {
37 return { ...state };
38 }
39 }
40};
41
42const initialState = {
43 url: "",

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected