Compare commits

...

2 Commits

6 changed files with 154 additions and 24 deletions

View File

@ -3,6 +3,8 @@ import { defHttp } from '@/utils/http/axios';
enum Api { enum Api {
VerifyToken = '/api/DroneDock/VerifyToken', VerifyToken = '/api/DroneDock/VerifyToken',
GetDroneDockflightInfos = '/api/DroneDock/GetDroneDockflightInfos', GetDroneDockflightInfos = '/api/DroneDock/GetDroneDockflightInfos',
GetTaskPicList = '/api/Manage/GetTaskPicList',
GetTaskVideoList = '/api/Manage/GetTaskVideoList',
} }
export function getVerifyToken(token) { export function getVerifyToken(token) {
@ -12,3 +14,15 @@ export function getVerifyToken(token) {
export function getDroneDockflightInfos(id) { export function getDroneDockflightInfos(id) {
return defHttp.get({ url: Api.GetDroneDockflightInfos + '?taskid=' + id }); return defHttp.get({ url: Api.GetDroneDockflightInfos + '?taskid=' + id });
} }
export function getTaskPicList(params) {
return defHttp.get({
url: Api.GetTaskPicList + '?flightId=' + params.flightId + '&timestamp=' + params.timestamp,
});
}
export function getTaskVideoList(params) {
return defHttp.get({
url: Api.GetTaskVideoList + '?flightId=' + params.flightId + '&timestamp=' + params.timestamp,
});
}

View File

@ -1,13 +1,21 @@
import { createConnection, client, servicesTopic, destroyConnection } from './src/mqtt'; import { createConnection, client, servicesTopic, destroyConnection } from './src/mqtt';
import { airport, uav, liveInfo, buildGUID } from './src/config'; import { airport, uav, liveInfo, buildGUID, base64ByURL } from './src/config';
import { GetUavPageByDocksn } from '@/api/demo/projecthome'; import { GetUavPageByDocksn } from '@/api/demo/projecthome';
import { getVerifyToken, getDroneDockflightInfos } from '@/api/workmanagement/droneDock'; import {
getVerifyToken,
getDroneDockflightInfos,
getTaskPicList,
getTaskVideoList,
} from '@/api/workmanagement/droneDock';
import TCPlayer from 'tcplayer.js'; import TCPlayer from 'tcplayer.js';
import { useMessage } from '@/hooks/web/useMessage';
const { createMessage } = useMessage();
const bid = buildGUID(); const bid = buildGUID();
let video_id; let video_id;
let sn; let sn;
let live_url; let live_url;
let video_time;
class LiveStreamPlugin { class LiveStreamPlugin {
constructor() { constructor() {
@ -52,13 +60,11 @@ class LiveStreamPlugin {
console.log('LiveStreamPlugin startLiveStreamCall', serialNum, deviceType); console.log('LiveStreamPlugin startLiveStreamCall', serialNum, deviceType);
sn = serialNum; sn = serialNum;
createConnection('mqtt_' + serialNum); createConnection('mqtt_' + serialNum);
video_id =
deviceType == 1
? serialNum + '/' + airport.camera_index + '/' + airport.video_index
: serialNum + '/' + uav.camera_index + '/' + uav.video_index;
// const liveUrl = liveInfo.rtmp + serialNum; // const liveUrl = liveInfo.rtmp + serialNum;
let querys; let querys;
if (deviceType == 1) { if (deviceType == 1) {
video_id = serialNum + '/' + airport.camera_index + '/' + airport.video_index;
querys = { querys = {
bid: bid, bid: bid,
method: 'live_start_push', method: 'live_start_push',
@ -82,6 +88,7 @@ class LiveStreamPlugin {
await GetUavPageByDocksn(params).then((res) => { await GetUavPageByDocksn(params).then((res) => {
console.log('GetUavPageByDocksn', res); console.log('GetUavPageByDocksn', res);
if (res.items.length > 0) { if (res.items.length > 0) {
video_id = res.items[0].sn + '/' + uav.camera_index + '/' + uav.video_index;
querys = { querys = {
bid: bid, bid: bid,
method: 'live_start_push', method: 'live_start_push',
@ -138,19 +145,63 @@ class LiveStreamPlugin {
* zpkzxx * zpkzxx
*/ */
console.log('LiveStreamPlugin takePicture', callback); console.log('LiveStreamPlugin takePicture', callback);
const querys = { servicesTopic(sn, {
bid: bid, bid: bid,
method: 'camera_photo_take', method: 'camera_mode_switch',
tid: buildGUID(), tid: buildGUID(),
timestamp: new Date().getTime(), timestamp: new Date().getTime(),
data: { data: {
camera_mode: 0,
payload_index: uav.camera_index, payload_index: uav.camera_index,
}, },
}; });
console.log(querys); const time = new Date().getTime();
servicesTopic(sn, querys); setTimeout(() => {
const data = {}; const querys = {
callback(data); bid: bid,
method: 'camera_photo_take',
tid: buildGUID(),
timestamp: time,
data: {
payload_index: uav.camera_index,
},
};
console.log(querys);
servicesTopic(sn, querys);
client.subscribe('thing/product/' + sn + '/events', { qos: 2 }, () => {});
}, 1000);
// 接收消息
let id = '';
return new Promise((resolve, reject) => {
client.on('message', async (topic, message) => {
const rs = JSON.parse(message);
if (
rs.method == 'flighttask_progress' &&
rs.data.output.status == 'in_progress' &&
id == ''
) {
id = rs.data.output.ext.flight_id;
createMessage.info('正在获取数据,预计需要一分钟,请稍后');
setTimeout(() => {
getTaskPicList({
flightId: id,
timestamp: time,
}).then(async (res) => {
if (res) {
await base64ByURL(res.pictureLink).then((urlres) => {
let { blob } = urlres;
res.imgBlob = blob;
});
createMessage.success('获取数据成功');
} else {
createMessage.error('获取数据失败,请稍后重试');
}
resolve(callback(res));
});
}, 50000);
}
});
});
} }
startVideoRecording() { startVideoRecording() {
/** /**
@ -168,13 +219,26 @@ class LiveStreamPlugin {
}); });
servicesTopic(sn, { servicesTopic(sn, {
bid: bid, bid: bid,
method: 'camera_recording_start', method: 'camera_mode_switch',
tid: buildGUID(), tid: buildGUID(),
timestamp: new Date().getTime(), timestamp: new Date().getTime(),
data: { data: {
camera_mode: 1,
payload_index: uav.camera_index, payload_index: uav.camera_index,
}, },
}); });
setTimeout(() => {
video_time = new Date().getTime();
servicesTopic(sn, {
bid: bid,
method: 'camera_recording_start',
tid: buildGUID(),
timestamp: video_time,
data: {
payload_index: uav.camera_index,
},
});
}, 1000);
} }
endVideoRecording(callback: Function) { endVideoRecording(callback: Function) {
/** /**
@ -184,17 +248,52 @@ class LiveStreamPlugin {
* true/false * true/false
*/ */
console.log('LiveStreamPlugin endVideoRecording', callback); console.log('LiveStreamPlugin endVideoRecording', callback);
const time = new Date().getTime();
servicesTopic(sn, { servicesTopic(sn, {
bid: bid, bid: bid,
method: 'camera_recording_stop', method: 'camera_recording_stop',
tid: buildGUID(), tid: buildGUID(),
timestamp: new Date().getTime(), timestamp: time,
data: { data: {
payload_index: uav.camera_index, payload_index: uav.camera_index,
}, },
}); });
const data = {}; client.subscribe('thing/product/' + sn + '/events', { qos: 2 }, () => {});
callback(data); // 接收消息
let id = '';
return new Promise((resolve, reject) => {
client.on('message', async (topic, message) => {
const rs = JSON.parse(message);
if (
rs.method == 'flighttask_progress' &&
rs.data.output.status == 'in_progress' &&
id == ''
) {
id = rs.data.output.ext.flight_id;
createMessage.info('正在获取数据,预计需要五分钟,请稍后');
setTimeout(() => {
getTaskVideoList({
flightId: id,
timestamp: video_time,
}).then(async (res) => {
if (res) {
await base64ByURL(res.videoLink).then((urlres) => {
let { blob } = urlres;
console.log(blob);
res.videoBlob = blob;
console.log(res);
});
createMessage.success('获取数据成功');
} else {
createMessage.error('获取数据失败,请稍后重试');
}
resolve(callback(res));
});
}, 300000);
}
});
});
} }
disposeSDK() { disposeSDK() {
/** /**

View File

@ -29,3 +29,24 @@ export function buildGUID(): string {
} }
return guid; return guid;
} }
// 图片地址 转为 blob 、base64格式 imgUrl类型为字符串string
export function base64ByURL(imgUrl) {
// 两大重点 Promise XMLHttpRequest
return new Promise((resolve) => {
var xhr = new XMLHttpRequest();
xhr.open('get', imgUrl, true);
xhr.responseType = 'blob';
xhr.onload = function () {
if (this.status == 200) {
let blob = this.response;
let oFileReader = new FileReader();
oFileReader.onloadend = function (e) {
resolve({ blob, base64: e.target.result });
};
oFileReader.readAsDataURL(blob);
}
};
xhr.send();
});
}

View File

@ -20,7 +20,7 @@
liveStreamPlugin.startLiveStreamCall('8UUXN5400A079H', 1); liveStreamPlugin.startLiveStreamCall('8UUXN5400A079H', 1);
}; };
const startUAV = () => { const startUAV = () => {
liveStreamPlugin.startLiveStreamCall('1581F8HGX254V00A0BUY', 0); liveStreamPlugin.startLiveStreamCall('8UUXN5400A079H', 0);
}; };
const startRecording = () => { const startRecording = () => {
liveStreamPlugin.startVideoRecording(); liveStreamPlugin.startVideoRecording();

View File

@ -120,11 +120,7 @@
// tid: buildGUID(), // tid: buildGUID(),
// timestamp: new Date().getTime(), // timestamp: new Date().getTime(),
// data: { // data: {
// air_transfer_enable: 1, // air_transfer_enable: true,
// cameras: {
// zoom_factor: 2,
// ir_zoom_factor: 2,
// },
// }, // },
// }; // };
// console.log(querys); // console.log(querys);

View File

@ -550,7 +550,7 @@
} }
} else { } else {
drc_eart_beat(); drc_eart_beat();
createMessage.error('DRC连接失败' + errorName(rs.data.result)); createMessage.error('DRC连接中断' + errorName(rs.data.result) + ',正在重新连接');
} }
} }
// //