all files / components/device-selection/ component.js

62.5% Statements 30/48
53.85% Branches 14/26
62.5% Functions 10/16
57.14% Lines 24/42
1 statement Ignored     
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131                                                        20×   20× 20× 19×               29×   29× 29× 29× 29×       20×   20× 19× 19×                   20×                                                                       31×         31×         29×           32×                    
/* global cheet */
 
// import LoggerMixin from 'web-directory/mixins/logger'
import Ember from 'ember';
import layout from './template';
 
const {computed, RSVP, Component, inject, run} = Ember;
 
export default Component.extend(/* LoggerMixin, */{
  layout: layout,
  classNameBindings: [':device-selection'],
 
  selectedCamera: null,
  selectedMicrophone: null,
  selectedResolution: null,
  selectedOutputDevice: null,
  selectedFilter: null,
 
  audio: true,
  video: true,
  troubleshoot: true,
 
  webrtc: inject.service(),
 
  audioCallCapable: computed.reads('webrtc.audioCallCapable'),
  videoCallCapable: computed.reads('webrtc.videoCallCapable'),
 
  didInsertElement () {
    this._super(...arguments);
 
    run.scheduleOnce('afterRender', () => {
      if (this.get('video')) {
        cheet('i n s t a', () => {
          this.set('advancedOptions', ['willow', 'sutro', 'lofi', 'kelvin', 'inkwell', 'sepia', 'tint', 'none']);
        });
      }
    });
  },
 
  didReceiveAttrs () {
    this._super(...arguments);
 
    this.send('changeCamera', this.get('selectedCamera.deviceId'));
    this.send('changeMicrophone', this.get('selectedMicrophone.deviceId'));
    this.send('changeResolution', this.get('selectedResolution.presetId'));
    this.send('changeOutputDevice', this.get('selectedOutputDevice.deviceId'));
  },
 
  willDestroyElement () {
    this._super(...arguments);
 
    if (this.get('video')) {
      cheet.disable('i n s t a');
      this.set('advancedOptions', null);
    }
  },
 
  selectedCameraId: computed.reads('selectedCamera.deviceId'),
  selectedResolutionId: computed.reads('selectedResolution.presetId'),
  selectedMicrophoneId: computed.reads('selectedMicrophone.deviceId'),
  selectedOutputDeviceId: computed.reads('selectedOutputDevice.deviceId'),
 
  showTroubleshoot: computed('troubleshoot', function () {
    return this.get('troubleshoot') && typeof this.attrs.openTroubleshoot === 'function';
  }),
 
  actions: {
    openTroubleshoot () {
      Eif (typeof this.attrs.openTroubleshoot === 'function') {
        this.attrs.openTroubleshoot();
      }
    },
 
    playTestSound () {
      const audio = this.$('.preview-audio')[0];
 
      const outputDevice = this.get('selectedOutputDevice');
 
      if (!audio || !outputDevice) {
        return;
      }
 
      if (!audio.play) {
        return console.warn('Audio playback not supported');
      }
 
      audio.muted = true;
      audio.currentTime = 0;
      const playPromise = audio.play() || RSVP.resolve();
      playPromise.then(() => {
        return this.get('webrtc').setOutputDevice(audio, outputDevice);
      }).then(() => {
        return audio.pause() || RSVP.resolve();
      }).then(() => {
        audio.muted = false;
        audio.currentTime = 0;
        audio.play();
      });
    },
 
    changeCamera (id) {
      if (this.get('selectedCamera.deviceId') !== id) {
        this.set('selectedCamera', this.get('webrtc.cameraList').findBy('deviceId', id));
      }
    },
 
    changeMicrophone (id) {
      if (this.get('selectedMicrophone.deviceId') !== id) {
        this.set('selectedMicrophone', this.get('webrtc.microphoneList').findBy('deviceId', id));
      }
    },
 
    changeOutputDevice (id) {
      Iif (this.get('selectedOutputDevice.deviceId') !== id) {
        this.set('selectedOutputDevice', this.get('webrtc.outputDeviceList').findBy('deviceId', id));
      }
    },
 
    changeResolution (id) {
      if (this.get('selectedResolution.presetId') !== id) {
        this.set('selectedResolution', this.get('webrtc.resolutionList').findBy('presetId', id));
      }
    },
 
    changeFilter (filter) {
      this.set('selectedFilter', filter);
    }
  }
});