Session Class
A Session object enables and manages communication among all peers in a Multipeer Connectivity session.
Item Index
Properties
Methods
disconnect
()
Void
Disconnects the local peer from the session.
Returns:
openStream
-
params
Opens a byte stream to a nearby peer.
Parameters:
-
params
Object-
peer
Peer -
name
StringA name for the stream. This name is provided to the nearby peer.
-
Returns:
retrieveConnectionData
-
params
Obtains connection data for the specified peer.
Parameters:
-
params
Object-
peer
Peer -
success
FunctionCallback to call in case of success.
-
error
FunctionCallback to call in case of error.
-
Returns:
sendData
-
params
Sends a message encapsulated in a TiBuffer object to nearby peers.
Parameters:
-
params
Object-
peers
ArrayAn array of Peer objects.
-
mode
NumberThe transmission mode to use (reliable or unreliable delivery -- see SEND_MODE_* constants).
-
data
TiBufferThe message to send.
-
Returns:
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
Sends the contents of a file or HTTP URL to a peer.
Parameters:
-
params
Object-
peer
Peer -
name
String -
[file]
TiFile optionalThe file to send. Optional, but either this, or the
url
parameter must be specified. -
[url]
String optionalThe HTTP URL whose content to send. Optional, but either this, or the
file
parameter must be specified. -
success
FunctionCallback to call in case of success.
-
error
FunctionCallback to call in case of error.
-
progress
FunctionCallback to call with progress indicator.
-
Returns:
Properties
connectedPeers
Array of Peer objects
read-only
An array of all peers that are currently connected to this session.
encryptionPreference
Array of Peer objects
read-only
Indicates whether the connection prefers encrypted connections, unencrypted connections, or has no preference.
Events
peerStateChanged
Fired when the state of a nearby peer changes.
Event Payload:
-
peer
PeerThe sending peer.
-
state
NumberSee the SESSION_STATE_* constants.
receivedData
Fired when data is received from a peer.
Event Payload:
-
peer
PeerThe sending peer.
-
data
TiBuffer
receivedResource
Indicates that the local peer finished receiving a resource from a nearby peer.
Event Payload:
-
peer
PeerThe sending peer.
-
name
StringName of the resource as provided by the sender.
-
url
StringLocation of the received data.
-
file
TiFileFile object representing the received data.
receivedStream
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:
-
peer
PeerThe sending peer.
-
stream
InputStream -
streamName
String
receivingResource
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
PeerThe sending peer.
-
name
StringName of the resource as provided by the sender.
-
progress
NumberA number between 0.0 and 1.0 indicating progress.
streamBytesAvailable
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:
-
stream
InputStream
streamEndEncountered
This event is fired when the end of the stream is encountered.
Event Payload:
-
stream
StreamAn InputStream or OutputStream object.
streamError
This event is fired when a stream related error occurs.
Event Payload:
-
stream
StreamAn InputStream or OutputStream object.
streamOpenCompleted
This event is fired when the stream is opened.
Event Payload:
-
stream
StreamAn InputStream or OutputStream object.
streamReadCompleted
This event is fired when a OutputStream/read:method operation completes.
Event Payload:
-
byteCount
NumberThe number of bytes read from the stream; it may be 0 if no data was read, or -1 in case of an error.
-
buffer
TiBufferThe data received from the stream.
-
stream
InputStream
streamSpaceAvailable
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:
-
stream
OutputStream
streamWriteCompleted
This event is fired when a write operation completes.
Event Payload:
-
stream
OutputStream -
byteCount
NumberThe number of bytes written to the stream; it may be 0 if no data was written, or -1 in case of an error.