UserID and UserSig. For more information on these parameters, see Login Authentication.TencentCloudChat.EVENT.SDK_READY) before calling interfaces that require authentication, such as sendMessage.TencentCloudChat.EVENT.KICKED_OUT is triggered, and the user can handle it accordingly after listening for the event.chat.login(options);
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. |
Promiselet promise = chat.login({userID: 'your userID', userSig: 'your userSig'});promise.then(function(imResponse) {console.log(imResponse.data); // Logged in successfullyif (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);});
chat.getLoginUser();
Stringconst userID = chat.getLoginUser();
chat.getServerTime();
Numberconst serverTime = chat.getServerTime();
SDK_READY, which is triggered when the SDK enters the ready state.SDK_NOT_READY, which is triggered when the SDK enters the not ready state.chat.isReady();
Booleanlet isReady = chat.isReady();
SDK_NOT_READY event. In this case, the instance is logged out and cannot receive or send messages.KICKED_OUT event is triggered. You can listen for this event and redirect to the login page when triggered. At this time, a1 is offline, while a2 and a3 continue running.chat.logout();
Promiselet promise = chat.logout();promise.then(function(imResponse) {console.log(imResponse.data);// Logged out successfully}).catch(function(imError) {console.warn('logout error:', imError);});
chat.destroy();
Promiselet promise = chat.destroy();
KICKED_OUT event. You can proceed accordingly after detecting the event through listening.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);
Feedback