Session constructor
Session({
- required String appId,
- String? token,
- TokenFetcherHandler? tokenFetcher,
- MessageHandler? onMessage,
- Unreads? unreads,
- UnreadsChangeHandler? onUnreadsChange,
- ErrorHandler? onError,
- bool? enablePushNotifications = false,
- @Deprecated("Use [token] or [tokenFetcher] instead") String? signature,
Implementation
Session({
required this.appId,
this.token,
this.tokenFetcher,
this.onMessage,
this.unreads,
this.onUnreadsChange,
this.onError,
this.enablePushNotifications = false,
@Deprecated("Use [token] or [tokenFetcher] instead") this.signature,
}) : _completer = Completer() {
rootBundle.loadString('packages/talkjs_flutter/assets/version.txt').then((
version,
) {
if (Platform.isAndroid) {
InAppWebViewController.setWebContentsDebuggingEnabled(kDebugMode);
}
_headlessWebView = HeadlessInAppWebView(
onWebViewCreated: _onWebViewCreated,
onLoadStop: _onLoadStop,
onConsoleMessage:
(InAppWebViewController controller, ConsoleMessage message) {
if (kDebugMode) {
print("session [${message.messageLevel}] ${message.message}");
}
if (message.messageLevel == ConsoleMessageLevel.ERROR) {
this.onError?.call(message.message);
}
},
initialSettings: InAppWebViewSettings(
// Since iOS 16.4, this is required to enabled debugging the webview.
isInspectable: kDebugMode,
applicationNameForUserAgent:
'TalkJS_Flutter/${version.trim().replaceAll('"', '')}',
),
);
// Runs the headless WebView
_headlessWebView!.run();
});
}