Suggestions

close search

Connecting

Connecting the Stringee Client to the Stringee server allows authentication to proceed 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.

  // global
  var stringeeClient;

  // Init
  stringeeClient = new StringeeClient();

2. Listners

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.

  stringeeClient.on('connect', function () {
    console.log('++++++++++++++ connected to StringeeServer');
  });

  stringeeClient.on('authen', function (res) {
    console.log('authen', res);
  });

  stringeeClient.on('disconnect', function () {
    console.log('++++++++++++++ disconnected');
  });

3. Connect client

Once you have initialized Stringee Client and registered listeners, connect the SDK:

    stringeeClient.connect('YOUR_ACCESS_TOKEN');

See Authentication to get your access token.

4. Disconnect client

You can disconnect Stringee Client by calling:

  stringeeClient.disconnect();