Java http request ->fetch() sessions: active or closed?

Hello everybody,
thank you for this open source openvidu server, really a great job.

I am trying to understand this part of the code
openvidu-java-client → OpenVidu.java → fetch()
How can i make the difference between active session , closed session und dead sessions?

his.activeSessions.computeIfPresent(sessionId, (sId, s) → {
String beforeJSON = s.toJson();
s = s.resetSessionWithJson((JSONObject) session);
String afterJSON = s.toJson();
boolean changed = !beforeJSON.equals(afterJSON);
hasChanged[0] = hasChanged[0] || changed;
log.info(“Available session ‘{}’ info fetched. Any change: {}”, sessionId, changed);
return s;
});
this.activeSessions.computeIfAbsent(sessionId, sId → {
log.info(“New session ‘{}’ fetched”, sessionId);
hasChanged[0] = true;
return new Session(this, (JSONObject) session);
});
});
// Remove closed sessions from activeSessions map
this.activeSessions = this.activeSessions.entrySet().stream().filter(entry → {
if (fetchedSessionIds.contains(entry.getKey())) {

						log.info("Removing closed session {}", entry.getKey());
						hasChanged[0] = true;
						return false;
				 
				}).collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue()));
				log.info("Active sessions info fetched: {}", this.activeSessions.keySet());
				return hasChanged[0];
	 
			EntityUtils.consumeQuietly(response.getEntity());

Thank you

Hi,

OpenVidu Server REST API and server SDKs (openvidu-java-client and openvidu-node-client libraries, which are simply a wrapper consuming the same REST API) only provide information about active sessions.

If you want to register closed/dead sessiones, you will have to do so on your own. Best way to do it is listening to WebHook events: https://openvidu.io/docs/reference-docs/openvidu-server-webhook/

That code snippet you got from openvidu-java-client simply updates the previous value of active sessiones with the value recently got from OpenVidu Server. That’s why the method is called “fetch”: it brings the real status of active sessions from OpenVidu Server and stores it in memory, so you can consult it from your Java backend. So to make sure you have the actual status of active session at a particular moment, you must call “fetch” method.

This is done this way because server SDKs do not have a hook system to which they can receive real time events from OpenVIdu Server. They must relay on actively polling from OpenVidu Server.

Regards