• UIKit
  • SDK
  • 서버 API
Chat/
SDK/
Web/
SDK
  • Chat SDK 설치
  • Chat SDK 초기화
  • 로그인 및 로그아웃
  • 고객 인터페이스
  • Changelog
  • 메시지
    • 개요
    • 메시지 보내기
    • 메시지 받기
    • 과거 메시지
    • 메시지 전달
    • 메시지 수정
    • 메시지 삭제
    • 과거 메시지 비우기
    • 메시지 철회
    • 온라인 메시지 보내기
    • 메시지 읽음 확인
    • 메시지 조회
    • 지향적 그룹 메시지
    • 알림 차단
    • Key-Value 확장
    • 번역
  • 대화
    • 개요
    • 대화 목록
    • 대화 획득
    • 읽지 않은 메시지 수
    • 대화 최상단 고정
    • 대화 삭제
    • 마크
    • 대화 그룹
  • 그룹
    • 개요
    • 그룹 관리
    • 그룹 정보
    • 그룹 멤버 관리
    • 그룹 멤버 정보
    • 그룹 속성 사용자 정의
    • 그룹 카운터
  • 커뮤니티 화제
    • 커뮤니티 관리
  • 사용자 정보 및 관계망
    • 사용자 정보
    • 사용자 상태
    • 친구 관리
    • 친구 목록
    • 블록리스트
  • Guideline for Beginners
  • 콘솔 안내
    • 애플리케이션 생성 및 업그레이드
    • 기본 구성
    • 기능 구성
    • 계정 관리
    • 그룹 관리
    • 콜백 구성
  • 제품 소개
    • 메시지 관리
      • 1대1 메시지
      • 메시지 저장
      • 오프라인 푸시
      • 그룹 메시지
      • 메시지 포맷
    • 계정 시스템
      • 로그인 인증
      • 온라인 상태 관리
    • 그룹 관련
      • 그룹 시스템
      • 그룹 관리
    • 사용자 정보 및 관계망
      • 정보 관리
      • 관계망 관리
  • 구매 가이드
    • 과금 개요
    • 가격
  • 에러코드
이 페이지는 현재 영어로만 제공되며 한국어 버전은 곧 제공될 예정입니다. 기다려 주셔서 감사드립니다.

로그인 및 로그아웃

Feature Description

Users can send and receive messages only after they have logged in to the Chat SDK. To log in to the Tencent backend server, a user needs to provide information, including the UserID and UserSig. For more information on these parameters, see Login Authentication.

Login

Note:
After the successful login, wait until the SDK enters the ready status (by listening to the TencentCloudChat.EVENT.SDK_READY event), and then call APIs that require authentication, such as sendMessage.
To support multi-instance login (allowing logging in to the same account concurrently on multiple webpages), log in to the Chat Console, find the target SDKAppID, and click Application > Configuration > Login and Message > Login Settings > Max Login Instances per User per Platform to configure the number of instances. The configuration will take effect in 5 minutes.
API
chat.login(options);
Parameter
The options parameter is of the Object type. It contains the following attribute values:
Name
Type
Description
UserID
String
User ID.
UserSig
String
The password with which the user logs in to the Chat console. It is essentially the ciphertext generated by encrypting information such as the UserID. For the detailed generation method, see Generating UserSig.
Returned value
Promise
Sample
let promise = chat.login({userID: 'your userID', userSig: 'your userSig'});
promise.then(function(imResponse) {
console.log(imResponse.data);
// Logged in successfully
if (imResponse.data.repeatLogin === true) {
// This indicates that the account is already logged in.
console.log(imResponse.data.errorInfo);
}
}).catch(function(imError) {
console.warn('login error:', imError);
});

Logout

This API is used to log out of the Chat SDK. It is usually called when you switch between accounts. This API clears the login status of the current account and all the data in the memory.
Note:
When calling this API, the instance publishes the SDK_NOT_READY event. In this case, the instance is automatically logged out and cannot receive or send messages.
Assume that the value of the Web configuration item in the Chat Console is greater than 1, and the same account has been used to log in to instances a1 and a2. After a1.logout() is executed, a1 will be automatically logged out and cannot receive or send messages, while a2 will not be affected.
Assume that the Online Web Instances is set to 2, and your account has been used to log in to instances a1 and a2. When you use this account to log in to instance a3, either a1 or a2 will be forcibly logged out. In most cases, the instance that first entered the login state is forcibly logged out. This is called kicked offline due to multi-account login. If a1 is forcibly logged out, a logout process is executed within a1 and the KICKED_OUT event is triggered. You can listen for this event and redirect to the login page when the event is triggered. At this time, a1 is forcibly logged out, whereas a2 and a3 can continue to run properly.
API
chat.logout();
Parameter
None
Returned value
Promise
Sample
let promise = chat.logout();
promise.then(function(imResponse) {
console.log(imResponse.data);
// Logged out successfully
}).catch(function(imError) {
console.warn('logout error:', imError);
});

Terminating

You can terminate SDK instances, including logout, disconnecting persistent connection, and releasing all resources.
API
chat.destroy();
Parameter
None
Returned value
Promise
Sample
chat.destroy().then(() => {
console.log('sdk destroyed');
});

Login Settings

By default, multi-account login is not supported. If you use an account that has been logged in on another page to log in on the current page, the account may be forcibly logged out on the other page, which will trigger the KICKED_OUT event. You can proceed accordingly after detecting the event through listening. Below is an example:
let onKickedOut = function (event) {
console.log(event.data.type);
// TencentCloudChat.TYPES.KICKED_OUT_MULT_ACCOUNT (The user is forcibly logged out because the same account logs in from multiple webpages on the web client.)
// TencentCloudChat.TYPES.KICKED_OUT_MULT_DEVICE (The user is forcibly logged out because the same account logs in from multiple terminals.)
// TencentCloudChat.TYPES.KICKED_OUT_USERSIG_EXPIRED (The signature expired.)
// TencentCloudChat.TYPES.KICKED_OUT_REST_API (The user is forcibly logged out by the RESTful API.
)};
chat.on(TencentCloudChat.EVENT.KICKED_OUT, onKickedOut);