Tutorial: WebSocket Upgrade Guide (Web & Mini Program)

WebSocket Upgrade Guide (Web & Mini Program)

Upgrade Guide

Starting from v2.11.2, the SDK uses WebSocket instead of HTTP long polling as the underlying transport technology. In contrast, WebSocket has the following advantages:

  • Higher message sending and receiving efficiency. The SDK uses the combination of push (Server Push) and pulling (SDK Pull) for message sending and receiving, which not only gives full play to the advantages of WebSocket and reduces the message transmission delay, but also ensures the reliability of messages.
  • Greatly reduces the amount of front-end network requests and is more friendly to Mini Programs.
  • More rapid perception of user status changes. When you close the browser tab page or forcibly kill the browser process, the IM status system can perceive it very quickly (if the client sends FIN or RST packets, the system will perceive it in real time, otherwise it will perceive it in 60s at the latest).
  • Faster problem locating and troubleshooting.

The SDK upgrade process is as follows:

1. APIs are backward compatible, and the SDK can be upgraded smoothly on the access side.

Please use npm to upgrade the SDK.

Web:

npm install tim-js-sdk --save

Mini Program:

npm install tim-wx-sdk --save

APIs are completely backward compatible, and the use methods of all APIs remain unchanged. For details, see the API documentation.

2. Before using the Mini Program, change trusted domain names first.

Before using the Mini Program, you need to set the following domain names as trusted domain names (existing IM trusted domain names can be deleted):

  • wss://wss.im.qcloud.com
  • wss://wss.tim.qq.com
  • https://web.sdk.qcloud.com
  • https://webim.tim.qq.com

Add the following domain name to the downloadFile valid domain name:

  • https://cos.ap-shanghai.myqcloud.com

3. For technical exchanges, join the Tencent Cloud IM technology QQ group 468195767.