In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
Web SDK how to achieve only one device login, I believe that many inexperienced people do not know what to do, so this paper summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.
Background
When integrating Rongyun's instant messaging, the product said: in order to achieve a function, whether it is Web or mobile login, only one user can log in successfully and the account that logs in successfully later needs to kick out the previously logged-in account.
It sounds pretty simple to me. Rongyun doesn't have a service: it's called multi-device message synchronization. I'll just turn off the service ~ O (∩ _ ∩) O ~
But my idea is too simple. After the service is turned off, the Web can kick each other, but the mobile and Web can still be online. By default, Rongyun only supports one Web, one desktop and one mobile at the same time.
This is Rongyun multi-terminal simultaneous online details: https://docs.rongcloud.cn/v4/views/im/noui/guide/group/connection/multiclient/
Without saying much, we began to unravel the mystery.
1. First synchronize multi-device messages-close, close the connection: https://developer.rongcloud.cn/advance/index/YTrydqMSdEsmBtX2zX0Amg
2. If the multi-end login status monitor hears the status code 6, the disconnect link will be executed.
Code example
Im.watch ({conversation: function (event) {var updatedConversationList = event.updatedConversationList; / / updated session list console.log ('update session summary:', updatedConversationList); console.log ('latest session list:', im.Conversation.merge ({conversationList, updatedConversationList}));}, message: function (event) {var message = event.message; console.log ('new message received:', message) }, status: function (event) {console.log ('connection status code:', status); var status = event.status; if (status = = 6) {im.disconnect () .then (function () {console.log ('link disconnected successfully');});})
3. Execute the disconnection method by sending a custom message
For example, if you have two devices, APermine B, the user starts to log in on device A, and then sends himself or someone a custom message after device B has successfully logged in. Device A judges according to the custom message during monitoring and calls the disconnection method. Only one device can log in.
/ / send custom message var conversation = im.Conversation.get ({targetId: 'receiver's userId', type: RongIMLib.CONVERSATION_TYPE.PRIVATE}) Conversation.send ({messageType:'s name personalization, / / enter developer-defined messageType content: {/ / enter developer-defined message content name: 'RongCloud', age: 12}, whether isPersited: true,// is stored on the server, default is true isCounted: true / / whether to count. Count the number of messages received without reading plus 1, default is true}). Then (function (message) {console.log ('s:person message sent successfully', message);})
Through the above steps, you can only log in to a single device, but you need to pay attention to the version of SDK you use. At first, I did it with 3.0.5 SDK, but there is a problem: disconnection will still reconnect, so use SDK version 3.0.6 or above of SDK.
After reading the above, have you mastered how Web SDK can log in with only one device? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.