}
public static Long _stopRecordAndSave(IScope scope, String roomrecordingName, RoomClient currentClient){
try {
log.debug("stopRecordAndSave "+currentClient.getUsername()+","+currentClient.getUserip());
RoomRecording roomRecording = roomRecordingList.get(roomrecordingName);
Long room_id = currentClient.getRoom_id();
currentClient.setIsRecording(false);
currentClient.setRoomRecordingName("");
ClientListManager.getInstance().updateClientByStreamId(currentClient.getStreamid(), currentClient);
String conferenceType = roomRecording.getConferenceType();
//get all stream and stop recording them
//Todo: Check that nobody does Recording at the same time Issue 253
Collection<Set<IConnection>> conCollection = scope.getConnections();
for (Set<IConnection> conset : conCollection) {
for (IConnection conn : conset) {
if (conn != null) {
if (conn instanceof IServiceCapableConnection) {
RoomClient rcl = ClientListManager.getInstance().getClientByStreamId(conn.getClient().getId());
log.debug("is this users still alive? :"+rcl);
//Check if the Client is in the same room and same domain
if(room_id.equals(rcl.getRoom_id()) && room_id!=null){
if (!conferenceType.equals("audience") || rcl.getIsMod()){
//stop the recorded flv and add the event to the notifications
log.debug("*** sendClientBroadcastNotifications Any Client is Recording - stop that");
StreamService._addRoomClientEnterEventFunc(rcl, roomrecordingName, rcl.getUserip(), false);
_stopRecordingShowForClient(conn, rcl, roomrecordingName, true);
}
}
}
}
}
}
String newRecordFileName = roomRecording.getRoomRecordingsTableString();
String comment = roomRecording.getComment();
Date starttime = roomRecording.getStarttime();
Date endtime = new java.util.Date();
Long duration = endtime.getTime() - starttime.getTime();
roomRecording.setEndtime(endtime);
roomRecording.setEnduser(currentClient);
roomRecording.setRecordname(newRecordFileName);
RoomClient startedClient = roomRecording.getStartedby();
Long recordedby = startedClient.getUser_id();
Users us = null;
if (recordedby!=null && recordedby>0){
us = UsersDaoImpl.getInstance().getUser(recordedby);
}
// //TODO: Replace Persistence Logic with Database-DAO
// XStream xStream = new XStream(new XppDriver());
// xStream.setMode(XStream.NO_REFERENCES);
// String xmlString = xStream.toXML(roomRecording);
//
// //log.error(xmlString);
//
// //make persistent
// Long recording_id = RecordingDaoImpl.getInstance().addRecording(newRecordFileName, duration, "", currentClient.getRoom_id(), us, comment, null);
//
// //save XML to Disk
// IScope scope = Red5.getConnectionLocal().getScope().getParent();
// String current_dir = scope.getResource("upload/").getFile().getAbsolutePath();
// //System.out.println(current_dir + File.separatorChar + this.folderForRecordings);
// File f = new File(current_dir + File.separatorChar + folderForRecordings);
// if (!f.exists()){
// f.mkdir();
// }
// String fileName = f.getAbsolutePath() + File.separatorChar + fileNameXML+recording_id+".xml";
// //System.out.println("fileName"+fileName);
// PrintWriter pw = new PrintWriter(new FileWriter(fileName));
// pw.println(xmlString);
// pw.flush();
// pw.close();
//
// List<LinkedHashMap<String,Object>> roomClients = (List<LinkedHashMap<String,Object>>)roomRecording.get("roomclients");
// for (Iterator<LinkedHashMap<String,Object>> iter = roomClients.iterator();iter.hasNext();){
// LinkedHashMap<String,Object> roomClient = iter.next();
//
// log.debug("###### NEW RRR1: "+roomClient.get("roomenter"));
// log.debug("###### NEW RRR2: "+roomClient.get("startdate"));
// log.debug("###### NEW RRR3: "+roomClient.get("starttime"));
// RoomClient rcl = (RoomClient) roomClient.get("rcl");
// log.debug("###### NEW RRR4: "+rcl.getBroadCastID());
// log.debug("###### NEW RRR5: "+rcl.getConnectedSince());
// log.debug("###### NEW RRR6: "+rcl.getPublicSID());
// log.debug("###### NEW RRR7: "+rcl.getUserip());
//
// }
//remove recording from Temp - List
roomRecordingList.remove(roomrecordingName);
//Store to database
//First Store the RoomRecording
Long roomRecordingId = RoomRecordingDaoImpl.getInstance().addRoomRecording(roomRecording);
RoomRecording roomRecordingRemote = RoomRecordingDaoImpl.getInstance().getRoomRecordingById(roomRecordingId);
//Store all RoomRecordingClients
for (Iterator<RecordingClient> iter = roomRecording.getRoomClients().iterator();iter.hasNext();) {
RecordingClient recordingClient = iter.next();
recordingClient.setRoomRecordingId(roomRecordingId);