Connecting the Stringee Client to Stringee's server allows authentication to procede and data to flow.
The Stringee Client is initialized with a context.
Only one instance of StringeeClient should be instantiated and used at all times.
render() {
return (
<View style={styles.container}>
<StringeeClient ref="client"/>
</View>
);
}
StringeeClient uses listner pattern to notify your app about specific events. You need to implement listeners for connection and object (Conversation, Message) change events.
constructor(props) {
super(props);
this.clientEventHandlers = {
onConnect: this._clientDidConnect,
onDisConnect: this._clientDidDisConnect,
onFailWithError: this._clientDidFailWithError,
onRequestAccessToken: this._clientRequestAccessToken,
onIncomingCall: this._callIncomingCall,
onObjectChange: this.onObjectChange
};
}
render() {
return (
<View style={styles.container}>
<StringeeClient ref="client" eventHandlers={this.clientEventHandlers} />
</View>
);
}
Once you have initialized Stringee Client and registered listeners, connect the SDK:
async componentDidMount() {
await this.refs.client.connect("your_access_token");
}
See Authentication to get your access token.
You can disconnect Stringee Client by calling:
this.refs.client.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:
this.refs.client.clearDb((status, code, message) => {
console.log("status-" + status + " code-" + code + " message-" + message);
});