<commit_before>
var websocket = require('websocket-stream');
var URL = require('url');

function buildBuilder(client, opts) {
  var host = opts.hostname || 'localhost'
    , port = opts.port || 80
    , url = opts.protocol + '://' + host + ':' + port
    , ws =  websocket(url, {
        protocol: 'mqttv3.1'
      });

  return ws;
}

function buildBuilderBrowser(mqttClient, opts) {
  var parsed = URL.parse(document.URL);

  if (!opts.protocol) {
    if (parsed.protocol === 'https:') {
      opts.protocol = 'wss';
    } else {
      opts.protocol = 'ws';
    }
  }

  if (!opts.host) {
    opts.host = parsed.hostname;
  }

  if (!opts.port) {
    if(opts.protocol === 'wss'){
      opts.port = 443;
    } else if(opts.protocol === 'ws') {
      opts.port = 80;
    } else {
      opts.port = parsed.port;
    }
  }

  var host = opts.hostname || opts.host
    , port = opts.port
    , url = opts.protocol + '://' + host + ':' + opts.port

  return websocket(url);
}

if (process.title !== 'browser') {
  module.exports = buildBuilder;
} else {
  module.exports = buildBuilderBrowser;<commit_msg>Revert "Use port for protocol when none is provided"<commit_after>
var websocket = require('websocket-stream');
var URL = require('url');

function buildBuilder(client, opts) {
  var host = opts.hostname || 'localhost'
    , port = opts.port || 80
    , url = opts.protocol + '://' + host + ':' + port
    , ws =  websocket(url, {
        protocol: 'mqttv3.1'
      });

  return ws;
}

function buildBuilderBrowser(mqttClient, opts) {
  var parsed = URL.parse(document.URL);

  if (!opts.protocol) {
    if (parsed.protocol === 'https:') {
      opts.protocol = 'wss';
    } else {
      opts.protocol = 'ws';
    }
  }

  if (!opts.host) {
    opts.host = parsed.hostname;
  }

  if (!opts.port) {
    opts.port = parsed.port;
  }

  var host = opts.hostname || opts.host
    , port = opts.port
    , url = opts.protocol + '://' + host + ':' + opts.port

  return websocket(url);
}

if (process.title !== 'browser') {
  module.exports = buildBuilder;
} else {
  module.exports = buildBuilderBrowser;
{'fraction_non_alphanumeric': 0.170313986679353, 'fraction_numerical': 0.006184586108468126, 'mean_word_length': 2.63840830449827, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5170688', 'n_tokens_mistral': 737, 'n_tokens_neox': 716, 'n_words': 159}