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

View File

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