Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A new extension to send plain chat message to peer #4

Closed
vairabagni opened this issue Jul 6, 2015 · 2 comments
Closed

A new extension to send plain chat message to peer #4

vairabagni opened this issue Jul 6, 2015 · 2 comments

Comments

@vairabagni
Copy link

How can I use this extension or ut_metadata or by creating a new one to be able to send messages to other peer (chat message) ?

I just started by creating a new extension which i am thinking of integrating that into webtorrent. So I modified torrent.js (inside webtorrent, ln 463) - _onWire callback - this block is same as that of ut_pex.

if (typeof ut_message === 'function') {
    wire.use(ut_message())

    //wire.ut_message.start() // TODO two-way communication
    wire.ut_message.on('peer', function (peer) {
      debug('ut_message: got peer: %s (from %s)', peer, addr)
      self.addPeer(peer)
    })

    wire.ut_message.on('dropped', function (peer) {
      // the remote peer believes a given peer has been dropped from the swarm.
      // if we're not currently connected to it, then remove it from the swarm's queue.
      debug('ut_message: dropped peer: %s (from %s)', peer, addr)
      var peerObj = self.swarm._peers[peer]
      if (!peerObj || !peerObj.conn) self.swarm.removePeer(peer)
    })
  }

Is it required? Or i can just use any extension (ut_metadata, ut_pex or mine - ut_message) as:

torrent.swarm.on("wire", function(wire) {
    console.log("onwire - " + wire.peerId + " - " + wire.remoteAddress + ':' + wire.remotePort);

    wire.on('extended', function (ext, obj) {
        console.log('extended', ext, obj.toString());
    });
    wire.use(ut_message()); 
        //or
        wire.use(ut_metadata());
        //or
    wire.use(ut_pex()); 

    wire.extended(3, 'hello'); //first param will be either 1, 2 or 3
});
@feross
Copy link
Member

feross commented Jul 6, 2015

Duplicate of webtorrent/webtorrent#368

@transitive-bullshit
Copy link
Member

Closing as question is handled in duplicate thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants