Releases: thaliproject/Thali_CordovaPlugin
Includes BLE discovery on Android
npmv2.1.0 Preparations for 2.1.0 release.
Patch release to fix version mapping between npm package and cordova plugin
npmv2.0.4 Preparing for 2.0.4 release.
Fixing iOS Issues
This release fixes issues we had in iOS that made it unreliable when moving large data across the multipeer connectivity framework. It also includes fixes to make Android more robust.
Story 0 - Turning on the lights
This is our first release with all the major components needed for Thali. It's still early days but it's good to have a foundation. See here for details.
Thali Cordova Plugin Story 0 for Android
This is the first release of the Thali Cordova Plugin, a platform for building peer to peer applications, which completes Story 0. This release includes the basic infrastructure for discovery over WiFi-Direct of other devices and then synchronize data over Bluetooth for Android devices that are running Android 4.4 KitKat or higher using the power of JXcore, Apache Cordova and PouchDB.
Note that Story 0 is a turn on the lights build which means that it is missing many features that will be delivered later in parts of Story 0, such as Access Control Lists (ACLs), Identity Exchange and so forth, but is a basic building block for building Thali applications that you can get started with right away.
What's great about using JXcore is that you can now publish JXcore applications in both Apple's App Store as well as Google Play as Nubisa relayed in a blog post, which means that yes, your Thali applications can be deployed via the stores for your platform!
Getting Started
This will cover how to get started using the Thali Cordova Plugin for Story 0. For Windows users, we recommend using the Git for Windows Shell, GitHub for Windows Shell, MinGW, or cmder to run the following setup.
Android Studio
To get started, first download Android Studio and follow the instructions below.
Make sure to set your ANDROID_HOME
environment variable:
Mac OS X (put in your ~/.bash_profile
file):
export ANDROID_HOME=~/Library/Android/sdk
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
Linux (put in your ~/.bashrc
file):
export ANDROID_HOME=/<installation location>/Android/sdk
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
Windows:
set ANDROID_HOME=C:\<installation location>\Android\sdk
set PATH=%PATH%;%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools
JXcore
Follow the instructions at http://jxcore.com/downloads/. When you're done, check that the installation worked:
$ jx -jxv
v Beta-0.3.0.3
Install Apache Cordova
Ensure that Apache Cordova is installed globally by using JXcore's jx install
command.
Mac/Linux:
$ sudo jx install -g cordova
Windows:
$ jx install -g cordova
Create an Apache Cordova project
Create an Apache Cordova application using the following syntax where <PATH>
indicates where you want the application created, <ID>
indicates the reverse-domain-style package name, and finally <NAME>
which is the human readable field for the application name.
$ cordova create <PATH> <ID> <NAME>
So for example, we could create an application called "ThaliTest" such as the following:
$ cordova create ThaliTest com.test.thalitest ThaliTest
Using the Thali Cordova Plugin
To use Thali in a Cordova project follow the instructions below:
- Ensure to add the Android platform using the following command
$ cordova platform add android
- Add a subfolder to
www
namedjxcore
(case sensitivity matters) - Inside the
jxcore
folder create theapp.js
for your application - Inside the jxcore folder create the
package.json
for your application using JXcore:
$ jx npm init
- Inside the jxcore folder run the following command:
$ jx install thali --save
- Finally, build the Cordova Plugin by running the following command. Yes, an exception did get thrown during the build. No, it isn't harmful. No, we haven't quite figured out why it gets thrown, the verbose debug logs aren't saying anything useful. If you want to build an application, hold off on this step and follow the steps below and then build.
$ cordova build
Now you can run your app!
Note that Thali uses a subdirectory in your project called thaliDontCheckin
to manage certain downloads. Per the name of the directory, please don't check it in to your repro.
If you want to upgrade to a newer version of Thali_CordovaPlugin all you have to do is just edit your package.json
with the version you want and then run 'jx install'. This will automatically update the Javascript files as well as uninstall the old plugin and install the new plugin.
Building an Application
To build a minimal application, we'll use express, express-pouchdb, PouchDB, leveldown-mobile and the ThaliReplicationManager
class from thali.
To install them, run the following in the www/jxcore
and ensure to clean up the "_.gz" files which will prevent the Cordova Plugin from deploying successfully to Android. Note in the future, JXcore will support jx install <package> --autoremove "_.gz"
to take care of the cleanup step for you.
$ jx install express --save
$ jx install pouchdb --save
$ jx install leveldown-mobile --save
$ jx install express-pouchdb --save
$ jx install thali --save
$ find . -name "*.gz" -delete
Now we can get to building our minimal application which creates an express application, exposes a PouchDB instance with leveldown-mobile as the backing storage via express-pouchdb. Then we'll use the ThaliReplicationManager
class to start the synchronization between the databases.
var fs = require('fs');
var express = require('express');
var path = require('path');
var PouchDB = require('pouchdb');
var ThaliReplicationManager = require('thali/thalireplicationmanager');
// Use leveldown-mobile as leveldown will not work on Android
var dbPath = path.join(os.tmpdir(), 'dbPath');
var LevelDownPouchDB = PouchDB.defaults({db: require('leveldown-mobile'), prefix: dbPath});
var app = express();
app.disable('x-powered-by');
// Expose the database via express-pouchdb
app.use('/db', require('express-pouchdb')(LevelDownPouchDB, { mode: 'minimumForPouchDB'}));
var db = new LevelDownPouchDB('thali');
var server = app.listen(5000, function () {
console.log('Express server started. (port: 5000)');
// Create the replication manager
var manager = new ThaliReplicationManager(db);
manager.start('user name' /* user name */, 5000 /* port */, 'thali' /* database name */);
manager.on('started', function () {
console.log('Thali replication has started');
});
});
From here, you can build the application and run it by calling:
$ cordova build android
Note that it might take some time to discover devices, so don't worry! Now you can use your imagination and add items to the PouchDB database, and the discovery and replication will happen automatically for you between your Android devices. If you are looking for inspiration, we have a demo application called postcardapp which is an application which creates postcards and synchronizes them between devices.