mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-09 08:38:50 +00:00
38 lines
996 B
TypeScript
38 lines
996 B
TypeScript
import { Filter } from './filter.ts'
|
|
import { AbstractRelay } from './relay.ts'
|
|
|
|
function sendNegentropyToRelay(
|
|
open: boolean,
|
|
relay: AbstractRelay,
|
|
msg: string,
|
|
filters: Filter[],
|
|
subscriptionId?: any,
|
|
): void {
|
|
const subId = subscriptionId || Math.random().toString(36).slice(2, 10)
|
|
const parts: any[] = [open ? 'NEG-OPEN' : 'NEG-MSG', subId, ...filters, msg]
|
|
relay.send(JSON.stringify(parts))
|
|
}
|
|
|
|
export function sendNegentropyMessage(
|
|
relay: AbstractRelay,
|
|
msg: string,
|
|
filters: Filter[],
|
|
subscriptionId?: any,
|
|
): void {
|
|
sendNegentropyToRelay(false, relay, msg, filters, subscriptionId)
|
|
}
|
|
|
|
export function openNegentropyWithMessage(
|
|
relay: AbstractRelay,
|
|
msg: string,
|
|
filters: Filter[],
|
|
subscriptionId?: any,
|
|
): void {
|
|
sendNegentropyToRelay(true, relay, msg, filters, subscriptionId)
|
|
}
|
|
|
|
export function closeNegentropy(relay: AbstractRelay, subscriptionId: string): void {
|
|
const request = '["NEG-CLOSE","' + subscriptionId + '"]'
|
|
relay.send(request)
|
|
}
|