<commit_before>angular.module 'app.control'

.controller 'app.control.index', [
  '$scope', '$state', '$stateParams', '$facebook', '$kinvey', 'PubNub', 'me', 'users', 'rooms', '$subscriber', '$modal', '$window', '$peer',
  ($scope, $state, $stateParams, $facebook, $kinvey, PubNub, me, users, rooms, $subscriber, $modal, $window, $peer) ->

    $scope.me = me
    $scope.users = users
    $scope.rooms = rooms
    $scope.notifications = {}
    $scope.inCall = false

    $peer.create me._id
    navigator.getMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
    window.URL = window.URL || window.webkitURL || window.mozURL || window.msURL;

    $peer.on 'call', (call) ->
      $scope.$apply ->
        if !$scope.inCall
          calloptions =
            video: true
            audio: true
          navigator.getMedia calloptions, (stream) ->
            call.answer stream
            call.on 'stream', (remoteStream) ->
              $scope.$apply ->
                showCallStream call, remoteStream
            , (err) ->
              console.log err

    $scope.call = (user) ->
      calloptions =
        video: true
        audio: true
      navigator.getMedia calloptions, (stream) ->
        call = $peer.call user._id, stream
        call.on 'stream', ((remoteStream) ->
          $scope.$apply ->
            showCallStream call, remoteStream
        ), ((err) -> console.log err)

    showCallStream = (call, stream)->
      $scope.inCall = true

      $modal.open
        templateUrl: 'html/call.html'
        controller: ['$scope', 'call', ($scope, call) ->
          call.on 'close', ->
            $scope.$apply ->
              console.log 'closing event'
              $scope.$close()
        ]
        resolve:
          call: -> call
      .result.then ->
        console.log 'closing call'
        call.close()
      , ->
        console.log 'closing call erback'
        call.close()

      url = (URL.createObjectURL stream)
      tryShowVideo = ->
        setTimeout ->
          if $('#call').length > 0
            $('#call').prop 'src', url
          else
            tryShowVideo()
        , 10
      tryShowVideo()<commit_msg>WIP: calling<commit_after>angular.module 'app.control'

.controller 'app.control.index', [
  '$scope', '$state', '$stateParams', '$facebook', '$kinvey', 'PubNub', 'me', 'users', 'rooms', '$subscriber', '$modal', '$window', '$peer',
  ($scope, $state, $stateParams, $facebook, $kinvey, PubNub, me, users, rooms, $subscriber, $modal, $window, $peer) ->

    $scope.me = me
    $scope.users = users
    $scope.rooms = rooms
    $scope.notifications = {}
    $scope.inCall = false

    $peer.create me._id
    navigator.getMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
    window.URL = window.URL || window.webkitURL || window.mozURL || window.msURL;

    $peer.on 'call', (call) ->
      $scope.$apply ->
        if !$scope.inCall
          calloptions =
            video: true
            audio: true
          navigator.getMedia calloptions, (stream) ->
            call.answer stream
            call.on 'stream', (remoteStream) ->
              $scope.$apply ->
                showCallStream call, remoteStream
            , (err) ->
              console.log err

    $scope.call = (user) ->
      calloptions =
        video: true
        audio: true
      navigator.getMedia calloptions, (stream) ->
        call = $peer.call user._id, stream
        call.on 'stream', ((remoteStream) ->
          $scope.$apply ->
            showCallStream call, remoteStream
        ), ((err) -> console.log err)

    showCallStream = (call, stream)->
      $scope.inCall = true

      $modal.open
        templateUrl: 'html/call.html'
        controller: ['$scope', 'call', ($scope, call) ->
          call.on 'close', ->
            console.log 'closing event'
            $scope.$close()
        ]
        resolve:
          call: -> call
      .result.then ->
        call.close()
      , ->
        call.close()

      url = (URL.createObjectURL stream)
      tryShowVideo = ->
        setTimeout ->
          if $('#call').length > 0
            $('#call').prop 'src', url
          else
            tryShowVideo()
        , 10
      tryShowVideo()
{'fraction_non_alphanumeric': 0.1503374447288806, 'fraction_numerical': 0.0013963230160577147, 'mean_word_length': 1.8981793661496966, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 46, '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': '222712', 'n_tokens_mistral': 1263, 'n_tokens_neox': 1236, 'n_words': 288}