|
@@ -1,11 +1,11 @@
|
|
|
import { Message } from 'element-ui';
|
|
|
+import store from '@/store';
|
|
|
import { GetLiveRoomInfo } from '@/api/live';
|
|
|
-import { rtc, publishStream, closeVideo } from '@/views/live/common';
|
|
|
+import { rtc, publishStream, closeVideo, getDevice } from '@/views/live/common';
|
|
|
export {
|
|
|
initSDK,
|
|
|
sendMsg,
|
|
|
getLiveStat,
|
|
|
- getDevice,
|
|
|
downloadWebSDK,
|
|
|
createScript,
|
|
|
handsDown,
|
|
@@ -86,11 +86,41 @@ export function initListener(vue) {
|
|
|
// 教师 必须在加入房间成功的事件回调里创建本地流
|
|
|
rtc.on('conference_join', () => {
|
|
|
console.log('加入房间成功');
|
|
|
+
|
|
|
+ getDevice({
|
|
|
+ success(data) {
|
|
|
+ console.log('获取音视频设备成功', data);
|
|
|
+ let device = store.state.app.liveDevice;
|
|
|
+ vue.device = data;
|
|
|
+
|
|
|
+ let isVideo =
|
|
|
+ data.video.some(item => item.deviceId === device.video) ||
|
|
|
+ (data.video.length === 0 && device.video.length === 0);
|
|
|
+ let isAudio =
|
|
|
+ data.audio.some(item => item.deviceId === device.audio) ||
|
|
|
+ (data.audio.length === 0 && device.audio.length === 0);
|
|
|
+
|
|
|
+ if (!isVideo || !isAudio) {
|
|
|
+ vue.setDevice();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail(str) {
|
|
|
+ console.log('直播关闭状态或查询直播失败: ', str);
|
|
|
+ Message({
|
|
|
+ type: 'error',
|
|
|
+ message: `直播关闭状态或查询直播失败: ${str}`
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
rtc.on('conference_join_failed', err => {
|
|
|
// 加入房间失败 err为错误原因
|
|
|
console.log('加入房间失败', err);
|
|
|
+ Message({
|
|
|
+ message: `加入房间失败:${err}`,
|
|
|
+ type: 'warning'
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
// 新增订阅流事件
|
|
@@ -172,6 +202,18 @@ export function initListener(vue) {
|
|
|
rtc.on('publishStreamErr', data => {
|
|
|
console.log('推流意外终止:' + data.streamName);
|
|
|
// 直播开启状态下,尝试重推这条流
|
|
|
+ publishStream('picture');
|
|
|
+ });
|
|
|
+
|
|
|
+ // 网络整体状态事件
|
|
|
+ rtc.on('netStatus', data => {
|
|
|
+ console.log(data.netStatus);
|
|
|
+ vue.netStatus = data.netStatus;
|
|
|
+ });
|
|
|
+
|
|
|
+ // 单条流状态通知事件
|
|
|
+ rtc.on('streamStatus', data => {
|
|
|
+ console.log(data);
|
|
|
});
|
|
|
|
|
|
rtc.on('kick_out', function () {
|
|
@@ -224,14 +266,22 @@ export function initListener(vue) {
|
|
|
GetLiveRoomInfo({ task_id: vue.task_id }).then(({ video_mode }) => {
|
|
|
console.log('创建本地流推流');
|
|
|
vue.roomInfo.video_mode = video_mode;
|
|
|
+ let device = store.state.app.liveDevice;
|
|
|
+ let video =
|
|
|
+ device.video.length > 0
|
|
|
+ ? { device: 'camera', resolution: 'vga', deviceId: device.video }
|
|
|
+ : false;
|
|
|
+ let audio = device.audio.length > 0 ? { deviceId: device.audio } : false;
|
|
|
+
|
|
|
const createData = {
|
|
|
- video: video_mode === 1,
|
|
|
- audio: true
|
|
|
+ video: video_mode === 1 ? video : false,
|
|
|
+ audio
|
|
|
};
|
|
|
+
|
|
|
rtc.createLocalStream({
|
|
|
streamName: 'picture',
|
|
|
createData,
|
|
|
- success: function (stream) {
|
|
|
+ success(stream) {
|
|
|
vue.connect = true;
|
|
|
vue.callLoading = false;
|
|
|
console.log('创建本地流成功', stream);
|
|
@@ -239,12 +289,12 @@ export function initListener(vue) {
|
|
|
stream.show('student');
|
|
|
publishStream('picture'); // 如果需要立即推流,执行 publish 方法
|
|
|
},
|
|
|
- fail: function (data) {
|
|
|
+ fail(data) {
|
|
|
console.log('创建本地流失败,应用层处理', data);
|
|
|
// 创建本地流失败,应用层处理
|
|
|
Message({
|
|
|
type: 'error',
|
|
|
- message: '创建本地流失败:' + data
|
|
|
+ message: '创建本地流失败:' + data.err
|
|
|
});
|
|
|
}
|
|
|
});
|