Class: Carrier

Carrier


new Carrier()

The class representing Carrier.

Source:

Members


address

Properties:
Name Type Description
address string

Node address.

Source:

nodeId

Properties:
Name Type Description
nodeId string

Node id.

Source:

nospam

Properties:
Name Type Description
nospam number

The nospam for Carrier address is used to eliminate spam friend.

Source:

presence

Properties:
Name Type Description
presence number

Presence status.

Source:

userId

Properties:
Name Type Description
userId string

User id.

Source:

Methods


acceptFriend(onSuccess [, onError], userId)

Accept the friend request.

This function is used to add a friend in response to a friend 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.

userId string

The user id who want be friend with us.

Source:

addFriend(onSuccess [, onError], address, hello)

Add friend by sending a new friend request.

This function will add a new friend with specific address, and then
send a friend request to the target node.

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.

address string

the target user address of remote carrier node.

hello string

PIN for target user, or any application defined content.

Source:

destroy(onSuccess [, onError])

Disconnect carrier node from carrier network, and destroy all associated resources to carreier node instance.
After calling the method, the carrier node instance becomes invalid.

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.

Source:

getFriend(onSuccess [, onError], userId)

Get specified friend information.

Parameters:
Name Type Argument Description
onSuccess function

The function to call when success, the param is a FriendInfo: The friend information.

onError function <optional>

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

userId string

The user identifier of friend

Source:

getFriends(onSuccess [, onError])

Get friends list.

Parameters:
Name Type Argument Description
onSuccess function

The function to call when success, the param is a {friendId: info} Object: The list of friend information to current user.

onError function <optional>

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

Source:

getSelfInfo(onSuccess [, onError])

Get self user information.

Parameters:
Name Type Argument Description
onSuccess function

The function to call when success, the param is a UserInfo: the user information to the carrier node.

onError function <optional>

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

Source:

inviteFriend(onSuccess [, onError], to, data, handler)

Send invite request to a friend.

Application can attach the application defined data with in the invite
request, and the data will send to target 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.

to string

The target id

data string

The application defined data send to target user

handler onFriendInviteResponse

The handler to receive invite reponse

Source:

isFriend(onSuccess [, onError], userId)

Check if the user ID is friend.

Parameters:
Name Type Argument Description
onSuccess function

The function to call when success, the param is a Boolean: True if the user is a friend, or false if not.

onError function <optional>

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

userId string

The userId to check.

Source:

isReady(onSuccess [, onError])

Check if carrier node instance is being ready.

All carrier interactive APIs should be called only if carrier node instance
is being ready.

Parameters:
Name Type Argument Description
onSuccess function

The function to call when success, the param is a Boolean: true if the carrier node instance is ready, or false if not.

onError function <optional>

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

Source:

labelFriend(onSuccess [, onError], userId, label)

Set the label of the specified friend.

The label of a friend is a private alias name for current user. It can be
seen by current user only, and has no impact to the target friend itself.

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.

userId string

The friend's user identifier

label string

The new label of specified friend

Source:

newSession(onSuccess [, onError], to)

Create a new session to a friend.

The session object represent a conversation handle to a friend.

Parameters:
Name Type Argument Description
onSuccess function

The function to call when success, the param is a Session Object: The new Session object

onError function <optional>

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

to string

The target id(userid or [email protected]).

Source:

on(name, callback)

Add or remove Carrier callback.

Parameters:
Name Type Description
name string

The callback name.

callback function

The function to add or change callback function. If set to null, will remove callback.

Source:

removeFriend(onSuccess [, onError], userId)

Remove a friend.

This function will remove a friend on this carrier node.

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.

userId string

The target user id to remove friendship

Source:

replyFriendInvite(onSuccess [, onError], to, status, reason, data)

Reply the friend invite request.

This function will send a invite 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.

to string

The id who send invite request

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

data string

The application defined data send to target user. If the status is error, this will be ignored

Source:

sendFriendMessage(onSuccess [, onError], to, message)

Send a message to a friend.

The message length may not exceed MAX_APP_MESSAGE_LEN, and message itself
should be text-formatted. Larger messages must be split by application
and sent as separate messages. Other nodes can reassemble the fragments.

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.

to string

The target id

message string

The message content defined by application

Source:

setSelfInfo(onSuccess [, onError], userinfo)

Update self user information.
After self user information changed, carrier node will update this information
to carrier network, and thereupon network broadcasts the change to all friends.

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.

userinfo UserInfo

The user information to update for this carrier node.

Source:

start(onSuccess [, onError], iterateInterval)

Start carrier node asynchronously to connect to carrier network. If the connection
to network is successful, carrier node starts working.

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.

iterateInterval number

Internal loop interval, in milliseconds.

Source: