In order to connect to Stringee Server, 3-parties authentication is required as described here: Client authentication
For testing purpose, go to Dashboard -> Tools -> Generate Access token and generates an access_token. In production, the access_token should be generated by your server, sample code generates access token here: https://github.com/stringeecom/server-samples/tree/master/access_token
import {StringeeClient} from 'stringee-react-native-v2';
...
const stringeeClient: StringeeClient = new StringeeClient();
// Listen for the StringeeClient event
const stringeeClientListener: 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 StringeeClient connect false
stringeeClientListener.onFailWithError = (stringeeClient, code, message) => {
console.log('onFailWithError: ', message);
};
// Invoked when your token is expired
stringeeClientListener.onRequestAccessToken = (stringeeClient) => {
console.log('onRequestAccessToken');
};
// Invoked when receive an incoming of StringeeCall
stringeeClientListener.onIncomingCall = (stringeeClient, stringeeCall) => {
console.log('onIncomingCall: ', JSON.stringify(stringeeCall));
};
// Invoked when receive an incoming of StringeeCall2
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);
token: string = '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. If your app wants to authenticate with another user, you must clear the local database first by calling:
stringeeClient.clearDb()
.then(() => {
console.log('clearDb success');
})
.catch(console.log);