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, {
request: { target: this.target,
method: 'connect', request: {
params: [getPublicKey(secretKey)], method: 'connect',
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, {
request: { target: this.target,
method: 'disconnect', request: {
params: [], method: 'disconnect',
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,17 +37,20 @@ export class NostrRPC {
}; };
} }
async call({ async call(
target, {
request: { id = randomID(), method, params = [] }, target,
}: { request: { id = randomID(), method, params = [] },
target: string; }: {
request: { target: string;
id?: string; request: {
method: string; id?: string;
params?: any[]; method: string;
}; 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) {
}); });
}); });
} }