WebRTC delay on iceConnectionState - 'disconnected' - javascript

Two peers are connected - host and client
Client gets offline and iceConnectionState - 'disconnected' on host is triggered after about 3-7 seconds
Why is there a delay ? and how to remove that delay?
I just wanted get online status of user in realtime

Peer connection gets closed when there's no data coming for several seconds, hence the delay. There's no Web API to configure this timeout.
I see three ways how you might reduce the delay:
Send keepalives between peers via datachannel. If there were no keepalive for n milliseconds, client is considered disconnected; connection might be closed (or "pending" user status can be displayed).
Some timeout is still needed, but it can be shorter than the default one.
If client always sends the video, you might use getStats() to detect when there's no new packets coming => client disconnected. It's the same as 1, but using video packets instead of keepalive messages. See this answer.
Send a message to server when client is about to disconnect so the server knows connection is no longer needed and close it. For example, you could send a "goodbye" message to WebRTC datachannel in window.onbeforeunload callback. The drawback is that if client goes offline without closing the page you still have to wait for n seconds, whatever is default in your browser.

Related

Change Firebase real time database ping pong time

a query related to firebase presence app using javascript sdk. I have seen that there is 60 seconds buffer after the internet is disconnected after which the entries are removed from the firebase real tim edatabase. Is it possible to configure this time from 60 seconds to lets say 30 seconds? . I basically want the entries to be removed from the presence as soon as the internet is disconnected. If not immediately then at least sooner than a minute alteast.Does anybody have any idea on this?
There are two ways an onDisconnect handler can be triggered on the Firebase servers:
A clean disconnect is when the client has time to inform the server that it is about to disconnect, and in that case the server executes the onDisconnect handlers immediately.
A dirty disconnect is when the client disconnects without informing the server. In this case the server detects that the client is gone when the socket from that client times out, and then it executes the onDisconnect handlers.
Detecting the dirty disconnects takes some times (upwards to a few minutes) and there's no way for you to configure it.
If you want more granular presence detection, the common approach is to periodically write a timestamp into the database from the client. This indicates when the client was last active, and can be used by the other clients to then indicate the liveliness of that user/client.

Signalr inactivity timeout

I have googled many things related to this issue. I am doing signalr connection using WebSocket and longpooling, I am pinging the server every 30 sec from the connection.
When I load the first time, I don't doing anything on the page, no refresh, after some time connection is disconnected due to inactivity(he client has been inactive since 26/03/2018 30000ms and it has exceeded the inactivity timeout), and reconnected again as I have written reconnect function,
though if I calling ping method to server every 20 sec after some time server is disconnected and I don't know why.
I have enabled logging=true on client side,
my client is HTML page.
If the server is not reconnected, an error like
longpooling request is failed
occurs. On the server keepalive is null.
The first time the client is able to reconnect, but the second time not.
I don't know why the server disconnects, as I am using longpooling.
The ping method is an empty method only for the heartbeat I used.
The application is hosted using Amazon ELB.
Please help, I have tried for 3-4 days, but I could not find the issue.

Socket.io when client Internet going to off

How can i callback from client to server internet going to off? I have users and i added their connections in the some room. But I can not know when they are Internet going to down. I want to callback their statues but I do not know how. My clients are android phone.
this function does not work.
socket.on("disconnect", function () {
var SocketRoom= socket.room;
socket.leave(SocketRoom);
});
The clients can't send a message through the socket connection, if they are not connected to the network/internet anymore. You might want to check for timeouts.
Once a client connects to the server, the server sends a message to the client in a fixed time interval (like every 5 seconds).
If the client responds to that message, you know, it's still conencted and continue with your program logic.
If the client does not respond to your message, then they are very likely not connected to the internet anymore (or are unreachable for other reasons). If this is the case, you can force them to leave the room (like in your socket.on("disconnect", ...) function).
Please note:
The higher the timeout interval, the less precise is the actual disconnect time, but the load on the connection is kept low.
If a client does not respond to a timeout-check, you might want to retry to send a message to that client a couple of times before force-closing the connection.

reconnect socket after sleep

I am trying to learn sockets in Perl. It is common that user closes the lid and socket connection gets disconnected.Is there any way that the server can get to know about client going to sleep mode. Please Help.I am using Net::WebSocket::Server
The usual means of detecting a socket that was not actively closed, but has suddenly become unreachable is for a heartbeat packet to be sent on some agreed upon schedule. The other end of the socket is supposed to response with a heartbeat response each time it receives a heartbeat packet.
If the server sends out the heartbeat and does not receive a response in a reasonable amount of time, then it can assume that the client is no longer actively connected.
Socket libraries like socket.io implement this very technique for detecting when the connection has gone dead for use with websockets, but the same technique can be used with any type of socket.
The heartbeat can be used from either end of the connection (just depending upon how you want to do it and what each side expects). So, if the server is sending the heartbeat, a client could assume that if it goes X amount of time without receiving any heartbeat requests, then it's connection to the server must have gone dead so it should close the socket and reconnect.

How do I recover from a WebSocket client computer going to sleep or app going to background (Safari on iPad)

I have browser client Javascript which opens a WebSocket (using socket.io) to request a long-running process start, and then gets a callback when the process is done. When I get the callback, I update the web page to let the user know the process has completed.
This works ok, except on my iPad when I switch to another app and then come back (it never gets the callback, because I guess the app is not online at the time). I'm assuming the same thing will happen on a laptop or other computer that sleeps while waiting for the callback.
Is there a standard way (or any way) to deal with this scenario? Thanks.
For reference, if you want to see the problem page, it is at http://amigen.perfectapi.com/
There are a couple of things to consider in this scenario:
Detect the app going off/on line
See: Online and offline events.
When your app detects the online event after the computer wakes up you can get any information that you've missed.
For older web browsers you'll need to do this in a cleverer way. At Pusher we've added a ping - pong check between the client and server. If the client doesn't receive a ping within a certain amount of time it knows there's a connection problem. If the server sends a ping and doesn't get a pong back with a certain time it knows there's a problem.
A ping pong mechanism is defined in the spec but a way of sending a ping or pong hasn't been defined on the WebSocket API as yet.
Fetching missed information
Most realtime servers only deliver messages to connected to clients. If a client isn't connected, maybe due to temporary network disturbance or their computer has been asleep for a while, then those clients will miss the message.
Some frameworks do provide access to messages through a history/cache. For those that don't you'll need to detect the problem (as above) and then fetch any missed messages. A good way to do this is by providing a timestamp or sequence ID with each messages so you can make a call to your web server to say "give me all messages since X".

Categories

Resources