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.

397 lines
11 KiB

3 years ago
<template>
<div class="mt20 flex-column flex-justify-start flex-align-center">
<div id="player" style="width: 720px; height: 420px; border: 1px solid"></div>
<p class="fz24">Live streaming source selection</p>
<div class="flex-row flex-justify-center flex-align-center mt10">
3 years ago
<template v-if="livePara.liveState && dronePara.isDockLive">
<span class="mr10">Lens:</span>
<a-radio-group v-model:value="dronePara.lensSelected" button-style="solid">
<a-radio-button v-for="lens in dronePara.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 Drone"
3 years ago
v-model:value="dronePara.droneSelected"
3 years ago
>
<a-select-option
v-for="item in dronePara.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="dronePara.cameraSelected"
3 years ago
>
<a-select-option
v-for="item in dronePara.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"
@select="onVideoSelect"
>
<a-select-option
v-for="item in dronePara.videoList"
:key="item.value"
:value="item.value"
>{{ 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"
>
<a-select-option
v-for="item in clarityList"
:key="item.value"
:value="item.value"
>{{ item.label }}</a-select-option
>
</a-select>
</div>
<p class="fz16 mt10">
Note: Obtain The Following Parameters From https://console.agora.io
</p>
<div class="flex-row flex-justify-center flex-align-center">
3 years ago
<span class="mr10">AppId:</span>
3 years ago
<a-input v-model:value="agoraPara.appid" placeholder="APP ID"></a-input>
3 years ago
<span class="ml10">Token:</span>
3 years ago
<a-input
class="ml10"
v-model:value="agoraPara.token"
placeholder="Token"
3 years ago
@change="encodeToken"
3 years ago
></a-input>
3 years ago
<span class="ml10">Channel:</span>
3 years ago
<a-input
class="ml10"
v-model:value="agoraPara.channel"
placeholder="Channel"
></a-input>
</div>
<div class="mt20 flex-row flex-justify-center flex-align-center">
3 years ago
<a-button v-if="livePara.liveState && dronePara.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="!livePara.liveState || !dronePara.isDockLive" class="ml20" type="primary" large @click="onRefresh"
3 years ago
>Refresh Live Capacity</a-button
>
</div>
</div>
</template>
<script lang="ts" setup>
import AgoraRTC, { IAgoraRTCClient, IAgoraRTCRemoteUser } from 'agora-rtc-sdk-ng'
import { message } from 'ant-design-vue'
import { onMounted, reactive } from 'vue'
3 years ago
import { uuidv4 } from '../utils/uuid'
3 years ago
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'
const root = getRoot()
const clarityList = [
{
value: 0,
label: 'Adaptive'
},
{
value: 1,
label: 'Smooth'
},
{
value: 2,
label: 'Standard'
},
{
value: 3,
label: 'HD'
},
{
value: 4,
label: 'Super Clear'
}
]
3 years ago
interface SelectOption {
value: any,
label: string,
more?: any
}
3 years ago
let agoraClient = {} as IAgoraRTCClient
const agoraPara = reactive({
appid: config.agoraAPPID,
token: config.agoraToken,
channel: config.agoraChannel,
uid: 123456,
stream: {}
})
const dronePara = reactive({
livestreamSource: [],
3 years ago
droneList: [] as SelectOption[],
cameraList: [] as SelectOption[],
videoList: [] as SelectOption[],
droneSelected: undefined as string | undefined,
cameraSelected: undefined as string | undefined,
videoSelected: undefined as string | undefined,
claritySelected: 0,
lensList: [] as string[],
lensSelected: undefined as string | undefined,
isDockLive: false
3 years ago
})
const livePara = reactive({
url: '',
webrtc: {} as any,
videoId: '',
liveState: false
})
3 years ago
const nonSwitchable = 'normal'
3 years ago
const onRefresh = async () => {
dronePara.droneList = []
dronePara.cameraList = []
dronePara.videoList = []
3 years ago
dronePara.droneSelected = undefined
dronePara.cameraSelected = undefined
dronePara.videoSelected = undefined
3 years ago
await getLiveCapacity({})
.then(res => {
if (res.code === 0) {
if (res.data === null) {
console.warn('warning: get live capacity is null!!!')
return
}
dronePara.livestreamSource = res.data
dronePara.droneList = []
console.log('live_capacity:', dronePara.livestreamSource)
if (dronePara.livestreamSource) {
dronePara.livestreamSource.forEach((ele: any) => {
3 years ago
dronePara.droneList.push({ label: ele.name + '-' + ele.sn, value: ele.sn, more: ele.cameras_list })
3 years ago
})
}
}
})
.catch(error => {
3 years ago
message.error(error)
3 years ago
console.error(error)
})
}
onMounted(() => {
onRefresh()
3 years ago
agoraPara.token = encodeURIComponent(agoraPara.token)
3 years ago
agoraClient = AgoraRTC.createClient({ mode: 'live', codec: 'vp8' })
// Subscribe when a remote user publishes a stream
agoraClient.on('user-joined', async (user: IAgoraRTCRemoteUser) => {
message.info('user[' + user.uid + '] join')
})
agoraClient.on('user-published', async (user: IAgoraRTCRemoteUser, mediaType: 'audio' | 'video') => {
await agoraClient.subscribe(user, mediaType)
if (mediaType === 'video') {
console.log('subscribe success')
// Get `RemoteVideoTrack` in the `user` object.
const remoteVideoTrack = user.videoTrack!
// Dynamically create a container in the form of a DIV element for playing the remote video track.
const remotePlayerContainer: any = document.getElementById('player')
3 years ago
remotePlayerContainer.id = user.uid.toString()
3 years ago
remoteVideoTrack.play(remotePlayerContainer)
}
})
agoraClient.on('user-unpublished', async (user: any) => {
console.log('unpublish live:', user)
message.info('unpublish live')
})
3 years ago
agoraClient.on('exception', async (e: any) => {
console.error(e)
message.error(e.msg)
})
3 years ago
})
const handleError = (err: any) => {
console.error(err)
}
const handleJoinChannel = (uid: any) => {
agoraPara.uid = uid
}
3 years ago
const encodeToken = (e: any) => {
agoraPara.token = encodeURIComponent(agoraPara.token)
}
3 years ago
const onStart = async () => {
const that = this
console.log(
'drone parameter:',
dronePara.droneSelected,
dronePara.cameraSelected,
dronePara.videoSelected,
dronePara.claritySelected
)
const timestamp = new Date().getTime().toString()
const liveTimestamp = timestamp
if (
dronePara.droneSelected == null ||
dronePara.cameraSelected == null ||
dronePara.claritySelected == null
) {
message.warn('waring: not select live para!!!')
return
}
3 years ago
agoraClient.setClientRole('audience', { level: 2 })
3 years ago
if (agoraClient.connectionState === 'DISCONNECTED') {
agoraClient
.join(agoraPara.appid, agoraPara.channel, agoraPara.token)
}
livePara.videoId =
dronePara.droneSelected +
'/' +
3 years ago
dronePara.cameraSelected + '/' + (dronePara.videoSelected || nonSwitchable + '-0')
3 years ago
console.log(agoraPara)
livePara.url =
'channel=' +
agoraPara.channel +
'&sn=' +
dronePara.droneSelected +
'&token=' +
agoraPara.token +
'&uid=' +
agoraPara.uid
startLivestream({
url: livePara.url,
video_id: livePara.videoId,
url_type: 0,
video_quality: dronePara.claritySelected
})
.then(res => {
3 years ago
if (res.code !== 0) {
return
}
3 years ago
livePara.liveState = true
})
.catch(err => {
console.error(err)
})
}
const onStop = async () => {
livePara.videoId =
dronePara.droneSelected +
'/' +
dronePara.cameraSelected + '/' + (dronePara.videoSelected || nonSwitchable + '-0')
3 years ago
stopLivestream({
video_id: livePara.videoId
}).then(res => {
if (res.code === 0) {
message.success(res.message)
}
livePara.liveState = false
3 years ago
dronePara.lensSelected = ''
3 years ago
console.log('stop play livestream')
})
}
3 years ago
const onDroneSelect = (val: SelectOption) => {
dronePara.cameraList = []
dronePara.videoList = []
dronePara.lensList = []
3 years ago
3 years ago
dronePara.cameraSelected = undefined
dronePara.videoSelected = undefined
dronePara.lensSelected = undefined
dronePara.droneSelected = val.value
if (!val.more) {
return
3 years ago
}
3 years ago
val.more.forEach((ele: any) => {
dronePara.cameraList.push({ label: ele.name, value: ele.index, more: ele.videos_list })
})
3 years ago
}
3 years ago
const onCameraSelect = (val: SelectOption) => {
dronePara.cameraSelected = val.value
dronePara.videoSelected = undefined
dronePara.lensSelected = undefined
dronePara.videoList = []
dronePara.lensList = []
if (!val.more) {
return
}
3 years ago
3 years ago
val.more.forEach((ele: any) => {
dronePara.videoList.push({ label: ele.type, value: ele.index, more: ele.switch_video_types })
})
if (dronePara.videoList.length === 0) {
return
3 years ago
}
3 years ago
const firstVideo: SelectOption = dronePara.videoList[0]
dronePara.videoSelected = firstVideo.value
dronePara.lensList = firstVideo.more
dronePara.lensSelected = firstVideo.label
dronePara.isDockLive = dronePara.lensList.length > 0
3 years ago
}
3 years ago
const onVideoSelect = (val: SelectOption) => {
dronePara.videoSelected = val.value
dronePara.lensList = val.more
dronePara.lensSelected = val.label
3 years ago
}
const onClaritySelect = (val: any) => {
dronePara.claritySelected = val
}
const onUpdateQuality = () => {
if (!livePara.liveState) {
message.info('Please turn on the livestream first.')
return
}
setLivestreamQuality({
video_id: livePara.videoId,
video_quality: dronePara.claritySelected
}).then(res => {
if (res.code === 0) {
message.success('Set the clarity to ' + clarityList[dronePara.claritySelected].label)
}
})
}
3 years ago
const onSwitch = () => {
if (dronePara.lensSelected === undefined || dronePara.lensSelected === nonSwitchable) {
message.info('The ' + nonSwitchable + ' lens cannot be switched, please select the lens to be switched.', 8)
return
}
changeLivestreamLens({
video_id: livePara.videoId,
video_type: dronePara.lensSelected
}).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>