Skip to content

Commit 10f395b

Browse files
committed
feat: new connection match regex
1 parent 1bde21e commit 10f395b

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/tunnel.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ export function tunnel(options: Record<string, string | number | null> = {}): {
4343
let url_rejector: (reason: unknown) => void = () => undefined;
4444
const url = new Promise<string>((...pair) => ([url_resolver, url_rejector] = pair));
4545

46-
const connection_regex =
47-
/Connection ([a-z0-9-]+) (?:.*?)connIndex=(\d) ip=([0-9.]+) location=([A-Z]+)/;
46+
const conn_regex = /connection[= ]([a-z0-9-]+)/i;
47+
const ip_regex = /ip=([0-9.]+)/;
48+
const location_regex = /location=([A-Z]+)/;
49+
const index_regex = /connIndex=(\d)/;
4850
const connection_resolvers: ((value: Connection | PromiseLike<Connection>) => void)[] = [];
4951
const connection_rejectors: ((reason: unknown) => void)[] = [];
5052
const connections: Promise<Connection>[] = [];
@@ -62,10 +64,16 @@ export function tunnel(options: Record<string, string | number | null> = {}): {
6264
const url_match = str.match(url_regex);
6365
url_match && url_resolver(url_match[1]);
6466

65-
const connection_match = str.match(connection_regex);
66-
if (connection_match) {
67-
const [, id, idx, ip, location] = connection_match;
68-
connection_resolvers[+idx]({ id, ip, location });
67+
const conn_match = str.match(conn_regex);
68+
const ip_match = str.match(ip_regex);
69+
const location_match = str.match(location_regex);
70+
const index_match = str.match(index_regex);
71+
if (conn_match && ip_match && location_match && index_match) {
72+
const [, id] = conn_match;
73+
const [, ip] = ip_match;
74+
const [, location] = location_match;
75+
const [, idx] = index_match;
76+
connection_resolvers[+idx]?.({ id, ip, location });
6977
}
7078
};
7179
child.stdout.on("data", parser).on("error", url_rejector);

0 commit comments

Comments
 (0)