Session constructor

Session({
  1. required String appId,
  2. String? token,
  3. TokenFetcherHandler? tokenFetcher,
  4. MessageHandler? onMessage,
  5. Unreads? unreads,
  6. UnreadsChangeHandler? onUnreadsChange,
  7. ErrorHandler? onError,
  8. bool? enablePushNotifications = false,
  9. @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();
  });
}