Logical Labs Multipeer Module

API Docs for: 1.0.0
Show:

Session Class

Module: Readme

A Session object enables and manages communication among all peers in a Multipeer Connectivity session.

Methods

disconnect

() Void

Available since 1.0.0

Disconnects the local peer from the session.

Returns:

Void:

openStream

(
  • params
)
OutputStream

Available since 1.0.0

Opens a byte stream to a nearby peer.

Parameters:

  • params Object
    • peer Peer
    • name String

      A name for the stream. This name is provided to the nearby peer.

Returns:

retrieveConnectionData

(
  • params
)
Void

Available since 1.0.0

Obtains connection data for the specified peer.

Parameters:

  • params Object
    • peer Peer
    • success Function

      Callback to call in case of success.

    • error Function

      Callback to call in case of error.

Returns:

Void:

sendData

(
  • params
)
Object

Available since 1.0.0

Sends a message encapsulated in a TiBuffer object to nearby peers.

Parameters:

  • params Object
    • peers Array

      An array of Peer objects.

    • mode Number

      The transmission mode to use (reliable or unreliable delivery -- see SEND_MODE_* constants).

    • data TiBuffer

      The message to send.

Returns:

Object:

This function returns an object that contains the standard errorCode, errorDomain, and errorMessage properties in case a problem occurs. The object will not have any properties otherwise.

sendResource

(
  • params
)
Void

Available since 1.0.0

Sends the contents of a file or HTTP URL to a peer.

Parameters:

  • params Object
    • peer Peer
    • name String
    • [file] TiFile optional

      The file to send. Optional, but either this, or the url parameter must be specified.

    • [url] String optional

      The HTTP URL whose content to send. Optional, but either this, or the file parameter must be specified.

    • success Function

      Callback to call in case of success.

    • error Function

      Callback to call in case of error.

    • progress Function

      Callback to call with progress indicator.

Returns:

Void:

Properties

connectedPeers

Array of Peer objects read-only

Available since 1.0.0

An array of all peers that are currently connected to this session.

encryptionPreference

Array of Peer objects read-only

Available since 1.0.0

Indicates whether the connection prefers encrypted connections, unencrypted connections, or has no preference.

peer

Peer read-only

Available since 1.0.0

The Peer object associated with this session.

Events

peerStateChanged

Available since 1.0.0

Fired when the state of a nearby peer changes.

Event Payload:

  • peer Peer

    The sending peer.

  • state Number

    See the SESSION_STATE_* constants.

receivedData

Available since 1.0.0

Fired when data is received from a peer.

Event Payload:

  • peer Peer

    The sending peer.

  • data TiBuffer

receivedResource

Available since 1.0.0

Indicates that the local peer finished receiving a resource from a nearby peer.

Event Payload:

  • peer Peer

    The sending peer.

  • name String

    Name of the resource as provided by the sender.

  • url String

    Location of the received data.

  • file TiFile

    File object representing the received data.

receivedStream

Available since 1.0.0

Fired when a stream is received from a peer.

It is vitally important to assign the stream object carried by this event to a variable that will not be garbage collected for while the stream is in used; otherwise the application might crash!

Event Payload:

receivingResource

Available since 1.0.0

Indicates that the local peer started receiving a resource from a nearby peer. This event will be fired several times for each resource being received and can be used to indicate progress.

Event Payload:

  • peer Peer

    The sending peer.

  • name String

    Name of the resource as provided by the sender.

  • progress Number

    A number between 0.0 and 1.0 indicating progress.

streamBytesAvailable

Available since 1.0.0

This event is fired when the stream is ready for a read operation.

Note that, according to the Apple documentation, receiving this event is not an air-tight guarantee that there is actually data to be read. The streamReadCompleted may return 0 bytes.

Event Payload:

streamEndEncountered

Available since 1.0.0

This event is fired when the end of the stream is encountered.

Event Payload:

streamError

Available since 1.0.0

This event is fired when a stream related error occurs.

Event Payload:

streamOpenCompleted

Available since 1.0.0

This event is fired when the stream is opened.

Event Payload:

streamReadCompleted

Available since 1.0.0

This event is fired when a OutputStream/read:method operation completes.

Event Payload:

  • byteCount Number

    The number of bytes read from the stream; it may be 0 if no data was read, or -1 in case of an error.

  • buffer TiBuffer

    The data received from the stream.

  • stream InputStream

streamSpaceAvailable

Available since 1.0.0

This event is fired when the stream is ready for a write operation.

Note that, according to the Apple documentation, receiving this event is not an air-tight guarantee that the write will actually succeed. Check the byteCount property of the streamWriteCompleted event to verify how much data, if any, was actually written.

Event Payload:

streamWriteCompleted

Available since 1.0.0

This event is fired when a write operation completes.

Event Payload:

  • stream OutputStream
  • byteCount Number

    The number of bytes written to the stream; it may be 0 if no data was written, or -1 in case of an error.