浏览代码

增加web展示字段

kwl 3 周之前
父节点
当前提交
08d0f0b32d

+ 9 - 0
src/main/java/com/jttserver/device/DeviceManager.java

@@ -19,6 +19,7 @@ public class DeviceManager {
     public static class DeviceInfo {
         private String channelId;
         private String remoteAddress;
+        private String prefix;
         private long connectTime;
         private String simCardNumber;
         private byte logicChannelNumber;
@@ -67,6 +68,14 @@ public class DeviceManager {
         public void updateLastActiveTime() {
             this.lastActiveTime = System.currentTimeMillis();
         }
+
+        public String getPrefix() {
+            return prefix;
+        }
+
+        public void setPrefix(String prefix) {
+            this.prefix = prefix;
+        }
     }
 
     /**

+ 3 - 1
src/main/java/com/jttserver/service/ManagerWebServer.java

@@ -295,7 +295,8 @@ public class ManagerWebServer {
                     + "\"," +
                     "\"logicChannelNumber\":" + device.get("logicChannelNumber") + "," +
                     "\"connectTime\":" + device.get("connectTime") + "," +
-                    "\"lastActiveTime\":" + device.get("lastActiveTime") +
+                    "\"lastActiveTime\":" + device.get("lastActiveTime") + "," +
+                    "\"prefix\":\"" + (device.get("prefix") != null ? device.get("prefix") : "") + "\"" +
                     "}";
         }
 
@@ -314,6 +315,7 @@ public class ManagerWebServer {
                 deviceMap.put("logicChannelNumber", device.getLogicChannelNumber());
                 deviceMap.put("connectTime", device.getConnectTime());
                 deviceMap.put("lastActiveTime", device.getLastActiveTime());
+                deviceMap.put("prefix", device.getPrefix());
                 deviceList.add(deviceMap);
             }
 

+ 8 - 3
src/main/java/com/jttserver/service/receiver/JttVideoRecvServer.java

@@ -80,7 +80,7 @@ public class JttVideoRecvServer extends RecvSever {
                         ch.pipeline().addLast(new Jtt1078MessageDecoder()); // 添加JTT1078解码器处理粘包拆包
 
                         // 添加处理视频流数据的处理器
-                        ch.pipeline().addLast(new VideoStreamHandler(deviceManagementEnabled, streamRelay, publishServer));
+                        ch.pipeline().addLast(new VideoStreamHandler(deviceManagementEnabled, streamRelay, publishServer, prefix));
                     }
                 })
                 .option(ChannelOption.SO_BACKLOG, 128)
@@ -160,11 +160,14 @@ public class JttVideoRecvServer extends RecvSever {
         // WebSocket服务器引用
         private final PublishServer publishServer;
 
+        private final String prefix;
+
         public VideoStreamHandler(boolean deviceManagementEnabled, StreamRelay streamRelay,
-                PublishServer publishServer) {
+                PublishServer publishServer, String prefix) {
             this.deviceManagementEnabled = deviceManagementEnabled;
             this.streamRelay = streamRelay;
             this.publishServer = publishServer;
+            this.prefix = prefix;
         }
 
         @Override
@@ -180,7 +183,9 @@ public class JttVideoRecvServer extends RecvSever {
             // 添加设备信息(受功能开关控制)
             if (deviceManagementEnabled) {
                 DeviceManager.DeviceInfo deviceInfo = new DeviceManager.DeviceInfo(channelId,
-                        ctx.channel().remoteAddress().toString());
+                    ctx.channel().remoteAddress().toString());
+                // 设置接收服务器的路径前缀,例如 "/realtime/" 或 "/playback/"
+                deviceInfo.setPrefix(this.prefix);
                 DeviceManager.registerDevice(channelId, deviceInfo);
             }
 

+ 9 - 4
src/main/resources/web/devices.html

@@ -129,6 +129,7 @@
                                     <th>远程地址</th>
                                     <th>SIM卡号</th>
                                     <th>逻辑通道号</th>
+                                    <th>前缀</th>
                                     <th>连接时间</th>
                                     <th>最后活跃时间</th>
                                     <th>操作</th>
@@ -167,6 +168,10 @@
                         channelCell.textContent = device.logicChannelNumber;
                         row.appendChild(channelCell);
 
+                        const prefixCell = document.createElement('td');
+                        prefixCell.textContent = device.prefix || '';
+                        row.appendChild(prefixCell);
+
                         const connectTimeCell = document.createElement('td');
                         connectTimeCell.textContent = new Date(device.connectTime).toLocaleString();
                         row.appendChild(connectTimeCell);
@@ -188,8 +193,8 @@
                         playBtn.textContent = '播放';
                         playBtn.className = 'btn btn-player';
                         playBtn.onclick = function () {
-                            // 构建带参数的URL
-                            const url = `/player.html?sim=${encodeURIComponent(device.simCardNumber || '')}&channel=${encodeURIComponent(device.logicChannelNumber)}`;
+                            // 构建带参数的URL(包含 prefix)
+                            const url = `/player.html?sim=${encodeURIComponent(device.simCardNumber || '')}&channel=${encodeURIComponent(device.logicChannelNumber)}&prefix=${encodeURIComponent(device.prefix || '')}`;
                             // 使用bindOpenInPopup函数打开播放器
                             openPlayerInPopup(url, 'PlayerWindow');
                         };
@@ -201,8 +206,8 @@
                         playNoAudioBtn.className = 'btn btn-player-no-audio';
 
                         playNoAudioBtn.onclick = function () {
-                            // 构建带参数的URL
-                            const url = `/playerWhthoutAudio.html?sim=${encodeURIComponent(device.simCardNumber || '')}&channel=${encodeURIComponent(device.logicChannelNumber)}`;
+                            // 构建带参数的URL(包含 prefix)
+                            const url = `/playerWhthoutAudio.html?sim=${encodeURIComponent(device.simCardNumber || '')}&channel=${encodeURIComponent(device.logicChannelNumber)}&prefix=${encodeURIComponent(device.prefix || '')}`;
                             // 使用bindOpenInPopup函数打开无音频播放器
                             openPlayerInPopup(url, 'PlayerWindowNoAudio');
                         };

+ 11 - 1
src/main/resources/web/player.html

@@ -72,7 +72,17 @@
             const host = window.location.hostname;
             // WebSocketServer 默认端口 18090,路径 /realtime/{streamId}
             const protocol = window.location.protocol === 'https:' ? 'wss' : 'ws';
-            return `${protocol}://${host}:18090/realtime/${encodeURIComponent(streamId)}`;
+            // 读取 URL 参数中的 prefix(优先),否则默认使用 /realtime/
+            const params = getUrlParams();
+            let prefix = params.prefix || '/realtime/';
+            // 规范化 prefix,确保以 / 开头并以 / 结尾
+            if (prefix && prefix.length > 0) {
+                if (!prefix.startsWith('/')) prefix = '/' + prefix;
+                if (!prefix.endsWith('/')) prefix = prefix + '/';
+            } else {
+                prefix = '/realtime/';
+            }
+            return `${protocol}://${host}:18090${prefix}${encodeURIComponent(streamId)}`;
         }
 
         // 获取URL参数

+ 10 - 1
src/main/resources/web/playerWhthoutAudio.html

@@ -59,7 +59,16 @@
         function buildWsUrl(streamId) {
             const host = window.location.hostname;
             const protocol = window.location.protocol === 'https:' ? 'wss' : 'ws';
-            return `${protocol}://${host}:18090/realtime/${encodeURIComponent(streamId)}`;
+            // 读取 URL 参数中的 prefix(优先),否则默认使用 /realtime/
+            const params = getUrlParams();
+            let prefix = params.prefix || '/realtime/';
+            if (prefix && prefix.length > 0) {
+                if (!prefix.startsWith('/')) prefix = '/' + prefix;
+                if (!prefix.endsWith('/')) prefix = prefix + '/';
+            } else {
+                prefix = '/realtime/';
+            }
+            return `${protocol}://${host}:18090${prefix}${encodeURIComponent(streamId)}`;
         }
 
         // 获取URL参数