TIMLogin

Introduction

Login

Only the conversation acquisition API can be called immediately after you call the login API, and other APIs can be called only after you have successfully logged in to the SDK. Therefore, make sure that you have logged in successfully before using other features; otherwise, such features may become abnormal or unavailable.

User needs to login to Tencent Cloud IM server to communicate, and for login you need to fill out UserID and UserSig, more details please check Login Authentication

Login before the following scenarios

First calling IM SDK functions after APP launched.

Credential expired when login, Login callback returns ERR_USER_SIG_EXPIRED(6206) or ERR_SVR_ACCOUNT_USERSIG_EXPIRED(70001) error code, and you need to generate new userSig and relogin.

Credential expired when logged in, user will receive TIMSetUserSigExpiredCallback callback, and you need to generate new userSig and relogin.

Kicked offline, kicked offline when logged in, IM SDK will inform you by KickedOfflineCallback, you may notify users to Login again.

No Login before the following scenarios

Network reconnected, don't 'Login' and IM SDK will back online automatically.

When logging, don't repeat logging in.

Once logged in, DAU is start counting. Please double check your login scenarios to prevent hyper DAU.

You don't need to sign up on your first login, as you will automatically sign up if the login is successful.

Within the same APP, IM SDK doesn't allow multi-logged in. If logged in multiple times simultaneously, only the last one will stay online.

You can configure multi-client login policies for the IM SDK in the Tencent Cloud console.

There are multiple multi-client login policies, such as A user can be concurrently online on a mobile or desktop platform and the web platform or A user can be concurrently online on all platforms.

For more information on the configuration, see Feature Configuration.

You can configure the Max Login Instances per User per Platform for the IM SDK in the Tencent Cloud console, that is, the maximum number of instances on the same platform that can be concurrently online.

This feature is available only for the Ultimate edition. A user can be concurrently online on up to ten clients on the web platform or on up to three clients on the Android, iPhone, iPad, Windows, or macOS platform (the maximum number of clients that can be concurrently online on Flutter is subject to the actual compilation result).

For more information on the configuration, see Feature Configuration.

When you call the Login API to log in, if the limit specified by the multi-client login policy for your account is exceeded, a newly logged in instance will kick out an earlier one.

The one kicked out will receive KickedOfflineCallback.

Call Login to switch between accounts in the application.

For example, to switch the logged-in user from Alice to Bob, just call Login bob. You don't need to explicitly call logout alice, as this operation will be handled automatically inside the IM SDK.

Parameter details

Parameter name Parameter type Required Description
param loginParam yes Param of Login operation

Returned template

Promise<commonResult<string>>

{
    code: TIMResult | TIMErrCode;
    desc?: string | undefined;
    json_param?: string | undefined;
    json_params?: string | undefined; 
    user_data?: string | undefined;
}

Return value details

name type description
code TIMResultTIMErrCode Request result: Error codes. 0 means success.
desc string | undefined The description of the error. It will be empty if success.
json_param string | undefined Return value of calling API
json_params string | undefined Return value of calling API. Compatible field, which is returned in some cases.
user_data string | undefined ImSDK is responsible for transporting user-defined data without any processing

Code example

import { loginParam } from "im_electron_sdk/dist/interfaces";
import TimRender from "im_electron_sdk/dist/renderer";
const timRenderInstance = new TimRender();

let userID = "";
let userSig = "";
let userData = "";

let param: loginParam = {
    userID: userID,  // userID
    userSig: userSig,    // userSig
    userData: userData      // optional,userData
}

let { code } = await timRenderInstance.TIMLogin(param);

if (code == 0) {
    // success
}

results matching ""

    No results matching ""