Skip to content
This repository has been archived by the owner on Apr 16, 2019. It is now read-only.

Commit

Permalink
Initial import of Java library, Hello World\!
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim Cortez committed May 23, 2012
1 parent 1be98ce commit 12c0fbb
Show file tree
Hide file tree
Showing 60 changed files with 10,054 additions and 0 deletions.
32 changes: 32 additions & 0 deletions LICENSE
@@ -0,0 +1,32 @@
Copyright (c) 2011, Yahoo! Inc.
All rights reserved.

Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:

* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.

* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.

* Neither the name of Yahoo! Inc. nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of Yahoo! Inc.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
57 changes: 57 additions & 0 deletions README.txt
@@ -0,0 +1,57 @@
OVERVIEW
********
The Yahoo! Connected TV Device Communication Java Library uses several 3rd party open source libraries and tools. This file summarizes the tools used, their purpose, and the licenses under which they are released. This file also explains how to build the jar file and generate Javadoc documentation.

BUILD
*****
To create a jar for this library use Maven (http://maven.apache.org/). Use the command:

mvn package

This will download all dependencies and create the jar file "target/device-control-<version>.jar".

DOCUMENTATION
*************
If you wish to create documentation from the source use this command:

mvn "javadoc:javadoc"

Generated documentation will be created in the doc/ folder. Open the doc/index.html file in your web browser.

LIBRARIES
*********
Except as specifically stated below, the 3rd party software packages are not distributed as part of this project, but instead are separately downloaded from their respective provider and built on the developer's machine prior to building the library.

* JmDNS version 3.4.0 (Apache 2.0 license)
(A mDNS client library)
http://jmdns.sourceforge.net/

* org.json version 20090211
(Java JSON Library)
http://json.org/java/

For unit tests:
* Junit version 4.8.2
(Java testing library)
http://junit.sourceforge.net/

* Hamcrest version 1.3.RC2
(Java unit test helper library)
http://code.google.com/p/hamcrest/

LICENSE
*******
The Yahoo! Connected TV Device Communication Java Library is licensed under the following BSD License.

Software License Agreement (BSD License)
Copyright c 2011 Yahoo! Inc. All rights reserved.

Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

* Neither the name of Yahoo! Inc. nor the names of Yahoo! Connected TV's contributors may be used to endorse or promote products derived from this software without specific prior written permission of Yahoo! Inc.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
20 changes: 20 additions & 0 deletions build.properties
@@ -0,0 +1,20 @@
# This file is used to override default values used by the Ant build system.
#
# This file must be checked in Version Control Systems, as it is
# integral to the build system of your project.

# This file is only used by the Ant script.

# You can use this to override default values such as
# 'source.dir' for the location of your java source folder and
# 'out.dir' for the location of your output folder.

# You can also use it define how the release builds are signed by declaring
# the following properties:
# 'key.store' for the location of your keystore and
# 'key.alias' for the name of the key to use.
# The password will be asked during the build when you use the 'release' target.

# The name of your application package as defined in the manifest.
# Used by the 'uninstall' rule.
application.package=com.yahoo.connectedtv.ycommand
216 changes: 216 additions & 0 deletions examples/AppChatExample/AppChatExample.java
@@ -0,0 +1,216 @@
/*******************************************************************************
* Copyright (c) 2011, Yahoo! Inc.
* All rights reserved.
*
* Redistribution and use of this software in source and binary forms,
* with or without modification, are permitted provided that the following
* conditions are met:
*
* * Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* following disclaimer.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* * Neither the name of Yahoo! Inc. nor the names of its
* contributors may be used to endorse or promote products
* derived from this software without specific prior
* written permission of Yahoo! Inc.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
******************************************************************************/

/***
* This example demonstrates how to communicate with a specific TV app. It allows an IM-type message passing. Type in
* the console and your message will be printed on the TV screen. Type something on the TV and it will show up in the
* console.
*/

import com.yahoo.connectedtv.ycommand.*;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.UnknownHostException;

public class AppChatExample {
public static String HOST = "localhost";
public static int PORT = 8099;
public static String APP_NAME = "AppChatExample";
public final static String APP_ID = "0xeTgF3c";
public final static String CONSUMER_KEY = "dj0yJmk9T1Y0MmVIWWEzWVc3JmQ9WVdrOU1IaGxWR2RHTTJNbWNHbzlNVEUzTkRFM09ERTJNZy0tJnM9Y29uc3VtZXJzZWNyZXQmeD0yNA--";
public final static String SECRET = "1b8f0feb4d8d468676293caa769e19958bf36843";

public static String WIDGET_ID = "com.yahoo.connectedtv.examples.appchat.widget";

public Connection conn;

private CommandRouter router;

public AppChatExample(String host, int port) {
// Set up our router object, this is responsible for routing incoming
// and outgoing messages
router = new CommandRouter();
try {
// setup our socket connection to the tv, but don't connect yet
conn = new Connection(InetAddress.getByName(host), port, router);

// Tell out router which network connection to use
router.setConnection(conn);

// setup a handler for incoming GrantedSessionCommand message
// objects
router.registerCommandSubscriber(new CommandSubscriber(), GrantedSessionCommand.class);

// Establish a connection
conn.establish();
// Since this is the first time we are connecting, we must
// create a new session
router.publishCommand(new CreateSessionCommand(APP_ID, CONSUMER_KEY, SECRET, APP_NAME));

String message = this.getUserInput("Code: ");

router.publishCommand(new AuthSessionCommand(message, conn.getPeerCertificate()));
} catch (UnknownHostException e) {
this.exitWithError("Error resolving " + host);
} catch (IOException e) {
this.exitWithError("Problem writing to the network connection");
} catch (InterruptedException e) {
this.exitWithError("Problem writing to the network connection");
}
}

private String getUserInput(String prompt) {
System.out.print(prompt);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {
return br.readLine().trim();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}

private class CommandSubscriber implements ICommandSubscriber {
public void onCommandReceived(AbstractCommand command) {
// Filter out the messages we care about
if (command instanceof GrantedSessionCommand) {
// Print our our unique key, this will be used for
// subsequent connections
Utilities.log("Your instanceId is " + ((GrantedSessionCommand) command).getInstanceId());

try {
router.registerCommandSubscriber(this, WidgetCommand.class, WIDGET_ID);
} catch (InterruptedException e) {
e.printStackTrace();
}

AppChatExample.this.startUserInput();

//Launch widget
try {
AppChatExample.this.router.publishCommand(new WidgetLaunchMethodCommand("callid-launch-" + WIDGET_ID, WIDGET_ID));
} catch (InterruptedException e) {
e.printStackTrace();
}
} else if (command instanceof WidgetCommand) {
// handle incoming message from a widget
try {
JSONObject payload = new JSONObject(command.getPayload());
String username = payload.getString("username");
String message = payload.getString("message");
Utilities.log(username + ": " + message);
} catch (JSONException e) {
e.printStackTrace();
}
} else { // print out the others for educational purposes
Utilities.log("Received: " + command.toString());
}
}

public void onConnectionLost(Connection conn) {
Utilities.log("Connection Lost!");
// AppChatExample.this.closeConnectionAndExit();

synchronized (AppChatExample.this.conn) {
AppChatExample.this.conn.notifyAll();
}
}
}

private void startUserInput() {
(new Thread() {
public void run() {
try {
while (true) {
String message = AppChatExample.this.getUserInput("Message: ");

if (message == null || message.equals("")) {
continue;
} else if (message.equals("q") || message.equals("quit")) {
break;
}

JSONObject msgObj = new JSONObject();
msgObj.put("message", message);
msgObj.put("username", "You");
AppChatExample.this.router.publishCommand(new WidgetCommand(WIDGET_ID, msgObj));
}
AppChatExample.this.closeConnectionAndExit();

} catch (JSONException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
}

private void closeConnectionAndExit() {
this.conn.close();

// Notify the main thread that everything we wanted to
// do is done.
synchronized (this.conn) {
this.conn.notifyAll();
}
}

private void exitWithError(String message) {
Utilities.log(message);
System.exit(-1);
}

public static void main(String[] args) {
AppChatExample chatExample = new AppChatExample(HOST, PORT);

// Let's wait until everything is done. This thread will get
// notified once we are ready to clean up
synchronized (chatExample.conn) {
try {
chatExample.conn.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}

System.exit(1);
}
}
7 changes: 7 additions & 0 deletions examples/AppChatExample/README
@@ -0,0 +1,7 @@
This example opens a connection, then starts an IM-like dialog with the Chat example.

Java:
compiling:
javac -cp <path_to_library_jar> AppChatExample
running:
java -cp "<path_to_library_jar>:<path_to_org.json.jar>" AppChatExample
7 changes: 7 additions & 0 deletions examples/SimpleNavigationExample/README
@@ -0,0 +1,7 @@
This example opens a connection, issues a command to navigate right, then closes.

Java:
compiling:
javac -cp <path_to_library_jar> SimpleExample
running:
java -cp "<path_to_library_jar>:<path_to_org.json.jar>" SimpleExample

0 comments on commit 12c0fbb

Please sign in to comment.