Suggestions

close search

StringeeClient

public class StringeeClient



Represents a Stringee client, manages connection, call, chat, and room events.



Summary


Constructors
Constructor StringeeClient({List<StringeeServerAddress>? serverAddresses, String? baseAPIUrl})

Creates a StringeeClient instance.

Properties
String? userId

Current connected user id.

String? projectId

Current project id.

bool hasConnected

Whether the client is connected.

bool isReconnecting

Whether the current connection event is a reconnect.

StreamController<dynamic> eventStreamController

Stream of client, call, chat, and room events for this client instance.

String uuid

Unique native client instance id.

Events
StringeeClientEvents didConnect

Invoked when the client connects successfully.

StringeeClientEvents didDisconnect

Invoked when the client disconnects.

StringeeClientEvents didFailWithError

Invoked when connection fails; body contains code and message.

StringeeClientEvents requestAccessToken

Invoked when a new access token is required.

StringeeClientEvents tokenWillExpire

Invoked about 60 seconds before the access token expires.

StringeeClientEvents didReceiveCustomMessage

Invoked when the client receives a custom message.

StringeeClientEvents incomingCall

Invoked for an incoming StringeeCall.

StringeeClientEvents incomingCall2

Invoked for an incoming StringeeCall2.

StringeeClientEvents didReceiveChatRequest

Invoked when a live chat request is received.

StringeeClientEvents didReceiveTransferChatRequest

Invoked when a transferred live chat request is received.

StringeeClientEvents timeoutAnswerChat

Invoked when answering a chat request times out.

StringeeClientEvents timeoutInQueue

Invoked when the visitor times out in queue.

StringeeClientEvents conversationEnded

Invoked when a conversation is ended.

StringeeClientEvents userBeginTyping

Invoked when a user begins typing.

StringeeClientEvents userEndTyping

Invoked when a user ends typing.

Public methods
Future<Map<dynamic, dynamic>> connect(String token)

Connects this client with an access token.

Future<Map<dynamic, dynamic>> updateToken(String token)

Renews the access token on the open connection without reconnecting.

Future<Map<dynamic, dynamic>> disconnect()

Disconnects this client from Stringee.

Future<Map<dynamic, dynamic>> registerPush(String deviceToken, {bool? isProduction, bool? isVoip})

Registers a push notification token.

Future<Map<dynamic, dynamic>> registerPushAndDeleteOthers(String deviceToken, List<String> packageNames, {bool? isProduction, bool? isVoip})

Registers a push token and removes tokens from the provided package names.

Future<Map<dynamic, dynamic>> unregisterPush(String deviceToken)

Unregisters a push notification token.

Future<Map<dynamic, dynamic>> sendCustomMessage(String userId, Map<dynamic, dynamic> customData)

Sends custom data to a Stringee user.

Future<Result> existCall(String callId)

Checks whether a call exists on the Stringee server.

Constructors


StringeeClient({List<StringeeServerAddress>? serverAddresses, String? baseAPIUrl})
Creates a StringeeClient instance.

Properties


userId
Current connected user id.
projectId
Current project id.
hasConnected
Whether the client is connected.
isReconnecting
Whether the current connection event is a reconnect.
eventStreamController
Stream of client, call, chat, and room events for this client instance.
uuid
Unique native client instance id.

Events


didConnect
Invoked when the client connects successfully.
didDisconnect
Invoked when the client disconnects.
didFailWithError
Invoked when connection fails; body contains code and message.
requestAccessToken
Invoked when a new access token is required: the token was rejected, or it expired without being renewed and the server closed the connection. The SDK does not reconnect by itself; call connect(newToken) on the same client with a new token from your server to resume the session.
tokenWillExpire
Invoked about 60 seconds before the access token expires. Fetch a new token for the same user from your server and pass it to updateToken to keep the connection open. If the token is not renewed, the server closes the connection when it expires and requestAccessToken is invoked. Available from plugin 1.3.4 (Android SDK 2.1.18, iOS SDK 2.2.0).
body: Map with exp (int, token expiry time in epoch seconds) and expireInSeconds (int, seconds left before the token expires).
didReceiveCustomMessage
Invoked when the client receives a custom message.
incomingCall
Invoked for an incoming StringeeCall.
incomingCall2
Invoked for an incoming StringeeCall2.
didReceiveChatRequest
Invoked when a live chat request is received.
didReceiveTransferChatRequest
Invoked when a transferred live chat request is received.
timeoutAnswerChat
Invoked when answering a chat request times out.
timeoutInQueue
Invoked when the visitor times out in queue.
conversationEnded
Invoked when a conversation is ended.
userBeginTyping
Invoked when a user begins typing.
userEndTyping
Invoked when a user ends typing.

Public methods


connect(String token)
Connects this client with an access token.
updateToken(String token)
Renews the access token on the open connection without reconnecting. Call it after tokenWillExpire. On success the SDK keeps the new token, also for automatic reconnects. On failure the connection stays open until the current token expires. Available from plugin 1.3.4 (Android SDK 2.1.18, iOS SDK 2.2.0).
token: new access token for the same user and project.
Returns Map with status (bool), code (int) and message (String). The codes are the same on Android and iOS:
CodeDescription
0Success.
> 0Server error: 6 expired token, 10 invalid signature, 17 token for another user or project.
-1Not connected.
-2Empty token.
-4No server response within 10 seconds.
-5The server has not requested token renewal on this connection: call it only after tokenWillExpire.
disconnect()
Disconnects this client from Stringee.
registerPush(String deviceToken, {bool? isProduction, bool? isVoip})
Registers a push notification token.
registerPushAndDeleteOthers(String deviceToken, List<String> packageNames, {bool? isProduction, bool? isVoip})
Registers a push token and removes tokens from the provided package names.
unregisterPush(String deviceToken)
Unregisters a push notification token.
sendCustomMessage(String userId, Map<dynamic, dynamic> customData)
Sends custom data to a Stringee user.
existCall(String callId)
Checks whether a call exists on the Stringee server.