Esempio n. 1
0
  public static void main(String[] args) throws Exception {
    ManagerConnectionFactory factory =
        new ManagerConnectionFactory("172.168.10.205", "manager", "P@$$w0rd");

    ManagerConnection managerConnection = factory.createManagerConnection();
    managerConnection.login();
    verifyMeetMeRoom("6300", "6000", managerConnection);
    managerConnection.logoff();
  }
Esempio n. 2
0
  /** Reloads asterisk config properties. */
  public void reload() {
    // retrieve asterisk manager configuration here
    Properties configProperties = UtilProperties.getProperties("asterisk.properties");
    // asterisk host address
    String host = (String) configProperties.get("asterisk.host");
    // asterisk manager username
    String username = (String) configProperties.get("asterisk.username");
    // asterisk manager password
    String password = (String) configProperties.get("asterisk.password");
    // asterisk dial out prefix, calls between internal extensions are made by dialing the extension
    // number
    // whereas external calls need a prefix before the number you want dial, such as 9
    asteriskExternalCode = (String) configProperties.get("asterisk.outbound.prev");
    // the country code of asterisk server, can be specified to avoid dialing national numbers using
    // the country code
    asteriskCountryCode =
        UtilProperties.getPropertyValue("asterisk.properties", "asterisk.countryCode", "");
    // the area code of asterisk server, can be specified to avoid dialing local area numbers using
    // the area code
    asteriskAreaCode =
        UtilProperties.getPropertyValue("asterisk.properties", "asterisk.areaCode", "");
    // the current phone number of the asterisk server (the phone number of the phone line connected
    // to the asterisk server)
    asteriskPhoneNumber =
        UtilProperties.getPropertyValue("asterisk.properties", "asterisk.phoneNumber", "");
    // the prefix used to dial international phone numbers, usually "011" or "00" ... depends on the
    // origin country
    asteriskInternationalPrefix =
        UtilProperties.getPropertyValue("asterisk.properties", "asterisk.outbound.foreign", "");
    // the prefix used to dial numbers out of the local area, for example to dial other cities /
    // states
    asteriskAreaPrefix =
        UtilProperties.getPropertyValue("asterisk.properties", "asterisk.outbound.area", "");
    // if always add area code to dial, even though it was the same area code.
    alwaysDialAreaCode =
        UtilProperties.getPropertyValue("asterisk.properties", "asterisk.alwaysDialAreaCode", "Y");
    // if always add country code to dial, even though it was the same country code, it used in some
    // voip provider.
    alwaysDialCountryCode =
        UtilProperties.getPropertyValue(
            "asterisk.properties", "asterisk.alwaysDialCountryCode", "Y");
    // Dialplan context to use for outgoing calls, i.e. the dialed number
    originationContext =
        UtilProperties.getPropertyValue(
            "asterisk.properties", "asterisk.originationContext", "from-internal");
    // Channel Technology to use for outgoing calls for the user's channel i.e. SIP/ for chan_sip or
    // Local/ for chan_local
    originationChannel =
        UtilProperties.getPropertyValue(
            "asterisk.properties", "asterisk.originationChannel", "Local/");
    // Channel Technology suffix (useful for ChanLocal - i.e. Local/825@from-internal
    originationChannelSuffix =
        UtilProperties.getPropertyValue(
            "asterisk.properties", "asterisk.originationChannelSuffix", "");
    // Area codes that don't need the long-distance prefix
    String localAreaCodesString =
        UtilProperties.getPropertyValue("asterisk.properties", "asterisk.localAreaCodes", "");
    localAreaCodes = UtilMisc.toListArray(localAreaCodesString.split(","));
    // logs out an existing connection
    if (managerConnection != null) {
      if (managerConnection.getState().equals(ManagerConnectionState.CONNECTED)) {
        managerConnection.logoff();
      }
    }

    ManagerConnectionFactory factory = new ManagerConnectionFactory(host, username, password);

    this.managerConnection = factory.createManagerConnection();
    // connect to Asterisk and log in
    try {
      managerConnection.login();
      managerConnection.addEventListener(
          new ManagerEventListener() {
            public void onManagerEvent(ManagerEvent event) {
              // add a listener to handle incoming and outgoing calls
              // e.getCallerId() is the calling phone number. such as 8605758672106
              // e.getDestination() is the destination of call, include asterisk communication, such
              // as SIP/825-09caf850
              if (event instanceof DialEvent) {
                DialEvent e = (DialEvent) event;
                String destinationNumber = retrieveNumber(e.getDestination());
                Debug.logInfo("Call from:" + e.getCallerId() + ", to:" + destinationNumber, MODULE);
                calls.put(destinationNumber, e.getCallerId());
              }
            }
          });
      managerConnection.sendAction(new StatusAction());
    } catch (IllegalStateException e) {
      Debug.logError(e, "Error reloading asterisk server manager connection", MODULE);
    } catch (IOException e) {
      Debug.logError(e, "Error reloading asterisk server manager connection", MODULE);
    } catch (AuthenticationFailedException e) {
      Debug.logError(e, "Error reloading asterisk server manager connection", MODULE);
    } catch (TimeoutException e) {
      Debug.logError(e, "Error reloading asterisk server manager connection", MODULE);
    }
  }
Esempio n. 3
0
 public void disconnect() {
   managerConnection.logoff();
 }