视频插件

main
刘妍 2 months ago
parent 3859ba2df3
commit 6bda14f90f

@ -3,6 +3,8 @@ import { defHttp } from '@/utils/http/axios';
enum Api {
VerifyToken = '/api/DroneDock/VerifyToken',
GetDroneDockflightInfos = '/api/DroneDock/GetDroneDockflightInfos',
GetTaskPicList = '/api/Manage/GetTaskPicList',
GetTaskVideoList = '/api/Manage/GetTaskVideoList',
}
export function getVerifyToken(token) {
@ -12,3 +14,15 @@ export function getVerifyToken(token) {
export function getDroneDockflightInfos(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,
});
}

@ -1,13 +1,21 @@
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 { getVerifyToken, getDroneDockflightInfos } from '@/api/workmanagement/droneDock';
import {
getVerifyToken,
getDroneDockflightInfos,
getTaskPicList,
getTaskVideoList,
} from '@/api/workmanagement/droneDock';
import TCPlayer from 'tcplayer.js';
import { useMessage } from '@/hooks/web/useMessage';
const { createMessage } = useMessage();
const bid = buildGUID();
let video_id;
let sn;
let live_url;
let video_time;
class LiveStreamPlugin {
constructor() {
@ -52,13 +60,11 @@ class LiveStreamPlugin {
console.log('LiveStreamPlugin startLiveStreamCall', serialNum, deviceType);
sn = 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;
let querys;
if (deviceType == 1) {
video_id = serialNum + '/' + airport.camera_index + '/' + airport.video_index;
querys = {
bid: bid,
method: 'live_start_push',
@ -82,6 +88,7 @@ class LiveStreamPlugin {
await GetUavPageByDocksn(params).then((res) => {
console.log('GetUavPageByDocksn', res);
if (res.items.length > 0) {
video_id = res.items[0].sn + '/' + uav.camera_index + '/' + uav.video_index;
querys = {
bid: bid,
method: 'live_start_push',
@ -138,19 +145,63 @@ class LiveStreamPlugin {
* zpkzxx
*/
console.log('LiveStreamPlugin takePicture', callback);
const querys = {
servicesTopic(sn, {
bid: bid,
method: 'camera_photo_take',
method: 'camera_mode_switch',
tid: buildGUID(),
timestamp: new Date().getTime(),
data: {
camera_mode: 0,
payload_index: uav.camera_index,
},
};
console.log(querys);
servicesTopic(sn, querys);
const data = {};
callback(data);
});
const time = new Date().getTime();
setTimeout(() => {
const querys = {
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() {
/**
@ -168,13 +219,26 @@ class LiveStreamPlugin {
});
servicesTopic(sn, {
bid: bid,
method: 'camera_recording_start',
method: 'camera_mode_switch',
tid: buildGUID(),
timestamp: new Date().getTime(),
data: {
camera_mode: 1,
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) {
/**
@ -184,17 +248,52 @@ class LiveStreamPlugin {
* true/false
*/
console.log('LiveStreamPlugin endVideoRecording', callback);
const time = new Date().getTime();
servicesTopic(sn, {
bid: bid,
method: 'camera_recording_stop',
tid: buildGUID(),
timestamp: new Date().getTime(),
timestamp: time,
data: {
payload_index: uav.camera_index,
},
});
const data = {};
callback(data);
client.subscribe('thing/product/' + sn + '/events', { qos: 2 }, () => {});
// 接收消息
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() {
/**

@ -29,3 +29,24 @@ export function buildGUID(): string {
}
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();
});
}

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

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

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

Loading…
Cancel
Save