-
Notifications
You must be signed in to change notification settings - Fork 175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(app-shell,usb-bridge): improve flex usb communication #14170
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
bb37499
fix(usb-bridge): limit send bandwidth
sfoster1 1defd85
remove the most annoying log in our system
sfoster1 e7a9342
bump keepalive to infinity
sfoster1 cb73eee
some small fixes in usb-agent
sfoster1 c84bbbd
formats and lints
sfoster1 2d3816c
format the py side
sfoster1 da67885
lint
sfoster1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
bump keepalive to infinity
- Loading branch information
commit e7a93425665854608ad8b4269fe93e391491eb0d
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { ipcMain, IpcMainInvokeEvent } from 'electron' | ||
import axios, { AxiosRequestConfig } from 'axios' | ||
import axios, { AxiosRequestConfig, AxiosError } from 'axios' | ||
import FormData from 'form-data' | ||
import fs from 'fs' | ||
import path from 'path' | ||
|
@@ -34,19 +34,17 @@ let usbFetchInterval: NodeJS.Timeout | |
export function getSerialPortHttpAgent(): SerialPortHttpAgent | undefined { | ||
return usbHttpAgent | ||
} | ||
|
||
export function createSerialPortHttpAgent(path: string): void { | ||
const serialPortHttpAgent = new SerialPortHttpAgent({ | ||
maxFreeSockets: 1, | ||
maxSockets: 1, | ||
maxTotalSockets: 1, | ||
keepAlive: true, | ||
keepAliveMsecs: 10000, | ||
keepAliveMsecs: Infinity, | ||
path, | ||
logger: usbLog, | ||
timeout: 100000, | ||
}) | ||
|
||
usbHttpAgent = serialPortHttpAgent | ||
} | ||
|
||
|
@@ -63,12 +61,10 @@ function isUsbDeviceOt3(device: UsbDevice): boolean { | |
device.vendorId === parseInt(DEFAULT_VENDOR_ID, 16) | ||
) | ||
} | ||
|
||
async function usbListener( | ||
_event: IpcMainInvokeEvent, | ||
config: AxiosRequestConfig | ||
): Promise<unknown> { | ||
try { | ||
// TODO(bh, 2023-05-03): remove mutation | ||
let { data } = config | ||
let formHeaders = {} | ||
|
@@ -94,21 +90,21 @@ async function usbListener( | |
} | ||
|
||
const usbHttpAgent = getSerialPortHttpAgent() | ||
|
||
const response = await axios.request({ | ||
httpAgent: usbHttpAgent, | ||
...config, | ||
data, | ||
headers: { ...config.headers, ...formHeaders }, | ||
}) | ||
return { | ||
data: response.data, | ||
status: response.status, | ||
statusText: response.statusText, | ||
} | ||
try { | ||
const response = await axios.request({ | ||
httpAgent: usbHttpAgent, | ||
...config, | ||
data, | ||
headers: { ...config.headers, ...formHeaders }, | ||
}) | ||
return { | ||
error: false, | ||
data: response.data, | ||
status: response.status, | ||
statusText: response.statusText, | ||
} | ||
} catch (e) { | ||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions | ||
usbLog.debug(`usbListener error ${e?.message ?? 'unknown'}`) | ||
console.log(`axios request error ${e?.message ?? 'unknown'}`) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. was this changed cuz reading logs from the usb logger was annoying? cuz it seems like thats the right place to report logs here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah how does one get logs out of the usb logger? |
||
} | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lol