WeChat Mini Program integration
Interactive Messaging is a service that enhances communication and user interaction in live streaming rooms. It provides a rich, easy-to-integrate SDK to add features like comments, bullet comments, and likes to your live streaming applications. This topic describes how to integrate the Interactive Messaging SDK with a WeChat Mini Program.
Prerequisites
Server-side integration
Before you perform client-side integration, ensure you have completed server-side integration and provided an API for the client to obtain a token. For more information, see Server-side integration.
Configure server domains in the console
Log in to the WeChat Official Accounts Platform.
In the left-side navigation pane, choose Development > Development Management.
On the Development Settings page, add the following domain names to the server domain name list.
Request valid domain name: HTTPS domains
https://slsrole.alicdn.com https://videocloud.cn-hangzhou.log.aliyuncs.comSocket valid domain name: WSS domains
wss://rcoims.rtn.aliyuncs.com
Integrate SDK files
Download SDK files
Download the WeChat Mini Program SDK. Rename the downloaded alivc-im.bin file to alivc-im.zip, then extract the alivc-im.js and alivc-im.wasm.br files.
Integrate into a native project
If you have a native WeChat Mini Program project, follow these two steps to integrate the SDK:
Copy the alivc-im.js and alivc-im.wasm.br files to the /lib directory of your project.
Modify the WASM file path specified during initialization. For more information, see Initialization.
The following example shows the project directory structure:
.
├── lib
│ ├── alivc-im.js
│ ├── alivc-im.wasm.br
├── pages
│ ├── index
│ │ ├── index.js
│ │ ├── index.json
│ │ ├── index.wxml
│ │ └── index.wxssIntegrate into a uni-app project
If you are using the uni-app framework to build a WeChat Mini Program, follow these three steps to integrate the SDK:
Copy the alivc-im.js file to the /lib directory.
Copy the alivc-im.wasm.br file to the /static/mp-weixin directory. This ensures the alivc-im.wasm.br file is copied to the final build directory during compilation.
Change the path returned by the
locateFilefunction in theinitAPI to /static/mp-weixin/alivc-im.wasm.br. For more information, see Initialization.
The following example shows the project directory structure:
.
├── lib
│ ├── alivc-im.js
├── static
│ ├── mp-weixin
│ │ ├── alivc-im.wasm.br
├── pages
│ ├── index
│ │ ├── index.vueIntegrate into a Taro project
If you are using the Taro framework to build a WeChat Mini Program, follow these four steps to integrate the SDK:
Copy the alivc-im.js file to the /src/lib directory.
Copy the alivc-im.wasm.br file to the /static directory.
In the project configuration file /config/index.js, modify the copy option to directly copy the /static folder from the source directory to the final build directory.
The following example shows how to modify the configuration file:
const config = { projectName: "demo", outputRoot: "dist", copy: { patterns: [ // Copy the static folder to the production directory after compilation. { from: 'static', to: 'dist/static' } ], options: {}, }, // Other configuration items are omitted. }; module.exports = function (merge) { if (process.env.NODE_ENV === "development") { return merge({}, config, require("./dev")); } return merge({}, config, require("./prod")); };Change the path returned by the
locateFilefunction in theinitAPI to /static/alivc-im.wasm.br. For more information, see Initialization.
The following example shows the project directory structure:
.
├── config
│ ├── index.js
│ ├── dev.js
│ ├── prod.js
├── static
│ ├── alivc-im.wasm.br
├── src
│ ├── lib
│ │ ├── alivc-im.js
│ ├── pages
│ │ ├── index
│ │ │ ├── index.tsxUse the SDK
To use the SDK, perform the following operations in order:
Initialization
Login
Operations
Logout
Uninitialization
Other operations
Operations include group operations and message operations, as described below:
Usage notes
All IDs must follow these rules.
appid | Maximum 64 characters. Allowed characters: uppercase letters (A-Z), lowercase letters (a-z), digits (0-9), and hyphens (-). |
userid | Maximum 64 characters. Allowed characters: uppercase letters (A-Z), lowercase letters (a-z), digits (0-9), and hyphens (-). |
groupid | Maximum 64 characters. Allowed characters: uppercase letters (A-Z), lowercase letters (a-z), digits (0-9), and hyphens (-). |
Initialization
Initialize the SDK before use. You can do this at the main entry point of your business module.
Login
Login requires credentials from your server. Ensure you have completed the prerequisites and obtained the required timestamp, nonce, and token.
Group operations
Ensure the asynchronous login operation is successful before performing the following operations.
Get the group manager
Add and remove group listeners
Create a group
Only an administrator can call this method. Calls from other users will fail.
You can create up to 5,000 groups. This quota does not include closed groups. To ensure efficient resource use, close groups that are no longer needed.
Close a group
Only the group owner or an administrator can call this method. Calls from other users will fail.
Join a group
Leave a group
Query group information
Modify group information
You can modify group extension information and set administrators. Only the group owner or an administrator can call this method. Calls from other users will fail.
Query recent group members
Query all group members
Only the group owner or an administrator can call this method. Calls from other users will fail.
Mute a group
Only the group owner or an administrator can call this method. Calls from other users will fail.
Unmute a group
Only the group owner or an administrator can call this method. Calls from other users will fail.
Mute users in a group
Only the group owner or an administrator can call this method. Calls from other users will fail.
Unmute users in a group
Only the group owner or an administrator can call this method. Calls from other users will fail.
Query muted users
Only the group owner or an administrator can call this method. Calls from other users will fail.
Message operations
Get the message manager
Add and remove message listeners
Send a one-to-one message
Send a group message
Delete or retract a group message
A successful API call triggers a callback for recipients.
Query recent group messages
After joining a group, you can call this API to retrieve the last 50 messages. Any user type can call this API.
Query all group messages
Only the group owner or an administrator can call this method. Otherwise, the call fails. Regular users should use the listRecentMessage API to get the last 50 messages.
Query historical messages
This API is primarily for replaying historical messages after a live stream ends. Users can call this API without joining the group. Because this is a time-consuming operation, we do not recommend using it during a live stream. This API will be a paid service in the future.
Logout
await engine.logout();Uninitialization
After you log out, if you do not need to log in again, you can uninitialize the engine to release underlying SDK resources.
engine.unInit()Other operations
These are helper APIs for checking states and handling specific scenarios.
# Checks whether the SDK is initialized. You can use this API to determine if the SDK instance has been created.
ImEngine.isInitialized();
# Checks if you are logged in (returns false if login is in progress). You can only join a group or log out when logged in.
engine.isLogin();
# Checks whether you are logged out (returns false if login is in progress). You can perform a login operation only when you are in the logged-out state.
engine.isLogout();