diff --git a/src/main/java/com/genersoft/iot/vmp/jt1078/bean/JTChannel.java b/src/main/java/com/genersoft/iot/vmp/jt1078/bean/JTChannel.java index 64515eca7..67d5a5ef4 100644 --- a/src/main/java/com/genersoft/iot/vmp/jt1078/bean/JTChannel.java +++ b/src/main/java/com/genersoft/iot/vmp/jt1078/bean/JTChannel.java @@ -20,7 +20,7 @@ public class JTChannel { * 设备的数据库ID */ @Schema(description = "设备的数据库ID") - private int terminalId; + private int terminalDbId; /** * 通道ID @@ -41,6 +41,9 @@ public class JTChannel { @Schema(description = "更新时间") private String updateTime; + @Schema(description = "流信息") + private String stream; + public int getId() { return id; } @@ -57,12 +60,12 @@ public class JTChannel { this.name = name; } - public int getTerminalId() { - return terminalId; + public int getTerminalDbId() { + return terminalDbId; } - public void setTerminalId(int terminalId) { - this.terminalId = terminalId; + public void setTerminalDbId(int terminalDbId) { + this.terminalDbId = terminalDbId; } public String getCreateTime() { @@ -97,12 +100,20 @@ public class JTChannel { this.hasAudio = hasAudio; } + public String getStream() { + return stream; + } + + public void setStream(String stream) { + this.stream = stream; + } + @Override public String toString() { return "JTChannel{" + "id=" + id + ", name='" + name + '\'' + - ", terminalId=" + terminalId + + ", terminalDbId=" + terminalDbId + ", channelId=" + channelId + ", createTime='" + createTime + '\'' + ", updateTime='" + updateTime + '\'' + diff --git a/src/main/java/com/genersoft/iot/vmp/jt1078/dao/JTChannelMapper.java b/src/main/java/com/genersoft/iot/vmp/jt1078/dao/JTChannelMapper.java index 92763f029..331c4095b 100644 --- a/src/main/java/com/genersoft/iot/vmp/jt1078/dao/JTChannelMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/jt1078/dao/JTChannelMapper.java @@ -14,18 +14,18 @@ public interface JTChannelMapper { "from " + "wvp_jt_channel jc " + "WHERE " + - "terminal_id = #{terminalId}" + + "terminal_db_id = #{terminalDbId}" + " AND " + "jc.name LIKE concat('%',#{query},'%') " + " " + "ORDER BY jc.channel_id " + " "}) - List getAll(@Param("terminalId") int terminalId, @Param("query") String query); + List getAll(@Param("terminalDbId") int terminalDbId, @Param("query") String query); @Update(value = {" "}) + JTChannel getChannel(@Param("terminalDbId") int terminalDbId, @Param("channelId") Integer channelId); + } diff --git a/src/main/java/com/genersoft/iot/vmp/jt1078/service/impl/jt1078ServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/jt1078/service/impl/jt1078ServiceImpl.java index f266b75e0..e83d0d87a 100644 --- a/src/main/java/com/genersoft/iot/vmp/jt1078/service/impl/jt1078ServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/jt1078/service/impl/jt1078ServiceImpl.java @@ -19,6 +19,7 @@ import com.genersoft.iot.vmp.jt1078.event.FtpUploadEvent; import com.genersoft.iot.vmp.jt1078.proc.request.J1205; import com.genersoft.iot.vmp.jt1078.proc.response.*; import com.genersoft.iot.vmp.jt1078.service.Ijt1078Service; +import com.genersoft.iot.vmp.jt1078.session.SessionManager; import com.genersoft.iot.vmp.media.bean.MediaInfo; import com.genersoft.iot.vmp.media.bean.MediaServer; import com.genersoft.iot.vmp.media.event.hook.Hook; @@ -136,7 +137,13 @@ public class jt1078ServiceImpl implements Ijt1078Service { @Override public void play(String phoneNumber, String channelId, int type, GeneralCallback callback) { - + JTDevice device = getDevice(phoneNumber); + if (device == null) { + throw new ControllerException(ErrorCode.ERROR100.getCode(), "设备不存在"); + } + if (SessionManager.INSTANCE.get(phoneNumber) == null) { + throw new ControllerException(ErrorCode.ERROR100.getCode(), "设备离线"); + } // 检查流是否已经存在,存在则返回 String playKey = VideoManagerConstants.INVITE_INFO_1078_PLAY + phoneNumber + ":" + channelId; List> errorCallbacks = inviteErrorCallbackMap.computeIfAbsent(playKey, k -> new ArrayList<>()); @@ -149,14 +156,11 @@ public class jt1078ServiceImpl implements Ijt1078Service { // 查询流是否存在,不存在则删除缓存数据 JSONObject mediaInfo = zlmresTfulUtils.getMediaInfo(mediaServer, "rtp", "rtsp", streamInfo.getStream()); if (mediaInfo != null && mediaInfo.getInteger("code") == 0) { - Boolean online = mediaInfo.getBoolean("online"); - if (online != null && online) { - logger.info("[1078-点播] 点播已经存在,直接返回, phoneNumber: {}, channelId: {}", phoneNumber, channelId); - for (GeneralCallback errorCallback : errorCallbacks) { - errorCallback.run(InviteErrorCode.SUCCESS.getCode(), InviteErrorCode.SUCCESS.getMsg(), streamInfo); - } - return; + logger.info("[1078-点播] 点播已经存在,直接返回, phoneNumber: {}, channelId: {}", phoneNumber, channelId); + for (GeneralCallback errorCallback : errorCallbacks) { + errorCallback.run(InviteErrorCode.SUCCESS.getCode(), InviteErrorCode.SUCCESS.getMsg(), streamInfo); } + return; } } // 清理数据 @@ -174,7 +178,7 @@ public class jt1078ServiceImpl implements Ijt1078Service { Hook hook = Hook.getInstance(HookType.on_media_arrival, "rtp", stream, mediaServer.getId()); subscribe.addSubscribe(hook, (hookData) -> { dynamicTask.stop(playKey); - logger.info("[1078-点播] 点播成功, phoneNumber: {}, channelId: {}", phoneNumber, channelId); + logger.info("[1078-点播] 点播成功, 手机号: {}, 通道: {}", phoneNumber, channelId); // TODO 发送9105 实时音视频传输状态通知, 通知丢包率 StreamInfo info = onPublishHandler(mediaServer, hookData, phoneNumber, channelId); @@ -184,6 +188,8 @@ public class jt1078ServiceImpl implements Ijt1078Service { subscribe.removeSubscribe(hook); redisTemplate.opsForValue().set(playKey, info); }); + // 开启收流端口 + SSRCInfo ssrcInfo = mediaServerService.openRTPServer(mediaServer, stream, "000", false, false, 0, false, false, false, 1); // 设置超时监听 dynamicTask.startDelay(playKey, () -> { logger.info("[1078-点播] 超时, phoneNumber: {}, channelId: {}", phoneNumber, channelId); @@ -191,11 +197,10 @@ public class jt1078ServiceImpl implements Ijt1078Service { errorCallback.run(InviteErrorCode.ERROR_FOR_SIGNALLING_TIMEOUT.getCode(), InviteErrorCode.ERROR_FOR_SIGNALLING_TIMEOUT.getMsg(), null); } - + mediaServerService.closeRTPServer(mediaServer, stream); + subscribe.removeSubscribe(hook); }, userSetting.getPlayTimeout()); - // 开启收流端口 - SSRCInfo ssrcInfo = mediaServerService.openRTPServer(mediaServer, stream, null, false, false, 0, false, false, false, 1); logger.info("[1078-点播] phoneNumber: {}, channelId: {}, 端口: {}", phoneNumber, channelId, ssrcInfo.getPort()); J9101 j9101 = new J9101(); j9101.setChannel(Integer.valueOf(channelId)); @@ -204,9 +209,7 @@ public class jt1078ServiceImpl implements Ijt1078Service { j9101.setTcpPort(ssrcInfo.getPort()); j9101.setUdpPort(ssrcInfo.getPort()); j9101.setType(type); - Object s = jt1078Template.startLive(phoneNumber, j9101, 6); - System.out.println("ssss=== " + s); - + jt1078Template.startLive(phoneNumber, j9101, 6); } public StreamInfo onPublishHandler(MediaServer mediaServerItem, HookData hookData, String phoneNumber, String channelId) { @@ -1011,8 +1014,21 @@ public class jt1078ServiceImpl implements Ijt1078Service { @Override public PageInfo getChannelList(int page, int count, int deviceId, String query) { + + JTDevice device = getDeviceById(deviceId); + if (device == null) { + throw new ControllerException(ErrorCode.ERROR100.getCode(), "设备不存在"); + } PageHelper.startPage(page, count); List all = jtChannelMapper.getAll(deviceId, query); + PageInfo jtChannelPageInfo = new PageInfo<>(all); + for (JTChannel jtChannel : jtChannelPageInfo.getList()) { + String playKey = VideoManagerConstants.INVITE_INFO_1078_PLAY + device.getPhoneNumber() + ":" + jtChannel.getChannelId(); + StreamInfo streamInfo = (StreamInfo) redisTemplate.opsForValue().get(playKey); + if (streamInfo != null) { + jtChannel.setStream(streamInfo.getStream()); + } + } return new PageInfo<>(all); } @@ -1024,6 +1040,10 @@ public class jt1078ServiceImpl implements Ijt1078Service { @Override public void addChannel(JTChannel channel) { + JTChannel channelInDb = jtChannelMapper.getChannel(channel.getTerminalDbId(), channel.getChannelId()); + if (channelInDb != null) { + throw new ControllerException(ErrorCode.ERROR100.getCode(), "通道已存在"); + } channel.setCreateTime(DateUtil.getNow()); channel.setUpdateTime(DateUtil.getNow()); jtChannelMapper.add(channel); diff --git a/web_src/src/components/JTChannelList.vue b/web_src/src/components/JTChannelList.vue index d06d9b5f9..6b4bad514 100755 --- a/web_src/src/components/JTChannelList.vue +++ b/web_src/src/components/JTChannelList.vue @@ -52,7 +52,7 @@ 停止 @@ -162,8 +162,9 @@ export default { this.currentPage = 1; this.count = 15; this.deviceService.getDevice(this.deviceId, (result) => { - this.device = result; - + if (result.code === 0) { + this.device = result.data; + } }, (error) => { console.log("获取设备信息失败") console.error(error) @@ -180,6 +181,7 @@ export default { getDeviceChannelList: function () { if (typeof (this.deviceId) == "undefined") return; this.deviceService.getAllChannel(this.currentPage, this.count, this.searchSrt, this.deviceId, (data)=>{ + console.log(data) if (data.code === 0) { this.total = data.data.total; this.deviceChannelList = data.data.list; @@ -197,6 +199,7 @@ export default { this.isLoging = true; let channelId = itemData.channelId; console.log("通知设备推流1:" + deviceId + " : " + channelId); + console.log(this.device); let that = this; this.$axios({ method: 'get', diff --git a/web_src/src/components/dialog/jtChannelEdit.vue b/web_src/src/components/dialog/jtChannelEdit.vue index 55c9a4ecd..9ff4d6099 100755 --- a/web_src/src/components/dialog/jtChannelEdit.vue +++ b/web_src/src/components/dialog/jtChannelEdit.vue @@ -69,7 +69,7 @@ export default { method: 'post', url:`/api/jt1078/terminal/channel/${this.isEdit?'update':'add'}/`, params: { - terminalId: this.deviceId, + terminalDbId: this.deviceId, name: this.form.name, channelId: this.form.channelId, } diff --git a/web_src/src/components/service/JTDeviceService.js b/web_src/src/components/service/JTDeviceService.js index 1732da0d4..d39249383 100755 --- a/web_src/src/components/service/JTDeviceService.js +++ b/web_src/src/components/service/JTDeviceService.js @@ -30,6 +30,8 @@ class JTDeviceService{ deviceId: deviceId }, }).then((res) => { + console.log(11) + console.log(res) if (typeof (callback) == "function") callback(res.data) }).catch((error) => { console.log(error); @@ -53,7 +55,7 @@ class JTDeviceService{ - getAllChannel(currentPage, count, searchSrt, deviceId, callback, endCallback, errorCallback) { + getAllChannel(currentPage, count, searchSrt, deviceId, endCallback, errorCallback) { this.$axios({ method: 'get', url: `/api/jt1078/terminal/channel/list`, diff --git a/数据库/JT1078-2.7.0/初始化-mysql-2.7.0.sql b/数据库/JT1078-2.7.0/初始化-mysql-2.7.0.sql index 8c67bc9d8..19f135fde 100644 --- a/数据库/JT1078-2.7.0/初始化-mysql-2.7.0.sql +++ b/数据库/JT1078-2.7.0/初始化-mysql-2.7.0.sql @@ -338,13 +338,13 @@ create table wvp_jt_terminal ( ); create table wvp_jt_channel ( id serial primary key, + terminal_db_id integer, channel_id integer, - terminal_id integer, has_audio bool default false, name character varying(255), update_time character varying(50) not null, create_time character varying(50) not null, - constraint uk_jt_device_id_device_id unique (id, terminal_id) + constraint uk_jt_device_id_device_id unique (terminal_db_id, channel_id) ); /*初始数据*/ diff --git a/数据库/JT1078-2.7.0/初始化-postgresql-kingbase-2.7.0.sql b/数据库/JT1078-2.7.0/初始化-postgresql-kingbase-2.7.0.sql index 5343fe856..f9d9fe4b1 100644 --- a/数据库/JT1078-2.7.0/初始化-postgresql-kingbase-2.7.0.sql +++ b/数据库/JT1078-2.7.0/初始化-postgresql-kingbase-2.7.0.sql @@ -338,13 +338,13 @@ create table wvp_jt_terminal ( ); create table wvp_jt_channel ( id serial primary key, + terminal_db_id integer, channel_id integer, - terminal_id integer, has_audio bool default false, name character varying(255), update_time character varying(50) not null, create_time character varying(50) not null, - constraint uk_jt_device_id_device_id unique (id, terminal_id) + constraint uk_jt_device_id_device_id unique (terminal_db_id, channel_id) ); /*初始数据*/ diff --git a/数据库/JT1078-2.7.0/更新-mysql-2.7.0.sql b/数据库/JT1078-2.7.0/更新-mysql-2.7.0.sql index 7c0c74586..e4426a527 100644 --- a/数据库/JT1078-2.7.0/更新-mysql-2.7.0.sql +++ b/数据库/JT1078-2.7.0/更新-mysql-2.7.0.sql @@ -22,11 +22,12 @@ create table wvp_jt_terminal ( create table wvp_jt_channel ( id serial primary key, - terminal_id integer, + terminal_db_id integer, channel_id integer, has_audio bool default false, name character varying(255), update_time character varying(50) not null, - create_time character varying(50) not null + create_time character varying(50) not null, + constraint uk_jt_device_id_device_id unique (terminal_db_id, channel_id) ); diff --git a/数据库/JT1078-2.7.0/更新-postgresql-kingbase-2.7.0.sql b/数据库/JT1078-2.7.0/更新-postgresql-kingbase-2.7.0.sql index ef5824001..33a8c0c98 100644 --- a/数据库/JT1078-2.7.0/更新-postgresql-kingbase-2.7.0.sql +++ b/数据库/JT1078-2.7.0/更新-postgresql-kingbase-2.7.0.sql @@ -21,11 +21,11 @@ create table wvp_jt_terminal ( ); create table wvp_jt_channel ( id serial primary key, + terminal_db_id integer, channel_id integer, - terminal_id integer, has_audio bool default false, name character varying(255), update_time character varying(50) not null, create_time character varying(50) not null, - constraint uk_jt_device_id_device_id unique (id, terminal_id) + constraint uk_jt_device_id_device_id unique (terminal_db_id, channel_id) ); \ No newline at end of file