@@ -112,15 +112,27 @@ def _zconf_update_zmq(self):
112112 'connectionUUID' : self .connection_uuid ,
113113 'deviceID' : ',' .join (self .device_id_list )
114114 }
115- zconf_info = ServiceInfo (
116- self .fully_qualified_name ,
117- f"{ self .connection_uuid } ._DashIO._tcp.local." ,
118- addresses = [socket .inet_aton (self .local_ip_address )],
119- port = self .local_port ,
120- properties = zconf_desc ,
121- server = self .host_name + "." ,
122- )
123- self .zeroconf .update_service (zconf_info )
115+ if self .local_ipv4_address :
116+ zconf_ipv4_info = ServiceInfo (
117+ self .fully_qualified_name ,
118+ f"{ self .connection_uuid } ._DashIO._tcp.local." ,
119+ addresses = [socket .inet_aton (self .local_ipv4_address )],
120+ port = self .local_port ,
121+ properties = zconf_desc ,
122+ server = self .host_name + "." ,
123+ )
124+ self .zeroconf .update_service (zconf_ipv4_info )
125+
126+ if self .local_ipv6_address :
127+ zconf_ipv6_info = ServiceInfo (
128+ self .fully_qualified_name ,
129+ f"{ self .connection_uuid } ._DashIO._tcp.local." ,
130+ addresses = [socket .inet_pton (socket .AF_INET6 , self .local_ipv6_address )],
131+ port = self .local_port ,
132+ properties = zconf_desc ,
133+ server = self .host_name + "." ,
134+ )
135+ self .zeroconf .update_service (zconf_ipv6_info )
124136
125137 def add_device (self , device_id ):
126138 """Add a device_id to the advertiser"""
@@ -139,7 +151,7 @@ def close(self):
139151 self .zeroconf .unregister_all_services ()
140152 self .zeroconf .close ()
141153
142- def __init__ (self , connection_uuid : str , ip_address : str , port : int , context : zmq .Context | None = None ):
154+ def __init__ (self , connection_uuid : str , ipv4_address : str , ipv6_address : str , port : int , context : zmq .Context | None = None ):
143155 threading .Thread .__init__ (self , daemon = True )
144156 self .context = context or zmq .Context .instance ()
145157 self .connection_uuid = connection_uuid
@@ -148,7 +160,8 @@ def __init__(self, connection_uuid: str, ip_address: str, port: int, context: zm
148160 host_list = host_name .split ("." )
149161 # rename for .local mDNS advertising
150162 self .host_name = f"{ host_list [0 ]} .local"
151- self .local_ip_address = ip_address
163+ self .local_ipv4_address = ipv4_address
164+ self .local_ipv6_address = ipv6_address
152165 self .local_port = port
153166 self .zeroconf = Zeroconf ()
154167 self .listener = ZeroConfDashTCPListener (self .fully_qualified_name , self .connection_uuid , self .context )
@@ -161,12 +174,24 @@ def run(self):
161174 'connectionUUID' : self .connection_uuid ,
162175 'deviceID' : ',' .join (self .device_id_list )
163176 }
164- zconf_info = ServiceInfo (
165- self .fully_qualified_name ,
166- f"{ self .connection_uuid } ._DashIO._tcp.local." ,
167- addresses = [socket .inet_aton (self .local_ip_address )],
168- port = self .local_port ,
169- properties = zconf_desc ,
170- server = self .host_name + "." ,
171- )
172- self .zeroconf .update_service (zconf_info )
177+ if self .local_ipv4_address :
178+ zconf_ipv4_info = ServiceInfo (
179+ self .fully_qualified_name ,
180+ f"{ self .connection_uuid } ._DashIO._tcp.local." ,
181+ addresses = [socket .inet_aton (self .local_ipv4_address )],
182+ port = self .local_port ,
183+ properties = zconf_desc ,
184+ server = self .host_name + "." ,
185+ )
186+ self .zeroconf .update_service (zconf_ipv4_info )
187+
188+ if self .local_ipv6_address :
189+ zconf_ipv6_info = ServiceInfo (
190+ self .fully_qualified_name ,
191+ f"{ self .connection_uuid } ._DashIO._tcp.local." ,
192+ addresses = [socket .inet_pton (socket .AF_INET6 , self .local_ipv6_address )],
193+ port = self .local_port ,
194+ properties = zconf_desc ,
195+ server = self .host_name + "." ,
196+ )
197+ self .zeroconf .update_service (zconf_ipv6_info )
0 commit comments