aws / amazon-chime-sdk-js

A JavaScript client library for integrating multi-party communications powered by the Amazon Chime service.
Apache License 2.0
713 stars 475 forks source link

How to implement the DefaultReconnectController #2679

Closed jitt3 closed 1 day ago

jitt3 commented 1 year ago

What are you trying to do?

We have a meeting application, and we want to handle the reconnections when the user's internet service is down and then comes back we want to be able to notify the users that the app is trying to reconnect to the current meeting session

How can the documentation be improved to help your use case?

So far, I have only found the class definition documentation, but it would be nice to have some examples.s

What documentation have you looked at so far?

So far, I have looked into this page https://aws.github.io/amazon-chime-sdk-js/interfaces/reconnectcontroller.html

xuesichao commented 1 year ago

Hi @jitt3 , you can build a notification based on the navigator.onLine. Check here for more details: https://developer.mozilla.org/en-US/docs/Web/API/Navigator/onLine#listening_for_changes_in_network_status

Btw do you really need to implement DefaultReconnectController by yourself? We would recommend you avoid doing this unless necessary. If you do think you need, could you share the reason?

Our SDK provides audioVideoDidStartConnecting event to indicate whether SDK is trying to reconnect or not. Check our use case 6:

Use case 6. Add an observer to receive session lifecycle events: connecting, start, and stop.

Note: You can remove an observer by calling meetingSession.audioVideo.removeObserver(observer). In a component-based architecture (such as React, Vue, and Angular), you may need to add an observer when a component is mounted, and remove it when unmounted.

const observer = {
 audioVideoDidStart: () => {
   console.log('Started');
 },
 audioVideoDidStop: sessionStatus => {
   // See the "Stopping a session" section for details.
   console.log('Stopped with a session status code: ', sessionStatus.statusCode());
 },
 audioVideoDidStartConnecting: reconnecting => {
   if (reconnecting) {
     // e.g. the WiFi connection is dropped.
     console.log('Attempting to reconnect');
   }
 },
};

meetingSession.audioVideo.addObserver(observer);

For network condition change, we also provide connectionDidBecomePoor and connectionDidBecomeGood event. Check here: https://aws.github.io/amazon-chime-sdk-js/modules/qualitybandwidth_connectivity.html#events-for-monitoring-local-attendee-downlink

jitt3 commented 1 year ago

@xuesichao thanks for your response, it turned out it wasn't necessary to implement the DefaultReconnectController, following the examples you added was enough to get that part of the app working as we wanted