Update MFC SessionState from search result
This commit is contained in:
parent
52bbf78e40
commit
1a0cc73ec3
|
@ -407,51 +407,6 @@ public class MyFreeCamsClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateSessionState(SessionState newState) {
|
|
||||||
if (newState.getUid() <= 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
SessionState storedState = sessionStates.getIfPresent(newState.getUid());
|
|
||||||
if (storedState != null) {
|
|
||||||
storedState.merge(newState);
|
|
||||||
updateModel(storedState);
|
|
||||||
} else {
|
|
||||||
lock.lock();
|
|
||||||
try {
|
|
||||||
sessionStates.put(newState.getUid(), newState);
|
|
||||||
updateModel(newState);
|
|
||||||
} finally {
|
|
||||||
lock.unlock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateModel(SessionState state) {
|
|
||||||
// essential data not yet available
|
|
||||||
if (state.getNm() == null || state.getM() == null || state.getU() == null || state.getU().getCamserv() == null
|
|
||||||
|| state.getU().getCamserv() == 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// tokens not yet available
|
|
||||||
if (ctxenc == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// uid not set, we can't identify this model
|
|
||||||
if (state.getUid() == null || state.getUid() <= 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
MyFreeCamsModel model = models.getIfPresent(state.getUid());
|
|
||||||
if (model == null) {
|
|
||||||
model = mfc.createModel(state.getNm());
|
|
||||||
model.setUid(state.getUid());
|
|
||||||
models.put(state.getUid(), model);
|
|
||||||
}
|
|
||||||
model.update(state, getStreamUrl(state));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMessage(WebSocket webSocket, ByteString bytes) {
|
public void onMessage(WebSocket webSocket, ByteString bytes) {
|
||||||
super.onMessage(webSocket, bytes);
|
super.onMessage(webSocket, bytes);
|
||||||
|
@ -461,6 +416,51 @@ public class MyFreeCamsClient {
|
||||||
return websocket;
|
return websocket;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateSessionState(SessionState newState) {
|
||||||
|
if (newState.getUid() <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SessionState storedState = sessionStates.getIfPresent(newState.getUid());
|
||||||
|
if (storedState != null) {
|
||||||
|
storedState.merge(newState);
|
||||||
|
updateModel(storedState);
|
||||||
|
} else {
|
||||||
|
lock.lock();
|
||||||
|
try {
|
||||||
|
sessionStates.put(newState.getUid(), newState);
|
||||||
|
updateModel(newState);
|
||||||
|
} finally {
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateModel(SessionState state) {
|
||||||
|
// essential data not yet available
|
||||||
|
if (state.getNm() == null || state.getM() == null || state.getU() == null || state.getU().getCamserv() == null
|
||||||
|
|| state.getU().getCamserv() == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// tokens not yet available
|
||||||
|
if (ctxenc == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// uid not set, we can't identify this model
|
||||||
|
if (state.getUid() == null || state.getUid() <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
MyFreeCamsModel model = models.getIfPresent(state.getUid());
|
||||||
|
if (model == null) {
|
||||||
|
model = mfc.createModel(state.getNm());
|
||||||
|
model.setUid(state.getUid());
|
||||||
|
models.put(state.getUid(), model);
|
||||||
|
}
|
||||||
|
model.update(state, getStreamUrl(state));
|
||||||
|
}
|
||||||
|
|
||||||
private Message parseMessage(StringBuilder msgBuffer) {
|
private Message parseMessage(StringBuilder msgBuffer) {
|
||||||
int packetLengthBytes = 6;
|
int packetLengthBytes = 6;
|
||||||
if (msgBuffer.length() < packetLengthBytes) {
|
if (msgBuffer.length() < packetLengthBytes) {
|
||||||
|
@ -676,6 +676,15 @@ public class MyFreeCamsClient {
|
||||||
LOG.trace("Search result: {}", msg);
|
LOG.trace("Search result: {}", msg);
|
||||||
if (StringUtil.isNotBlank(msg.getMessage()) && !Objects.equals(msg.getMessage(), q)) {
|
if (StringUtil.isNotBlank(msg.getMessage()) && !Objects.equals(msg.getMessage(), q)) {
|
||||||
JSONObject json = new JSONObject(msg.getMessage());
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
String name = json.getString("nm");
|
String name = json.getString("nm");
|
||||||
MyFreeCamsModel model = mfc.createModel(name);
|
MyFreeCamsModel model = mfc.createModel(name);
|
||||||
model.setUid(json.getInt("uid"));
|
model.setUid(json.getInt("uid"));
|
||||||
|
|
Loading…
Reference in New Issue