@rookdaemon/agora 0.2.0 → 0.2.2
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/dist/config.d.ts +18 -5
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +63 -22
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/service.d.ts +82 -0
- package/dist/service.d.ts.map +1 -0
- package/dist/service.js +132 -0
- package/dist/service.js.map +1 -0
- package/dist/utils.d.ts +10 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +12 -0
- package/dist/utils.js.map +1 -0
- package/package.json +1 -1
package/dist/config.d.ts
CHANGED
|
@@ -16,15 +16,20 @@ export interface AgoraPeerConfig {
|
|
|
16
16
|
token: string;
|
|
17
17
|
name?: string;
|
|
18
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Identity with optional display name (e.g. for relay registration).
|
|
21
|
+
*/
|
|
22
|
+
export interface AgoraIdentity {
|
|
23
|
+
publicKey: string;
|
|
24
|
+
privateKey: string;
|
|
25
|
+
name?: string;
|
|
26
|
+
}
|
|
19
27
|
/**
|
|
20
28
|
* Canonical Agora configuration shape.
|
|
21
29
|
* Use loadAgoraConfig() to load from file with normalized relay.
|
|
22
30
|
*/
|
|
23
31
|
export interface AgoraConfig {
|
|
24
|
-
identity:
|
|
25
|
-
publicKey: string;
|
|
26
|
-
privateKey: string;
|
|
27
|
-
};
|
|
32
|
+
identity: AgoraIdentity;
|
|
28
33
|
peers: Record<string, AgoraPeerConfig>;
|
|
29
34
|
relay?: RelayConfig;
|
|
30
35
|
}
|
|
@@ -33,7 +38,7 @@ export interface AgoraConfig {
|
|
|
33
38
|
*/
|
|
34
39
|
export declare function getDefaultConfigPath(): string;
|
|
35
40
|
/**
|
|
36
|
-
* Load and normalize Agora configuration from a JSON file.
|
|
41
|
+
* Load and normalize Agora configuration from a JSON file (sync).
|
|
37
42
|
* Supports relay as string (backward compat) or object { url?, autoConnect?, name?, reconnectMaxMs? }.
|
|
38
43
|
*
|
|
39
44
|
* @param path - Config file path; defaults to getDefaultConfigPath()
|
|
@@ -41,4 +46,12 @@ export declare function getDefaultConfigPath(): string;
|
|
|
41
46
|
* @throws Error if file doesn't exist or config is invalid
|
|
42
47
|
*/
|
|
43
48
|
export declare function loadAgoraConfig(path?: string): AgoraConfig;
|
|
49
|
+
/**
|
|
50
|
+
* Load and normalize Agora configuration from a JSON file (async).
|
|
51
|
+
*
|
|
52
|
+
* @param path - Config file path; defaults to getDefaultConfigPath()
|
|
53
|
+
* @returns Normalized AgoraConfig
|
|
54
|
+
* @throws Error if file doesn't exist or config is invalid
|
|
55
|
+
*/
|
|
56
|
+
export declare function loadAgoraConfigAsync(path?: string): Promise<AgoraConfig>;
|
|
44
57
|
//# sourceMappingURL=config.d.ts.map
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,EAAE,OAAO,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,aAAa,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IACvC,KAAK,CAAC,EAAE,WAAW,CAAC;CACrB;AAED;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,CAK7C;AAsDD;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,WAAW,CAgB1D;AAED;;;;;;GAMG;AACH,wBAAsB,oBAAoB,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAsB9E"}
|
package/dist/config.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { readFileSync, existsSync } from 'node:fs';
|
|
2
|
+
import { readFile } from 'node:fs/promises';
|
|
2
3
|
import { resolve } from 'node:path';
|
|
3
4
|
import { homedir } from 'node:os';
|
|
4
5
|
/**
|
|
@@ -11,30 +12,18 @@ export function getDefaultConfigPath() {
|
|
|
11
12
|
return resolve(homedir(), '.config', 'agora', 'config.json');
|
|
12
13
|
}
|
|
13
14
|
/**
|
|
14
|
-
*
|
|
15
|
-
* Supports relay as string (backward compat) or object { url?, autoConnect?, name?, reconnectMaxMs? }.
|
|
16
|
-
*
|
|
17
|
-
* @param path - Config file path; defaults to getDefaultConfigPath()
|
|
18
|
-
* @returns Normalized AgoraConfig
|
|
19
|
-
* @throws Error if file doesn't exist or config is invalid
|
|
15
|
+
* Parse and normalize config from a JSON object (shared by sync and async loaders).
|
|
20
16
|
*/
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
if (!
|
|
24
|
-
throw new Error(`Config file not found at ${configPath}. Run 'npx @rookdaemon/agora init' first.`);
|
|
25
|
-
}
|
|
26
|
-
const content = readFileSync(configPath, 'utf-8');
|
|
27
|
-
let config;
|
|
28
|
-
try {
|
|
29
|
-
config = JSON.parse(content);
|
|
30
|
-
}
|
|
31
|
-
catch {
|
|
32
|
-
throw new Error(`Invalid JSON in config file: ${configPath}`);
|
|
33
|
-
}
|
|
34
|
-
const identity = config.identity;
|
|
35
|
-
if (!identity?.publicKey || !identity?.privateKey) {
|
|
17
|
+
function parseConfig(config) {
|
|
18
|
+
const rawIdentity = config.identity;
|
|
19
|
+
if (!rawIdentity?.publicKey || !rawIdentity?.privateKey) {
|
|
36
20
|
throw new Error('Invalid config: missing identity.publicKey or identity.privateKey');
|
|
37
21
|
}
|
|
22
|
+
const identity = {
|
|
23
|
+
publicKey: rawIdentity.publicKey,
|
|
24
|
+
privateKey: rawIdentity.privateKey,
|
|
25
|
+
name: typeof rawIdentity.name === 'string' ? rawIdentity.name : undefined,
|
|
26
|
+
};
|
|
38
27
|
const peers = {};
|
|
39
28
|
if (config.peers && typeof config.peers === 'object') {
|
|
40
29
|
for (const [name, entry] of Object.entries(config.peers)) {
|
|
@@ -66,9 +55,61 @@ export function loadAgoraConfig(path) {
|
|
|
66
55
|
}
|
|
67
56
|
}
|
|
68
57
|
return {
|
|
69
|
-
identity
|
|
58
|
+
identity,
|
|
70
59
|
peers,
|
|
71
60
|
...(relay ? { relay } : {}),
|
|
72
61
|
};
|
|
73
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Load and normalize Agora configuration from a JSON file (sync).
|
|
65
|
+
* Supports relay as string (backward compat) or object { url?, autoConnect?, name?, reconnectMaxMs? }.
|
|
66
|
+
*
|
|
67
|
+
* @param path - Config file path; defaults to getDefaultConfigPath()
|
|
68
|
+
* @returns Normalized AgoraConfig
|
|
69
|
+
* @throws Error if file doesn't exist or config is invalid
|
|
70
|
+
*/
|
|
71
|
+
export function loadAgoraConfig(path) {
|
|
72
|
+
const configPath = path ?? getDefaultConfigPath();
|
|
73
|
+
if (!existsSync(configPath)) {
|
|
74
|
+
throw new Error(`Config file not found at ${configPath}. Run 'npx @rookdaemon/agora init' first.`);
|
|
75
|
+
}
|
|
76
|
+
const content = readFileSync(configPath, 'utf-8');
|
|
77
|
+
let config;
|
|
78
|
+
try {
|
|
79
|
+
config = JSON.parse(content);
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
throw new Error(`Invalid JSON in config file: ${configPath}`);
|
|
83
|
+
}
|
|
84
|
+
return parseConfig(config);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Load and normalize Agora configuration from a JSON file (async).
|
|
88
|
+
*
|
|
89
|
+
* @param path - Config file path; defaults to getDefaultConfigPath()
|
|
90
|
+
* @returns Normalized AgoraConfig
|
|
91
|
+
* @throws Error if file doesn't exist or config is invalid
|
|
92
|
+
*/
|
|
93
|
+
export async function loadAgoraConfigAsync(path) {
|
|
94
|
+
const configPath = path ?? getDefaultConfigPath();
|
|
95
|
+
let content;
|
|
96
|
+
try {
|
|
97
|
+
content = await readFile(configPath, 'utf-8');
|
|
98
|
+
}
|
|
99
|
+
catch (err) {
|
|
100
|
+
const code = err && typeof err === 'object' && 'code' in err ? err.code : undefined;
|
|
101
|
+
if (code === 'ENOENT') {
|
|
102
|
+
throw new Error(`Config file not found at ${configPath}. Run 'npx @rookdaemon/agora init' first.`);
|
|
103
|
+
}
|
|
104
|
+
throw err;
|
|
105
|
+
}
|
|
106
|
+
let config;
|
|
107
|
+
try {
|
|
108
|
+
config = JSON.parse(content);
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
throw new Error(`Invalid JSON in config file: ${configPath}`);
|
|
112
|
+
}
|
|
113
|
+
return parseConfig(config);
|
|
114
|
+
}
|
|
74
115
|
//# sourceMappingURL=config.js.map
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,OAAO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AC,CAAE,GAA6B,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;QAC/G,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CAAC,4BAA4B,UAAU,2CAA2C,CAAC,CAAC;QACrG,CAAC;QACD,MAAM,GAAG,CAAC;IACZ,CAAC;IAED,IAAI,MAA+B,CAAC;IACpC,IAAI,CAAC;QACH,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAA4B,CAAC;IAC1D,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,KAAK,CAAC,gCAAgC,UAAU,EAAE,CAAC,CAAC;IAChE,CAAC;IAED,OAAO,WAAW,CAAC,MAAM,CAAC,CAAC;AAC7B,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -13,6 +13,8 @@ export * from './config.js';
|
|
|
13
13
|
export * from './relay/server.js';
|
|
14
14
|
export * from './relay/client.js';
|
|
15
15
|
export * from './relay/types.js';
|
|
16
|
+
export * from './utils.js';
|
|
17
|
+
export * from './service.js';
|
|
16
18
|
export * from './discovery/peer-discovery.js';
|
|
17
19
|
export * from './discovery/bootstrap.js';
|
|
18
20
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,iCAAiC,CAAC;AAChD,cAAc,oCAAoC,CAAC;AACnD,cAAc,mCAAmC,CAAC;AAClD,cAAc,qBAAqB,CAAC;AACpC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,0BAA0B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,iCAAiC,CAAC;AAChD,cAAc,oCAAoC,CAAC;AACnD,cAAc,mCAAmC,CAAC;AAClD,cAAc,qBAAqB,CAAC;AACpC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,+BAA+B,CAAC;AAC9C,cAAc,0BAA0B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -13,6 +13,8 @@ export * from './config.js';
|
|
|
13
13
|
export * from './relay/server.js';
|
|
14
14
|
export * from './relay/client.js';
|
|
15
15
|
export * from './relay/types.js';
|
|
16
|
+
export * from './utils.js';
|
|
17
|
+
export * from './service.js';
|
|
16
18
|
export * from './discovery/peer-discovery.js';
|
|
17
19
|
export * from './discovery/bootstrap.js';
|
|
18
20
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,iCAAiC,CAAC;AAChD,cAAc,oCAAoC,CAAC;AACnD,cAAc,mCAAmC,CAAC;AAClD,cAAc,qBAAqB,CAAC;AACpC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,0BAA0B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,iCAAiC,CAAC;AAChD,cAAc,oCAAoC,CAAC;AACnD,cAAc,mCAAmC,CAAC;AAClD,cAAc,qBAAqB,CAAC;AACpC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,+BAA+B,CAAC;AAC9C,cAAc,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { AgoraIdentity, RelayConfig } from './config.js';
|
|
2
|
+
import type { Envelope } from './message/envelope.js';
|
|
3
|
+
import type { MessageType } from './message/envelope.js';
|
|
4
|
+
import type { PeerConfig } from './transport/http.js';
|
|
5
|
+
/**
|
|
6
|
+
* Service config: identity, peers keyed by name, optional relay.
|
|
7
|
+
*/
|
|
8
|
+
export interface AgoraServiceConfig {
|
|
9
|
+
identity: AgoraIdentity;
|
|
10
|
+
peers: Map<string, PeerConfig>;
|
|
11
|
+
relay?: RelayConfig;
|
|
12
|
+
}
|
|
13
|
+
export interface SendMessageOptions {
|
|
14
|
+
peerName: string;
|
|
15
|
+
type: MessageType;
|
|
16
|
+
payload: unknown;
|
|
17
|
+
inReplyTo?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface SendMessageResult {
|
|
20
|
+
ok: boolean;
|
|
21
|
+
status: number;
|
|
22
|
+
error?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface DecodeInboundResult {
|
|
25
|
+
ok: boolean;
|
|
26
|
+
envelope?: Envelope;
|
|
27
|
+
reason?: string;
|
|
28
|
+
}
|
|
29
|
+
export type RelayMessageHandler = (envelope: Envelope) => void;
|
|
30
|
+
export interface Logger {
|
|
31
|
+
debug(message: string): void;
|
|
32
|
+
}
|
|
33
|
+
export interface RelayClientLike {
|
|
34
|
+
connect(): Promise<void>;
|
|
35
|
+
disconnect(): void;
|
|
36
|
+
connected(): boolean;
|
|
37
|
+
on(event: 'message', handler: (envelope: Envelope, from: string, fromName?: string) => void): void;
|
|
38
|
+
on(event: 'error', handler: (error: Error) => void): void;
|
|
39
|
+
}
|
|
40
|
+
export interface RelayClientFactory {
|
|
41
|
+
(opts: {
|
|
42
|
+
relayUrl: string;
|
|
43
|
+
publicKey: string;
|
|
44
|
+
privateKey: string;
|
|
45
|
+
name?: string;
|
|
46
|
+
pingInterval: number;
|
|
47
|
+
maxReconnectDelay: number;
|
|
48
|
+
}): RelayClientLike;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* High-level Agora service: send by peer name, decode inbound, relay lifecycle.
|
|
52
|
+
*/
|
|
53
|
+
export declare class AgoraService {
|
|
54
|
+
private config;
|
|
55
|
+
private relayClient;
|
|
56
|
+
private relayMessageHandler;
|
|
57
|
+
private logger;
|
|
58
|
+
private relayClientFactory;
|
|
59
|
+
constructor(config: AgoraServiceConfig, logger?: Logger, relayClientFactory?: RelayClientFactory);
|
|
60
|
+
/**
|
|
61
|
+
* Send a signed message to a named peer.
|
|
62
|
+
*/
|
|
63
|
+
sendMessage(options: SendMessageOptions): Promise<SendMessageResult>;
|
|
64
|
+
/**
|
|
65
|
+
* Decode and verify an inbound envelope from a webhook message.
|
|
66
|
+
*/
|
|
67
|
+
decodeInbound(message: string): Promise<DecodeInboundResult>;
|
|
68
|
+
getPeers(): string[];
|
|
69
|
+
getPeerConfig(name: string): PeerConfig | undefined;
|
|
70
|
+
/**
|
|
71
|
+
* Connect to the relay server.
|
|
72
|
+
*/
|
|
73
|
+
connectRelay(url: string): Promise<void>;
|
|
74
|
+
setRelayMessageHandler(handler: RelayMessageHandler): void;
|
|
75
|
+
disconnectRelay(): Promise<void>;
|
|
76
|
+
isRelayConnected(): boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Load Agora configuration and return service config (peers as Map).
|
|
79
|
+
*/
|
|
80
|
+
static loadConfig(path?: string): Promise<AgoraServiceConfig>;
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE9D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAGtD;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,aAAa,CAAC;IACxB,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAC/B,KAAK,CAAC,EAAE,WAAW,CAAC;CACrB;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,CAAC,EAA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CAAC,mBAAmB,CAAoC;IAC/D,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,kBAAkB,CAA4B;gBAGpD,MAAM,EAAE,kBAAkB,EAC1B,MAAM,CAAC,EAAE,MAAM,EACf,kBAAkB,CAAC,EAAE,kBAAkB;IAOzC;;OAEG;IACG,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IA2B1E;;OAEG;IACG,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAYlE,QAAQ,IAAI,MAAM,EAAE;IAIpB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS;IAInD;;OAEG;IACG,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAyC9C,sBAAsB,CAAC,OAAO,EAAE,mBAAmB,GAAG,IAAI;IAIpD,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC;IAOtC,gBAAgB,IAAI,OAAO;IAI3B;;OAEG;WACU,UAAU,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC;CAmBpE"}
|
package/dist/service.js
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { getDefaultConfigPath, loadAgoraConfigAsync } from './config.js';
|
|
2
|
+
import { RelayClient } from './relay/client.js';
|
|
3
|
+
import { decodeInboundEnvelope, sendToPeer } from './transport/http.js';
|
|
4
|
+
/**
|
|
5
|
+
* High-level Agora service: send by peer name, decode inbound, relay lifecycle.
|
|
6
|
+
*/
|
|
7
|
+
export class AgoraService {
|
|
8
|
+
config;
|
|
9
|
+
relayClient = null;
|
|
10
|
+
relayMessageHandler = null;
|
|
11
|
+
logger;
|
|
12
|
+
relayClientFactory;
|
|
13
|
+
constructor(config, logger, relayClientFactory) {
|
|
14
|
+
this.config = config;
|
|
15
|
+
this.logger = logger ?? null;
|
|
16
|
+
this.relayClientFactory = relayClientFactory ?? null;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Send a signed message to a named peer.
|
|
20
|
+
*/
|
|
21
|
+
async sendMessage(options) {
|
|
22
|
+
const peer = this.config.peers.get(options.peerName);
|
|
23
|
+
if (!peer) {
|
|
24
|
+
return {
|
|
25
|
+
ok: false,
|
|
26
|
+
status: 0,
|
|
27
|
+
error: `Unknown peer: ${options.peerName}`,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
const transportConfig = {
|
|
31
|
+
identity: {
|
|
32
|
+
publicKey: this.config.identity.publicKey,
|
|
33
|
+
privateKey: this.config.identity.privateKey,
|
|
34
|
+
},
|
|
35
|
+
peers: new Map([[peer.publicKey, peer]]),
|
|
36
|
+
};
|
|
37
|
+
return sendToPeer(transportConfig, peer.publicKey, options.type, options.payload, options.inReplyTo);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Decode and verify an inbound envelope from a webhook message.
|
|
41
|
+
*/
|
|
42
|
+
async decodeInbound(message) {
|
|
43
|
+
const peersByPubKey = new Map();
|
|
44
|
+
for (const peer of this.config.peers.values()) {
|
|
45
|
+
peersByPubKey.set(peer.publicKey, peer);
|
|
46
|
+
}
|
|
47
|
+
const result = decodeInboundEnvelope(message, peersByPubKey);
|
|
48
|
+
if (result.ok) {
|
|
49
|
+
return { ok: true, envelope: result.envelope };
|
|
50
|
+
}
|
|
51
|
+
return { ok: false, reason: result.reason };
|
|
52
|
+
}
|
|
53
|
+
getPeers() {
|
|
54
|
+
return Array.from(this.config.peers.keys());
|
|
55
|
+
}
|
|
56
|
+
getPeerConfig(name) {
|
|
57
|
+
return this.config.peers.get(name);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Connect to the relay server.
|
|
61
|
+
*/
|
|
62
|
+
async connectRelay(url) {
|
|
63
|
+
if (this.relayClient) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const maxReconnectDelay = this.config.relay?.reconnectMaxMs ?? 300000;
|
|
67
|
+
const name = this.config.identity.name ?? this.config.relay?.name;
|
|
68
|
+
const opts = {
|
|
69
|
+
relayUrl: url,
|
|
70
|
+
publicKey: this.config.identity.publicKey,
|
|
71
|
+
privateKey: this.config.identity.privateKey,
|
|
72
|
+
name,
|
|
73
|
+
pingInterval: 30000,
|
|
74
|
+
maxReconnectDelay,
|
|
75
|
+
};
|
|
76
|
+
if (this.relayClientFactory) {
|
|
77
|
+
this.relayClient = this.relayClientFactory(opts);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
this.relayClient = new RelayClient(opts);
|
|
81
|
+
}
|
|
82
|
+
this.relayClient.on('error', (error) => {
|
|
83
|
+
this.logger?.debug(`Agora relay error: ${error.message}`);
|
|
84
|
+
});
|
|
85
|
+
this.relayClient.on('message', (envelope) => {
|
|
86
|
+
if (this.relayMessageHandler) {
|
|
87
|
+
this.relayMessageHandler(envelope);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
try {
|
|
91
|
+
await this.relayClient.connect();
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
95
|
+
this.logger?.debug(`Agora relay connect failed (${url}): ${message}`);
|
|
96
|
+
this.relayClient = null;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
setRelayMessageHandler(handler) {
|
|
100
|
+
this.relayMessageHandler = handler;
|
|
101
|
+
}
|
|
102
|
+
async disconnectRelay() {
|
|
103
|
+
if (this.relayClient) {
|
|
104
|
+
this.relayClient.disconnect();
|
|
105
|
+
this.relayClient = null;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
isRelayConnected() {
|
|
109
|
+
return this.relayClient?.connected() ?? false;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Load Agora configuration and return service config (peers as Map).
|
|
113
|
+
*/
|
|
114
|
+
static async loadConfig(path) {
|
|
115
|
+
const configPath = path ?? getDefaultConfigPath();
|
|
116
|
+
const loaded = await loadAgoraConfigAsync(configPath);
|
|
117
|
+
const peers = new Map();
|
|
118
|
+
for (const [name, p] of Object.entries(loaded.peers)) {
|
|
119
|
+
peers.set(name, {
|
|
120
|
+
publicKey: p.publicKey,
|
|
121
|
+
url: p.url,
|
|
122
|
+
token: p.token,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
return {
|
|
126
|
+
identity: loaded.identity,
|
|
127
|
+
peers,
|
|
128
|
+
relay: loaded.relay,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAGzE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,qBAAqB,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAuDxE;;GAEG;AACH,MAAM,OAAO,YAAY;IACf,MAAM,CAAqB;IAC3B,WAAW,GAA2B,IAAI,CAAC;IAC3C,mBAAmB,GAA+B,IAAI,CAAC;IACvD,MAAM,CAAgB;IACtB,kBAAkB,CAA4B;IAEtD,YACE,MAA0B,EAC1B,MAAe,EACf,kBAAuC;QAEvC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,IAAI,CAAC;QAC7B,IAAI,CAAC,kBAAkB,GAAG,kBAAkB,IAAI,IAAI,CAAC;IACvD,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,WAAW,CAAC,OAA2B;QAC3C,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACrD,IAAI,CAAC,IAAI,EAAE,CA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AAS,EAAE,CAAC,CAAC,SAAS;gBACtB,GAAG,EAAE,CAAC,CAAC,GAAG;gBACV,KAAK,EAAE,CAAC,CAAC,KAAK;aACf,CAAC,CAAC;QACL,CAAC;QAED,OAAO;YACL,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,KAAK;YACL,KAAK,EAAE,MAAM,CAAC,KAAK;SACpB,CAAC;IACJ,CAAC;CACF"}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get a short display version of a public key using the last 8 characters.
|
|
3
|
+
* Ed25519 public keys all share the same OID prefix, so the last 8 characters
|
|
4
|
+
* are more distinguishable than the first 8.
|
|
5
|
+
*
|
|
6
|
+
* @param publicKey - The full public key hex string
|
|
7
|
+
* @returns "..." followed by the last 8 characters of the key
|
|
8
|
+
*/
|
|
9
|
+
export declare function shortKey(publicKey: string): string;
|
|
10
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAElD"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get a short display version of a public key using the last 8 characters.
|
|
3
|
+
* Ed25519 public keys all share the same OID prefix, so the last 8 characters
|
|
4
|
+
* are more distinguishable than the first 8.
|
|
5
|
+
*
|
|
6
|
+
* @param publicKey - The full public key hex string
|
|
7
|
+
* @returns "..." followed by the last 8 characters of the key
|
|
8
|
+
*/
|
|
9
|
+
export function shortKey(publicKey) {
|
|
10
|
+
return "..." + publicKey.slice(-8);
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,UAAU,QAAQ,CAAC,SAAiB;IACxC,OAAO,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AACrC,CAAC"}
|