648540858
2023-01-13 dea44dcd78418ed3e7f191a73cee2b81a7a0019f
web_src/src/components/dialog/devicePlayer.vue
@@ -4,9 +4,6 @@
    <el-dialog title="视频播放" top="0" :close-on-click-modal="false" :visible.sync="showVideoDialog" @close="close()">
      <div style="width: 100%; height: 100%">
        <el-tabs type="card" :stretch="true" v-model="activePlayer" @tab-click="changePlayer" v-if="Object.keys(this.player).length > 1">
<!--          <el-tab-pane label="LivePlayer" name="livePlayer">-->
<!--            <LivePlayer v-if="showVideoDialog" ref="livePlayer" :visible.sync="showVideoDialog" :videoUrl="videoUrl" :error="videoError" :message="videoError" :hasaudio="hasAudio" fluent autoplay live></LivePlayer>-->
<!--          </el-tab-pane>-->
          <el-tab-pane label="Jessibuca" name="jessibuca">
            <jessibucaPlayer v-if="activePlayer === 'jessibuca'" ref="jessibuca" :visible.sync="showVideoDialog" :videoUrl="videoUrl" :error="videoError" :message="videoError" height="100px" :hasAudio="hasAudio" fluent autoplay live ></jessibucaPlayer>
          </el-tab-pane>
@@ -232,6 +229,18 @@
                    </div>
                </el-tab-pane>
              <el-tab-pane label="语音对讲" name="broadcast" >
                <div class="trank" style="text-align: center;">
                  <el-button @click="broadcastStatusClick()" :type="getBroadcastStatus()" :disabled="broadcastStatus === -2" circle icon="el-icon-microphone"  style="font-size: 32px; padding: 24px;margin-top: 24px;"/>
                  <p>
                    <span v-if="broadcastStatus === -2">正在释放资源</span>
                    <span v-if="broadcastStatus === -1">点击开始对讲</span>
                    <span v-if="broadcastStatus === 0">等待接通中...</span>
                    <span v-if="broadcastStatus === 1">请说话</span>
                  </p>
                </div>
              </el-tab-pane>
            </el-tabs>
        </div>
@@ -242,6 +251,7 @@
<script>
import rtcPlayer from '../dialog/rtcPlayer.vue'
import LivePlayer from '@liveqing/liveplayer'
import crypto from 'crypto'
import jessibucaPlayer from '../common/jessibuca.vue'
export default {
    name: 'devicePlayer',
@@ -259,7 +269,9 @@
        }
    },
    created() {
      console.log("created")
      console.log(this.player)
      this.broadcastStatus = -1;
      if (Object.keys(this.player).length === 1) {
        this.activePlayer = Object.keys(this.player)[0]
      }
@@ -272,7 +284,6 @@
            // 如何你只是用一种播放器,直接注释掉不用的部分即可
            player: {
              jessibuca : ["ws_flv", "wss_flv"],
              livePlayer : ["ws_flv", "wss_flv"],
              webRTC: ["rtc", "rtcs"],
            },
            showVideoDialog: false,
@@ -308,6 +319,8 @@
            recordStartTime: 0,
            showTimeText: "00:00:00",
            streamInfo: null,
            broadcastRtc: null,
            broadcastStatus: -1, // -2 正在释放资源 -1 默认状态 0 等待接通 1 接通成功
        };
    },
    methods: {
@@ -465,6 +478,7 @@
              this.convertStop();
            }
            this.convertKey = ''
            this.stopBroadcast()
        },
        copySharedInfo: function (data) {
@@ -537,7 +551,75 @@
        },
              this.broadcastRtc.on(ZLMRTCClient.Events.WEBRTC_ICE_CANDIDATE_ERROR,(e)=>{// ICE 协商出错
                console.error('ICE 协商出错')
                this.$message({
                  showClose: true,
                  message: 'ICE 协商出错',
                  type: 'error'
                });
                this.broadcastStatus = -1;
              });
              this.broadcastRtc.on(ZLMRTCClient.Events.WEBRTC_OFFER_ANWSER_EXCHANGE_FAILED,(e)=>{// offer anwser 交换失败
                console.error('offer anwser 交换失败',e)
                this.$message({
                  showClose: true,
                  message: 'offer anwser 交换失败' + e,
                  type: 'error'
                });
                this.broadcastStatus = -1;
              });
              this.broadcastRtc.on(ZLMRTCClient.Events.WEBRTC_ON_CONNECTION_STATE_CHANGE,(e)=>{// offer anwser 交换失败
                console.log('状态改变',e)
                if (e === "connecting") {
                  this.broadcastStatus = 0;
                }else if (e === "connected") {
                  this.broadcastStatus = 1;
                }else if (e === "disconnected") {
                  this.broadcastStatus = -1;
                }
              });
              this.broadcastRtc.on(ZLMRTCClient.Events.CAPTURE_STREAM_FAILED,(e)=>{// offer anwser 交换失败
                console.log('捕获流失败',e)
                this.$message({
                  showClose: true,
                  message: '捕获流失败' + e,
                  type: 'error'
                });
                this.broadcastStatus = -1;
              });
            }
          }).catch((e) => {
            this.$message({
              showClose: true,
              message: e,
              type: 'error'
            });
            this.broadcastStatus = -1;
          });
        },
        stopBroadcast(){
          this.broadcastRtc.close();
          this.broadcastStatus = -1;
          this.$axios({
            method: 'get',
            url: '/api/play/broadcast/stop/' + this.deviceId + '/' + this.channelId
          }).then( (res)=> {
            if (res.data.code == 0) {
              // this.broadcastStatus = -1;
              // this.broadcastRtc.close()
            }else {
              this.$message({
                showClose: true,
                message: res.data.msg,
                type: "error",
              });
            }
          });
        }
    }
};
</script>