跳到主要内容

使用指南

调用流程

示例代码

Demo地址

https://dev.kedacom.com/appdemo/index.html

示例代码

const APP_TOKEN = "TOKEN12345678";
const USER_ID = "6666660000001";
const USER_NICKNAME = "张三";

let clientIds = KRtcClient.getClientIds();

let clientId = (clientIds && clientIds.length > 0) ? clientIds[0] : "";

let kRtcClient = new KRtcClient({clientId: clientId});

kRtcClient.init({
hostname: "dev.kedacom.com",
success: function() {
// 加入房间
doJoin();
},
error: function() {
// 未获取到用户信息,重定位到登录界面或执行登录
kRtcClient.login({
userId: USER_ID, // 用户ID
nickname: USER_NICKNAME, // 昵称
appToken: APP_TOKEN, // 应用token
success: function() {
// 加入房间
doJoin();
}
});
}
});

function doJoin(roomId) {
if (!roomId) {
roomId = kRtcClient.getRoomId();
}
kRtcClient.join({
roomId: roomId,
success: function(data) {
// 获取用户列表
// kRtcClient.getUserList();

// 订阅流
// kRtcClient.subscribe();
},
error: function(cause) {
// 加入房间失败
console.log("加入房间失败");
}
});
}