<commit_before>(function (mw, $, shaka) {
	"use strict";
	shaka.polyfill.installAll();

	if (shaka.Player.isBrowserSupported() &&
		!mw.getConfig("EmbedPlayer.ForceNativeComponent") &&
		!mw.isDesktopSafari() &&
		!mw.isAndroid()) {
		$(mw).bind('EmbedPlayerUpdateMediaPlayers', function (event, mediaPlayers) {
			mw.log("Dash::Register shaka player for application/dash+xml mime type");
			var shakaPlayer = new mw.MediaPlayer('shakaPlayer', ['application/dash+xml'], 'Native');
			mediaPlayers.addPlayer(shakaPlayer);
			mw.EmbedTypes.mediaPlayers.setMIMETypePlayers('application/dash+xml', 'Native');
		});
		var dash = mw.KBasePlugin.extend({

			/** type {boolean} */
			loaded: false,

			/** type {boolean} */
			LoadShaka: false,

			/** type {boolean} */
			manifestLoaded: false,

			destroyPromise: null,

			currentBitrate: null,
			/**
			 * Check is shaka is supported
			 * @returns {boolean}
			 */
			isSafeEnviornment: function () {
				return shaka.Player.isBrowserSupported();
			},
			/**
			 * Setup the shaka playback engine wrapper with supplied config options
			 */
			setup: function () {
				this.addBindings();
			},
			/**
			 *
			 */
			addBindings: function () {
				this.bind("SourceChange", this.isNeeded.bind(this));
				this.bind("playerReady", this.initShaka.bind(this));
				this.bind("switchAudioTrack", this.onSwitchAudioTrack.bind(this));
				this.bind("selectClosedCaptions", this.onSwitchTextTrack.bind(this));
				this.bind("onChangeMedia", this.clean.bind(this));
			},

			/**
			 * Check if Shaka engine is required, e.g. the selected source is dash
			 */
			isNeeded: function () {
				if (this.getPlayer().mediaElement.selectedSource.mimeType === "application/dash+xml") {
					this.LoadShaka = true;
				} else {
					this.LoadShaka = false;
				}
			},

			/**
			 * Register the playback events and attach the playback engine to the video element
			 */
			initShaka: function () {
				if (this.LoadShaka && !this.loaded) {
					this.log("Init shaka version " + shaka.Player.version);

					//Set streamerType to dash
					this.embedPlayer.streamerType = 'mpegdash';

					this.loaded = true;

					//Disable update of video source tag, MSE uses blob urls!
					this.getPlayer().skipUpdateSource = true;
					this.overridePlayerMethods();

					this.setEmbedPlayerConfig(this.getPlayer());

                    if ( this.destroyPromise ) {
						// after change media we should wait till the destroy promise will be resolved
                        this.destroyPromise.then( function () {
                            this.onShakaDestroyEnded();
                            this.createPlayer();
                        }.bind( this ) );
                    } else {
                        this.createPlayer();
                    }
                }
			},

			setEmbedPlayerConfig: function (embedPlayer) {
				//Get user configuration
				var userConfig = embedPlayer.getKalturaConfig("dash");
				//Get default config
				var dashConfig = this.getDefaultDashConfig();
				//Deep extend custom config
				$.extend(true, dashConfig, userConfig);
				embedPlayer.setKalturaConfig("dash", dashConfig);
			},

			getDefaultDashConfig: function () {
				var drmConfig = this.getDrmConfig();
				var defaultConfig = {
					shakaConfig: {
						drm: {
							servers: {
								'com.widevine.alpha': drmConfig.licenseBaseUrl + "/cenc/widevine/license?" + drmConfig.licenseData,
								'com.microsoft.playready': drmConfig.licenseBaseUrl + "/cenc/playready/license?" + drmConfig.licenseData
							}
						}
					}
				};
				if (mw.isChrome()){
					defaultConfig.shakaConfig.advanced = {
						'com.widevine.alpha': {
							'videoRobustness': 'SW_SECURE_CRYPTO',
							'audioRobustness': 'SW_SECURE_CRYPTO'
						}
					};
				}
				return defaultConfig;
			},

			getDrmConfig: function () {
				var licenseBaseUrl = mw.getConfig('Kaltura.UdrmServerURL');
				if (!licenseBaseUrl) {
					this.log('Error:: failed to retrieve UDRM license URL ');
				}

				var licenseData = this.getPlayer().mediaElement.getLicenseUriComponent();
				var drmConfig = {
					licenseBaseUrl: licenseBaseUrl,
					licenseData: licenseData
				};
				return drmConfig;
			},

			createPlayer: function () {
				// Create a Player instance.
				var player = new shaka.Player(this.getPlayer().getPlayerElement());

				player.configure(this.getConfig("shakaConfig"));

				// Attach player to the window to make it easy to access in the JS console.
				window.player = player;

				this.registerShakaEvents();

				var unbindAndLoadManifest = function () {
					this.unbind("firstPlay");
					this.unbind("seeking");
					this.loadManifest();
				}.bind(this);

				this.bind("firstPlay", function () {
					unbindAndLoadManifest();
				});

				this.bind("seeking", function () {
					unbindAndLoadManifest();
				});
			},<commit_msg>Fix VTTCue clash between VTT.js and Shaka(SUP-10832)<commit_after>(function (mw, $, shaka) {
	"use strict";
	shaka.polyfill.installAll();

	if (shaka.Player.isBrowserSupported() &&
		!mw.getConfig("EmbedPlayer.ForceNativeComponent") &&
		!mw.isDesktopSafari() &&
		!mw.isAndroid()) {
		$(mw).bind('EmbedPlayerUpdateMediaPlayers', function (event, mediaPlayers) {
			mw.log("Dash::Register shaka player for application/dash+xml mime type");
			var shakaPlayer = new mw.MediaPlayer('shakaPlayer', ['application/dash+xml'], 'Native');
			mediaPlayers.addPlayer(shakaPlayer);
			mw.EmbedTypes.mediaPlayers.setMIMETypePlayers('application/dash+xml', 'Native');
		});
		var dash = mw.KBasePlugin.extend({

			/** type {boolean} */
			loaded: false,

			/** type {boolean} */
			LoadShaka: false,

			/** type {boolean} */
			manifestLoaded: false,

			destroyPromise: null,

			currentBitrate: null,
			/**
			 * Check is shaka is supported
			 * @returns {boolean}
			 */
			isSafeEnviornment: function () {
				return shaka.Player.isBrowserSupported();
			},
			/**
			 * Setup the shaka playback engine wrapper with supplied config options
			 */
			setup: function () {
				this.addBindings();
			},
			/**
			 *
			 */
			addBindings: function () {
				this.bind("SourceChange", this.isNeeded.bind(this));
				this.bind("playerReady", this.initShaka.bind(this));
				this.bind("switchAudioTrack", this.onSwitchAudioTrack.bind(this));
				this.bind("selectClosedCaptions", this.onSwitchTextTrack.bind(this));
				this.bind("onChangeMedia", this.clean.bind(this));
			},

			/**
			 * Check if Shaka engine is required, e.g. the selected source is dash
			 */
			isNeeded: function () {
				if (this.getPlayer().mediaElement.selectedSource.mimeType === "application/dash+xml") {
					this.LoadShaka = true;
				} else {
					this.LoadShaka = false;
				}
			},

			/**
			 * Register the playback events and attach the playback engine to the video element
			 */
			initShaka: function () {
				if (this.LoadShaka && !this.loaded) {
					this.log("Init shaka version " + shaka.Player.version);

					//Set streamerType to dash
					this.embedPlayer.streamerType = 'mpegdash';

					this.loaded = true;

					//Disable update of video source tag, MSE uses blob urls!
					this.getPlayer().skipUpdateSource = true;
					this.overridePlayerMethods();

					this.setEmbedPlayerConfig(this.getPlayer());

                    if ( this.destroyPromise ) {
						// after change media we should wait till the destroy promise will be resolved
                        this.destroyPromise.then( function () {
                            this.onShakaDestroyEnded();
                            this.createPlayer();
                        }.bind( this ) );
                    } else {
                        this.createPlayer();
                    }
                }
			},

			setEmbedPlayerConfig: function (embedPlayer) {
				//Get user configuration
				var userConfig = embedPlayer.getKalturaConfig("dash");
				//Get default config
				var dashConfig = this.getDefaultDashConfig();
				//Deep extend custom config
				$.extend(true, dashConfig, userConfig);
				embedPlayer.setKalturaConfig("dash", dashConfig);
			},

			getDefaultDashConfig: function () {
				var drmConfig = this.getDrmConfig();
				var defaultConfig = {
					shakaConfig: {
						drm: {
							servers: {
								'com.widevine.alpha': drmConfig.licenseBaseUrl + "/cenc/widevine/license?" + drmConfig.licenseData,
								'com.microsoft.playready': drmConfig.licenseBaseUrl + "/cenc/playready/license?" + drmConfig.licenseData
							}
						}
					}
				};
				if (mw.isChrome()){
					defaultConfig.shakaConfig.advanced = {
						'com.widevine.alpha': {
							'videoRobustness': 'SW_SECURE_CRYPTO',
							'audioRobustness': 'SW_SECURE_CRYPTO'
						}
					};
				}
				return defaultConfig;
			},

			getDrmConfig: function () {
				var licenseBaseUrl = mw.getConfig('Kaltura.UdrmServerURL');
				if (!licenseBaseUrl) {
					this.log('Error:: failed to retrieve UDRM license URL ');
				}

				var licenseData = this.getPlayer().mediaElement.getLicenseUriComponent();
				var drmConfig = {
					licenseBaseUrl: licenseBaseUrl,
					licenseData: licenseData
				};
				return drmConfig;
			},

			createPlayer: function () {
                //Reinstall the polyfills to make sure they weren't ran over by others(VTT.js runs over VTTCue polyfill)
				shaka.polyfill.installAll();
				// Create a Player instance.
				var player = new shaka.Player(this.getPlayer().getPlayerElement());

				player.configure(this.getConfig("shakaConfig"));

				// Attach player to the window to make it easy to access in the JS console.
				window.player = player;

				this.registerShakaEvents();

				var unbindAndLoadManifest = function () {
					this.unbind("firstPlay");
					this.unbind("seeking");
					this.loadManifest();
				}.bind(this);

				this.bind("firstPlay", function () {
					unbindAndLoadManifest();
				});

				this.bind("seeking", function () {
					unbindAndLoadManifest();
				});
			},
{'fraction_non_alphanumeric': 0.13062745493000302, 'fraction_numerical': 0.0005035753852351697, 'mean_word_length': 2.7121495327102805, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5084304', 'n_tokens_mistral': 3785, 'n_tokens_neox': 2878, 'n_words': 611}