Suggestions

close search

StringeeClient

Represents a Stringee client, manages the client's connection. This component provides methods to connect to/disconnect from Stringee server, receives the connection's events, the incoming call event.

Props

eventHandlers: Object

Event handlers passed into the native StringeeClient instance. Example:


            clientEventHandlers = {
              onConnect: this._clientDidConnect,
              onDisConnect: this._clientDidDisConnect,
              onFailWithError: this._clientDidFailWithError,
              onRequestAccessToken: this._clientRequestAccessToken,
              onIncomingCall: this._callIncomingCall
            };
          

Events

onConnect : Function(userId: string, projectId: string, isReconnecting: boolean)

Invoked when the client connects to Stringee server:
- userId: It's the unique identification of the client on Stringee system.
- projectId: Id of your project.
- isReconnecting = YES: The client is reconnecting, isReconnecting = NO: The client connects first time.

onDisConnect : Function(userId: string, projectId: string, isReconnecting: boolean)

Invoked when the client connects to Stringee server:
- userId: It's the unique identification of the client on Stringee system.
- projectId: Id of your project.
- isReconnecting = YES: The client is reconnecting, isReconnecting = NO: The client connects first time.

onFailWithError : Function(userId: string, code: int, message: string)

Invoked when the client fails to connect to Stringee server:
- userId: It's the unique identification of the client on Stringee system.
- code = 1, message = "Access token is empty"
- code = 2, message = "Access token can not be decoded"
- code = 3, message = "Access token invalid format"
- code = 4, message = "Access token does not use HS256"
- code = 5, message = "API key sid or account sid not found"
- code = 6, message = "Access token expired or invalid"
- code = 7, message = "Access token invalid payload"
- code = 8, message = "Project not found"

onRequestAccessToken : Function()

Invoked when the access token is expired. You must get a new token and reconnect.

onIncomingCall : Function(userId: string, callId: string, from: string, to: string, fromAlias: string, toAlias: string, callType: int, isVideoCall: boolean, customDataFromYourServer: string)

Invoked when the client receives an incoming call:
- userId: It's the unique identification of the client on Stringee system.
- callId: The call's id generated by Stringee server.
- from: The caller's phone number or id.
- to: The callee's phone number or id.
- fromAlias: The alias of the caller.
- toAlias: The alias of the callee.
- callType: The type of the call:
    + callType = 0, App-to-app-outgoing-call
    + callType = 1, App-to-app-incoming-call
    + callType = 2, App-to-phone
    + callType = 3, Phone-to-app
- isVideoCall: Whether the call is a video call:
    + isVideoCall = true, a video call
    + isVideoCall = false, a voice call
- customDataFromYourServer: The custom data from your server when a client makes a call or receives an incoming call.

Functions

connect(token: string)

Connects to Stringee server with an access token:
- token: Your access token.

disconnect()

Disconnects from Stringee server.

registerPush(deviceToken: string, isProduction: boolean, isVoip: boolean, callback:(status, code, message))

Register device token to receive push notification. When you have an incoming call, you receive a notification from Stringee server:
- deviceToken: The token received from Apple's server when you register push notification to Apple (iOS).
- isProduction = true : For production environment, isProduction = false: For development environment (iOS).
- isVoip = true: To receive voip push notification, isVoip = false: To receive remote push notification (iOS).
- callback: The result of the registration:
    + status = true, code = 0, message = "Register successfully."
    + status = false, code = 1, message = "The Bundle Identifier has not been configured.".
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".
    + status = false, code = -2, message = "Data is empty.".
    + status = false, code = -3, message = "Generic error.".

unregisterPush(deviceToken: string, callback: (status, code, message))

Remove your device token from Stringee server. Your device will not receive push notification when you have an incoming call
- deviceToken: The device token which registered.
- callback: The result of unregistering
    + status = true, code = 0, message = "Unregister successfully."
    + status = false, code = 1, message = "The Bundle Identifier has not been configured.".
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".
    + status = false, code = -2, message = "Generic error".

sendCustomMessage(toUserId: string,message: string, callback: (status, code, message))

Send a custom message to a user
- toUserId: User's id whom send message to
- message: Custom message in JSON format
- callback: The result
    + status = true, code = 0, message = "Success"
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".
    + status = false, code = -2, message = "Generic error".

createConversation(userIds,options, callback: (status, code, message, conversation))

Construct a new conversation with the provided participants and options.
- userIds: Users' id of participants
- options: Conversation options to use when constructing this conversation
- callback: The result
    + status = true, code = 0, message = "Success"
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".
    + status = false, code = -2, message = "Generic error".
    + conversation: A conversation ready for messages.

getConversationById(conversationId: String, callback: (status, code, message, conversation))

Return the existing conversation with given ID.
- conversationId: Conversation ID
- callback: The result
    + status = true, code = 0, message = "Success"
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".
    + status = false, code = -2, message = "Generic error".
    + conversation: The existing conversation.

getLocalConversations(userId: String, count: String, callback: (status, code, message, conversations))

Return stored conversations.
- userId: Your user ID
- count: Number of conversations you want to get
- callback: The result
    + status = true, code = 0, message = "Success"
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".
    + status = false, code = -2, message = "User id can not be null".
    + conversations: A list of conversations.

getLastConversations(count: String, callback: (status, code, message, conversations))

Return latest conversations from server.
- count: Number of conversations you want to get
- callback: The result
    + status = true, code = 0, message = "Success"
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".
    + conversations: A list of conversations.

getConversationsAfter(datetime: long, count: String, callback: (status, code, message, conversations))

Return a list of conversations which have updated time greater than datetime from server.
- datetime: A timestamp
- count: Number of conversations you want to get
- callback: The result
    + status = true, code = 0, message = "Success"
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".
    + conversations: A list of conversations.

getConversationsBefore(datetime: long, count: String, callback: (status, code, message, conversations))

Return a list of conversations which have updated time smaller than datetime from server.
- datetime: A timestamp
- count: Number of conversations you want to get
- callback: The result
    + status = true, code = 0, message = "Success"
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".
    + conversations: A list of conversations.

deleteConversation(conversationId: String, callback: (status, code, message))

Delete a conversation
- conversationId: The conversation ID
- callback: The result
    + status = true, code = 0, message = "Success"
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".

addParticipants(conversationId: String, userIds: array, callback: (status, code, message, users))

Add participants to a conversation
- conversationId: The conversation ID
- userIds: Users' ID of participants
- callback: The result
    + status = true, code = 0, message = "Success"
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".
    + users: A list of added participants

removeParticipants(conversationId: String, userIds: array, callback: (status, code, message, users))

Remove participants from a conversation
- conversationId: The conversation ID
- userIds: Users' ID of participants
- callback: The result
    + status = true, code = 0, message = "Success"
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".
    + users: A list of removed participants

markConversationAsRead(conversationId: String, callback: (status, code, message))

Mark a conversation as read
- conversationId: The conversation ID
- callback: The result
    + status = true, code = 0, message = "Success"
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".

sendMessage(message: map, callback: (status, code, message))

Send a message
- message: Message to send
- callback: The result
    + status = true, code = 0, message = "Success"
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".

deleteMessage(conversationId: String, messageId: String, callback: (status, code, message))

Delete a message in a conversation
- conversationId: The conversation ID
- messageId: The message ID
- callback: The result
    + status = true, code = 0, message = "Success"
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".

getLocalMessages(conversationId: String, count: int, callback: (status, code, message,messages))

Return stored messages of a conversation
- conversationId: The conversation ID
- count: Number of messages you want to get ID
- callback: The result
    + status = true, code = 0, message = "Success"
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".
    + messages: A list of messages

getLastMessages(conversationId: String, count: int, callback: (status, code, message,messages))

Return latest messages of a conversation from server
- conversationId: The conversation ID
- count: Number of messages you want to get ID
- callback: The result
    + status = true, code = 0, message = "Success"
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".
    + messages: A list of messages

getMessagesAfter(conversationId: String, seq: long, count: int, callback: (status, code, message,messages))

Return a list of messages of a conversation from server which have sequence greater than seq
- conversationId: The conversation ID
- seq: A sequence
- count: Number of messages you want to get ID
- callback: The result
    + status = true, code = 0, message = "Success"
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".
    + messages: A list of messages

getMessagesBefore(conversationId: String, seq: long, count: int, callback: (status, code, message,messages))

Return a list of messages of a conversation from server which have sequence smaller than seq
- conversationId: The conversation ID
- seq: A sequence
- count: Number of messages you want to get ID
- callback: The result
    + status = true, code = 0, message = "Success"
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".
    + messages: A list of messages

clearDb(callback: (status, code, message))

Clear local database
- callback: The result
    + status = true, code = 0, message = "Success"
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".

updateConversation(conversationId: String, params: map, callback: (status, code, message))

Update a conversation
- conversationId: The conversation ID
- params: {name: ?, avatar: ?}
- callback: The result
    + status = true, code = 0, message = "Success"
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".
    + status = false, code = -2, message = "Conversation ID can not be null".