Suggestions

close search

Connect to Stringee Server

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

  1. Initialize StringeeClient:

    import 'package:stringee_flutter_plugin/stringee_flutter_plugin.dart';
    ...
    StringeeClient _stringeeClient = StringeeClient();
  2. Register the client's events in your State

    /// Listen for the StringeeClient event
    _stringeeClient.registerEvent(StringeeClientListener(
      /// Invoked when the StringeeClient is connected
      onConnect: (stringeeClient, userId) {
         debugPrint('onConnect: $userId');
      },
      /// Invoked when the StringeeClient is disconnected
      onDisconnect: (stringeeClient) {
         debugPrint('onDisconnect');
      },
      /// Invoked when StringeeClient connect false
      onFailWithError: (stringeeClient, code, message) {
         debugPrint('onFailWithError: code - $code - message - $message');
      },
      /// Invoked when your token is expired
      onRequestAccessToken: (stringeeClient) {
         debugPrint('onRequestAccessToken');
      },
      /// Invoked when receive an chat change event
      onChangeEvent: (stringeeClient, objectChange) {
         debugPrint('onChangeEvent: objectChange - ${objectChange.toString()}');
      },
    ));
  3. Connect

    String token = 'PUT YOUR TOKEN HERE'
    _stringeeClient.connect(token);