WEBRTC: How to deal with conflicts? - javascript

I am posting this question because I currently have some issues with WEBRTC in Javascript.
First of all, my implementation works pretty well and I can communicate with one or more people at the same time.
However, the context, where i use webrtc, can sometimes lead to a client creating multiple offers in a few ms (using STUN server) and sending those offers to multiple other client.
The issue is: sometimes the client connects really well to one or more other clients but the connection fails with the rest of clients he sent the offers. (and it is not an issue with particular client because all clients can connect each other if they send offers in a longer timing)
I suppose it is a conflict between sdp offers (maybe port conflict ?) that are generated by a same client in a too short time before the end of connection's establishments.
My question is how can i deal with it ? Is it possible to detect when connection fails and then create a new offer ? Should I check the sdp messages in my signal server to ask a client to create a new offer when he sends 2 offers that are conflicting ?
Thanks for your answers.
P.S:
Sorry for my bad language, I am not native english speaker. :/

Related

Real time client information synchronization, best practices and advice

I am writing a PHP backend, JS/Jquery front end application that will allow users to "communicate" in near real time. That is the hope at least, my question is what is my best course of action? Am I best to use WebSockets to send data between the server and client or would use AJAX and some sort of timer (x amount of seconds) be better. My worry with the AJAX way is that it may be taxing on the server to have 10+ clients all asking for data every 15-30 seconds. I need it to be near real-time and so 5 minutes is not really realistic.
An example of what I am trying to do would be if I had 5 users all on a page and user 1 updates their status, I would want users 2,3,4, and 5 to see the update as fast as possible without having to refresh.
I am mixed on what I think is best and I don't want to start doing it one way and find out it is insecure or terrible after getting halfway done. What is my best route with an application like this?
Here's a list of popular possible solutions:
Short polling (what you're referring to in AJAX
Long Polling (AJAX too, but not too many requests)
Websockets
WebRTC
So, for short polling as you've said it consumes lots of resources so let's remove that from the list.
as for long polling, its idea is that a request is send to server and the server doesn't respond unless a new event has happened (keeps the request) but its rarely used in modern development. so If you're going to work with other developers its kind of bad decision.
for WebRTC, browser compatibility is not that great and still a draft in W3C.
Thus, you're left out with WebSockets, and yes they consume ram but not CPU. ram is much cheaper (and it doesn't consume that much too).
As for security they can be considered equal (except for WebRTC which is better because it is actually P2P Communication)
Side note: don't overthink it :)
Here's some resources that can help you:
https://webrtc.org/
https://github.com/walkor/phpsocket.io //Socket library for PHP similar to Socket.io
https://socket.io
What are the realtime communication protocols available for the web? List of the protocols
https://codeburst.io/polling-vs-sse-vs-websocket-how-to-choose-the-right-one-1859e4e13bd9 great article for polling, websockets & covers SSE too
there is one way to make the RTC, RealTime App, Just Use the Socket.io "WebSocket " for signaling and before that take a full view of these webPages:
https://bloggeek.me/
https://www.html5rocks.com/en/tutorials/webrtc
https://w3c.github.io/webrtc-pc/#rtcsignalingstate-enum
https://www.w3.org/TR/mediacapture-streams/#legacy-interface-extensions
and i start to development this technology with this book enter link description here it will open your view of RTC usage and All Details.

JS to PHP Sockets?

I have become very comfortable with PHP and mySQL over the past couple months, but I have recently wanted to create a game (with database connections) that needs even better responsiveness then AJAX. This is where I came across sockets. I do not want to branch into Node.js (I am more comfortable with PHP servers) but PHP sockets can't be pushed information via JavaScript, which is crucial for responsive user input.
In short, I am seeking a method with the responsiveness of sockets but that can be pushed by the client in JS and received in PHP on server, similar to AJAX but bidirectional and fast.
Note I may be misunderstanding some of these concepts as a new member to this crazy new set of servers. Just correct and direct me please.
To build a PHP websocket server, Take a look at RatchetPHP: http://socketo.me/
It uses a sub protocol, WAMP so your websocket connection will have channels (topics).
Cons: It still uses the version 1 of WAMP subprotocol, the author suggest to use Thruway.
But RatchetPHP is better documented, and let you learn to implement websockets easily.

Multicast send from JavaScript?

I have a situation where I need to get some information from an application written in JavaScript, to another computer over the network, but neither system knows the ip address of the other. Multicast really seems like the right answer to me. This communication would require small and frequent update messages, perfect for a light multicast stream.
The problem is that I don't think JavaScript can send UDP messages and I don't think JavaScript can trigger external applications to send the messages on its behalf.
How can I solve this problem?

Comet WEb server implementation

I recently asked one question :- Handle Web Server with multiple clients
I have gone through the basic techniques to implement comet server like streamhub,Maven/Jetty etc.
I have following questions for that :
After that I found the issues like in case of Maven/Jetty internet
connection is required for downloading certain files from net.So it
it possible to implement it if no internet connection is there on
machine where the web server is hosted ?
Also I want the open source tools/technologies to achieve the thing
mentioned in the above question. and I think stream hub is not a
open source free version. Please help if you know any tool which is
free/open source to use.
Currently the web application is running on apache web server. so if
I use comet server what changes I need to do in that ??
Please help...
Thanks in advance...
For comet, pick a server which can handle many open connections. For a chat app I implemented which currently handles 10k open connections, I used Mochiweb. You might want to give that a look.
Going along the Mochiweb path, I will also recommend Erlang for implementing you server. It will be a small piece of code. Basically, you will listen on a path and hold the connection open till you have some data to respond with or timeout.
On the client side, you would write a simple JS function which will make an AJAX call and handle response timeout and data responses as and when they come. Nothing too different here. However, you may need JSONP instead (crossdomain/subdomain because of different servers for web and long poll), so ensure that your LongPoll server replies accordingly.

Javascript TCP connection to server

I have created server daemon, that produces some data, like messages and so. But, what im interested in - client monitoring. For example i have web page, and i need to establish persistent Tcp connection to server and show all incoming data into textbox. I know it can be done with flash, but im searching for JS implementation.
Is it possible and what`s the best practices ?
What you're asking for is known as Comet. Plenty of server software and client libraries exist - see the linked Wikipedia page.
WebSockets is designed to solve this problem.

Categories

Resources