录制视频接口
This commit is contained in:
parent
f550648cf4
commit
e765a67fae
|
@ -80,6 +80,11 @@ enum class EventBusAddress(val address: String) {
|
||||||
*/
|
*/
|
||||||
SYS_DEVICE_CHANNEL_SCREENSHOT("MSG://EVENT/BUS/SQL/SYS/SYS_DEVICE_CHANNEL_SCREENSHOT"),
|
SYS_DEVICE_CHANNEL_SCREENSHOT("MSG://EVENT/BUS/SQL/SYS/SYS_DEVICE_CHANNEL_SCREENSHOT"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通道录制视频
|
||||||
|
*/
|
||||||
|
SYS_DEVICE_CHANNEL_RECORD_VIDEO("MSG://EVENT/BUS/SQL/SYS/SYS_DEVICE_CHANNEL_RECORD_VIDEO"),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取在线设备通道
|
* 获取在线设备通道
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -116,4 +116,47 @@ class MonitorController(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 录制视频
|
||||||
|
*/
|
||||||
|
fun recordVideo(requestHandler: RoutingContext) {
|
||||||
|
val userId = requestHandler.get<Int>("userId") // 用户id
|
||||||
|
val queryParams = requestHandler.queryParams()
|
||||||
|
val channelId = queryParams.get("channelId")
|
||||||
|
val subType = queryParams.get("subType")
|
||||||
|
val scheme = queryParams.get("scheme")
|
||||||
|
val duration = queryParams.get("duration")
|
||||||
|
event!!.request<JsonArray>(EventBusAddress.SYS_MONITOR_USER_ALLMONITORUSER_TOKEN.address, JsonObject()) {
|
||||||
|
if (it.succeeded()) {
|
||||||
|
val token = it.result().body().stream().filter { index ->
|
||||||
|
index as JsonObject
|
||||||
|
index.getInteger("id") == userId
|
||||||
|
}.findFirst()
|
||||||
|
token.ifPresent { tokenInfo ->
|
||||||
|
tokenInfo as JsonObject
|
||||||
|
tokenInfo.put("channelId", channelId)
|
||||||
|
tokenInfo.put("subType", subType)
|
||||||
|
tokenInfo.put("scheme", MonitorScheme.values()[scheme.toInt()].scheme)
|
||||||
|
tokenInfo.put("duration", duration.toLong())
|
||||||
|
event!!.request<JsonObject>(
|
||||||
|
EventBusAddress.SYS_DEVICE_CHANNEL_RECORD_VIDEO.address,
|
||||||
|
tokenInfo
|
||||||
|
) { previewUrl ->
|
||||||
|
if (previewUrl.succeeded()) {
|
||||||
|
requestHandler
|
||||||
|
.response()
|
||||||
|
.putHeader("content-type", "application/json")
|
||||||
|
.end(previewUrl.result().body().encode())
|
||||||
|
} else {
|
||||||
|
requestHandler
|
||||||
|
.response()
|
||||||
|
.putHeader("content-type", "application/json")
|
||||||
|
.end(JsonObject().encode())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,20 @@
|
||||||
package com.hisense.dahua_video.dao
|
package com.hisense.dahua_video.dao
|
||||||
|
|
||||||
|
import com.hisense.dahua_video.consts.EventBusAddress
|
||||||
|
import com.hisense.dahua_video.modules.device.DeviceChannel
|
||||||
|
import com.hisense.dahua_video.modules.media.ScreenshotVideo
|
||||||
import io.vertx.core.Vertx
|
import io.vertx.core.Vertx
|
||||||
import io.vertx.core.eventbus.EventBus
|
import io.vertx.core.eventbus.EventBus
|
||||||
import io.vertx.core.impl.logging.Logger
|
import io.vertx.core.impl.logging.Logger
|
||||||
import io.vertx.core.impl.logging.LoggerFactory
|
import io.vertx.core.impl.logging.LoggerFactory
|
||||||
|
import io.vertx.core.json.JsonObject
|
||||||
|
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
|
||||||
|
import org.jetbrains.exposed.sql.StdOutSqlLogger
|
||||||
|
import org.jetbrains.exposed.sql.addLogger
|
||||||
|
import org.jetbrains.exposed.sql.insert
|
||||||
|
import org.jetbrains.exposed.sql.select
|
||||||
|
import org.jetbrains.exposed.sql.transactions.transaction
|
||||||
|
import java.time.LocalDateTime
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 截取短视频功能dao
|
* 截取短视频功能dao
|
||||||
|
@ -14,9 +25,43 @@ class ScreenshotVideoDao(event_: EventBus?, vertx: Vertx) {
|
||||||
private var event: EventBus? = null
|
private var event: EventBus? = null
|
||||||
private var vertx: Vertx? = null
|
private var vertx: Vertx? = null
|
||||||
|
|
||||||
|
private val deviceChannel = DeviceChannel()
|
||||||
|
private val screenshotVideo = ScreenshotVideo()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
this.event = event_
|
this.event = event_
|
||||||
this.vertx = vertx
|
this.vertx = vertx
|
||||||
|
saveVideo()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存视频记录
|
||||||
|
*/
|
||||||
|
private fun saveVideo() {
|
||||||
|
/**
|
||||||
|
* 只处理本地事件
|
||||||
|
*/
|
||||||
|
event!!.localConsumer<JsonObject>(EventBusAddress.SYS_DEVICE_CHANNEL_SCREENSHOT_VIDEO_SAVE.address)
|
||||||
|
?.handler { replay ->
|
||||||
|
val message = replay.body()
|
||||||
|
logger.info("saveVideo:" + message.encode())
|
||||||
|
val channelId = transaction {
|
||||||
|
addLogger(StdOutSqlLogger)
|
||||||
|
deviceChannel.slice(deviceChannel.id).select { deviceChannel.channelNo eq message.getString("channelNo") }
|
||||||
|
.withDistinct().map { it[deviceChannel.id] }.firstOrNull()?.value
|
||||||
|
}
|
||||||
|
transaction {
|
||||||
|
addLogger(StdOutSqlLogger)
|
||||||
|
screenshotVideo.insert {
|
||||||
|
it[screenshotVideo.channelId] = channelId!!.toInt()
|
||||||
|
it[screenshotVideo.channelNo] = message.getString("channelNo")
|
||||||
|
it[screenshotVideo.createTime] = LocalDateTime.now()
|
||||||
|
it[screenshotVideo.filePath] = message.getString("filePath")
|
||||||
|
it[screenshotVideo.fileSize] = message.getLong("fileSize")
|
||||||
|
it[screenshotVideo.duration] = message.getLong("duration")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -283,7 +283,7 @@ class ScreenshotUtil(vertx: Vertx) {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
event!!.consumer<JsonObject>(EventBusAddress.SYS_DEVICE_CHANNEL_SCREENSHOT_VIDEO_SAVE.address)?.handler { replay ->
|
event!!.consumer<JsonObject>(EventBusAddress.SYS_DEVICE_CHANNEL_RECORD_VIDEO.address)?.handler { replay ->
|
||||||
val message = replay.body()
|
val message = replay.body()
|
||||||
val port = message.getString("monitorDomain").substringAfterLast(":").toInt()
|
val port = message.getString("monitorDomain").substringAfterLast(":").toInt()
|
||||||
var domain = message.getString("monitorDomain").substringBeforeLast(":").substringAfterLast("/")
|
var domain = message.getString("monitorDomain").substringBeforeLast(":").substringAfterLast("/")
|
||||||
|
|
|
@ -88,6 +88,7 @@ class WebAPIVerticle : CoroutineVerticle() {
|
||||||
router.route(HttpMethod.POST, "/admin/monitor_user/sign_up").handler(monitorUserController::sign_up) // 第三方平台注册表单
|
router.route(HttpMethod.POST, "/admin/monitor_user/sign_up").handler(monitorUserController::sign_up) // 第三方平台注册表单
|
||||||
|
|
||||||
router.route(HttpMethod.GET, "/admin/realmonitorUrl").handler(monitorController::realmonitorUrl) // 获取预览地址
|
router.route(HttpMethod.GET, "/admin/realmonitorUrl").handler(monitorController::realmonitorUrl) // 获取预览地址
|
||||||
router.route(HttpMethod.GET, "/admin/screenshot").handler(monitorController::screenshot)
|
router.route(HttpMethod.GET, "/admin/screenshot").handler(monitorController::screenshot) // 截图
|
||||||
|
router.route(HttpMethod.GET, "/admin/record").handler(monitorController::recordVideo) // 截取短视频
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue