To connect to Stringee Server, third-party authentication is required as described in Client authentication.
For testing, go to Dashboard -> Tools -> Generate Access token and generate an access_token. In production, the access_token should be generated by your server. See the access token examples.
import {StringeeClient, StringeeClientListener} from 'stringee-react-native-v2';
...
const stringeeClient = new StringeeClient();
// Listen for the StringeeClient event
const stringeeClientListener = new StringeeClientListener();
// Invoked when the StringeeClient is connected
stringeeClientListener.onConnect = (stringeeClient, userId) => {
console.log('onConnect: ', userId);
};
// Invoked when the StringeeClient is disconnected
stringeeClientListener.onDisConnect = (stringeeClient) => {
console.log('onDisConnect');
};
// Invoked when the StringeeClient connection fails
stringeeClientListener.onFailWithError = (stringeeClient, code, message) => {
console.log('onFailWithError: ', message);
};
// Invoked when your token is expired
stringeeClientListener.onRequestAccessToken = (stringeeClient) => {
console.log('onRequestAccessToken');
};
// Invoked when an incoming StringeeCall is received
stringeeClientListener.onIncomingCall = (stringeeClient, stringeeCall) => {
console.log('onIncomingCall: ', JSON.stringify(stringeeCall));
};
// Invoked when an incoming StringeeCall2 is received
stringeeClientListener.onIncomingCall2 = (stringeeClient, stringeeCall2) => {
console.log('onIncomingCall2: ', JSON.stringify(stringeeCall2));
};
// Invoked when conversation or message update
stringeeClientListener.onObjectChange = (stringeeClient, objectType, objectChanges, changeType) => {
console.log('onObjectChange: ', objectType, objectChanges, changeType);
};
stringeeClient.setListener(stringeeClientListener);
const token = 'PUT YOUR TOKEN HERE';
...
stringeeClient.connect(token);
You can disconnect Stringee Client by calling:
stringeeClient.disconnect();
Stringee stores the authenticated user's data (Conversations, Messages, Participants...) in a local database. Before authenticating as another user, disconnect the current client and clear its local database:
stringeeClient.disconnect();
stringeeClient.clearDb()
.then(() => {
console.log('clearDb success');
stringeeClient.connect(newUserToken);
})
.catch(console.log);