public class NexmoClient
extends java.lang.Object
A session is the period during which your app is connected to NexmoConversation API. Sessions are established for the length of time given when the authToken was created.
Tokens also have a lifetime and can optionally be one-shot which will allow a single login only, before the authToken becomes invalid for another login attempt. If the authToken is revoked while a session is active the session may be terminated by the server. It is only possible to have a single session active over a socket.io connection at a time. Session multiplexing is not supported.
Note: The connection uses socket.io for both web and mobile clients. Upon a successful socket.io connection the client needs to authenticate itself. This is achieved by sending a login request vialogin(String, NexmoRequestListener)
.
Unless otherwise specified, all the methods invoked by this client are executed asynchronously.
For the security of your Nexmo account, you should not embed directly your NexmoConversation credential authToken as strings in the app you submit to the Google Play Store.
First step is to acquire a NexmoClient
instance based on user credentials.
To construct a NexmoClient
the required parameters are:
Remember to logout when needed in order to remove current user and disconnect from the underlying connection.
Example usage:
myClient.logout(new IRequestListener() { @Override public void onSuccess() { // Update the application UI here if needed. } @Override public void onError(NexmoAPIError error) { // Update the application UI here if needed. } });
Initiate Calls for array of userIds or phone numbers.
Example usage:
myClient.call(List(Arrays.asList("phoneNumber")), NexmoCallHandler.IN_APP, new IRequestListener() { @Override public void onSuccess(NexmoCall call) { // Update the application UI here if needed. } @Override public void onError(NexmoAPIError error) { // Update the application UI here if needed. } });
..... todo more example usage
Modifier and Type | Class and Description |
---|---|
static class |
NexmoClient.NexmoClientBuilder |
static class |
NexmoClient.NexmoClientConfig
POJO which contains current configuration (has to be built by Builder).
|
Modifier and Type | Method and Description |
---|---|
void |
addIncomingCallListener(NexmoIncomingCallListener incomingCallListener)
add Listener to incoming NexmoCall
|
void |
addNewConversationListener(NexmoNewConversationListener newConversationListener)
add Listener to incoming NexmoConversation.
|
void |
call(java.util.List<java.lang.String> users,
NexmoCallHandler callType,
com.nexmo.client.request_listener.NexmoRequestListener<NexmoCall> listener)
Initiate a NexmoCall.
|
void |
disablePushNotifications(com.nexmo.client.request_listener.NexmoRequestListener<java.lang.Void> listener) |
void |
enablePushNotifications(java.lang.String deviceToken,
com.nexmo.client.request_listener.NexmoRequestListener<java.lang.Void> listener) |
static NexmoClient |
get() |
NexmoClient.NexmoClientConfig |
getConfig()
Get config used to build
NexmoClient . |
Context |
getContext()
Get the context we used for building
NexmoClient . |
void |
getConversation(java.lang.String conversationId,
com.nexmo.client.request_listener.NexmoRequestListener<NexmoConversation> listener)
Get conversation information based on unique ID.
|
void |
getConversations(com.nexmo.client.request_listener.NexmoRequestListener<java.util.Collection<NexmoConversation>> listener)
Fetch conversation list for the logged in user.
|
NexmoCoreEventsListenersManager |
getNexmoCoreEventsListenersManager() |
java.lang.String |
getSDKVersion()
Returns the current version of the Nexmo Stitch SDK.
|
java.lang.String |
getToken()
Get the last used jwt token for logging in the NexmoUser, synchronously.
|
NexmoUser |
getUser()
Get the current logged in NexmoUser, synchronously.
|
void |
getUser(java.lang.String userId,
com.nexmo.client.request_listener.NexmoRequestListener<NexmoUser> listener)
Get user info for given userId.
|
static NexmoClient |
init(NexmoClient.NexmoClientConfig config,
Context context,
com.nexmo.client.request_listener.NexmoLoginListener loginListener) |
static boolean |
isNexmoPushNotification(java.util.Map<java.lang.String,java.lang.String> data) |
void |
login(java.lang.String token,
com.nexmo.client.request_listener.NexmoRequestListener<NexmoUser> listener)
Login this
NexmoClient instance based on the builder information and login details. |
void |
logout()
Logout current NexmoUser.
|
void |
newConversation(java.lang.String conversationName,
java.lang.String conversationDisplayName,
com.nexmo.client.request_listener.NexmoRequestListener<NexmoConversation> listener)
Create a new
Conversation for a given display name. |
void |
processPushNotification(java.util.Map<java.lang.String,java.lang.String> data,
NexmoPushEventListener listener) |
void |
removeIncomingCallListeners() |
void |
removeNewConversationListener() |
public static NexmoClient init(NexmoClient.NexmoClientConfig config, Context context, com.nexmo.client.request_listener.NexmoLoginListener loginListener)
public static NexmoClient get()
public java.lang.String getSDKVersion()
public NexmoClient.NexmoClientConfig getConfig()
NexmoClient
.public Context getContext()
NexmoClient
.public final NexmoUser getUser()
public java.lang.String getToken()
public void login(java.lang.String token, com.nexmo.client.request_listener.NexmoRequestListener<NexmoUser> listener)
NexmoClient
instance based on the builder information and login details.
Depending on the validity of the supplied token, NexmoLoginListener#onLoginStateChange(NexmoLoginListener.ELoginState, NexmoLoginListener.ELoginStateReason)
can be fired for:
NexmoLoginListener.ELoginStateReason#INVALID_TOKEN
. Supplied token is not valid, your application needs to retrieve another one in order to complete login.NexmoLoginListener.ELoginStateReason#EXPIRED_TOKEN
. Supplied token has expired, your application needs to retrieve another one in order to complete login.Required parameters are:
token
- The backend authorization jwt.public void logout()
Logout also:
public void getUser(java.lang.String userId, com.nexmo.client.request_listener.NexmoRequestListener<NexmoUser> listener)
userId
- The id of user.listener
- The request completion listener.public void enablePushNotifications(java.lang.String deviceToken, com.nexmo.client.request_listener.NexmoRequestListener<java.lang.Void> listener)
public void disablePushNotifications(com.nexmo.client.request_listener.NexmoRequestListener<java.lang.Void> listener)
public static boolean isNexmoPushNotification(java.util.Map<java.lang.String,java.lang.String> data)
public void processPushNotification(java.util.Map<java.lang.String,java.lang.String> data, NexmoPushEventListener listener)
public void newConversation(java.lang.String conversationName, java.lang.String conversationDisplayName, com.nexmo.client.request_listener.NexmoRequestListener<NexmoConversation> listener)
Conversation
for a given display name.
In order for a User
to be able to be part of a Conversation
, he must either:
NexmoConversation.join(String, NexmoRequestListener)
conversationName
- The optional conversation name, it's case-insensitive. If not provided, a name will be auto-generated.conversationDisplayName
- The optional conversation display name. If not provided, will be left empty.listener
- The request completion listener.public void getConversation(java.lang.String conversationId, com.nexmo.client.request_listener.NexmoRequestListener<NexmoConversation> listener)
conversationId
- The unique conversation ID.public void getConversations(com.nexmo.client.request_listener.NexmoRequestListener<java.util.Collection<NexmoConversation>> listener)
A NexmoMember is part of a Conversation
if he/she:
Note: there is a limitation of currently 30 conversations that can be fetched.
listener
- The listener in charge of dispatching the result.
TODO add filtering and pagination once CS-994 is done
public void call(java.util.List<java.lang.String> users, NexmoCallHandler callType, com.nexmo.client.request_listener.NexmoRequestListener<NexmoCall> listener)
users
- Array of userIds or phone numbers to invite to the NexmoCall.callType
- NexmoCall can be initiated through IN_APP flow or SERVER flow.listener
- Completion listener.public void addIncomingCallListener(NexmoIncomingCallListener incomingCallListener)
incomingCallListener
- public void removeIncomingCallListeners()
public void addNewConversationListener(NexmoNewConversationListener newConversationListener)
newConversationListener
- public void removeNewConversationListener()
public NexmoCoreEventsListenersManager getNexmoCoreEventsListenersManager()