MCPcopy Create free account
hub / github.com/SnapDrop/snapdrop / PeersUI

Class PeersUI

client/scripts/ui.js:16–71  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14});
15
16class PeersUI {
17
18 constructor() {
19 Events.on('peer-joined', e => this._onPeerJoined(e.detail));
20 Events.on('peer-left', e => this._onPeerLeft(e.detail));
21 Events.on('peers', e => this._onPeers(e.detail));
22 Events.on('file-progress', e => this._onFileProgress(e.detail));
23 Events.on('paste', e => this._onPaste(e));
24 }
25
26 _onPeerJoined(peer) {
27 if ($(peer.id)) return; // peer already exists
28 const peerUI = new PeerUI(peer);
29 $$('x-peers').appendChild(peerUI.$el);
30 setTimeout(e => window.animateBackground(false), 1750); // Stop animation
31 }
32
33 _onPeers(peers) {
34 this._clearPeers();
35 peers.forEach(peer => this._onPeerJoined(peer));
36 }
37
38 _onPeerLeft(peerId) {
39 const $peer = $(peerId);
40 if (!$peer) return;
41 $peer.remove();
42 }
43
44 _onFileProgress(progress) {
45 const peerId = progress.sender || progress.recipient;
46 const $peer = $(peerId);
47 if (!$peer) return;
48 $peer.ui.setProgress(progress.progress);
49 }
50
51 _clearPeers() {
52 const $peers = $$('x-peers').innerHTML = '';
53 }
54
55 _onPaste(e) {
56 const files = e.clipboardData.files || e.clipboardData.items
57 .filter(i => i.type.indexOf('image') > -1)
58 .map(i => i.getAsFile());
59 const peers = document.querySelectorAll('x-peer');
60 // send the pasted image content to the only peer if there is one
61 // otherwise, select the peer somehow by notifying the client that
62 // "image data has been pasted, click the client to which to send it"
63 // not implemented
64 if (files.length > 0 && peers.length === 1) {
65 Events.fire('files-selected', {
66 files: files,
67 to: $$('x-peer').id
68 });
69 }
70 }
71}
72
73class PeerUI {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected