-
Notifications
You must be signed in to change notification settings - Fork 175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
plat 24912:Add support in V2 to V7 redirect #12849
base: Tucana-20.18.0
Are you sure you want to change the base?
Changes from 45 commits
1ba5350
6141087
106a9f3
231426a
93f13ad
fa1f089
7564a5b
ccc7228
9996a86
9cd4d19
937fae0
45a92c5
0a98ae3
0b1ca2e
4d1a6d5
898c528
ae2f00e
633d309
9852f8f
b09fb6a
b6fe8aa
4c8a141
2311910
ca9d5fb
cbe60d5
ee90983
9e47b43
d4f445c
90a5ed5
fe816fc
113c90f
85a162e
e390270
828e634
cf2b074
9701834
10b8ed0
ea8a811
9f531f3
0e2dd0c
2f71403
8c3e554
8e3ba57
c8163d3
57ae9c3
dece8da
57a8226
921e06d
877573a
7e6093b
664e877
d9c6ae8
9bc7125
aaff267
fc70507
0afe31d
98a1e53
8fc005e
e0722aa
e532074
345cf6f
7125ad6
d1df7b5
ecb9813
7da53ac
c016c3c
320a53b
5cd239d
b20566d
7e6270e
8363fa9
0d45b6c
1a1e045
0f074f0
e9e85b3
f4b0f36
60b74b3
5a0fb6e
71ed3e0
92ef0b7
6d65a70
f15055c
7f2f12c
a6c457e
5c54398
e67475a
e66cff4
e6aee33
0535a09
5b56b26
be6ceed
36c2789
6ac5fc1
a2afa61
398d5ce
97d0906
f4d027a
6e72686
6fe8a38
5e1d436
014f75f
41f9952
1c9f97c
69a72d3
8950a45
dd564fc
905353e
573e049
62b010b
3aa0c0c
87d3e60
cc7ba7e
76cef4a
10f993a
3d43ea0
b1d3e78
b85cd4c
ab7ebc4
5e5d8b8
490fd66
dbe1517
8fd9b40
55e51b4
5d19c66
b21d86b
b3850e5
27c2322
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
<?php | ||
|
||
class v2Tov7Utils | ||
{ | ||
const V2TOV7_PARAM_NAME = 'v2tov7'; | ||
const FLASHVARS_PARAM_NAME = 'flashvars'; | ||
const SHOULD_TRANSLATE_PLUGINS = self::V2TOV7_PARAM_NAME ."translate"; | ||
|
||
static private function getV7PluginInfo($v2PluginName): array | ||
{ | ||
KalturaLog::log("Searching for " . $v2PluginName . " " . strlen($v2PluginName)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do you need to print strlen here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed entire print message - needed only for debug |
||
$translation = self::v2toV7PluginMap(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not simply save the map as a static member of the class instead of doing a function call here? If this could change you can even move it toa config (ini) file and load it using kConf to be able to change it without the need of pushing code changes for it. |
||
if(isset($translation[$v2PluginName])) | ||
{ | ||
$v7PluginInfo = $translation[$v2PluginName]; | ||
KalturaLog::log("Found " . print_r($v7PluginInfo, true)); | ||
return $v7PluginInfo; | ||
} | ||
else | ||
{ | ||
throw new Exception ($v2PluginName); | ||
} | ||
} | ||
|
||
static function addV2toV7plugins($flashvars, &$bundleConfig, &$playerConfig) | ||
{ | ||
if(!$flashvars) | ||
{ | ||
return; | ||
} | ||
$unHandledPlugins = array(); | ||
|
||
//Merge v7 config | ||
foreach ($flashvars as $key => $value) | ||
{ | ||
if(self::isVarPlugin($key)) | ||
{ | ||
//get plugin name | ||
KalturaLog::log("V2 to V7 adding plugin: " . $key. " value:" . $value); | ||
if ($value) { | ||
if (!$bundleConfig) { | ||
$bundleConfig = []; | ||
} | ||
$key = trim(trim($key, '"'), "'"); | ||
$v2PluginName = explode(".", $key); | ||
try | ||
{ | ||
$v7PluginName = self::getV7PluginInfo($v2PluginName[0]); | ||
$bundleConfig = array_merge($bundleConfig, [$v7PluginName[0] => "{latest}"]); | ||
$v7PluginConfig = $v7PluginName[1]; | ||
if (!isset($playerConfig->plugins)) { | ||
$playerConfig->plugins = new stdClass(); | ||
} | ||
if (!isset($playerConfig->plugins->$v7PluginConfig)) { | ||
$playerConfig->plugins->$v7PluginConfig = new stdClass(); | ||
} | ||
} | ||
catch (Exception $e){ | ||
$unHandledPlugins[] = $e->getMessage(); | ||
} | ||
} | ||
} | ||
} | ||
if(sizeof($unHandledPlugins)) | ||
{ | ||
throw new Exception ("Unhandled plugins: " . implode(", ", $unHandledPlugins)); | ||
} | ||
} | ||
|
||
static function addV2toV7config($flashvars, $uiconfId) | ||
{ | ||
$config = []; | ||
//Merge v7 config | ||
|
||
if($flashvars) | ||
{ foreach ($flashvars as $key => $value) { | ||
$key = trim(trim($key, '"'), "'"); | ||
$config[$key] = json_decode($value); | ||
} | ||
} | ||
$config["uiconf_id"] = $uiconfId; | ||
return $config; | ||
} | ||
|
||
private static function isVarPlugin($varKeyName) | ||
{ | ||
return str_contains($varKeyName, ".plugin"); | ||
} | ||
|
||
private static function v2toV7PluginMap() | ||
{ | ||
return | ||
["info" => ["playkitscreen", "playkit-js-info"], | ||
"quiz" => ["playkit-ivq", "ivq"], | ||
"moderation" => ["playkit-moderation", "playkit-js-moderation"], | ||
"playlistAPI" => ["playkit-playlist", "playlist"], | ||
"liveStatus" => ["playkit-kaltura-live","kaltura-live"], | ||
"related" => ["playkit-related", "related"], | ||
"dualScreen" => ["playkit-dual-screen", "dualscreen"], | ||
"video360" => ["playkit-vr" ,"vr"], | ||
"raptMedia" => ["rapt", "rapt"], | ||
"transcript" => ["playkit-transcript", "playkit-js-transcript"], | ||
"qna" => ["playkit-qna", "qna"], | ||
"bumper" => [ "playkit-bumper" , "bumper" ], | ||
"infoScreen" => ["playkit-info", "playkit-js-info"]]; | ||
} | ||
|
||
public static function getBundledFacade() | ||
{ | ||
//build key based on version | ||
$facadeVersion = kConf::getArrayValue('v2tov7FacadeVersion','playkit-js'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where is the config for v2tov7FacadeVersion do you have another PR for it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to go to local.ini |
||
$facadeVersion .= "/v2tov7Facade.js"; | ||
|
||
//try get value from local memcache | ||
$cacheStore = kCacheManager::getSingleLayerCache(kCacheManager::CACHE_TYPE_PLAYKIT_JS); | ||
$bundledFacade = $cacheStore->get($facadeVersion); | ||
if(strlen($bundledFacade)) | ||
{ | ||
return $bundledFacade; | ||
} | ||
|
||
//if not local - get it from remote location | ||
$remoteUrl = kConf::getArrayValue('v2tov7FacadeRemoteUrl','playkit-js'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where is the config for v2tov7FacadeRemoteUrl do you have another PR for it? |
||
$remoteUrl .= '/' . $facadeVersion; | ||
|
||
$curlWrapper = new KCurlWrapper(); | ||
|
||
$content = $curlWrapper->exec($remoteUrl,null, null, true); | ||
if(KCurlHeaderResponse::isError($curlWrapper->getHttpCode())) | ||
{ | ||
throw new Exception ('Cannot find V2 to V7 facade in the following URL: ' . $remoteUrl . "Error code:" . $curlWrapper->getHttpCode()); | ||
} | ||
|
||
//store in local cache for next time | ||
$cacheStore->set($facadeVersion,$content); | ||
return $content; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,7 +47,6 @@ public function execute() | |
|
||
$ui_conf_html5_url = $uiConf->getHtml5Url(); | ||
|
||
|
||
if (array_key_exists($partner_id, $optimizedPlayback)) | ||
{ | ||
// force a specific kdp for the partner | ||
|
@@ -61,6 +60,14 @@ public function execute() | |
$autoEmbed = $this->getRequestParameter('autoembed'); | ||
|
||
$iframeEmbed = $this->getRequestParameter('iframeembed'); | ||
|
||
//redirect the call to V7 | ||
if($uiConf->getV2tov7id() && ($this->getRequestParameter(v2Tov7Utils::V2TOV7_PARAM_NAME) || $uiConf->getV2tov7Approved()) ) | ||
{ | ||
$this->redirectToV7($uiConf->getV2tov7id(), $uiconf_id, $partner_id, $uiConf->getV2tov7ShouldTranslatePlugins() ); | ||
} | ||
|
||
|
||
$scriptName = ($iframeEmbed) ? 'mwEmbedFrame.php' : 'mwEmbedLoader.php'; | ||
if($ui_conf_html5_url && $iframeEmbed) { | ||
$ui_conf_html5_url = str_replace('mwEmbedLoader.php', 'mwEmbedFrame.php', $ui_conf_html5_url); | ||
|
@@ -143,4 +150,44 @@ public function execute() | |
header("Location:$url"); | ||
KExternalErrors::dieGracefully(); | ||
} | ||
|
||
/* | ||
* v2 - https://cdnapisec.kaltura.com/p/1915851/sp/191585100/embedIframeJs/uiconf_id/32880931/partner_id/1915851?iframeembed=true&playerId=kaltura_player_1719900446&entry_id=1_aeg07vpv | ||
* v7 - https://cdnapisec.kaltura.com/p/1915851/embedPlaykitJs/uiconf_id/54813242?iframeembed=true&entry_id=1_aeg07vpv | ||
*/ | ||
private function redirectToV7($v7Id, $v2UiConfId, $partnerId, $shouldTranslatePlugins) : void | ||
{ | ||
//validate all the params are handled | ||
try | ||
{ | ||
$config = array(); | ||
$config['bundleConfig'] = null; | ||
$config['playerConfig'] = new stdClass(); | ||
v2Tov7Utils::addV2toV7config($this->getRequestParameter(v2Tov7Utils::FLASHVARS_PARAM_NAME),$v7Id); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are you calling this if you're not using the return value? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it throws here it will be catched and redirect will be avoided. |
||
if($shouldTranslatePlugins) | ||
{ | ||
v2Tov7Utils::addV2toV7plugins( | ||
$this->getRequestParameter(v2Tov7Utils::FLASHVARS_PARAM_NAME), | ||
$config['bundleConfig'], | ||
$config['playerConfig']); | ||
} | ||
//validate that the facade is reachable | ||
v2Tov7Utils::getBundledFacade(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why call this if you're not using the return value? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am checking here all parts that are essential to the redirect - a. translate plugins. b. add falsh vars. c. get facade, if one of them fails, then redirect will not happen |
||
} | ||
catch(Exception $e) | ||
{ | ||
//if we failed, then should not redirect! | ||
KalturaLog::log('V2toV7 was rejected because: ' . $e->getMessage() . ' v2 id:' . $v2UiConfId. ' v7 id:' . $v2UiConfId); | ||
return; | ||
} | ||
|
||
$shouldTranslatePluginsQueryParam = $shouldTranslatePlugins ? '&' . v2Tov7Utils::SHOULD_TRANSLATE_PLUGINS . '=true' : '' ; | ||
$host = myPartnerUtils::getCdnHost($partnerId, null , 'api'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. replace with internal API URL for the machines that served embedPlaykitJs Action |
||
$url = $host . '/p/' . $partnerId . '/embedPlaykitJs/uiconf_id/' . $v7Id . '?' | ||
. $_SERVER['QUERY_STRING'] . "&" | ||
. v2Tov7Utils::V2TOV7_PARAM_NAME .'=true' | ||
. $shouldTranslatePluginsQueryParam; | ||
header("Location:$url"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the reason for returning redirect here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Per our original design the redirect needs to be catched by the proxy gw |
||
KExternalErrors::dieGracefully(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
<?php | ||
|
||
/** | ||
* @package Core | ||
* @subpackage externalWidgets | ||
|
@@ -68,6 +67,11 @@ public function execute() | |
|
||
$lastModified = $this->getLastModified($bundleContent); | ||
|
||
if($this->getRequestParameter(v2Tov7Utils::V2TOV7_PARAM_NAME)) | ||
{ | ||
$bundleContent .= PHP_EOL . v2Tov7Utils::getBundledFacade(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You ar not checking the exception that might be thrown from getBundledFacade is this intended? |
||
} | ||
|
||
//Format bundle content | ||
$bundleContent = $this->formatBundleContent($bundleContent, $i18nContent, $extraModulesNames); | ||
|
||
|
@@ -498,23 +502,31 @@ private function getAutoEmbedCode($targetId = null) | |
$config["provider"]->uiConfId = $this->uiconfId; | ||
|
||
$ks = $this->getRequestParameter(self::KS_PARAM_NAME); | ||
|
||
if ($ks) | ||
{ | ||
$config["provider"]->ks = $ks; | ||
} | ||
|
||
$config["targetId"] = $targetId; | ||
|
||
$config = json_encode($config); | ||
if ($config === false) | ||
{ | ||
KExternalErrors::dieError(KExternalErrors::INVALID_PARAMETER, "Invalid config object"); | ||
} | ||
|
||
$v2tov7ConfigJs=''; | ||
if($this->getRequestParameter(v2Tov7Utils::V2TOV7_PARAM_NAME)) | ||
{ | ||
$v2ToV7config = v2Tov7Utils::addV2toV7config($this->getRequestParameter(v2Tov7Utils::FLASHVARS_PARAM_NAME), $this->uiconfId); | ||
$v2tov7ConfigJs = 'var v2toV7Config = window.v2tov7_buildConfigFromFlashvars(' . JSON_encode($v2ToV7config) . '); | ||
config = {...config,...v2toV7Config};'; | ||
} | ||
|
||
$autoEmbedCode = " | ||
try { | ||
var kalturaPlayer = KalturaPlayer.setup($config); | ||
var config=$config; | ||
$v2tov7ConfigJs | ||
var kalturaPlayer = KalturaPlayer.setup(config); | ||
$loadContentMethod | ||
} catch (e) { | ||
console.error(e.message); | ||
|
@@ -543,7 +555,7 @@ private function getIfarmEmbedCode($bundleContent) | |
</head > | ||
<body > | ||
<div id="player_container"></div> | ||
<script type = "text/javascript" > window.originalRequestReferrer = "' . $_SERVER['HTTP_REFERER'] . '"</script > | ||
<script type = "text/javascript" > window.originalRequestReferrer = "' . @$_SERVER['HTTP_REFERER'] . '"</script > | ||
<script type = "text/javascript" > ' . $bundleContent . '</script > | ||
</body > | ||
</html >'; | ||
|
@@ -576,6 +588,7 @@ private function mergeVersionsParamIntoConfig() | |
if (!$this->bundleConfig) { | ||
$this->bundleConfig = array(); | ||
} | ||
KalturaLog::log("versionsArr" . print_r($versionsArr,true)); | ||
$this->bundleConfig = array_merge($this->bundleConfig, $versionsArr); | ||
} | ||
} | ||
|
@@ -813,6 +826,15 @@ private function initMembers() | |
} | ||
|
||
$this->mergeVersionsParamIntoConfig(); | ||
|
||
if($this->getRequestParameter(v2Tov7Utils::V2TOV7_PARAM_NAME) && $this->getRequestParameter(v2Tov7Utils::SHOULD_TRANSLATE_PLUGINS)) | ||
{ | ||
v2Tov7Utils::addV2toV7plugins( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can throw exceptions, don't you need to handle it gracefully? |
||
$this->getRequestParameter(v2Tov7Utils::FLASHVARS_PARAM_NAME), | ||
$this->bundleConfig, | ||
$this->playerConfig); | ||
} | ||
|
||
if (!$this->bundleConfig) { | ||
KExternalErrors::dieError(KExternalErrors::MISSING_PARAMETER, "unable to resolve bundle config"); | ||
} | ||
|
@@ -822,6 +844,8 @@ private function initMembers() | |
$this->setBundleName(); | ||
} | ||
|
||
|
||
|
||
private function setBundleName() | ||
{ | ||
//sort bundle config by key | ||
|
@@ -843,5 +867,4 @@ public function getRequestParameter($name, $default = null) | |
$returnValue = parent::getRequestParameter($name, $default); | ||
return $returnValue ? $returnValue : $default; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,8 +113,12 @@ class uiConf extends BaseuiConf implements ISyncableFile, IRelatedObject | |
|
||
const CUSTOM_DATA_CON_FILE_VERSION = 'conf_file_version'; | ||
const CUSTOM_DATA_CONF_FILE_FEATURES_VERSION = 'conf_file_features_version'; | ||
|
||
public function save(PropelPDO $con = null) | ||
|
||
const CUSTOM_DATA_V2V7_ID = "v2v7_id"; | ||
const CUSTOM_DATA_V2V7_APPROVED = "v2v7_approved"; | ||
const CUSTOM_DATA_V2V7_TRANSLATE_PLUGINS = "v2v7_translate_plugins"; | ||
|
||
public function save(PropelPDO $con = null) | ||
{ | ||
try | ||
{ | ||
|
@@ -809,4 +813,32 @@ public function setVersion($v, $subType = self::FILE_SYNC_UICONF_SUB_TYPE_CONFIG | |
|
||
return parent::setVersion($v); | ||
} | ||
|
||
//v2 to v7 | ||
public function getV2tov7id() | ||
{ | ||
return $this->getFromCustomData(self::CUSTOM_DATA_V2V7_ID, null, null); | ||
} | ||
public function setV2tov7id($v) | ||
{ | ||
return $this->putInCustomData(self::CUSTOM_DATA_V2V7_ID, $v); | ||
} | ||
public function getV2tov7Approved() | ||
{ | ||
$val = $this->getFromCustomData(self::CUSTOM_DATA_V2V7_APPROVED, null, false, null); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the 4th param here? getFromCustomData get 3 params? |
||
return ($val === 1 || $val === true || $val === "true"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are you doing this instead of simply doing Same comment applies to "getV2tov7ShouldTranslatePlugins" |
||
} | ||
public function setV2tov7Approved($v) | ||
{ | ||
return $this->putInCustomData(self::CUSTOM_DATA_V2V7_APPROVED, $v); | ||
} | ||
public function getV2tov7ShouldTranslatePlugins() | ||
{ | ||
$val = $this->getFromCustomData(self::CUSTOM_DATA_V2V7_TRANSLATE_PLUGINS, null, false, null); | ||
return ($val === 1 || $val === true || $val === "true"); | ||
} | ||
public function setV2tov7ShouldTranslatePlugins($v) | ||
{ | ||
return $this->putInCustomData( self::CUSTOM_DATA_V2V7_TRANSLATE_PLUGINS, $v ); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -155,8 +155,24 @@ class KalturaUiConf extends KalturaObject implements IFilterable | |
* @filter mlikeor, mlikeand | ||
*/ | ||
public $partnerTags; | ||
|
||
|
||
|
||
MosheMaorKaltura marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** | ||
* @var string | ||
*/ | ||
public $v2tov7id; | ||
|
||
/** | ||
* @var string | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why isn't this bool? |
||
*/ | ||
public $v2tov7Approved; | ||
|
||
/** | ||
* @var string | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why isn't this bool? |
||
*/ | ||
public $v2tov7ShouldTranslatePlugins; | ||
|
||
|
||
private static $map_between_objects = array | ||
( | ||
"id" , | ||
|
@@ -181,8 +197,11 @@ class KalturaUiConf extends KalturaObject implements IFilterable | |
"updatedAt", | ||
"html5Url", | ||
"config", | ||
"version", | ||
"version", | ||
"partnerTags", | ||
"v2tov7id", | ||
"v2tov7Approved", | ||
"v2tov7ShouldTranslatePlugins" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to validate that those values are set only on V2 UCONF, and validate the each param comes after the ID |
||
); | ||
|
||
public function getMapBetweenObjects ( ) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really like all these v2tov7. why not have something more intuitive v7CompatibleId or something similar