clapper icon indicating copy to clipboard operation
clapper copied to clipboard

Not always broadcasting mDNS/DNS-SD?

Open peteruithoven opened this issue 10 months ago • 1 comments

I noticed while playing with bonjour-service to discover running Clapper instances and to find their ports I didn't always get all Clapper instances.

A simple example:

// Use bonjour-service for mDNS/Bonjour discovery
import { Bonjour } from 'bonjour-service'

const bonjour = new Bonjour();

const browser = bonjour.find({ type: 'clapper', protocol: 'tcp' });
// const browser = bonjour.find(); // find all

browser.on('up', service => {
  const {name, type, host, port} = service;
  console.log(`up: ${name} (${type} @ ${host}:${port}`);
});

console.log('Searching for Clapper services on the local network...');

I have 3 Clapper instances running:

~ ps aux | grep 'clapper -n'      
peterui+ 3007565  0.0  0.0   3648  1920 pts/3    S+   12:29   0:00 bwrap --args 45 clapper -n /home/peteruithoven/Videos/video.mp4
peterui+ 3007574  0.0  0.0   3768  1160 pts/3    S+   12:29   0:00 bwrap --args 45 clapper -n /home/peteruithoven/Videos/video.mp4
peterui+ 3007576  0.3  0.3 5293780 205280 pts/3  Sl+  12:29   0:01 clapper -n /home/peteruithoven/Videos/video.mp4
peterui+ 3016462  0.0  0.0  47220  2688 pts/10   S+   12:36   0:00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn --exclude-dir=.idea --exclude-dir=.tox clapper -n

I've started them in separate terminal tabs by executing:

flatpak run com.github.rafostar.Clapper -n ~/Videos/video.mp4

Even using avahi-browse -r _clapper._tcp -t I got 0 results. While avahi-browse --all did find services, like some googlecasts.

When I restarted one of the Clapper instances just that one showed up:

avahi-browse -r _clapper._tcp   
+ wlp0s20f3 IPv4 peteruithoven-framework clapper clapperserver0 _clapper._tcp        local
= wlp0s20f3 IPv4 peteruithoven-framework clapper clapperserver0 _clapper._tcp        local
   hostname = [peteruithoven-framework.local]
   address = [192.168.178.100]
   port = [34495]

Another attempt, starting 3 instances and then running avahi-browse I see just one service:

avahi-browse -r _clapper._tcp -t
+ wlp0s20f3 IPv4 peteruithoven-framework clapper clapperserver2 _clapper._tcp        local
= wlp0s20f3 IPv4 peteruithoven-framework clapper clapperserver2 _clapper._tcp        local
   hostname = [peteruithoven-framework.local]
   address = [192.168.178.100]
   port = [36211]
   txt = []

Am I running into a mDNS/DNS-SD limitation or could there be an issue with Clappers broadcasting logic?

peteruithoven avatar May 17 '25 10:05 peteruithoven

No. Seems like a bug on app side.

NOTE: Issue does not seem to happen if there is only one window open.

To reproduce:

  1. Start listening (without -t option):
avahi-browse -r _clapper._tcp
  1. Open Clapper with video, it pops up in avahi-browse = OK
  2. Open another one or two "New window" (top right menu option)
  3. They pop up in avahi-browse = OK
  4. After a while they seem to die and no longer can be discovered = NOT OK :-(

AVAHI logs them going away (minus sign prefix):

- wlp0s20f3 IPv4 XXX clapper clapperserver1                _clapper._tcp        local
- wlp0s20f3 IPv4 XXX clapper clapperserver0                _clapper._tcp        local
- wlp0s20f3 IPv4 XXX clapper clapperserver2                _clapper._tcp        local

Rafostar avatar May 17 '25 11:05 Rafostar

Server functionality was ported into an enhancer plugin for the player. During porting I changed a few things, among them made the MDNS context separate for each player instance. This seems to improve things related to issue reported here.

Using avahi-browse -r _clapper._tcp -t I am now able to find all created windows/players. Also tested with your Bonjour script (with addition to service "down" detection):

import { Bonjour } from 'bonjour-service'

const bonjour = new Bonjour();

const browser = bonjour.find({ type: 'clapper', protocol: 'tcp' });

browser.on('up', service => {
  const {name, type, host, port} = service;
  console.log(`up: ${name} (${type} @ ${host}:${port}`);
});
browser.on('down', service => {
  const {name, type, host, port} = service;
  console.log(`down: ${name} (${type} @ ${host}:${port}`);
});

console.log('Searching for Clapper services on the local network...');

Works fine here, services appear immediately after window is created and go down when closed.

If you still encounter any problems, feel free to open a new issue ticket against the new implementation (renamed to control-hub in clapper-enhancers repo).

Rafostar avatar Dec 02 '25 20:12 Rafostar