Improve behaviour of getOnlineState for XloveCam

This commit is contained in:
0xb00bface 2021-05-24 20:34:25 +02:00
parent 1f9dcf1ca4
commit 341846e94e
1 changed files with 18 additions and 1 deletions

View File

@ -45,7 +45,7 @@ public class XloveCamModel extends AbstractModel {
@Override
public boolean isOnline(boolean ignoreCache) throws IOException, ExecutionException, InterruptedException {
if (ignoreCache || onlineState == UNKNOWN) {
if (ignoreCache) {
String body = getModelPage();
Matcher m = HLS_PLAYLIST_PATTERN.matcher(body);
online = m.find();
@ -54,6 +54,23 @@ public class XloveCamModel extends AbstractModel {
return online;
}
@Override
public State getOnlineState(boolean failFast) throws IOException, ExecutionException {
if (failFast && onlineState != UNKNOWN) {
return onlineState;
} else {
try {
onlineState = isOnline(true) ? ONLINE : OFFLINE;
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
onlineState = OFFLINE;
} catch (IOException | ExecutionException e) {
onlineState = OFFLINE;
}
return onlineState;
}
}
@Override
public List<StreamSource> getStreamSources() throws IOException, ExecutionException, ParseException, PlaylistException, JAXBException {
MasterPlaylist masterPlaylist = getMasterPlaylist();