| | |
| | | import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.cmd.CatalogResponseMessageHandler; |
| | | import com.genersoft.iot.vmp.service.IDeviceChannelService; |
| | | import com.genersoft.iot.vmp.service.IDeviceService; |
| | | import com.genersoft.iot.vmp.service.IInviteStreamService; |
| | | import com.genersoft.iot.vmp.service.IMediaServerService; |
| | | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| | | import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper; |
| | |
| | | private IRedisCatchStorage redisCatchStorage; |
| | | |
| | | @Autowired |
| | | private IInviteStreamService inviteStreamService; |
| | | |
| | | @Autowired |
| | | private DeviceMapper deviceMapper; |
| | | |
| | | @Autowired |
| | |
| | | private IMediaServerService mediaServerService; |
| | | |
| | | @Override |
| | | public void online(Device device) { |
| | | public void online(Device device, SipTransactionInfo sipTransactionInfo) { |
| | | logger.info("[设备上线] deviceId:{}->{}:{}", device.getDeviceId(), device.getIp(), device.getPort()); |
| | | Device deviceInRedis = redisCatchStorage.getDevice(device.getDeviceId()); |
| | | Device deviceInDb = deviceMapper.getDeviceByDeviceId(device.getDeviceId()); |
| | |
| | | String now = DateUtil.getNow(); |
| | | if (deviceInRedis != null && deviceInDb == null) { |
| | | // redis 存在脏数据 |
| | | redisCatchStorage.clearCatchByDeviceId(device.getDeviceId()); |
| | | inviteStreamService.clearInviteInfo(device.getDeviceId()); |
| | | } |
| | | device.setUpdateTime(now); |
| | | if (device.getKeepaliveIntervalTime() == 0) { |
| | | // 默认心跳间隔60 |
| | | device.setKeepaliveIntervalTime(60); |
| | | } |
| | | if (sipTransactionInfo != null) { |
| | | device.setSipTransactionInfo(sipTransactionInfo); |
| | | }else { |
| | | if (deviceInRedis != null) { |
| | | device.setSipTransactionInfo(deviceInRedis.getSipTransactionInfo()); |
| | | } |
| | | } |
| | | |
| | | // 第一次上线 或则设备之前是离线状态--进行通道同步和设备信息查询 |
| | | if (device.getCreateTime() == null) { |
| | | device.setOnline(1); |
| | |
| | | // 刷新过期任务 |
| | | String registerExpireTaskKey = VideoManagerConstants.REGISTER_EXPIRE_TASK_KEY_PREFIX + device.getDeviceId(); |
| | | // 如果第一次注册那么必须在60 * 3时间内收到一个心跳,否则设备离线 |
| | | dynamicTask.startDelay(registerExpireTaskKey, ()-> offline(device.getDeviceId()), device.getKeepaliveIntervalTime() * 1000 * 3); |
| | | dynamicTask.startDelay(registerExpireTaskKey, ()-> offline(device.getDeviceId(), "首次注册后未能收到心跳"), device.getKeepaliveIntervalTime() * 1000 * 3); |
| | | if (userSetting.getDeviceStatusNotify()) { |
| | | // 发送redis消息 |
| | | redisCatchStorage.sendDeviceOrChannelStatus(device.getDeviceId(), null, true); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void offline(String deviceId) { |
| | | logger.error("[设备离线], device:{}", deviceId); |
| | | public void offline(String deviceId, String reason) { |
| | | logger.error("[设备离线],{}, device:{}", reason, deviceId); |
| | | Device device = deviceMapper.getDeviceByDeviceId(deviceId); |
| | | if (device == null) { |
| | | return; |
| | |
| | | // 移除订阅 |
| | | removeCatalogSubscribe(device); |
| | | removeMobilePositionSubscribe(device); |
| | | if (userSetting.getDeviceStatusNotify()) { |
| | | // 发送redis消息 |
| | | redisCatchStorage.sendDeviceOrChannelStatus(device.getDeviceId(), null, false); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | |
| | | node.setBasicData(channel); |
| | | node.setParent(false); |
| | | if (channel.getChannelId().length() > 8) { |
| | | String gbCodeType = channel.getChannelId().substring(10, 13); |
| | | node.setParent(gbCodeType.equals(ChannelIdType.BUSINESS_GROUP) || gbCodeType.equals(ChannelIdType.VIRTUAL_ORGANIZATION) ); |
| | | if (channel.getChannelId().length() > 13) { |
| | | String gbCodeType = channel.getChannelId().substring(10, 13); |
| | | node.setParent(gbCodeType.equals(ChannelIdType.BUSINESS_GROUP) || gbCodeType.equals(ChannelIdType.VIRTUAL_ORGANIZATION) ); |
| | | } |
| | | }else { |
| | | node.setParent(true); |
| | | } |
| | |
| | | public List<Device> getAll() { |
| | | return deviceMapper.getAll(); |
| | | } |
| | | |
| | | |
| | | } |