<commit_before>/* eslint-env browser */
/* global ciscospark */
/* eslint-disable camelcase */
/* eslint-disable max-nested-callbacks */
/* eslint-disable no-alert */
/* eslint-disable no-console */
/* eslint-disable require-jsdoc */

// Declare some globals that we'll need throughout
let spark;

// First, let's wire our form fields up to localStorage so we don't have to
// retype things everytime we reload the page

[
  `access-token`,
  `invitee`
].forEach((id) => {
  const el = document.getElementById(id);
  el.value = localStorage.getItem(id);
  el.addEventListener(`change`, (event) => {
    localStorage.setItem(id, event.target.value);
  });
});

// There's a few different events that'll let us know we should initialize
// CiscoSpark and start listening for incoming calls, so we'll wrap a few things
// up in a function.
function connect() {
  if (!spark) {
    spark = ciscospark.init({
      credentials: {
        access_token: document.getElementById(`access-token`).value
      }
    });
  }

  if (!spark.phone.registered) {
    // we want to start listening for incoming calls *before* registering with
    // the cloud so that we can join any calls that may already be in progress.
    spark.phone.on(`call:incoming`, (call) => {
      // Let's get the name of the person calling us; in production, you'd
      // probably want to cache this so that you're not adding latency on
      // incoming calls
      // FIXME: this is a temporary hack until the people batcher gets fixed
      spark.people.get(atob(call.from.personId).split(`/`).pop())
        .then((person) => {
          if (confirm(`Answer incoming call from ${person.displayName}`)) {
            call.answer({
              constraints: {
                audio: true,
                video: true,
                // add a query string parameter for controlling use of fake
                // media or the default camera (note, this is firefox-only)
                fake: location.search.toLowerCase().includes(`usefakemedia`)
              }
            });
            bindCallEvents(call);
          }<commit_msg>fix(samples): handle PSTN users for incoming calls<commit_after>/* eslint-env browser */
/* global ciscospark */
/* eslint-disable camelcase */
/* eslint-disable max-nested-callbacks */
/* eslint-disable no-alert */
/* eslint-disable no-console */
/* eslint-disable require-jsdoc */

// Declare some globals that we'll need throughout
let spark;

// First, let's wire our form fields up to localStorage so we don't have to
// retype things everytime we reload the page

[
  `access-token`,
  `invitee`
].forEach((id) => {
  const el = document.getElementById(id);
  el.value = localStorage.getItem(id);
  el.addEventListener(`change`, (event) => {
    localStorage.setItem(id, event.target.value);
  });
});

// There's a few different events that'll let us know we should initialize
// CiscoSpark and start listening for incoming calls, so we'll wrap a few things
// up in a function.
function connect() {
  if (!spark) {
    spark = ciscospark.init({
      credentials: {
        access_token: document.getElementById(`access-token`).value
      }
    });
  }

  if (!spark.phone.registered) {
    // we want to start listening for incoming calls *before* registering with
    // the cloud so that we can join any calls that may already be in progress.
    spark.phone.on(`call:incoming`, (call) => {
      // Let's get the name of the person calling us; in production, you'd
      // probably want to cache this so that you're not adding latency on
      // incoming calls
      spark.people.get(call.from.personId)
        .catch((err) => {
          // Fallback to the person id if we can't look up the person object.
          // This can happen if the call is coming from a telephone number
          // instead of a spark account.
          console.warn(err);
          return call.from.personId;
        })
        .then((person) => {
          if (confirm(`Answer incoming call from ${person.displayName || person}`)) {
            call.answer({
              constraints: {
                audio: true,
                video: true,
                // add a query string parameter for controlling use of fake
                // media or the default camera (note, this is firefox-only)
                fake: location.search.toLowerCase().includes(`usefakemedia`)
              }
            });
            bindCallEvents(call);
          }
{'fraction_non_alphanumeric': 0.11495285136955545, 'fraction_numerical': 0.0, 'mean_word_length': 2.387832699619772, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, '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': '531157', 'n_tokens_mistral': 1241, 'n_tokens_neox': 1200, 'n_words': 427}