mirror of
https://github.com/czp3009/bilibili-api.git
synced 2024-12-21 20:30:28 +08:00
UnknownPackageEvent 增加 cmd 字段
This commit is contained in:
parent
519b917105
commit
844d5a6dec
@ -3,15 +3,24 @@ package com.hiczp.bilibili.api.live.socket.event;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.hiczp.bilibili.api.live.socket.LiveClient;
|
||||
|
||||
/**
|
||||
* 这个事件在收到 cmd 为未知值的 Data 数据包时触发
|
||||
*/
|
||||
public class UnknownPackageEvent extends Event {
|
||||
private JsonObject jsonObject;
|
||||
private String cmd;
|
||||
|
||||
public UnknownPackageEvent(LiveClient source, JsonObject jsonObject) {
|
||||
public UnknownPackageEvent(LiveClient source, JsonObject jsonObject, String cmd) {
|
||||
super(source);
|
||||
this.jsonObject = jsonObject;
|
||||
this.cmd = cmd;
|
||||
}
|
||||
|
||||
public JsonObject getJsonObject() {
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
public String getCmd() {
|
||||
return cmd;
|
||||
}
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ public class LiveClientHandler extends SimpleChannelInboundHandler<Package> {
|
||||
jsonObject = JSON_PARSER.parse(new InputStreamReader(new ByteArrayInputStream(msg.getContent()), StandardCharsets.UTF_8))
|
||||
.getAsJsonObject();
|
||||
cmd = jsonObject.get("cmd").getAsString();
|
||||
} catch (JsonSyntaxException | IllegalStateException | NullPointerException e) {
|
||||
} catch (JsonSyntaxException | IllegalStateException | NullPointerException e) { //json 无法解析或者 cmd 字段不存在
|
||||
LOGGER.error("Receive invalid json: \n{}", new String(msg.getContent(), StandardCharsets.UTF_8));
|
||||
e.printStackTrace();
|
||||
break;
|
||||
@ -138,7 +138,7 @@ public class LiveClientHandler extends SimpleChannelInboundHandler<Package> {
|
||||
//UnknownPackage
|
||||
if (eventType == null) {
|
||||
LOGGER.error("Received unknown json below: \n{}", PRETTY_PRINTING_GSON.toJson(jsonObject));
|
||||
eventBus.post(new UnknownPackageEvent(liveClient, jsonObject));
|
||||
eventBus.post(new UnknownPackageEvent(liveClient, jsonObject, cmd));
|
||||
break;
|
||||
}
|
||||
|
||||
@ -147,7 +147,7 @@ public class LiveClientHandler extends SimpleChannelInboundHandler<Package> {
|
||||
DataEntity entityInstance;
|
||||
try {
|
||||
entityInstance = GSON.fromJson(jsonObject, entityType);
|
||||
} catch (JsonParseException e) {
|
||||
} catch (JsonParseException e) { //json 无法解析
|
||||
LOGGER.error("Json parse error: {}, json below: \n{}", e.getMessage(), PRETTY_PRINTING_GSON.toJson(jsonObject));
|
||||
break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user