Skip to content

Uncaught TypeError: Cannot read property 'cancel' of null #4

Description

@nat-pierce

Hi,

I am unsure if I am using this library correctly, I'm admittedly new to simple-peer altogether and recently discovered your library. I am trying to send multiple files from one browser to another (one at a time).

I managed to get multiple files to send with the following workflow:

  1. When User A presses the send button, User A calls:
    peer.send('PREPARING_TO_SEND');
  2. When User B receives the message, User B calls:
peer.on('data', data => {
            if (data === 'PREPARING_TO_SEND') {
                spf.receive(peer, `photo_${numPhotos}`).then(transfer => {
                    transfer.on('done', file => {
                        this.addPhoto(file);
                    });
                });

                peer.send('READY_FOR_FILE');
            }
        })
  1. When User A receives the message, User A calls:
peer.on('data', data => {
            if (data === 'READY_FOR_FILE') {
                spf.send(peer, `photo_${numPhotos}`, this.fileToSend).then(transfer => {
                    transfer.on('done', () => {
                        numPhotos++;
                        this.fileToSend = null;
                    });
        
                    transfer.start()
                })
            }
        })

This all seems to work, but every photo sent I get the following console error:

Uncaught TypeError: Cannot read property 'cancel' of null
    at Peer.<anonymous> (index.js:60)

Where line 60 is here:

pfs.on('done', destroy);
                pfs.on('cancel', destroy);
                fileChannel.on('close', function () {
 ---->              pfs.cancel();
                });

What's going on here? Do I need to call spf.receive before each file like I'm doing? I tried just calling it once but I got the same error where the file channel would close.

There are no errors coming from my server (and neither user has left the room), and the receiver browser has no errors either

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions