Skip to content

Connecting to the AllJoyn bus

michiyosony edited this page Apr 20, 2015 · 1 revision

Before joining a session, adding a listener to methods/signals, or sending a signal, the application must first connect to the AllJoyn network and establish a reference to the AllJoyn bus. To accomplish this, use the connect function with the following signature:

AllJoyn.connect(success, failure)

####success The first parameter is the success callback. It takes the bus as a parameter. The bus can be stored for later use.

function(bus) {
  // do stuff with the bus
} 

####failure The second parameter is the failure callback. It takes the error message as a parameter.

function(error) {
  // do something about the error
}

####Example:

var connectionSuccess = function(bus) {
  console.log("Successfully connected to the AllJoyn bus!");
  //Join a session, register objects, add listeners, etc...
};

var connectionFailure = function() {
  console.log("Failed to connect to the AllJoyn bus!");
};

if(AllJoyn) {
  AllJoyn.connect(connectionSuccess, connectionFailure);
} else {
  // how did we get here?  Is the AllJoyn plugin installed?
}

Note: this plugin implements the AllJoyn Thin Client only. As such, there must be an external AllJoyn router for a successful connection. An easy way to get a router running is to download the Core Android SDK and run one of the sample apps on an android device on the same network. A service will launch that contains the router.

Clone this wiki locally