<commit_before>(function (mw, $, kWidget) {
    "use strict";
    mw.streamSelectorUtils = mw.streamSelectorUtils || {};

    mw.streamSelectorUtils.selector = mw.KBaseComponent.extend({

        defaultConfig: {
            "defaultStream": 1,
            "maxNumOfStream": 4,
            "ignoreTag": null
        },

        streams: null,
        streamsReady: null,
        streamEnded: false,
        readyAndHasStreams: null,
		streamChanging: false,

        setup: function () {
            // we have to manually reset streams array because
            // class.js copies the value by reference from prototype
            this.streams = [];
            this.addBindings();
            this.readyAndHasStreams = $.Deferred();
        },
        destroy: function () {
            this._super();
            this.getComponent().remove();
        },
        addBindings: function () {
            var _this = this;

            this.bind('StreamListReady', function () {
                //Indicate that the streams are ready to enable spinning animation on source switching
                _this.streamsReady = true;
                //Insert original entry to streams
                _this.streams.splice(0, 0, {
                    id: _this.getPlayer().kentryid,
                    data: {
                        meta: _this.getPlayer().kalturaPlayerMetaData,
                        contextData: _this.getPlayer().kalturaContextData
                    }
                });
                _this.currentStream = _this.getDefaultStream();

                if (_this.getPlayer().kentryid !== _this.currentStream.id) {
                    _this.setStream(_this.currentStream);
                }
                if (_this.streams.length > 1) {
                    _this.readyAndHasStreams.resolve();
                } else {
                    _this.readyAndHasStreams.reject();
                }
            });

            this.bind("ended", function () {
                _this.streamEnded = true;
            });

            this.bind("onplay onChangeStreamDone", function () {
                _this.streamEnded = false;
            });

            this.bind('changeStream', function (e, arg) {
                _this.externalSetStream(arg);
            });
            
            this.bind('onChangeMedia', function () {
                if (!_this.streamChanging){
                    _this.streams = [];
                    _this.streamsReady = false;
                }
            });
        },
        getStreams: function () {
            var _this = this;
            var requestObject = [];
            requestObject.push({
                'service': 'baseEntry',
                'action': 'list',
                'filter:objectType': 'KalturaBaseEntryFilter',
                'filter:typeEqual': 1,
                'filter:parentEntryIdEqual': this.getPlayer().kentryid
            });

            var i = 0;
            var maxNumOfStream = this.getConfig("maxNumOfStream");
            for (i; i < maxNumOfStream; i++) {
                requestObject.push({
                    'service': 'flavorAsset',
                    'action': 'list',
                    'filter:entryIdEqual': '{1:result:objects:' + i + ':id}'
                });
            }

            // do the api request
            this.getKalturaClient().doRequest(requestObject, function (data) {
                // Validate result
                if (data && _this.isValidResult(data[0] && data[0].totalCount > 0)) {
                    _this.createStreamList(data);
                } else {
                    mw.log('streamSelectorUtil::Error retrieving streams, disabling component');
                    _this.readyAndHasStreams.reject();
                }
            });
        },
        createStreamList: function (data) {
            var _this = this;
            var subStreams = data[0].objects;
            var subStreamsData = data.slice(1);
            if (subStreams && subStreams.length > 0) {
                var ignoreTag = this.getConfig('ignoreTag');
                $.each( subStreams, function ( i, subStream ) {<commit_msg>PLAT-9400 split flavorAsset multi-request (#4072)<commit_after>(function (mw, $, kWidget) {
    "use strict";
    mw.streamSelectorUtils = mw.streamSelectorUtils || {};

    mw.streamSelectorUtils.selector = mw.KBaseComponent.extend({

        defaultConfig: {
            "defaultStream": 1,
            "maxNumOfStream": 4,
            "ignoreTag": null
        },

        streams: null,
        streamsReady: null,
        streamEnded: false,
        readyAndHasStreams: null,
		streamChanging: false,

        setup: function () {
            // we have to manually reset streams array because
            // class.js copies the value by reference from prototype
            this.streams = [];
            this.addBindings();
            this.readyAndHasStreams = $.Deferred();
        },
        destroy: function () {
            this._super();
            this.getComponent().remove();
        },
        addBindings: function () {
            var _this = this;

            this.bind('StreamListReady', function () {
                //Indicate that the streams are ready to enable spinning animation on source switching
                _this.streamsReady = true;
                //Insert original entry to streams
                _this.streams.splice(0, 0, {
                    id: _this.getPlayer().kentryid,
                    data: {
                        meta: _this.getPlayer().kalturaPlayerMetaData,
                        contextData: _this.getPlayer().kalturaContextData
                    }
                });
                _this.currentStream = _this.getDefaultStream();

                if (_this.getPlayer().kentryid !== _this.currentStream.id) {
                    _this.setStream(_this.currentStream);
                }
                if (_this.streams.length > 1) {
                    _this.readyAndHasStreams.resolve();
                } else {
                    _this.readyAndHasStreams.reject();
                }
            });

            this.bind("ended", function () {
                _this.streamEnded = true;
            });

            this.bind("onplay onChangeStreamDone", function () {
                _this.streamEnded = false;
            });

            this.bind('changeStream', function (e, arg) {
                _this.externalSetStream(arg);
            });
            
            this.bind('onChangeMedia', function () {
                if (!_this.streamChanging){
                    _this.streams = [];
                    _this.streamsReady = false;
                }
            });
        },
        getStreams: function () {
            var _this = this;
            var requestObject = [
                {
                    'service': 'baseEntry',
                    'action': 'list',
                    'filter:objectType': 'KalturaBaseEntryFilter',
                    'filter:typeEqual': 1,
                    'filter:parentEntryIdEqual': this.getPlayer().kentryid
                }
            ];
            var responceArray = [];
            // get child IDs
            _this.getKalturaClient().doRequest(requestObject, function (data) {
                // Validate result
                if (data && _this.isValidResult(data && data.totalCount > 0)) {
                    responceArray.push(data)
                    var i = 0;
                    var maxNumOfStream = Math.min(_this.getConfig("maxNumOfStream"), data.totalCount);
                    var flavorAssetRequestObject = [];
                    for (i; i < maxNumOfStream; i++) {
                        flavorAssetRequestObject.push({
                            'service': 'flavorAsset',
                            'action': 'list',
                            'filter:entryIdEqual': data.objects[i].id
                        });
                    }
                    // get flavorAssets data
                    _this.getKalturaClient().doRequest(flavorAssetRequestObject, function (flavorAssetsData) {
                        // Validate result
                        if (flavorAssetsData && Array.isArray(flavorAssetsData)) {
                            _this.createStreamList(responceArray.concat(flavorAssetsData));
                        } else {
                            mw.log('streamSelectorUtil::Error retrieving streams, disabling component');
                            _this.readyAndHasStreams.reject();
                        }
                    });
                } else {
                    mw.log('streamSelectorUtil::Error retrieving streams, disabling component');
                    _this.readyAndHasStreams.reject();
                }
            });
        },
        createStreamList: function (data) {
            var _this = this;
            var subStreams = data[0].objects;
            var subStreamsData = data.slice(1);
            if (subStreams && subStreams.length > 0) {
                var ignoreTag = this.getConfig('ignoreTag');
                $.each( subStreams, function ( i, subStream ) {
{'fraction_non_alphanumeric': 0.10528041980977369, 'fraction_numerical': 0.0036077402427025255, 'mean_word_length': 1.3141917530989122, 'pattern_counts': {'":': 6, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '2138888', 'n_tokens_mistral': 2320, 'n_tokens_neox': 2174, 'n_words': 434}