Package net.ioncannon.ap4j.model

Examples of net.ioncannon.ap4j.model.Device


    ServiceInfo serviceInfo = serviceEvent.getInfo();
    if(serviceInfo == null || serviceInfo.getInetAddress() == null)
    {
      serviceInfo = serviceEvent.getDNS().getServiceInfo(serviceEvent.getType(), serviceEvent.getName(), 2000);
    }
    JettyCommandService.addDevice(new Device(serviceEvent.getName(), serviceInfo.getInetAddress(), serviceInfo.getPort()));
  }
View Full Code Here


    ServiceInfo serviceInfo = serviceEvent.getInfo();
    if(serviceInfo == null || serviceInfo.getInetAddress() == null)
    {
      serviceInfo = serviceEvent.getDNS().getServiceInfo(serviceEvent.getType(), serviceEvent.getName(), 2000);
    }
    Device device = new Device(serviceEvent.getName(), serviceInfo.getInetAddress(), serviceInfo.getPort());
    JettyCommandService.removeDevice(device.getId());
  }
View Full Code Here

  public static void removeDevice(String deviceId)
  {
    if (deviceMap.containsKey(deviceId))
    {
      Device removedDevice = deviceMap.remove(deviceId);
      DeviceConnection deviceConnection = DeviceConnectionService.getConnection(removedDevice);
      if (deviceConnection != null)
      {
        deviceConnection.close();
      }
View Full Code Here

      case 2: // Start stream
      {
        String deviceId = request.getParameter("d");
        String streamURL = request.getParameter("s");

        Device device = deviceMap.get(deviceId);
        if(device == null)
        {
          logger.log(Level.SEVERE, "Device ID is not valid: " + deviceId);
          sendErrorResponse(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Device ID is not valid: " + deviceId, baseRequest, response);
        }
        else
        {
          DeviceConnection deviceConnection = DeviceConnectionService.getConnection(device);

          DeviceResponse deviceResponse = deviceConnection.sendCommand(new PlayCommand(URLDecoder.decode(streamURL, "utf-8"), 0.0));

          if (deviceResponse.getResponseCode() == 200)
          {
            sendOKResponse(baseRequest, response);
          }
          else
          {
            sendErrorResponse(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, deviceResponse.getResponseMessage(), baseRequest, response);
          }
        }
      }
      break;
      case 3: // Stop stream
      {
        String deviceId = request.getParameter("d");

        Device device = deviceMap.get(deviceId);
        DeviceConnection deviceConnection = DeviceConnectionService.getConnection(device);

        DeviceResponse deviceResponse = deviceConnection.sendCommand(new StopCommand());

        if (deviceResponse.getResponseCode() == 200)
        {
          sendOKResponse(baseRequest, response);
        }
        else
        {
          sendErrorResponse(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, deviceResponse.getResponseMessage(), baseRequest, response);
        }
      }
      break;
      case 4: // Get current content play state
      {
        String deviceId = request.getParameter("d");

        Device device = deviceMap.get(deviceId);
        DeviceConnection deviceConnection = DeviceConnectionService.getConnection(device);

        DeviceResponse deviceResponse = deviceConnection.sendCommand(new ScrubCommand());

        if (deviceResponse.getResponseCode() == 200)
        {
          response.setStatus(HttpServletResponse.SC_OK);
          baseRequest.setHandled(true);
          Map<String, Object> responseMap = new HashMap<String, Object>();
          responseMap.put("responseCode", "OK");
          responseMap.put("duration", deviceResponse.getContentParameterMap().get("duration"));
          responseMap.put("position", deviceResponse.getContentParameterMap().get("position"));
          response.getWriter().println(JSON.toString(responseMap));
        }
        else
        {
          logger.log(Level.INFO, "Error response: code=" + deviceResponse.getResponseCode() + " message=" + deviceResponse.getResponseMessage());
          sendErrorResponse(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, deviceResponse.getResponseMessage(), baseRequest, response);
        }
      }
      break;
      case 5: // Change the rate of playback
      {
        String deviceId = request.getParameter("d");
        double rate = 0.0;
        boolean rateParsed = false;
        try
        {
          rate = Double.parseDouble(request.getParameter("r"));
          rateParsed = true;
        }
        catch (NumberFormatException e)
        {
          logger.log(Level.INFO, "Could not parse rate parameter: " + request.getParameter("r"));
          sendErrorResponse(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Rate is not valid.", baseRequest, response);
        }

        if(rateParsed)
        {
          Device device = deviceMap.get(deviceId);
          DeviceConnection deviceConnection = DeviceConnectionService.getConnection(device);

          DeviceResponse deviceResponse = deviceConnection.sendCommand(new RateCommand(rate));

          if (deviceResponse.getResponseCode() == 200)
          {
            sendOKResponse(baseRequest, response);
          }
          else
          {
            sendErrorResponse(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, deviceResponse.getResponseMessage(), baseRequest, response);
          }
        }
      }
      break;
      case 6: // Scrub to the given location in the stream
      {
        String deviceId = request.getParameter("d");

        boolean scrubToParsed = false;
        double scrubTo = 0.0;
        try
        {
          scrubTo = Double.parseDouble(request.getParameter("p"));
          scrubToParsed = true;
        }
        catch (NumberFormatException e)
        {
          logger.log(Level.INFO, "Could not parse position parameter: " + request.getParameter("p"));
          sendErrorResponse(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Position is not valid.", baseRequest, response);
        }

        if(scrubToParsed)
        {
          Device device = deviceMap.get(deviceId);
          DeviceConnection deviceConnection = DeviceConnectionService.getConnection(device);

          DeviceResponse deviceResponse = deviceConnection.sendCommand(new ScrubCommand(scrubTo));

          if (deviceResponse.getResponseCode() == 200)
View Full Code Here

TOP

Related Classes of net.ioncannon.ap4j.model.Device

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.