snapdrop

A Progressive Web App for local file sharing
git clone http://git.hanabi.in/repos/snapdrop.git
Log | Files | Refs | README | LICENSE

commit 5efd9a3bba86fa0d1084afd2af40d990845dbd95
parent 662a2e48dec193a73c4a2c557fee4351b83b7e9c
Author: CJ <sonicblis@users.noreply.github.com>
Date:   Tue,  3 Mar 2020 09:15:32 -0500

Paste image content from the clipboard

This allows someone to take a screen capture and send it to a peer without having to save it as a file.  This only works if only one peer is connected as I wasn't sure what the UI flow should be if there are multiple peers.  If nothing else, maybe this can be used to implement the full flow for multiple peers. =]
Diffstat:
Mclient/scripts/ui.js | 23++++++++++++++++++++---
1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/client/scripts/ui.js b/client/scripts/ui.js @@ -11,7 +11,8 @@ class PeersUI { Events.on('peer-joined', e => this._onPeerJoined(e.detail)); Events.on('peer-left', e => this._onPeerLeft(e.detail)); Events.on('peers', e => this._onPeers(e.detail)); - Events.on('file-progress', e => this._onFileProgress(e.detail)); + Events.on('file-progress', e => this._onFileProgress(e.detail)); + window.addEventListener('paste', e => this._onPaste(e)); } _onPeerJoined(peer) { @@ -40,6 +41,23 @@ class PeersUI { _clearPeers() { const $peers = $$('x-peers').innerHTML = ''; + } + + _onPaste(e) { + const files = e.clipboardData.items + .filter(i => i.type.indexOf('image') > -1) + .map(i => i.getAsFile()); + + // send the pasted image content to the only peer if there is one + // otherwise, select the peer somehow by notifying the client that + // "image data has been pasted, click the client to which to send it" + // not implemented + if (files.length > 0 && $$('x-peer').length === 1) { + Events.fire('files-selected', { + files: files, + to: $$('x-peer').id + }); + } } } @@ -613,4 +631,4 @@ document.body.onclick = e => { // safari hack to fix audio document.body.onclick = null; if (!(/.*Version.*Safari.*/.test(navigator.userAgent))) return; blop.play(); -} -\ No newline at end of file +}