Working With Multiple Call Client Instances
react-native-daily-js
version >=0.67.0
.daily-js
and react-native-daily-js
now support multiple simultaneous call client instances. The ability to use multiple instances simultaneously affords various use cases both simple and complex.
One simple example is having a secondary call instance for building a background effects preview. In a single call, setting the background processing effect applies the effect immediately, disallowing any preview step. With a second call instance, you can use prejoin functionality to start the camera, set the background effect, and preview the track without affecting the primary call until you chose to apply the effect.
Another use case we’ve heard is for call coordinators, where a special set of participants monitor or coordinate a larger call and may want to be in a separate call simultaneously for communicating behind the scenes.
Breakout rooms could also be solved using multiple call instances, though we generally encourage the use of track subscriptions for smoother transitioning, communication between rooms, and call quality monitoring.
There are doubtless other use cases that could be solved with multiple clients. Always feel free to reach out to daily for help determining the best approach for solving yours.
Limitations
There are a few known limitations when working with multiple call instances.
- Each additional call instance will use additional bandwidth and CPU, as it does not simply piggyback on resources already in use. This should be taken into consideration to ensure instances are properly limited so as not to overwhelm a client’s network or device.
setOutputDevicesAsync()
will affect all audio elements on the window regardless of which instance the underlying tracks stem from. This function is simply a helper for rounding up all audio elements on the window and setting their sinkId to the matching device. It is recommended that if you use this function, you call it on all call instances so that the underlying state management is kept in sync with reality.- On React Native, only one instance can work with the local camera at a time.
- Multiple call client instances are not yet supported in
Daily React
.
Technical Detail
There are few things to know when working with multiple call instances.
Opt-In Flag
Most use cases are still best suited for use with only one call client instance and the existence of multiple often indicates a bug. For this reason, we have made support for multiple call instances opt-in. Without opting in, the SDK will throw an error in the constructor when it detects a second call instance. To opt-in, simply add allowMultipleCallInstances: true
to the properties passed in to your constructors.
If you were using multiple call instances prior to official support, you may have been setting strictMode: false
in your constructor. This flag still exists and is used for other validation work but will soon no longer allow the multiple-instance behavior. You will need to replace it with the new allowMultipleCallInstances
flag.
CallClientId
Each call client instance now has a public parameter identifying it: callClientId
. You can use this not only for obvious identifying reasons but you can also optionally pass this in to the static getCallInstance()
call to get a handle to the corresponding instance.
Event Handling
All events include the callClientId
to designate which client the event belongs to.
Logging
To help match up logs and metrics across multiple calls for a single user, we log all user session IDs for every simultaneous session. An example log would be:
Simultaneous call client instance created, with participant session_id: 47365350-8116-4ec3-b4eb-f39a21a9ead8
If the other instance has not joined a room (like in the background processing use case), there will be no logs for the second instance, but the other instance joined to a room will still have a log like so:
Simultaneous call client instance created, with participant session_id: not yet set
If the second instance does eventually join, the first will log again with the correct session ID.
Demos
- Using a second instance to preview camera effects
- Joining two seperate calls in a split screen: Coming Soon...