Skip to content

Commit

Permalink
Orion-15.2.0-PLAT-9936 zoom chat file support
Browse files Browse the repository at this point in the history
Also, include a change to ignore the owner if you get it from participant
  • Loading branch information
ZurPHP committed Jul 11, 2019
1 parent c515481 commit 7698bf6
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 22 deletions.
13 changes: 11 additions & 2 deletions plugins/content/attachment/services/AttachmentAssetService.php
Expand Up @@ -9,6 +9,8 @@
*/
class AttachmentAssetService extends KalturaAssetService
{
const MAX_FILE_NAME_LENGTH = 255;

public function initService($serviceId, $serviceName, $actionName)
{
parent::initService($serviceId, $serviceName, $actionName);
Expand Down Expand Up @@ -213,14 +215,21 @@ protected function attachFile(AttachmentAsset $attachmentAsset, $fullPath, $copy
$attachmentAsset->setStatus(AttachmentAsset::ASSET_STATUS_READY);
$attachmentAsset->save();
}

/**
* @param AttachmentAsset $attachmentAsset
* @param string $url
* @throws KalturaAPIException
*/
protected function attachUrl(AttachmentAsset $attachmentAsset, $url)
{
$fullPath = myContentStorage::getFSUploadsPath() . '/' . basename($url);
$fileName = basename($url);
if(strlen($fileName) > self::MAX_FILE_NAME_LENGTH)
{
$fileName = md5($url);
}

$fullPath = myContentStorage::getFSUploadsPath() . '/' . $fileName;
if (KCurlWrapper::getDataFromFile($url, $fullPath))
return $this->attachFile($attachmentAsset, $fullPath);

Expand Down
3 changes: 3 additions & 0 deletions plugins/vendor/lib/model/enums/kVendorErrorMessages.php
Expand Up @@ -15,4 +15,7 @@ interface kVendorErrorMessages extends BaseEnum
const TOKEN_PARSING_FAILED = 'Parse Tokens failed, response received from zoom is: ';
const FAILED_VERIFICATION = 'ZOOM - verification token is different from existing token';
const MISSING_ENTRY_FOR_ZOOM_MEETING = 'Could not find entry for meeting id: ';
const MISSING_ENTRY_FOR_CHAT = 'Missing entry for the chat file';
const ERROR_HANDLING_CHAT = 'Error while trying to handle chat file';
const ERROR_HANDLING_TRANSCRIPT = 'Error while trying to handle transcript file';
}
109 changes: 89 additions & 20 deletions plugins/vendor/lib/model/zoom/kZoomEngine.php
Expand Up @@ -14,6 +14,7 @@ class kZoomEngine

protected static $FILE_VIDEO_TYPES = array('MP4');
protected static $FILE_CAPTION_TYPES = array('TRANSCRIPT');
protected static $FILE_CHAT_TYPES = array('CHAT');
protected $zoomConfiguration;
protected $zoomClient;

Expand Down Expand Up @@ -77,7 +78,7 @@ protected function handleRecordingTranscriptComplete($event)
$zoomIntegration = ZoomHelper::getZoomIntegration();
$dbUser = $this->getEntryOwner($transcript->hostEmail, $zoomIntegration);
$this->initUserPermissions($dbUser);
$entry = $this->getZoomEntryByReferenceId($transcript->id);
$entry = $this->getZoomEntryByMeetingId($transcript->id);
$this->initUserPermissions($dbUser, true);
$captionAssetService = new CaptionAssetService();
$captionAssetService->initService('caption_captionasset', 'captionAsset', 'setContent');
Expand All @@ -90,14 +91,21 @@ protected function handleRecordingTranscriptComplete($event)
continue;
}

$captionAsset = $this->createAssetForTranscription($entry);
$captionAssetResource = new KalturaUrlResource();
$captionAssetResource->url = $recordingFile->download_url . self::URL_ACCESS_TOKEN . $event->downloadToken;
$captionAssetService->setContentAction($captionAsset->getId(), $captionAssetResource);
try
{
$captionAsset = $this->createAssetForTranscription($entry);
$captionAssetResource = new KalturaUrlResource();
$captionAssetResource->url = $recordingFile->download_url . self::URL_ACCESS_TOKEN . $event->downloadToken;
$captionAssetService->setContentAction($captionAsset->getId(), $captionAssetResource);
}
catch (Exception $e)
{
ZoomHelper::exitWithError(kVendorErrorMessages::ERROR_HANDLING_TRANSCRIPT);
}
}
}

protected function getZoomEntryByReferenceId($meetingId)
protected function getZoomEntryByMeetingId($meetingId)
{
$entryFilter = new entryFilter();
$pager = new KalturaFilterPager();
Expand All @@ -112,7 +120,7 @@ protected function getZoomEntryByReferenceId($meetingId)
entryPeer::setFilterResults(true);
}

!$entry = entryPeer::doSelectOne($c);
$entry = entryPeer::doSelectOne($c);
if(!$entry)
{
ZoomHelper::exitWithError(kVendorErrorMessages::MISSING_ENTRY_FOR_ZOOM_MEETING . $meetingId);
Expand All @@ -132,25 +140,66 @@ protected function handleRecordingVideoComplete($event)
$meeting = $event->object;
$dbUser = $this->getEntryOwner($meeting->hostEmail, $zoomIntegration);
$this->initUserPermissions($dbUser);
$participantsUsersNames = $this->extractMeetingParticipants($meeting->id, $zoomIntegration);
$participantsUsersNames = $this->extractMeetingParticipants($meeting->id, $zoomIntegration, $dbUser->getPuserId());
$validatedUsers = $this->getValidatedUsers($participantsUsersNames, $zoomIntegration->getPartnerId(), $zoomIntegration->getCreateUserIfNotExist());
$entry = null;
foreach ($meeting->recordingFiles as $recordingFile)
{
/* @var kZoomRecordingFile $recordingFile */
if (in_array ($recordingFile->fileType, self::$FILE_VIDEO_TYPES))
{
$entry = $this->handleVideoRecord($meeting, $dbUser, $zoomIntegration, $validatedUsers, $recordingFile, $event);
}
}

if (!in_array ($recordingFile->fileType, self::$FILE_VIDEO_TYPES))
foreach ($meeting->recordingFiles as $recordingFile)
{
/* @var kZoomRecordingFile $recordingFile */
if (in_array ($recordingFile->fileType, self::$FILE_CHAT_TYPES))
{
continue;
$this->handleChatRecord($entry, $meeting, $recordingFile->download_url, $event->downloadToken, $dbUser);
}
}
}

$entry = $this->createEntryFromMeeting($meeting, $dbUser);
$this->setEntryCategory($zoomIntegration, $entry);
$this->handleParticipants($entry, $validatedUsers, $zoomIntegration);
$entry->save();
$url = $recordingFile->download_url . self::URL_ACCESS_TOKEN . $event->downloadToken;
kJobsManager::addImportJob(null, $entry->getId(), $entry->getPartnerId(), $url);
/**
* @param entry $entry
* @param kZoomMeeting $meeting
* @param string $chatDownloadUrl
* @param string $downloadToken
* @param kuser $dbUser
*/
protected function handleChatRecord($entry, $meeting, $chatDownloadUrl, $downloadToken, $dbUser)
{
if(!$entry)
{
ZoomHelper::exitWithError(kVendorErrorMessages::MISSING_ENTRY_FOR_CHAT);
}
try
{
$attachmentAsset = $this->createAttachmentAssetForChatFile($meeting->id, $entry);
$attachmentAssetResource = new KalturaUrlResource();
$attachmentAssetResource->url = $chatDownloadUrl . self::URL_ACCESS_TOKEN . $downloadToken;
$this->initUserPermissions($dbUser, true);
$attachmentAssetService = new AttachmentAssetService();
$attachmentAssetService->initService('attachment_attachmentasset', 'attachmentAsset', 'setContent');
$attachmentAssetService->setContentAction($attachmentAsset->getId(), $attachmentAssetResource);
}
catch (Exception $e)
{
ZoomHelper::exitWithError(kVendorErrorMessages::ERROR_HANDLING_CHAT);
}
}

protected function handleVideoRecord($meeting, $dbUser, $zoomIntegration, $validatedUsers, $recordingFile, $event)
{
$entry = $this->createEntryFromMeeting($meeting, $dbUser);
$this->setEntryCategory($zoomIntegration, $entry);
$this->handleParticipants($entry, $validatedUsers, $zoomIntegration);
$entry->save();
$url = $recordingFile->download_url . self::URL_ACCESS_TOKEN . $event->downloadToken;
kJobsManager::addImportJob(null, $entry->getId(), $entry->getPartnerId(), $url);
return $entry;
}

/**
Expand Down Expand Up @@ -263,7 +312,7 @@ protected function createEntryFromMeeting($meeting, $owner)
* @param entry $entry
* @return CaptionAsset
*/
public function createAssetForTranscription($entry)
protected function createAssetForTranscription($entry)
{
$caption = new CaptionAsset();
$caption->setEntryId($entry->getId());
Expand All @@ -274,12 +323,28 @@ public function createAssetForTranscription($entry)
return $caption;
}

/**
* @param string $meetingId
* @return AttachmentAsset
*/
protected function createAttachmentAssetForChatFile($meetingId, $entry)
{
$attachment = new AttachmentAsset();
$attachment->setFilename("Meeting {$meetingId} chat file");
$attachment->setPartnerId($entry->getPartnerId());
$attachment->setEntryId($entry->getId());
$attachment->setcontainerFormat(AttachmentType::TEXT);
$attachment->save();
return $attachment;
}

/**
* @param $meetingId
* @param ZoomVendorIntegration $zoomIntegration
* @param $meetingOwnerName
* @return array participants users names
*/
protected function extractMeetingParticipants($meetingId, $zoomIntegration)
protected function extractMeetingParticipants($meetingId, $zoomIntegration, $meetingOwnerName)
{
if ($zoomIntegration->getHandleParticipantsMode() == kHandleParticipantsMode::IGNORE)
{
Expand All @@ -293,10 +358,15 @@ protected function extractMeetingParticipants($meetingId, $zoomIntegration)
$participantsEmails = $participants->getParticipantsEmails();
if($participantsEmails)
{
KalturaLog::info('Found the following participants: ' . implode(", ", $participantsEmails));
$result = array();
foreach ($participantsEmails as $participantEmail)
{
$result[] = $this->matchZoomUserName($participantEmail, $zoomIntegration);
$userName = $this->matchZoomUserName($participantEmail, $zoomIntegration);
if($meetingOwnerName != $userName)
{
$result[] = $userName;
}
}
}
else
Expand Down Expand Up @@ -332,7 +402,6 @@ public function getEntryOwner($hostEmail, $zoomIntegration)
return $dbUser;
}


/**
* @param string $userName
* @param ZoomVendorIntegration $zoomIntegration
Expand Down

0 comments on commit 7698bf6

Please sign in to comment.