Merge pull request #342 from pedrobmarin/recording-events-improvments

Recording events improvments
This commit is contained in:
Felipe Cecagno 2016-09-29 15:19:50 -03:00 committed by GitHub
commit ab8eb279a0
14 changed files with 110 additions and 18 deletions

View File

@ -58,6 +58,7 @@ with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
<property name="publishedDir" value="${publishedDir}"/>
<property name="unpublishedDir" value="${unpublishedDir}"/>
<property name="recordingServiceHelper" ref="recordingServiceHelper"/>
<property name="messagingService" ref="messagingService"/>
</bean>
<bean id="configServiceHelper" class="org.bigbluebutton.api.ClientConfigServiceHelperImp"/>

View File

@ -445,7 +445,7 @@ public class MeetingService implements MessageListener {
success = recordingService.changeState(id, Recording.STATE_UNPUBLISHED);
}
if (success) {
messagingService.publishRecording(id, publish);
log.debug("Publish recording operation succeeded for meeting {}", id);
}
}
}
@ -454,7 +454,7 @@ public class MeetingService implements MessageListener {
for (String id : idList) {
boolean success = recordingService.changeState(id, Recording.STATE_DELETED);
if (success) {
messagingService.deleteRecording(id);
log.debug("Delete recording operation succeeded for meeting {}", id);
}
}
}

View File

@ -34,6 +34,7 @@ import java.util.Map;
import java.util.Set;
import org.bigbluebutton.api.domain.Recording;
import org.bigbluebutton.api.messaging.MessagingService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -45,6 +46,7 @@ public class RecordingService {
private String unpublishedDir = "/var/bigbluebutton/unpublished";
private String deletedDir = "/var/bigbluebutton/deleted";
private RecordingServiceHelper recordingServiceHelper;
private MessagingService messagingService;
private String recordStatusDir;
public void startIngestAndProcessing(String meetingId) {
@ -339,6 +341,7 @@ public class RecordingService {
deleteRecording(recordingId, deletedDir);
}
recordingServiceHelper.writeRecordingInfo(dest.getAbsolutePath() + File.separatorChar + recordings.get(f).getName(), r);
sendRedisEvent(r.getId(), r.getId(), r.getExternalMeetingId(), format[i], state);
log.debug(String.format("Recording successfully %s!", state));
} else {
log.debug("Recording was not moved");
@ -351,6 +354,19 @@ public class RecordingService {
return anyResult;
}
private void sendRedisEvent(String recordId, String meetingId, String externalMeetingId, String format, String state) {
log.debug("Sending Redis event for meeting {} {}", meetingId, format);
if (state.equals(Recording.STATE_PUBLISHED)) {
messagingService.publishRecording(recordId, meetingId, externalMeetingId, format, true);
} else if (state.equals(Recording.STATE_UNPUBLISHED)) {
messagingService.publishRecording(recordId, meetingId, externalMeetingId, format, false);
} else if (state.equals(Recording.STATE_DELETED)) {
messagingService.deleteRecording(recordId, meetingId, externalMeetingId, format);
} else {
log.debug("No event for {}", state);
}
}
private List<File> getAllDirectories(String state) {
List<File> allDirectories = new ArrayList<File>();
@ -406,4 +422,8 @@ public class RecordingService {
return allDirectories;
}
public void setMessagingService(MessagingService service) {
messagingService = service;
}
}

View File

@ -282,6 +282,18 @@ public class Recording {
return newdate;
}
public String getExternalMeetingId() {
String externalMeetingId = null;
if (this.metadata != null) {
externalMeetingId = this.metadata.get("meetingId");
}
if (externalMeetingId != null) {
return externalMeetingId;
} else {
return "";
}
}
}
/*

View File

@ -94,4 +94,6 @@ public class Constants {
public static final String CREATE_DATE = "create_date";
public static final String GUEST = "guest";
public static final String WAITING_FOR_ACCEPTANCE = "waiting_for_acceptance";
public static final String FORMAT = "format";
public static final String RECORD_ID = "record_id";
}

View File

@ -73,7 +73,10 @@ public class MessageToJson {
public static String publishRecordingMessageToJson(PublishRecordingMessage message) {
HashMap<String, Object> payload = new HashMap<String, Object>();
payload.put(Constants.RECORD_ID, message.recordId);
payload.put(Constants.MEETING_ID, message.meetingId);
payload.put(Constants.EXTERNAL_MEETING_ID, message.externalMeetingId);
payload.put(Constants.FORMAT, message.format);
java.util.HashMap<String, Object> header = MessageBuilder.buildHeader(PublishRecordingMessage.PUBLISH_RECORDING, PublishRecordingMessage.VERSION, null);
return MessageBuilder.buildJson(header, payload);
@ -81,7 +84,10 @@ public class MessageToJson {
public static String unpublishRecordingMessageToJson(UnpublishRecordingMessage message) {
HashMap<String, Object> payload = new HashMap<String, Object>();
payload.put(Constants.RECORD_ID, message.recordId);
payload.put(Constants.MEETING_ID, message.meetingId);
payload.put(Constants.EXTERNAL_MEETING_ID, message.externalMeetingId);
payload.put(Constants.FORMAT, message.format);
java.util.HashMap<String, Object> header = MessageBuilder.buildHeader(UnpublishRecordingMessage.UNPUBLISH_RECORDING, UnpublishRecordingMessage.VERSION, null);
return MessageBuilder.buildJson(header, payload);
@ -89,7 +95,10 @@ public class MessageToJson {
public static String deleteRecordingMessageToJson(DeleteRecordingMessage message) {
HashMap<String, Object> payload = new HashMap<String, Object>();
payload.put(Constants.RECORD_ID, message.recordId);
payload.put(Constants.MEETING_ID, message.meetingId);
payload.put(Constants.EXTERNAL_MEETING_ID, message.externalMeetingId);
payload.put(Constants.FORMAT, message.format);
java.util.HashMap<String, Object> header = MessageBuilder.buildHeader(DeleteRecordingMessage.DELETE_RECORDING, DeleteRecordingMessage.VERSION, null);
return MessageBuilder.buildJson(header, payload);

View File

@ -34,6 +34,6 @@ public interface MessagingService {
void sendPolls(String meetingId, String title, String question, String questionType, List<String> answers);
void registerUser(String meetingID, String internalUserId, String fullname, String role, String externUserID, String authToken, String guest);
void sendKeepAlive(String system, Long timestamp);
void publishRecording(String meetingId, boolean publish);
void deleteRecording(String meetingId);
void publishRecording(String recordId, String meetingId, String externalMeetingId, String format, boolean publish);
void deleteRecording(String recordId, String meetingId, String externalMeetingId, String format);
}

View File

@ -134,28 +134,28 @@ public class RedisMessagingService implements MessagingService {
storeService.removeMeeting(meetingId);
}
private void publishRecording(String meetingId) {
PublishRecordingMessage msg = new PublishRecordingMessage(meetingId);
private void publishRecording(String recordId, String meetingId, String externalMeetingId, String format) {
PublishRecordingMessage msg = new PublishRecordingMessage(recordId, meetingId, externalMeetingId, format);
String json = MessageToJson.publishRecordingMessageToJson(msg);
sender.send(MessagingConstants.FROM_BBB_RECORDING_CHANNEL, json);
}
private void unpublishRecording(String meetingId) {
UnpublishRecordingMessage msg = new UnpublishRecordingMessage(meetingId);
private void unpublishRecording(String recordId, String meetingId, String externalMeetingId, String format) {
UnpublishRecordingMessage msg = new UnpublishRecordingMessage(recordId, meetingId, externalMeetingId, format);
String json = MessageToJson.unpublishRecordingMessageToJson(msg);
sender.send(MessagingConstants.FROM_BBB_RECORDING_CHANNEL, json);
}
public void publishRecording(String meetingId, boolean publish) {
public void publishRecording(String recordId, String meetingId, String externalMeetingId, String format, boolean publish) {
if (publish) {
publishRecording(meetingId);
publishRecording(recordId, meetingId, externalMeetingId, format);
} else {
unpublishRecording(meetingId);
unpublishRecording(recordId, meetingId, externalMeetingId, format);
}
}
public void deleteRecording(String meetingId) {
DeleteRecordingMessage msg = new DeleteRecordingMessage(meetingId);
public void deleteRecording(String recordId, String meetingId, String externalMeetingId, String format) {
DeleteRecordingMessage msg = new DeleteRecordingMessage(recordId, meetingId, externalMeetingId, format);
String json = MessageToJson.deleteRecordingMessageToJson(msg);
sender.send(MessagingConstants.FROM_BBB_RECORDING_CHANNEL, json);
}

View File

@ -4,9 +4,15 @@ public class DeleteRecordingMessage {
public static final String DELETE_RECORDING = "deleted";
public static final String VERSION = "0.0.1";
public final String recordId;
public final String meetingId;
public final String externalMeetingId;
public final String format;
public DeleteRecordingMessage(String meetingId) {
public DeleteRecordingMessage(String recordId, String meetingId, String externalMeetingId, String format) {
this.recordId = recordId;
this.meetingId = meetingId;
this.externalMeetingId = externalMeetingId;
this.format = format;
}
}

View File

@ -4,9 +4,15 @@ public class PublishRecordingMessage {
public static final String PUBLISH_RECORDING = "published";
public static final String VERSION = "0.0.1";
public final String recordId;
public final String meetingId;
public final String externalMeetingId;
public final String format;
public PublishRecordingMessage(String meetingId) {
public PublishRecordingMessage(String recordId, String meetingId, String externalMeetingId, String format) {
this.recordId = recordId;
this.meetingId = meetingId;
this.externalMeetingId = externalMeetingId;
this.format = format;
}
}

View File

@ -4,9 +4,15 @@ public class UnpublishRecordingMessage {
public static final String UNPUBLISH_RECORDING = "unpublished";
public static final String VERSION = "0.0.1";
public final String recordId;
public final String meetingId;
public final String externalMeetingId;
public final String format;
public UnpublishRecordingMessage(String meetingId) {
public UnpublishRecordingMessage(String recordId, String meetingId, String externalMeetingId, String format) {
this.recordId = recordId;
this.meetingId = meetingId;
this.externalMeetingId = externalMeetingId;
this.format = format;
}
}

View File

@ -26,6 +26,10 @@ require 'builder'
require 'yaml'
module BigBlueButton
$bbb_props = YAML::load(File.open('../../core/scripts/bigbluebutton.yml'))
$recording_dir = $bbb_props['recording_dir']
$raw_recording_dir = "#{$recording_dir}/raw"
# Class to wrap Redis so we can mock
# for testing
class RedisWrapper
@ -93,7 +97,15 @@ module BigBlueButton
RECORDINGS_CHANNEL = "bigbluebutton:from-rap"
def put_message(message_type, meeting_id, additional_payload = {})
events_xml = "#{$raw_recording_dir}/#{meeting_id}/events.xml"
if File.exist?(events_xml)
additional_payload.merge!({
"external_meeting_id" => BigBlueButton::Events.get_external_meeting_id(events_xml)
})
end
msg = build_message build_header(message_type), additional_payload.merge({
"record_id" => meeting_id,
"meeting_id" => meeting_id
})
@redis.publish RECORDINGS_CHANNEL, msg.to_json

View File

@ -38,6 +38,15 @@ module BigBlueButton
end
metadata
end
# Get the external meeting id
def self.get_external_meeting_id(events_xml)
BigBlueButton.logger.info("Task: Getting external meeting id")
metadata = get_meeting_metadata(events_xml)
external_meeting_id = {}
external_meeting_id = metadata['meetingId'] if !metadata['meetingId'].nil?
external_meeting_id
end
# Get the timestamp of the first event.
def self.first_event_timestamp(events_xml)

View File

@ -242,13 +242,19 @@ def publish_processed_meeting(recording_dir)
playback = {}
metadata = {}
download = {}
raw_size = {}
start_time = {}
end_time = {}
metadata_xml_path = "#{published_dir}/#{publish_type}/#{meeting_id}/metadata.xml"
if File.exists? metadata_xml_path
begin
doc = Hash.from_xml(File.open(metadata_xml_path))
playback = doc[:recording][:playback] if !doc[:recording][:playback].nil?
metadata = doc[:recording][:metadata] if !doc[:recording][:metadata].nil?
metadata = doc[:recording][:meta] if !doc[:recording][:meta].nil?
download = doc[:recording][:download] if !doc[:recording][:download].nil?
raw_size = doc[:recording][:raw_size] if !doc[:recording][:raw_size].nil?
start_time = doc[:recording][:start_time] if !doc[:recording][:start_time].nil?
end_time = doc[:recording][:end_time] if !doc[:recording][:end_time].nil?
rescue Exception => e
BigBlueButton.logger.warn "An exception occurred while loading the extra information for the publish event"
BigBlueButton.logger.warn e.message
@ -265,7 +271,10 @@ def publish_processed_meeting(recording_dir)
"step_time" => step_time,
"playback" => playback,
"metadata" => metadata,
"download" => download
"download" => download,
"raw_size" => raw_size,
"start_time" => start_time,
"end_time" => end_time
}
if step_succeeded