peerjs icon indicating copy to clipboard operation
peerjs copied to clipboard

Documentation on connections

Open ineiti opened this issue 4 years ago • 4 comments

Hi there - I'm trying to understand how peerjs works, in order to write a rust crate that supports it (of course I'd be happy to hear that such a thing already exists ;)

From what I read in the code, there are two connections set up between a client and the peerjs-server:

  • one websocket connection
  • one (or more?) connection for the REST-calls to offer/candidate/answer/leave

From what I understand, if node1 wants to connect to node2, they each need to be connected to the server using websockets. Then node1 makes a POST-request with an offer to the server. This request will be sent over the websocket to node2.

What I don't understand is: why do you use the REST calls at all? Couldn't you keep all the communication through the websocket?

Is there any low-level documentation other than the source code?

ineiti avatar Jan 17 '21 17:01 ineiti

From what I know about the library, the REST API is only used to get a unique id and to list all peers (https://github.com/peers/peerjs/blob/master/lib/api.ts). Everything else is send over the websocket.

DirkHeinke avatar Mar 06 '21 16:03 DirkHeinke

Yes, this is what I understood. As I'm writing my own signalling server in rust, I wondered whether there is a good reason to have two protocols instead of one. But so far it works very nice with only one protocol (websockets), so I'll keep that.

ineiti avatar Mar 08 '21 06:03 ineiti

Hi, is your Rust implementation available? Would love to try it out :)

lingosandi avatar Aug 30 '23 17:08 lingosandi

You can find it here:

https://crates.io/crates/flnet

Be sure to check out the documentation. I also have a running example here:

https://web.fledg.re

ineiti avatar Aug 31 '23 06:08 ineiti