跳到主要内容

使用指南

调用流程

示例代码

单用户实例

Demo地址

https://dev.kedacom.com/sdkdemo/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("加入房间失败");
}
});
}

多用户实例

Demo地址

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

示例代码

const APP_TOKEN = "TOKEN12345678";

let clientIds = KRtcClient.getClientIds();

let clientId1 = (clientIds && clientIds.length > 0) ? clientIds[0] : "";
let clientId2 = (clientIds && clientIds.length > 1) ? clientIds[1] : "";
let clientId3 = (clientIds && clientIds.length > 2) ? clientIds[2] : "";
let clientId4 = (clientIds && clientIds.length > 3) ? clientIds[3] : "";

initKRtcClient(clientId1, "dev.kedacom.com", "6660001", "监控终端别名1");
initKRtcClient(clientId2, "dev.kedacom.com", "6660002", "监控终端别名2");
initKRtcClient(clientId3, "dev.kedacom.com", "6660003", "监控终端别名3");
initKRtcClient(clientId4, "dev.kedacom.com", "6660004", "监控终端别名4");

function initKRtcClient(clientId, hostname, roomId, nickname) {
let kRtcClient = new KRtcClient({clientId: clientId});

kRtcClient.init({
hostname: hostname,
success: function(data) {
doJoin(roomId);
},
error: function(cause) {
kRtcClient.login({
appToken: APP_TOKEN, // 应用token
nickname: nickname,
success: function(data) {
doJoin(roomId);
},
error: function(cause) {
// 登录失败
console.log("登录失败");
}
})
}
});

return kRtcClient1;
}

function doJoin(roomId) {
kRtcClient1.join({
roomId: roomId,
success: function(data) {
// 获取用户列表
// kRtcClient.getUserList();

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