Skip to content

Commit 2b6abed

Browse files
committed
committing mid-refactor to checkout master functionality
1 parent 91c0409 commit 2b6abed

File tree

7 files changed

+99
-32
lines changed

7 files changed

+99
-32
lines changed

httpMainController.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
const nodeFetch = require('node-fetch');
2+
const http2 = require("http2");
3+
const setCookie = require("set-cookie-parser");
4+
5+
const httpMainController = {};
6+
7+
// array of open http2 connections
8+
httpMainController.openHTTP2Connections = [];
9+
10+
httpMainController.openHTTPconnection = (reqResObj, connectionArray) => {
11+
// http2 is currentonly supported over https
12+
reqResObj.protocol === "https://"
13+
? httpController.establishHTTP2Connection(reqResObj, connectionArray)
14+
: httpController.establishHTTP1connection(reqResObj, connectionArray);
15+
};
16+
17+
httpMainController.establishHTTP2Connection = (reqResObj, connectionArray) => {
18+
/*
19+
Attempt to find an existing HTTP2 connection in openHTTP2Connections Array.
20+
If exists, use connection to initiate request
21+
If not, create connection, push to array, and then initiate request
22+
*/
23+
24+
// find connection with same host as passed in reqResObj
25+
const foundHTTP2Connection = httpMainController.openHTTP2Connections.find(
26+
(conn) => conn.host === reqResObj.host
27+
);
28+
29+
// EXISTING HTTP2 CONNECTION IS FOUND -----
30+
31+
if (foundHTTP2Connection) {
32+
const { client } = foundHTTP2Connection;
33+
34+
// periodically check if the client is open or destroyed, and attach if conditions are met
35+
const interval = setInterval(() => {
36+
if (foundHTTP2Connection.status === "connected") {
37+
this.attachRequestToHTTP2Client(client, reqResObj, connectionArray);
38+
clearInterval(interval);
39+
}
40+
// if failed, could because of protocol error. try HTTP1
41+
else if (foundHTTP2Connection.status === "failed" || client.destroyed) {
42+
httpController.establishHTTP1connection(reqResObj, connectionArray);
43+
clearInterval(interval);
44+
}
45+
}, 50);
46+
47+
// --------------------------------------------------
48+
// if hasnt changed in 10 seconds, mark as error
49+
// --------------------------------------------------
50+
setTimeout(() => {
51+
clearInterval(interval);
52+
if (foundHTTP2Connection.status === "initialized") {
53+
reqResObj.connection = "error";
54+
store.default.dispatch(actions.reqResUpdate(reqResObj));
55+
}
56+
}, 10000);
57+
};
58+
}

main.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,3 +664,6 @@ ipcMain.on("open-gql", (event, args) => {
664664
});
665665
}
666666
});
667+
668+
// export main window so we can access ipcMain from other files
669+
module.exports = mainWindow;

package-lock.json

Lines changed: 21 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

preload.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
const { ipcRenderer, contextBridge } = require("electron");
22

33
contextBridge.exposeInMainWorld("api", {
4-
send: (channel, data) => {
4+
send: (channel, ...data) => {
55
// allowlist channels
66
const allowedChannels = [
77
"toMain",
88
"confirm-clear-history",
99
"import-proto",
1010
"quit-and-install",
11+
'open-http'
1112
];
1213
if (allowedChannels.includes(channel)) {
13-
ipcRenderer.send(channel, data);
14+
ipcRenderer.send(channel, ...data);
1415
}
1516
},
1617
receive: (channel, cb) => {
@@ -22,6 +23,7 @@ contextBridge.exposeInMainWorld("api", {
2223
"clear-history-response",
2324
"proto-info",
2425
"message",
26+
'testing'
2527
];
2628
if (allowedChannels.includes(channel)) {
2729
ipcRenderer.on(channel, (event, ...args) => cb(...args));

src/client/components/containers/App.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { Component } from "react";
22
import "../../../assets/style/App.scss";
33
const { api } = window;
4-
// import ContentsContainer from './ContentsContainer.jsx';
4+
import ContentsContainer from './ContentsContainer.jsx';
55
// import ReqResCtrl from '../../controllers/reqResController';
66
import SidebarContainer from "./SidebarContainer.jsx";
77
import UpdatePopUpContainer from "./UpdatePopUpContainer.jsx";
@@ -56,7 +56,7 @@ class App extends Component {
5656
<div id="app">
5757
<UpdatePopUpContainer />
5858
<SidebarContainer />
59-
{/* <ContentsContainer /> */}
59+
<ContentsContainer />
6060
</div>
6161
);
6262
}

src/client/components/containers/ContentsContainer.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { Component } from 'react';
22

3-
import GraphContainer from './GraphContainer.jsx';
3+
// import GraphContainer from './GraphContainer.jsx';
44
import ReqResContainer from './ReqResContainer.jsx';
55
import NavBarContainer from './NavBarContainer.jsx';
66

@@ -12,7 +12,7 @@ class Contents extends Component {
1212
render() {
1313
return(
1414
<div className={'contents'}>
15-
<GraphContainer/>
15+
{/* <GraphContainer/> */}
1616
<NavBarContainer/>
1717
<ReqResContainer/>
1818
</div>

src/client/controllers/reqResController.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import * as store from "../store";
22
import * as actions from "../actions/actions";
3-
import httpController from "./httpController.js";
4-
import wsController from "./wsController.js";
5-
import graphQLController from "./graphQLController.js";
6-
import grpcController from "./grpcController.js";
3+
// import httpController from "./httpController.js";
4+
// import wsController from "./wsController.js";
5+
// import graphQLController from "./graphQLController.js";
6+
// import grpcController from "./grpcController.js";
7+
8+
const { api } = window;
79

810
const connectionController = {
911
openConnectionArray: [],
@@ -57,7 +59,9 @@ const connectionController = {
5759
wsController.openWSconnection(reqResObj, this.openConnectionArray);
5860
else if (reqResObj.gRPC) grpcController.openGrpcConnection(reqResObj);
5961
else {
60-
httpController.openHTTPconnection(reqResObj, this.openConnectionArray);
62+
api.send('open-http', reqResObj, this.openConnectionArray);
63+
api.receive('testing', (data) => console.log('just received : ', data))
64+
// httpController.openHTTPconnection(reqResObj, this.openConnectionArray);
6165
}
6266
},
6367

0 commit comments

Comments
 (0)