WebRTC - Can it be done or I'm talking about sci-fi?

63 views
Skip to first unread message

Robbi

unread,
Sep 26, 2022, 3:36:20 PMSep 26
to Chromium Extensions
I'm taking some interest in WebRTC technology.
I've read several articles and will probably have to read more.
Without shame, I affirm that I don't think I understand much about it.
I would have in mind to accomplish a certain thing, but I'm not sure if this is fully feasible, so I ask you to avoid finding myself in a dead end.

An MV2 extension of mine is ready on the CWS, but it's not public since it's only used within the organization where I work.
There is a simple tool inside it that allows to search for colleagues contact inside the company phonebook.
In the search results I would like to add a led indicator (green\red light) that tells me if the colleague in the list is online or not.
I'd like to have, obviously only for online users, the possibility to establish a peer to peer connection and exchange text messages (no audio\video, at least for the moment).
Since I stated I'm in a LAN and would like to exchange one-to-one messages ONLY WITHIN THIS NETWORK, my main question is:

Can I carry out this exchange of messages without the aid of a server?
If the answer is YES:
Wow, good news!
Would you give me some tips, or some links where to get inspiration and start with the first lines of code?

If the answer is NO:
If I need some kind of server, (1) does that server (STUN, if I have not misunderstood) must physically reside inside the LAN or can an external server be considered as well? (i.e. Web Hosting service).

(2) Could the server-side code be written in PHP preferably using the TCP protocol (no WebSocket or UDP)?
If there were any adaptable PHP code snippets, that would be great ;-)
   
Thank you in advance.

T S

unread,
Sep 26, 2022, 5:14:53 PMSep 26
to Chromium Extensions, Robbi
WebRTC requires some form of signaling to initiate a connection.  This layer is unspecified, it's simply required that you can exchange a few pieces of json between the two clients.  So, realistically, you need some kind of server to act as your signaling layer.  There are plenty of free cloud services that could do the job here - anything that facilitates data transfer would work.  Firebase?  HiveMQ?

You don't need a STUN server if you're only talking to local peers, if your network configuration is such that there are no NAT layers between peers.
If you did need one, by definition STUN servers must be past your NAT, generally on the external internet.  They wouldn't work otherwise.

The server code literally just moves json back and forth between the two clients so they have the details necessary to connect, so if you're happiest doing that with PHP, sure.  You're not really going to find specific examples for WebRTC here, because its signaling can be provided by almost anything.  Once the clients have connected, the signaling layer plays no further role.

There's way too many webrtc tutorials on the web for me to be able to recommend any one in particular, but it can't hurt to start at https://webrtc.org/getting-started/peer-connections

T S

unread,
Sep 26, 2022, 5:21:06 PMSep 26
to Chromium Extensions, T S, Robbi
(The only real pain point here is the fact that, due to the MV3 service worker's lifespan issues, you have to do some horribly contrived things if you want your extension to be able to e.g. maintain a websocket or poll a server for connection requests.  You might genuinely be better off just doing this in a regular web app and encouraging users to pin the tab.)

ome chukwuemeka

unread,
Sep 26, 2022, 7:13:41 PMSep 26
to T S, chromium-...@chromium.org, rob...@gmail.com
It can be done. I have done it before but you must need a server. I implemented my server using python, then extracted the webrtc into pop.html of the extension and added a custom Javascript file. Information is sent through the websocket with the aid of webrtc

--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/4b6e285c-9eeb-439d-8e2e-5a93d031c002n%40chromium.org.

Robbi

unread,
Sep 27, 2022, 9:01:25 AMSep 27
to Chromium Extensions, omeco4...@gmail.com, chromium-...@chromium.org, Robbi, T S
Thanks for your answers,
I hope you still have some patience with me.

I seem to have understood that:
  1. A server is needed for "handshaking" between peers.
  2. That this server provides the two actors with the minimum knowledge to establish two-way communication
  3. That this server does not intercept the data stream (audio \ video \ text) between peers.
  4. That this server steps aside once communication has begun.
This server is not called STUN, but it could be called SIGNALING server (right ???)

Does this server need to be configured inside the LAN or can \ should it be external?
My preference would be to rely on an already operating PHP server (external to the LAN) that I found among the offer of free hosting services.
This service however does not provide webSocket support.

I guess this signaling server has to provide both peers with the information for routing the data stream, right?
How do you comply with this task? An abstraction of what this server does or even practical examples I have not found them on the net.
They would help me break the toy and understand (maybe) what's inside.

@T S   was talking to me about free cloud services. What exactly should I look for on the net? "cloud service webRTC signaling" or what else?
This cloud service thing might be fine for me; however, I must be sure that these services do not intercept the flow of data between the 2 peers (for obvious reasons of privacy and corporate security).

Finally, I can't imagine how potential peers on the network to connect with are detected.
It is the individual peer who somehow transmit their willingness to the server to be called or it is the server that does a sort of pooling \ scan on all the devices it finds on the network and then shows a list to other interested peers?
What would this list of peers look like: a list of IPAs, mac addresses, pc names, or what else?
I would need to associate each value of this list to the respective colleague (first name + last name).

As you will have understood, the things that I am not clear are many.
@T S   I had already read the article on https://webrtc.org but I hadn't looked at the link with the examples. I'll take a look at it right away; may it never be that some light bulbs (or LEDs) turn on.

Thanks for your patience

T S

unread,
Sep 29, 2022, 9:30:16 AMSep 29
to Chromium Extensions, Robbi, omeco4...@gmail.com, chromium-...@chromium.org, T S
Calling it a signalling server is just convention, as this is usually fulfilled by some kind of server.  However, you could write the json out on paper and pass notes to much the same effect.
There's no requirement for your signalling service to be external - all that matters is that both peers can transfer data between one another, so if you're using a server to achieve that, both peers need to be able to access that server.

https://surma.dev/things/comlink-webrtc/ has a decent explanation of the connection establishment process.  Precisely how the json is conveyed between peers isn't part of the webrtc spec and can be achieved however you like.  For that reason, you won't really find specific services offering webrtc-specific signalling, because there is nothing webrtc-specific about moving json around.  I feel like using e.g. firestore which has websocket support and simple client libraries would be easier than trying to implement my own messaging service in php, but that's personal preference.  

Webrtc doesn't specify anything about peer discovery or peer identifiers, that would be your own problem to tackle.  At its very simplest you might have peers poll for incoming connection requests and the list of online peers, have the server track the last poll timestamp from each peer, and adjust the online peer list based on when each client last polled.  You'd then have to bolt on a mechanism for letting the two peers exchange data once the connection process begins.

On firestore you could do online status with TTL documents and use the websocket-driven updates instead of polling.

Robbi

unread,
Sep 29, 2022, 11:53:40 AMSep 29
to Chromium Extensions, T S, Robbi, omeco4...@gmail.com, chromium-...@chromium.org
I don't think I can write it all in one night, but you definitely got me on the right track. I am also working on 2 extensions at the same time and maybe I will not be able to dedicate myself to this WebRCT project full time. As soon as I have the opportunity to seriously devote myself to it you can be sure that in one way or another I will hang more questions on this thread or open a new one.
The light bulb, being dimmable, now begins to produce a faint light :-)
The "Surma" article is more than decent, thank you very much
Reply all
Reply to author
Forward
0 new messages