Skip to content

Commit 49a3116

Browse files
authored
Merge pull request #160 from FoxxMD/remoteIpc
feat: Add remote IPC option
2 parents 266bc13 + 9ac0e41 commit 49a3116

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

src/transport/IPC.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export enum IPC_OPCODE {
1313
PONG
1414
}
1515

16-
export type FormatFunction = (id: number) => string;
16+
export type FormatFunction = (id: number) => string | [number, string];
1717
export type PathData = { platform: NodeJS.Platform[]; format: FormatFunction };
1818

1919
export type IPCTransportOptions = {
@@ -53,7 +53,7 @@ const defaultPathList: PathData[] = [
5353
}
5454
];
5555

56-
const createSocket = async (path: string): Promise<net.Socket> => {
56+
const createSocket = async (path: string | [number,string]): Promise<net.Socket> => {
5757
return new Promise((resolve, reject) => {
5858
const onError = () => {
5959
socket.removeListener("connect", onConnect);
@@ -64,8 +64,9 @@ const createSocket = async (path: string): Promise<net.Socket> => {
6464
socket.removeListener("error", onError);
6565
resolve(socket);
6666
};
67-
68-
const socket = net.createConnection(path);
67+
let socket: net.Socket;
68+
if (typeof path === "string") socket = net.createConnection(path);
69+
else socket = net.createConnection(path[0], path[1]);
6970

7071
socket.once("connect", onConnect);
7172
socket.once("error", onError);
@@ -93,7 +94,7 @@ export class IPCTransport extends Transport {
9394
const pipeId = this.client.pipeId;
9495

9596
return new Promise(async (resolve, reject) => {
96-
const useablePath: string[] = [];
97+
const useablePath: (string | [number,string])[] = [];
9798

9899
for (const pat of pathList) {
99100
if (!pat.platform.includes(process.platform)) continue;
@@ -103,16 +104,21 @@ export class IPCTransport extends Transport {
103104
if (pipeId) pipeIdList = [pipeId];
104105
else for (let i = 0; i < 10; i++) pipeIdList.push(i);
105106

106-
for (const pipeId of pipeIdList) {
107-
const socketPath = pat.format(pipeId);
108-
if (process.platform !== "win32" && !fs.existsSync(socketPath)) continue;
109-
useablePath.push(socketPath);
107+
const maybeTcp = pat.format(0);
108+
if (Array.isArray(maybeTcp)) {
109+
useablePath.push(maybeTcp);
110+
} else {
111+
for (const pipeId of pipeIdList) {
112+
const socketPath = pat.format(pipeId);
113+
if (process.platform !== "win32" && typeof socketPath === 'string' && !fs.existsSync(socketPath)) continue;
114+
useablePath.push(socketPath);
115+
}
110116
}
111117
}
112118

113119
this.client.emit(
114120
"debug",
115-
`CLIENT | Found ${useablePath.length} Discord client path;\n${useablePath.join("\n")}`
121+
`CLIENT | Found ${useablePath.length} Discord client path;\n${useablePath.map(x => Array.isArray(x) ? `${x[1]}:${x[0]}` : x).join("\n")}`
116122
);
117123

118124
if (useablePath.length < 0)

0 commit comments

Comments
 (0)