Connecting the Stringee Client to Stringee's server allows authentication to proceed 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.
constructor(props) {
super(props);
...
this.client = createRef();
...
}
...
render() {
return (
<View style={styles.container}>
<StringeeClient ref={this.client}/>
</View>
);
}
StringeeClient uses a listener 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,
onObjectChange: this.onObjectChange
onUserBeginTyping: this.onUserBeginTyping,
onUserEndTyping: this.onUserEndTyping,
};
}
render() {
return (
<View style={styles.container}>
<StringeeClient ref={this.client} eventHandlers={this.clientEventHandlers} />
</View>
);
}
Once you have initialized the Stringee Client and registered listeners, connect the SDK:
async componentDidMount() {
await this.client.current.connect("your_access_token");
}
See Authentication to get your access token.
You can disconnect Stringee Client by calling:
this.client.current.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.client.current.clearDb((status, code, message) => {
console.log("status-" + status + " code-" + code + " message-" + message);
});