<commit_before>import {Component, PropTypes} from 'react';

import {Howl} from 'howler';

import RingtoneIncoming from './media/Ringtone.mp3';
import RingtoneRingback from './media/Ringback_v2.mp3';

export const RINGTONE_TYPE_INCOMING = `RINGTONE_TYPE_INCOMING`;
export const RINGTONE_TYPE_RINGBACK = `RINGTONE_TYPE_RINGBACK`;

class Ringtone extends Component {
  constructor(props) {
    super(props);
    let src;
    switch (props.type) {
    case RINGTONE_TYPE_INCOMING:
      src = RingtoneIncoming;
      break;
    case RINGTONE_TYPE_RINGBACK:
      src = RingtoneRingback;
      break;
    default:
    }

    this.audio = new Howl({
      src: [src],
      loop: true
    });
  }

  componentDidMount() {
    if (this.props.play) {
      this.audio.play();
    }
  }

  componentWillReceiveProps(nextProps) {
    if (!nextProps.play && this.props.play) {
      this.audio.stop();
    }
    else if (nextProps.play && !this.props.play) {
      this.audio.play();
    }
  }

  shouldComponentUpdate() {
    return false;
  }

  componentWillUnmount() {
    this.audio.unload();
  }

  render() {
    return null;
  }
}

Ringtone.propTypes = {
  play: PropTypes.bool,
  type: PropTypes.oneOf([RINGTONE_TYPE_INCOMING, RINGTONE_TYPE_RINGBACK]).isRequired
};

export default Ringtone;<commit_msg>fix(react-component-ringtone): Add try/catch for creating audio<commit_after>import {Component, PropTypes} from 'react';

import {Howl} from 'howler';

import RingtoneIncoming from './media/Ringtone.mp3';
import RingtoneRingback from './media/Ringback_v2.mp3';

export const RINGTONE_TYPE_INCOMING = `RINGTONE_TYPE_INCOMING`;
export const RINGTONE_TYPE_RINGBACK = `RINGTONE_TYPE_RINGBACK`;

class Ringtone extends Component {
  constructor(props) {
    super(props);
    let src;
    switch (props.type) {
    case RINGTONE_TYPE_INCOMING:
      src = RingtoneIncoming;
      break;
    case RINGTONE_TYPE_RINGBACK:
      src = RingtoneRingback;
      break;
    default:
    }
    try {
      this.audio = new Howl({
        src: [src],
        loop: true
      });
    }
    catch (error) {
      console.warn(`Audio not available`, error); // eslint-disable-line no-console
    }
  }

  componentDidMount() {
    if (this.props.play && this.audio) {
      this.audio.play();
    }
  }

  componentWillReceiveProps(nextProps) {
    const audio = this.audio;
    if (audio) {
      if (!nextProps.play && this.props.play) {
        audio.stop();
      }
      else if (nextProps.play && !this.props.play) {
        audio.play();
      }
    }
  }

  shouldComponentUpdate() {
    return false;
  }

  componentWillUnmount() {
    if (this.audio) {
      this.audio.unload();
    }
  }

  render() {
    return null;
  }
}

Ringtone.propTypes = {
  play: PropTypes.bool,
  type: PropTypes.oneOf([RINGTONE_TYPE_INCOMING, RINGTONE_TYPE_RINGBACK]).isRequired
};

export default Ringtone;
{'fraction_non_alphanumeric': 0.12170596393897365, 'fraction_numerical': 0.0020804438280166435, 'mean_word_length': 2.9466484268125854, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1374589', 'n_tokens_mistral': 1038, 'n_tokens_neox': 1002, 'n_words': 189}