Skip to content

Commit

Permalink
feat: expose broadcast method
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyTseng committed Mar 24, 2024
1 parent d51c744 commit ee2ec34
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/core/__test__/nostr-relay.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,4 +423,17 @@ describe('NostrRelay', () => {
expect(nostrRelay.isAuthorized(client)).toBeTruthy();
});
});

describe('broadcast', () => {
it('should call broadcast on subscriptionService', async () => {
const mockSubscriptionServiceBroadcast = jest
.spyOn(nostrRelay['subscriptionService'], 'broadcast')
.mockImplementation();
const event = { id: 'eventId' } as Event;

await nostrRelay.broadcast(event);

expect(mockSubscriptionServiceBroadcast).toHaveBeenCalledWith(event);
});
});
});
9 changes: 9 additions & 0 deletions packages/core/src/nostr-relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,15 @@ export class NostrRelay {
return this.domain ? !!this.getClientContext(client).pubkey : true;
}

/**
* Broadcast an event. This method does not call any plugins.
*
* @param event The event to broadcast
*/
async broadcast(event: Event): Promise<void> {
await this.subscriptionService.broadcast(event);
}

private getClientContext(client: Client): ClientContext {
const ctx = this.clientContexts.get(client);
if (ctx) return ctx;
Expand Down

0 comments on commit ee2ec34

Please sign in to comment.