You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

417 lines
11 KiB

3 years ago
<template>
<div class="flex-column flex-justify-start flex-align-center mt20">
<video
:style="{ width: '720px', height: '480px' }"
id="video-webrtc"
ref="videowebrtc"
controls
class="mt20"
></video>
<p class="fz24">Live streaming source selection</p>
3 years ago
3 years ago
<div class="flex-row flex-justify-center flex-align-center mt10">
3 years ago
<template v-if="liveState && isDockLive">
<span class="mr10">Lens:</span>
<a-radio-group v-model:value="lensSelected" button-style="solid">
<a-radio-button v-for="lens in lensList" :key="lens" :value="lens">{{lens}}</a-radio-button>
</a-radio-group>
</template>
<template v-else>
3 years ago
<a-select
style="width: 150px"
placeholder="Select Live Type"
@select="onLiveTypeSelect"
3 years ago
v-model:value="livetypeSelected"
3 years ago
>
<a-select-option
v-for="item in liveTypeList"
:key="item.label"
:value="item.value"
>
{{ item.label }}
</a-select-option>
</a-select>
<a-select
class="ml10"
style="width:150px"
placeholder="Select Drone"
3 years ago
v-model:value="droneSelected"
3 years ago
>
<a-select-option
v-for="item in droneList"
:key="item.value"
:value="item.value"
3 years ago
@click="onDroneSelect(item)"
3 years ago
>{{ item.label }}</a-select-option
>
</a-select>
<a-select
class="ml10"
style="width:150px"
placeholder="Select Camera"
3 years ago
v-model:value="cameraSelected"
3 years ago
>
<a-select-option
v-for="item in cameraList"
:key="item.value"
:value="item.value"
3 years ago
@click="onCameraSelect(item)"
3 years ago
>{{ item.label }}</a-select-option
>
</a-select>
<!-- <a-select
class="ml10"
style="width:150px"
placeholder="Select Lens"
3 years ago
v-model:value="videoSelected"
3 years ago
>
<a-select-option
v-for="item in videoList"
:key="item.value"
:value="item.value"
3 years ago
@click="onVideoSelect(item)"
3 years ago
>{{ item.label }}</a-select-option
>
</a-select> -->
3 years ago
</template>
3 years ago
<a-select
class="ml10"
style="width:150px"
placeholder="Select Clarity"
@select="onClaritySelect"
3 years ago
v-model:value="claritySelected"
3 years ago
>
<a-select-option
v-for="item in clarityList"
:key="item.value"
:value="item.value"
>{{ item.label }}</a-select-option
>
</a-select>
</div>
<div class="mt20">
<p class="fz10" v-if="livetypeSelected == 2">
Please use VLC media player to play the RTSP livestream !!!
</p>
<p class="fz10" v-if="livetypeSelected == 2">
RTSP Parameter:{{ rtspData }}
</p>
</div>
<div class="mt10 flex-row flex-justify-center flex-align-center">
3 years ago
<a-button v-if="liveState && isDockLive" type="primary" large @click="onSwitch">Switch Lens</a-button>
<a-button v-else type="primary" large @click="onStart">Play</a-button>
3 years ago
<a-button class="ml20" type="primary" large @click="onStop"
>Stop</a-button
>
<a-button class="ml20" type="primary" large @click="onUpdateQuality"
>Update Clarity</a-button
>
3 years ago
<a-button v-if="!liveState || !isDockLive" class="ml20" type="primary" large @click="onRefresh"
3 years ago
>Refresh Live Capacity</a-button
>
</div>
</div>
</template>
<script lang="ts" setup>
import { message } from 'ant-design-vue'
import { onMounted, reactive, ref } from 'vue'
import { CURRENT_CONFIG as config } from '/@/api/http/config'
3 years ago
import { changeLivestreamLens, getLiveCapacity, setLivestreamQuality, startLivestream, stopLivestream } from '/@/api/manage'
3 years ago
import { getRoot } from '/@/root'
import jswebrtc from '/@/vendors/jswebrtc.min.js'
const root = getRoot()
3 years ago
interface SelectOption {
value: any,
label: string,
more?: any
}
const liveTypeList: SelectOption[] = [
3 years ago
{
value: 1,
label: 'RTMP'
},
{
value: 2,
label: 'RTSP'
},
{
value: 3,
label: 'GB28181'
}
]
3 years ago
const clarityList: SelectOption[] = [
3 years ago
{
value: 0,
label: 'Adaptive'
},
{
value: 1,
label: 'Smooth'
},
{
value: 2,
label: 'Standard'
},
{
value: 3,
label: 'HD'
},
{
value: 4,
label: 'Super Clear'
}
]
const videowebrtc = ref(null)
const livestreamSource = ref()
const droneList = ref()
const cameraList = ref()
const videoList = ref()
const droneSelected = ref()
const cameraSelected = ref()
3 years ago
const videoSelected = ref()
const claritySelected = ref()
3 years ago
const videoId = ref()
const liveState = ref<boolean>(false)
const livetypeSelected = ref()
const rtspData = ref()
3 years ago
const lensList = ref<string[]>([])
const lensSelected = ref<String>()
const isDockLive = ref(false)
const nonSwitchable = 'normal'
3 years ago
const onRefresh = async () => {
droneList.value = []
cameraList.value = []
videoList.value = []
droneSelected.value = null
cameraSelected.value = null
3 years ago
videoSelected.value = null
3 years ago
await getLiveCapacity({})
.then(res => {
console.log(res)
if (res.code === 0) {
if (res.data === null) {
console.warn('warning: get live capacity is null!!!')
return
}
const resData: Array<[]> = res.data
console.log('live_capacity:', resData)
livestreamSource.value = resData
3 years ago
const temp: Array<SelectOption> = []
3 years ago
if (livestreamSource.value) {
livestreamSource.value.forEach((ele: any) => {
3 years ago
temp.push({ label: ele.name + '-' + ele.sn, value: ele.sn, more: ele.cameras_list })
3 years ago
})
droneList.value = temp
}
}
})
.catch(error => {
3 years ago
message.error(error)
3 years ago
console.error(error)
})
}
onMounted(() => {
onRefresh()
})
const onStart = async () => {
console.log(
'Param:',
livetypeSelected.value,
droneSelected.value,
cameraSelected.value,
3 years ago
videoSelected.value,
claritySelected.value
3 years ago
)
const timestamp = new Date().getTime().toString()
if (
livetypeSelected.value == null ||
droneSelected.value == null ||
cameraSelected.value == null ||
3 years ago
claritySelected.value == null
3 years ago
) {
message.warn('waring: not select live para!!!')
return
}
videoId.value =
3 years ago
droneSelected.value + '/' + cameraSelected.value + '/' + (videoSelected.value || nonSwitchable + '-0')
3 years ago
let liveURL = ''
switch (livetypeSelected.value) {
case 1: {
// RTMP
liveURL = config.rtmpURL + timestamp
break
}
case 2: {
// RTSP
liveURL = `userName=${config.rtspUserName}&password=${config.rtspPassword}&port=${config.rtspPort}`
break
}
case 3: {
liveURL = `serverIP=${config.gbServerIp}&serverPort=${config.gbServerPort}&serverID=${config.gbServerId}&agentID=${config.gbAgentId}&agentPassword=${config.gbPassword}&localPort=${config.gbAgentPort}&channel=${config.gbAgentChannel}`
break
}
default:
console.warn('warning: live type is not correct!!!')
break
}
await startLivestream({
url: liveURL,
video_id: videoId.value,
url_type: livetypeSelected.value,
3 years ago
video_quality: claritySelected.value
3 years ago
})
.then(res => {
3 years ago
if (res.code !== 0) {
return
}
3 years ago
if (livetypeSelected.value === 3) {
const url = res.data.url
const videoElement = videowebrtc.value
// gb28181,it will fail if not wait.
message.loading({
content: 'Loding...',
duration: 4,
onClose () {
const player = new jswebrtc.Player(url, {
video: videoElement,
autoplay: true,
onPlay: (obj: any) => {
console.log('start play livestream')
}
})
}
})
} else if (livetypeSelected.value === 2) {
console.log(res)
rtspData.value =
'url:' +
res.data.url +
'&username:' +
res.data.username +
'&password:' +
res.data.password
} else if (livetypeSelected.value === 1) {
const url = res.data.url
const videoElement = videowebrtc.value
console.log('start live:', url)
console.log(videoElement)
const player = new jswebrtc.Player(url, {
video: videoElement,
autoplay: true,
onPlay: (obj: any) => {
console.log('start play livestream')
}
})
}
3 years ago
liveState.value = true
3 years ago
})
.catch(err => {
console.error(err)
})
}
const onStop = () => {
stopLivestream({
video_id: videoId.value
}).then(res => {
if (res.code === 0) {
3 years ago
message.success(res.message)
3 years ago
liveState.value = false
3 years ago
lensSelected.value = undefined
3 years ago
console.log('stop play livestream')
}
})
}
const onUpdateQuality = () => {
if (!liveState.value) {
message.info('Please turn on the livestream first.')
return
}
setLivestreamQuality({
video_id: videoId.value,
3 years ago
video_quality: claritySelected.value
3 years ago
}).then(res => {
if (res.code === 0) {
3 years ago
message.success('Set the clarity to ' + clarityList[claritySelected.value].label)
3 years ago
}
})
}
const onLiveTypeSelect = (val: any) => {
livetypeSelected.value = val
}
3 years ago
const onDroneSelect = (val: SelectOption) => {
droneSelected.value = val.value
const temp: Array<SelectOption> = []
3 years ago
cameraList.value = []
3 years ago
cameraSelected.value = undefined
videoSelected.value = undefined
videoList.value = []
lensList.value = []
if (!val.more) {
return
3 years ago
}
3 years ago
val.more.forEach((ele: any) => {
temp.push({ label: ele.name, value: ele.index, more: ele.videos_list })
})
cameraList.value = temp
3 years ago
}
3 years ago
const onCameraSelect = (val: SelectOption) => {
cameraSelected.value = val.value
const result: Array<SelectOption> = []
videoSelected.value = undefined
videoList.value = []
lensList.value = []
if (!val.more) {
return
}
val.more.forEach((ele: any) => {
result.push({ label: ele.type, value: ele.index, more: ele.switch_video_types })
})
videoList.value = result
if (videoList.value.length === 0) {
return
3 years ago
}
3 years ago
const firstVideo: SelectOption = videoList.value[0]
videoSelected.value = firstVideo.value
lensList.value = firstVideo.more
lensSelected.value = firstVideo.label
isDockLive.value = lensList.value.length > 0
3 years ago
}
3 years ago
const onVideoSelect = (val: SelectOption) => {
videoSelected.value = val.value
lensList.value = val.more
lensSelected.value = val.label
3 years ago
}
const onClaritySelect = (val: any) => {
3 years ago
claritySelected.value = val
}
const onSwitch = () => {
if (lensSelected.value === undefined || lensSelected.value === nonSwitchable) {
message.info('The ' + nonSwitchable + ' lens cannot be switched, please select the lens to be switched.', 8)
return
}
changeLivestreamLens({
video_id: videoId.value,
video_type: lensSelected.value
}).then(res => {
if (res.code === 0) {
message.success('Switching live camera successfully.')
}
})
3 years ago
}
</script>
<style lang="scss" scoped>
@import '/@/styles/index.scss';
</style>