<commit_before>var connectsdk = (function () {
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Mixins

    // Event emitter
    var SimpleEventEmitter = {
        addListener: function (event, callback, context) {
            if (!event) { throw new Error("missing parameter: event"); }
            if (!callback) { throw new Error("missing parameter: callback"); }

            this._listeners = this._listeners || {};
            if (!this._listeners) this._listeners = {};
            if (!this._listeners[event]) this._listeners[event] = [];
            this._listeners[event].push({callback: callback, context: context});

            this.emit("_addListener", event);

            return this;
        },

        removeListener: function (event, callback, context) {
            if (this._listeners && this._listeners[event]) {
                this._listeners[event] = this._listeners[event].filter(function (l) {
                    return (callback && callback !== l.callback) && (context && context !== l.context);
                });
            }

            this.emit("_removeListener", event);

            return this;
        },

        hasListeners: function (event) {
            if (event) {
                return (this._listeners && this._listeners[event] && this._listeners[event].length > 0);
            } else {
                for (event in this._listeners) {
                    if (event[0] !== "_" && this._listeners.hasOwnProperty(event) && this._listeners[event].length > 0) {
                        return true;
                    }
                }
                return false;
            }
        },

        emit: function (event) {
            var listeners = this._listeners && this._listeners[event];
            var args = Array.prototype.slice.call(arguments, 1);

            // upper-case first char
            event = event.charAt(0).toUpperCase() + event.slice(1);

            if (this["on" + event]) {
                this["on" + event].apply(this, args);
            }

            if (listeners) {
                listeners.forEach(function (l) {
                    l.callback.apply(l.context || null, args);
                });
            }
        },

        on: function (event, callback, context) {
            return this.addListener(event, callback, context);
        },

        off: function (event, callback, context) {
            return this.removeListener(event, callback, context);
        }
    };

////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// ConnectManager

    var ConnectManager = createClass({
        mixins: [SimpleEventEmitter],

        statics: {
            PlatformType: {
                DEFAULT: "Default",
                GOOGLE_CAST: "GoogleCast",
                WEBOS_NATIVE: "WebOSNative",
                WEBOS_WEB_APP: "WebOSWebApp"
            },

            EventType: {
                MESSAGE: "message",
                PAUSE: "pause",
                PLAY: "play",
                READY: "ready",
                STOP: "stop",
                STATUS: "mediaStatusUpdate"
            }
        },

        mediaEvents: {
            loadstart: "buffering",
            playing: "playing",
            waiting: "buffering",
            ended: "finished",
            play: "playing",
            pause: "paused"
        },

        constructor: function () {
            this.handleMediaEvent = this.handleMediaEvent.bind(this);

            extend(this, platforms[this._detectPlatform()]);
        },

        setImageElement: function (element) {
            // Register new image element
            if (element) {
                this.imageElement = element;
            }
        },

        setMediaElement: function (element) {
            // Unregister existing media element
            this.mediaElement && this.unregisterMediaEvents(this.mediaElement);

            // Register new media element
            if (element) {
                this.registerMediaEvents(element);
                this.mediaElement = element;
                this.mediaElement.autoPlay = true;
                this.setMediaStatus("idle");
            }
        },

        setMediaStatus: function (status) {
            this.mediaStatus = status;
            this.emit(ConnectManager.EventType.STATUS, status);
        },

        registerMediaEvents: function (element) {
            if (element) {
                for (var key in this.mediaEvents) {
                    this.mediaEvents.hasOwnProperty(key) && element.addEventListener(key, this.handleMediaEvent, false);
                }
            }
        },

        unregisterMediaEvents: function (element) {
            if (element) {
                for (var key in this.mediaEvents) {
                    this.mediaEvents.hasOwnProperty(key) && element.removeEventListener(key, this.handleMediaEvent, false);
                }
            }
        },

        handleMediaEvent: function (evt) {
            this.mediaEvents.hasOwnProperty(evt.type) && this.setMediaStatus(this.mediaEvents[evt.type]);
        },

        handleReady: function (evt) {
            this.emit(ConnectManager.EventType.READY);
        },

        _detectPlatform: function() {
            var userAgent = navigator.userAgent.toLowerCase();
            this.platformType = ConnectManager.PlatformType.DEFAULT;

            if (userAgent.indexOf('crkey') > 0 && cast != null)
                this.platformType = ConnectManager.PlatformType.GOOGLE_CAST;
            else if (userAgent.indexOf('tv') >= 0 && userAgent.indexOf('webos') >= 0)
            {
                if (window.PalmServiceBridge)
                    this.platformType = ConnectManager.PlatformType.WEBOS_NATIVE;
                else
                    this.platformType = ConnectManager.PlatformType.WEBOS_WEB_APP;
            }
            return this.platformType;
        },

        init: nop,

        sendMessage: nop,

        broadcastMessage: nop
    });

////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Platforms

    var platforms = {};

    // Default
    platforms.Default = {
        interactive: false,
        init: nop,
        sendMessage: nop,
        broadcastMessage: nop
    };<commit_msg>Fixed error with detecting webOS platform<commit_after>var connectsdk = (function () {
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Mixins

    // Event emitter
    var SimpleEventEmitter = {
        addListener: function (event, callback, context) {
            if (!event) { throw new Error("missing parameter: event"); }
            if (!callback) { throw new Error("missing parameter: callback"); }

            this._listeners = this._listeners || {};
            if (!this._listeners) this._listeners = {};
            if (!this._listeners[event]) this._listeners[event] = [];
            this._listeners[event].push({callback: callback, context: context});

            this.emit("_addListener", event);

            return this;
        },

        removeListener: function (event, callback, context) {
            if (this._listeners && this._listeners[event]) {
                this._listeners[event] = this._listeners[event].filter(function (l) {
                    return (callback && callback !== l.callback) && (context && context !== l.context);
                });
            }

            this.emit("_removeListener", event);

            return this;
        },

        hasListeners: function (event) {
            if (event) {
                return (this._listeners && this._listeners[event] && this._listeners[event].length > 0);
            } else {
                for (event in this._listeners) {
                    if (event[0] !== "_" && this._listeners.hasOwnProperty(event) && this._listeners[event].length > 0) {
                        return true;
                    }
                }
                return false;
            }
        },

        emit: function (event) {
            var listeners = this._listeners && this._listeners[event];
            var args = Array.prototype.slice.call(arguments, 1);

            // upper-case first char
            event = event.charAt(0).toUpperCase() + event.slice(1);

            if (this["on" + event]) {
                this["on" + event].apply(this, args);
            }

            if (listeners) {
                listeners.forEach(function (l) {
                    l.callback.apply(l.context || null, args);
                });
            }
        },

        on: function (event, callback, context) {
            return this.addListener(event, callback, context);
        },

        off: function (event, callback, context) {
            return this.removeListener(event, callback, context);
        }
    };

////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// ConnectManager

    var ConnectManager = createClass({
        mixins: [SimpleEventEmitter],

        statics: {
            PlatformType: {
                DEFAULT: "Default",
                GOOGLE_CAST: "GoogleCast",
                WEBOS_NATIVE: "WebOSNative",
                WEBOS_WEB_APP: "WebOSWebApp"
            },

            EventType: {
                MESSAGE: "message",
                PAUSE: "pause",
                PLAY: "play",
                READY: "ready",
                STOP: "stop",
                STATUS: "mediaStatusUpdate"
            }
        },

        mediaEvents: {
            loadstart: "buffering",
            playing: "playing",
            waiting: "buffering",
            ended: "finished",
            play: "playing",
            pause: "paused"
        },

        constructor: function () {
            this.handleMediaEvent = this.handleMediaEvent.bind(this);

            extend(this, platforms[this._detectPlatform()]);
        },

        setImageElement: function (element) {
            // Register new image element
            if (element) {
                this.imageElement = element;
            }
        },

        setMediaElement: function (element) {
            // Unregister existing media element
            this.mediaElement && this.unregisterMediaEvents(this.mediaElement);

            // Register new media element
            if (element) {
                this.registerMediaEvents(element);
                this.mediaElement = element;
                this.mediaElement.autoPlay = true;
                this.setMediaStatus("idle");
            }
        },

        setMediaStatus: function (status) {
            this.mediaStatus = status;
            this.emit(ConnectManager.EventType.STATUS, status);
        },

        registerMediaEvents: function (element) {
            if (element) {
                for (var key in this.mediaEvents) {
                    this.mediaEvents.hasOwnProperty(key) && element.addEventListener(key, this.handleMediaEvent, false);
                }
            }
        },

        unregisterMediaEvents: function (element) {
            if (element) {
                for (var key in this.mediaEvents) {
                    this.mediaEvents.hasOwnProperty(key) && element.removeEventListener(key, this.handleMediaEvent, false);
                }
            }
        },

        handleMediaEvent: function (evt) {
            this.mediaEvents.hasOwnProperty(evt.type) && this.setMediaStatus(this.mediaEvents[evt.type]);
        },

        handleReady: function (evt) {
            this.emit(ConnectManager.EventType.READY);
        },

        _detectPlatform: function() {
            var userAgent = navigator.userAgent.toLowerCase();
            this.platformType = ConnectManager.PlatformType.DEFAULT;

            if (userAgent.indexOf('crkey') > 0 && cast != null)
                this.platformType = ConnectManager.PlatformType.GOOGLE_CAST;
            else if (userAgent.indexOf('tv') >= 0 && (userAgent.indexOf('webos') >= 0) || (userAgent.indexOf('web0s') >= 0))
            {
                if (window.PalmServiceBridge)
                    this.platformType = ConnectManager.PlatformType.WEBOS_NATIVE;
                else
                    this.platformType = ConnectManager.PlatformType.WEBOS_WEB_APP;
            }
            return this.platformType;
        },

        init: nop,

        sendMessage: nop,

        broadcastMessage: nop
    });

////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Platforms

    var platforms = {};

    // Default
    platforms.Default = {
        interactive: false,
        init: nop,
        sendMessage: nop,
        broadcastMessage: nop
    };
{'fraction_non_alphanumeric': 0.15882489729478336, 'fraction_numerical': 0.001550267421130145, 'mean_word_length': 1.3677739034685263, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, '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': '4515184', 'n_tokens_mistral': 3186, 'n_tokens_neox': 3035, 'n_words': 625}