Connections
Provides services to create, accept, and manage connections.
Connections
Connection types
The BBM Platform supports the following types of connections:blackberry.bbm.platform.io.Channel
blackberry.bbm.platform.io.Session
Creating a connections
Connections can be created using createConnection. When a connection is created, the application should assign callbacks to it in order to be notified of various events.
var type = ... // One of "channel" or "session" var conn = blackberry.bbm.platform.io.createConnection(type); setConnectionCallbacks(conn, type);
Accepting incoming connections
When the current user accepts an invitation within BBM, onconnectionaccepted will be invoked with the connection on which the invitation was accepted. The application should assign callbacks to the connection within this method.var conn; blackberry.bbm.platform.io.onconnectionaccepted = function(type, connection, cookie) { // Save the connection and set the callbacks conn = connection; setConnectionCallbacks(conn, type); };
Connection events
A generic function can be used to assign callbacks to connections.function setConnectionCallbacks(conn, type) { // Channel/Session callbacks conn.onusersinvited = function(users) { // ... }; conn.onusersjoined = function(users, type, cookie) { // ... }; conn.onuserdeclined = function(user) { // ... }; conn.onuserleft = function(user) { // ... }; conn.ondata = function(user, data) { // ... }; // Session callbacks if(type == "session") { conn.onbroadcastdata = function(user, data) { // ... }; conn.onusersremoved = function(user, users) { // ... }; conn.onended = function(user) { // ... }; } };
Adding Users to Connections
There are two ways to add users to connections: (1) inviting contacts to join a connection, and (2) hosting a connection for non-contacts to join. A user does not have to be the connection creator in order to invite users.
1. Inviting contacts to join
An application user can invite contacts to join a connection.
When the application calls inviteContacts a Contact Picker dialog will be shown containing contacts that have the application installed. If the user invites contacts then the onusersinvited callback will be invoked on the inviter's side.
Invitees receive the invitations within BBM.
- If they accept the invitation, onusersjoined is invoked on the inviter's side, and onconnectionaccepted is invoked on the invitee's side with the connection they just joined.
- If they decline the invitation, onuserdeclined is invoked on the inviter's side.
2. Hosting a public connection for non-contacts to join
An application user can also host an event within a public connection to let all application users join.
When the application calls host a dialog will be shown for the user to allow or deny the decision. If the user allows, the application should then post the host's PIN and PPID to its discovery service. The BBM platform does not provide a discovery service. This must be provided by the application developer.
Peers should download host information (PIN and PPID) from the discovery service and then call joinHost. The peer will also be presented with a dialog to allow or deny the decision.
At this point the request is in the "pending"
state. In this state the peer can cancel the request, and the host can accept or decline.
Supported Platform(s)
- BlackBerry OS 5.0+
API | OS 5.0 | OS 6.0 | OS 7.0 | PlayBook | Ripple |
---|---|---|---|---|---|
createConnection | Y | Y | Y | ||
host | Y | Y | Y | ||
joinHost | Y | Y | Y | ||
hostRequests | Y | Y | Y | ||
hostedConnection | Y | Y | Y | ||
joinHostRequests | Y | Y | Y | ||
onconnectionaccepted | Y | Y | Y | ||
ondataexpired | Y | Y | Y | ||
onuserreachable | Y | Y | Y |
Configuration Document Settings
To use all of the API described for this object, you must ensure the following settings are in your configuration document:
You must declare the feature element(s) below in your configuration document:
Feature ID | OS 5.0 | OS 6.0 | OS 7.0 | PlayBook | Ripple |
---|---|---|---|---|---|
<feature id="blackberry.bbm.platform" /> | Y | Y | Y |
Permission Elements (PlayBook Only) |
---|
This API does not require a <permission> element to be declared in the configuration document of your BlackBerry WebWorks Application. |
API Summary
Functions
Properties
createConnection
static blackberry.bbm.platform.io.Channel | blackberry.bbm.platform.io.Session createConnection(type : String) |
Supported Platform(s)
- BlackBerry OS 5.0+Description
Creates a connection.
The application should assign callbacks to the connection after creating it.
Returns
The connection created.Parameter | Type | Description |
---|---|---|
type | String |
The type of connection to create: "channel" or "session" .
|
host
static void host(connection : blackberry.bbm.platform.io.Connection, onComplete : Function, onRequestReceived : Function, onRequestCanceled : Function) |
Supported Platform(s)
- BlackBerry OS 5.0+Description
Enables hosting on this connection. The user will be prompted with a dialog to allow or deny hosting.
To stop hosting, call blackberry.bbm.platform.io.host()
. Stopping hosting will not
remove users from the connection who have already joined, it will only disallow others from joining.
hostRequests will be emptied.
The user may only host on one connection in the application. If this application is already hosting a public connection and this method is invoked on a different connection, then hosting will stop on the old connection and begin on the new one. The user will again be prompted with a dialog to allow or deny hosting.
Reasons why a request is canceled
"peercanceled"
: The peer canceled the request without a specific reason."peerleft"
: The peer exited the application.
Parameter | Type | Description |
---|---|---|
connection | blackberry.bbm.platform.io.Connection | The connection on which to host. |
onComplete | Function(hosting : Boolean) |
Invoked when the user finishes approving/denying hosting.
hosting: true if the user decided to start hosting;
false otherwise.
|
onRequestReceived | Function(request : blackberry.bbm.platform.io.IncomingJoinRequest) |
Invoked when the host receives a join request from a peer.
request: The received request. |
onRequestCanceled | Function(request : blackberry.bbm.platform.io.IncomingJoinRequest, reason : String) |
Invoked when a peer cancels a join request.
request: The canceled request. reason: The reason that the request was canceled. |
joinHost
static void joinHost(hostPIN : String, hostPPID : String, onComplete : Function, onHostAccepted : Function, onHostDeclined : Function, [cookie: String]) |
Supported Platform(s)
- BlackBerry OS 5.0+Description
Sends a join request to a user hosting a public connection for others to join.
The host does not need to be a contact of the current user.
Reasons why a request is declined
"hostdeclined"
: The host declined without a specific reason."hostppidinvalid"
: The host PPID is invalid."appnotrunning"
: The host's application was not running when they received the request."connectionnotfound"
: The host is not hosting on any connection, or stopped hosting on the connection while the request was pending."connectionfull"
: The host's hosted connection is full.
Parameter | Type | Description |
---|---|---|
hostPIN | String |
The host PIN. Can be obtained by blackberry.identity.PIN
|
hostPPID | String |
The host PPID. Can be obtained by blackberry.bbm.platform.self.ppid .
|
onComplete | Function(request : blackberry.bbm.platform.io.BBMPlatformOutgoingJoinRequest) |
Invoked when the user finishes approving the join request.
request: The request sent to the host; undefined if the user aborted the join request.
|
onHostAccepted | Function(request : blackberry.bbm.platform.io.BBMPlatformOutgoingJoinRequest, cookie : String) |
Invoked when the join request is accepted by the host.
request: The accepted request. cookie: The cookie sent when the host accepted the join request in accept. undefined
if no cookie was provided.
|
onHostDeclined | Function(request : blackberry.bbm.platform.io.BBMPlatformOutgoingJoinRequest, reason : String) |
Invoked when the join request is declined by the host.
request: The declined request. reason: The reason that the request was declined. |
cookie |
String
Optional |
A custom parameter provided by the application. e.g. Their current game level. Max length of 128 characters. |
Throws | Description |
---|---|
IllegalStateException | If the current user has connected with the host in a connection but still attempts to send another join request to the host. |
IllegalArgumentException |
If hostPIN is invalid.
|
IllegalArgumentException |
If hostPPID is invalid.
|
IllegalArgumentException |
If cookie is longer than 128 characters.
|
onconnectionaccepted
static void onconnectionaccepted(connectionType : String, connection : blackberry.bbm.platform.io.Channel|blackberry.bbm.platform.io.Session, cookie : String) |
Supported Platform(s)
- BlackBerry OS 5.0+Description
Invoked when an incoming connection is accepted. There are two cases when this may happen:
- When an invitation is accepted in the BBM chat window.
- When a host accepts a join request.
This callback is required when using either invitation framework. It must be assigned before the call to register.
The application should assign callbacks to the connection in this method.
Parameter | Type | Description |
---|---|---|
connectionType | String |
The type of connection: "channel" or "session" .
|
connection | blackberry.bbm.platform.io.Channel | blackberry.bbm.platform.io.Session | The connection. |
cookie | String |
The cookie sent with the invitation. May be null .
|
ondataexpired
static void ondataexpired(user : blackberry.bbm.platform.users.BBMPlatformUser, data : String[]) |
Supported Platform(s)
- BlackBerry OS 5.0+Description
Invoked when pending data for an unreachable user has expired.
Parameter | Type | Description |
---|---|---|
user | blackberry.bbm.platform.users.BBMPlatformUser | The unreachable user. |
data | String[] | The data messages which expired. |
onuserreachable
static void onuserreachable(user : blackberry.bbm.platform.users.BBMPlatformUser) |
Supported Platform(s)
- BlackBerry OS 5.0+Description
Invoked when a contact has become reachable after a ContactUnreachableException was thrown.
Parameter | Type | Description |
---|---|---|
user | blackberry.bbm.platform.users.BBMPlatformUser | The user who has become reachable. |
Properties:
Property | Type | Description | Supported Platform(s) |
---|---|---|---|
hostRequests |
Static blackberry.bbm.platform.io.IncomingJoinRequest[] readonly |
Requests that the current user (host) has received on hostedConnection.
Requests in this list are in the pending state. New requests will be added to this list automatically. Requests that are accepted, denied, or canceled will be removed from this list automatically. The host can accept or decline a request using accept
and decline.
|
- BlackBerry OS 5.0+
|
hostedConnection |
Static blackberry.bbm.platform.io.Connection readonly |
The connection being hosted. undefined if no connection is being hosted.
Use host to host an existing connection.
|
- BlackBerry OS 5.0+
|
joinHostRequests |
Static blackberry.bbm.platform.io.OutgoingJoinRequest[] readonly |
Requests that the current user (peer) has sent to hosts using joinHost.
Requests in this list are in the pending state. New requests will be added to this list automatically. Requests that are accepted, denied, or canceled will be removed from this list automatically. The user can cancel a request using cancel.
|
- BlackBerry OS 5.0+
|