This commit is contained in:
tiero
2023-01-04 03:36:04 +01:00
parent d7903a88bd
commit 60c25f041c
2 changed files with 33 additions and 25 deletions

View File

@@ -62,13 +62,16 @@ export class ConnectURI {
relay: this.relayURL, relay: this.relayURL,
secretKey, secretKey,
}); });
await rpc.call({ await rpc.call(
{
target: this.target, target: this.target,
request: { request: {
method: 'connect', method: 'connect',
params: [getPublicKey(secretKey)], params: [getPublicKey(secretKey)],
}, },
}, { skipResponse: true }); },
{ skipResponse: true }
);
return; return;
} }
@@ -78,13 +81,16 @@ export class ConnectURI {
relay: this.relayURL, relay: this.relayURL,
secretKey, secretKey,
}); });
await rpc.call({ await rpc.call(
{
target: this.target, target: this.target,
request: { request: {
method: 'disconnect', method: 'disconnect',
params: [], params: [],
}, },
}, { skipResponse: true }); },
{ skipResponse: true }
);
return; return;
} }
@@ -135,7 +141,7 @@ export class Connect {
const [pubkey] = payload.params; const [pubkey] = payload.params;
this.target = pubkey; this.target = pubkey;
this.events.emit('connect', pubkey); this.events.emit('connect', pubkey);
return return;
case 'disconnect': case 'disconnect':
this.target = undefined; this.target = undefined;
this.events.emit('disconnect'); this.events.emit('disconnect');

View File

@@ -37,7 +37,8 @@ export class NostrRPC {
}; };
} }
async call({ async call(
{
target, target,
request: { id = randomID(), method, params = [] }, request: { id = randomID(), method, params = [] },
}: { }: {
@@ -47,7 +48,9 @@ export class NostrRPC {
method: string; method: string;
params?: any[]; params?: any[];
}; };
}, opts?: { skipResponse?: boolean, timeout?: number }): Promise<any> { },
opts?: { skipResponse?: boolean; timeout?: number }
): Promise<any> {
// connect to relay // connect to relay
const relay = await connectToRelay(this.relay); const relay = await connectToRelay(this.relay);
@@ -295,4 +298,3 @@ export async function broadcastToRelay(relay: Relay, event: Event) {
}); });
}); });
} }