|
|
@@ -1,5 +1,5 @@
|
|
|
<script>
|
|
|
-import { createWatchCore } from '@polyv/live-watch-sdk';
|
|
|
+import { createWatchCore, PlayerEvents, ChatEvents } from '@polyv/live-watch-sdk';
|
|
|
|
|
|
export default {
|
|
|
name: "LiveVideo",
|
|
|
@@ -16,7 +16,7 @@ export default {
|
|
|
this.watchCore = createWatchCore({
|
|
|
channelId: "4247961",
|
|
|
userInfo: {
|
|
|
- userId: "test1"
|
|
|
+ userId: this.$route.query.id || "e6soizn34h"
|
|
|
}
|
|
|
})
|
|
|
|
|
|
@@ -26,6 +26,7 @@ export default {
|
|
|
// 连接
|
|
|
await this.watchCore.connect();
|
|
|
await this.createPlayer();
|
|
|
+ this.getChatContent();
|
|
|
} catch (err) {
|
|
|
console.error(err);
|
|
|
}
|
|
|
@@ -47,10 +48,34 @@ export default {
|
|
|
|
|
|
// 创建播放器
|
|
|
async createPlayer() {
|
|
|
+ this.watchCore.player.eventEmitter.on(PlayerEvents.PlayerInfoChange, (data) => {
|
|
|
+ const playerInfo = data.playerInfo;
|
|
|
+ console.log('播放状态', playerInfo.playStatus);
|
|
|
+ });
|
|
|
+
|
|
|
await this.watchCore.player.setupPlayer({
|
|
|
container: document.getElementById('liveVideoContainer'),
|
|
|
+ barrageEnabled: false,
|
|
|
+ autoplay: true,
|
|
|
+ barrageShow: false,
|
|
|
+ showController: false,
|
|
|
// lowLatency: true, // 使用无延迟播放
|
|
|
});
|
|
|
+ },
|
|
|
+
|
|
|
+ // 获取聊天内容
|
|
|
+ async getChatContent() {
|
|
|
+ console.log("来获取聊天内容啦")
|
|
|
+ const list = await this.watchCore.chat.getChatHistory();
|
|
|
+ console.log("聊天内容", list);
|
|
|
+ this.listenChat();
|
|
|
+ },
|
|
|
+
|
|
|
+ // 监听聊天信息
|
|
|
+ async listenChat() {
|
|
|
+ this.watchCore.chat.eventEmitter.on(ChatEvents.ChatMessage, (data) => {
|
|
|
+ console.log("聊天信息", data);
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
}
|