<commit_before>'use strict';

angular.module('bbc.transport', ['btford.socket-io'])
/**
 * @ngdoc object
 * @name bbc.transport.$bbcSocket
 *
 * @description
 * Service for socket connection.
 *
 * @param {object} socketFactory The socket io object
 */
    .factory('$bbcSocket', function (socketFactory) {
        var pub = {};

        function Connection(host, connectTimeout) {
            var connection = io.connect(host, {'connect timeout': connectTimeout});

            return {
                socket: socketFactory({
                    // Creates a new socket connection.
                    ioSocket: connection
                }),
                connection: connection
            };
        }

        /**
         * @ngdoc method
         * @name bbc.transport.$bbcSocket#createSocket
         * @methodOf bbc.transport.$bbcSocket
         *
         * @description
         * Set navigation with app and route of app
         *
         * @param {string} host The host connection string
         * @param {number} connectTimeout The connection timeout
         */
        pub.createSocket = function (host, connectTimeout) {
            // when 2 is callback in data, rewrite this
            if (arguments.length !== 2) {
                throw new TypeError('Param "host" and "connectTimeout" are required');
            }

            // check host
            if (typeof host !== 'string' || host.length === 0) {
                throw new TypeError('Param "host" is required and must be of type string!');
            }

            // check connectTimeout
            if (typeof connectTimeout !== 'number' || connectTimeout < 0) {
                throw new TypeError('Param "connectTimeout" is required and must be of type number and greater than 0!');
            }

            return new Connection(host, connectTimeout);
        };

        return pub;
    })

/**
 * @ngdoc object
 * @name bbc.transport.$bbcTransport
 * @requires $timeout
 *
 * @description
 * Service for transport. It can either use a socket connection or a rest connection. The option which communication
 * to use is useSocket.
 *
 * For more information look at the [guide](/transport).
 *
 */
    .provider('$bbcTransport', function () {
        var config = {};

        /**
         * @ngdoc method
         * @name bbc.transport.$bbcTransport#set
         * @methodOf bbc.transport.$bbcTransport
         *
         * @description
         * Setup the transport configuration
         *
         * @param {object} options The options for config
         */
        this.set = function (options) {
            options = options || {};

            // default settings
            config.protocol = options.protocol;
            config.hostname = options.hostname;
            config.port = options.port;

            if (options.hasOwnProperty('useSocket')) {
                config.useSocket = options.useSocket;
            } else {
                config.useSocket = true;
            }

            config.connectTimeout = options.connectTimeout || 5000;
            config.socketResponseTimeout = options.socketResponseTimeout || 5000;
        };

        this.$get = function ($rootScope, $http, $bbcSocket, $window, $log, $timeout) {
            var pub = {};

            var socket;
            var socketConnection;

            // default settings when options is empty
            config.protocol = config.protocol || $window.location.protocol;
            config.hostname = config.hostname || $window.location.hostname;
            config.port = config.port || parseInt($window.location.port);

            // fix protocol when forgotten :
            if (config.protocol === 'http' || config.protocol === 'https' ||
                config.protocol === 'ws' || config.protocol === 'wss') {
                config.protocol = config.protocol + ':';
            }

            // create the host url
            config.host = config.protocol + '//' + config.hostname + ':' + config.port;

            // default socket is not enabled
            $rootScope.socketEnabled = false;

            /**
             * Register socket events
             *
             * @param socket
             */
            var registerSocketEvents = function (socket) {
                // socket connect event, change transportSocket to true.
                socket.on('connecting', function () {
                    $log.info('socket: connecting to ', config.host);
                });
<commit_msg>fix(transport): resolve port Nan error<commit_after>'use strict';

angular.module('bbc.transport', ['btford.socket-io'])
/**
 * @ngdoc object
 * @name bbc.transport.$bbcSocket
 *
 * @description
 * Service for socket connection.
 *
 * @param {object} socketFactory The socket io object
 */
    .factory('$bbcSocket', function (socketFactory) {
        var pub = {};

        function Connection(host, connectTimeout) {
            var connection = io.connect(host, {'connect timeout': connectTimeout});

            return {
                socket: socketFactory({
                    // Creates a new socket connection.
                    ioSocket: connection
                }),
                connection: connection
            };
        }

        /**
         * @ngdoc method
         * @name bbc.transport.$bbcSocket#createSocket
         * @methodOf bbc.transport.$bbcSocket
         *
         * @description
         * Set navigation with app and route of app
         *
         * @param {string} host The host connection string
         * @param {number} connectTimeout The connection timeout
         */
        pub.createSocket = function (host, connectTimeout) {
            // when 2 is callback in data, rewrite this
            if (arguments.length !== 2) {
                throw new TypeError('Param "host" and "connectTimeout" are required');
            }

            // check host
            if (typeof host !== 'string' || host.length === 0) {
                throw new TypeError('Param "host" is required and must be of type string!');
            }

            // check connectTimeout
            if (typeof connectTimeout !== 'number' || connectTimeout < 0) {
                throw new TypeError('Param "connectTimeout" is required and must be of type number and greater than 0!');
            }

            return new Connection(host, connectTimeout);
        };

        return pub;
    })

/**
 * @ngdoc object
 * @name bbc.transport.$bbcTransport
 * @requires $timeout
 *
 * @description
 * Service for transport. It can either use a socket connection or a rest connection. The option which communication
 * to use is useSocket.
 *
 * For more information look at the [guide](/transport).
 *
 */
    .provider('$bbcTransport', function () {
        var config = {};

        /**
         * @ngdoc method
         * @name bbc.transport.$bbcTransport#set
         * @methodOf bbc.transport.$bbcTransport
         *
         * @description
         * Setup the transport configuration
         *
         * @param {object} options The options for config
         */
        this.set = function (options) {
            options = options || {};

            // default settings
            config.protocol = options.protocol;
            config.hostname = options.hostname;
            config.port = options.port;

            if (options.hasOwnProperty('useSocket')) {
                config.useSocket = options.useSocket;
            } else {
                config.useSocket = true;
            }

            config.connectTimeout = options.connectTimeout || 5000;
            config.socketResponseTimeout = options.socketResponseTimeout || 5000;
        };

        this.$get = function ($rootScope, $http, $bbcSocket, $window, $log, $timeout) {
            var pub = {};

            var socket;
            var socketConnection;

            // default settings when options is empty
            config.protocol = config.protocol || $window.location.protocol;
            config.hostname = config.hostname || $window.location.hostname;
            config.port = config.port || parseInt($window.location.port);

            // fix protocol when forgotten :
            if (config.protocol === 'http' || config.protocol === 'https' ||
                config.protocol === 'ws' || config.protocol === 'wss') {
                config.protocol = config.protocol + ':';
            }

            if (!config.port || config.port === 443 || config.port === 80) {

                // create the host url without port
                config.host = config.protocol + '//' + config.hostname;
            }
            else {

                // create the host url with port
                config.host = config.protocol + '//' + config.hostname + ':' + config.port;
            }

            // default socket is not enabled
            $rootScope.socketEnabled = false;

            /**
             * Register socket events
             *
             * @param socket
             */
            var registerSocketEvents = function (socket) {
                // socket connect event, change transportSocket to true.
                socket.on('connecting', function () {
                    $log.info('socket: connecting to ', config.host);
                });

{'fraction_non_alphanumeric': 0.10896952729622052, 'fraction_numerical': 0.003337999353935609, 'mean_word_length': 1.6797461050201963, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '752693', 'n_tokens_mistral': 2272, 'n_tokens_neox': 2174, 'n_words': 646}