<commit_before>angular.module('connecting', [
  'utils'
])

.controller('connectingController', [
  '$scope',
  '$http',
  '$stateParams',
  '$rootScope',
  'fileTransfer',
  'webRTC',
  'packetHandlers',
  function($scope, $http, $stateParams, $rootScope, fileTransfer, webRTC, packetHandlers) {
    console.log('connecting controller loaded');
    /**
     * if arriving from redirect,
     * sender has access to their own peer object,
     * becasue it's on the fileTransfer
     *
     * if arriving from a link,
     * follow the code below:
     */
    var clipboard = new Clipboard('.btn');
    document.getElementById('currentUrl').value = window.location.href;
    var disconnectingReceiverId = null;

    $scope.incomingFileTransfers = fileTransfer.incomingFileTransfers = {};
    $scope.outgoingFileTransfers = fileTransfer.outgoingFileTransfers = {};
    fileTransfer.finishedTransfers = [];
    $scope.offers = fileTransfer.offers = [];

    if (!fileTransfer.peer) {
      fileTransfer.myItems = [];

      fileTransfer.conn = [];


      fileTransfer.peer = webRTC.createPeer();

      fileTransfer.peer.on('open', function(id) {
        disconnectingReceiverId = id;
        $http({
            method: 'POST',
            url: '/api/webrtc/users',
            data: {
              hash: $stateParams.roomHash,
              recipientId: id
            }
          })
          .then(function(res) {
            // expect res.data === sender id
            var conn = fileTransfer.peer.connect(res.data.senderID);
            fileTransfer.conn.push(conn);
            conn.on('data', function(data) {
              console.log('incoming packet');
              if (data.type === 'file-accepted') {
                packetHandlers.accepted(data, conn, $rootScope);
              } else if (data.type === 'file-offer') {
                packetHandlers.offer(data, conn, $rootScope);
              } else if (data.type === 'file-chunk') {
                packetHandlers.chunk(data, $rootScope);
              }
            });
          });
      });

      window.onbeforeunload = function(e) {
        e.preventDefault();
        //stops notification from showing
      };

      window.addEventListener('beforeunload', function() {
        $http({
          method: 'POST',
          url: '/api/webrtc/deleteReceiverId',
          data: {
            hash: $stateParams.roomHash,
            id: disconnectingReceiverId
          }
        });
      });

      document.getElementById('filesId').addEventListener('change', function() {
        console.log('connecting input listener');
        var files = this.files;
        for (var i = 0; i < files.length; i++) {
          if(fileTransfer.myItems.indexOf(files[i]) > -1){
            continue;
          }
          files[i].beenSent = false;
          fileTransfer.myItems.push(files[i]);
        }
        fileTransfer.conn.forEach(function(connection) {
          webRTC.clearQueue(fileTransfer.myItems, connection);
        });
        //TODO: send files back

      });
    }

  }
]);<commit_msg>[feat] fn to toggle class in connectingController.js<commit_after>angular.module('connecting', [
  'utils'
])

.controller('connectingController', [
  '$scope',
  '$http',
  '$stateParams',
  '$rootScope',
  'fileTransfer',
  'webRTC',
  'packetHandlers',
  function($scope, $http, $stateParams, $rootScope, fileTransfer, webRTC, packetHandlers) {
    console.log('connecting controller loaded');
    /**
     * if arriving from redirect,
     * sender has access to their own peer object,
     * becasue it's on the fileTransfer
     *
     * if arriving from a link,
     * follow the code below:
     */

    $('#lightningBoltButton').on('click', function() {
      $('#lightningBoltButton').removeClass('glowing');
    });

    setTimeout(function() {
      var clipboard = new Clipboard('.clipboardButton');
      document.getElementById('currentUrl').value = window.location.href;
    }, 0)

    var disconnectingReceiverId = null;
    // console.log(window.location.href);

    $scope.incomingFileTransfers = fileTransfer.incomingFileTransfers = {};
    $scope.outgoingFileTransfers = fileTransfer.outgoingFileTransfers = {};
    fileTransfer.finishedTransfers = [];
    $scope.offers = fileTransfer.offers = [];

    if (!fileTransfer.peer) {
      fileTransfer.myItems = [];

      fileTransfer.conn = [];


      fileTransfer.peer = webRTC.createPeer();

      fileTransfer.peer.on('open', function(id) {
        disconnectingReceiverId = id;
        $http({
            method: 'POST',
            url: '/api/webrtc/users',
            data: {
              hash: $stateParams.roomHash,
              recipientId: id
            }
          })
          .then(function(res) {
            // expect res.data === sender id
            var conn = fileTransfer.peer.connect(res.data.senderID);
            fileTransfer.conn.push(conn);
            conn.on('data', function(data) {
              console.log('incoming packet');
              if (data.type === 'file-accepted') {
                packetHandlers.accepted(data, conn, $rootScope);
              } else if (data.type === 'file-offer') {
                packetHandlers.offer(data, conn, $rootScope);
              } else if (data.type === 'file-chunk') {
                packetHandlers.chunk(data, $rootScope);
              }
            });
          });
      });

      window.onbeforeunload = function(e) {
        e.preventDefault();
        //stops notification from showing
      };

      window.addEventListener('beforeunload', function() {
        $http({
          method: 'POST',
          url: '/api/webrtc/deleteReceiverId',
          data: {
            hash: $stateParams.roomHash,
            id: disconnectingReceiverId
          }
        });
      });

      document.getElementById('filesId').addEventListener('change', function() {
        console.log('connecting input listener');
        var files = this.files;
        for (var i = 0; i < files.length; i++) {
          if (fileTransfer.myItems.indexOf(files[i]) > -1) {
            continue;
          }
          files[i].beenSent = false;
          fileTransfer.myItems.push(files[i]);
        }
        fileTransfer.conn.forEach(function(connection) {
          webRTC.clearQueue(fileTransfer.myItems, connection);
        });
        //TODO: send files back

      });
    }

  }
]);
{'fraction_non_alphanumeric': 0.13727940028111824, 'fraction_numerical': 0.0007808839606434484, 'mean_word_length': 2.0982099661344944, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5559973', 'n_tokens_mistral': 1811, 'n_tokens_neox': 1764, 'n_words': 335}