mirror of https://github.com/OpenVidu/openvidu.git
SDKs send "mediaNode" property
parent
64b241c170
commit
0e4bbc4555
|
@ -661,17 +661,9 @@ public class Session {
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpPost request = new HttpPost(this.openVidu.hostname + OpenVidu.API_SESSIONS);
|
HttpPost request = new HttpPost(this.openVidu.hostname + OpenVidu.API_SESSIONS);
|
||||||
|
|
||||||
JsonObject json = new JsonObject();
|
|
||||||
json.addProperty("mediaMode", properties.mediaMode().name());
|
|
||||||
json.addProperty("recordingMode", properties.recordingMode().name());
|
|
||||||
json.addProperty("defaultOutputMode", properties.defaultOutputMode().name());
|
|
||||||
json.addProperty("defaultRecordingLayout", properties.defaultRecordingLayout().name());
|
|
||||||
json.addProperty("defaultCustomLayout", properties.defaultCustomLayout());
|
|
||||||
json.addProperty("customSessionId", properties.customSessionId());
|
|
||||||
StringEntity params = null;
|
StringEntity params = null;
|
||||||
try {
|
try {
|
||||||
params = new StringEntity(json.toString());
|
params = new StringEntity(properties.toJson().toString());
|
||||||
} catch (UnsupportedEncodingException e1) {
|
} catch (UnsupportedEncodingException e1) {
|
||||||
throw new OpenViduJavaClientException(e1.getMessage(), e1.getCause());
|
throw new OpenViduJavaClientException(e1.getMessage(), e1.getCause());
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
|
|
||||||
package io.openvidu.java.client;
|
package io.openvidu.java.client;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
|
||||||
import io.openvidu.java.client.Recording.OutputMode;
|
import io.openvidu.java.client.Recording.OutputMode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -261,4 +263,20 @@ public class SessionProperties {
|
||||||
return this.mediaNode;
|
return this.mediaNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected JsonObject toJson() {
|
||||||
|
JsonObject json = new JsonObject();
|
||||||
|
json.addProperty("mediaMode", mediaMode().name());
|
||||||
|
json.addProperty("recordingMode", recordingMode().name());
|
||||||
|
json.addProperty("defaultOutputMode", defaultOutputMode().name());
|
||||||
|
json.addProperty("defaultRecordingLayout", defaultRecordingLayout().name());
|
||||||
|
json.addProperty("defaultCustomLayout", defaultCustomLayout());
|
||||||
|
json.addProperty("customSessionId", customSessionId());
|
||||||
|
if (mediaNode() != null) {
|
||||||
|
JsonObject mediaNodeJson = new JsonObject();
|
||||||
|
mediaNodeJson.addProperty("id", mediaNode());
|
||||||
|
json.add("mediaNode", mediaNodeJson);
|
||||||
|
}
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -465,7 +465,8 @@ export class Session {
|
||||||
defaultOutputMode: !!this.properties.defaultOutputMode ? this.properties.defaultOutputMode : Recording.OutputMode.COMPOSED,
|
defaultOutputMode: !!this.properties.defaultOutputMode ? this.properties.defaultOutputMode : Recording.OutputMode.COMPOSED,
|
||||||
defaultRecordingLayout: !!this.properties.defaultRecordingLayout ? this.properties.defaultRecordingLayout : RecordingLayout.BEST_FIT,
|
defaultRecordingLayout: !!this.properties.defaultRecordingLayout ? this.properties.defaultRecordingLayout : RecordingLayout.BEST_FIT,
|
||||||
defaultCustomLayout: !!this.properties.defaultCustomLayout ? this.properties.defaultCustomLayout : '',
|
defaultCustomLayout: !!this.properties.defaultCustomLayout ? this.properties.defaultCustomLayout : '',
|
||||||
customSessionId: !!this.properties.customSessionId ? this.properties.customSessionId : ''
|
customSessionId: !!this.properties.customSessionId ? this.properties.customSessionId : '',
|
||||||
|
mediaNode: !!this.properties.mediaNode ? this.properties.mediaNode : undefined
|
||||||
});
|
});
|
||||||
|
|
||||||
axios.post(
|
axios.post(
|
||||||
|
|
|
@ -69,8 +69,11 @@ export interface SessionProperties {
|
||||||
* **This feature is part of OpenVidu Pro tier** <a href="https://docs.openvidu.io/en/stable/openvidu-pro/" target="_blank" style="display: inline-block; background-color: rgb(0, 136, 170); color: white; font-weight: bold; padding: 0px 5px; margin-right: 5px; border-radius: 3px; font-size: 13px; line-height:21px; font-family: Montserrat, sans-serif">PRO</a>
|
* **This feature is part of OpenVidu Pro tier** <a href="https://docs.openvidu.io/en/stable/openvidu-pro/" target="_blank" style="display: inline-block; background-color: rgb(0, 136, 170); color: white; font-weight: bold; padding: 0px 5px; margin-right: 5px; border-radius: 3px; font-size: 13px; line-height:21px; font-family: Montserrat, sans-serif">PRO</a>
|
||||||
*
|
*
|
||||||
* The Media Node where to host the session. The default option if this property is not defined is the less loaded
|
* The Media Node where to host the session. The default option if this property is not defined is the less loaded
|
||||||
* Media Node at the moment the first user joins the session.
|
* Media Node at the moment the first user joins the session. This object defines the following properties as Media Node selector:
|
||||||
|
* - `id`: Media Node unique identifier
|
||||||
*/
|
*/
|
||||||
mediaNode?: string;
|
mediaNode?: {
|
||||||
|
id: string;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
|
@ -445,38 +446,11 @@ public abstract class SessionManager {
|
||||||
log.info("Running non active sessions garbage collector...");
|
log.info("Running non active sessions garbage collector...");
|
||||||
final long currentMillis = System.currentTimeMillis();
|
final long currentMillis = System.currentTimeMillis();
|
||||||
|
|
||||||
// Loop through all non active sessions. Safely remove them and clean all of
|
this.closeNonActiveSessions(sessionNotActive -> {
|
||||||
// their data if their threshold has elapsed
|
// Remove non active session if threshold has elapsed
|
||||||
for (Iterator<Entry<String, Session>> iter = sessionsNotActive.entrySet().iterator(); iter.hasNext();) {
|
return (currentMillis - sessionNotActive.getStartTime()) > (openviduConfig.getSessionGarbageThreshold()
|
||||||
final Session sessionNotActive = iter.next().getValue();
|
* 1000);
|
||||||
final String sessionId = sessionNotActive.getSessionId();
|
});
|
||||||
long sessionExistsSince = currentMillis - sessionNotActive.getStartTime();
|
|
||||||
if (sessionExistsSince > (openviduConfig.getSessionGarbageThreshold() * 1000)) {
|
|
||||||
try {
|
|
||||||
if (sessionNotActive.closingLock.writeLock().tryLock(15, TimeUnit.SECONDS)) {
|
|
||||||
try {
|
|
||||||
if (sessions.containsKey(sessionId)) {
|
|
||||||
// The session passed to active during lock wait
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
iter.remove();
|
|
||||||
cleanCollections(sessionId);
|
|
||||||
log.info("Non active session {} cleaned up by garbage collector", sessionId);
|
|
||||||
} finally {
|
|
||||||
sessionNotActive.closingLock.writeLock().unlock();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
log.error(
|
|
||||||
"Timeout waiting for Session closing lock to be available for garbage collector to clean session {}",
|
|
||||||
sessionId);
|
|
||||||
}
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
log.error(
|
|
||||||
"InterruptedException while waiting for Session closing lock to be available for garbage collector to clean session {}",
|
|
||||||
sessionId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Warn about possible ghost sessions
|
// Warn about possible ghost sessions
|
||||||
for (Iterator<Entry<String, Session>> iter = sessions.entrySet().iterator(); iter.hasNext();) {
|
for (Iterator<Entry<String, Session>> iter = sessions.entrySet().iterator(); iter.hasNext();) {
|
||||||
|
@ -550,6 +524,40 @@ public abstract class SessionManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void closeNonActiveSessions(Function<Session, Boolean> conditionToRemove) {
|
||||||
|
// Loop through all non active sessions. Safely remove and clean all of
|
||||||
|
// the data for each non active session meeting the condition
|
||||||
|
for (Iterator<Entry<String, Session>> iter = sessionsNotActive.entrySet().iterator(); iter.hasNext();) {
|
||||||
|
final Session sessionNotActive = iter.next().getValue();
|
||||||
|
final String sessionId = sessionNotActive.getSessionId();
|
||||||
|
if (conditionToRemove.apply(sessionNotActive)) {
|
||||||
|
try {
|
||||||
|
if (sessionNotActive.closingLock.writeLock().tryLock(15, TimeUnit.SECONDS)) {
|
||||||
|
try {
|
||||||
|
if (sessions.containsKey(sessionId)) {
|
||||||
|
// The session passed to active during lock wait
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
iter.remove();
|
||||||
|
cleanCollections(sessionId);
|
||||||
|
log.info("Non active session {} cleaned up", sessionId);
|
||||||
|
} finally {
|
||||||
|
sessionNotActive.closingLock.writeLock().unlock();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.error(
|
||||||
|
"Timeout waiting for Session closing lock to be available to clean up non active session {}",
|
||||||
|
sessionId);
|
||||||
|
}
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
log.error(
|
||||||
|
"InterruptedException while waiting for non active Session closing lock to be available to clean up non active session session {}",
|
||||||
|
sessionId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void closeSessionAndEmptyCollections(Session session, EndReason reason, boolean stopRecording) {
|
public void closeSessionAndEmptyCollections(Session session, EndReason reason, boolean stopRecording) {
|
||||||
|
|
||||||
if (openviduConfig.isRecordingModuleEnabled()) {
|
if (openviduConfig.isRecordingModuleEnabled()) {
|
||||||
|
|
Loading…
Reference in New Issue