Ejemplo n.º 1
0
  /**
   * Implements CallListener.incomingCallReceived. When a call is received creates a call panel and
   * adds it to the main tabbed pane and plays the ring phone sound to the user.
   */
  public void incomingCallReceived(CallEvent event) {
    Call sourceCall = event.getSourceCall();

    CallPanel callPanel = new CallPanel(this, sourceCall, GuiCallParticipantRecord.INCOMING_CALL);

    mainFrame.addCallPanel(callPanel);

    if (mainFrame.getState() == JFrame.ICONIFIED) mainFrame.setState(JFrame.NORMAL);

    if (!mainFrame.isVisible()) mainFrame.setVisible(true);

    mainFrame.toFront();

    this.callButton.setEnabled(true);
    this.hangupButton.setEnabled(true);

    NotificationManager.fireNotification(
        NotificationManager.INCOMING_CALL,
        null,
        "Incoming call recived from: " + sourceCall.getCallParticipants().next());

    activeCalls.put(sourceCall, callPanel);

    this.setCallPanelVisible(true);
  }
Ejemplo n.º 2
0
  /** Handle a dial request */
  public void handleDialRequest(String phoneNumber) {
    try {

      System.err.println(
          "Audio Static:"
              + PhoneManager.isUseStaticLocator()
              + " Using:"
              + PhoneManager.isUsingMediaLocator());

      // cancel call request if no Media Locator
      if (PhoneManager.isUseStaticLocator() && PhoneManager.isUsingMediaLocator()) {
        return;
      }

      PhoneManager.setUsingMediaLocator(true);

      SessionDescription sdpData = mediaManager.generateSdpDescription();

      Call call = sipManager.establishCall(phoneNumber, sdpData.toString());

      if (call == null) return;

      call.setLocalSdpDescription(sdpData);

      call.addStateChangeListener(this);
      Interlocutor interlocutor = new Interlocutor();
      interlocutor.setCall(call);

      guiManager.addInterlocutor(interlocutor);
    } catch (Exception e) {
      Log.error("handleDialRequest", e);
    }
  }
Ejemplo n.º 3
0
 /**
  * Fired when a call is received
  *
  * @param evt CallEvent
  */
 public void callReceived(CallEvent evt) {
   try {
     Call call = evt.getSourceCall();
     Interlocutor interlocutor = new Interlocutor();
     interlocutor.setCall(call);
     guiManager.addInterlocutor(interlocutor);
     call.addStateChangeListener(this);
     // handleAnswerRequest(interlocutor);
   } catch (Exception e) {
     Log.error("callReceived", e);
   }
 }
Ejemplo n.º 4
0
    public void run() {
      ProtocolProviderService pps = call.getProtocolProvider();

      Iterator participants = call.getCallParticipants();

      while (participants.hasNext()) {
        CallParticipant participant = (CallParticipant) participants.next();

        OperationSetBasicTelephony telephony = mainFrame.getTelephonyOpSet(pps);

        try {
          telephony.answerCallParticipant(participant);
        } catch (OperationFailedException e) {
          logger.error(
              "Could not answer to : " + participant + " caused by the following exception: " + e);
        }
      }
    }
Ejemplo n.º 5
0
  /**
   * Fired when call state changes
   *
   * @param evt CallStateEvent
   */
  public void callStateChanged(CallStateEvent evt) {
    try {

      for (SoftPhoneListener sfl : softPhoneListeners) {
        sfl.callStateChanged(evt);
      }

      Call call = evt.getSourceCall();
      Log.debug("callStateChanged", evt.getOldState() + " -> " + evt.getNewState());
      if (evt.getNewState() == Call.CONNECTED) {
        // sipManager.setBusy(true);

        if (call.getAudioReceiverChannel() != null) call.getAudioReceiverChannel().stop();

        if (evt.getOldState() == Call.MOVING_REMOTELY) {
          AudioMediaSession audioMediaSession = evt.getSourceCall().getAudioMediaSession();
          if (call.getAudioReceiverChannel() != null) call.getAudioReceiverChannel().stop();

          if (audioMediaSession != null) {
            audioMediaSession.stopTrasmit();
            audioMediaSession.stopReceive();
          }
          VideoMediaSession videoMediaSession = evt.getSourceCall().getVideoMediaSession();
          if (videoMediaSession != null) {
            videoMediaSession.stopTrasmit();
            videoMediaSession.stopReceive();
          }
          PhoneManager.setUsingMediaLocator(false);
        }

        int localAudioPort = -1;
        int localVideoPort = -1;

        Vector<MediaDescription> mediaDescriptions =
            call.getLocalSdpDescription().getMediaDescriptions(true);
        for (MediaDescription mediaDescription : mediaDescriptions) {
          if (mediaDescription.getMedia().getMediaType().equals("audio"))
            localAudioPort = mediaDescription.getMedia().getMediaPort();
          else if (mediaDescription.getMedia().getMediaType().equals("video"))
            localVideoPort = mediaDescription.getMedia().getMediaPort();
        }

        AudioMediaSession audioMediaSession =
            mediaManager.createAudioMediaSession(
                call.getRemoteSdpDescription().toString(), localAudioPort);
        call.setAudioMediaSession(audioMediaSession);

        if (audioMediaSession != null) {
          audioMediaSession.startTrasmit();
          audioMediaSession.startReceive();
        }

        // If remote client have video
        if (localVideoPort > 0) {
          if (SettingsManager.getLocalPreferences().getVideoDevice() != null
              && !"".equals(SettingsManager.getLocalPreferences().getVideoDevice())) {
            VideoMediaSession videoMediaSession =
                mediaManager.createVideoMediaSession(
                    call.getRemoteSdpDescription().toString(), localVideoPort);
            if (videoMediaSession != null) {
              videoMediaSession.startTrasmit();
              videoMediaSession.startReceive();
              call.setVideoMediaSession(videoMediaSession);
            }
          }
        }

        evt.getSourceCall().start();

        Log.debug("MEDIA STREAMS OPENED");

      } else if (evt.getNewState() == Call.RINGING) {

        if (call.getRemoteSdpDescription() != null && !call.getRemoteSdpDescription().equals("")) {

          Log.debug("STATE", call.getRemoteSdpDescription().toString());

          int localPort =
              ((MediaDescription) (call.getLocalSdpDescription().getMediaDescriptions(true).get(0)))
                  .getMedia()
                  .getMediaPort();
          int destPort =
              ((MediaDescription)
                      (call.getRemoteSdpDescription().getMediaDescriptions(true).get(0)))
                  .getMedia()
                  .getMediaPort();
          String destIp = call.getRemoteSdpDescription().getConnection().getAddress();

          AudioReceiverChannel audioReceiverChannel =
              mediaManager.createAudioReceiverChannel(localPort, destIp, destPort, (destPort + 1));
          call.setAudioReceiverChannel(audioReceiverChannel);

          if (audioReceiverChannel != null) audioReceiverChannel.start();
        }

      } else if (evt.getNewState() == Call.DISCONNECTED) {
        sipManager.setBusy(false);

        AudioMediaSession audioMediaSession = evt.getSourceCall().getAudioMediaSession();
        if (audioMediaSession != null) {
          audioMediaSession.stopTrasmit();
          audioMediaSession.stopReceive();
        }
        if (call.getAudioReceiverChannel() != null) call.getAudioReceiverChannel().stop();
        VideoMediaSession videoMediaSession = evt.getSourceCall().getVideoMediaSession();
        if (videoMediaSession != null) {
          videoMediaSession.stopTrasmit();
          videoMediaSession.stopReceive();
        }

        PhoneManager.setUsingMediaLocator(false);

      } else if (evt.getNewState() == Call.FAILED) {
        call.setState(Call.DISCONNECTED);
        if (call.getAudioReceiverChannel() != null) call.getAudioReceiverChannel().stop();

        CallRejectedEvent rejectEvt =
            new CallRejectedEvent("Disconnected", call.getLastRequest(), call);

        for (SoftPhoneListener softPhoneListener : softPhoneListeners) {
          softPhoneListener.callRejectedRemotely(rejectEvt);
        }

        PhoneManager.setUsingMediaLocator(false);
      }
    } catch (Exception e) {
      Log.error("callStateChanged", e);
    }
  }
Ejemplo n.º 6
0
  /** Creates sound level related components. */
  private void createSoundLevelIndicators() {
    TransparentPanel localLevelPanel = new TransparentPanel(new BorderLayout(5, 0));
    TransparentPanel remoteLevelPanel = new TransparentPanel(new BorderLayout(5, 0));

    localLevel =
        new InputVolumeControlButton(
            call, ImageLoader.MICROPHONE, ImageLoader.MUTE_BUTTON, false, false);
    remoteLevel =
        new OutputVolumeControlButton(call.getConference(), ImageLoader.HEADPHONE, false, false)
            .getComponent();

    final SoundLevelIndicator localLevelIndicator =
        new SoundLevelIndicator(SoundLevelChangeEvent.MIN_LEVEL, SoundLevelChangeEvent.MAX_LEVEL);
    final SoundLevelIndicator remoteLevelIndicator =
        new SoundLevelIndicator(SoundLevelChangeEvent.MIN_LEVEL, SoundLevelChangeEvent.MAX_LEVEL);

    localLevelPanel.add(localLevel, BorderLayout.WEST);
    localLevelPanel.add(localLevelIndicator, BorderLayout.CENTER);
    remoteLevelPanel.add(remoteLevel, BorderLayout.WEST);
    remoteLevelPanel.add(remoteLevelIndicator, BorderLayout.CENTER);

    GridBagConstraints constraints = new GridBagConstraints();
    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 0;
    constraints.gridy = 5;
    constraints.weightx = 0;
    constraints.weighty = 0;
    constraints.insets = new Insets(10, 0, 0, 0);

    add(localLevelPanel, constraints);

    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 0;
    constraints.gridy = 6;
    constraints.weightx = 0;
    constraints.weighty = 0;
    constraints.insets = new Insets(5, 0, 10, 0);

    add(remoteLevelPanel, constraints);

    if (!GuiActivator.getConfigurationService()
        .getBoolean(
            "net.java.sip.communicator.impl.gui.main.call." + "DISABLE_SOUND_LEVEL_INDICATORS",
            false)) {
      callPeer.addStreamSoundLevelListener(
          new SoundLevelListener() {
            public void soundLevelChanged(Object source, int level) {
              remoteLevelIndicator.updateSoundLevel(level);
            }
          });
      /*
       * By the time the UI gets to be initialized, the callPeer may have
       * been removed from its Call. As far as the UI is concerned, the
       * callPeer will never have a Call again and there will be no audio
       * levels to display anyway so there is no point in throwing a
       * NullPointerException here.
       */
      if (call != null) {
        call.addLocalUserSoundLevelListener(
            new SoundLevelListener() {
              public void soundLevelChanged(Object source, int level) {
                localLevelIndicator.updateSoundLevel(level);
              }
            });
      }
    }
  }
Ejemplo n.º 7
0
  /**
   * Handles the <tt>ActionEvent</tt> generated when user presses one of the buttons in this panel.
   */
  public void actionPerformed(ActionEvent evt) {
    JButton button = (JButton) evt.getSource();
    String buttonName = button.getName();

    if (buttonName.equals("call")) {
      Component selectedPanel = mainFrame.getSelectedTab();

      // call button is pressed over an already open call panel
      if (selectedPanel != null
          && selectedPanel instanceof CallPanel
          && ((CallPanel) selectedPanel).getCall().getCallState()
              == CallState.CALL_INITIALIZATION) {

        NotificationManager.stopSound(NotificationManager.BUSY_CALL);
        NotificationManager.stopSound(NotificationManager.INCOMING_CALL);

        CallPanel callPanel = (CallPanel) selectedPanel;

        Iterator participantPanels = callPanel.getParticipantsPanels();

        while (participantPanels.hasNext()) {
          CallParticipantPanel panel = (CallParticipantPanel) participantPanels.next();

          panel.setState("Connecting");
        }

        Call call = callPanel.getCall();

        answerCall(call);
      }
      // call button is pressed over the call list
      else if (selectedPanel != null
          && selectedPanel instanceof CallListPanel
          && ((CallListPanel) selectedPanel).getCallList().getSelectedIndex() != -1) {

        CallListPanel callListPanel = (CallListPanel) selectedPanel;

        GuiCallParticipantRecord callRecord =
            (GuiCallParticipantRecord) callListPanel.getCallList().getSelectedValue();

        String stringContact = callRecord.getParticipantName();

        createCall(stringContact);
      }
      // call button is pressed over the contact list
      else if (selectedPanel != null && selectedPanel instanceof ContactListPanel) {
        // call button is pressed when a meta contact is selected
        if (isCallMetaContact) {
          Object[] selectedContacts =
              mainFrame.getContactListPanel().getContactList().getSelectedValues();

          Vector telephonyContacts = new Vector();

          for (int i = 0; i < selectedContacts.length; i++) {

            Object o = selectedContacts[i];

            if (o instanceof MetaContact) {

              Contact contact =
                  ((MetaContact) o).getDefaultContact(OperationSetBasicTelephony.class);

              if (contact != null) telephonyContacts.add(contact);
              else {
                new ErrorDialog(
                        this.mainFrame,
                        Messages.getI18NString("warning").getText(),
                        Messages.getI18NString(
                                "contactNotSupportingTelephony",
                                new String[] {((MetaContact) o).getDisplayName()})
                            .getText())
                    .showDialog();
              }
            }
          }

          if (telephonyContacts.size() > 0) createCall(telephonyContacts);

        } else if (!phoneNumberCombo.isComboFieldEmpty()) {

          // if no contact is selected checks if the user has chosen
          // or has
          // writen something in the phone combo box

          String stringContact = phoneNumberCombo.getEditor().getItem().toString();

          createCall(stringContact);
        }
      } else if (selectedPanel != null && selectedPanel instanceof DialPanel) {
        String stringContact = phoneNumberCombo.getEditor().getItem().toString();
        createCall(stringContact);
      }
    } else if (buttonName.equalsIgnoreCase("hangup")) {
      Component selectedPanel = this.mainFrame.getSelectedTab();

      if (selectedPanel != null && selectedPanel instanceof CallPanel) {

        NotificationManager.stopSound(NotificationManager.BUSY_CALL);
        NotificationManager.stopSound(NotificationManager.INCOMING_CALL);
        NotificationManager.stopSound(NotificationManager.OUTGOING_CALL);

        CallPanel callPanel = (CallPanel) selectedPanel;

        Call call = callPanel.getCall();

        if (removeCallTimers.containsKey(callPanel)) {
          ((Timer) removeCallTimers.get(callPanel)).stop();
          removeCallTimers.remove(callPanel);
        }

        removeCallPanel(callPanel);

        if (call != null) {
          ProtocolProviderService pps = call.getProtocolProvider();

          OperationSetBasicTelephony telephony = mainFrame.getTelephonyOpSet(pps);

          Iterator participants = call.getCallParticipants();

          while (participants.hasNext()) {
            try {
              // now we hang up the first call participant in the
              // call
              telephony.hangupCallParticipant((CallParticipant) participants.next());
            } catch (OperationFailedException e) {
              logger.error("Hang up was not successful: " + e);
            }
          }
        }
      }
    } else if (buttonName.equalsIgnoreCase("minimize")) {
      JCheckBoxMenuItem hideCallPanelItem =
          mainFrame.getMainMenu().getViewMenu().getHideCallPanelItem();

      if (!hideCallPanelItem.isSelected()) hideCallPanelItem.setSelected(true);

      this.setCallPanelVisible(false);
    } else if (buttonName.equalsIgnoreCase("restore")) {

      JCheckBoxMenuItem hideCallPanelItem =
          mainFrame.getMainMenu().getViewMenu().getHideCallPanelItem();

      if (hideCallPanelItem.isSelected()) hideCallPanelItem.setSelected(false);

      this.setCallPanelVisible(true);
    }
  }