Logical Labs Multipeer Module

API Docs for: 1.0.0



The Logical Labs Multipeer module gives Titanium developers easy access to the Multipeer Connectivity Framework of the iOS SDK.

The module defines the following classes:

The names of these classes follow the naming convention of the Multipeer Connectivity Framework.

A peer is an entity representing the iOS device that participates in the multipeer communication. An iOS device can create multiple peer objects to have them represent it in multiple connections.

Peers use an advertiser to make themselves available to other devices, and a browser to find other devices that are available for connection.

A session is a connection between 2-8 devices.


The first step in using the Logical Labs Multipeer module is to load the module, create a peer object, and create a session tied to said peer object:

var Multipeer = require('com.logicallabs.multipeer');
localPeer = Multipeer.createPeer({
    name: Ti.Platform.username

session = localPeer.createSession({
    encryptionPreference: Multipeer.ENCRYPTION_REQUIRED

Then, depending whether you want your app to actively connect to other devices or merely wait for other devices to connect to it, you create a browser or an advertiser object using the createBrowser or createAdvertiser method, respectively.

The browser object will receive a peerFound event when a new peer is found; you can initiate a connection to the newly found peer using the invitePeer method:

browser = localPeer.createBrowser({
    serviceType: <<your service type>>

browser.addEventListener('peerFound', function(e) {
        peer: e.peer,
        session: session,

The advertiser will receive a receivedInvite event when an invitiation comes in; you can use the inviteResponse method to accept or reject the invite:

advertiser = localPeer.createAdvertiser({
    serviceType: <<your service type>>,

advertiser.addEventListener('receivedInvite', function(e) {
        inviteId: e.inviteId,
        accept: true,
        session: session

An alternative to creating a browser object is to use the built-in browser view. Use the showPicker function to present this view.

An alternative to creating an advertiser object is to use the createAdvertiserAssistant to create an AdvertiserAssistant object.

The session object on all sides of the connection will receive peerStateChanged events when a peer connects or disconnects from a session:

session.addEventListener('peerStateChanged', function(e) {
    switch (e.state) {
        case Multipeer.SESSION_STATE_CONNECTING:
        case Multipeer.SESSION_STATE_CONNECTED:
        case Multipeer.SESSION_STATE_NOT_CONNECTED:

While a peer is in connected state, you can send data to it in several ways:

  1. Using the sendData method.

  2. Using the sendResource method.

  3. By creating a stream using the openStream method and then writing to the stream using the write method.

The receiving side will be notified about the incoming data via various events:

  1. receivedData.

  2. receivingResource and receivedResource.

  3. receivedStream.

Issues and Limitations

Change Log

Version 1.0.0

  • First release


Zsombor Papp titanium@logicallabs.com


Logical Labs Commercial License

Copyright (c) 2014 by Logical Labs, LLC