diff --git a/src/main/java/com/yutou/bilibili/BiliBili/Live.java b/src/main/java/com/yutou/bilibili/BiliBili/Live.java index b5d5ae9..4e2f8ac 100644 --- a/src/main/java/com/yutou/bilibili/BiliBili/Live.java +++ b/src/main/java/com/yutou/bilibili/BiliBili/Live.java @@ -152,6 +152,10 @@ public class Live implements ApplicationContextAware { header.put("Pragma", "no-cache"); header.put("Upgrade", "websocket"); header.put("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.190 Safari/537.36"); + if (client != null && !client.isClosed()) { + stop(); + return; + } client = new WebSocketClient(new URI(url), header) { private long time = 0; private boolean init = true; @@ -223,6 +227,14 @@ public class Live implements ApplicationContextAware { } }; client.connect(); + new Timer().schedule(new TimerTask() { + @Override + public void run() { + if (client == null || client.isClosed()) { + stop(); + } + } + }, 0, 60 * 1000); } public void stop() { @@ -294,11 +306,11 @@ public class Live implements ApplicationContextAware { if (data.length > 32) { List list = LiveUtils.getMsgList(LiveUtils.dec(bytes), new ArrayList<>(), true); String tmp = ""; - for (int i=0;i