{"size": 1013, "ext": "js", "max_stars_repo_path": "lib/cmds/join.js", "max_stars_repo_name": "jimmy1wu/zoom-links", "max_stars_repo_stars_event_min_datetime": "2021-01-21T19:59:09.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-26T00:22:46.000Z", "max_issues_repo_path": "lib/cmds/join.js", "max_issues_repo_name": "jimmy1wu/zoom-links", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lib/cmds/join.js", "max_forks_repo_name": "jimmy1wu/zoom-links", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 5, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 25.9743589744, "max_line_length": 73, "alphanum_fraction": 0.5913129319}
"use strict";

const open = require("open");
const chalk = require("chalk");
const meetings = require("../store");

const { log } = console;

module.exports = {
  command: "join <name>",
  aliases: ["j"],
  describe: "Join a Zoom meeting",
  builder: function (yargs) {
    return yargs.option("s", {
      alias: "start",
      describe: "Start the meeting if you are the host",
      boolean: true,
    });
  },
  handler: function (argv) {
    const { name, start } = argv;
    const meeting = meetings.get(name);
    if (!meeting) {
      log(chalk.red("Zoom meeting does not exist."));
      process.exit(1);
    }

    const zoomURL = new URL(meeting);
    const host = zoomURL.host;
    const action = start ? "start" : "join";
    const confno = `confno=${zoomURL.pathname.split("/")[2]}`;
    const pwd = zoomURL.search && `&${zoomURL.search.split("?")[1]}`;
    const zoomDirectLink = `zoommtg://${host}/${action}?${confno}${pwd}`;

    log("Joining Zoom meeting...");
    open(zoomDirectLink);
  },
};
