chr15m / bugout

Back end web app services over WebRTC.
https://chr15m.github.io/bugout
MIT License
603 stars 59 forks source link

How do I RPC a client in a P2P room? #57

Closed hello-smile6 closed 2 years ago

hello-smile6 commented 2 years ago

I am making a P2P social media app and want to use RPC calls to retrieve data. Should I connect to the peer address, or is there another way?

hello-smile6 commented 2 years ago

I'll just pass a WebTorrent() instance to all of my Bugout instances.

draeder commented 2 years ago

Register your RPC:

  b.register("ping", function(address, args, cb) {
    args["pong"] = Math.random(); // this is the RPC action
    cb(args);
  });

Create a listener for your RPC:

  b.on("rpc", function(address, call, args) { 
    console.log("rpc:", address, call, args);
  });