|
@@ -13,7 +13,7 @@
|
|
</el-col>
|
|
</el-col>
|
|
</el-col>
|
|
</el-col>
|
|
<el-col :span="24" class="live">
|
|
<el-col :span="24" class="live">
|
|
- <el-col :span="24" class="liveInfo">
|
|
|
|
|
|
+ <el-col :span="24" class="liveInfo" id="liveScreen">
|
|
直播
|
|
直播
|
|
</el-col>
|
|
</el-col>
|
|
</el-col>
|
|
</el-col>
|
|
@@ -23,10 +23,12 @@
|
|
</template>
|
|
</template>
|
|
|
|
|
|
<script>
|
|
<script>
|
|
|
|
+import TRTC from 'trtc-js-sdk';
|
|
import detailFrame from '@frame/layout/admin/detail-frame';
|
|
import detailFrame from '@frame/layout/admin/detail-frame';
|
|
import { mapState, createNamespacedHelpers } from 'vuex';
|
|
import { mapState, createNamespacedHelpers } from 'vuex';
|
|
const { mapActions: subject } = createNamespacedHelpers('subject');
|
|
const { mapActions: subject } = createNamespacedHelpers('subject');
|
|
const { mapActions: liveroom } = createNamespacedHelpers('liveroom');
|
|
const { mapActions: liveroom } = createNamespacedHelpers('liveroom');
|
|
|
|
+const { mapActions: gensign } = createNamespacedHelpers('gensign');
|
|
export default {
|
|
export default {
|
|
metaInfo: { title: '在线直播' },
|
|
metaInfo: { title: '在线直播' },
|
|
name: 'live',
|
|
name: 'live',
|
|
@@ -40,15 +42,25 @@ export default {
|
|
info: {},
|
|
info: {},
|
|
// 科目列表
|
|
// 科目列表
|
|
subjectList: [],
|
|
subjectList: [],
|
|
|
|
+ // 直播相关变量
|
|
|
|
+ sdkAppId: '1400414461',
|
|
|
|
+ client: null,
|
|
|
|
+ userMainId: '',
|
|
|
|
+ cameras: [],
|
|
|
|
+ microphones: [],
|
|
|
|
+ localStream_: [], //流
|
|
};
|
|
};
|
|
},
|
|
},
|
|
- created() {
|
|
|
|
|
|
+ async created() {
|
|
this.getOtherList();
|
|
this.getOtherList();
|
|
if (this.id) {
|
|
if (this.id) {
|
|
this.search();
|
|
this.search();
|
|
}
|
|
}
|
|
|
|
+ await this.initclient();
|
|
|
|
+ await this.getDevices();
|
|
},
|
|
},
|
|
methods: {
|
|
methods: {
|
|
|
|
+ ...gensign(['gensignFetch']),
|
|
...subject({ getSubjectList: 'query' }),
|
|
...subject({ getSubjectList: 'query' }),
|
|
...liveroom(['fetch', 'create', 'update']),
|
|
...liveroom(['fetch', 'create', 'update']),
|
|
// 查詢詳情
|
|
// 查詢詳情
|
|
@@ -80,7 +92,7 @@ export default {
|
|
message: '开始直播',
|
|
message: '开始直播',
|
|
type: 'success',
|
|
type: 'success',
|
|
});
|
|
});
|
|
- this.search();
|
|
|
|
|
|
+ this.toStart();
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
let res = await this.update(data);
|
|
let res = await this.update(data);
|
|
@@ -93,6 +105,41 @@ export default {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
+ // 初始化
|
|
|
|
+ async initclient() {
|
|
|
|
+ this.userMainId = 'mainr-' + this.user.userid;
|
|
|
|
+ const res = await this.gensignFetch({ userid: this.userMainId });
|
|
|
|
+ if (this.$checkRes(res)) {
|
|
|
|
+ this.client = await TRTC.createClient({
|
|
|
|
+ mode: 'live',
|
|
|
|
+ sdkAppId: this.sdkAppId,
|
|
|
|
+ userId: this.userMainId,
|
|
|
|
+ userSig:
|
|
|
|
+ 'eJwtzTEPgjAQBeD-0lXFtl5pS*KgMhmjg6AOLtUWchIQgRCN8b9LgPG*l-fuS6Ld0WtdRQLCPUqm-Y3WFQ0m2HNusKhmIuE3KZ2Gu1loIzQFxazw9diobWbKEi0JGFAKDMBnQ*LeJVaucyEEp5QO2mDem1ZMUyH5uIJp9zAtTo8zbGMVrlQYqfUpzSIdTzaHV8t8eZ3nUkFtn59kf8mW5PcHFLs3aw__',
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ // 调用设备
|
|
|
|
+ async getDevices() {
|
|
|
|
+ this.cameras = await TRTC.getCameras();
|
|
|
|
+ this.microphones = await TRTC.getMicrophones();
|
|
|
|
+ },
|
|
|
|
+ // 开始直播
|
|
|
|
+ async toStart() {
|
|
|
|
+ await this.client.join({ roomId: 980890, role: 'anchor' });
|
|
|
|
+ this.localStream_ = await TRTC.createStream({
|
|
|
|
+ audio: true,
|
|
|
|
+ video: true,
|
|
|
|
+ cameraId: this.cameras[0].deviceId,
|
|
|
|
+ microphoneId: this.microphones[0].deviceId,
|
|
|
|
+ userId: this.userMainId,
|
|
|
|
+ });
|
|
|
|
+ this.localStream_.setVideoProfile('480p');
|
|
|
|
+ await this.localStream_.initialize();
|
|
|
|
+ console.log('initialize local stream success');
|
|
|
|
+ await this.client_.publish(this.localStream_);
|
|
|
|
+ this.localStream_.play('liveScreen');
|
|
|
|
+ },
|
|
},
|
|
},
|
|
computed: {
|
|
computed: {
|
|
...mapState(['user']),
|
|
...mapState(['user']),
|