public joinCall()

in packages/react-composites/src/composites/CallComposite/adapter/AzureCommunicationCallAdapter.ts [716:754]


  public joinCall(options?: boolean | JoinCallOptions): CallTypeOf<AgentType> | undefined {
    if (_isInCall(this.getState().call?.state ?? 'None')) {
      throw new Error('You are already in the call!');
    } else if (this.locator === undefined) {
      throw new Error('Locator is not defined!');
    }

    return this.teeErrorToEventEmitter(() => {
      // Default to keeping camera/mic on if no override argument specified
      let shouldCameraBeOnInCall = this.getState().cameraStatus === 'On';
      let shouldMicrophoneBeOnInCall = this.getState().isLocalPreviewMicrophoneEnabled;

      // Apply override arguments
      if (typeof options === 'boolean') {
        // Deprecated joinCall API (boolen)
        shouldMicrophoneBeOnInCall = options;
      } else if (typeof options === 'object') {
        // Options bag API
        if (options.microphoneOn && options.microphoneOn !== 'keep') {
          shouldMicrophoneBeOnInCall = options.microphoneOn;
        }
        if (options.cameraOn && options.cameraOn !== 'keep') {
          shouldCameraBeOnInCall = options.cameraOn;
        }
      }

      const audioOptions: AudioOptions = { muted: !shouldMicrophoneBeOnInCall };
      const selectedCamera = getSelectedCameraFromAdapterState(this.getState());
      const videoOptions: VideoOptions =
        selectedCamera && shouldCameraBeOnInCall
          ? { localVideoStreams: [new SDKLocalVideoStream(selectedCamera)] }
          : {};
      const call = this._joinCall(audioOptions, videoOptions);

      this.originCall = call;
      this.processNewCall(call);
      return call;
    });
  }