| 71 | } |
| 72 | |
| 73 | class PeerUI { |
| 74 | |
| 75 | html() { |
| 76 | return ` |
| 77 | <label class="column center" title="Click to send files or right click to send a text"> |
| 78 | <input type="file" multiple> |
| 79 | <x-icon shadow="1"> |
| 80 | <svg class="icon"><use xlink:href="#"/></svg> |
| 81 | </x-icon> |
| 82 | <div class="progress"> |
| 83 | <div class="circle"></div> |
| 84 | <div class="circle right"></div> |
| 85 | </div> |
| 86 | <div class="name font-subheading"></div> |
| 87 | <div class="device-name font-body2"></div> |
| 88 | <div class="status font-body2"></div> |
| 89 | </label>` |
| 90 | } |
| 91 | |
| 92 | constructor(peer) { |
| 93 | this._peer = peer; |
| 94 | this._initDom(); |
| 95 | this._bindListeners(this.$el); |
| 96 | } |
| 97 | |
| 98 | _initDom() { |
| 99 | const el = document.createElement('x-peer'); |
| 100 | el.id = this._peer.id; |
| 101 | el.innerHTML = this.html(); |
| 102 | el.ui = this; |
| 103 | el.querySelector('svg use').setAttribute('xlink:href', this._icon()); |
| 104 | el.querySelector('.name').textContent = this._displayName(); |
| 105 | el.querySelector('.device-name').textContent = this._deviceName(); |
| 106 | this.$el = el; |
| 107 | this.$progress = el.querySelector('.progress'); |
| 108 | } |
| 109 | |
| 110 | _bindListeners(el) { |
| 111 | el.querySelector('input').addEventListener('change', e => this._onFilesSelected(e)); |
| 112 | el.addEventListener('drop', e => this._onDrop(e)); |
| 113 | el.addEventListener('dragend', e => this._onDragEnd(e)); |
| 114 | el.addEventListener('dragleave', e => this._onDragEnd(e)); |
| 115 | el.addEventListener('dragover', e => this._onDragOver(e)); |
| 116 | el.addEventListener('contextmenu', e => this._onRightClick(e)); |
| 117 | el.addEventListener('touchstart', e => this._onTouchStart(e)); |
| 118 | el.addEventListener('touchend', e => this._onTouchEnd(e)); |
| 119 | // prevent browser's default file drop behavior |
| 120 | Events.on('dragover', e => e.preventDefault()); |
| 121 | Events.on('drop', e => e.preventDefault()); |
| 122 | } |
| 123 | |
| 124 | _displayName() { |
| 125 | return this._peer.name.displayName; |
| 126 | } |
| 127 | |
| 128 | _deviceName() { |
| 129 | return this._peer.name.deviceName; |
| 130 | } |
nothing calls this directly
no outgoing calls
no test coverage detected