Fix: Update online state more reliable
So online state was only updated by the ThumbnailOverviewTab, so the recorder would never start recording.
This commit is contained in:
parent
014ab5312f
commit
6c1a757af3
|
@ -43,9 +43,42 @@ public class BongaCamsModel extends AbstractModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isOnline(boolean ignoreCache) throws IOException, ExecutionException, InterruptedException {
|
public boolean isOnline(boolean ignoreCache) throws IOException, ExecutionException, InterruptedException {
|
||||||
|
if(ignoreCache) {
|
||||||
|
String url = getStreamUrl();
|
||||||
|
Request req = new Request.Builder().url(url).build();
|
||||||
|
try(Response resp = site.getHttpClient().execute(req)) {
|
||||||
|
online = resp.isSuccessful();
|
||||||
|
}
|
||||||
|
}
|
||||||
return online;
|
return online;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private JSONObject getRoomData() throws IOException {
|
||||||
|
String url = BongaCams.BASE_URL + "/tools/amf.php";
|
||||||
|
RequestBody body = new FormBody.Builder()
|
||||||
|
.add("method", "getRoomData")
|
||||||
|
.add("args[]", getName())
|
||||||
|
.add("args[]", "false")
|
||||||
|
.build();
|
||||||
|
Request request = new Request.Builder()
|
||||||
|
.url(url)
|
||||||
|
.addHeader("User-Agent", Config.getInstance().getSettings().httpUserAgent)
|
||||||
|
.addHeader("Accept", "application/json, text/javascript, */*")
|
||||||
|
.addHeader("Accept-Language", "en")
|
||||||
|
.addHeader("Referer", BongaCams.BASE_URL)
|
||||||
|
.addHeader("X-Requested-With", "XMLHttpRequest")
|
||||||
|
.post(body)
|
||||||
|
.build();
|
||||||
|
try(Response response = site.getHttpClient().execute(request)) {
|
||||||
|
if(response.isSuccessful()) {
|
||||||
|
JSONObject json = new JSONObject(response.body().string());
|
||||||
|
return json;
|
||||||
|
} else {
|
||||||
|
throw new IOException(response.code() + " " + response.message());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void setOnline(boolean online) {
|
public void setOnline(boolean online) {
|
||||||
this.online = online;
|
this.online = online;
|
||||||
}
|
}
|
||||||
|
@ -95,34 +128,13 @@ public class BongaCamsModel extends AbstractModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getStreamUrl() throws IOException {
|
private String getStreamUrl() throws IOException {
|
||||||
String url = BongaCams.BASE_URL + "/tools/amf.php";
|
JSONObject roomData = getRoomData();
|
||||||
RequestBody body = new FormBody.Builder()
|
if(roomData.optString("status").equals("success")) {
|
||||||
.add("method", "getRoomData")
|
JSONObject localData = roomData.getJSONObject("localData");
|
||||||
.add("args[]", getName())
|
String server = localData.getString("videoServerUrl");
|
||||||
.add("args[]", "false")
|
return "https:" + server + "/hls/stream_" + getName() + "/playlist.m3u8";
|
||||||
.build();
|
} else {
|
||||||
Request request = new Request.Builder()
|
throw new IOException("Request was not successful: " + roomData.toString(2));
|
||||||
.url(url)
|
|
||||||
.addHeader("User-Agent", Config.getInstance().getSettings().httpUserAgent)
|
|
||||||
.addHeader("Accept", "application/json, text/javascript, */*")
|
|
||||||
.addHeader("Accept-Language", "en")
|
|
||||||
.addHeader("Referer", BongaCams.BASE_URL)
|
|
||||||
.addHeader("X-Requested-With", "XMLHttpRequest")
|
|
||||||
.post(body)
|
|
||||||
.build();
|
|
||||||
try(Response response = site.getHttpClient().execute(request)) {
|
|
||||||
if(response.isSuccessful()) {
|
|
||||||
JSONObject json = new JSONObject(response.body().string());
|
|
||||||
if(json.optString("status").equals("success")) {
|
|
||||||
JSONObject localData = json.getJSONObject("localData");
|
|
||||||
String server = localData.getString("videoServerUrl");
|
|
||||||
return "https:" + server + "/hls/stream_" + getName() + "/playlist.m3u8";
|
|
||||||
} else {
|
|
||||||
throw new IOException("Request was not successful: " + json.toString(2));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new IOException(response.code() + " " + response.message());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue