mirror of https://github.com/sipwise/jitsi.git
parent
549cc87c86
commit
4930d5be2a
Binary file not shown.
@ -0,0 +1,8 @@
|
||||
Bundle-Name: JmDNS Lib Provider
|
||||
Bundle-Description: JmDNS Lib Provider
|
||||
Bundle-Vendor: sip-communicator.org
|
||||
Bundle-Version: 0.0.1
|
||||
System-Bundle: yes
|
||||
Export-Package:
|
||||
javax.jmdns,
|
||||
|
||||
@ -0,0 +1,168 @@
|
||||
/*
|
||||
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.impl.provdisc.mdns;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
import net.java.sip.communicator.service.provdisc.event.*;
|
||||
import net.java.sip.communicator.util.*;
|
||||
|
||||
import javax.jmdns.*;
|
||||
|
||||
/**
|
||||
* Class that will perform mDNS provisioning discovery.
|
||||
*
|
||||
* @author Sebastien Vincent
|
||||
*/
|
||||
public class MDNSProvisioningDiscover
|
||||
implements Runnable
|
||||
{
|
||||
/**
|
||||
* Logger.
|
||||
*/
|
||||
private final Logger logger
|
||||
= Logger.getLogger(MDNSProvisioningDiscover.class);
|
||||
|
||||
/**
|
||||
* MDNS timeout (in milliseconds).
|
||||
*/
|
||||
private static final int MDNS_TIMEOUT = 2000;
|
||||
|
||||
/**
|
||||
* List of <tt>ProvisioningListener</tt> that will be notified when
|
||||
* a provisioning URL is retrieved.
|
||||
*/
|
||||
private List<DiscoveryListener> listeners =
|
||||
new ArrayList<DiscoveryListener>();
|
||||
|
||||
/**
|
||||
* Reference to JmDNS singleton.
|
||||
*/
|
||||
private JmDNS jmdns = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public MDNSProvisioningDiscover()
|
||||
{
|
||||
try
|
||||
{
|
||||
jmdns = JmDNS.create();
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
logger.info("Failed to create mDNS", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Thread entry point. It runs <tt>discoverProvisioningURL</tt> in a
|
||||
* separate thread.
|
||||
*/
|
||||
public void run()
|
||||
{
|
||||
String url = discoverProvisioningURL();
|
||||
|
||||
if(url != null)
|
||||
{
|
||||
/* as we run in an asynchronous manner, notify the listener */
|
||||
DiscoveryEvent evt = new DiscoveryEvent(this, url);
|
||||
|
||||
for(DiscoveryListener listener : listeners)
|
||||
{
|
||||
listener.notifyProvisioningURL(evt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* It sends a mDNS to retrieve provisioning URL and wait for a response.
|
||||
* Thread stops after first successful answer that contains the provisioning
|
||||
* URL.
|
||||
*
|
||||
* @return provisioning URL or null if no provisioning URL was discovered
|
||||
*/
|
||||
public String discoverProvisioningURL()
|
||||
{
|
||||
StringBuffer url = new StringBuffer();
|
||||
ServiceInfo info = jmdns.getServiceInfo("_https._tcp.local",
|
||||
"Provisioning URL", MDNS_TIMEOUT);
|
||||
|
||||
if(info == null)
|
||||
{
|
||||
/* try HTTP */
|
||||
info = jmdns.getServiceInfo("_http._tcp.local", "Provisioning URL",
|
||||
MDNS_TIMEOUT);
|
||||
}
|
||||
|
||||
if(info != null && info.getName().equals("Provisioning URL"))
|
||||
{
|
||||
String protocol = info.getApplication();
|
||||
|
||||
url.append(info.getURL(protocol));
|
||||
|
||||
Enumeration<String> en = info.getPropertyNames();
|
||||
|
||||
if(en.hasMoreElements())
|
||||
{
|
||||
url.append("?");
|
||||
}
|
||||
|
||||
/* add the parameters */
|
||||
while(en.hasMoreElements())
|
||||
{
|
||||
String tmp = en.nextElement();
|
||||
|
||||
/* take all other parameters except "path" */
|
||||
if(tmp.equals("path"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
url.append(tmp);
|
||||
url.append("=");
|
||||
url.append(info.getPropertyString(tmp));
|
||||
|
||||
if(en.hasMoreElements())
|
||||
{
|
||||
url.append("&");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (url.toString().length() > 0) ? url.toString() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a listener that will be notified when the
|
||||
* <tt>discoverProvisioningURL</tt> has finished.
|
||||
*
|
||||
* @param listener <tt>ProvisioningListener</tt> to add
|
||||
*/
|
||||
public void addDiscoveryListener(DiscoveryListener listener)
|
||||
{
|
||||
if(!listeners.contains(listener))
|
||||
{
|
||||
listeners.add(listener);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a listener that will be notified when the
|
||||
* <tt>discoverProvisioningURL</tt> has finished.
|
||||
*
|
||||
* @param listener <tt>ProvisioningListener</tt> to add
|
||||
*/
|
||||
public void removeDiscoveryListener(DiscoveryListener listener)
|
||||
{
|
||||
if(listeners.contains(listener))
|
||||
{
|
||||
listeners.remove(listener);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.impl.provdisc.mdns;
|
||||
|
||||
import net.java.sip.communicator.service.provdisc.*;
|
||||
import net.java.sip.communicator.util.*;
|
||||
|
||||
import org.osgi.framework.*;
|
||||
|
||||
/**
|
||||
* Implements <tt>BundleActivator</tt> for the mDNS provisioning bundle.
|
||||
*
|
||||
* @author Sebastien Vincent
|
||||
*/
|
||||
public class ProvisioningDiscoveryMDNSActivator
|
||||
implements BundleActivator
|
||||
{
|
||||
/**
|
||||
* <tt>Logger</tt> used by this <tt>ProvisioningDiscoveryMDNSActivator</tt>
|
||||
* instance for logging output.
|
||||
*/
|
||||
private final Logger logger
|
||||
= Logger.getLogger(ProvisioningDiscoveryMDNSActivator.class);
|
||||
|
||||
/**
|
||||
* MDNS provisioning service.
|
||||
*/
|
||||
private static ProvisioningDiscoveryServiceMDNSImpl provisioningService =
|
||||
new ProvisioningDiscoveryServiceMDNSImpl();
|
||||
|
||||
/**
|
||||
* Starts the mDNS provisioning service
|
||||
*
|
||||
* @param bundleContext the <tt>BundleContext</tt> as provided by the OSGi
|
||||
* framework.
|
||||
* @throws Exception if anything goes wrong
|
||||
*/
|
||||
public void start(BundleContext bundleContext)
|
||||
throws Exception
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("mDNS provisioning discovery Service [STARTED]");
|
||||
|
||||
bundleContext.registerService(
|
||||
ProvisioningDiscoveryService.class.getName(),
|
||||
provisioningService,
|
||||
null);
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("mDNS provisioning discovery Service [REGISTERED]");
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the mDNS provisioning service.
|
||||
*
|
||||
* @param bundleContext the <tt>BundleContext</tt> as provided by the OSGi
|
||||
* framework.
|
||||
* @throws Exception if anything goes wrong
|
||||
*/
|
||||
public void stop(BundleContext bundleContext) throws Exception
|
||||
{
|
||||
if (logger.isInfoEnabled())
|
||||
logger.info("mDNS provisioning discovery Service ...[STOPPED]");
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,104 @@
|
||||
/*
|
||||
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.impl.provdisc.mdns;
|
||||
|
||||
import net.java.sip.communicator.service.provdisc.*;
|
||||
import net.java.sip.communicator.service.provdisc.event.*;
|
||||
import net.java.sip.communicator.util.*;
|
||||
|
||||
/**
|
||||
* Class that uses mDNS to retrieve provisioning URL.
|
||||
*
|
||||
* @author Sebastien Vincent
|
||||
*/
|
||||
public class ProvisioningDiscoveryServiceMDNSImpl
|
||||
extends AbstractProvisioningDiscoveryService
|
||||
implements DiscoveryListener
|
||||
{
|
||||
/**
|
||||
* Logger.
|
||||
*/
|
||||
private final Logger logger
|
||||
= Logger.getLogger(ProvisioningDiscoveryServiceMDNSImpl.class);
|
||||
|
||||
/**
|
||||
* Name of the method used to retrieve provisioning URL.
|
||||
*/
|
||||
private static final String METHOD_NAME = "Bonjour";
|
||||
|
||||
/**
|
||||
* MDNS provisioning discover object.
|
||||
*/
|
||||
private MDNSProvisioningDiscover discover = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public ProvisioningDiscoveryServiceMDNSImpl()
|
||||
{
|
||||
try
|
||||
{
|
||||
discover = new MDNSProvisioningDiscover();
|
||||
discover.addDiscoveryListener(this);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
logger.warn("Cannot create JmDNS instance", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the method name used to retrieve provisioning URL.
|
||||
*
|
||||
* @return method name
|
||||
*/
|
||||
public String getMethodName()
|
||||
{
|
||||
return METHOD_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* Launch a discovery for a provisioning URL. This method is synchronous and
|
||||
* may block for some time. Note that you don't have to call
|
||||
* <tt>startDiscovery</tt> method prior to this one to retrieve URL.
|
||||
*
|
||||
* @return provisioning URL
|
||||
*/
|
||||
public String discoverURL()
|
||||
{
|
||||
if(discover != null)
|
||||
{
|
||||
return discover.discoverProvisioningURL();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Launch a mDNS discovery for a provisioning URL.
|
||||
*
|
||||
* This method is asynchronous, the response will be notified to any
|
||||
* <tt>ProvisioningListener</tt> registered.
|
||||
*/
|
||||
public void startDiscovery()
|
||||
{
|
||||
if(discover != null)
|
||||
{
|
||||
new Thread(discover).start();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify the provisioning URL.
|
||||
*
|
||||
* @param event provisioning event
|
||||
*/
|
||||
public void notifyProvisioningURL(DiscoveryEvent event)
|
||||
{
|
||||
fireDiscoveryEvent(event);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
Bundle-Activator: net.java.sip.communicator.impl.provdisc.mdns.ProvisioningDiscoveryMDNSActivator
|
||||
Bundle-Name: mDNS provisioning discovery
|
||||
Bundle-Description: A bundle providing support for mDNS provisioning discovery
|
||||
Bundle-Vendor: sip-communicator.org
|
||||
Bundle-Version: 0.0.1
|
||||
System-Bundle: yes
|
||||
Import-Package: org.osgi.framework,
|
||||
net.java.sip.communicator.service.provdisc,
|
||||
net.java.sip.communicator.service.provdisc.event,
|
||||
net.java.sip.communicator.util,
|
||||
javax.jmdns,
|
||||
Loading…
Reference in new issue