DELETE /api/sessions/{sessionId}

pull/88/merge
pabloFuente 2018-07-05 14:05:09 +02:00
parent c9ad0309f6
commit bb58206ebc
9 changed files with 90 additions and 66 deletions

View File

@ -565,7 +565,7 @@ export class Session implements EventDispatcher {
* @hidden * @hidden
*/ */
onParticipantLeft(msg): void { onParticipantLeft(msg): void {
this.getRemoteConnection(msg.name, 'Remote connection ' + msg.name + " unknown when 'onParticipantLeft'. " + this.getRemoteConnection(msg.connectionId, 'Remote connection ' + msg.connectionId + " unknown when 'onParticipantLeft'. " +
'Existing remote connections: ' + JSON.stringify(Object.keys(this.remoteConnections))) 'Existing remote connections: ' + JSON.stringify(Object.keys(this.remoteConnections)))
.then(connection => { .then(connection => {
@ -630,7 +630,7 @@ export class Session implements EventDispatcher {
* @hidden * @hidden
*/ */
onParticipantUnpublished(msg): void { onParticipantUnpublished(msg): void {
this.getRemoteConnection(msg.name, "Remote connection '" + msg.name + "' unknown when 'onParticipantUnpublished'. " + this.getRemoteConnection(msg.connectionId, "Remote connection '" + msg.connectionId + "' unknown when 'onParticipantUnpublished'. " +
'Existing remote connections: ' + JSON.stringify(Object.keys(this.remoteConnections))) 'Existing remote connections: ' + JSON.stringify(Object.keys(this.remoteConnections)))
.then(connection => { .then(connection => {
@ -653,26 +653,33 @@ export class Session implements EventDispatcher {
* @hidden * @hidden
*/ */
onParticipantEvicted(msg): void { onParticipantEvicted(msg): void {
/*this.getRemoteConnection(msg.name, 'Remote connection ' + msg.name + " unknown when 'onParticipantLeft'. " + if (msg.connectionId === this.connection.connectionId) {
// You have been evicted from the session
if (!!this.sessionId && !this.connection.disposed) {
this.leave(true, msg.reason);
}
} else {
// Other user has been evicted from the session
this.getRemoteConnection(msg.connectionId, 'Remote connection ' + msg.connectionId + " unknown when 'onParticipantEvicted'. " +
'Existing remote connections: ' + JSON.stringify(Object.keys(this.remoteConnections))) 'Existing remote connections: ' + JSON.stringify(Object.keys(this.remoteConnections)))
.then(connection => { .then(connection => {
if (!!connection.stream) { if (!!connection.stream) {
const stream = connection.stream; const stream = connection.stream;
const streamEvent = new StreamEvent(true, this, 'streamDestroyed', stream, 'forceDisconnect'); const streamEvent = new StreamEvent(true, this, 'streamDestroyed', stream, msg.reason);
this.ee.emitEvent('streamDestroyed', [streamEvent]); this.ee.emitEvent('streamDestroyed', [streamEvent]);
streamEvent.callDefaultBehavior(); streamEvent.callDefaultBehavior();
delete this.remoteStreamsCreated[stream.streamId]; delete this.remoteStreamsCreated[stream.streamId];
} }
connection.dispose();
delete this.remoteConnections[connection.connectionId]; delete this.remoteConnections[connection.connectionId];
this.ee.emitEvent('connectionDestroyed', [new ConnectionEvent(false, this, 'connectionDestroyed', connection, 'forceDisconnect')]); this.ee.emitEvent('connectionDestroyed', [new ConnectionEvent(false, this, 'connectionDestroyed', connection, msg.reason)]);
}) })
.catch(openViduError => { .catch(openViduError => {
console.error(openViduError); console.error(openViduError);
});*/ });
}
} }
/** /**
@ -764,7 +771,7 @@ export class Session implements EventDispatcher {
*/ */
onSessionClosed(msg): void { onSessionClosed(msg): void {
console.info('Session closed: ' + JSON.stringify(msg)); console.info('Session closed: ' + JSON.stringify(msg));
const s = msg.room; const s = msg.sessionId;
if (s !== undefined) { if (s !== undefined) {
this.ee.emitEvent('session-closed', [{ this.ee.emitEvent('session-closed', [{
session: s session: s

View File

@ -95,10 +95,12 @@ public class ProtocolElements {
public static final String PARTICIPANTJOINED_METADATA_PARAM = "metadata"; public static final String PARTICIPANTJOINED_METADATA_PARAM = "metadata";
public static final String PARTICIPANTLEFT_METHOD = "participantLeft"; public static final String PARTICIPANTLEFT_METHOD = "participantLeft";
public static final String PARTICIPANTLEFT_NAME_PARAM = "name"; public static final String PARTICIPANTLEFT_NAME_PARAM = "connectionId";
public static final String PARTICIPANTLEFT_REASON_PARAM = "reason"; public static final String PARTICIPANTLEFT_REASON_PARAM = "reason";
public static final String PARTICIPANTEVICTED_METHOD = "participantEvicted"; public static final String PARTICIPANTEVICTED_METHOD = "participantEvicted";
public static final String PARTICIPANTEVICTED_CONNECTIONID_PARAM = "connectionId";
public static final String PARTICIPANTEVICTED_REASON_PARAM = "reason";
public static final String PARTICIPANTPUBLISHED_METHOD = "participantPublished"; public static final String PARTICIPANTPUBLISHED_METHOD = "participantPublished";
public static final String PARTICIPANTPUBLISHED_USER_PARAM = "id"; public static final String PARTICIPANTPUBLISHED_USER_PARAM = "id";
@ -113,7 +115,7 @@ public class ProtocolElements {
public static final String PARTICIPANTPUBLISHED_VIDEODIMENSIONS_PARAM = "videoDimensions"; public static final String PARTICIPANTPUBLISHED_VIDEODIMENSIONS_PARAM = "videoDimensions";
public static final String PARTICIPANTUNPUBLISHED_METHOD = "participantUnpublished"; public static final String PARTICIPANTUNPUBLISHED_METHOD = "participantUnpublished";
public static final String PARTICIPANTUNPUBLISHED_NAME_PARAM = "name"; public static final String PARTICIPANTUNPUBLISHED_NAME_PARAM = "connectionId";
public static final String PARTICIPANTUNPUBLISHED_REASON_PARAM = "reason"; public static final String PARTICIPANTUNPUBLISHED_REASON_PARAM = "reason";
public static final String PARTICIPANTSENDMESSAGE_METHOD = "sendMessage"; public static final String PARTICIPANTSENDMESSAGE_METHOD = "sendMessage";
@ -122,7 +124,7 @@ public class ProtocolElements {
public static final String PARTICIPANTSENDMESSAGE_TYPE_PARAM = "type"; public static final String PARTICIPANTSENDMESSAGE_TYPE_PARAM = "type";
public static final String ROOMCLOSED_METHOD = "roomClosed"; public static final String ROOMCLOSED_METHOD = "roomClosed";
public static final String ROOMCLOSED_ROOM_PARAM = "room"; public static final String ROOMCLOSED_ROOM_PARAM = "sessionId";
public static final String MEDIAERROR_METHOD = "mediaError"; public static final String MEDIAERROR_METHOD = "mediaError";
public static final String MEDIAERROR_ERROR_PARAM = "error"; public static final String MEDIAERROR_ERROR_PARAM = "error";

View File

@ -349,9 +349,12 @@ public class SessionEventsHandler {
rpcNotificationService.sendResponse(participant.getParticipantPrivateId(), transactionId, new JsonObject()); rpcNotificationService.sendResponse(participant.getParticipantPrivateId(), transactionId, new JsonObject());
} }
public void onParticipantEvicted(Participant participant) { public void onParticipantEvicted(Participant participant, String reason) {
JsonObject params = new JsonObject();
params.addProperty(ProtocolElements.PARTICIPANTEVICTED_CONNECTIONID_PARAM, participant.getParticipantPublicId());
params.addProperty(ProtocolElements.PARTICIPANTEVICTED_REASON_PARAM, reason);
rpcNotificationService.sendNotification(participant.getParticipantPrivateId(), rpcNotificationService.sendNotification(participant.getParticipantPrivateId(),
ProtocolElements.PARTICIPANTEVICTED_METHOD, new JsonObject()); ProtocolElements.PARTICIPANTEVICTED_METHOD, params);
} }
public void sendRecordingStartedNotification(Session session, Recording recording) { public void sendRecordingStartedNotification(Session session, Recording recording) {

View File

@ -75,7 +75,8 @@ public abstract class SessionManager {
public abstract void joinRoom(Participant participant, String sessionId, Integer transactionId); public abstract void joinRoom(Participant participant, String sessionId, Integer transactionId);
public abstract void leaveRoom(Participant participant, Integer transactionId, String reason); public abstract void leaveRoom(Participant participant, Integer transactionId, String reason,
boolean closeWebSocket);
public abstract void publishVideo(Participant participant, MediaOptions mediaOptions, Integer transactionId); public abstract void publishVideo(Participant participant, MediaOptions mediaOptions, Integer transactionId);
@ -397,7 +398,7 @@ public abstract class SessionManager {
* @throws OpenViduException * @throws OpenViduException
* in case the session doesn't exist or has been already closed * in case the session doesn't exist or has been already closed
*/ */
private Set<Participant> closeSession(String sessionId, String reason) { public Set<Participant> closeSession(String sessionId, String reason) {
Session session = sessions.get(sessionId); Session session = sessions.get(sessionId);
if (session == null) { if (session == null) {
throw new OpenViduException(Code.ROOM_NOT_FOUND_ERROR_CODE, "Session '" + sessionId + "' not found"); throw new OpenViduException(Code.ROOM_NOT_FOUND_ERROR_CODE, "Session '" + sessionId + "' not found");
@ -410,21 +411,13 @@ public abstract class SessionManager {
Set<String> pids = participants.stream().map(Participant::getParticipantPrivateId).collect(Collectors.toSet()); Set<String> pids = participants.stream().map(Participant::getParticipantPrivateId).collect(Collectors.toSet());
for (String pid : pids) { for (String pid : pids) {
try { try {
session.leave(pid, reason); this.evictParticipant(pid, reason);
} catch (OpenViduException e) { } catch (OpenViduException e) {
log.warn("Error evicting participant with id '{}' from session '{}'", pid, sessionId, e); log.warn("Error evicting participant with id '{}' from session '{}'", pid, sessionId, e);
} }
} }
if (session.close(reason)) {
sessionEventsHandler.onSessionClosed(sessionId, reason);
}
sessions.remove(sessionId);
sessionProperties.remove(sessionId); this.closeSessionAndEmptyCollections(session, reason);
sessionidParticipantpublicidParticipant.remove(sessionId);
sessionidTokenTokenobj.remove(sessionId);
log.warn("Session '{}' removed and closed", sessionId);
if (recordingService.sessionIsBeingRecorded(session.getSessionId())) { if (recordingService.sessionIsBeingRecorded(session.getSessionId())) {
recordingService.stopRecording(session); recordingService.stopRecording(session);
@ -433,4 +426,17 @@ public abstract class SessionManager {
return participants; return participants;
} }
public void closeSessionAndEmptyCollections(Session session, String reason) {
if (session.close(reason)) {
sessionEventsHandler.onSessionClosed(session.getSessionId(), reason);
}
sessions.remove(session.getSessionId());
sessionProperties.remove(session.getSessionId());
sessionidParticipantpublicidParticipant.remove(session.getSessionId());
sessionidTokenTokenobj.remove(session.getSessionId());
log.warn("Session '{}' removed and closed", session.getSessionId());
}
} }

View File

@ -105,7 +105,7 @@ public class KurentoSessionManager extends SessionManager {
} }
@Override @Override
public synchronized void leaveRoom(Participant participant, Integer transactionId, String reason) { public synchronized void leaveRoom(Participant participant, Integer transactionId, String reason, boolean closeWebSocket) {
log.debug("Request [LEAVE_ROOM] ({})", participant.getParticipantPublicId()); log.debug("Request [LEAVE_ROOM] ({})", participant.getParticipantPublicId());
KurentoParticipant kParticipant = (KurentoParticipant) participant; KurentoParticipant kParticipant = (KurentoParticipant) participant;
@ -156,26 +156,13 @@ public class KurentoSessionManager extends SessionManager {
log.info("Possible collision when closing the session '{}' (not found)", sessionId); log.info("Possible collision when closing the session '{}' (not found)", sessionId);
remainingParticipants = Collections.emptySet(); remainingParticipants = Collections.emptySet();
} }
sessionEventsHandler.onParticipantLeft(participant, sessionId, remainingParticipants, transactionId, null, sessionEventsHandler.onParticipantLeft(participant, sessionId, remainingParticipants, transactionId, null,
reason); reason);
if (remainingParticipants.isEmpty()) { if (remainingParticipants.isEmpty()) {
log.info("No more participants in session '{}', removing it and closing it", sessionId); log.info("No more participants in session '{}', removing it and closing it", sessionId);
if (session.close(reason)) { this.closeSessionAndEmptyCollections(session, reason);
sessionEventsHandler.onSessionClosed(sessionId, "lastParticipantLeft");
}
sessions.remove(sessionId);
sessionProperties.remove(sessionId);
sessionidParticipantpublicidParticipant.remove(sessionId);
sessionidTokenTokenobj.remove(sessionId);
showTokens(); showTokens();
log.warn("Session '{}' removed and closed", sessionId);
} else if (remainingParticipants.size() == 1 && openviduConfig.isRecordingModuleEnabled() } else if (remainingParticipants.size() == 1 && openviduConfig.isRecordingModuleEnabled()
&& MediaMode.ROUTED.equals(session.getSessionProperties().mediaMode()) && MediaMode.ROUTED.equals(session.getSessionProperties().mediaMode())
&& RecordingMode.ALWAYS.equals(session.getSessionProperties().recordingMode()) && RecordingMode.ALWAYS.equals(session.getSessionProperties().recordingMode())
@ -188,9 +175,11 @@ public class KurentoSessionManager extends SessionManager {
.getParticipantPrivateId(), "EVICT_RECORDER"); .getParticipantPrivateId(), "EVICT_RECORDER");
} }
// Finally close websocket session // Finally close websocket session if required
if (closeWebSocket) {
sessionEventsHandler.closeRpcSession(participant.getParticipantPrivateId()); sessionEventsHandler.closeRpcSession(participant.getParticipantPrivateId());
} }
}
/** /**
* Represents a client's request to start streaming her local media to anyone * Represents a client's request to start streaming her local media to anyone
@ -477,8 +466,9 @@ public class KurentoSessionManager extends SessionManager {
@Override @Override
public void evictParticipant(String participantPrivateId, String reason) throws OpenViduException { public void evictParticipant(String participantPrivateId, String reason) throws OpenViduException {
Participant participant = this.getParticipant(participantPrivateId); Participant participant = this.getParticipant(participantPrivateId);
this.leaveRoom(participant, null, reason); this.leaveRoom(participant, null, reason, false);
sessionEventsHandler.onParticipantEvicted(participant); sessionEventsHandler.onParticipantEvicted(participant, reason);
sessionEventsHandler.closeRpcSession(participantPrivateId);
} }
@Override @Override

View File

@ -166,6 +166,17 @@ public class SessionRestController {
return new ResponseEntity<>(json, HttpStatus.OK); return new ResponseEntity<>(json, HttpStatus.OK);
} }
@RequestMapping(value = "/sessions/{sessionId}", method = RequestMethod.DELETE)
public ResponseEntity<JSONObject> closeSession(@PathVariable("sessionId") String sessionId) {
Session session = this.sessionManager.getSession(sessionId);
if (session != null) {
this.sessionManager.closeSession(sessionId, "sessionClosedByServer");
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
} else {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@RequestMapping(value = "/tokens", method = RequestMethod.POST) @RequestMapping(value = "/tokens", method = RequestMethod.POST)
public ResponseEntity<JSONObject> newToken(@RequestBody Map<?, ?> params) { public ResponseEntity<JSONObject> newToken(@RequestBody Map<?, ?> params) {

View File

@ -203,7 +203,7 @@ public class RpcHandler extends DefaultJsonRpcHandler<JsonObject> {
Participant participant = sessionManager.getParticipant(sessionId, participantPrivateId); Participant participant = sessionManager.getParticipant(sessionId, participantPrivateId);
if (participant != null) { if (participant != null) {
log.info("Participant {} is leaving session {}", participant.getParticipantPublicId(), sessionId); log.info("Participant {} is leaving session {}", participant.getParticipantPublicId(), sessionId);
sessionManager.leaveRoom(participant, request.getId(), "disconnect"); sessionManager.leaveRoom(participant, request.getId(), "disconnect", true);
log.info("Participant {} has left session {}", participant.getParticipantPublicId(), sessionId); log.info("Participant {} has left session {}", participant.getParticipantPublicId(), sessionId);
} else { } else {
log.warn("Participant with private id {} not found in session {}. " log.warn("Participant with private id {} not found in session {}. "

View File

@ -10,12 +10,8 @@ sudo apt-get -y update && sudo apt-get -y install iptables && sudo apt-get -y in
# UDP rules (DROP all) # UDP rules (DROP all)
sudo iptables -A OUTPUT -p udp --dport 0:65535 -j DROP
sudo iptables -A INPUT -p udp --dport 0:65535 -j DROP
sudo iptables -A OUTPUT -o eth0 -p tcp --dport 80 -j ACCEPT sudo iptables -A OUTPUT -o eth0 -p tcp --dport 80 -j ACCEPT
sudo iptables -A OUTPUT -o eth0 -p tcp --dport 443 -j ACCEPT sudo iptables -A OUTPUT -o eth0 -p tcp --dport 443 -j ACCEPT
sudo iptables -A OUTPUT -o eth0 -p tcp --dport 53 -j ACCEPT
sudo iptables -A OUTPUT -o eth0 -p tcp --dport 4444 -j ACCEPT sudo iptables -A OUTPUT -o eth0 -p tcp --dport 4444 -j ACCEPT
sudo iptables -A OUTPUT -o eth0 -p tcp --dport 6080 -j ACCEPT sudo iptables -A OUTPUT -o eth0 -p tcp --dport 6080 -j ACCEPT
sudo iptables -A OUTPUT -o eth0 -p tcp --dport 5900 -j ACCEPT sudo iptables -A OUTPUT -o eth0 -p tcp --dport 5900 -j ACCEPT
@ -25,7 +21,6 @@ sudo iptables -A OUTPUT -o eth0 -p tcp --dport 3478 -j ACCEPT
sudo iptables -A OUTPUT -o eth0 -p tcp --sport 80 -j ACCEPT sudo iptables -A OUTPUT -o eth0 -p tcp --sport 80 -j ACCEPT
sudo iptables -A OUTPUT -o eth0 -p tcp --sport 443 -j ACCEPT sudo iptables -A OUTPUT -o eth0 -p tcp --sport 443 -j ACCEPT
sudo iptables -A OUTPUT -o eth0 -p tcp --sport 53 -j ACCEPT
sudo iptables -A OUTPUT -o eth0 -p tcp --sport 4444 -j ACCEPT sudo iptables -A OUTPUT -o eth0 -p tcp --sport 4444 -j ACCEPT
sudo iptables -A OUTPUT -o eth0 -p tcp --sport 6080 -j ACCEPT sudo iptables -A OUTPUT -o eth0 -p tcp --sport 6080 -j ACCEPT
sudo iptables -A OUTPUT -o eth0 -p tcp --sport 5900 -j ACCEPT sudo iptables -A OUTPUT -o eth0 -p tcp --sport 5900 -j ACCEPT
@ -33,8 +28,20 @@ sudo iptables -A OUTPUT -o eth0 -p tcp --sport 4200 -j ACCEPT
sudo iptables -A OUTPUT -o eth0 -p tcp --sport 4443 -j ACCEPT sudo iptables -A OUTPUT -o eth0 -p tcp --sport 4443 -j ACCEPT
sudo iptables -A OUTPUT -o eth0 -p tcp --sport 3478 -j ACCEPT sudo iptables -A OUTPUT -o eth0 -p tcp --sport 3478 -j ACCEPT
sudo iptables -A OUTPUT -p tcp --sport 53 -j ACCEPT
sudo iptables -A OUTPUT -p tcp --dport 53 -j ACCEPT
sudo iptables -A OUTPUT -p udp --sport 53 -j ACCEPT
sudo iptables -A OUTPUT -p udp --dport 53 -j ACCEPT
sudo iptables -A INPUT -p tcp --sport 53 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 53 -j ACCEPT
sudo iptables -A INPUT -p udp --sport 53 -j ACCEPT
sudo iptables -A INPUT -p udp --dport 53 -j ACCEPT
sudo iptables -A OUTPUT -o eth0 -p tcp -j DROP sudo iptables -A OUTPUT -o eth0 -p tcp -j DROP
sudo iptables -A OUTPUT -p udp --dport 0:65535 -j DROP
sudo iptables -A INPUT -p udp --dport 0:65535 -j DROP
exit exit
EOF EOF

View File

@ -356,10 +356,8 @@ export class OpenviduInstanceComponent implements OnInit, OnChanges, OnDestroy {
if (this.sessionEvents.sessionDisconnected) { if (this.sessionEvents.sessionDisconnected) {
this.session.on('sessionDisconnected', (event: SessionDisconnectedEvent) => { this.session.on('sessionDisconnected', (event: SessionDisconnectedEvent) => {
this.updateEventList('sessionDisconnected', 'No data'); this.updateEventList('sessionDisconnected', 'No data');
if (event.reason === 'networkDisconnect') {
this.session = null; this.session = null;
this.OV = null; this.OV = null;
}
}); });
} }
} }