Skip to content

Commit 71a3bc5

Browse files
committed
FEC-5936: support latest player version
1 parent 3331240 commit 71a3bc5

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

app/js/controllers/EditCtrl.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ KMCMenu.controller('EditCtrl', ['$scope','$http', '$timeout','PlayerData','Playe
1111
$scope.aspectRatio = playerRatio == (9/16) ? "wide" : playerRatio == (3/4) ? "narrow" : "custom"; // set aspect ratio to wide screen
1212
$scope.newPlayer = !$routeParams.id; // New player flag
1313
$scope.menuOpen = true;
14+
if (typeof $scope.playerData["autoUpdate"] === "undefined") { // new players will have autoUpdate set to true. Old players will not have autoUpdate defined so we derive from html5url
15+
$scope.playerData["autoUpdate"] = $scope.playerData.html5Url.indexOf("{latest}") !== -1;
16+
}
1417
// auto preview flag
1518
$scope.autoPreview = localStorageService.get('autoPreview') ? localStorageService.get('autoPreview')=='true' : false;
1619
$scope.simulateMobile = false;
@@ -325,6 +328,10 @@ KMCMenu.controller('EditCtrl', ['$scope','$http', '$timeout','PlayerData','Playe
325328
kdp.setKDPAttribute(obj, prop, property.initvalue);
326329
return;
327330
}
331+
if (property.model === "autoUpdate"){ // handle auto-update checkbox
332+
$scope.playerData["autoUpdate"] = property.initvalue;
333+
return;
334+
}
328335
$scope.dataChanged = true;
329336
window.parent.studioDataChanged = true; // used when navigating away from studio
330337
$scope.validate(property);

app/js/controllers/playerListCtrl.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ angular.module('KMCModule').controller('PlayerListCtrl',
99
requestNotificationChannel.requestStarted('list');
1010
$rootScope.lang = 'en-US';
1111

12+
var getHTML5Version = function(path){
13+
var version = "";
14+
if (path.indexOf("{latest}") !== -1){
15+
version = "latest";
16+
}else{
17+
version = path.substring(path.lastIndexOf('/v')+2, path.indexOf('/mwEmbedLoader.php'));
18+
}
19+
return version;
20+
}
1221
// init search
1322
$scope.search = '';
1423
$scope.searchSelect2Options = {};
@@ -122,19 +131,19 @@ angular.module('KMCModule').controller('PlayerListCtrl',
122131
};
123132
// check if this player is a v2 player that can be upgraded to a new version
124133
$scope.checkV2Upgrade = function(item) {
125-
var html5libVersion = item.html5Url.substring(item.html5Url.indexOf('/v')+2, item.html5Url.indexOf('/mwEmbedLoader.php')); // get html5 lib version from its URL
126-
return !$scope.checkVersionNeedsUpgrade(item) && window.MWEMBED_VERSION !== html5libVersion;
134+
var html5libVersion = getHTML5Version(item.html5Url); // get html5 lib version from its URL
135+
return !$scope.checkVersionNeedsUpgrade(item) && window.MWEMBED_VERSION !== html5libVersion && html5libVersion !== "latest";
127136
};
128137

129138
// check if this player should be upgraded (binded to the player's HTML outdated message)
130139
$scope.checkVersionNeedsUpgrade = function(item) {
131-
var html5libVersion = item.html5Url.substr(item.html5Url.indexOf('/v') + 2, 1); // get html5 lib version number from its URL
140+
var html5libVersion = getHTML5Version(item.html5Url)[0]; // get html5 lib version number from its URL
132141
return ((html5libVersion == "1") ); // need to upgrade if the version is lower than 2 or the player doesn't have a config object
133142
};
134143

135144
// check if this player is an old playlist
136145
$scope.checkOldPlaylistPlayer = function(item) {
137-
var html5libVersion = item.html5Url.substr(item.html5Url.indexOf('/v') + 2, 1); // get html5 lib version number from its URL
146+
var html5libVersion = getHTML5Version(item.html5Url)[0]; // get html5 lib version number from its URL
138147
return ((html5libVersion == "1") && item.tags.indexOf("playlist") !== -1); // this player is an old playlist that is not supported in Universal studio
139148
};
140149

@@ -278,15 +287,15 @@ angular.module('KMCModule').controller('PlayerListCtrl',
278287
// upgrade a V2 player to the latest version
279288
$scope.upgrade = function(player){
280289
var upgradeProccess = $q.defer();
281-
var html5libVersion = player.html5Url.substring(player.html5Url.indexOf('/v')+2, player.html5Url.indexOf('/mwEmbedLoader.php'));
290+
var html5libVersion = getHTML5Version(player.html5Url);
282291
var currentVersion = window.MWEMBED_VERSION;
283292
var msg = 'This will update the player "' + player.name + '" (ID: ' + player.id + ').';
284293
msg+='<br>Current player version: ' + html5libVersion;
285294
msg+='<br>Update to version: ' + currentVersion + '<a href="https://github.com/kaltura/mwEmbed/releases/tag/v'+currentVersion+'" target="_blank"> (release notes)</a>';
286295
var modal = utilsSvc.confirm('Updating confirmation', msg, 'Update');
287296
modal.result.then(function(result) {
288297
if (result) {
289-
var html5lib = player.html5Url.substr(0, player.html5Url.indexOf('/v') + 2) + window.MWEMBED_VERSION + "/mwEmbedLoader.php";
298+
var html5lib = player.html5Url.substr(0, player.html5Url.lastIndexOf('/v') + 2) + window.MWEMBED_VERSION + "/mwEmbedLoader.php";
290299
PlayerService.playerUpgrade(player, html5lib).then(function(data) {
291300
// update local data (we will not retrieve from the server again)
292301
player.html5Url = html5lib;
@@ -316,7 +325,7 @@ angular.module('KMCModule').controller('PlayerListCtrl',
316325
if (isPlaylist){
317326
text+="<br><span><b>Note:</b> Playlist configuration will not be updated.<br>Please re-configure your playlist plugin after this upgrade.</span>";
318327
}
319-
var html5lib = player.html5Url.substr(0, player.html5Url.indexOf('/v') + 2) + window.MWEMBED_VERSION + "/mwEmbedLoader.php";
328+
var html5lib = player.html5Url.substr(0, player.html5Url.lastIndexOf('/v') + 2) + window.MWEMBED_VERSION + "/mwEmbedLoader.php";
320329
var modal = utilsSvc.confirm('Upgrade confirmation',text, 'Upgrade');
321330
modal.result.then(function(result) {
322331
if (result)

app/js/services/services.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ KMCServices.factory('PlayerService', ['$http', '$modal', '$log', '$q', 'apiServi
309309
apiService.setCache(false); // disable cache before this request to prevent fetching last created player from cache
310310
apiService.doRequest(request).then(function(data) {
311311
var playerData = $.isArray(data) ? data[1] : data; // when using kmc.vars.default_kdp.id we get an array because of the multi request
312+
playerData["autoUpdate"] = true; // new players always auto-update
312313
playersService.setCurrentPlayer(playerData);
313314
apiService.setCache(true); // restore cache usage
314315
localStorageService.set('tempPlayerID', playerData.id);
@@ -487,7 +488,11 @@ KMCServices.factory('PlayerService', ['$http', '$modal', '$log', '$q', 'apiServi
487488
};
488489
// update the player version to the latest version when using production players
489490
if (data.html5Url.indexOf("/html5/html5lib/") === 0){
490-
request['uiConf:html5Url'] = "/html5/html5lib/v" + window.MWEMBED_VERSION + '/mwEmbedLoader.php';
491+
if (data.autoUpdate){
492+
request['uiConf:html5Url'] = "/html5/html5lib/{latest}/mwEmbedLoader.php";
493+
}else {
494+
request['uiConf:html5Url'] = "/html5/html5lib/v" + window.MWEMBED_VERSION + "/mwEmbedLoader.php";
495+
}
491496
}
492497
apiService.doRequest(request).then(function(result) {
493498
playersCache[data.id] = data; // update player data in players cache

0 commit comments

Comments
 (0)