修正 LiveClient 同步连接的逻辑

This commit is contained in:
czp3009 2018-05-13 17:35:51 +08:00
parent 28ddc6758b
commit 31b1762ebb
3 changed files with 14 additions and 5 deletions

View File

@ -13,7 +13,7 @@
# 添加依赖
## Gradle
compile group: 'com.hiczp', name: 'bilibili-api', version: '0.0.12'
compile group: 'com.hiczp', name: 'bilibili-api', version: '0.0.13'
# 名词解释
B站不少参数都是瞎取的, 并且不统一, 经常混用, 以下给出一些常见参数对应的含义

View File

@ -1,5 +1,5 @@
group = 'com.hiczp'
version = '0.0.12'
version = '0.0.13'
description = 'Bilibili android client API library written in Java'
apply plugin: 'idea'

View File

@ -24,7 +24,10 @@ import retrofit2.Call;
import javax.annotation.Nonnull;
import java.io.IOException;
import java.util.concurrent.*;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
public class LiveClient {
private static final Logger LOGGER = LoggerFactory.getLogger(LiveClient.class);
@ -38,6 +41,7 @@ public class LiveClient {
private final EventBus eventBus = new EventBus("BilibiliLiveClientEventBus");
private Long showRoomId;
private Long realRoomId;
private boolean useRealRoomIdForConstructing;
private LiveRoomInfoEntity.LiveRoom liveRoom;
@ -46,6 +50,7 @@ public class LiveClient {
public LiveClient(@Nonnull BilibiliServiceProvider bilibiliServiceProvider, @Nonnull EventLoopGroup eventLoopGroup, long roomId, boolean isRealRoomId, long userId) {
this.bilibiliServiceProvider = bilibiliServiceProvider;
this.eventLoopGroup = eventLoopGroup;
this.useRealRoomIdForConstructing = isRealRoomId;
if (isRealRoomId) {
realRoomId = roomId;
} else {
@ -144,8 +149,8 @@ public class LiveClient {
return future.get();
}
public LiveClient connect() throws InterruptedException, ExecutionException {
return connect(Executors.newSingleThreadExecutor());
public synchronized LiveClient connect() throws Exception {
return connectAsync().call();
}
public synchronized ChannelFuture closeChannelAsync() {
@ -221,6 +226,10 @@ public class LiveClient {
return channel;
}
public boolean isUseRealRoomIdForConstructing() {
return useRealRoomIdForConstructing;
}
private LiveClient self() {
return this;
}