Skip to content

Messages are doubled when using WebRTC #37

Open

Description

@Jiffer

When "private" connection is established messages on the receive end are printed twice (the on 'peer-msg' function is called twice).
Is it possible the socket it still open and it is sending now over both despite this line in goPrivate()? :
p2psocket.usesockets = false

Activity

  1. bennytheshap commented on Apr 21, 2017

    @bennytheshap

    +1

  2. NerveCoordinator commented on Aug 26, 2018

    @NerveCoordinator

    I am also getting this issue.

    As a bandaid solution, can check the time between the last message and only display it iff the difference is more than 10 milliseconds.

    It is strange because as far as I can tell the message is only emitted once, and doesn't go through the server. But this p2psocket.on('peer-msg', function (data) {} still fires twice. Couldn't figure out why.

    Should also be noted I'm using bundle.js instead of index.js. There is a lot more code in bundle.js, so something in there might make a difference? Haven't tried index.js to see.

  3. jasonkester commented on Apr 7, 2026

    @jasonkester

    I fixed this inadvertently while fixing #55

    After the below (copy/pasted from that issue), I went back to tackle the double-message issue and found it had gone away.

    I was able to fix this by setting trickle: true in that peerOpts object.

    That fixed the problem, but introduced a new one where the server would crash if either browser reloaded. The fix for that was to modify socket.io-p2p-server.js to not try to use client methods if the client doesn't exist. As in:

    Line 44:

    client?.emit('peer-signal', data)
    

    That little question mark is all it took. I pulled the file out of node modules and am now referencing it directly. At some point somebody who cares about such things should make a PR for that project.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions