public get()

in packages/calling-stateful-client/src/StatefulCallClient.ts [214:292]


  public get<P extends keyof CallClient>(target: CallClient, prop: P): any {
    switch (prop) {
      case 'createCallAgent': {
        return this._context.withAsyncErrorTeedToState(
          async (...args: Parameters<CallClient['createCallAgent']>): Promise<DeclarativeCallAgent> => {
            // createCallAgent will throw an exception if the previous callAgent was not disposed. If the previous
            // callAgent was disposed then it would have unsubscribed to events so we can just create a new declarative
            // callAgent if the createCallAgent succeeds.
            const callAgent = await target.createCallAgent(...args);
            this._callAgent = callAgentDeclaratify(callAgent, this._context, this._internalContext);
            this._context.setCallAgent({
              displayName: this._callAgent.displayName
            });
            return this._callAgent;
          },
          'CallClient.createCallAgent'
        );
      }
      case 'createTeamsCallAgent': {
        return this._context.withAsyncErrorTeedToState(
          async (...args: Parameters<CallClient['createTeamsCallAgent']>): Promise<DeclarativeTeamsCallAgent> => {
            // createCallAgent will throw an exception if the previous callAgent was not disposed. If the previous
            // callAgent was disposed then it would have unsubscribed to events so we can just create a new declarative
            // callAgent if the createCallAgent succeeds.
            const callAgent = await target.createTeamsCallAgent(...args);
            this._callAgent = teamsCallAgentDeclaratify(callAgent, this._context, this._internalContext);
            this._context.setCallAgent({
              displayName: undefined
            });
            return this._callAgent;
          },
          'CallClient.createTeamsCallAgent'
        );
      }
      case 'getDeviceManager': {
        return this._context.withAsyncErrorTeedToState(async () => {
          // As of writing, the SDK always returns the same instance of DeviceManager so we keep a reference of
          // DeviceManager and if it does not change we return the cached DeclarativeDeviceManager. If it does not we'll
          // throw an error that indicate we need to fix this issue as our implementation has diverged from the SDK.
          const deviceManager = await target.getDeviceManager();
          if (this._sdkDeviceManager) {
            if (this._sdkDeviceManager === deviceManager) {
              return this._deviceManager;
            } else {
              throw new Error(
                'Multiple DeviceManager not supported. This means a incompatible version of communication-calling is ' +
                  'used OR calling declarative was not properly updated to communication-calling version.'
              );
            }
          } else {
            this._sdkDeviceManager = deviceManager;
          }
          this._deviceManager = deviceManagerDeclaratify(deviceManager, this._context, this._internalContext);
          return this._deviceManager;
        }, 'CallClient.getDeviceManager');
      }
      case 'feature': {
        return this._context.withErrorTeedToState((...args: Parameters<CallClient['feature']>) => {
          if (args[0] === Features.DebugInfo) {
            const feature = target.feature(Features.DebugInfo);
            /**
             * add to this object if we want to proxy anything else off the DebugInfo feature object.
             */
            return {
              ...feature,
              getEnvironmentInfo: async () => {
                const environmentInfo = await feature.getEnvironmentInfo();
                this._context.setEnvironmentInfo(environmentInfo);
                return environmentInfo;
              }
            };
          }
          return Reflect.get(target, prop);
        }, 'CallClient.feature');
      }
      default:
        return Reflect.get(target, prop);
    }
  }