Class: Session

Session


new Session()

The class representing Carrier Session.

Source:

Members


carrier

Properties:
Name Type Description
carrier Carrier

Parent carrier object.

Source:

peer

Properties:
Name Type Description
peer string

The remote peer userid.

Source:

Methods


addService(onSuccess [, onError], service, protocol, host, port)

Add a new portforwarding service to session.

The registered services can be used by remote peer in portforwarding request.

Parameters:
Name Type Argument Description
onSuccess function

The function to call when success.

onError function <optional>

The function to call when error, the param is a String. Or set to null.

service string

The new service name, should be unique in session scope.

protocol PortForwardingProtocol

The protocol of the service.

host string

The host name or ip of the service.

port number

The port of the service.

Source:

addStream(onSuccess [, onError], type, options, callbacks)

Add a new stream to session.

Carrier stream supports several underlying transport mechanisms:

  • Plain/encrypted UDP data gram protocol
  • Plain/encrypted TCP like reliable stream protocol
  • Multiplexing over UDP
  • Multiplexing over TCP like reliable protocol

Application can use options to specify the new stream mode.
Multiplexing over UDP can not provide reliable transport.

Parameters:
Name Type Argument Description
onSuccess function

The function to call when success, the param is a Stream object: The new added carrier stream.

onError function <optional>

The function to call when error, the param is a String. Or set to null.

type StreamType

The stream type defined in StreamType

options number

The stream mode options. options are constructed by a bitwise-inclusive OR of flags

callbacks StreamCallbacks

The stream callbacks.

Source:

close()

Close a session to friend. All resources include streams, channels, portforwardings
associated with current session will be destroyed.

Source:

removeService(onSuccess [, onError], service)

Remove a portforwarding server to session.

This function has not effect on existing portforwarings.

Parameters:
Name Type Argument Description
onSuccess function

The function to call when success.

onError function <optional>

The function to call when error, the param is a String. Or set to null.

service string

The service name.

Source:

removeStream(onSuccess [, onError], stream)

Remove a stream from session.

Parameters:
Name Type Argument Description
onSuccess function

The function to call when success.

onError function <optional>

The function to call when error, the param is a String. Or set to null.

stream stream

The Stream to be removed

Source:

replyRequest(onSuccess [, onError], status, reason)

Reply the session request from friend.

This function will send a session response to friend.

Parameters:
Name Type Argument Description
onSuccess function

The function to call when success.

onError function <optional>

The function to call when error, the param is a String. Or set to null.

status number

The status code of the response. 0 is success, otherwise is error

reason string

The error message if status is error, or null if success

Source:

request(onSuccess [, onError], handler)

Send session request to the friend.

Parameters:
Name Type Argument Description
onSuccess function

The function to call when success.

onError function <optional>

The function to call when error, the param is a String. Or set to null.

handler onSessionRequestComplete

A handler to the SessionRequestCompleteHandler to receive the session response

Source:

start(onSuccess [, onError], sdp)

Begin to start a session.

All streams in current session will try to connect with remote friend,
The stream status will update to application by stream's StreamHandler.

Parameters:
Name Type Argument Description
onSuccess function

The function to call when success.

onError function <optional>

The function to call when error, the param is a String. Or set to null.

sdp string

The remote user's SDP. Reference: https://tools.ietf.org/html/rfc4566

Source: