onStreamsChanged method
Implementation
Future<void> onStreamsChanged(CallSession call) async {
final opponentMemberId = getCallUserId(call);
if (opponentMemberId == null) {
throw Exception('Cannot change call streams without user id');
}
final currentUserMediaStream = getUserMediaStreamByUserId(opponentMemberId);
final remoteUsermediaStream = call.remoteUserMediaStream;
final remoteStreamChanged = remoteUsermediaStream != currentUserMediaStream;
if (remoteStreamChanged) {
if (currentUserMediaStream == null && remoteUsermediaStream != null) {
await addUserMediaStream(remoteUsermediaStream);
} else if (currentUserMediaStream != null &&
remoteUsermediaStream != null) {
await replaceUserMediaStream(
currentUserMediaStream, remoteUsermediaStream);
} else if (currentUserMediaStream != null &&
remoteUsermediaStream == null) {
await removeUserMediaStream(currentUserMediaStream);
}
}
final currentScreenshareStream =
getScreenshareStreamByUserId(opponentMemberId);
final remoteScreensharingStream = call.remoteScreenSharingStream;
final remoteScreenshareStreamChanged =
remoteScreensharingStream != currentScreenshareStream;
if (remoteScreenshareStreamChanged) {
if (currentScreenshareStream == null &&
remoteScreensharingStream != null) {
addScreenshareStream(remoteScreensharingStream);
} else if (currentScreenshareStream != null &&
remoteScreensharingStream != null) {
await replaceScreenshareStream(
currentScreenshareStream, remoteScreensharingStream);
} else if (currentScreenshareStream != null &&
remoteScreensharingStream == null) {
await removeScreenshareStream(currentScreenshareStream);
}
}
onGroupCallFeedsChanged.add(this);
}