Skip to content

myPeer.on('data') firing twice, how to check if a connection already exists or not #1104

Closed Answered by newmediacrew
newmediacrew asked this question in Q&A
Discussion options

You must be logged in to vote

The problem has been solved. I turns out

 // receive file
    myPeer.on('connection', (conn) => {
        conn.on('data', (data) => {
            console.log('here we save the file, which is firing multiple times when repeating this action on the sender side');           
            // socketCtbMethod.saveFile(data);
            conn.close();
            // let the receiver know we received the file and are done.
            socketCtbMethod.sendFileFinishedChannelMessage(peerJsId, payload.data.resourceId)
                .then((data) => {
                })
        });
    });

was inside an event listerner block triggering multiple times. Moving it outside solved the problem.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@newmediacrew
Comment options

@newmediacrew
Comment options

Answer selected by newmediacrew
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1103 on July 12, 2023 06:58.