Fix: MyFreeCams model state updates
This commit is contained in:
parent
f926f784b3
commit
3e038f7429
|
@ -1,10 +1,12 @@
|
|||
package ctbrec.sites.mfc;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import ctbrec.Config;
|
||||
import ctbrec.StringUtil;
|
||||
import ctbrec.io.HttpException;
|
||||
import ctbrec.io.json.ObjectMapperFactory;
|
||||
import okhttp3.*;
|
||||
import okio.ByteString;
|
||||
import org.json.JSONArray;
|
||||
|
@ -33,6 +35,8 @@ public class MyFreeCamsClient {
|
|||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(MyFreeCamsClient.class);
|
||||
|
||||
private static final ObjectMapper objectMapper = ObjectMapperFactory.getMapper();
|
||||
|
||||
private static MyFreeCamsClient instance;
|
||||
private MyFreeCams mfc;
|
||||
private WebSocket ws;
|
||||
|
@ -224,16 +228,14 @@ public class MyFreeCamsClient {
|
|||
case MYWEBCAM:
|
||||
case JOINCHAN:
|
||||
case SESSIONSTATE:
|
||||
// if (!message.getMessage().isEmpty()) {
|
||||
// //LOG.debug("SessionState: {}", message.getMessage());
|
||||
// JsonAdapter<SessionState> adapter = moshi.adapter(SessionState.class);
|
||||
// try {
|
||||
// SessionState sessionState = adapter.fromJson(message.getMessage());
|
||||
// updateSessionState(sessionState);
|
||||
// } catch (IOException e) {
|
||||
// LOG.error("Couldn't parse session state message {}", message, e);
|
||||
// }
|
||||
// }
|
||||
if (!message.getMessage().isEmpty()) {
|
||||
try {
|
||||
SessionState sessionState = objectMapper.readValue(message.getMessage(), SessionState.class);
|
||||
updateSessionState(sessionState);
|
||||
} catch (IOException e) {
|
||||
LOG.error("Couldn't parse session state message {}", message, e);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case USERNAMELOOKUP:
|
||||
// LOG.debug("{}", message.getType());
|
||||
|
@ -675,14 +677,12 @@ public class MyFreeCamsClient {
|
|||
LOG.trace("Search result: {}", msg);
|
||||
if (StringUtil.isNotBlank(msg.getMessage()) && !Objects.equals(msg.getMessage(), q)) {
|
||||
JSONObject json = new JSONObject(msg.getMessage());
|
||||
|
||||
// JsonAdapter<SessionState> adapter = moshi.adapter(SessionState.class);
|
||||
// try {
|
||||
// SessionState sessionState = Objects.requireNonNull(adapter.fromJson(msg.getMessage()));
|
||||
// updateSessionState(sessionState);
|
||||
// } catch (Exception e) {
|
||||
// LOG.error("Couldn't parse session state message {}", msg, e);
|
||||
// }
|
||||
try {
|
||||
SessionState sessionState = Objects.requireNonNull(objectMapper.readValue(msg.getMessage(), SessionState.class));
|
||||
updateSessionState(sessionState);
|
||||
} catch (Exception e) {
|
||||
LOG.error("Couldn't parse session state message {}", msg, e);
|
||||
}
|
||||
|
||||
String name = json.getString("nm");
|
||||
MyFreeCamsModel model = mfc.createModel(name);
|
||||
|
|
Loading…
Reference in New Issue