replaceScreenshareStream method

Future<void> replaceScreenshareStream(
  1. WrappedMediaStream existingStream,
  2. WrappedMediaStream replacementStream
)

Implementation

Future<void> replaceScreenshareStream(WrappedMediaStream existingStream,
    WrappedMediaStream replacementStream) async {
  final streamIndex = screenshareStreams
      .indexWhere((stream) => stream.userId == existingStream.userId);

  if (streamIndex == -1) {
    throw Exception('Couldn\'t find screenshare stream to replace');
  }

  screenshareStreams.replaceRange(streamIndex, 1, [replacementStream]);

  await existingStream.dispose();
  onGroupCallEvent.add(GroupCallEvent.ScreenshareStreamsChanged);
}