Commit 7591e81e authored by Saravana Kumar's avatar Saravana Kumar
Browse files

Enable webex

parent 6cfaf43a
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@ import { Inter } from "@next/font/google";
import { useEffect, useMemo } from "react";
import useTeamsMeeting from "./hooks/teams-provider/useTeamsMeeting";
import useZoomMeeting from "./hooks/zoom-provider/useZoomMeeting";
// import useWebexMeeting from "./hooks/webex-provider/useWebexMeeting";
import useWebexMeeting from "./hooks/webex-provider/useWebexMeeting";
import useJitsiMeeting from "./hooks/jitsi-provider/useJitsiMeeting";
import useBlueJeansMeeting from "./hooks/blueJeans-provider/useBlueJeansMeeting";
import Router from "next/router";
@@ -18,7 +18,7 @@ const mockData = {
  login: false,
  isShareScreen: false,
  isStartMeeting: false,
  setOpenShareScreen: () => {},
  setOpenShareScreen: () => {}
};

function getURL(meetingLink) {
@@ -54,15 +54,15 @@ function getMeetingIdAndPasscode(link, passcode, meetingType) {
const useMeetingConnector = {
  teams: useTeamsMeeting,
  zoom: useZoomMeeting,
  // webex: useWebexMeeting,
  webex: useWebexMeeting,
  jitsi: useJitsiMeeting,
  blueJeans: useBlueJeansMeeting,
  blueJeans: useBlueJeansMeeting
};

export default function ConferenceScreen({
  meetingLink,
  meetingPasscode,
  provider,
  provider
}) {
  const {
    meetingIdOrLink,
@@ -71,7 +71,7 @@ export default function ConferenceScreen({
    login,
    isShareScreen,
    isStartMeeting,
    setOpenShareScreen,
    setOpenShareScreen
  } = mockData;

  const meetingConnector = useMeetingConnector[provider];
@@ -105,7 +105,7 @@ export default function ConferenceScreen({
          backgroundColor: "red",
          cursor: "pointer",
          border: "none",
          borderRadius: "10px",
          borderRadius: "10px"
        }}
        onClick={() => {
          leaveMeeting();
+88 −80
Original line number Diff line number Diff line
import Webex from "webex";
import { init as initWebex } from "webex";
import { createMeetingAccessToken } from "../../../util/globalApiServices";

const MEETING_STATE = {
@@ -35,27 +35,24 @@ function getInitConfig() {
}

function loadParticipants(membersData, localParticipantSelfId) {
   
  let participants = [];

  Object.values(membersData).forEach(member => {
    let participantInfo = {
      id: member.id,
      participantName: member.name,
      profileUrl :
        member.participant.person?.avatarUrl,
      profileUrl: member.participant.person?.avatarUrl,
      isHost: member.participant.cmrHost || false,
      isLocalParticipant: member.id === localParticipantSelfId,
      isInLobby: member.isInLobby
    }
    };
    if (member.participant.state === "JOINED" || member.isInLobby) {
      participants.push(participantInfo);
    }
  })
  return participants
  });
  return participants;
}


/**
 * Webex initialization with current user authenticated token
 * @param {String} token User authentication token for Webex meeting
@@ -65,9 +62,9 @@ function initWithLogin(token) {
  const initConfig = getInitConfig();
  initConfig.credentials = {
    access_token: token
  }
  const webex = Webex.init(initConfig);
  return new Promise((resolve) => {
  };
  const webex = (window.webex = initWebex(initConfig));
  return new Promise(resolve => {
    webex.once("ready", () => {
      resolve(webex);
    });
@@ -80,7 +77,7 @@ function initWithLogin(token) {
 * @returns {Object} Returns initialized webex object
 */
function initAsGuest(token) {
  const webex = Webex.init(getInitConfig());
  const webex = (window.webex = initWebex(getInitConfig()));
  return new Promise((resolve, reject) => {
    webex.once("ready", () => {
      webex.authorization
@@ -174,30 +171,33 @@ function connectMedia(props) {
  });

  // Update participant info
    meeting.members.on("members:update", (delta) => {
  meeting.members.on("members:update", delta => {
    const { full: membersData } = delta;
      const participants =  loadParticipants(membersData, meeting.members.selfId)
    const participants = loadParticipants(membersData, meeting.members.selfId);
    setParticipants(participants);
  });

  // host updates
    meeting.members.on("members:host:update", (payload) => {
  meeting.members.on("members:host:update", payload => {
    const { members: membersData } = meeting.members.membersCollection;
      const participants =  loadParticipants(membersData, meeting.members.selfId)
    const participants = loadParticipants(membersData, meeting.members.selfId);
    setParticipants(participants);
  });

  // calling when 'Host' meeting is ended.
    meeting.on('meeting:stateChange', () => {
      if(meeting.meetingState === "INACTIVE" || meeting.meetingState === "TERMINATING"){
  meeting.on("meeting:stateChange", () => {
    if (
      meeting.meetingState === "INACTIVE" ||
      meeting.meetingState === "TERMINATING"
    ) {
      setMeetingStatus(prevState => {
        return {
          ...prevState,
          remoteHostMeetingEnd: true
        };
      });
    }
        })
      }
    })
  });
  meeting.on("meeting:stoppedSharingLocal", () => {
    setMeetingStatus(prevState => {
      return {
@@ -206,7 +206,7 @@ function connectMedia(props) {
        message: "Screen Share stopped"
      };
    });
    })
  });
}
/**
 * Starts the Webex meeting connection process. Following steps are followed,
@@ -224,7 +224,7 @@ function connectMedia(props) {
function start(props) {
  const { setMeetingStatus, login, name } = props;
  return createMeetingAccessToken({ provider: "webex", login, name })
    .then(token => login ? initWithLogin(token) : initAsGuest(token))
    .then(token => (login ? initWithLogin(token) : initAsGuest(token)))
    .then(webex => {
      setMeetingStatus(prevState => {
        return {
@@ -296,7 +296,7 @@ function leaveMeeting({ meeting, webex, setMeetingStatus }) {
  setMeetingStatus(prevState => {
    return {
      ...prevState,
      message: "Leaving",
      message: "Leaving"
    };
  });

@@ -313,9 +313,10 @@ function leaveMeeting({ meeting, webex, setMeetingStatus }) {

function assignHost(meeting, hostMemberId) {
  if (hostMemberId) {
      meeting.transfer(hostMemberId)
    meeting
      .transfer(hostMemberId)
      .then(() => console.log("Host assigned"))
      .catch((e) => {
      .catch(e => {
        console.log("assignHost() catch:e", e);
      });
  }
@@ -323,9 +324,10 @@ function assignHost(meeting, hostMemberId) {

function removeParticipant(meeting, participantId) {
  if (participantId) {
    meeting.remove(participantId)
    meeting
      .remove(participantId)
      .then(() => console.log("participant removed"))
      .catch((e) => {
      .catch(e => {
        console.log("removeParticipant() catch:e", e);
      });
  }
@@ -333,14 +335,13 @@ function removeParticipant(meeting, participantId) {

function admitParticipants(meeting, participantsId) {
  if (participantsId.length > 0) {
    meeting.members.admitMembers(participantsId)
    meeting.members
      .admitMembers(participantsId)
      .then(() => console.log("participants admitted"))
    .catch((e) => console.log("admitParticipants e()"))
      .catch(e => console.log("admitParticipants e()"));
  }
}



/**
 * Gets the current member Object from meeting
 */
@@ -418,7 +419,13 @@ function stopShare({ meeting, setMeetingStatus }) {
 * @returns {Object} Object with internal status, webex meeting objects
 *            and methods for leave, start share and stop share
 */
function startMeeting(meetingUrl, login, setMeetingStatus, setParticipants, name) {
function startMeeting(
  meetingUrl,
  login,
  setMeetingStatus,
  setParticipants,
  name
) {
  const props = {
    meetingState: MEETING_STATE.NOT_STARTED,
    login,
@@ -434,10 +441,11 @@ function startMeeting(meetingUrl, login, setMeetingStatus, setParticipants, name
    startShare: async () => startShare(props),
    stopShare: async () => stopShare(props),
    leaveMeeting: async () => leaveMeeting(props),
    assignHost: (hostMemberId) => assignHost(props.meeting, hostMemberId),
    removeParticipant:  (participantId) =>
    assignHost: hostMemberId => assignHost(props.meeting, hostMemberId),
    removeParticipant: participantId =>
      removeParticipant(props.meeting, participantId),
    admitParticipants: (participantsId) => admitParticipants(props.meeting, participantsId),
    admitParticipants: participantsId =>
      admitParticipants(props.meeting, participantsId)
  };
}