Giter Site home page Giter Site logo

cordova-plugin-alljoyn's Introduction

cordova-plugin-alljoyn

iOS Windows Android
Build Status Build status Circle CI

A Cordova plugin to expose the AllJoyn Thin Client (AJTCL 14.12) to cross platform applications written in Javascript.

Purpose

To provide a plugin which allows using the AllJoyn Thin Client library across all mobile platforms without requiring the user to deal with implementing and compiling the native code for each operating system.

Current Platforms:

  • iOS
  • Windows Modern App
  • Windows Phone
  • Android (in-progress)

An effort has been made to expose as many of the AJTCL features to Javascript as possible, while maintaining a clean Javascript API. Features are prioritized based on which scenarios they unblock.

Resources

Various explanatory blog posts can be found here: http://www.stefangordon.com/introducing-the-alljoyn-plugin-for-cordova/

For Plugin Developers / Contributors

After cloning this repository, a plugin developer needs to get AJTCL by running these commands in the project root folder:

$ git clone https://github.com/AllJoyn-Cordova/ajtcl.git src/ajtcl

For plugin users, above is taken care of by a hook run after plugin is added with Cordova scripts.

Using The Plugin On Windows

$ cd /path/to/your/cordova/app
$ cordova add [/path/to/plugin or https://github.com/AllJoyn-Cordova/cordova-plugin-alljoyn.git or cordova-plugin-alljoyn]
$ cordova platform add windows

Running With Cordova Scripts:

// To run on Windows Phone 8.1 emulator
$ cordova run windows --emulator --archs="x86" -- -phone
// Running on Windows Phone 8.1 device
$ cordova run windows --device --archs="arm" -- -phone
// To run on Windows
$ cordova run windows --device --archs="x64" -- -win

Alternative for running with Cordova scripts is to open the solution file generated after "cordova platform add windows"-command in Visual Studio and running the wanted app project. In this case, these is a need to manually select the correct architecture from build configuration.

Building For Android

In addition to the Android SDK, the NDK is required. See https://developer.android.com/tools/sdk/ndk/index.html for installation instructions.

The environment variables ANDROID_HOME and ANDROID_NDK_HOME must be set to the point to the locations where the Android SDK and NDK are installed.

There are some external dependencies when building the plugin for the Android platform. Those are Ant, Gradle and Swig (Swig version needs to be 3.0 or higher). Before building for Android, make sure the respective binaries are found from your PATH environment variable.

The plugin build process is currently depending on Android build tools version 20.0.0. If you don't have that installed, it can be obtained using the Android SDK manager or via command line with command:

$ android update sdk --no-ui --all --filter build-tools-20.0.0

When building on a Mac, one of the easiest ways to install the dependencies is via Homebrew with following command:

$ brew install ant gradle swig

After the dependencies are met, the steps to build and run using the Cordova CLI are something like:

$ cordova platform add android
$ cordova build android
$ cordova run android

If the Android build fails on Windows with an error like:

[...]\AllJoynLib\src\main\jni\aj_keyauthentication.o.d: No such file or directory

It might be caused by hitting the maximum path length limitation. As a workaround, try moving your project to a shorter path.

Running Tests

The tests can be run locally with:

$ npm install
$ npm test

An AllJoyn router must be accessible in the network in which the target device runs for the tests to pass.

The target platform will be selected automatically based on which platform the tests are run. On Mac, an iOS build is made. On Windows, the Cordova universal Windows platform is used and on Linux, the build will be targeting Android. To switch the target, one needs to edit the variable cordovaPlatformMapping at the top of file tests/run.js.

To run tests on Windows, first ensure that fresh enough Cordova script is found from the path. You can look at appveyor.yml file from the root of this repository how this is done in the CI environment. You can use where command to check which cordova is found first from your path:

$ where cordova

If you only want to verify that the build is working via Cordova scripts, you can run:

$ npm run build-only

cordova-plugin-alljoyn's People

Contributors

garethsony avatar leecrossley avatar obsoleted avatar phongcao avatar sgrebnov avatar stefangordon avatar vjrantal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cordova-plugin-alljoyn's Issues

Needs Good Documentation

It would be great to see some good documentation in the README, and in the code.

We're trying to use this currently and can't figure out how to get the return values from a method call.

Plugin add fails if android platform exists if it can not find shelljs

Haven't investigated this at all, we'll need to figure out what the dependency is and the right way to deal with it (instructions, removal, inclusion, etc).

Cloning ajtcl-android from: https://github.com/irjudson/ajtcl-android.git
Failed to install 'org.allseen.alljoyn':Error: Cannot find module 'shelljs'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (c:\Users\Keir\Documents\cordova-chat-alljoyn\plugins\org.allseen.alljoyn\scripts\androidAfter
PluginInstall.js:6:10)

Error installing Plugin with Cordova 6.1.1

I'm trying to instal the plugin on my project but I received this error:
Error: warn

This doesn't help very much to understand what's the problem.
If I try install plugin with Cordova 5.3.3 it works.

iOS: plugin unusable after putting device to sleep, then waking

Steps to reproduce:

  1. Open app that uses the AJ plugin and connect to bus (successfully)
  2. Push power button, blackening screen
  3. Push power button again and unlock device, returning to the app
  4. Attempt to do something with the plugin (e.g. connect to a session)
    Observe crash

When returning to the AllJoyn app (step 3), these messages

029.102 aj_net.c:245 AJ_Net_Recv(): recv() failed. errno="Socket is not connected", status=AJ_ERR_READ
029.102 aj_net.c:251 AJ_Net_Recv(): status=AJ_ERR_READ
029.102 AllJoyn_Cordova.m:1469  -- MainLoopError AJ_UnmarshalMsg returned status=AJ_ERR_READ
ERROR: Main loop had a non-succesful iteration. Exit status: 5 0x5 AJ_ERR_READ029.202 aj_net.c:220 AJ_Net_Recv(buf=0x0x17412fe08, len=16., timeout=1000.)
029.202 aj_net.c:245 AJ_Net_Recv(): recv() failed. errno="Socket is not connected", status=AJ_ERR_READ
029.202 aj_net.c:251 AJ_Net_Recv(): status=AJ_ERR_READ
029.202 AllJoyn_Cordova.m:1469  -- MainLoopError AJ_UnmarshalMsg returned status=AJ_ERR_READ
ERROR: Main loop had a non-succesful iteration. Exit status: 5 0x5 AJ_ERR_READ029.302 aj_net.c:220 AJ_Net_Recv(buf=0x0x17412fe08, len=16., timeout=1000.)
029.302 aj_net.c:245 AJ_Net_Recv(): recv() failed. errno="Socket is not connected", status=AJ_ERR_READ
029.302 aj_net.c:251 AJ_Net_Recv(): status=AJ_ERR_READ
029.302 AllJoyn_Cordova.m:1469  -- MainLoopError AJ_UnmarshalMsg returned status=AJ_ERR_READ
ERROR: Main loop had a non-succesful iteration. Exit status: 5 0x5 AJ_ERR_READ029.401 aj_net.c:220 AJ_Net_Recv(buf=0x0x17412fe08, len=16., timeout=1000.)

are being constantly printed in the Xcode console.

When the crash occurs (on attempting to use plugin, step 4), the error that appears in the Xcode console is dependent upon the action performed:

(Attempted to create a channel in the chat app)

027.463 aj_bus.c:172 AJ_BusBindSessionPort(bus=0x0x17013b6c0, port=27., opts=0x0x0)
027.463 aj_net.c:169 AJ_Net_Send(buf=0x0x17013b6d8)
027.463 aj_net.c:176 AJ_Net_Send(): send() failed. errno="Broken pipe", status=AJ_ERR_WRITE
SENDING ERROR: startAdvertisingName: Failure in AJ_BusBindSessionPort AJ_ERR_WRITE

(Attempted to call a method which could be successfully called prior to pushing power button)

Message id: 33554434
MemberType: 63, MemberSignature: increment >i, IsSecure 0
072.498 aj_net.c:169 AJ_Net_Send(buf=0x0x170127d18)
072.498 aj_net.c:176 AJ_Net_Send(): send() failed. errno="Broken pipe", status=AJ_ERR_WRITE

while Xcode shows the crash at the same point:

libsystem_kernel.dylib`mach_msg_trap:
    0x197940e04 <+0>: movn   x16, #0x1e
    0x197940e08 <+4>: svc    #0x80
->  0x197940e0c <+8>: ret    

Windows build requires manual steps

It appears these manual steps are required for making Windows builds. We should figure out what specific issues block a pure command line build/run and come up with a plan for them. We should also document the required SDK/VS versions so we can update the readme for samples.

  • use the private checkout of cordova-cli/lib that were referenced
  • When the app is generated i open the solution in vs2013
  • Flip the build config to x86, set default startup project to the windows 8.1 app
  • Add the capability for internet client & server
  • Update the debugging setting to debug both native and script

iOS: Crash After Re-Connect

Attempting to connect after a connection failure results in a crash.
To reproduce:
1.) Call AllJoyn.connect with a guaranteed failure condition (e.g. turn WiFi off).
2.) Observe the on-failure callback is called.
3.) Issue a second call to AllJoyn.connect (this will result in a crash).

Support for responding to application object method calls

Currently, one can define interfaces with methods and register them under application objects, but there is no way to respond to method calls after methods are invoked.

In ajtcl code, this is done with the AJ_MarshalReplyMsg function and an example can be found from https://git.allseenalliance.org/cgit/core/ajtcl.git/tree/samples/basic/basic_service.c#n84.

In terms of the API how this is exposed, alternatives include at least extending the addListener interface for returning values from the callbacks or defining a new interface like addMethodImplementation that has mechanism to handle returns.

See the comment at #26 (comment) for background information.

Build failed on Cordova > 4

I have an error on build with initWithWebView. I've found similar issue shazron/KeychainPlugin#21 and installing older (<4) version of cordova solves the problem.

Possible solution: initWithWebView goes away in cordova-ios 4.0, all plugin initialization should be in the pluginInitialize function.

[Windows] Can't connect to a Windows10 AllJoyn Router Service

I use built-in AllJoyn Router Service on Windows 10 and cordova-lighting-alljoyn sample for testing.

Android implementation works fine and sample app can find and connect to the router.

When using Windows Cordova platform the following line always reports connection timeout. I tried to increase timeout, restart service, Windows 8.1 and Windows UAP projects (Desktop/x64, sample app is run on the same PC w/ Ajn Service).

var status = AllJoynWinRTComponent.AllJoyn.aj_FindBusAndConnect(busAttachment, daemonName, 5000);

PS. Awesome work

iOS: Issues when trying to send a new message when message loop is blocked

Some messages, such as the join session request, need to be handled synchronously currently. To do this we block the message loop until the messages is dealt with. Unfortunately the blocking logic has some flaws. When blocked it is possible to send a message from the application causing the underlying msg buffer state to change. This can cause the app to get into an unrecoverable failure state.

While we should probably move away from the blocking implementation at some point but until then more can be done to protect against this behavior.

Change the way error type messages are delivered

Messages that are successfully received, but marked as error type messages should be delivered in the public API to the success callbacks so that they can be separated from errors happening in the message delivery.

One option is to add a property called error to the returned messages that is null in case of success and the error message in case of errors.

In case of error messages, it is expected that the message doesn't contain the arguments that would be expected in success cases. For example, if an error message is returned to a method call that would otherwise return arguments with signature 'sss' would not necessarily have the arguments included (not sure if the protocol would allow this, but the user of the API should be prepared for return arguments to be missing).

Rebase the ajtcl changes on the latest 15.04 release.

At the same time, the ajtcl repository that has changes this plugin needs (https://github.com/AllJoyn-Cordova/ajtcl) could be made a fork (in GitHub) of the upstream repository at https://github.com/allseenalliance/core-ajtcl.

Nothing extremely significant in the new release, but the router selection algorithm might be sometimes valuable. More details about what the release contains at https://git.allseenalliance.org/cgit/core/ajtcl.git/tree/ReleaseNotes.txt?h=RB15.04.

SessionListener functionality

I don't see anything in the plugin with functionality akin to the SessionListener, or some way of being notified that another party has left a joined session/the session has been closed, etc. Am I overlooking it? If it does not currently exist, is it planned?

Cann't build for android

I have some problem when building it for Android.

Step to reproduce(on Ubuntu 14.04, nodejs v0.12.6, cordova 5.1.1, on this commit b0fb979):

cordova create hello com.example.hello HelloWorld
cordova plugin add https://github.com/AllJoyn-Cordova/cordova-plugin-alljoyn.git
cordova platform add android
cordova build android

After these steps there are many errors like so:

/home/german/projects/hello/platforms/android/src/org/allseen/alljoyn/AllJoynCordova.java:54: error: cannot find symbol
    private AJ_BusAttachment bus;
            ^
  symbol:   class AJ_BusAttachment
  location: class AllJoynCordova
/home/german/projects/hello/platforms/android/src/org/allseen/alljoyn/AllJoynCordova.java:55: error: cannot find symbol
    private AJ_Object proxyObjects;
            ^
  symbol:   class AJ_Object
  location: class AllJoynCordova
/home/german/projects/hello/platforms/android/src/org/allseen/alljoyn/AllJoynCordova.java:56: error: cannot find symbol
    private AJ_Object appObjects;
            ^
  symbol:   class AJ_Object
  location: class AllJoynCordova
/home/german/projects/hello/platforms/android/src/org/allseen/alljoyn/AllJoynCordova.java:60: error: cannot find symbol
    private _AJ_Message m_pMsg = new _AJ_Message();
            ^
  symbol:   class _AJ_Message
  location: class AllJoynCordova
/home/german/projects/hello/platforms/android/src/org/allseen/alljoyn/AllJoynCordova.java:65: error: cannot find symbol
    _AJ_Message m_pCallbackMessagePtr = null;
    ^
  symbol:   class _AJ_Message
  location: class AllJoynCordova
/home/german/projects/hello/platforms/android/src/org/allseen/alljoyn/AllJoynCordova.java:1306: error: cannot find symbol
    JSONObject getMsgInfo(_AJ_Message pMsg) throws JSONException
                          ^
  symbol:   class _AJ_Message
  location: class AllJoynCordova
/home/german/projects/hello/platforms/android/src/org/allseen/alljoyn/AllJoynCordova.java:1333: error: cannot find symbol
    void sendSuccessArray(JSONArray argumentValues, CallbackContext callbackContext, boolean keepCallback, _AJ_Message pMsg) throws JSONException
                                                                                                           ^
  symbol:   class _AJ_Message
  location: class AllJoynCordova
/home/german/projects/hello/platforms/android/src/org/allseen/alljoyn/AllJoynCordova.java:1393: error: cannot find symbol
    void sendSuccessDictionary(JSONObject argumentValues, CallbackContext callbackContext, boolean keepCallback, _AJ_Message pMsg) throws JSONException
                                                                                                                 ^
  symbol:   class _AJ_Message
  location: class AllJoynCordova
/home/german/projects/hello/platforms/android/src/org/allseen/alljoyn/AllJoynCordova.java:1551: error: cannot find symbol
    AJ_Status UnmarshalArgs(_AJ_Message msg, StringBuffer sig, JSONArray args, StringBuffer nested) throws JSONException
                            ^
  symbol:   class _AJ_Message
  location: class AllJoynCordova
/home/german/projects/hello/platforms/android/src/org/allseen/alljoyn/AllJoynCordova.java:1551: error: cannot find symbol
    AJ_Status UnmarshalArgs(_AJ_Message msg, StringBuffer sig, JSONArray args, StringBuffer nested) throws JSONException
    ^
  symbol:   class AJ_Status
  location: class AllJoynCordova
/home/german/projects/hello/platforms/android/src/org/allseen/alljoyn/AllJoynCordova.java:1854: error: cannot find symbol
    JSONArray AJ_UnmarshalArgs(_AJ_Message msg, String signature)
                               ^
  symbol:   class _AJ_Message
  location: class AllJoynCordova

And after all of this:

:compileDebugJava FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileDebugJava'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 14.305 secs

/home/german/projects/hello/platforms/android/cordova/node_modules/q/q.js:126
                    throw e;
                          ^
Error code 1 for command: /home/german/projects/hello/platforms/android/gradlew with args: cdvBuildDebug,-b,/home/german/projects/hello/platforms/android/build.gradle,-Dorg.gradle.daemon=true
ERROR building one of the platforms: Error: /home/german/projects/hello/platforms/android/cordova/build: Command failed with exit code 1
You may not have the required environment or OS to build this project
Error: /home/german/projects/hello/platforms/android/cordova/build: Command failed with exit code 1
    at ChildProcess.whenDone (/home/german/.nvm/versions/node/v0.12.6/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:134:23)
    at ChildProcess.emit (events.js:110:17)
    at maybeClose (child_process.js:1015:16)
    at Process.ChildProcess._handle.onexit (child_process.js:1087:5)

But when I add this plugin like so cordova plugin add org.allseen.alljoyn, there is some errors too:

npm http GET http://cordova.iriscouch.com/registry/_design/app/_rewrite/org.allseen.alljoyn/-/org.allseen.alljoyn-0.0.4.tgz
npm http 200 http://cordova.iriscouch.com/registry/_design/app/_rewrite/org.allseen.alljoyn/-/org.allseen.alljoyn-0.0.4.tgz
Installing "org.allseen.alljoyn" for android
Cloning ajtcl from: https://github.com/AllJoyn-Cordova/ajtcl.git
Checking out branch: RB14.12
Cloning ajtcl-android from: https://github.com/irjudson/ajtcl-android.git
Failed to install 'org.allseen.alljoyn':Error: ENOENT, no such file or directory '/home/german/projects/hello/plugins/org.allseen.alljoyn/www/AllJoyn.js'
...

So I need to manually add this file(AllJoyn.js). And it works! :-)

(Btw I have some problem when build with npm plugin too https://www.npmjs.com/package/alljoyn)

Ok, when I manually add this file this plugin appear to be only a thin client, but no a router. So I need to build an additional app with alljoyn sdk to have a router.

Can you fix these problems than I mentioned above? So the building app were not so painful :-)
And please add a router to this plugin so there were ability to use all the features of alljoyn system.

iOS: session.sendSignal success callback called erroneously

A session's sendSignal success callback is triggered when the wifi is turned off. This seems counterintuitive, unless the success/failure callbacks are intended to indicate just whether the arguments have the specified types, etc.?

Steps to reproduce:

  1. Connect to bus and session
  2. Disconnect from wifi
  3. Send session-specific signal and observe success callback

Try using keepCallback option also on Windows

When doing the implementation, it wasn't known that Windows should also support the keepCallback option. The support seems to have been added at sgrebnov/cordova-js@a9371e5.

This task is to check that it works and refactor use that instead of passing the success callback in parameters.

This change would not affect the API we expose, but is all "under the hood".

iOS: plugin crashes after leaving/returning to app

  1. Open app that uses the AJ plugin and connect to bus (successfully)
  2. Push home button to leave app
  3. Do something substantial outside app (for example, I found that simply opening and leaving another app does not cause the problem, but taking a panoramic photo does)
  4. Return to AJ app & observe crash

Xcode console output:
053.269 AllJoyn_Cordova.m:1461 Timeout getting MSG. Will try again...
053.278 aj_net.c:220 AJ_Net_Recv(buf=0x0x1701291e8, len=16., timeout=1000.)
053.278 aj_net.c:251 AJ_Net_Recv(): status=AJ_OK
053.278 aj_net.c:220 AJ_Net_Recv(buf=0x0x1701291e8, len=120., timeout=15000.)
053.278 aj_net.c:251 AJ_Net_Recv(): status=AJ_OK
053.278 aj_introspect.c:939 Identified message 30100
053.278 AllJoyn_Cordova.m:1470 Executing handlers if any ...
053.278 AllJoyn_Cordova.m:1479 Done Executing handlers if any ...
Dunno msg 196864
Member: Ping
053.278 AllJoyn_Cordova.m:1489 -- (): AJ_BusHandleBusMessage()
053.278 aj_bus.c:417 AJ_BusHandleBusMessage(msg=0x0x100125008)
053.278 aj_bus.c:428 AJ_BusHandleBusMessage(): AJ_METHOD_PING
053.278 aj_net.c:169 AJ_Net_Send(buf=0x0x1701291b8)
053.279 aj_net.c:176 AJ_Net_Send(): send() failed. errno="Broken pipe", status=AJ_ERR_WRITE
ERROR: Main loop had a non-succesful iteration. Exit status: 6 0x6 AJ_ERR_WRITE053.282 aj_net.c:220 AJ_Net_Recv(buf=0x0x1701291e8, len=16., timeout=1000.)
053.282 aj_net.c:245 AJ_Net_Recv(): recv() failed. errno="Connection reset by peer", status=AJ_ERR_READ

Plugin does not compile for windows, AJ_Introspect.c

AJ_Introspect fails to compile.

Conversion from 'void*' to pointer to non-'void' requires an explicit cast

AJ_InterfaceDescription* AJ_InterfacesCreate()
{
    char ***array;
    array = AJ_Malloc(sizeof(char**));
    array[0] = NULL;
    return (AJ_InterfaceDescription *) array;
}

This method doesn't appear to have been changed at all by Ivan's commit, so perhaps it never worked? Any ideas?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.