export default function createDefaultCardActionMiddleware()

in packages/component/src/Middleware/CardAction/createCoreMiddleware.js [32:88]


export default function createDefaultCardActionMiddleware() {
  return [
    () =>
      next =>
      (...args) => {
        const [
          {
            cardAction: { type, value },
            getSignInUrl
          }
        ] = args;

        switch (type) {
          case 'call':
          case 'downloadFile':
          case 'openUrl':
          case 'playAudio':
          case 'playVideo':
          case 'showImage':
            if (ALLOWED_SCHEMES.includes(getScheme(value))) {
              if (ie11) {
                const newWindow = window.open();
                newWindow.opener = null;
                newWindow.location = value;
              } else {
                // False alarm: this is "window.open", and not "fs.open".
                // eslint-disable-next-line security/detect-non-literal-fs-filename
                window.open(value, '_blank', 'noopener noreferrer');
              }
            } else {
              console.warn('botframework-webchat: Cannot open URL with disallowed schemes.', value);
            }

            break;

          case 'signin': {
            /**
             * @todo TODO: [P3] We should prime the URL into the OAuthCard directly, instead of calling getSessionId on-demand
             *       This is to eliminate the delay between window.open() and location.href call
             */

            (async function () {
              const popup = window.open();
              const url = await getSignInUrl();

              popup.location.href = url;
            })();

            break;
          }

          default:
            return next(...args);
        }
      }
  ];
}