<commit_before>const _ = require('underscore');
const Peer = require('./Peer.js');
const debug = require('debug')('peer-calls:peer');
const dispatcher = require('../dispatcher/dispatcher.js');
const notify = require('../action/notify.js');

let peers = {};

/**
 * @param {Socket} socket
 * @param {User} user
 * @param {String} user.id
 * @param {Boolean} [initiator=false]
 * @param {MediaStream} [stream]
 */
function create({ socket, user, initiator, stream }) {
  debug('create peer: %s', user.id);
  notify.warn('Connecting to peer...');

  if (peers[user.id]) {
    notify.info('Cleaning up old connection...');
    destroy(user.id);
  }

  let peer = peers[user.id] = Peer.init({
    initiator: '/#' + socket.id === initiator,
    stream,
    config: {
      iceServers: [{
        url: 'stun:192.168.3.11',
        urls: 'stun:192.168.3.11'
      }]
    }
  });

  peer.once('error', err => {
    debug('peer: %s, error %s', user.id, err.stack);
    notify.error('A peer connection error occurred');
    destroy(user.id);
  });<commit_msg>Add turn server<commit_after>const _ = require('underscore');
const Peer = require('./Peer.js');
const debug = require('debug')('peer-calls:peer');
const dispatcher = require('../dispatcher/dispatcher.js');
const notify = require('../action/notify.js');

let peers = {};

/**
 * @param {Socket} socket
 * @param {User} user
 * @param {String} user.id
 * @param {Boolean} [initiator=false]
 * @param {MediaStream} [stream]
 */
function create({ socket, user, initiator, stream }) {
  debug('create peer: %s', user.id);
  notify.warn('Connecting to peer...');

  if (peers[user.id]) {
    notify.info('Cleaning up old connection...');
    destroy(user.id);
  }

  let peer = peers[user.id] = Peer.init({
    initiator: '/#' + socket.id === initiator,
    stream,
    config: {
      iceServers: [{
        url: 'stun:192.168.3.11',
        urls: 'stun:192.168.3.11'
      }, {
        url: 'turn:numb.viagenie.ca',
        credential: 'muazkh',
        username: '<EMAIL>'
      }]
    }
  });

  peer.once('error', err => {
    debug('peer: %s, error %s', user.id, err.stack);
    notify.error('A peer connection error occurred');
    destroy(user.id);
  });
{'fraction_non_alphanumeric': 0.2018140589569161, 'fraction_numerical': 0.0163265306122449, 'mean_word_length': 3.1544256120527305, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, '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': '6579216', 'n_tokens_mistral': 781, 'n_tokens_neox': 744, 'n_words': 166}