javascript – WebRTC on shared hosting ( SSH ) without nodejs, preferrably in php

As far as I know, there is no way to re-use the same RTCPeerConnection for multiple peers, so you’ll have to do the same thing as 1-on-1 but between every single peer in a group.

As far as signalling, it’s pretty simple, goes kind of like this:

Client A -> [Offer] -> Server -> [Offer] -> Client B -> [Answer] -> Server -> [Answer] -> Client A

A nicer explanation at MDN

There isn’t necessarily a need for NodeJS or WebSocket. The reason most people go for it it is because the last link in this chain (Server -> Client A) requires server-initiated connection. But that can be substituted with alternative techniques such as (long-)polling. Or, in case of PHP, you might use websocket implementations such as Bloatless or Aerys

To implement the room functionality, you’ll have to implement the following:

Variant A (using polling):

  • An endpoint to throw offers at, e.g. POST /rooms/{id}

  • An endpoint to regularly check for new offers from, e.g. GET /rooms/{id}

Variant B (with websockets)

  • Create a broadcast rooms, for example, by dynamically creating HTTP endpoints and websocket server instances. Or by having a single websocket instance but sending whatever room you’re intending to join right inside after establishing a connection. From there, it’s only a matter of sending correct offers and answers to correct users.

In both cases, you might want to either create multiple offers in advance to pool from the server, or to dynamically create new ones, but, most importantly, make sure you’re not connecting the same peers twice, otherwise you will end up with a loop. To prevent it, just provide each user with a randomly generated string to identify themself and send it among offers.

There are turnkey solutions available if you don’t want to go this route, but be careful and check whether you can use your own TURN servers with them. A common trend I have noticed is that there are a lot of WebRTC solution providers out there that lure you with their simplicity but then lock you in with their own TURN servers for which you might have to pay a quite hefty bill later on.

Read more here: Source link