How to use the mdns/service function in mdns

To help you get started, we’ve selected a few mdns examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Kinoma / kinomajs / xs6 / extensions / mdns / mdns_server.js View on Github external
query(service, cb) {
		if (!cb) {	// stop the query
			let svc = this.services.find(e => e.match(service) && e.querying);
			if (svc)
				this.remove(svc);
			return;
		}
		let svc = new Service(service);
		svc.onFound = res => cb(res);
		svc.query(this.socks);
		svc.querying = true;
		this.services.push(svc);
	},
github Kinoma / kinomajs / xs6 / extensions / mdns / mdns_server.js View on Github external
register(service, servname, port, txt, ttl, i = 0) {
		if (i > 0) {
			let dot = servname.indexOf('.');
			if (dot >= 0) {
				let nn = servname.slice(0, dot);
				nn += ` (${i})`;
				var uniqname = nn + slice(dot);
			}
			else
				var uniqname = `${servname} (${i})`;
		}
		else
			var uniqname = servname;
		var svc = new Service(service, uniqname, port, txt, ttl);
		svc.onFound = res => {
			if (res) {
				if (this.socks.some(s => res.addr == s.addr)) {	// multicast_loop is false so this should not happen...
					// trace("mdns: from myself!\n");
					return;
				}
				if (this.services.some(svc => res.name == svc.name)) {
					// trace(`mdns.register: conflict! ${service} / ${servname} (${i})\n`);
					this.remove(svc);
					this.register(service, servname, port, txt, ttl, i + 1);
				}
			}
		};
		svc.probe(this.socks, () => svc.announce(this.socks, () => svc.probed = true));
		this.services.push(svc);
	},