Skip to content

Commit

Permalink
SDKs send "mediaNode" property
Browse files Browse the repository at this point in the history
  • Loading branch information
pabloFuente committed Oct 26, 2020
1 parent 64b241c commit 0e4bbc4
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -661,17 +661,9 @@ private void getSessionIdHttp() throws OpenViduJavaClientException, OpenViduHttp
}

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;
try {
params = new StringEntity(json.toString());
params = new StringEntity(properties.toJson().toString());
} catch (UnsupportedEncodingException e1) {
throw new OpenViduJavaClientException(e1.getMessage(), e1.getCause());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package io.openvidu.java.client;

import com.google.gson.JsonObject;

import io.openvidu.java.client.Recording.OutputMode;

/**
Expand Down Expand Up @@ -261,4 +263,20 @@ public String 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;
}

}
3 changes: 2 additions & 1 deletion openvidu-node-client/src/Session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,8 @@ export class Session {
defaultOutputMode: !!this.properties.defaultOutputMode ? this.properties.defaultOutputMode : Recording.OutputMode.COMPOSED,
defaultRecordingLayout: !!this.properties.defaultRecordingLayout ? this.properties.defaultRecordingLayout : RecordingLayout.BEST_FIT,
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(
Expand Down
7 changes: 5 additions & 2 deletions openvidu-node-client/src/SessionProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>
*
* 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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.stream.Collectors;

import javax.annotation.PostConstruct;
Expand Down Expand Up @@ -445,38 +446,11 @@ private void startSessionGarbageCollector() {
log.info("Running non active sessions garbage collector...");
final long currentMillis = System.currentTimeMillis();

// Loop through all non active sessions. Safely remove them and clean all of
// their data if their threshold has elapsed
for (Iterator<Entry<String, Session>> iter = sessionsNotActive.entrySet().iterator(); iter.hasNext();) {
final Session sessionNotActive = iter.next().getValue();
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);
}
}
}
this.closeNonActiveSessions(sessionNotActive -> {
// Remove non active session if threshold has elapsed
return (currentMillis - sessionNotActive.getStartTime()) > (openviduConfig.getSessionGarbageThreshold()
* 1000);
});

// Warn about possible ghost sessions
for (Iterator<Entry<String, Session>> iter = sessions.entrySet().iterator(); iter.hasNext();) {
Expand Down Expand Up @@ -550,6 +524,40 @@ public void closeSession(String sessionId, EndReason reason) {
}
}

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) {

if (openviduConfig.isRecordingModuleEnabled()) {
Expand Down

0 comments on commit 0e4bbc4

Please sign in to comment.