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:
-
paramsObject-
peerPeer -
nameStringA name for the stream. This name is provided to the nearby peer.
-
Returns:
retrieveConnectionData
-
params
Obtains connection data for the specified peer.
Parameters:
-
paramsObject-
peerPeer -
successFunctionCallback to call in case of success.
-
errorFunctionCallback to call in case of error.
-
Returns:
sendData
-
params
Sends a message encapsulated in a TiBuffer object to nearby peers.
Parameters:
-
paramsObject-
peersArrayAn array of Peer objects.
-
modeNumberThe transmission mode to use (reliable or unreliable delivery -- see SEND_MODE_* constants).
-
dataTiBufferThe 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:
-
paramsObject-
peerPeer -
nameString -
[file]TiFile optionalThe file to send. Optional, but either this, or the
urlparameter must be specified. -
[url]String optionalThe HTTP URL whose content to send. Optional, but either this, or the
fileparameter must be specified. -
successFunctionCallback to call in case of success.
-
errorFunctionCallback to call in case of error.
-
progressFunctionCallback 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:
-
peerPeerThe sending peer.
-
stateNumberSee the SESSION_STATE_* constants.
receivedData
Fired when data is received from a peer.
Event Payload:
-
peerPeerThe sending peer.
-
dataTiBuffer
receivedResource
Indicates that the local peer finished receiving a resource from a nearby peer.
Event Payload:
-
peerPeerThe sending peer.
-
nameStringName of the resource as provided by the sender.
-
urlStringLocation of the received data.
-
fileTiFileFile 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:
-
peerPeerThe sending peer.
-
streamInputStream -
streamNameString
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:
-
peerPeerThe sending peer.
-
nameStringName of the resource as provided by the sender.
-
progressNumberA 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:
-
streamInputStream
streamEndEncountered
This event is fired when the end of the stream is encountered.
Event Payload:
-
streamStreamAn InputStream or OutputStream object.
streamError
This event is fired when a stream related error occurs.
Event Payload:
-
streamStreamAn InputStream or OutputStream object.
streamOpenCompleted
This event is fired when the stream is opened.
Event Payload:
-
streamStreamAn InputStream or OutputStream object.
streamReadCompleted
This event is fired when a OutputStream/read:method operation completes.
Event Payload:
-
byteCountNumberThe number of bytes read from the stream; it may be 0 if no data was read, or -1 in case of an error.
-
bufferTiBufferThe data received from the stream.
-
streamInputStream
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:
-
streamOutputStream
streamWriteCompleted
This event is fired when a write operation completes.
Event Payload:
-
streamOutputStream -
byteCountNumberThe number of bytes written to the stream; it may be 0 if no data was written, or -1 in case of an error.
