public static Boolean addFrameToSession(ServerFrameBean serverFrameBean) {
try {
if (sharingSessions.containsKey(serverFrameBean.getPublicSID())) {
ServerSharingSessionBean serverSharingSessionBean = sharingSessions.get(serverFrameBean.getPublicSID());
if (serverSharingSessionBean.isDeleted()) {
//This happens because packets arrive later then the status message
//this is quite usual
log.debug("Session already Stopped");
return false;
}
if (serverFrameBean.getMode() == 1) {
serverSharingSessionBean.setSharing(true);
serverSharingSessionBean.setRecording(false);
} else if (serverFrameBean.getMode() == 2) {
serverSharingSessionBean.setSharing(false);
serverSharingSessionBean.setRecording(true);
} else if (serverFrameBean.getMode() == 3) {
serverSharingSessionBean.setSharing(true);
serverSharingSessionBean.setRecording(true);
}
if (serverSharingSessionBean.getServerFrameBeans().size() < serverSharingSessionBean.getNumberOfImages()) {
log.debug("Server Frame Buffer Not yet Full ");
//Check for duplicates
boolean foundDuplicate = false;
//log.debug("Check :: "+serverFrameBean.getXValue()+"||"+serverFrameBean.getYValue());
//log.debug("Check :: SIZE "+serverSharingSessionBean.getServerFrameBeans().size());
for (ServerFrameBean serverFrameBeanStored : serverSharingSessionBean.getServerFrameBeans()) {
if (serverFrameBeanStored.getXValue().equals(serverFrameBean.getXValue()) &&
serverFrameBeanStored.getYValue().equals(serverFrameBean.getYValue())) {
//log.debug("Found Duplicate Before Buffer is NOT full "+serverFrameBeanStored.getXValue()+"||"+serverFrameBeanStored.getYValue());
foundDuplicate = true;
serverFrameBeanStored.setImageBytesAsJPEG(serverFrameBean.getImageBytesAsJPEG());
serverFrameBeanStored.setImageBytes(serverFrameBean.getImageBytes());
break;
}
}
if (!foundDuplicate) {
//log.debug("Add to Cache "+serverFrameBean.getXValue()+"||"+serverFrameBean.getYValue());
serverSharingSessionBean.getServerFrameBeans().add(serverFrameBean);
}
} else {
/* ##################################
* Buffer Full, there is a complete Screen available
*
*/
//log.debug("Check :: SIZE -1- "+serverSharingSessionBean.getServerFrameBeans().size());
//log.debug("Check :: SIZE -2- "+serverSharingSessionBean.getNumberOfImages());
if (!serverSharingSessionBean.isSendCompleteFlag()) {
log.debug("SEND Buffer Full Message -1- Start ScreenSharing or Recording for all Clients "+serverSharingSessionBean.getPublicSID());
Date d = new Date();
log.debug("SEND Buffer Full Message -2- Start ScreenSharing or Recording for all Clients "+(d.getTime() - serverSharingSessionBean.getSessionStarted().getTime()));
ScopeApplicationAdapter scopeApplicationAdapter = ScopeApplicationAdapter.getInstance();
if (scopeApplicationAdapter != null) {
scopeApplicationAdapter.sendScreenSharingMessage(serverSharingSessionBean);
}
if (serverSharingSessionBean.isSharing()) {
}
if (serverSharingSessionBean.isRecording()) {
//TODO: Add Scheduler to produce Frame capture
//For Testing Write all Images to a standard dir
//writeImagesToStandardDirectory(serverSharingSessionBean);
}
serverSharingSessionBean.setSendCompleteFlag(true);
} else {
/* #################################
* Send Screen to ODSP-Connections
*
*/
ServerSocketMinaProcess.sendMessageToSession(serverFrameBean);
/* #################################
* Send Screen to trigger HTTP-Connections
*
*/
ScopeApplicationAdapter scopeApplicationAdapter = ScopeApplicationAdapter.getInstance();
if (scopeApplicationAdapter != null) {
ScopeApplicationAdapter.getInstance().sendScreenSharingFrame(serverFrameBean);
}
}
//Check for duplicates
boolean foundDuplicate = false;
//log.debug("SEARCH getXValue(),getYValue()"+serverFrameBean.getXValue()+","+serverFrameBean.getYValue());
for (ServerFrameBean serverFrameBeanStored : serverSharingSessionBean.getServerFrameBeans()) {
//log.debug("serverFrameBeanStored.getXValue(),serverFrameBeanStored.getYValue()"+serverFrameBeanStored.getXValue()+","+serverFrameBeanStored.getYValue());
if (serverFrameBeanStored.getXValue().equals(serverFrameBean.getXValue()) &&
serverFrameBeanStored.getYValue().equals(serverFrameBean.getYValue())) {