-
Notifications
You must be signed in to change notification settings - Fork 176
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
Changes from all commits
bb37499
1defd85
e7a9342
cb73eee
c84bbbd
2d3816c
da67885
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,19 +34,17 @@ | |
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, | ||
Comment on lines
-44
to
+43
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. lol |
||
path, | ||
logger: usbLog, | ||
timeout: 100000, | ||
}) | ||
|
||
usbHttpAgent = serialPortHttpAgent | ||
} | ||
|
||
|
@@ -63,52 +61,50 @@ | |
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 = {} | ||
|
||
// check for formDataProxy | ||
if (data?.formDataProxy != null) { | ||
// reconstruct FormData | ||
const formData = new FormData() | ||
const { protocolKey } = data.formDataProxy | ||
|
||
const srcFilePaths: string[] = await getProtocolSrcFilePaths(protocolKey) | ||
|
||
// create readable stream from file | ||
srcFilePaths.forEach(srcFilePath => { | ||
const readStream = fs.createReadStream(srcFilePath) | ||
formData.append('files', readStream, path.basename(srcFilePath)) | ||
}) | ||
|
||
formData.append('key', protocolKey) | ||
// TODO(bh, 2023-05-03): remove mutation | ||
let { data } = config | ||
let formHeaders = {} | ||
|
||
// check for formDataProxy | ||
if (data?.formDataProxy != null) { | ||
// reconstruct FormData | ||
const formData = new FormData() | ||
const { protocolKey } = data.formDataProxy | ||
|
||
const srcFilePaths: string[] = await getProtocolSrcFilePaths(protocolKey) | ||
|
||
// create readable stream from file | ||
srcFilePaths.forEach(srcFilePath => { | ||
const readStream = fs.createReadStream(srcFilePath) | ||
formData.append('files', readStream, path.basename(srcFilePath)) | ||
}) | ||
|
||
formHeaders = formData.getHeaders() | ||
data = formData | ||
} | ||
formData.append('key', protocolKey) | ||
|
||
const usbHttpAgent = getSerialPortHttpAgent() | ||
formHeaders = formData.getHeaders() | ||
data = formData | ||
} | ||
|
||
const usbHttpAgent = getSerialPortHttpAgent() | ||
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? |
||
} | ||
} | ||
|
||
|
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.
is this to cut down on noise? seems like a useful warning since we expect there to be urls in the release set
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.
yeah the noise is just brutal