initSDK static method

Future<V2TimValueCallback<bool>> initSDK({
  1. required int sdkAppID,
  2. required int loglevel,
  3. String? listenerUuid,
  4. V2TimSDKListener? listener,
  5. required int uiPlatform,
  6. bool? showImLog,
})

Implementation

static Future<V2TimValueCallback<bool>> initSDK({
  required int sdkAppID,
  required int loglevel,
  String? listenerUuid,
  V2TimSDKListener? listener,
  required int uiPlatform,
  bool? showImLog,
}) async {
  try {
    await copydyliptoSysTempath();
  } catch (err) {
    print("copy sdk error ${err.toString()}");
  }

  int data = desktopSDK.InitDartApiDL(NativeApi.initializeApiDLData);

  desktopSDK.registerSendPort(_receivePort.sendPort.nativePort);

  bool ismac = Platform.isMacOS;
  if (!_receivePortListened) {
    _receivePort.listen(_handleNativeMessage);
  }
  _receivePortListened = true;
  var spt = ismac ? "/" : "\\";
  var paths = Platform.resolvedExecutable.split(spt);

  var avpaths = paths.sublist(0, paths.length - 1);
  var imPath = normalize(avpaths.join(spt));
  var configpath = join(imPath, 'tencent_cloud_chat_config');
  var logpath = join(imPath, 'tencent_cloud_chat_xlog');
  if (!ismac) {
    final String documentsDirectoryPath = "${Platform.environment['USERPROFILE']}";
    PackageInfo packageInfo = await PackageInfo.fromPlatform();
    String pkgName = packageInfo.packageName;
    logpath = join(documentsDirectoryPath, "Documents", ".TencentCloudChat", pkgName, "tencent_cloud_chat_xlog");
    configpath = join(documentsDirectoryPath, "Documents", ".TencentCloudChat", pkgName, "tencent_cloud_chat_config");
  }

  print("current log path is $logpath you can find xlog files here.");
  Pointer<Uint8> json_sdk_config = Tools.string2PointerInt8(json.encode({
    "sdk_config_config_file_path": configpath,
    "sdk_config_log_file_path": logpath,
  }));
  String userData = Tools.generateUserData();
  Pointer<Uint8> user_data = Tools.string2PointerInt8(userData);
  if (listener != null) {
    timSDKListenerMap.addAll({userData: listener});
  }

  IMNative.callExperimentalAPI(
    api: "internal_operation_set_ui_platform",
    param: 27,
  );

  _TIMSetNetworkStatusListenerCallback(user_data);
  _TIMSetKickedOfflineCallback(user_data);
  _TIMSetUserSigExpiredCallback(user_data);
  _TIMSetSelfInfoUpdatedCallback(user_data);
  _TIMSetUserStatusChangedCallback(user_data);
  _TIMSetUserInfoChangedCallback(user_data);
  int res = desktopSDK.D_TIMInit(sdkAppID, json_sdk_config);

  return V2TimValueCallback<bool>.fromJson({
    "code": 0,
    "desc": res == 0 ? "success" : "error",
    "data": res == 0 ? true : false,
  });
}