-
Notifications
You must be signed in to change notification settings - Fork 4
/
ng-kaltura-player.js
59 lines (50 loc) · 1.79 KB
/
ng-kaltura-player.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
var kalturaDirectivesModule = angular.module('Kaltura.directives', []);
kalturaDirectivesModule.directive('kalturaPlayer', ['$rootScope', function($rootScope) {
return {
restrict: 'E',
template: '<div id="kaltura_player_{{id}}" style="width:{{width}}; height:{{height}}; background-color: black"></div>',
scope: {},
compile: function(element, attributes) {
if (document.getElementById("kalturaLib") === null){
var s = document.createElement('script');
s.src = 'http://cdnapi.kaltura.com/p/'+attributes.pid+'/sp/'+attributes.pid+'00/embedIframeJs/uiconf_id/'+attributes.uiconfid+'/partner_id/'+attributes.pid;
s.id = "kalturaLib";
s.async = false;
document.head.appendChild(s);
}
var linkFunction = function($scope, element, attributes) {
if (attributes.width){
$scope.width = attributes.width;
}
if (attributes.height){
$scope.height = attributes.height;
}
if (attributes.id){
$scope.id = attributes.id;
}
if (!$scope.kdp){
var intervalID = setInterval(function(){
if (typeof window.kWidget !== "undefined"){
clearInterval(intervalID);
var target = attributes.id ? "kaltura_player_"+attributes.id : "kaltura_player_";
var flashvars = attributes.flashvars ? JSON.parse(attributes.flashvars) : {};
window.kWidget.embed({
"targetId": target,
"wid": "_"+attributes.pid,
"uiconf_id": attributes.uiconfid,
"flashvars": flashvars,
"cache_st": Math.random(),
"entry_id": attributes.entryid,
"readyCallback": function(playerID){
$scope.kdp = document.getElementById(playerID);
$rootScope.$broadcast('kalturaPlayerReady', $scope.kdp, attributes.id);
}
});
}
},50);
}
}
return linkFunction;
}
}
}]);