From c4d2a9a870fbe5f0c0e3c6efc308ae28199b8330 Mon Sep 17 00:00:00 2001 From: czp Date: Tue, 6 Feb 2018 15:25:45 +0800 Subject: [PATCH] =?UTF-8?q?=E7=8E=B0=E5=9C=A8=E9=80=9A=E8=BF=87=20LiveClie?= =?UTF-8?q?nt=20=E5=8F=AF=E4=BB=A5=E7=9B=B4=E6=8E=A5=E5=8F=91=E9=80=81?= =?UTF-8?q?=E5=BC=B9=E5=B9=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bilibili/api/live/socket/LiveClient.java | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/hiczp/bilibili/api/live/socket/LiveClient.java b/src/main/java/com/hiczp/bilibili/api/live/socket/LiveClient.java index 61f40ea..1997999 100644 --- a/src/main/java/com/hiczp/bilibili/api/live/socket/LiveClient.java +++ b/src/main/java/com/hiczp/bilibili/api/live/socket/LiveClient.java @@ -3,7 +3,9 @@ package com.hiczp.bilibili.api.live.socket; import com.google.common.eventbus.EventBus; import com.google.common.eventbus.Subscribe; import com.hiczp.bilibili.api.BilibiliServiceProvider; +import com.hiczp.bilibili.api.live.entity.BulletScreenEntity; import com.hiczp.bilibili.api.live.entity.LiveRoomInfoEntity; +import com.hiczp.bilibili.api.live.entity.SendBulletScreenResponseEntity; import com.hiczp.bilibili.api.live.socket.codec.PackageDecoder; import com.hiczp.bilibili.api.live.socket.codec.PackageEncoder; import com.hiczp.bilibili.api.live.socket.event.ConnectionCloseEvent; @@ -32,7 +34,7 @@ public class LiveClient implements Closeable { private final long showRoomId; private final long userId; - private Long roomId; + private LiveRoomInfoEntity.LiveRoomEntity liveRoomEntity; private EventLoopGroup eventLoopGroup; private Channel channel; @@ -66,12 +68,12 @@ public class LiveClient implements Closeable { } LOGGER.info("Fetching info of live room {}", showRoomId); - LiveRoomInfoEntity.LiveRoomEntity liveRoomEntity = bilibiliServiceProvider.getLiveService() + liveRoomEntity = bilibiliServiceProvider.getLiveService() .getRoomInfo(showRoomId) .execute() .body() .getData(); - roomId = liveRoomEntity.getRoomId(); + long roomId = liveRoomEntity.getRoomId(); LOGGER.info("Get actual room id {}", roomId); eventLoopGroup = new NioEventLoopGroup(1); @@ -91,7 +93,6 @@ public class LiveClient implements Closeable { 0 )) .addLast(new IdleStateHandler(40, 0, 0)) - //.addLast(new LoggingHandler(LogLevel.DEBUG)) .addLast(new PackageEncoder()) .addLast(new PackageDecoder()) .addLast(new LiveClientHandler(roomId, userId, eventBus)); @@ -148,6 +149,24 @@ public class LiveClient implements Closeable { return this; } + public SendBulletScreenResponseEntity sendBulletScreen(String message) throws IOException { + return bilibiliServiceProvider.getLiveService() + .sendBulletScreen( + new BulletScreenEntity( + liveRoomEntity != null ? liveRoomEntity.getRoomId() : showRoomId, + userId, + message + ) + ) + .execute() + .body(); + } + + //TODO 弹幕发送队列 + public void sendBulletScreenInBlockingQueue(String message) { + throw new UnsupportedOperationException(); + } + public long getShowRoomId() { return showRoomId; } @@ -156,7 +175,7 @@ public class LiveClient implements Closeable { return userId; } - public Optional getRoomId() { - return Optional.of(roomId); + public Optional getRoomInfo() { + return Optional.of(liveRoomEntity); } }