<commit_before>'use strict';

var olyMod = angular.module('mcWebRTC');

olyMod.controller('SignInCtrl', function ($scope, $rootScope, $location, $timeout, $animate, $http, $window, wrtcEventListener) {

  $rootScope.clientVersion = '1.0.0';

  $scope.iceServers = [];

  $http.get('resources/xml/olympus.xml', {
    transformResponse: function (xmlResponse) {
      return new X2JS().xml_str2json(xmlResponse);
    }
    })
    .then(function successCallback(response) {
      var olympusConfig = response.data.olympus;
      $scope.serverAddress =  olympusConfig.server.address || $window.location.hostname;

      if (olympusConfig.server._secure && olympusConfig.server._secure.toLowerCase() === 'true') {
        $scope.serverProtocol = olympusConfig.server._secure === 'true' ? 'wss' : 'ws';
      }
      else {
        $scope.serverProtocol = $location.protocol() === 'https' ? 'wss' : 'ws';
      }
      $scope.serverPort = ($scope.serverProtocol === 'wss' ? (olympusConfig.server['secure-port'] || 5083) : (olympusConfig.server.port || 5082));
      $scope.serverPath = olympusConfig.server.path || '';

      $scope.sipRegisterMode = olympusConfig.client._register !== 'false';
      $scope.sipDomain =  olympusConfig.client.domain || $window.location.hostname;
      $scope.sipUserAgent =  olympusConfig.client['user-agent'] || 'TelScale RTM Olympus';

      if (olympusConfig.turn && olympusConfig.turn._enabled.toLowerCase() !== 'false') {
        $scope.iceAutoConfig = {
          address: olympusConfig.turn.address || 'https://global.xirsys.net/_turn/',
          domain: olympusConfig.turn.domain || '',
          login: olympusConfig.turn.login || '',
          password: <PASSWORD>.turn.password || ''
        };
      }

      if (olympusConfig.stun && olympusConfig.stun._enabled.toLowerCase() === 'true') {
        $scope.iceServers.push(
          { url: 'stun:' + (olympusConfig.stun.address ?
              (olympusConfig.stun.address + ':' + (olympusConfig.stun.port || 19302)) : 'stun.l.google.com:19302') });
      }

      $scope.outboundProxy = {
        address: $scope.serverProtocol + '://' + $scope.serverAddress + ':' + $scope.serverPort + '/' + $scope.serverPath
      };
  });

  $rootScope.loggedUser = '';

  $scope.sip = {
    displayName: '<NAME>',
    // username: 'alice',
    // login: 'alice',
    // password: '<PASSWORD>',
    // domain: $scope.serverAddress
  };

  $scope.mirrorUsername = function() {
    $scope.sip.displayName = $scope.sip.login = $scope.sip.username;
  };

  var processICEAutoConfig = function () {
    if (!$scope.iceAutoConfig.address) {
      return;
    }

    if (!$scope.iceAutoConfig.login || !$scope.iceAutoConfig.password) {
      console.warn('Not all parameters for ICE Auto Config are set, please check.');
    }

    // because Firefox is picky...
    $.ajaxSetup({
      beforeSend: function(xhr) {
        xhr.setRequestHeader ("Authorization", "Basic " + btoa($scope.iceAutoConfig.login + ":" + $scope.iceAutoConfig.password));
        if (xhr.overrideMimeType) {
          xhr.overrideMimeType('application/json');
        }
      }
    });

    $.ajax({
      type: 'PUT',
      url: $scope.iceAutoConfig.address,
      data: {},
      success: function (data) {
        $scope.iceServers = $scope.iceServers.concat(data.v.iceServers);
      },
      async: false
    });
  };

  $scope.connect = function() {
    $scope.registerFailed = false;
    $scope.registering = true;

    processICEAutoConfig();

    // TODO: Make scope config match this, so we don't need to re-format it here
    var wrtcConfiguration = {
      communicationMode: WebRTCommClient.prototype.SIP,
      sip: {
        sipUserAgent: $scope.sipUserAgent + '/' +  $rootScope.clientVersion,<commit_msg>Properly check if Xirsys answer is really a success<commit_after>'use strict';

var olyMod = angular.module('mcWebRTC');

olyMod.controller('SignInCtrl', function ($scope, $rootScope, $location, $timeout, $animate, $http, $window, wrtcEventListener) {

  $rootScope.clientVersion = '1.0.0';

  $scope.iceServers = [];

  $http.get('resources/xml/olympus.xml', {
    transformResponse: function (xmlResponse) {
      return new X2JS().xml_str2json(xmlResponse);
    }
    })
    .then(function successCallback(response) {
      var olympusConfig = response.data.olympus;
      $scope.serverAddress =  olympusConfig.server.address || $window.location.hostname;

      if (olympusConfig.server._secure && olympusConfig.server._secure.toLowerCase() === 'true') {
        $scope.serverProtocol = olympusConfig.server._secure === 'true' ? 'wss' : 'ws';
      }
      else {
        $scope.serverProtocol = $location.protocol() === 'https' ? 'wss' : 'ws';
      }
      $scope.serverPort = ($scope.serverProtocol === 'wss' ? (olympusConfig.server['secure-port'] || 5083) : (olympusConfig.server.port || 5082));
      $scope.serverPath = olympusConfig.server.path || '';

      $scope.sipRegisterMode = olympusConfig.client._register !== 'false';
      $scope.sipDomain =  olympusConfig.client.domain || $window.location.hostname;
      $scope.sipUserAgent =  olympusConfig.client['user-agent'] || 'TelScale RTM Olympus';

      if (olympusConfig.turn && olympusConfig.turn._enabled.toLowerCase() !== 'false') {
        $scope.iceAutoConfig = {
          address: olympusConfig.turn.address || 'https://global.xirsys.net/_turn/',
          domain: olympusConfig.turn.domain || '',
          login: olympusConfig.turn.login || '',
          password: olympusConfig.turn.password || ''
        };
      }

      if (olympusConfig.stun && olympusConfig.stun._enabled.toLowerCase() === 'true') {
        $scope.iceServers.push(
          { url: 'stun:' + (olympusConfig.stun.address ?
              (olympusConfig.stun.address + ':' + (olympusConfig.stun.port || 19302)) : 'stun.l.google.com:19302') });
      }

      $scope.outboundProxy = {
        address: $scope.serverProtocol + '://' + $scope.serverAddress + ':' + $scope.serverPort + '/' + $scope.serverPath
      };
  });

  $rootScope.loggedUser = '';

  $scope.sip = {
    displayName: '<NAME>',
    // username: 'alice',
    // login: 'alice',
    // password: '<PASSWORD>',
    // domain: $scope.serverAddress
  };

  $scope.mirrorUsername = function() {
    $scope.sip.displayName = $scope.sip.login = $scope.sip.username;
  };

  var processICEAutoConfig = function () {
    if (!$scope.iceAutoConfig.address) {
      return;
    }

    if (!$scope.iceAutoConfig.login || !$scope.iceAutoConfig.password) {
      console.warn('Not all parameters for ICE Auto Config are set, please check.');
    }

    // because Firefox is picky...
    $.ajaxSetup({
      beforeSend: function(xhr) {
        xhr.setRequestHeader ("Authorization", "Basic " + btoa($scope.iceAutoConfig.login + ":" + $scope.iceAutoConfig.password));
        if (xhr.overrideMimeType) {
          xhr.overrideMimeType('application/json');
        }
      }
    });

    $.ajax({
      type: 'PUT',
      url: $scope.iceAutoConfig.address,
      data: {},
      success: function (data) {
        if (data.v.iceServers) {
          $scope.iceServers = $scope.iceServers.concat(data.v.iceServers);
        }
        else {
          console.warn('Invalid answer from ICE Auto Config server', data);
        }
      },
      async: false
    });
  };

  $scope.connect = function() {
    $scope.registerFailed = false;
    $scope.registering = true;

    processICEAutoConfig();

    // TODO: Make scope config match this, so we don't need to re-format it here
    var wrtcConfiguration = {
      communicationMode: WebRTCommClient.prototype.SIP,
      sip: {
        sipUserAgent: $scope.sipUserAgent + '/' +  $rootScope.clientVersion,
{'fraction_non_alphanumeric': 0.16033700583279326, 'fraction_numerical': 0.005962410887880752, 'mean_word_length': 2.8715504264927247, 'pattern_counts': {'":': 2, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, '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': '1211315', 'n_tokens_mistral': 2475, 'n_tokens_neox': 2458, 'n_words': 406}