Skip to content

Commit

Permalink
#13 Added visualizer project
Browse files Browse the repository at this point in the history
- with initial frame receiving to demonstrate web-bridge functionality
  • Loading branch information
pappist committed Sep 26, 2016
1 parent 57665e4 commit cb59914
Show file tree
Hide file tree
Showing 8 changed files with 348 additions and 0 deletions.
32 changes: 32 additions & 0 deletions lm-demo/com.incquerylabs.iot.leapmotion.visualizer/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src/main/webapp"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
23 changes: 23 additions & 0 deletions lm-demo/com.incquerylabs.iot.leapmotion.visualizer/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>com.incquerylabs.iot.leapmotion.visualizer</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.8
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
186 changes: 186 additions & 0 deletions lm-demo/com.incquerylabs.iot.leapmotion.visualizer/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.incquerylabs.iot.leapmotion</groupId>
<artifactId>leapmotion-visualizer</artifactId>
<version>0.0.1-SNAPSHOT</version>

<properties>
<jetty-version>9.3.5.v20151012</jetty-version>
</properties>

<dependencies>

<dependency>
<groupId>com.incquerylabs.iot</groupId>
<artifactId>leapmotion-proto</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>com.incquerylabs.iot</groupId>
<artifactId>communication-zeromq</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>com.incquerylabs.iot</groupId>
<artifactId>iot-web-bridge</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${jetty-version}</version>
</dependency>

<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>${jetty-version}</version>
</dependency>

<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<version>${jetty-version}</version>
</dependency>

<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-server</artifactId>
<version>${jetty-version}</version>
</dependency>

<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>3.0.0</version>
</dependency>

<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java-util</artifactId>
<version>3.0.0</version>
</dependency>

<dependency>
<groupId>com.incquerylabs.iot</groupId>
<artifactId>protobuf-sandbox</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>

</dependencies>

<build>
<sourceDirectory>src/main/java</sourceDirectory>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>Unpack web bridge resources</id>
<phase>prepare-package</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.incquerylabs.iot</groupId>
<artifactId>iot-web-bridge</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>${project.basedir}/target/classes</outputDirectory>
<includes>**/*.js</includes>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>Copy resources</id>
<!-- here the phase you need -->
<phase>prepare-package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.basedir}/target/classes</outputDirectory>
<resources>
<resource>
<directory>${project.basedir}/src/main/webapp</directory>
<include>**/*.html</include>
</resource>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<include>**/*.properties</include>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.incquerylabs.iot.leapmotion.visualizer.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>

</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.incquerylabs.iot.leapmotion.visualizer;

import org.atmosphere.container.Jetty9AsyncSupportWithWebSocket;
import org.atmosphere.cpr.ApplicationConfig;
import org.atmosphere.cpr.AtmosphereServlet;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.HttpConnectionFactory;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.server.handler.ResourceHandler;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.util.resource.Resource;

import com.incquerylabs.iot.communication.PublisherPool;
import com.incquerylabs.iot.communication.SubscriberPool;
import com.incquerylabs.iot.communication.zmq.ZMQFactory;
import com.incquerylabs.iot.web.proto.MessageBuilderService;

public class Main {

public static void main(String[] args) throws Exception {
SubscriberPool.initializePool(new ZMQFactory());
PublisherPool.initializePool(new ZMQFactory());
Main main = new Main();
main.run();
}

private void run() throws Exception {
Server server = new Server();
MessageBuilderService mbSrv = new MessageBuilderService();
mbSrv.load();

ServerConnector http = new ServerConnector(server, new HttpConnectionFactory());
http.setPort(8080);
http.setIdleTimeout(30000);

server.setConnectors(new Connector[] { http });

ServletHolder atmosphereServletHolder = new ServletHolder(AtmosphereServlet.class);
atmosphereServletHolder.setInitParameter(ApplicationConfig.ANNOTATION_PACKAGE, "com.incquerylabs.iot.web.service");
atmosphereServletHolder.setInitParameter(ApplicationConfig.WEBSOCKET_CONTENT_TYPE, "application/json");
atmosphereServletHolder.setInitParameter(ApplicationConfig.PROPERTY_COMET_SUPPORT, Jetty9AsyncSupportWithWebSocket.class.getName());

atmosphereServletHolder.setAsyncSupported(true);

ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
servletContextHandler.setContextPath("/");
servletContextHandler.addServlet(atmosphereServletHolder, "/ws/*");

ResourceHandler cpr = new ResourceHandler();
cpr.setBaseResource(Resource.newClassPathResource("/"));

HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[] { cpr, servletContextHandler });

server.setHandler(handlers);
server.setStopAtShutdown(true);
server.start();
server.join();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
2/127.0.0.1/5555/framestream=com.incquerylabs.iot.leapmotion.proto.LeapMotionProtos$Frame
1/127.0.0.1/5556/commands=com.incquerylabs.iot.protobuf.sandbox.Sandbox$TestMessage
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html>
<head>
<!-- Atmosphere -->
<script type="text/javascript"
src="../javascript/atmosphere-javascript/2.3.0/atmosphere.js"></script>
<!-- Application -->
<script type="text/javascript" src="../javascript/jquery/2.2.4/jquery.js"></script>
<script type="text/javascript" src="../javascript/wsbridge.js"></script>

<script type="text/javascript">

var subscriber = new WSConnection(2, '127.0.0.1', 5555, 'framestream');
subscriber.connect();

subscriber.onMessageArrived = function(frame) {
console.log(frame.id);
}
var publisher = new WSConnection(1, '127.0.0.1', 5556, 'commands');
publisher.connect();

</script>
</head>

<body>

<h3>Leap Motion visualizer</h3>

</body>

</html>

0 comments on commit cb59914

Please sign in to comment.