Created
December 7, 2010 16:38
-
-
Save leggetter/732019 to your computer and use it in GitHub Desktop.
A really simple example of how to use the Kwwika JavaScript API within a webOS application.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" | |
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> | |
<head> | |
<title>sampleApp</title> | |
<script src="ares.js" type="text/javascript"></script> | |
<script src="http://js.kwwika.com/staging/api.js" type="text/javascript"></script> | |
<script> | |
var conn = kwwika.Service.connect({ | |
apiKey: "YOUR_API_KEY", | |
//logLevel: "finest", | |
connectionStatusUpdated:function(status) | |
{ | |
Mojo.Log.info("ConnectionStatusUpdated: " + status); | |
if( status == kwwika.ConnectionStatus.LOGGED_IN ) | |
{ | |
conn.publish("/KWWIKA/SANDBOX",{webOS: "Very pleased indeed! " + | |
new Date().toString()}, | |
{ | |
commandSuccess:function(topicName) | |
{ | |
Mojo.Log.info("CommandSuccess: " + topicName); | |
}, | |
commandError:function(topicName, error) | |
{ | |
Mojo.Log.info("commandError: " + topicName + " - " + error); | |
} | |
}); | |
} | |
} | |
}); | |
var sub = conn.subscribe("/KWWIKA/SANDBOX", { | |
topicUpdated:function(sub, update) | |
{ | |
var updateStr = "Subscription update for " + sub.topicName + ":\n"; | |
for(var name in update) | |
{ | |
updateStr += name + "=" + update[name] + "\n"; | |
} | |
Mojo.Log.info(updateStr); | |
}, | |
topicError:function(sub, reason) | |
{ | |
Mojo.Log.error("Error subscribing to " + sub.topicName + ": " + reason); | |
} | |
}); | |
</script> | |
</head> | |
<body> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment