增加弹幕推送流中的数据包类型 CHANGE_ROOM_INFO

This commit is contained in:
czp 2018-03-14 00:35:14 +08:00
parent dc7c763433
commit 79af856db9
7 changed files with 52 additions and 28 deletions

View File

@ -319,6 +319,7 @@ API 文档
| 事件 | 抛出条件 |
| :--- | :--- |
| ActivityEventPackageEvent | 收到 ACTIVITY_EVENT 数据包 |
| ChangeRoomInfoPackageEvent | 收到 CHANGE_ROOM_INFO 数据包 |
| ConnectionCloseEvent | 连接断开(主动或被动) |
| ConnectSucceedEvent | 进房成功 |
| CutOffPackageEvent | 收到 CUT_OFF 数据包 |

View File

@ -0,0 +1,4 @@
{
"cmd": "CHANGE_ROOM_INFO",
"background": "http://static.hdslb.com/live-static/images/bg/4.jpg"
}

View File

@ -1,26 +0,0 @@
package com.hiczp.bilibili.api.interceptor;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import okhttp3.Interceptor;
import okhttp3.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
public class PrintResponseBodyInterceptor implements Interceptor {
private static final Logger LOGGER = LoggerFactory.getLogger(PrintResponseBodyInterceptor.class);
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
@Override
public Response intercept(Chain chain) throws IOException {
Response response = chain.proceed(chain.request());
JsonObject jsonObject = InterceptorHelper.getJsonInBody(response);
LOGGER.info(GSON.toJson(jsonObject));
return response;
}
}

View File

@ -0,0 +1,32 @@
package com.hiczp.bilibili.api.live.socket.entity;
import com.google.gson.annotations.SerializedName;
public class ChangeRoomInfoEntity implements DataEntity {
/**
* cmd : CHANGE_ROOM_INFO
* background : http://static.hdslb.com/live-static/images/bg/4.jpg
*/
@SerializedName("cmd")
private String cmd;
@SerializedName("background")
private String background;
@Override
public String getCmd() {
return cmd;
}
public void setCmd(String cmd) {
this.cmd = cmd;
}
public String getBackground() {
return background;
}
public void setBackground(String background) {
this.background = background;
}
}

View File

@ -0,0 +1,9 @@
package com.hiczp.bilibili.api.live.socket.event;
import com.hiczp.bilibili.api.live.socket.entity.ChangeRoomInfoEntity;
public class ChangeRoomInfoPackageEvent extends ReceiveDataPackageEvent<ChangeRoomInfoEntity> {
public ChangeRoomInfoPackageEvent(Object source, ChangeRoomInfoEntity entity) {
super(source, entity);
}
}

View File

@ -197,6 +197,11 @@ public class LiveClientHandler extends SimpleChannelInboundHandler<Package> {
eventCreationExpression = () -> new RoomShieldPackageEvent(this, GSON.fromJson(jsonObject, RoomShieldEntity.class));
}
break;
//更换房间背景图片
case "CHANGE_ROOM_INFO": {
eventCreationExpression = () -> new ChangeRoomInfoPackageEvent(this, GSON.fromJson(jsonObject, ChangeRoomInfoEntity.class));
}
break;
// B站 管理员强制中断
case "CUT_OFF": {
eventCreationExpression = () -> new CutOffPackageEvent(this, GSON.fromJson(jsonObject, CutOffEntity.class));

View File

@ -1,7 +1,6 @@
package com.hiczp.bilibili.api.test;
import com.hiczp.bilibili.api.BilibiliAPI;
import com.hiczp.bilibili.api.interceptor.PrintResponseBodyInterceptor;
import okhttp3.logging.HttpLoggingInterceptor;
import org.junit.Test;
@ -13,7 +12,7 @@ public class GetAwardsTest {
@Test
public void getAwards() throws Exception {
BILIBILI_API
.getLiveService(Collections.singletonList(new PrintResponseBodyInterceptor()), HttpLoggingInterceptor.Level.BODY)
.getLiveService(Collections.emptyList(), HttpLoggingInterceptor.Level.BODY)
.getAwards()
.execute()
.body();