|
|
@@ -22,6 +22,44 @@
|
|
|
</div>
|
|
|
</div>
|
|
|
</template>
|
|
|
+ <div
|
|
|
+ v-if="controls"
|
|
|
+ class="l-flex--row c-footer"
|
|
|
+ >
|
|
|
+ <div class="l-flex__fill c-sibling-item u-ellipsis">{{ device.name }}</div>
|
|
|
+ <div
|
|
|
+ v-if="online"
|
|
|
+ class="l-flex__none c-sibling-item o-quality-menu"
|
|
|
+ @click.stop="toggleQualityMenu"
|
|
|
+ >
|
|
|
+ <div
|
|
|
+ v-if="showQualityMenu"
|
|
|
+ class="o-quality-menu__list"
|
|
|
+ >
|
|
|
+ <div
|
|
|
+ class="o-quality-menu__item u-pointer"
|
|
|
+ @click="changeQuality('fff')"
|
|
|
+ >
|
|
|
+ 标清
|
|
|
+ </div>
|
|
|
+ <div
|
|
|
+ class="o-quality-menu__item u-pointer"
|
|
|
+ @click="changeQuality('ff')"
|
|
|
+ >
|
|
|
+ 高清
|
|
|
+ </div>
|
|
|
+ <div
|
|
|
+ class="o-quality-menu__item u-pointer"
|
|
|
+ @click="changeQuality('')"
|
|
|
+ >
|
|
|
+ 原画
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <div class="u-pointer">
|
|
|
+ {{ qualityValue }}
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
<slot />
|
|
|
</div>
|
|
|
</template>
|
|
|
@@ -42,6 +80,10 @@ export default {
|
|
|
autoplay: {
|
|
|
type: [Boolean, String],
|
|
|
default: false
|
|
|
+ },
|
|
|
+ controls: {
|
|
|
+ type: [Boolean, String],
|
|
|
+ default: false
|
|
|
}
|
|
|
},
|
|
|
data () {
|
|
|
@@ -49,7 +91,9 @@ export default {
|
|
|
poster: videoPoster,
|
|
|
loading: false,
|
|
|
refreshShow: false,
|
|
|
- paused: false
|
|
|
+ paused: false,
|
|
|
+ showQualityMenu: false,
|
|
|
+ quality: ''
|
|
|
}
|
|
|
},
|
|
|
computed: {
|
|
|
@@ -67,19 +111,50 @@ export default {
|
|
|
},
|
|
|
online () {
|
|
|
return this.device.activate === 2 && this.device.onlineStatus === 1
|
|
|
+ },
|
|
|
+ qualityValue () {
|
|
|
+ switch (this.quality) {
|
|
|
+ case 'fff':
|
|
|
+ return '标清'
|
|
|
+ case 'ff':
|
|
|
+ return '高清'
|
|
|
+ default:
|
|
|
+ return '原画'
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
created () {
|
|
|
this.$timer = -1
|
|
|
if (this.online) {
|
|
|
this.getAuthCode()
|
|
|
+ if (this.controls) {
|
|
|
+ document.addEventListener('click', this.hideQualityMenu)
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
beforeDestroy () {
|
|
|
+ if (this.online && this.controls) {
|
|
|
+ document.removeEventListener('click', this.hideQualityMenu)
|
|
|
+ }
|
|
|
this.destroyPlayer()
|
|
|
this.$timer = null
|
|
|
},
|
|
|
methods: {
|
|
|
+ hideQualityMenu () {
|
|
|
+ this.showQualityMenu = false
|
|
|
+ },
|
|
|
+ toggleQualityMenu () {
|
|
|
+ this.showQualityMenu = !this.showQualityMenu
|
|
|
+ },
|
|
|
+ changeQuality (quality) {
|
|
|
+ if (this.quality !== quality) {
|
|
|
+ this.quality = quality
|
|
|
+ if (this.$playerInfo && this.$player) {
|
|
|
+ this.destroyPlayer()
|
|
|
+ this.createPlayer(this.$playerInfo)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
onPause () {
|
|
|
this.paused = true
|
|
|
},
|
|
|
@@ -115,10 +190,12 @@ export default {
|
|
|
return
|
|
|
}
|
|
|
this.loading = true
|
|
|
+ this.$playerInfo = null
|
|
|
authCode({ deviceId: this.device.id }).then(
|
|
|
({ data }) => {
|
|
|
if (this.$timer !== null) {
|
|
|
- this.createPlayer(data)
|
|
|
+ this.$playerInfo = data
|
|
|
+ this.createPlayer(this.$playerInfo)
|
|
|
}
|
|
|
},
|
|
|
() => {
|
|
|
@@ -128,11 +205,12 @@ export default {
|
|
|
},
|
|
|
createPlayer ({ timestamp, token, expire }) {
|
|
|
if (flvjs.isSupported()) {
|
|
|
+ const quality = this.quality ? `_${this.quality}` : ''
|
|
|
const player = flvjs.createPlayer({
|
|
|
type: 'flv',
|
|
|
isLive: true,
|
|
|
hasAudio: false,
|
|
|
- url: `${GATEWAY}/live/${this.device.id}.flv?authorization=${token}×tamp=${timestamp}&expire=${expire}`
|
|
|
+ url: `${GATEWAY}/live/${this.device.id}${quality}.flv?authorization=${token}×tamp=${timestamp}&expire=${expire}`
|
|
|
})
|
|
|
player.on(flvjs.Events.ERROR, e => {
|
|
|
console.log('flvjs', this.device.name, flvjs.Events.ERROR, e)
|
|
|
@@ -190,4 +268,39 @@ export default {
|
|
|
display: inline-block;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+.o-quality-menu {
|
|
|
+ display: inline-block;
|
|
|
+ position: relative;
|
|
|
+ padding: 0 6px;
|
|
|
+ z-index: 1;
|
|
|
+
|
|
|
+ &:hover {
|
|
|
+ .o-quality-menu__list {
|
|
|
+ display: inline-block;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ &__list {
|
|
|
+ display: none;
|
|
|
+ position: absolute;
|
|
|
+ right: 0;
|
|
|
+ bottom: 0;
|
|
|
+ width: 100%;
|
|
|
+ padding-bottom: 24px;
|
|
|
+ font-size: 14px;
|
|
|
+ text-align: center;
|
|
|
+ border-radius: $radius $radius 0 0;
|
|
|
+ background-color: rgba(#000, 0.3);
|
|
|
+ z-index: -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ &__item {
|
|
|
+ padding: 4px 0;
|
|
|
+
|
|
|
+ &:hover {
|
|
|
+ color: $primary;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
</style>
|