|
@@ -15,12 +15,39 @@ export function initSDK(data) {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * @method createLocalStram
|
|
|
+ * @description 创建本地流
|
|
|
+ */
|
|
|
+function createLocalStream() {
|
|
|
+ const createData = {
|
|
|
+ video: true,
|
|
|
+ audio: true
|
|
|
+ };
|
|
|
+ rtc.createLocalStream({
|
|
|
+ streamName: 'main',
|
|
|
+ createData,
|
|
|
+ success: function (stream) {
|
|
|
+ // 创建本地流成功,将流展示到id为 live 的dom元素盒子中
|
|
|
+ stream.show('live');
|
|
|
+ // publish(stream); // 如果需要立即推流,执行 publish 方法
|
|
|
+ alert('创建本地流成功');
|
|
|
+ },
|
|
|
+ fail: function (data) {
|
|
|
+ // 创建本地流失败,应用层处理
|
|
|
+ console.log(data);
|
|
|
+ alert('创建本地流失败');
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
* @method initListener
|
|
|
* @description 初始化监听事件
|
|
|
*/
|
|
|
export function initListener() {
|
|
|
rtc.on('login_success', data => {
|
|
|
console.log('登录成功', data);
|
|
|
+
|
|
|
alert('登录成功:' + JSON.stringify(data));
|
|
|
});
|
|
|
|
|
@@ -29,9 +56,11 @@ export function initListener() {
|
|
|
alert('登录失败:' + JSON.stringify(data));
|
|
|
});
|
|
|
|
|
|
+ // 必须在加入房间成功的“conference_join”事件回调里创建本地流
|
|
|
rtc.on('conference_join', function () {
|
|
|
// 有监听就是加入房间成功
|
|
|
console.log('加入房间成功');
|
|
|
+ createLocalStream();
|
|
|
});
|
|
|
|
|
|
rtc.on('conference_join_failed', function (err) {
|
|
@@ -39,6 +68,19 @@ export function initListener() {
|
|
|
console.log('加入房间失败', err);
|
|
|
});
|
|
|
|
|
|
+ // 房间全量信息事件
|
|
|
+ rtc.on('room_context', function (roomData) {
|
|
|
+ console.log(JSON.parse(roomData));
|
|
|
+ });
|
|
|
+
|
|
|
+ rtc.on('publish_stream', function (str) {
|
|
|
+ console.log('直播已开启', str);
|
|
|
+ });
|
|
|
+
|
|
|
+ rtc.on('end_stream', function (str) {
|
|
|
+ console.log('直播已关闭', str);
|
|
|
+ });
|
|
|
+
|
|
|
rtc.on('switch_user_settings', function (settingData) {
|
|
|
// 单个用户配置监听
|
|
|
console.log(settingData);
|
|
@@ -69,6 +111,20 @@ export function initListener() {
|
|
|
console.log('推流意外终止:' + data.streamName);
|
|
|
// 直播开启状态下,尝试重推这条流
|
|
|
});
|
|
|
+
|
|
|
+ // 视频无法自动播放
|
|
|
+ rtc.on('playError', function (data) {
|
|
|
+ console.log(data);
|
|
|
+ });
|
|
|
+
|
|
|
+ // 监听聊天事件
|
|
|
+ rtc.on('chat_message', function (data) {
|
|
|
+ let dat = JSON.parse(data);
|
|
|
+ // data数据需要解析
|
|
|
+ if (dat.isFilterChat && dat.isFilterChat === 1) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -104,28 +160,6 @@ export function stopLive() {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @method createLocalStram
|
|
|
- * @description 创建本地流
|
|
|
- */
|
|
|
-export function createLocalStream() {
|
|
|
- rtc.createLocalStream({
|
|
|
- streamName: 'main',
|
|
|
- success: function (stream) {
|
|
|
- // 创建本地流成功,将流展示到id为 live 的dom元素盒子中
|
|
|
- stream.show('live');
|
|
|
- // publish(stream); // 如果需要立即推流,执行publish方法
|
|
|
- console.log(stream);
|
|
|
- alert('创建本地流成功');
|
|
|
- },
|
|
|
- fail: function (data) {
|
|
|
- // 创建本地流失败,应用层处理
|
|
|
- console.log(data);
|
|
|
- alert('创建本地流失败');
|
|
|
- }
|
|
|
- });
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
* @method closeVideo
|
|
|
* @description 结束本地流
|
|
|
*/
|
|
@@ -150,30 +184,21 @@ export function publishStream() {
|
|
|
streamName: 'main',
|
|
|
// 推流成功,更新上麦结果
|
|
|
success: function (stream) {
|
|
|
- rtc.updateMcResult({
|
|
|
- pid: 1,
|
|
|
- stid: stream.id(),
|
|
|
- success: function (data) {
|
|
|
- alert('更新上麦结果请求成功,此处可处理应用层逻辑' + JSON.stringify(data));
|
|
|
- },
|
|
|
- fail: function (data) {
|
|
|
- alert('更新上麦结果请求失败,此处可处理应用层逻辑' + JSON.stringify(data));
|
|
|
- }
|
|
|
- });
|
|
|
+ console.log(stream);
|
|
|
+ // rtc.updateMcResult({
|
|
|
+ // pid: 1,
|
|
|
+ // stid: stream.id(),
|
|
|
+ // success: function (data) {
|
|
|
+ // alert('更新上麦结果请求成功,此处可处理应用层逻辑' + JSON.stringify(data));
|
|
|
+ // },
|
|
|
+ // fail: function (data) {
|
|
|
+ // alert('更新上麦结果请求失败,此处可处理应用层逻辑' + JSON.stringify(data));
|
|
|
+ // }
|
|
|
+ // });
|
|
|
},
|
|
|
- fail: function (stream) {
|
|
|
+ fail: function (str) {
|
|
|
// 推流失败,更新上麦结果
|
|
|
- rtc.updateMcResult({
|
|
|
- pid: 0,
|
|
|
- stid: stream.id(),
|
|
|
- success: function (data) {
|
|
|
- console.log('更新上麦结果请求成功,此处可处理应用层逻辑', data);
|
|
|
- },
|
|
|
- fail: function (data) {
|
|
|
- console.log('更新上麦结果请求失败,此处可处理应用层逻辑', data);
|
|
|
- }
|
|
|
- });
|
|
|
- alert('推流失败,此处可处理应用层逻辑');
|
|
|
+ alert(str);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
@@ -249,3 +274,48 @@ export function playVideo() {
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+/**
|
|
|
+ * @description 查询直播是否开启
|
|
|
+ */
|
|
|
+export function getLiveStat() {
|
|
|
+ rtc.getLiveStat({
|
|
|
+ success: function (data) {
|
|
|
+ console.log('直播开启状态');
|
|
|
+ console.log(data);
|
|
|
+ },
|
|
|
+ fail: function (str) {
|
|
|
+ console.log('直播关闭状态或查询直播失败', str);
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * @description 开启、结束、暂停、恢复录制
|
|
|
+ * @param { String } status: 'start' 开启, 'end' 结束, 'pause' 暂停, 'resume' 恢复
|
|
|
+ */
|
|
|
+export function liveRecord(status) {
|
|
|
+ rtc.liveRecord({
|
|
|
+ status: status,
|
|
|
+ success: function (data) {
|
|
|
+ console.log('成功', data);
|
|
|
+ },
|
|
|
+ fail: function (str) {
|
|
|
+ console.log(str);
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+// 聊天组件
|
|
|
+
|
|
|
+/**
|
|
|
+ * @descrption 发送聊天
|
|
|
+ * @param {String} msg length不能超过400
|
|
|
+ */
|
|
|
+export function sendMsg(msg) {
|
|
|
+ rtc.sendMsg(msg);
|
|
|
+}
|
|
|
+
|
|
|
+export function roomUpdate() {
|
|
|
+ rtc.roomUpdate();
|
|
|
+}
|