/**
   * List published node(s) configuration in the network via multicast
   *
   * @param serviceName name of service published. (e.g. release version for installation)
   * @return node(s) configuration list
   */
  public Map<String, Map<String, String>> list(String serviceName) {
    Map<String, Map<String, String>> results = new HashMap<String, Map<String, String>>();
    ServiceInfo[] infos = jmdns.list("_" + serviceName + "._tcp.local.");
    for (ServiceInfo info : infos) {
      _log.info("ServiceInfo:{}", info);

      // Construct the key
      final String[] hostAddrs = info.getHostAddresses();
      final StringBuffer buf = new StringBuffer();
      for (String hostAddr : hostAddrs) {
        buf.append(hostAddr);
        buf.append(';');
      }
      final String key = buf.toString();
      _log.info("\tkey:{}", key);

      // Construct the values
      final Map<String, String> values = new HashMap<String, String>();
      for (Enumeration<String> e = info.getPropertyNames(); e.hasMoreElements(); ) {
        final String prop = e.nextElement();
        final String value = new String(info.getPropertyBytes(prop));
        _log.info("\tprop:{}, value:{}", prop, value);
        values.put(prop, value);
      }

      // Put <key,values> into the results
      if (values.isEmpty()) {
        _log.warn("values are empty for key: {}", key);
      }
      results.put(key, values.isEmpty() ? null : values);
    }
    return results;
  }
  @Override
  public PluginResult execute(String action, JSONArray data, String callbackId) {
    // Log.d("OSCManager", "executing something " + action);
    System.out.println("EXECUTING ********************************************");
    PluginResult result = null;
    if (action.equals("start")) {
      System.out.println("STARTING ********************************************");

      ServiceInfo[] infos = jmdns.list("_osc._udp.local.");
      for (int i = 0; i < infos.length; i++) {
        String jsString =
            "javascript:destinationManager.addDestination('"
                + infos[i].getHostAddress()
                + "',"
                + infos[i].getPort()
                + ", 0, 0);";
        System.out.println(jsString);
        webView.loadUrl(jsString);
        System.out.println("after sending to js");
      }
    }
    return result;
  }
Exemplo n.º 3
0
  @Override
  public PluginResult execute(String action, JSONArray data, String callbackId) {
    // Log.d("OSCManager", "executing something " + action);
    PluginResult result = null;
    try {
      System.out.println("EXECUTING BONJOUR ********************************************");
      if (action.equals("start") || action.equals("browse")) {
        System.out.println("STARTING BONJOUR ********************************************");

        ServiceInfo[] infos = jmdns.list("_osc._udp.local.");
        for (int i = 0; i < infos.length; i++) {
          String jsString =
              "javascript:destinationManager.addDestination('"
                  + infos[i].getHostAddress()
                  + "',"
                  + infos[i].getPort()
                  + ", 0, 0);";
          System.out.println(jsString);
          webView.loadUrl(jsString);
          System.out.println("after sending to js");
        }
        if (action.equals("start")) {
          ServiceInfo serviceInfo =
              ServiceInfo.create(
                  "_osc._udp.local.",
                  "Control_" + (Math.round(Math.random() * 100000)),
                  8080,
                  "OSC reception for device running Control");
          jmdns.registerService(serviceInfo);
        }
      }
    } catch (Exception e) {
      System.out.println("after sending to js");
    }
    return result;
  }