I believe that many friends who do development have more or less met the needs of similar chat functions. Today, xiaobian will recommend a super good message push tool – Baicheng push.
Baicheng Push is a universal script language compatible with all WebSocket client professional push services, with the following advantages:
- Zero storage: The platform does not store any of your push messages, and we are focused on providing communication capabilities
- Secure and reliable: Frontline service providers provide secure and reliable computing and data processing capabilities
- Independent and open: Customize data packets to easily realize functions such as text, expression, picture, location and voice
- Platform compatibility: The platform is based on WebSocket and supports all WebSocket languages and clients
- Multi-terminal synchronization: When you log in to the same account from multiple terminals, the information is automatically synchronized, facilitating rapid and efficient communication
- Fast and efficient: the program only needs to interconnect with the server authorization interface, greatly reducing your learning and development costs
Rapid experience
H5 version
Docking step
Step 1: Registration/login (use email to register your account, please keep your appKey and appSecret properly after successful registration)
Step 2: Obtain the authorization code (the server obtains the authorization code through the API)
Step 3: Client use (the client uses the authorization code obtained from the back end to connect the Socket, and the connection should be a global connection)
Step 4: Send/receive messages (Use WebSocket to send and receive messages and save messages based on specific application scenarios)
- To create a single chat: Click to jump
- Create a group chat: Click to jump to
Step 5: Close the connection (close the Socket connection when exiting the application)
SDK
Download the SDK
Method of use
Initialize the SDK
var xbcim = XBCIM.init(token);
Copy the code
1. Parameter token is the connection authorization code, which can be obtained by using the appKey and other parameters of the platform registered account. For details, see Obtaining an Authorization Code.
2. The parameter can be passed the token string directly or in JSON format, such as {token: token}.
3. WebSocket links are created by default during initialization.
2. Listener initialization is successful
xbcim.onsuccess(callback);
Copy the code
Callback, which can be used to perform other logical operations after a successful connection.
3. Monitoring error
xbcim.onerror(callback);
Copy the code
1. Onerror will listen for error callbacks such as initialization failure and token verification.
Callback, which can be used to perform other logical operations after the connection is successful.
4. Monitor whether the connection is disconnected
xbcim.onclose(callback);
Copy the code
Callback in which other logical operations can be performed after the connection is disconnected.
5. Disconnect manually
xbcim.close(callback);
Copy the code
Callback in which other logical operations can be performed after the connection is disconnected.
6. Reconnect
xbcim.reconnect();
Copy the code
7. Send single chat
xbcim.sendSingle(data);
Copy the code
Data indicates the message data to be sent. Specific parameters and their meanings are as follows:
parameter | describe |
---|---|
type | Message type, default text, support for other custom message types |
source | ID of the message sender |
target | Message receiver ID |
content | Message content, string |
extra | Additional data, support any format |
8. Send group chats
xbcim.sendGroup(data);
Copy the code
Data indicates the message data to be sent. Specific parameters and their meanings are as follows:
parameter | describe |
---|---|
type | Message type, default text, support for other custom message types |
source | ID of the message sender |
target | Group ID |
content | Message content, string |
extra | Additional data, support any format |
9. Receive messages
xbcim.onmessage(callback);
Copy the code
Callback Returns the received message data.