shengwang-chat
v1.3.2
Published
Shengwang chat web sdk
Readme
声网 Chat SDK 介绍
Chat SDK 提供完整的即时消息功能开发能力,屏蔽/封装并阻止其内部复杂的细节,并提供相对简单和简洁的 API 接口,以方便第三方应用程序快速集成 PC/mobile Web 应用程序的即时消息功能。
可以通过以下方式引用 ChatSDK:
- 安装
npm install shengwang-chat- 引入 SDK。
import ChatSDK from 'shengwang-chat'3、初始化 SDK
const chatClient = new ChatSDK.connection({
appId: '<your appId>',
});4、登录Chat服务
const options = {
user: 'userId',
accessToken: 'accessToken',
};
chatClient.open(options).then(() => {
console.log('Login succeeded')
});5、发送消息
const option = {
chatType: 'singleChat', // 会话类型,设置为单聊。
type: 'txt', // 消息类型。
to: 'userID', // 消息接收方(用户 ID)。
msg: 'message content', // 消息内容。
};
const msg = ChatSDK.message.create(option);
chatClient.send(msg)
.then(() => {
console.log('send private text Success');
})
.catch((e) => {
console.log('Send private text error');
});