intents.js 524 B

1234567891011121314151617181920
  1. /* eslint-disable no-console */
  2. export default function intentHandler(state, emitter) {
  3. window.addEventListener(
  4. 'message',
  5. event => {
  6. if (typeof event.data !== 'string' || !event.data.startsWith('data:')) {
  7. return;
  8. }
  9. fetch(event.data)
  10. .then(res => res.blob())
  11. .then(blob => {
  12. emitter.emit('addFiles', { files: [blob] });
  13. emitter.emit('upload', {});
  14. })
  15. .catch(e => console.error('ERROR ' + e + ' ' + e.stack));
  16. },
  17. false
  18. );
  19. }