philnash / twilio-video-react-hooks

A video chat application built with Twilio Video and React Hooks
MIT License
110 stars 61 forks source link

reconnect as soon as user is disconnected #10

Closed SanskarSans closed 4 years ago

SanskarSans commented 4 years ago

Can anyone tell me the place to reconnect as soon as user is disconnected(not when user disconnects deliberately), please? In detail what I wanted is start a time as soon as remote participant joins and if any user is disconnected before available time(5min), then reconnect that user instead of refreshing the page.

Thanks

philnash commented 4 years ago

Hi @SanskarSans, I'm not sure what you mean here. If a participant is disconnected unintentionally, the SDK will try to reconnect. You can listen for reconnecting and reconnected events on the Room object. Does that help?

SanskarSans commented 4 years ago

Thank you @philnash. I got about reconnecting events. I want to take your idea on timer part.

Here is my use case.

It's a call between patient and doctor for coronavirus related issue.

A patient calls a specific doctor. When doctor joins the call, the timer will be started for around 10mins. When the time reaches to 10min, the call should drop. But sometime, the call might drop(disconnect) due to network issue then it will affect the timer. For this can you provide me an idea, please?

philnash commented 4 years ago

Ah, ok. In that case I wouldn't do the timing on the client side. Instead I would use the REST API to set the room status to "completed" which would overall close the room for the participants. That way they can connect, refresh, reconnect, whatever for the lifetime of the timer, and once that timer is over and the room is completed they won't be able to join again and will be disconnected.

Does that help?

SanskarSans commented 4 years ago

Thank you very much for your quick response. I got the point of updating the status to completed. But to update the status as completed, do i need to use socket? I mean once the participant is joined, I will have to fire socket event to keep on listening the time. If it's 10 min then update the room status to completed? Because I need to know if the time has reached to 10min or not so I can update the room status to completed.

philnash commented 4 years ago

I would do all the timing on the server side. That is, once you have all the participants you want in the video, fire off a request to your server (an XHR request would do, or you could use a websocket) to say that it's started. Then, on the server side, receive that request and set up a timer or an asynchronous job that will run after 10 minutes and set the room status to "completed". Do not trust the client-side for this interaction.

Once the room is completed, Twilio will trigger the end of the call on the client side using the existing websocket connection that is setup between the participants and Twilio.

Give that a go and let me know how you get on.

SanskarSans commented 4 years ago

Thank you very much for giving me your idea. I will do the same like you have said and will let you know.

philnash commented 4 years ago

Hi @SanskarSans, how did this go for you? Can this issue be closed?

SanskarSans commented 4 years ago

As soon as remote participant joins the room, i start the cron job to run after 10 minutes and set the running room status to completed. Thank you for your help.