mirror of
https://github.com/viarotel-org/escrcpy.git
synced 2025-02-22 04:49:42 +01:00
perf: ♻️ Improve wireless connection stability
This commit is contained in:
parent
69fecc3bc5
commit
85be8980d4
@ -1,8 +1,15 @@
|
|||||||
import ipRegex from 'ip-regex'
|
import ipRegex from 'ip-regex'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether it is an ipv6 address
|
||||||
|
*/
|
||||||
|
export function isIpv6(string) {
|
||||||
|
return ipRegex.v6().test(string)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Square brackets for IPV6 address
|
* Square brackets for IPV6 address
|
||||||
*/
|
*/
|
||||||
export function ipv6Wrapper(string) {
|
export function ipv6Wrapper(string) {
|
||||||
return ipRegex.v6().test(string) ? `[${string}]` : string
|
return isIpv6(string) ? `[${string}]` : string
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ import { uniq } from 'lodash-es'
|
|||||||
import adbConnectionMonitor from './helpers/adbConnectionMonitor/index.js'
|
import adbConnectionMonitor from './helpers/adbConnectionMonitor/index.js'
|
||||||
import { streamToBase64 } from '$electron/helpers/index.js'
|
import { streamToBase64 } from '$electron/helpers/index.js'
|
||||||
import { parseBatteryDump } from './helpers/battery/index.js'
|
import { parseBatteryDump } from './helpers/battery/index.js'
|
||||||
import { ipv6Wrapper } from './helpers/index.js'
|
import { ipv6Wrapper, isIpv6 } from './helpers/index.js'
|
||||||
|
|
||||||
const exec = util.promisify(_exec)
|
const exec = util.promisify(_exec)
|
||||||
|
|
||||||
@ -297,6 +297,10 @@ async function pair(host, port, code) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function connect(host, port = 5555) {
|
async function connect(host, port = 5555) {
|
||||||
|
if (!isIpv6(host) && client) {
|
||||||
|
return client.connect(host, port)
|
||||||
|
}
|
||||||
|
|
||||||
const { stderr, stdout } = await shell(`connect ${ipv6Wrapper(host)}:${port}`)
|
const { stderr, stdout } = await shell(`connect ${ipv6Wrapper(host)}:${port}`)
|
||||||
|
|
||||||
if (stderr) {
|
if (stderr) {
|
||||||
@ -313,6 +317,10 @@ async function connect(host, port = 5555) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function disconnect(host, port = 5555) {
|
async function disconnect(host, port = 5555) {
|
||||||
|
if (!isIpv6(host) && client) {
|
||||||
|
return client.disconnect(host, port)
|
||||||
|
}
|
||||||
|
|
||||||
const { stderr, stdout } = await shell(`disconnect ${ipv6Wrapper(host)}:${port}`)
|
const { stderr, stdout } = await shell(`disconnect ${ipv6Wrapper(host)}:${port}`)
|
||||||
|
|
||||||
if (stderr) {
|
if (stderr) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user