recker 1.0.14 → 1.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -3
- package/dist/ai/client.d.ts +2 -3
- package/dist/ai/client.d.ts.map +1 -1
- package/dist/ai/client.js +5 -6
- package/dist/ai/index.d.ts +1 -1
- package/dist/ai/index.d.ts.map +1 -1
- package/dist/ai/index.js +1 -1
- package/dist/cli/tui/ai-chat.js +2 -2
- package/dist/dns/index.d.ts +35 -0
- package/dist/dns/index.d.ts.map +1 -0
- package/dist/dns/index.js +124 -0
- package/dist/transport/base-udp.d.ts.map +1 -1
- package/dist/transport/base-udp.js +1 -0
- package/dist/transport/udp-response.d.ts +2 -2
- package/dist/transport/udp-response.d.ts.map +1 -1
- package/dist/transport/udp-response.js +2 -2
- package/dist/transport/udp.d.ts +4 -3
- package/dist/transport/udp.d.ts.map +1 -1
- package/dist/transport/udp.js +16 -7
- package/dist/types/udp.d.ts +1 -0
- package/dist/types/udp.d.ts.map +1 -1
- package/dist/udp/index.d.ts +2 -2
- package/dist/udp/index.d.ts.map +1 -1
- package/dist/udp/index.js +2 -2
- package/dist/utils/whois.d.ts +18 -0
- package/dist/utils/whois.d.ts.map +1 -1
- package/dist/utils/whois.js +63 -0
- package/dist/webrtc/index.d.ts +80 -0
- package/dist/webrtc/index.d.ts.map +1 -0
- package/dist/webrtc/index.js +311 -0
- package/dist/websocket/client.d.ts +1 -1
- package/dist/websocket/client.d.ts.map +1 -1
- package/dist/websocket/client.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/ai/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AIClient, AIClientConfig, ChatOptions, AIResponse, AIStream, EmbedOptions, EmbedResponse, AIMetrics } from '../types/ai.js';
|
|
2
|
-
export declare class
|
|
2
|
+
export declare class UnifiedAIClient implements AIClient {
|
|
3
3
|
private config;
|
|
4
4
|
private providers;
|
|
5
5
|
private _metrics;
|
|
@@ -19,6 +19,5 @@ export declare class AIClientImpl implements AIClient {
|
|
|
19
19
|
private logResponse;
|
|
20
20
|
private sleep;
|
|
21
21
|
}
|
|
22
|
-
export declare function
|
|
23
|
-
export declare const ai: AIClient;
|
|
22
|
+
export declare function createAI(config?: AIClientConfig): AIClient;
|
|
24
23
|
//# sourceMappingURL=client.d.ts.map
|
package/dist/ai/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/ai/client.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAEV,QAAQ,EACR,cAAc,EACd,WAAW,EACX,UAAU,EACV,QAAQ,EACR,YAAY,EACZ,aAAa,EACb,SAAS,EAGV,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/ai/client.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAEV,QAAQ,EACR,cAAc,EACd,WAAW,EACX,UAAU,EACV,QAAQ,EACR,YAAY,EACZ,aAAa,EACb,SAAS,EAGV,MAAM,gBAAgB,CAAC;AA+IxB,qBAAa,eAAgB,YAAW,QAAQ;IAC9C,OAAO,CAAC,MAAM,CAAiB;IAC/B,OAAO,CAAC,SAAS,CAA8C;IAC/D,OAAO,CAAC,QAAQ,CAA4C;gBAEhD,MAAM,GAAE,cAAmB;IAevC,IAAI,OAAO,IAAI,SAAS,CAEvB;IAKK,IAAI,CAAC,eAAe,EAAE,WAAW,GAAG,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IA8BhE,MAAM,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC;IAQ/C,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC;IAQ1D,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,QAAQ;IAwBhD,OAAO,CAAC,mBAAmB;IAe3B,OAAO,CAAC,WAAW;IAkBnB,OAAO,CAAC,gBAAgB;YAYV,gBAAgB;IAwE9B,OAAO,CAAC,WAAW;IAoBnB,OAAO,CAAC,gBAAgB;IAgCxB,OAAO,CAAC,aAAa;IAwBrB,OAAO,CAAC,WAAW;IAYnB,OAAO,CAAC,KAAK;CAGd;AAiBD,wBAAgB,QAAQ,CAAC,MAAM,CAAC,EAAE,cAAc,GAAG,QAAQ,CAE1D"}
|
package/dist/ai/client.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AIError, RateLimitError, ContextLengthError, OverloadedError } from './providers/base.js';
|
|
2
2
|
import { OpenAIProvider } from './providers/openai.js';
|
|
3
3
|
import { AnthropicProvider } from './providers/anthropic.js';
|
|
4
|
-
class
|
|
4
|
+
class AIMetricsTracker {
|
|
5
5
|
data = {
|
|
6
6
|
totalRequests: 0,
|
|
7
7
|
totalTokens: 0,
|
|
@@ -87,10 +87,10 @@ class AIMetricsImpl {
|
|
|
87
87
|
};
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
|
-
export class
|
|
90
|
+
export class UnifiedAIClient {
|
|
91
91
|
config;
|
|
92
92
|
providers = new Map();
|
|
93
|
-
_metrics = new
|
|
93
|
+
_metrics = new AIMetricsTracker();
|
|
94
94
|
constructor(config = {}) {
|
|
95
95
|
this.config = {
|
|
96
96
|
defaultProvider: 'openai',
|
|
@@ -283,7 +283,6 @@ export class AIClientImpl {
|
|
|
283
283
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
284
284
|
}
|
|
285
285
|
}
|
|
286
|
-
export function
|
|
287
|
-
return new
|
|
286
|
+
export function createAI(config) {
|
|
287
|
+
return new UnifiedAIClient(config);
|
|
288
288
|
}
|
|
289
|
-
export const ai = createAIClient();
|
package/dist/ai/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { UnifiedAIClient, createAI } from './client.js';
|
|
2
2
|
export { BaseAIProvider, AIError, RateLimitError, ContextLengthError, OverloadedError, AuthenticationError } from './providers/base.js';
|
|
3
3
|
export { OpenAIProvider } from './providers/openai.js';
|
|
4
4
|
export { AnthropicProvider } from './providers/anthropic.js';
|
package/dist/ai/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ai/index.ts"],"names":[],"mappings":"AA2DA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ai/index.ts"],"names":[],"mappings":"AA2DA,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAGxD,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AACxI,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAG7D,OAAO,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAG1G,OAAO,EACL,gBAAgB,EAChB,sBAAsB,EACtB,iBAAiB,EACjB,eAAe,EACf,oBAAoB,GACrB,MAAM,mBAAmB,CAAC;AAG3B,YAAY,EAEV,UAAU,EACV,WAAW,EACX,WAAW,EACX,WAAW,EACX,cAAc,EACd,QAAQ,EAGR,UAAU,EACV,QAAQ,EACR,SAAS,EAGT,gBAAgB,EAChB,cAAc,EACd,cAAc,EACd,WAAW,EACX,YAAY,EAGZ,UAAU,EACV,aAAa,EAGb,eAAe,EACf,WAAW,EACX,eAAe,EACf,mBAAmB,EACnB,wBAAwB,EACxB,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,QAAQ,EAGR,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,mBAAmB,EACnB,YAAY,EAGZ,QAAQ,EACR,SAAS,EACT,gBAAgB,EAGhB,SAAS,EACT,WAAW,EACX,cAAc,EACd,gBAAgB,EAChB,KAAK,GACN,MAAM,gBAAgB,CAAC;AAGxB,YAAY,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAC1D,YAAY,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC"}
|
package/dist/ai/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { UnifiedAIClient, createAI } from './client.js';
|
|
2
2
|
export { BaseAIProvider, AIError, RateLimitError, ContextLengthError, OverloadedError, AuthenticationError } from './providers/base.js';
|
|
3
3
|
export { OpenAIProvider } from './providers/openai.js';
|
|
4
4
|
export { AnthropicProvider } from './providers/anthropic.js';
|
package/dist/cli/tui/ai-chat.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import readline from 'node:readline';
|
|
2
2
|
import pc from '../../utils/colors.js';
|
|
3
|
-
import {
|
|
3
|
+
import { createAI } from '../../ai/client.js';
|
|
4
4
|
export async function startAIChat(rl, provider = 'openai', apiKey, model) {
|
|
5
5
|
console.clear();
|
|
6
6
|
console.log(pc.bold(pc.magenta(`🤖 Rek AI Chat (${provider})`)));
|
|
@@ -14,7 +14,7 @@ Warning: No API Key found for ${provider}.`));
|
|
|
14
14
|
console.log(`Example: set ${envKey}=sk-... inside the shell.`);
|
|
15
15
|
return;
|
|
16
16
|
}
|
|
17
|
-
const client =
|
|
17
|
+
const client = createAI({
|
|
18
18
|
defaultProvider: provider,
|
|
19
19
|
providers: {
|
|
20
20
|
[provider]: { apiKey: key }
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type DnsSecurityRecords } from '../utils/dns-toolkit.js';
|
|
2
|
+
export { createLookupFunction, customDNSLookup } from '../utils/dns.js';
|
|
3
|
+
export { createDoHLookup } from '../utils/doh.js';
|
|
4
|
+
export { getSecurityRecords, type DnsSecurityRecords } from '../utils/dns-toolkit.js';
|
|
5
|
+
export type { DNSOptions } from '../types/index.js';
|
|
6
|
+
export type RecordType = 'A' | 'AAAA' | 'CNAME' | 'MX' | 'TXT' | 'NS' | 'SOA' | 'SRV' | 'CAA' | 'PTR';
|
|
7
|
+
export type DoHProvider = 'cloudflare' | 'google' | 'quad9' | 'system';
|
|
8
|
+
export interface DNSClientOptions {
|
|
9
|
+
provider?: DoHProvider;
|
|
10
|
+
timeout?: number;
|
|
11
|
+
debug?: boolean;
|
|
12
|
+
servers?: string[];
|
|
13
|
+
}
|
|
14
|
+
export declare class DNSClient {
|
|
15
|
+
private options;
|
|
16
|
+
constructor(options?: DNSClientOptions);
|
|
17
|
+
private log;
|
|
18
|
+
resolve(hostname: string, type?: RecordType): Promise<string[]>;
|
|
19
|
+
resolve4(hostname: string): Promise<string[]>;
|
|
20
|
+
resolve6(hostname: string): Promise<string[]>;
|
|
21
|
+
resolveMx(hostname: string): Promise<{
|
|
22
|
+
priority: number;
|
|
23
|
+
exchange: string;
|
|
24
|
+
}[]>;
|
|
25
|
+
resolveTxt(hostname: string): Promise<string[]>;
|
|
26
|
+
resolveNs(hostname: string): Promise<string[]>;
|
|
27
|
+
resolveSoa(hostname: string): Promise<import("dns").SoaRecord>;
|
|
28
|
+
resolveSrv(hostname: string): Promise<import("dns").SrvRecord[]>;
|
|
29
|
+
resolveCaa(hostname: string): Promise<import("dns").CaaRecord[]>;
|
|
30
|
+
reverse(ip: string): Promise<string[]>;
|
|
31
|
+
resolveAll(hostname: string): Promise<Record<string, unknown[]>>;
|
|
32
|
+
getSecurityRecords(domain: string): Promise<DnsSecurityRecords>;
|
|
33
|
+
}
|
|
34
|
+
export declare function createDNS(options?: DNSClientOptions): DNSClient;
|
|
35
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dns/index.ts"],"names":[],"mappings":"AA4BA,OAAO,EAAgD,KAAK,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;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IAQrD,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAO9C,UAAU,CAAC,QAAQ,EAAE,MAAM;IAO3B,UAAU,CAAC,QAAQ,EAAE,MAAM;IAO3B,UAAU,CAAC,QAAQ,EAAE,MAAM;IAO3B,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAOhC,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;IA4BhE,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC;CAItE;AA0BD,wBAAgB,SAAS,CAAC,OAAO,CAAC,EAAE,gBAAgB,GAAG,SAAS,CAE/D"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { promises as nodeDns } from 'node:dns';
|
|
2
|
+
import { getSecurityRecords as getSecurityRecordsUtil } from '../utils/dns-toolkit.js';
|
|
3
|
+
export { createLookupFunction, customDNSLookup } from '../utils/dns.js';
|
|
4
|
+
export { createDoHLookup } from '../utils/doh.js';
|
|
5
|
+
export { getSecurityRecords } from '../utils/dns-toolkit.js';
|
|
6
|
+
export class DNSClient {
|
|
7
|
+
options;
|
|
8
|
+
constructor(options = {}) {
|
|
9
|
+
this.options = {
|
|
10
|
+
provider: options.provider ?? 'system',
|
|
11
|
+
timeout: options.timeout ?? 5000,
|
|
12
|
+
debug: options.debug ?? false,
|
|
13
|
+
servers: options.servers ?? [],
|
|
14
|
+
};
|
|
15
|
+
if (this.options.servers.length > 0 && this.options.provider === 'system') {
|
|
16
|
+
nodeDns.setServers(this.options.servers);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
log(message, ...args) {
|
|
20
|
+
if (this.options.debug) {
|
|
21
|
+
console.log(`[DNS] ${message}`, ...args);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
async resolve(hostname, type = 'A') {
|
|
25
|
+
this.log(`Resolving ${hostname} (${type})`);
|
|
26
|
+
const start = Date.now();
|
|
27
|
+
try {
|
|
28
|
+
let result;
|
|
29
|
+
switch (type) {
|
|
30
|
+
case 'A':
|
|
31
|
+
result = await nodeDns.resolve4(hostname);
|
|
32
|
+
break;
|
|
33
|
+
case 'AAAA':
|
|
34
|
+
result = await nodeDns.resolve6(hostname);
|
|
35
|
+
break;
|
|
36
|
+
case 'CNAME':
|
|
37
|
+
result = await nodeDns.resolveCname(hostname);
|
|
38
|
+
break;
|
|
39
|
+
case 'NS':
|
|
40
|
+
result = await nodeDns.resolveNs(hostname);
|
|
41
|
+
break;
|
|
42
|
+
case 'PTR':
|
|
43
|
+
result = await nodeDns.resolvePtr(hostname);
|
|
44
|
+
break;
|
|
45
|
+
case 'TXT': {
|
|
46
|
+
const txt = await nodeDns.resolveTxt(hostname);
|
|
47
|
+
result = txt.map(chunks => chunks.join(''));
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
default: {
|
|
51
|
+
const records = await nodeDns.resolve(hostname, type);
|
|
52
|
+
if (Array.isArray(records)) {
|
|
53
|
+
result = records.map(r => typeof r === 'string' ? r : JSON.stringify(r));
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
result = [JSON.stringify(records)];
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
this.log(`Resolved ${hostname} in ${Date.now() - start}ms:`, result);
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
this.log(`Failed to resolve ${hostname}:`, error);
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
resolve4(hostname) {
|
|
69
|
+
return nodeDns.resolve4(hostname);
|
|
70
|
+
}
|
|
71
|
+
resolve6(hostname) {
|
|
72
|
+
return nodeDns.resolve6(hostname);
|
|
73
|
+
}
|
|
74
|
+
resolveMx(hostname) {
|
|
75
|
+
return nodeDns.resolveMx(hostname);
|
|
76
|
+
}
|
|
77
|
+
async resolveTxt(hostname) {
|
|
78
|
+
const records = await nodeDns.resolveTxt(hostname);
|
|
79
|
+
return records.map(chunks => chunks.join(''));
|
|
80
|
+
}
|
|
81
|
+
resolveNs(hostname) {
|
|
82
|
+
return nodeDns.resolveNs(hostname);
|
|
83
|
+
}
|
|
84
|
+
resolveSoa(hostname) {
|
|
85
|
+
return nodeDns.resolveSoa(hostname);
|
|
86
|
+
}
|
|
87
|
+
resolveSrv(hostname) {
|
|
88
|
+
return nodeDns.resolveSrv(hostname);
|
|
89
|
+
}
|
|
90
|
+
resolveCaa(hostname) {
|
|
91
|
+
return nodeDns.resolveCaa(hostname);
|
|
92
|
+
}
|
|
93
|
+
reverse(ip) {
|
|
94
|
+
return nodeDns.reverse(ip);
|
|
95
|
+
}
|
|
96
|
+
async resolveAll(hostname) {
|
|
97
|
+
this.log(`Resolving all records for ${hostname}`);
|
|
98
|
+
const results = {};
|
|
99
|
+
const tryResolve = async (type, fn) => {
|
|
100
|
+
try {
|
|
101
|
+
results[type] = await fn();
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
await Promise.all([
|
|
107
|
+
tryResolve('A', () => nodeDns.resolve4(hostname)),
|
|
108
|
+
tryResolve('AAAA', () => nodeDns.resolve6(hostname)),
|
|
109
|
+
tryResolve('MX', () => nodeDns.resolveMx(hostname)),
|
|
110
|
+
tryResolve('TXT', () => nodeDns.resolveTxt(hostname)),
|
|
111
|
+
tryResolve('NS', () => nodeDns.resolveNs(hostname)),
|
|
112
|
+
tryResolve('CAA', () => nodeDns.resolveCaa(hostname)),
|
|
113
|
+
]);
|
|
114
|
+
this.log(`Resolved all for ${hostname}:`, Object.keys(results));
|
|
115
|
+
return results;
|
|
116
|
+
}
|
|
117
|
+
async getSecurityRecords(domain) {
|
|
118
|
+
this.log(`Getting security records for ${domain}`);
|
|
119
|
+
return getSecurityRecordsUtil(domain);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
export function createDNS(options) {
|
|
123
|
+
return new DNSClient(options);
|
|
124
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-udp.d.ts","sourceRoot":"","sources":["../../src/transport/base-udp.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,KAAK,EACV,uBAAuB,EACvB,UAAU,EACV,aAAa,EACd,MAAM,iBAAiB,CAAC;AAMzB,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAKD,eAAO,MAAM,iBAAiB,sCAA6C,CAAC;AAK5E,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,uBAAuB,
|
|
1
|
+
{"version":3,"file":"base-udp.d.ts","sourceRoot":"","sources":["../../src/transport/base-udp.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,KAAK,EACV,uBAAuB,EACvB,UAAU,EACV,aAAa,EACd,MAAM,iBAAiB,CAAC;AAMzB,MAA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AS,CAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE;IAqB7E,SAAS,CAAC,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAWhD,SAAS,CAAC,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOpC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7B"}
|
|
@@ -5,7 +5,7 @@ export interface UDPResponseOptions {
|
|
|
5
5
|
connection?: UDPConnection;
|
|
6
6
|
url?: string;
|
|
7
7
|
}
|
|
8
|
-
export declare class
|
|
8
|
+
export declare class UDPResponseWrapper implements UDPResponse {
|
|
9
9
|
private _buffer;
|
|
10
10
|
private _timings;
|
|
11
11
|
private _connection;
|
|
@@ -26,7 +26,7 @@ export declare class UDPResponseImpl implements UDPResponse {
|
|
|
26
26
|
cleanText(): Promise<string>;
|
|
27
27
|
blob(): Promise<Blob>;
|
|
28
28
|
read(): ReadableStream<Uint8Array> | null;
|
|
29
|
-
clone():
|
|
29
|
+
clone(): UDPResponseWrapper;
|
|
30
30
|
sse(): AsyncGenerator<SSEEvent>;
|
|
31
31
|
download(): AsyncGenerator<ProgressEvent>;
|
|
32
32
|
packets(): AsyncGenerator<Buffer>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"udp-response.d.ts","sourceRoot":"","sources":["../../src/transport/udp-response.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAkB,QAAQ,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACjF,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAK9E,MAAM,WAAW,kBAAkB;IACjC,OAAO,CAAC,EAAE,UAAU,CAAC;IACrB,UAAU,CAAC,EAAE,aAAa,CAAC;IA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CAAC,UAAU,CAAC,GAAG,IAAI;IAczC,KAAK,IAAI,oBAAoB;IAWtB,GAAG,IAAI,cAAc,CAAC,QAAQ,CAAC;IAI/B,QAAQ,IAAI,cAAc,CAAC,aAAa,CAAC;IAezC,OAAO,IAAI,cAAc,CAAC,MAAM,CAAC;IA6BjC,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,cAAc,CAAC,UAAU,CAAC;CAK5D"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export class
|
|
1
|
+
export class UDPResponseWrapper {
|
|
2
2
|
_buffer;
|
|
3
3
|
_timings;
|
|
4
4
|
_connection;
|
|
@@ -85,7 +85,7 @@ export class UDPResponseImpl {
|
|
|
85
85
|
});
|
|
86
86
|
}
|
|
87
87
|
clone() {
|
|
88
|
-
return new
|
|
88
|
+
return new UDPResponseWrapper(Buffer.from(this._buffer), {
|
|
89
89
|
timings: { ...this._timings },
|
|
90
90
|
connection: { ...this._connection },
|
|
91
91
|
url: this._url,
|
package/dist/transport/udp.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import type { ReckerRequest, ReckerResponse } from '../types/index.js';
|
|
2
2
|
import type { UDPTransportOptions, SimpleUDPAPI } from '../types/udp.js';
|
|
3
3
|
import { BaseUDPTransport } from './base-udp.js';
|
|
4
|
-
export declare class
|
|
4
|
+
export declare class UDPClient extends BaseUDPTransport {
|
|
5
5
|
private socket;
|
|
6
6
|
private baseUrl;
|
|
7
7
|
private udpOptions;
|
|
8
8
|
private multicastGroups;
|
|
9
9
|
constructor(baseUrl?: string, options?: UDPTransportOptions);
|
|
10
|
+
private log;
|
|
10
11
|
private getSocket;
|
|
11
12
|
private _socketBound;
|
|
12
13
|
dispatch(req: ReckerRequest): Promise<ReckerResponse>;
|
|
@@ -16,7 +17,7 @@ export declare class UDPTransportImpl extends BaseUDPTransport {
|
|
|
16
17
|
leaveMulticast(group: string): void;
|
|
17
18
|
close(): Promise<void>;
|
|
18
19
|
}
|
|
19
|
-
export declare function
|
|
20
|
+
export declare function createUDP(options?: UDPTransportOptions): UDPClient;
|
|
20
21
|
export declare const udp: SimpleUDPAPI;
|
|
21
|
-
export {
|
|
22
|
+
export { UDPClient as UDPTransport };
|
|
22
23
|
//# sourceMappingURL=udp.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"udp.d.ts","sourceRoot":"","sources":["../../src/transport/udp.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,KAAK,EACV,mBAAmB,EAInB,YAAY,EACb,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,gBAAgB,EAAwC,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"udp.d.ts","sourceRoot":"","sources":["../../src/transport/udp.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,KAAK,EACV,mBAAmB,EAInB,YAAY,EACb,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,gBAAgB,EAAwC,MAAM,eAAe,CAAC;AA2CvF,qBAAa,SAAU,SAAQ,gBAAgB;IAC7C,OAAO,CAAC,MAAM,CAA6B;IAC3C,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,UAAU,CAAgC;IAClD,OAAO,CAAC,eAAe,CAA0B;gBAErC,OAAO,GAAE,MAAW,EAAE,OAAO,GAAE,mBAAwB;IAuBnE,OAAO,CAAC,GAAG;IASX,OAAO,CAAC,SAAS;IA0CjB,OAAO,CAAC,YAAY,CAAkB;IAKhC,QAAQ,CAAC,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC;IAwFrD,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAyB7D,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAiB1D,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAWlC,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAW7B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAqB7B;AAsBD,wBAAgB,SAAS,CAAC,OAAO,GAAE,mBAAwB,GAAG,SAAS,CAEtE;AAKD,eAAO,MAAM,GAAG,EAAE,YAuGjB,CAAC;AAGF,OAAO,EAAE,SAAS,IAAI,YAAY,EAAE,CAAC"}
|
package/dist/transport/udp.js
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import dgram from 'node:dgram';
|
|
2
2
|
import { BaseUDPTransport, udpRequestStorage } from './base-udp.js';
|
|
3
|
-
import {
|
|
3
|
+
import { UDPResponseWrapper } from './udp-response.js';
|
|
4
4
|
const DEFAULT_OPTIONS = {
|
|
5
5
|
timeout: 5000,
|
|
6
6
|
retransmissions: 3,
|
|
7
7
|
maxPacketSize: 65507,
|
|
8
8
|
observability: true,
|
|
9
|
+
debug: false,
|
|
9
10
|
broadcast: false,
|
|
10
11
|
multicastTTL: 1,
|
|
11
12
|
multicastLoopback: true,
|
|
12
13
|
type: 'udp4',
|
|
13
14
|
};
|
|
14
|
-
export class
|
|
15
|
+
export class UDPClient extends BaseUDPTransport {
|
|
15
16
|
socket = null;
|
|
16
17
|
baseUrl;
|
|
17
18
|
udpOptions;
|
|
@@ -26,6 +27,7 @@ export class UDPTransportImpl extends BaseUDPTransport {
|
|
|
26
27
|
retransmissions: options.retransmissions ?? DEFAULT_OPTIONS.retransmissions,
|
|
27
28
|
maxPacketSize: options.maxPacketSize ?? DEFAULT_OPTIONS.maxPacketSize,
|
|
28
29
|
observability: options.observability ?? DEFAULT_OPTIONS.observability,
|
|
30
|
+
debug: options.debug ?? DEFAULT_OPTIONS.debug,
|
|
29
31
|
localAddress: options.localAddress ?? '',
|
|
30
32
|
localPort: options.localPort ?? 0,
|
|
31
33
|
broadcast: options.broadcast ?? DEFAULT_OPTIONS.broadcast,
|
|
@@ -37,6 +39,11 @@ export class UDPTransportImpl extends BaseUDPTransport {
|
|
|
37
39
|
sendBufferSize: options.sendBufferSize,
|
|
38
40
|
};
|
|
39
41
|
}
|
|
42
|
+
log(message, ...args) {
|
|
43
|
+
if (this.udpOptions.debug) {
|
|
44
|
+
console.log(`[UDP] ${message}`, ...args);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
40
47
|
getSocket() {
|
|
41
48
|
if (!this.socket) {
|
|
42
49
|
this.socket = this.createSocket(this.udpOptions.type);
|
|
@@ -75,6 +82,7 @@ export class UDPTransportImpl extends BaseUDPTransport {
|
|
|
75
82
|
return udpRequestStorage.run(context, async () => {
|
|
76
83
|
const fullUrl = this.baseUrl ? `${this.baseUrl}${req.url}` : req.url;
|
|
77
84
|
const { host, port, path } = this.parseUrl(fullUrl);
|
|
85
|
+
this.log(`Dispatch to ${fullUrl}`);
|
|
78
86
|
if (!host || !port) {
|
|
79
87
|
throw new Error(`Invalid UDP URL: ${fullUrl}. Expected format: udp://host:port/path`);
|
|
80
88
|
}
|
|
@@ -114,7 +122,8 @@ export class UDPTransportImpl extends BaseUDPTransport {
|
|
|
114
122
|
const responseBuffer = await this.sendWithRetry(socket, body, targetPort, targetAddress, req.signal);
|
|
115
123
|
const timings = this.collectTimings();
|
|
116
124
|
const connection = this.collectConnection(socket);
|
|
117
|
-
|
|
125
|
+
this.log(`Response received in ${timings.total.toFixed(0)}ms (${responseBuffer.length} bytes)`);
|
|
126
|
+
return new UDPResponseWrapper(responseBuffer, {
|
|
118
127
|
timings,
|
|
119
128
|
connection,
|
|
120
129
|
url: fullUrl,
|
|
@@ -183,12 +192,12 @@ export class UDPTransportImpl extends BaseUDPTransport {
|
|
|
183
192
|
}
|
|
184
193
|
}
|
|
185
194
|
}
|
|
186
|
-
export function
|
|
187
|
-
return new
|
|
195
|
+
export function createUDP(options = {}) {
|
|
196
|
+
return new UDPClient('', options);
|
|
188
197
|
}
|
|
189
198
|
export const udp = {
|
|
190
199
|
async send(address, data, options = {}) {
|
|
191
|
-
const transport = new
|
|
200
|
+
const transport = new UDPClient('', options);
|
|
192
201
|
try {
|
|
193
202
|
const response = await transport.dispatch({
|
|
194
203
|
url: address.startsWith('udp://') ? address : `udp://${address}`,
|
|
@@ -257,4 +266,4 @@ export const udp = {
|
|
|
257
266
|
});
|
|
258
267
|
},
|
|
259
268
|
};
|
|
260
|
-
export {
|
|
269
|
+
export { UDPClient as UDPTransport };
|
package/dist/types/udp.d.ts
CHANGED
package/dist/types/udp.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"udp.d.ts","sourceRoot":"","sources":["../../src/types/udp.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAS3E,MAAM,WAAW,UAAU;IAEzB,MAAM,EAAE,MAAM,CAAC;IAEf,IAAI,EAAE,MAAM,CAAC;IAEb,OAAO,EAAE,MAAM,CAAC;IAEhB,eAAe,EAAE,MAAM,CAAC;IAExB,KAAK,EAAE,MAAM,CAAC;CACf;AAKD,MAAM,WAAW,WAAY,SAAQ,UAAU;IAE7C,SAAS,EAAE,MAAM,CAAC;CACnB;AAKD,MAAM,WAAW,WAAY,SAAQ,UAAU;IAE7C,aAAa,EAAE,MAAM,CAAC;IAEtB,UAAU,EAAE,MAAM,CAAC;IAEnB,SAAS,EAAE,MAAM,CAAC;IAElB,OAAO,EAAE,OAAO,CAAC;CAClB;AASD,MAAM,WAAW,aAAa;IAE5B,QAAQ,EAAE,KAAK,GAAG,MAAM,GAAG,MAAM,CAAC;IAElC,YAAY,EAAE,MAAM,CAAC;IAErB,SAAS,EAAE,MAAM,CAAC;IAElB,aAAa,EAAE,MAAM,CAAC;IAEtB,UAAU,EAAE,MAAM,CAAC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C;IAKhD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AASD,MAAM,WAAW,cAAc,CAAC,CAAC;IAC/B,OAAO,EAAE,KAAK,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC;IAC1B,KAAK,EAAE;QACL,KAAK,EAAE,MAAM,CAAC;QACd,UAAU,EAAE,MAAM,CAAC;QACnB,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;CACH;AAKD,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAKD,MAAM,WAAW,YAAY;IAI3B,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IAKzF,SAAS,CACP,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,mBAAmB,GAAG;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,GACnD,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAAC;IAKjC,QAAQ,CACN,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,mBAAmB,GAAG;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,GACnD,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAAC;CAClC"}
|
package/dist/udp/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { UDPClient, UDPTransport, createUDP, udp } from '../transport/udp.js';
|
|
2
|
+
export { UDPResponseWrapper, StreamingUDPResponse } from '../transport/udp-response.js';
|
|
3
3
|
export { BaseUDPTransport, udpRequestStorage } from '../transport/base-udp.js';
|
|
4
4
|
export type { UDPRequestContext } from '../transport/base-udp.js';
|
|
5
5
|
export type { UDPTimings, DTLSTimings, QUICTimings, UDPConnection, DTLSConnection, QUICConnection, BaseUDPTransportOptions, UDPTransportOptions, DTLSTransportOptions, QUICTransportOptions, UDPRequestOptions, UDPRequest, UDPResponse, UDPTransport as UDPTransportInterface, DTLSTransportInterface, QUICTransportInterface, UDPBatchResult, UDPDiscoveryResult, SimpleUDPAPI, } from '../types/udp.js';
|
package/dist/udp/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/udp/index.ts"],"names":[],"mappings":"AAmCA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/udp/index.ts"],"names":[],"mappings":"AAmCA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAC;AAG9E,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAGxF,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC/E,YAAY,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAGlE,YAAY,EAEV,UAAU,EACV,WAAW,EACX,WAAW,EAEX,aAAa,EACb,cAAc,EACd,cAAc,EAEd,uBAAuB,EACvB,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EAEpB,iBAAiB,EACjB,UAAU,EACV,WAAW,EAEX,YAAY,IAAI,qBAAqB,EACrC,sBAAsB,EACtB,sBAAsB,EAEtB,cAAc,EACd,kBAAkB,EAClB,YAAY,GACb,MAAM,iBAAiB,CAAC"}
|
package/dist/udp/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { UDPClient, UDPTransport, createUDP, udp } from '../transport/udp.js';
|
|
2
|
+
export { UDPResponseWrapper, StreamingUDPResponse } from '../transport/udp-response.js';
|
|
3
3
|
export { BaseUDPTransport, udpRequestStorage } from '../transport/base-udp.js';
|
package/dist/utils/whois.d.ts
CHANGED
|
@@ -12,4 +12,22 @@ export interface WhoisResult {
|
|
|
12
12
|
}
|
|
13
13
|
export declare function whois(query: string, options?: WhoisOptions): Promise<WhoisResult>;
|
|
14
14
|
export declare function isDomainAvailable(domain: string, options?: WhoisOptions): Promise<boolean>;
|
|
15
|
+
export interface WhoisClientOptions {
|
|
16
|
+
server?: string;
|
|
17
|
+
port?: number;
|
|
18
|
+
timeout?: number;
|
|
19
|
+
follow?: boolean;
|
|
20
|
+
debug?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export declare class WhoisClient {
|
|
23
|
+
private options;
|
|
24
|
+
constructor(options?: WhoisClientOptions);
|
|
25
|
+
private log;
|
|
26
|
+
lookup(query: string, options?: WhoisOptions): Promise<WhoisResult>;
|
|
27
|
+
isAvailable(domain: string): Promise<boolean>;
|
|
28
|
+
getRegistrar(domain: string): Promise<string | null>;
|
|
29
|
+
getExpiration(domain: string): Promise<Date | null>;
|
|
30
|
+
getNameServers(domain: string): Promise<string[]>;
|
|
31
|
+
}
|
|
32
|
+
export declare function createWhois(options?: WhoisClientOptions): WhoisClient;
|
|
15
33
|
//# sourceMappingURL=whois.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"whois.d.ts","sourceRoot":"","sources":["../../src/utils/whois.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,YAAY;IAK3B,MAAM,CAAC,EAAE,MAAM,CAAC;IAKhB,IAAI,CAAC,EAAE,MAAM,CAAC;IAMd,OAAO,CAAC,EAAE,MAAM,CAAC;IAMjB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,WAAW;IAI1B,GAAG,EAAE,MAAM,CAAC;IAKZ,KAAK,EAAE,M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CAAC;CACjB;AAsBD,qBAAa,WAAW;IACtB,OAAO,CAAC,OAAO,CAA+B;gBAElC,OAAO,GAAE,kBAAuB;IAU5C,OAAO,CAAC,GAAG;IASL,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC;IAkBnE,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAa7C,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAUpD,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;IAgBnD,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;CAKxD;AAoBD,wBAAgB,WAAW,CAAC,OAAO,CAAC,EAAE,kBAAkB,GAAG,WAAW,CAErE"}
|
package/dist/utils/whois.js
CHANGED
|
@@ -181,3 +181,66 @@ export async function isDomainAvailable(domain, options) {
|
|
|
181
181
|
return false;
|
|
182
182
|
}
|
|
183
183
|
}
|
|
184
|
+
export class WhoisClient {
|
|
185
|
+
options;
|
|
186
|
+
constructor(options = {}) {
|
|
187
|
+
this.options = {
|
|
188
|
+
server: options.server ?? '',
|
|
189
|
+
port: options.port ?? 43,
|
|
190
|
+
timeout: options.timeout ?? 10000,
|
|
191
|
+
follow: options.follow ?? true,
|
|
192
|
+
debug: options.debug ?? false,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
log(message, ...args) {
|
|
196
|
+
if (this.options.debug) {
|
|
197
|
+
console.log(`[WHOIS] ${message}`, ...args);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
async lookup(query, options) {
|
|
201
|
+
this.log(`Looking up: ${query}`);
|
|
202
|
+
const start = Date.now();
|
|
203
|
+
const result = await whois(query, {
|
|
204
|
+
server: options?.server ?? (this.options.server || undefined),
|
|
205
|
+
port: options?.port ?? this.options.port,
|
|
206
|
+
timeout: options?.timeout ?? this.options.timeout,
|
|
207
|
+
follow: options?.follow ?? this.options.follow,
|
|
208
|
+
});
|
|
209
|
+
this.log(`Lookup completed in ${Date.now() - start}ms from ${result.server}`);
|
|
210
|
+
return result;
|
|
211
|
+
}
|
|
212
|
+
async isAvailable(domain) {
|
|
213
|
+
this.log(`Checking availability: ${domain}`);
|
|
214
|
+
return isDomainAvailable(domain, {
|
|
215
|
+
server: this.options.server || undefined,
|
|
216
|
+
port: this.options.port,
|
|
217
|
+
timeout: this.options.timeout,
|
|
218
|
+
follow: this.options.follow,
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
async getRegistrar(domain) {
|
|
222
|
+
const result = await this.lookup(domain);
|
|
223
|
+
return result.data['registrar'] ||
|
|
224
|
+
result.data['sponsoring registrar'] ||
|
|
225
|
+
null;
|
|
226
|
+
}
|
|
227
|
+
async getExpiration(domain) {
|
|
228
|
+
const result = await this.lookup(domain);
|
|
229
|
+
const expiry = result.data['registry expiry date'] ||
|
|
230
|
+
result.data['expiration date'] ||
|
|
231
|
+
result.data['expiry date'];
|
|
232
|
+
if (expiry) {
|
|
233
|
+
const date = new Date(expiry);
|
|
234
|
+
return isNaN(date.getTime()) ? null : date;
|
|
235
|
+
}
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
async getNameServers(domain) {
|
|
239
|
+
const result = await this.lookup(domain);
|
|
240
|
+
const ns = result.data['name server'] || result.data['nserver'] || [];
|
|
241
|
+
return Array.isArray(ns) ? ns : [ns];
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
export function createWhois(options) {
|
|
245
|
+
return new WhoisClient(options);
|
|
246
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
export interface IceServer {
|
|
3
|
+
urls: string | string[];
|
|
4
|
+
username?: string;
|
|
5
|
+
credential?: string;
|
|
6
|
+
}
|
|
7
|
+
export type SignalingMessageType = 'offer' | 'answer' | 'ice-candidate' | 'bye';
|
|
8
|
+
export interface SignalingMessage {
|
|
9
|
+
type: SignalingMessageType;
|
|
10
|
+
from: string;
|
|
11
|
+
to: string;
|
|
12
|
+
payload: RTCSessionDescriptionInit | RTCIceCandidateInit | null;
|
|
13
|
+
}
|
|
14
|
+
export interface SignalingChannelOptions {
|
|
15
|
+
send: (message: SignalingMessage) => void | Promise<void>;
|
|
16
|
+
onMessage: (handler: (message: SignalingMessage) => void) => void;
|
|
17
|
+
onClose?: (handler: () => void) => void;
|
|
18
|
+
}
|
|
19
|
+
export interface WebRTCClientOptions {
|
|
20
|
+
peerId?: string;
|
|
21
|
+
signaling: SignalingChannelOptions;
|
|
22
|
+
iceServers?: IceServer[];
|
|
23
|
+
dataChannelOptions?: RTCDataChannelInit;
|
|
24
|
+
connectionTimeout?: number;
|
|
25
|
+
debug?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export type ConnectionState = 'new' | 'connecting' | 'connected' | 'disconnected' | 'failed' | 'closed';
|
|
28
|
+
export interface PeerInfo {
|
|
29
|
+
peerId: string;
|
|
30
|
+
state: ConnectionState;
|
|
31
|
+
dataChannelState: RTCDataChannelState | 'none';
|
|
32
|
+
localCandidates: number;
|
|
33
|
+
remoteCandidates: number;
|
|
34
|
+
connectedAt?: Date;
|
|
35
|
+
}
|
|
36
|
+
export declare class SignalingChannel extends EventEmitter {
|
|
37
|
+
private options;
|
|
38
|
+
constructor(options: SignalingChannelOptions);
|
|
39
|
+
send(message: SignalingMessage): Promise<void>;
|
|
40
|
+
sendOffer(to: string, from: string, offer: RTCSessionDescriptionInit): Promise<void>;
|
|
41
|
+
sendAnswer(to: string, from: string, answer: RTCSessionDescriptionInit): Promise<void>;
|
|
42
|
+
sendIceCandidate(to: string, from: string, candidate: RTCIceCandidateInit): Promise<void>;
|
|
43
|
+
sendBye(to: string, from: string): Promise<void>;
|
|
44
|
+
}
|
|
45
|
+
export declare class WebRTCClient extends EventEmitter {
|
|
46
|
+
private peerId;
|
|
47
|
+
private signaling;
|
|
48
|
+
private iceServers;
|
|
49
|
+
private dataChannelOptions;
|
|
50
|
+
private connectionTimeout;
|
|
51
|
+
private debug;
|
|
52
|
+
private connections;
|
|
53
|
+
private dataChannels;
|
|
54
|
+
private pendingCandidates;
|
|
55
|
+
constructor(options: WebRTCClientOptions);
|
|
56
|
+
getPeerId(): string;
|
|
57
|
+
getPeerInfo(peerId: string): PeerInfo | null;
|
|
58
|
+
getConnectedPeers(): string[];
|
|
59
|
+
connect(remotePeerId: string): Promise<void>;
|
|
60
|
+
disconnect(remotePeerId: string): void;
|
|
61
|
+
disconnectAll(): void;
|
|
62
|
+
send(data: unknown, remotePeerId?: string): void;
|
|
63
|
+
sendBinary(data: ArrayBuffer | Uint8Array, remotePeerId?: string): void;
|
|
64
|
+
private generatePeerId;
|
|
65
|
+
private log;
|
|
66
|
+
private createPeerConnection;
|
|
67
|
+
private setupDataChannel;
|
|
68
|
+
private setupSignalingHandlers;
|
|
69
|
+
private addPendingCandidates;
|
|
70
|
+
private waitForConnection;
|
|
71
|
+
}
|
|
72
|
+
export declare const DEFAULT_ICE_SERVERS: IceServer[];
|
|
73
|
+
export declare function isWebRTCAvailable(): boolean;
|
|
74
|
+
export declare function getWebRTCSupport(): {
|
|
75
|
+
available: boolean;
|
|
76
|
+
dataChannels: boolean;
|
|
77
|
+
media: boolean;
|
|
78
|
+
environment: 'browser' | 'node' | 'unknown';
|
|
79
|
+
};
|
|
80
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/webrtc/index.ts"],"names":[],"mappings":"AAmCA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAS3C,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;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AC,IAAI,EAAE,OAAO,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI;IAsBhD,UAAU,CAAC,IAAI,EAAE,WAAW,GAAG,UAAU,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI;IAqBvE,OAAO,CAAC,cAAc;IAItB,OAAO,CAAC,GAAG;IAMX,OAAO,CAAC,oBAAoB;IA6C5B,OAAO,CAAC,gBAAgB;IAkCxB,OAAO,CAAC,sBAAsB;YAgEhB,oBAAoB;IAWlC,OAAO,CAAC,iBAAiB;CAgC1B;AASD,eAAO,MAAM,mBAAmB,EAAE,SAAS,EAM1C,CAAC;AAKF,wBAAgB,iBAAiB,IAAI,OAAO,CAE3C;AAKD,wBAAgB,gBAAgB,IAAI;IAClC,SAAS,EAAE,OAAO,CAAC;IACnB,YAAY,EAAE,OAAO,CAAC;IACtB,KAAK,EAAE,OAAO,CAAC;IACf,WAAW,EAAE,SAAS,GAAG,MAAM,GAAG,SAAS,CAAC;CAC7C,CAUA"}
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
export class SignalingChannel extends EventEmitter {
|
|
3
|
+
options;
|
|
4
|
+
constructor(options) {
|
|
5
|
+
super();
|
|
6
|
+
this.options = options;
|
|
7
|
+
this.options.onMessage((message) => {
|
|
8
|
+
this.emit('message', message);
|
|
9
|
+
this.emit(message.type, message);
|
|
10
|
+
});
|
|
11
|
+
if (this.options.onClose) {
|
|
12
|
+
this.options.onClose(() => {
|
|
13
|
+
this.emit('close');
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
async send(message) {
|
|
18
|
+
await this.options.send(message);
|
|
19
|
+
}
|
|
20
|
+
async sendOffer(to, from, offer) {
|
|
21
|
+
await this.send({ type: 'offer', from, to, payload: offer });
|
|
22
|
+
}
|
|
23
|
+
async sendAnswer(to, from, answer) {
|
|
24
|
+
await this.send({ type: 'answer', from, to, payload: answer });
|
|
25
|
+
}
|
|
26
|
+
async sendIceCandidate(to, from, candidate) {
|
|
27
|
+
await this.send({ type: 'ice-candidate', from, to, payload: candidate });
|
|
28
|
+
}
|
|
29
|
+
async sendBye(to, from) {
|
|
30
|
+
await this.send({ type: 'bye', from, to, payload: null });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export class WebRTCClient extends EventEmitter {
|
|
34
|
+
peerId;
|
|
35
|
+
signaling;
|
|
36
|
+
iceServers;
|
|
37
|
+
dataChannelOptions;
|
|
38
|
+
connectionTimeout;
|
|
39
|
+
debug;
|
|
40
|
+
connections = new Map();
|
|
41
|
+
dataChannels = new Map();
|
|
42
|
+
pendingCandidates = new Map();
|
|
43
|
+
constructor(options) {
|
|
44
|
+
super();
|
|
45
|
+
this.peerId = options.peerId || this.generatePeerId();
|
|
46
|
+
this.signaling = new SignalingChannel(options.signaling);
|
|
47
|
+
this.iceServers = options.iceServers || [
|
|
48
|
+
{ urls: 'stun:stun.l.google.com:19302' },
|
|
49
|
+
{ urls: 'stun:stun1.l.google.com:19302' },
|
|
50
|
+
];
|
|
51
|
+
this.dataChannelOptions = options.dataChannelOptions || {
|
|
52
|
+
ordered: true,
|
|
53
|
+
};
|
|
54
|
+
this.connectionTimeout = options.connectionTimeout || 30000;
|
|
55
|
+
this.debug = options.debug || false;
|
|
56
|
+
this.setupSignalingHandlers();
|
|
57
|
+
}
|
|
58
|
+
getPeerId() {
|
|
59
|
+
return this.peerId;
|
|
60
|
+
}
|
|
61
|
+
getPeerInfo(peerId) {
|
|
62
|
+
const pc = this.connections.get(peerId);
|
|
63
|
+
const dc = this.dataChannels.get(peerId);
|
|
64
|
+
if (!pc)
|
|
65
|
+
return null;
|
|
66
|
+
return {
|
|
67
|
+
peerId,
|
|
68
|
+
state: pc.connectionState,
|
|
69
|
+
dataChannelState: dc?.readyState || 'none',
|
|
70
|
+
localCandidates: 0,
|
|
71
|
+
remoteCandidates: 0,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
getConnectedPeers() {
|
|
75
|
+
return Array.from(this.connections.keys()).filter((peerId) => {
|
|
76
|
+
const pc = this.connections.get(peerId);
|
|
77
|
+
return pc?.connectionState === 'connected';
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
async connect(remotePeerId) {
|
|
81
|
+
if (this.connections.has(remotePeerId)) {
|
|
82
|
+
throw new Error(`Already connected to peer: ${remotePeerId}`);
|
|
83
|
+
}
|
|
84
|
+
this.log(`Connecting to peer: ${remotePeerId}`);
|
|
85
|
+
const pc = this.createPeerConnection(remotePeerId);
|
|
86
|
+
const dc = pc.createDataChannel('data', this.dataChannelOptions);
|
|
87
|
+
this.setupDataChannel(remotePeerId, dc);
|
|
88
|
+
const offer = await pc.createOffer();
|
|
89
|
+
await pc.setLocalDescription(offer);
|
|
90
|
+
await this.signaling.sendOffer(remotePeerId, this.peerId, offer);
|
|
91
|
+
await this.waitForConnection(remotePeerId);
|
|
92
|
+
}
|
|
93
|
+
disconnect(remotePeerId) {
|
|
94
|
+
this.log(`Disconnecting from peer: ${remotePeerId}`);
|
|
95
|
+
const dc = this.dataChannels.get(remotePeerId);
|
|
96
|
+
if (dc) {
|
|
97
|
+
dc.close();
|
|
98
|
+
this.dataChannels.delete(remotePeerId);
|
|
99
|
+
}
|
|
100
|
+
const pc = this.connections.get(remotePeerId);
|
|
101
|
+
if (pc) {
|
|
102
|
+
pc.close();
|
|
103
|
+
this.connections.delete(remotePeerId);
|
|
104
|
+
}
|
|
105
|
+
this.pendingCandidates.delete(remotePeerId);
|
|
106
|
+
this.signaling.sendBye(remotePeerId, this.peerId).catch(() => { });
|
|
107
|
+
this.emit('disconnected', remotePeerId);
|
|
108
|
+
}
|
|
109
|
+
disconnectAll() {
|
|
110
|
+
for (const peerId of this.connections.keys()) {
|
|
111
|
+
this.disconnect(peerId);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
send(data, remotePeerId) {
|
|
115
|
+
const message = typeof data === 'string' ? data : JSON.stringify(data);
|
|
116
|
+
if (remotePeerId) {
|
|
117
|
+
const dc = this.dataChannels.get(remotePeerId);
|
|
118
|
+
if (!dc || dc.readyState !== 'open') {
|
|
119
|
+
throw new Error(`No open data channel to peer: ${remotePeerId}`);
|
|
120
|
+
}
|
|
121
|
+
dc.send(message);
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
for (const [peerId, dc] of this.dataChannels) {
|
|
125
|
+
if (dc.readyState === 'open') {
|
|
126
|
+
dc.send(message);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
sendBinary(data, remotePeerId) {
|
|
132
|
+
if (remotePeerId) {
|
|
133
|
+
const dc = this.dataChannels.get(remotePeerId);
|
|
134
|
+
if (!dc || dc.readyState !== 'open') {
|
|
135
|
+
throw new Error(`No open data channel to peer: ${remotePeerId}`);
|
|
136
|
+
}
|
|
137
|
+
dc.send(data);
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
for (const [, dc] of this.dataChannels) {
|
|
141
|
+
if (dc.readyState === 'open') {
|
|
142
|
+
dc.send(data);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
generatePeerId() {
|
|
148
|
+
return `peer-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
|
|
149
|
+
}
|
|
150
|
+
log(message, ...args) {
|
|
151
|
+
if (this.debug) {
|
|
152
|
+
console.log(`[WebRTC:${this.peerId}] ${message}`, ...args);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
createPeerConnection(remotePeerId) {
|
|
156
|
+
if (typeof RTCPeerConnection === 'undefined') {
|
|
157
|
+
throw new Error('RTCPeerConnection is not available. ' +
|
|
158
|
+
'In Node.js, install the "wrtc" package and ensure it\'s loaded before using WebRTC.');
|
|
159
|
+
}
|
|
160
|
+
const pc = new RTCPeerConnection({
|
|
161
|
+
iceServers: this.iceServers,
|
|
162
|
+
});
|
|
163
|
+
this.connections.set(remotePeerId, pc);
|
|
164
|
+
this.pendingCandidates.set(remotePeerId, []);
|
|
165
|
+
pc.onicecandidate = (event) => {
|
|
166
|
+
if (event.candidate) {
|
|
167
|
+
this.signaling.sendIceCandidate(remotePeerId, this.peerId, event.candidate.toJSON());
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
pc.onconnectionstatechange = () => {
|
|
171
|
+
this.log(`Connection state with ${remotePeerId}: ${pc.connectionState}`);
|
|
172
|
+
this.emit('connectionStateChange', remotePeerId, pc.connectionState);
|
|
173
|
+
if (pc.connectionState === 'connected') {
|
|
174
|
+
this.emit('connected', remotePeerId);
|
|
175
|
+
}
|
|
176
|
+
else if (pc.connectionState === 'disconnected' || pc.connectionState === 'failed') {
|
|
177
|
+
this.emit('disconnected', remotePeerId);
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
pc.ondatachannel = (event) => {
|
|
181
|
+
this.log(`Received data channel from ${remotePeerId}`);
|
|
182
|
+
this.setupDataChannel(remotePeerId, event.channel);
|
|
183
|
+
};
|
|
184
|
+
return pc;
|
|
185
|
+
}
|
|
186
|
+
setupDataChannel(remotePeerId, dc) {
|
|
187
|
+
this.dataChannels.set(remotePeerId, dc);
|
|
188
|
+
dc.onopen = () => {
|
|
189
|
+
this.log(`Data channel opened with ${remotePeerId}`);
|
|
190
|
+
this.emit('dataChannelOpen', remotePeerId);
|
|
191
|
+
};
|
|
192
|
+
dc.onclose = () => {
|
|
193
|
+
this.log(`Data channel closed with ${remotePeerId}`);
|
|
194
|
+
this.emit('dataChannelClose', remotePeerId);
|
|
195
|
+
};
|
|
196
|
+
dc.onerror = (error) => {
|
|
197
|
+
this.log(`Data channel error with ${remotePeerId}:`, error);
|
|
198
|
+
this.emit('error', error, remotePeerId);
|
|
199
|
+
};
|
|
200
|
+
dc.onmessage = (event) => {
|
|
201
|
+
let data = event.data;
|
|
202
|
+
if (typeof data === 'string') {
|
|
203
|
+
try {
|
|
204
|
+
data = JSON.parse(data);
|
|
205
|
+
}
|
|
206
|
+
catch {
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
this.emit('data', data, remotePeerId);
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
setupSignalingHandlers() {
|
|
213
|
+
this.signaling.on('offer', async (message) => {
|
|
214
|
+
if (message.to !== this.peerId)
|
|
215
|
+
return;
|
|
216
|
+
this.log(`Received offer from ${message.from}`);
|
|
217
|
+
const pc = this.createPeerConnection(message.from);
|
|
218
|
+
await pc.setRemoteDescription(message.payload);
|
|
219
|
+
await this.addPendingCandidates(message.from);
|
|
220
|
+
const answer = await pc.createAnswer();
|
|
221
|
+
await pc.setLocalDescription(answer);
|
|
222
|
+
await this.signaling.sendAnswer(message.from, this.peerId, answer);
|
|
223
|
+
});
|
|
224
|
+
this.signaling.on('answer', async (message) => {
|
|
225
|
+
if (message.to !== this.peerId)
|
|
226
|
+
return;
|
|
227
|
+
this.log(`Received answer from ${message.from}`);
|
|
228
|
+
const pc = this.connections.get(message.from);
|
|
229
|
+
if (!pc) {
|
|
230
|
+
this.log(`No connection found for ${message.from}`);
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
await pc.setRemoteDescription(message.payload);
|
|
234
|
+
await this.addPendingCandidates(message.from);
|
|
235
|
+
});
|
|
236
|
+
this.signaling.on('ice-candidate', async (message) => {
|
|
237
|
+
if (message.to !== this.peerId)
|
|
238
|
+
return;
|
|
239
|
+
const pc = this.connections.get(message.from);
|
|
240
|
+
if (pc && pc.remoteDescription) {
|
|
241
|
+
await pc.addIceCandidate(message.payload);
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
const pending = this.pendingCandidates.get(message.from) || [];
|
|
245
|
+
pending.push(message.payload);
|
|
246
|
+
this.pendingCandidates.set(message.from, pending);
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
this.signaling.on('bye', (message) => {
|
|
250
|
+
if (message.to !== this.peerId)
|
|
251
|
+
return;
|
|
252
|
+
this.log(`Received bye from ${message.from}`);
|
|
253
|
+
this.disconnect(message.from);
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
async addPendingCandidates(remotePeerId) {
|
|
257
|
+
const pc = this.connections.get(remotePeerId);
|
|
258
|
+
const candidates = this.pendingCandidates.get(remotePeerId) || [];
|
|
259
|
+
for (const candidate of candidates) {
|
|
260
|
+
await pc?.addIceCandidate(candidate);
|
|
261
|
+
}
|
|
262
|
+
this.pendingCandidates.set(remotePeerId, []);
|
|
263
|
+
}
|
|
264
|
+
waitForConnection(remotePeerId) {
|
|
265
|
+
return new Promise((resolve, reject) => {
|
|
266
|
+
const timeout = setTimeout(() => {
|
|
267
|
+
reject(new Error(`Connection timeout to peer: ${remotePeerId}`));
|
|
268
|
+
}, this.connectionTimeout);
|
|
269
|
+
const checkConnection = () => {
|
|
270
|
+
const dc = this.dataChannels.get(remotePeerId);
|
|
271
|
+
if (dc?.readyState === 'open') {
|
|
272
|
+
clearTimeout(timeout);
|
|
273
|
+
resolve();
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
this.on('dataChannelOpen', (peerId) => {
|
|
277
|
+
if (peerId === remotePeerId) {
|
|
278
|
+
clearTimeout(timeout);
|
|
279
|
+
resolve();
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
this.on('disconnected', (peerId) => {
|
|
283
|
+
if (peerId === remotePeerId) {
|
|
284
|
+
clearTimeout(timeout);
|
|
285
|
+
reject(new Error(`Connection failed to peer: ${remotePeerId}`));
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
checkConnection();
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
export const DEFAULT_ICE_SERVERS = [
|
|
293
|
+
{ urls: 'stun:stun.l.google.com:19302' },
|
|
294
|
+
{ urls: 'stun:stun1.l.google.com:19302' },
|
|
295
|
+
{ urls: 'stun:stun2.l.google.com:19302' },
|
|
296
|
+
{ urls: 'stun:stun3.l.google.com:19302' },
|
|
297
|
+
{ urls: 'stun:stun4.l.google.com:19302' },
|
|
298
|
+
];
|
|
299
|
+
export function isWebRTCAvailable() {
|
|
300
|
+
return typeof RTCPeerConnection !== 'undefined';
|
|
301
|
+
}
|
|
302
|
+
export function getWebRTCSupport() {
|
|
303
|
+
const isBrowser = typeof window !== 'undefined';
|
|
304
|
+
const isNode = typeof process !== 'undefined' && process.versions?.node;
|
|
305
|
+
return {
|
|
306
|
+
available: typeof RTCPeerConnection !== 'undefined',
|
|
307
|
+
dataChannels: typeof RTCPeerConnection !== 'undefined',
|
|
308
|
+
media: typeof navigator !== 'undefined' && !!navigator.mediaDevices,
|
|
309
|
+
environment: isBrowser ? 'browser' : isNode ? 'node' : 'unknown',
|
|
310
|
+
};
|
|
311
|
+
}
|
|
@@ -62,5 +62,5 @@ export declare class ReckerWebSocket extends EventEmitter {
|
|
|
62
62
|
private getBufferedAmount;
|
|
63
63
|
private waitForDrain;
|
|
64
64
|
}
|
|
65
|
-
export declare function
|
|
65
|
+
export declare function createWebSocket(url: string, options?: WebSocketOptions): ReckerWebSocket;
|
|
66
66
|
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/websocket/client.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAKvC,MAAM,WAAW,gBAAgB;IAI/B,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAK9B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAKjC,UAAU,CAAC,EAAE,UAAU,CAAC;IAKxB,KA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,IAAI,CAAC;IA4BtI,UAAU,CAAC,MAAM,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE;QAAE,UAAU,CAAC,EAAE,OAAO,CAAC;QAAC,aAAa,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAS7G,QAAQ,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI;IAOzB,KAAK,CAAC,IAAI,SAAO,EAAE,MAAM,SAAK,GAAG,IAAI;IAgBrC,IAAI,IAAI,IAAI;IAwBZ,IAAI,UAAU,IAAI,MAAM,CAEvB;IAKD,IAAI,WAAW,IAAI,OAAO,CAEzB;IAMD,UAAU,IAAI,QAAQ,GAAG,IAAI;IAavB,QAAQ,CAAC,MAAM,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE;QAAE,UAAU,CAAC,EAAE,OAAO,CAAC;QAAC,aAAa,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAOrG,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAoBxD,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,cAAc,CAAC,gBAAgB,CAAC;IAoDjE,OAAO,CAAC,gBAAgB;IAuBxB,OAAO,CAAC,mBAAmB;IAO3B,OAAO,CAAC,cAAc;IAWtB,OAAO,CAAC,aAAa;IAQrB,OAAO,CAAC,iBAAiB;IAYzB,OAAO,CAAC,gBAAgB;IAOxB,OAAO,CAAC,iBAAiB;YAKX,YAAY;CAgB3B;AAuBD,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,eAAe,CAMxF"}
|
package/dist/websocket/client.js
CHANGED
|
@@ -304,7 +304,7 @@ export class ReckerWebSocket extends EventEmitter {
|
|
|
304
304
|
});
|
|
305
305
|
}
|
|
306
306
|
}
|
|
307
|
-
export function
|
|
307
|
+
export function createWebSocket(url, options) {
|
|
308
308
|
const ws = new ReckerWebSocket(url, options);
|
|
309
309
|
ws.connect().catch(() => {
|
|
310
310
|
});
|