mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-27 21:20:29 +08:00
fix websocket on macos
This commit is contained in:
parent
a061d440d7
commit
a481ca3c89
@ -5,8 +5,6 @@ import WebSocket from 'ws'
|
|||||||
import { tray } from '../resolve/tray'
|
import { tray } from '../resolve/tray'
|
||||||
import { calcTraffic } from '../utils/calc'
|
import { calcTraffic } from '../utils/calc'
|
||||||
import { getRuntimeConfig } from './factory'
|
import { getRuntimeConfig } from './factory'
|
||||||
import { join } from 'path'
|
|
||||||
import { mihomoWorkDir } from '../utils/dirs'
|
|
||||||
|
|
||||||
let axiosIns: AxiosInstance = null!
|
let axiosIns: AxiosInstance = null!
|
||||||
let mihomoTrafficWs: WebSocket | null = null
|
let mihomoTrafficWs: WebSocket | null = null
|
||||||
@ -21,13 +19,13 @@ let connectionsRetry = 10
|
|||||||
export const getAxios = async (force: boolean = false): Promise<AxiosInstance> => {
|
export const getAxios = async (force: boolean = false): Promise<AxiosInstance> => {
|
||||||
const {
|
const {
|
||||||
'external-controller-pipe': mihomoPipe = '\\\\.\\pipe\\MihomoParty\\mihomo',
|
'external-controller-pipe': mihomoPipe = '\\\\.\\pipe\\MihomoParty\\mihomo',
|
||||||
'external-controller-unix': mihomoUnix = 'mihomo-party.sock'
|
'external-controller-unix': mihomoUnix = '/tmp/mihomo-party.sock'
|
||||||
} = await getControledMihomoConfig()
|
} = await getControledMihomoConfig()
|
||||||
if (axiosIns && !force) return axiosIns
|
if (axiosIns && !force) return axiosIns
|
||||||
|
|
||||||
axiosIns = axios.create({
|
axiosIns = axios.create({
|
||||||
baseURL: `http://localhost`,
|
baseURL: `http://localhost`,
|
||||||
socketPath: process.platform === 'win32' ? mihomoPipe : join(mihomoWorkDir(), mihomoUnix),
|
socketPath: process.platform === 'win32' ? mihomoPipe : mihomoUnix,
|
||||||
timeout: 15000
|
timeout: 15000
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -183,11 +181,11 @@ export const stopMihomoTraffic = (): void => {
|
|||||||
const mihomoTraffic = async (): Promise<void> => {
|
const mihomoTraffic = async (): Promise<void> => {
|
||||||
const {
|
const {
|
||||||
'external-controller-pipe': mihomoPipe = '\\\\.\\pipe\\MihomoParty\\mihomo',
|
'external-controller-pipe': mihomoPipe = '\\\\.\\pipe\\MihomoParty\\mihomo',
|
||||||
'external-controller-unix': mihomoUnix = 'mihomo-party.sock'
|
'external-controller-unix': mihomoUnix = '/tmp/mihomo-party.sock'
|
||||||
} = await getControledMihomoConfig()
|
} = await getControledMihomoConfig()
|
||||||
|
|
||||||
mihomoTrafficWs = new WebSocket(
|
mihomoTrafficWs = new WebSocket(
|
||||||
`ws+unix:${process.platform === 'win32' ? mihomoPipe : join(mihomoWorkDir(), mihomoUnix)}:/traffic`
|
`ws+unix:${process.platform === 'win32' ? mihomoPipe : mihomoUnix}:/traffic`
|
||||||
)
|
)
|
||||||
|
|
||||||
mihomoTrafficWs.onmessage = async (e): Promise<void> => {
|
mihomoTrafficWs.onmessage = async (e): Promise<void> => {
|
||||||
@ -241,11 +239,11 @@ export const stopMihomoMemory = (): void => {
|
|||||||
const mihomoMemory = async (): Promise<void> => {
|
const mihomoMemory = async (): Promise<void> => {
|
||||||
const {
|
const {
|
||||||
'external-controller-pipe': mihomoPipe = '\\\\.\\pipe\\MihomoParty\\mihomo',
|
'external-controller-pipe': mihomoPipe = '\\\\.\\pipe\\MihomoParty\\mihomo',
|
||||||
'external-controller-unix': mihomoUnix = 'mihomo-party.sock'
|
'external-controller-unix': mihomoUnix = '/tmp/mihomo-party.sock'
|
||||||
} = await getControledMihomoConfig()
|
} = await getControledMihomoConfig()
|
||||||
|
|
||||||
mihomoMemoryWs = new WebSocket(
|
mihomoMemoryWs = new WebSocket(
|
||||||
`ws+unix:${process.platform === 'win32' ? mihomoPipe : join(mihomoWorkDir(), mihomoUnix)}:/memory`
|
`ws+unix:${process.platform === 'win32' ? mihomoPipe : mihomoUnix}:/memory`
|
||||||
)
|
)
|
||||||
|
|
||||||
mihomoMemoryWs.onmessage = (e): void => {
|
mihomoMemoryWs.onmessage = (e): void => {
|
||||||
@ -290,12 +288,12 @@ export const stopMihomoLogs = (): void => {
|
|||||||
const mihomoLogs = async (): Promise<void> => {
|
const mihomoLogs = async (): Promise<void> => {
|
||||||
const {
|
const {
|
||||||
'external-controller-pipe': mihomoPipe = '\\\\.\\pipe\\MihomoParty\\mihomo',
|
'external-controller-pipe': mihomoPipe = '\\\\.\\pipe\\MihomoParty\\mihomo',
|
||||||
'external-controller-unix': mihomoUnix = 'mihomo-party.sock',
|
'external-controller-unix': mihomoUnix = '/tmp/mihomo-party.sock',
|
||||||
'log-level': logLevel = 'info'
|
'log-level': logLevel = 'info'
|
||||||
} = await getControledMihomoConfig()
|
} = await getControledMihomoConfig()
|
||||||
|
|
||||||
mihomoLogsWs = new WebSocket(
|
mihomoLogsWs = new WebSocket(
|
||||||
`ws+unix:${process.platform === 'win32' ? mihomoPipe : join(mihomoWorkDir(), mihomoUnix)}:/logs?level=${logLevel}`
|
`ws+unix:${process.platform === 'win32' ? mihomoPipe : mihomoUnix}:/logs?level=${logLevel}`
|
||||||
)
|
)
|
||||||
|
|
||||||
mihomoLogsWs.onmessage = (e): void => {
|
mihomoLogsWs.onmessage = (e): void => {
|
||||||
@ -340,11 +338,11 @@ export const stopMihomoConnections = (): void => {
|
|||||||
const mihomoConnections = async (): Promise<void> => {
|
const mihomoConnections = async (): Promise<void> => {
|
||||||
const {
|
const {
|
||||||
'external-controller-pipe': mihomoPipe = '\\\\.\\pipe\\MihomoParty\\mihomo',
|
'external-controller-pipe': mihomoPipe = '\\\\.\\pipe\\MihomoParty\\mihomo',
|
||||||
'external-controller-unix': mihomoUnix = 'mihomo-party.sock'
|
'external-controller-unix': mihomoUnix = '/tmp/mihomo-party.sock'
|
||||||
} = await getControledMihomoConfig()
|
} = await getControledMihomoConfig()
|
||||||
|
|
||||||
mihomoConnectionsWs = new WebSocket(
|
mihomoConnectionsWs = new WebSocket(
|
||||||
`ws+unix:${process.platform === 'win32' ? mihomoPipe : join(mihomoWorkDir(), mihomoUnix)}:/connections`
|
`ws+unix:${process.platform === 'win32' ? mihomoPipe : mihomoUnix}:/connections`
|
||||||
)
|
)
|
||||||
|
|
||||||
mihomoConnectionsWs.onmessage = (e): void => {
|
mihomoConnectionsWs.onmessage = (e): void => {
|
||||||
|
|||||||
@ -192,8 +192,8 @@ async function migration(): Promise<void> {
|
|||||||
await patchAppConfig({ envType: [envType] })
|
await patchAppConfig({ envType: [envType] })
|
||||||
}
|
}
|
||||||
// use unix socket
|
// use unix socket
|
||||||
if (process.platform !== 'win32' && externalControllerUnix !== 'mihomo-party.sock') {
|
if (process.platform !== 'win32' && externalControllerUnix !== '/tmp/mihomo-party.sock') {
|
||||||
await patchControledMihomoConfig({ 'external-controller-unix': 'mihomo-party.sock' })
|
await patchControledMihomoConfig({ 'external-controller-unix': '/tmp/mihomo-party.sock' })
|
||||||
}
|
}
|
||||||
// use named pipe
|
// use named pipe
|
||||||
if (
|
if (
|
||||||
|
|||||||
@ -37,7 +37,7 @@ export const defaultConfig: IAppConfig = {
|
|||||||
|
|
||||||
export const defaultControledMihomoConfig: Partial<IMihomoConfig> = {
|
export const defaultControledMihomoConfig: Partial<IMihomoConfig> = {
|
||||||
'external-controller-pipe': '\\\\.pipe\\MihomoParty\\mihomo',
|
'external-controller-pipe': '\\\\.pipe\\MihomoParty\\mihomo',
|
||||||
'external-controller-unix': 'mihomo-party.sock',
|
'external-controller-unix': '/tmp/mihomo-party.sock',
|
||||||
ipv6: true,
|
ipv6: true,
|
||||||
mode: 'rule',
|
mode: 'rule',
|
||||||
'mixed-port': 7890,
|
'mixed-port': 7890,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user