| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <script>
- import { createWatchCore, PlayerEvents, ChatEvents } from '@polyv/live-watch-sdk';
- export default {
- name: "LiveVideo",
- data() {
- return {
- watchCore: null
- }
- },
- mounted() {
- this.getWatchCore();
- },
- methods: {
- async getWatchCore() {
- this.watchCore = createWatchCore({
- channelId: "4247961",
- userInfo: {
- userId: this.$route.query.id || "e6soizn34h"
- }
- })
- try {
- await this.watchAuth();
- await this.watchCore.setup();
- // 连接
- await this.watchCore.connect();
- await this.createPlayer();
- this.getChatContent();
- } catch (err) {
- console.error(err);
- }
- },
- // 观看授权
- watchAuth() {
- return new Promise( (resolve, reject) => {
- this.watchCore.auth.verifyNoneAuth().then(result => {
- if (result.success) {
- resolve(result)
- } else {
- reject(result)
- }
- });
- })
- },
- // 创建播放器
- 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);
- });
- }
- }
- }
- </script>
- <template>
- <div class="live-video" id="liveVideoContainer"></div>
- </template>
- <style scoped>
- .live-video {
- width: 100%;
- //height: 56.25vw;
- }
- /deep/ .plwrap {
- background: transparent;
- }
- </style>
|