To connect to Stringee Server, 3-party authentication is required as described here: Client authentication
For testing purpose, go to Dashboard -> Tools -> Generate Access token and generate an access_token. In production, your server should generate the access_token. Sample code generates access token here: https://github.com/stringeecom/server-samples/tree/master/access_token
import 'package:stringee_plugin/stringee_plugin.dart';
...
StringeeClient client = StringeeClient();
StringeeChat chat = StringeeChat(client);
Register the client's events in your State
// Listen for the StringeeClient event
_client.eventStreamController.stream.listen((event) {
Map<dynamic, dynamic> map = event;
switch (map['eventType']) {
case StringeeClientEvents.didConnect:
handleDidConnectEvent();
break;
case StringeeClientEvents.didDisconnect:
handleDiddisconnectEvent();
break;
case StringeeClientEvents.didFailWithError:
int code = map['body']['code'];
String msg = map['body']['message'];
handleDidFailWithErrorEvent(code,msg);
break;
case StringeeClientEvents.requestAccessToken:
handleRequestAccessTokenEvent();
break;
case StringeeClientEvents.didReceiveCustomMessage:
handleDidReceiveCustomMessageEvent(map['body']);
break;
case StringeeClientEvents.userBeginTyping:
handleUserBeginTypingEvent(map['body']);
break;
case StringeeClientEvents.userEndTyping:
handleUserEndTypingEvent(map['body']);
break;
default:
break;
}
});
...
chat.eventStreamController.stream.listen((event) {
Map<dynamic, dynamic> map = event;
if (map['eventType'] == StringeeChatEvents.didReceiveObjectChange) {
handleDidReceiveObjectChangeEvent(map['body']);
}
});
...
/// Invoked when the StringeeClient is connected
void handleDidConnectEvent() {}
/// Invoked when the StringeeClient is disconnected
void handleDiddisconnectEvent() {}
/// Invoked when StringeeClient connect false
void handleDidFailWithErrorEvent(int code, String message) {}
/// Invoked when your token is expired
void handleRequestAccessTokenEvent() {}
/// Invoked when get Custom message
void handleDidReceiveCustomMessageEvent(Map<dynamic, dynamic> map) {}
/// Invoked when user send begin typing event
void handleUserBeginTypingEvent(Map<dynamic, dynamic> map) {}
/// Invoked when user send end typing event
void handleUserEndTypingEvent(Map<dynamic, dynamic> map) {}
/// Invoked when receive an chat change event
void handleDidReceiveObjectChangeEvent(StringeeObjectChange stringeeObjectChange) {}
...
}
String token = 'PUT YOUR TOKEN HERE'
_client.connect(token);