UserID
and UserSig
. For more information on these parameters, see Login Authentication.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. |
Promise
let 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);});
SDK_NOT_READY
event. In this case, the instance is automatically 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 the event is triggered. At this time, a1 is forcibly logged out, whereas a2 and a3 can continue to run properly.chat.logout();
let promise = chat.logout();promise.then(function(imResponse) {console.log(imResponse.data);// Logged out successfully}).catch(function(imError) {console.warn('logout error:', imError);});
chat.destroy();
chat.destroy().then(() => {console.log('sdk destroyed');});
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);
Was this page helpful?