export function disposeAllViewsFromCall()

in packages/calling-stateful-client/src/StreamUtils.ts [543:597]


export function disposeAllViewsFromCall(
  context: CallContext,
  internalContext: InternalCallContext,
  callId: string
): void {
  const remoteStreams = internalContext.getRemoteRenderInfoForCall(callId);
  if (remoteStreams) {
    for (const [participantKey, participantStreams] of remoteStreams.entries()) {
      for (const [_, remoteStreamAndRenderer] of participantStreams.entries()) {
        // We don't want to accept SDK stream as parameter but we also don't cache the declarative stream so we have to
        // convert the SDK stream to declarative stream which is not pretty so this could use some further refactoring.
        disposeView(
          context,
          internalContext,
          callId,
          participantKey,
          convertSdkRemoteStreamToDeclarativeRemoteStream(remoteStreamAndRenderer.stream)
        );
      }
    }
  }

  const localStreams = internalContext.getLocalRenderInfosForCall(callId);
  if (localStreams) {
    for (const localStreamAndRenderer of localStreams.values()) {
      if (localStreamAndRenderer && localStreamAndRenderer.renderer) {
        // We don't want to accept SDK stream as parameter but we also don't cache the declarative stream so we have to
        // convert the SDK stream to declarative stream which is not pretty so this could use some further refactoring.
        disposeView(
          context,
          internalContext,
          callId,
          undefined,
          convertSdkLocalStreamToDeclarativeLocalStream(localStreamAndRenderer.stream)
        );
      }
    }
  }
  /* @conditional-compile-remove(together-mode) */
  const callFeatureStreams = internalContext.getCallFeatureRenderInfosForCall(callId);
  /* @conditional-compile-remove(together-mode) */
  if (callFeatureStreams) {
    for (const featureStreams of callFeatureStreams.values()) {
      for (const streamAndRenderer of featureStreams.values()) {
        disposeView(
          context,
          internalContext,
          callId,
          undefined,
          convertSdkRemoteStreamToDeclarativeRemoteStream(streamAndRenderer.stream as RemoteVideoStream)
        );
      }
    }
  }
}