11 ms·
PeerJS – Simple peer-to-peer with WebRTC
- wesz 6y agoMy own attempt at creating simple to use wrapper for WebRTC: https://github.com/wesz/Peer https://github.com/wesz/Peer
- ht96 6y agoCan anyone recommend something this simple but for multi party conferencing like Zoom
- lxgr 6y agoMultiparty conferencing without a media relay is difficult, as bandwidth requirements scale quadratically with the number of participants for a full mesh topology. You can also have the participant with the beefiest connection act as such a relay, but if every participant is on a metered or upload limited connection, that's not an option. It's pretty sad actually: We seem to be caught in a perpetual catch-22 of "nobody needs public IP reachability and symmetric bandwidth for home connection, since everyone uses beefy cloud servers anyway" and "we need beefy cloud servers because home connections are asymmetric and NATs are horrible"...
- kwindla 6y agocpu usage on each client is also an issue. Architecturally, WebRTC connections are always peer-to-peer, in the sense that each transport carrying media is negotiated individually and does its own bandwidth shaping. This has some really nice properties. Doing the bandwidth shaping individually for each transport maximizes video quality for each track, but it also means that in an N-way call you have to encode your outgoing video N-1 times. Even with a perfect network connection, you run out of cpu to do the encoding at some point. Today, on a pretty new-ish laptop the limit for how many outgoing videos you can encode (<waves hands about codecs and settings>) is ~10. On an older Android phone that limit is ~1. It's possible to imagine changing how WebRTC works so that separate transports can reuse encoded streams. And hopefully that will become possible at some point (https://www.w3.org/TR/webrtc-nv-use-cases/ https://www.w3.org/TR/webrtc-nv-use-cases/). But not anytime soon. :-(
- Sean-Der 6y agoWhat you will want is a SFU. This is a non-exhaustive list, if others want to chime in would appreciate it! * https://galene.org https://galene.org * https://github.com/pion/ion https://github.com/pion/ion * https://github.com/peer-calls/peer-calls https://github.com/peer-calls/peer-calls * https://github.com/meetecho/janus-gateway https://github.com/meetecho/janus-gateway * https://github.com/versatica/mediasoup https://github.com/versatica/mediasoup * https://github.com/jitsi/jitsi-meet https://github.com/jitsi/jitsi-meet * https://github.com/fox-one/mornin.fm https://github.com/fox-one/mornin.fm
- amelius 6y agoHow about: https://jami.net/ https://jami.net/ (Official GNU software for video calls and more)
- lrossi 6y agoThey might want to update their demo page. The only demo link leads to a parked domain thingy with just ads.
- capableweb 6y agoFun fact about PeerJS, you'll need a server in order to use it (look into STUN/TURN/ICE for more info). The maintainer seems to be hosting one default instance that goes down from time to time. https://github.com/peers/peerjs/issues/671 https://github.com/peers/peerjs/issues/671 https://github.com/peers/peerjs/issues/693 https://github.com/peers/peerjs/issues/693 If you're looking to do "pure" P2P in the browser, we're not there yet as we cannot accept incoming connections without something in between right now.
- tantalor 6y agoDoes LAN work without internet connection?
- capableweb 6y agoTested this a couple of years ago and Chrome prevented WebRTC connections from ever establishing if you're not connected to internet proper (it was doing some lookup to a Google domain before trying to actually create the WebRTC connection, even if I had nothing to do with Google, and stopped the attempt if it couldn't connect). Might have changed by now.
- dnautics 6y agoIf memory serves me right it's a security issue, webrtc only allows connections when proper ssl certs exist on the initial brokered handshake, so you would only be able to do this if your lan has some sort of self signed ssl root cert and the cert placed in each machines authoritative cert stash.
- lxgr 6y agoWebRTC doesn't use any public CA certificates to my knowledge. DTLS-SRTP uses self-signed certificates on both sides, with the certificate hashes or key fingerprints being included in the SDP signalling messages. Maybe you're thinking of the "secure origin" requirement? (The page hosting the JS needs to be a "trusted context", i.e. no file:// and no http:// http://)
- KaoruAoiShiho 6y agoIt's honestly too simple, more work has to be done to get it to be actually useful and scalable.
- capableweb 6y agoSuch a strange wording. Sounds like you're saying "It's too simple, we need to make it more not-simple" while anyone would agree that simple is better than non-simple. What if it can be simple, useful and scalable? That's the ideal I think.
- cakoose 6y agoI don't think it's categorically wrong to say something is too simple. There are accepted terms for that: over-simplification, simplistic. There's also the Einstein line: "Everything should be made as simple as possible, but no simpler." I have no idea if PeerJS is actually too simple, but the "shape" of KaoruAoiShiho's statement seems fine.
- superkuh 6y agoNo application implemented within a browser is "simple". It's obfuscated and hidden complexity of a scale so large than only mega-corps are capable of handling, and so chosing, which directions things go. Simple would be a real application not subject to the constant churn and complexity of corporate driven web.
- deleted 6y ago[deleted]
- michjedi 6y agoThis stopped being supported half a decade ago
- corytheboyd 6y agoWhat? I see both the client and server repositories have activity in the last month
- devmor 6y agoPeerJS only came out half a decade ago.
- mrozbarry 6y agoI tried PeerJS in a pet project a few months ago. The one thing that became immediate is peer to peer over browsers isn't great. You can basically throw testing out the window, there is no good way to emulate p2p locally. Trying to test my PeerJS project involved having two computers, and occasionally required one to be connected through a VPN. Problems I found was connecting over LAN was really flaky. Most times, Chrome to Chrome was fine. Chrome to firefox was also mostly fine. Firefox to Firefox had a pile of quirks - connections only worked if I completely quit firefox, and started it again with just my two windows, and even then, sometimes that connection failed. The ICE/Turn server stuff is also a mess. I ended up installing and hosting a coturn server on digital ocean, and it was a pain. Documentation wasn't great, stackoverflow/forum questions were typically old, and there didn't appear to be any obvious alternatives. I also tried simple-peer by feross, which seemed to be fine, and most quirks remained as browser issues. I ended up ditching webrtc and went with a server with websockets. With peer to peer, I'm stuck using a server somewhere, so I'd rather use a websocket server. Webrtc just introduced too many unknown variables. Is there a problem with an ICE/Turn server? Is there a LAN issue? Can browsers vendors properly do p2p to each other without a bunch of "if firefox, do this, if chrome, do this, if something else, panic"? The websocket server took 100% of these concerns out of the equation. I'd love to be able to use webrtc confidently, but with the current tools for implementing and testing, I don't think I can say it is for myself. So I think the TLDR is that webrtc peer to peer isn't really consumer-ready. The browser support seems a little hit and miss, testing through a LAN appears to be very flaky, and testing via node/some other framework is spotty at best.
- corytheboyd 6y agoI’m curious, does your solution not need audio and/or video? I could agree that WebRTC is overkill if only data channels are used, but AV blows complexity up massively doesn’t it?
- mrozbarry 6y agoAudio and video would have been a nice to have, which is why I was going this route. I also wanted the data to never touch an external server so users could know their data is as safe as the people they share it with. The data for this app, by nature, isn't important to have a history, so just being able to share data immediately was all I needed, and p2p seemed like the optimal first step. I cut out audio and video from my features, and for the most part, things are working just fine.
- ScottyFillups 6y agoIf anyone is looking for an alternative to PeerJS, I highly recommend simple-peer by feross: https://github.com/feross/simple-peer https://github.com/feross/simple-peer I created multi party P2P audio/video chat in ~200 lines of code a while back, here it is: https://github.com/ScottyFillups/p2pchat https://github.com/ScottyFillups/p2pchat (see room.js and all the files under client/) Demo page is here: https://scottyfillups.io/p2pchat https://scottyfillups.io/p2pchat
- wintorez 6y agoI love his work. His "webtorrent" is also great. I always wondered if anyone is using it on their website to lower the cost of distributing large files.
- depressedpanda 6y agoHow would you say simple-peer compares to PeerJs? Pros/cons? I've had issues with PeerJs in that connections are randomly dropped after a while, and couldn't figure out why.
- feross 6y agoThanks for mentioning simple-peer! It's been humbling to see all the clever ways that people have used it to build clever and interesting apps.
- qeternity 6y agoThere's a big opportunity in the rtc space for someone to build a lib/service that "just works". We built a probject that started with peerjs for the prototype and then moved to simple-peer for the prod version, but it's still a nightmare in webrtc land. All sorts of random errors and quirks, connection glaring, reconnect handling, etc. This is still very much an unsolved problem.
- mattanimation 6y agotrue that. Every time I've used WebRTC it ended up way more complicated then it initially set out to be. Pion is actually pretty nice though
- Sean-Der 6y agoThanks :) if there is anything I can do to make it better I would love to hear!
- Sean-Der 6y agoI worked at a job that was trying to do this. The issue they ran into was money. * Signaling wasn't a big money maker. You are just exchanging small blobs. * We spent a lot of time helping people debug their networks/explaining WebRTC and making SDKs. I enjoyed the work, but didn't feel like it scaled well. * Adding features caused major paralysis. Everyone wanted different authentication or different signaling patterns etc...
- qeternity 6y agoSignalling is actually the easy part, as I'm sure you know. It was everything else that you take for granted when doing voice comms: auth, handshakes, reconnects, etc. They all seem really simple, until you actually sit down to do it yourself. Mad props to the FaceTime crew...nobody else has mastered seamless RTC the way they have.
- corytheboyd 6y agoWould you be open to having a brain dump chat? I want to deliver some WebRTC solutions in the near future but haven’t done this before, would be awesome to just pick someone’s brain about what happens after release :)
- Sean-Der 6y agohttps://github.com/muka/peerjs-go https://github.com/muka/peerjs-go is a Go implementation. I believe there is also effort to make a Python one. It is pretty exciting to have such an easy way to have processes in different languages (and different networks!) communicate. I would really love to find a way to drop the server dependency even https://sean-der.github.io/webrtc-uri/draft-seaduboi-webrtc-uri.html https://sean-der.github.io/webrtc-uri/draft-seaduboi-webrtc-... mDNS/Zerconf would be amazing. Even if it just works between WebRTC Agents and not the browser.
- arange 6y agohere's a really great article by the people who wrote WireGuard as to why P2P is really hard to do: https://tailscale.com/blog/how-nat-traversal-works/ https://tailscale.com/blog/how-nat-traversal-works/
- kim0 6y agoTailscale is just a commercial VPN provider, they did not create WG
- dest 6y agoCheck out https://streamroot.io https://streamroot.io if you want to work professionally on this kind of thing (demo at the bottom)
- wortmanager 6y agoI bounced off the documentation for STUN/TURN servers about a month ago when I was trying to make a chrome addon to stream a tab to a group of people who click a link. I also got hung up on trying to use WebRTC with Next.js Might be time to simplify my stack a little and try again.
- dangerboysteve 6y agoThe demo link looks like it redirects to a fake virus warning site. https://peerjs.com/examples.html https://peerjs.com/examples.html
- nashashmi 6y agoOT: I was trying to use this for a glorified multi-stream mobile video casting to a Zoom streaming server. I used a nodejs instance which was very easy to set up. But I could not find a solution for an in browser mobile weberc video solution. Pretty much all implementations went through an app.
- godot 6y agoWow, this seems really cool. I've looked into WebRTC before and every time I try to read the specs to see if I can implement something, I was turned away by how difficult it seems to be to get everything going to do hello world examples. This seems to simplify all of that and I'd love to try it out some time. Related question, does anyone know how heavy of a load is a STUN/TURN server? If I build a hobby project using this, and use a (for example) Heroku free tier dyno to host a STUN/TURN nodejs server, how many users/traffic can I expect to be able to run?
- corytheboyd 6y agoIt’s only used to negotiate connections, not transmit data, so in theory the load isn’t constant or heavy. I don’t have experience running this in production yet, have just done tons of reading and a moderate amount of prototyping
- miohtama 6y agoAlso see libp2p for complex use cases https://github.com/libp2p/js-libp2p-webrtc-star https://github.com/libp2p/js-libp2p-webrtc-star
- markkudlac 6y agoI used PeerJS for a project, http://subsect.net http://subsect.net , that has been running for a few years. I have run my own PeerServer on Heroku all of that time without incident. I have tested connectivity over WebRTC from many places around the world and have never had a problem other than from the lobbies of some banks as it seems they generally block IP traffic. WebRTC is a transitional technology and I look forward to the day blocks of IPv6 addresses are granted free to all people at birth and fixed addresses are supported on all devices.