<commit_before>/*
 * Q-municate chat application
 *
 * VideoChat View Module
 *
 */

var callTimer, videoStreamTime;

define(['jquery', 'quickblox', 'config', 'Helpers', 'QBNotification', 'QMHtml'], function($, QB, QMCONFIG, Helpers, QBNotification, QMHtml) {

  var self;
  var User,
      ContactList,
      VideoChat,
      curSession = {},
      network = {},
      stopStreamFF,
      is_firefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;

  function VideoChatView(app) {
    this.app = app;

    self = this;
    User = this.app.models.User;
    ContactList = this.app.models.ContactList;
    VideoChat = this.app.models.VideoChat;
  }

  VideoChatView.prototype.cancelCurrentCalls = function() {
    if ($('.mediacall').length > 0) {
      $('.mediacall').find('.btn_hangup').click();
    }
  };

  VideoChatView.prototype.init = function() {
    var DialogView = this.app.views.Dialog;

    $('body').on('click', '.videoCall, .audioCall', function() {
      if (QB.webrtc) {
        var className = $(this).attr('class');

        self.cancelCurrentCalls();
        self.startCall(className);
        
        curSession = self.app.models.VideoChat.session;
      } else {
        QMHtml.VideoChat.noWebRTC();
      }

      return false;
    });

    $('#popupIncoming').on('click', '.btn_decline', function() {
      var $self = $(this),
          $incomingCall = $self.parents('.incoming-call'),
          opponentId = $self.data('id'),
          dialogId = $self.data('dialog'),
          callType = $self.data('calltype'),
          audioSignal = $('#ringtoneSignal')[0];

      curSession.reject({});

      VideoChat.sendMessage(opponentId, '3', null, dialogId, callType);

      $incomingCall.remove();

      if ($('#popupIncoming .mCSB_container').children().length === 0) {
        closePopup();
        audioSignal.pause();
      }

      return false;
    });

    $('#popupIncoming').on('click', '.btn_accept', function() {
      self.cancelCurrentCalls();

      var $self = $(this),
          id = $self.data('id'),
          $dialogItem = $('.dialog-item[data-id="'+id+'"]').find('.contact');
      
      DialogView.htmlBuild($dialogItem);

      var opponentId = $self.data('id'),
          dialogId = $self.data('dialog'),
          sessionId = $self.data('session'),
          callType = $self.data('calltype'),
          audioSignal = $('#ringtoneSignal')[0],
          params = self.build(dialogId),
          $chat = $('.l-chat[data-dialog="'+dialogId+'"]');

      $self.parents('.incoming-call').remove();
      $('#popupIncoming .mCSB_container').children().each(function() {
        $self.find('.btn_decline').click();
      });
      closePopup();
      audioSignal.pause();

      params.isCallee = true;

      VideoChat.getUserMedia(params, callType, function(err, res) {
        if (err) {
          $chat.find('.mediacall .btn_hangup').data('errorMessage', 1);
          $chat.find('.mediacall .btn_hangup').click();
          fixScroll();
          return true;
        }

        if (callType === 'audio') {
          self.type = 'audio';
          $('.btn_camera_off').click();
        } else {
          self.type = 'video';
          self.unmute('video');
        }

        self.sessionID = sessionId;
        addCallTypeIcon(id, callType);
      });

      return false;
    });

    $('body').on('click', '.btn_hangup', function() {
      console.info(curSession);
      var $self = $(this),
          $chat = $self.parents('.l-chat'),
          opponentId = $self.data('id'),
          dialogId = $self.data('dialog'),
          duration = $self.parents('.mediacall').find('.mediacall-info-duration').text(),
          callingSignal = $('#callingSignal')[0],
          endCallSignal = $('#endCallSignal')[0],
          isErrorMessage = $self.data('errorMessage');

      if (VideoChat.caller) {
        if (!isErrorMessage && duration !== 'connect...') {
          VideoChat.sendMessage(opponentId, '1', duration, dialogId, null, null, self.sessionID);
        } else {
          $self.removeAttr('data-errorMessage');
        }
      }

      callingSignal.pause();
      endCallSignal.play();<commit_msg>removed console.info from views/videocalls.js<commit_after>/*
 * Q-municate chat application
 *
 * VideoChat View Module
 *
 */

var callTimer, videoStreamTime;

define(['jquery', 'quickblox', 'config', 'Helpers', 'QBNotification', 'QMHtml'], function($, QB, QMCONFIG, Helpers, QBNotification, QMHtml) {

  var self;
  var User,
      ContactList,
      VideoChat,
      curSession = {},
      network = {},
      stopStreamFF,
      is_firefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;

  function VideoChatView(app) {
    this.app = app;

    self = this;
    User = this.app.models.User;
    ContactList = this.app.models.ContactList;
    VideoChat = this.app.models.VideoChat;
  }

  VideoChatView.prototype.cancelCurrentCalls = function() {
    if ($('.mediacall').length > 0) {
      $('.mediacall').find('.btn_hangup').click();
    }
  };

  VideoChatView.prototype.init = function() {
    var DialogView = this.app.views.Dialog;

    $('body').on('click', '.videoCall, .audioCall', function() {
      if (QB.webrtc) {
        var className = $(this).attr('class');

        self.cancelCurrentCalls();
        self.startCall(className);
        
        curSession = self.app.models.VideoChat.session;
      } else {
        QMHtml.VideoChat.noWebRTC();
      }

      return false;
    });

    $('#popupIncoming').on('click', '.btn_decline', function() {
      var $self = $(this),
          $incomingCall = $self.parents('.incoming-call'),
          opponentId = $self.data('id'),
          dialogId = $self.data('dialog'),
          callType = $self.data('calltype'),
          audioSignal = $('#ringtoneSignal')[0];

      curSession.reject({});

      VideoChat.sendMessage(opponentId, '3', null, dialogId, callType);

      $incomingCall.remove();

      if ($('#popupIncoming .mCSB_container').children().length === 0) {
        closePopup();
        audioSignal.pause();
      }

      return false;
    });

    $('#popupIncoming').on('click', '.btn_accept', function() {
      self.cancelCurrentCalls();

      var $self = $(this),
          id = $self.data('id'),
          $dialogItem = $('.dialog-item[data-id="'+id+'"]').find('.contact');
      
      DialogView.htmlBuild($dialogItem);

      var opponentId = $self.data('id'),
          dialogId = $self.data('dialog'),
          sessionId = $self.data('session'),
          callType = $self.data('calltype'),
          audioSignal = $('#ringtoneSignal')[0],
          params = self.build(dialogId),
          $chat = $('.l-chat[data-dialog="'+dialogId+'"]');

      $self.parents('.incoming-call').remove();
      $('#popupIncoming .mCSB_container').children().each(function() {
        $self.find('.btn_decline').click();
      });
      closePopup();
      audioSignal.pause();

      params.isCallee = true;

      VideoChat.getUserMedia(params, callType, function(err, res) {
        if (err) {
          $chat.find('.mediacall .btn_hangup').data('errorMessage', 1);
          $chat.find('.mediacall .btn_hangup').click();
          fixScroll();
          return true;
        }

        if (callType === 'audio') {
          self.type = 'audio';
          $('.btn_camera_off').click();
        } else {
          self.type = 'video';
          self.unmute('video');
        }

        self.sessionID = sessionId;
        addCallTypeIcon(id, callType);
      });

      return false;
    });

    $('body').on('click', '.btn_hangup', function() {
      var $self = $(this),
          $chat = $self.parents('.l-chat'),
          opponentId = $self.data('id'),
          dialogId = $self.data('dialog'),
          duration = $self.parents('.mediacall').find('.mediacall-info-duration').text(),
          callingSignal = $('#callingSignal')[0],
          endCallSignal = $('#endCallSignal')[0],
          isErrorMessage = $self.data('errorMessage');

      if (VideoChat.caller) {
        if (!isErrorMessage && duration !== 'connect...') {
          VideoChat.sendMessage(opponentId, '1', duration, dialogId, null, null, self.sessionID);
        } else {
          $self.removeAttr('data-errorMessage');
        }
      }

      callingSignal.pause();
      endCallSignal.play();
{'fraction_non_alphanumeric': 0.17976047904191617, 'fraction_numerical': 0.0023952095808383233, 'mean_word_length': 2.4352118469765527, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '5424457', 'n_tokens_mistral': 2570, 'n_tokens_neox': 2524, 'n_words': 417}