Suggestions

close search

Connecting

Connecting the Stringee Client to Stringee's server allows authentication to procede and data to flow.

How to do it

The Stringee Client is initialized with a context.

1. Create client

Only one instance of StringeeClient should be instantiated and used at all times.

  render() {
    return (
      <View style={styles.container}>
        <StringeeClient ref="client"/>
      </View>
    );
  }

2. Listners

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>
    );
  }

3. Connect client

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.

4. Disconnect client

You can disconnect Stringee Client by calling:

this.refs.client.disconnect();

5. Local database

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);
    });