UNPKG

@achingbrain/ssdp

Version:

Yet another SSDP implementation for node.js

26 lines (19 loc) 687 B
import { cache } from '../cache.js' import { resolveService } from './resolve-service.js' import type { NotifyMessage, SSDP } from '../index.js' export const ALIVE = 'ssdp:alive' export const BYEBYE = 'ssdp:byebye' export function notify (ssdp: SSDP, message: NotifyMessage): void { if (message.LOCATION == null || message.USN == null || message.NT == null || message.NTS == null) { return } if (message.NTS === BYEBYE) { cache.deleteService(message.NT, message.USN) ssdp.emit('service:remove', message.USN) return } resolveService(ssdp, message.USN, message.NT, message.LOCATION, message.ttl()) .catch(err => { ssdp.emit('error', err) }) }