<commit_before>var twilio = require('twilio')
var winston = require('winston')

if (process.env.TWILIO_SID && process.env.TWILIO_TOKEN) {
  var client = twilio(process.env.TWILIO_SID, process.env.TWILIO_TOKEN)
} else {
  var client = null
}

var CACHE_LIFETIME = 5 * 60 * 1000 // 5 minutes
var cachedPromise = null

function clearCache() {
  cachedPromise = null
}

exports.getICEServers = function () {
  if (client == null) return Promise.resolve({})
  if (cachedPromise) return cachedPromise

  cachedPromise = new Promise(function (resolve, reject) {
    client.tokens.create({}, function(err, token) {
      if (err) {
        winston.error(err.message)
        return resolve({})
      }

      setTimeout(clearCache, CACHE_LIFETIME)
      resolve(token.ice_servers)
    })
  })

  return cachedPromise
}<commit_msg>return default ice servers when not using twilio<commit_after>var twilio = require('twilio')
var winston = require('winston')

if (process.env.TWILIO_SID && process.env.TWILIO_TOKEN) {
  var client = twilio(process.env.TWILIO_SID, process.env.TWILIO_TOKEN)
} else {
  var client = null
}

var DEFAULT_ICE_SERVERS = [
  {
    url: 'stun:192.168.127.12', // deprecated, replaced by `urls`
    urls: 'stun:192.168.127.12'
  }
]

var CACHE_LIFETIME = 5 * 60 * 1000 // 5 minutes
var cachedPromise = null

function clearCache() {
  cachedPromise = null
}

exports.getICEServers = function () {
  if (client == null) return Promise.resolve(DEFAULT_ICE_SERVERS)
  if (cachedPromise) return cachedPromise

  cachedPromise = new Promise(function (resolve, reject) {
    client.tokens.create({}, function(err, token) {
      if (err) {
        winston.error(err.message)
        return resolve({})
      }

      setTimeout(clearCache, CACHE_LIFETIME)
      resolve(token.ice_servers)
    })
  })

  return cachedPromise
}
{'fraction_non_alphanumeric': 0.12165848336061102, 'fraction_numerical': 0.020731042007637753, 'mean_word_length': 3.619647355163728, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '2670841', 'n_tokens_mistral': 654, 'n_tokens_neox': 610, 'n_words': 137}