本文主要介绍 一分钟集成 SDK, 将 云信令 SDK 快速集成到您的项目中。
一分钟集成 SDK
云信令
<style>
<script src="./BRTMSDK.js"></script>
下载最新版 云信令 Web SDK 软件包。 将下载下来的软件包中的 BRTM.js 文件保存到项目文件所在的目录下。
BRTM.js
const BRTM = require('BRTM')
import * as BRTM from 'BRTM'
const rtmClient = BRTM.createClient({ appId: 'xxxxxx' // 在控制台创建的appId }); rtmClient .on( BRTM.Events.Room.USER_KICKED, fromId => { this.$message({ type: 'error', message: `已被用户 ${fromId} 踢出房间` }) } ) .on( BRTM.Events.Room.CLIENT_BANNED, endType => { this.$message({ type: 'error', message: `你已在终端 ${endType} 上登录` }) this.$router.push({ path: 'join' }) } ) .on( BRTM.Events.Room.ERROR, error => { console.log('brtm error') } ) /** * 监听收到广播消息 */ .on(BRTM.Events.Room.BROADCAST_MESSAGE_RECEIVED, (data) => { console.log('收到广播消息:', data) }) /** * 监听收到广播消息 */ .on(BRTM.Events.Room.MESSAGE_RECEIVED, (data) => { console.log('收到单播消息:', data) if (data.messageType === 'logout') { this.leaveRoom() } }) rtmClient.user .on( BRTM.Events.User.USER_IN, user => { console.log('brtm user in', user) } ) .on( BRTM.Events.User.USER_OUT, user => { console.log('brtm user out', user) } ) rtmClient.chat .on( BRTM.Events.Chat.MESSAGE_RECEIVED, message => { console.log('brtm message received', message) } ) .on( BRTM.Events.Chat.MESSAGE_WHISPER_REVEIVED, message => { console.log('brtm message whisper received', message) } ) .on( BRTM.Events.Chat.MESSAGE_REVOKED, message => { console.log('brtm message revoked', message) } ) rtmClient.init().then(() => { // 加入房间 brtmClient.join(roomId, userId, sig, { userInfo: { name: name, avatar: avatar // 头像链接 } }).then(res => { console.log('rtm 加入房间成功') }).catch(error => { console.log('rtm 加入房间失败') console.log(error) }) })
一分钟集成 SDK
本文主要介绍
一分钟集成 SDK
, 将云信令
SDK 快速集成到您的项目中。从官网获取 SDK
云信令
Web SDK 软件包云信令
SDK 文件保存到项目文件所在的目录下<style>
标签的上一行从官网获取 SDK,使用模块导入
下载最新版
云信令
Web SDK 软件包。 将下载下来的软件包中的BRTM.js
文件保存到项目文件所在的目录下。示例代码