public void connectionOpenResponse(MsConnectionEvent event, SipServletResponse response) {
    logger.info("connection opened " + event);

    String sdp = event.getConnection().getLocalDescriptor();
    SipServletRequest ack = response.createAck();

    try {
      ack.setContent(sdp, "application/sdp");
      ack.send();
    } catch (Exception e) {
      logger.error(e);
    }
    provider = ConferenceCenter.getInstance().getProvider();
    MsConnection connection = event.getConnection();
    MsEndpoint endpoint = connection.getEndpoint();
    MsSession session = connection.getSession();
    String callerName = response.getTo().getURI().toString();

    ConferenceParticipant participant =
        new EndpointConferenceParticipant(callerName, endpoint, session, response, connection);

    String key = SipGwtConferenceConsole.CONFERENCE_NAME;

    ConferenceCenter.getInstance().getConference(key).joinParticipant(participant);
  }
Пример #2
0
 @Override
 protected void handleAck(final SIPCallImpl call, final SipServletRequest req) throws Exception {
   final SipServletResponse res =
       (SipServletResponse) req.getSession().getAttribute(REINVITE_PEER_RES);
   final SipServletRequest newReq = res.createAck();
   SIPHelper.copyContent(req, newReq);
   newReq.send();
 }
  @Override
  protected void doSuccessResponse(SipServletResponse resp) throws ServletException, IOException {
    logger.info("Got OK");
    SipSession session = resp.getSession();

    if (resp.getStatus() == SipServletResponse.SC_OK) {

      Boolean inviteSent = (Boolean) session.getAttribute("InviteSent");
      if (inviteSent != null && inviteSent.booleanValue()) {
        return;
      }
      Address secondPartyAddress = (Address) resp.getSession().getAttribute("SecondPartyAddress");
      if (secondPartyAddress != null) {

        SipServletRequest invite =
            sipFactory.createRequest(
                resp.getApplicationSession(),
                "INVITE",
                session.getRemoteParty(),
                secondPartyAddress);

        logger.info("Found second party -- sending INVITE to " + secondPartyAddress);

        String contentType = resp.getContentType();
        if (contentType.trim().equals("application/sdp")) {
          invite.setContent(resp.getContent(), "application/sdp");
        }

        session.setAttribute("LinkedSession", invite.getSession());
        invite.getSession().setAttribute("LinkedSession", session);

        SipServletRequest ack = resp.createAck();
        invite.getSession().setAttribute("FirstPartyAck", ack);
        invite.getSession().setAttribute("FirstPartyContent", resp.getContent());

        Call call = (Call) session.getAttribute("call");

        // The call links the two sessions, add the new session to the call
        call.addSession(invite.getSession());
        invite.getSession().setAttribute("call", call);

        invite.send();

        session.setAttribute("InviteSent", Boolean.TRUE);
      } else {
        String cSeqValue = resp.getHeader("CSeq");
        if (cSeqValue.indexOf("INVITE") != -1) {
          logger.info("Got OK from second party -- sending ACK");

          SipServletRequest secondPartyAck = resp.createAck();
          SipServletRequest firstPartyAck =
              (SipServletRequest) resp.getSession().getAttribute("FirstPartyAck");

          //					if (resp.getContentType() != null &&
          // resp.getContentType().equals("application/sdp")) {
          firstPartyAck.setContent(resp.getContent(), "application/sdp");
          secondPartyAck.setContent(
              resp.getSession().getAttribute("FirstPartyContent"), "application/sdp");
          //					}

          firstPartyAck.send();
          secondPartyAck.send();
        }
      }
    }
  }
Пример #4
0
  @Override
  protected void doInviteResponse(
      final SipServletResponse res, final SIPCallImpl call, final Map<String, String> headers)
      throws Exception {
    try {
      if (_call2.equals(call)) {
        if (SIPHelper.isProvisionalResponse(res)) {
          call.setSIPCallState(SIPCall.State.ANSWERING);

          if (res.getStatus() == SipServletResponse.SC_SESSION_PROGRESS) {
            if (SIPHelper.getRawContentWOException(res) != null) {
              ((SIPOutgoingCall) _call1)
                  .call(res.getRawContent(), _call2.getSipSession().getApplicationSession());
              _invitedCall1 = true;
            }
            try {
              res.createPrack().send();
            } catch (Rel100Exception ex) {
              LOG.warn(ex.getMessage());
            } catch (IllegalStateException ex) {
              LOG.warn(ex.getMessage());
            }
          }
        } else if (SIPHelper.isSuccessResponse(res)) {
          _response = res;
          if (!_invitedCall1) {
            ((SIPOutgoingCall) _call1)
                .call(res.getRawContent(), _call2.getSipSession().getApplicationSession());
          }
        } else if (SIPHelper.isErrorResponse(res)) {
          Exception ex = getExceptionByResponse(res);
          done(getJoinCompleteCauseByResponse(res), ex);
          _call2.disconnect(true, getCallCompleteCauseByResponse(res), ex, null);
        }
      } else if (_call1.equals(call)) {
        if (SIPHelper.isProvisionalResponse(res)) {
          call.setSIPCallState(SIPCall.State.ANSWERING);

          if (res.getStatus() == SipServletResponse.SC_SESSION_PROGRESS) {
            if (SIPHelper.getRawContentWOException(res) != null) {
              SipServletRequest ack2 = null;
              if (_response != null) {
                final SipServletResponse origRes = _response;
                _response = null;
                ack2 = origRes.createAck();
                SIPHelper.copyContent(res, ack2);
              }
              ack2.send();

              _ackedCall2 = true;
            }
            try {
              res.createPrack().send();
            } catch (Rel100Exception ex) {
              LOG.warn("", ex);
            }
          }
        } else if (SIPHelper.isSuccessResponse(res)) {
          final SipServletRequest ack1 = res.createAck();
          ack1.send();

          if (!_ackedCall2) {
            SipServletRequest ack2 = null;
            if (_response != null) {
              final SipServletResponse origRes = _response;
              _response = null;
              ack2 = origRes.createAck();
              SIPHelper.copyContent(res, ack2);
            }
            ack2.send();
          }

          _call2.setSIPCallState(State.ANSWERED);
          _call1.setSIPCallState(State.ANSWERED);
          _call1.linkCall(_call2, JoinType.DIRECT, _direction);
          done(JoinCompleteEvent.Cause.JOINED, null);
        } else if (SIPHelper.isErrorResponse(res)) {
          Exception ex = getExceptionByResponse(res);
          done(getJoinCompleteCauseByResponse(res), ex);
          _call1.disconnect(true, getCallCompleteCauseByResponse(res), ex, null);
          _call2.disconnect(true, getCallCompleteCauseByResponse(res), ex, null);
        }
      }
    } catch (final Exception e) {
      done(JoinCompleteEvent.Cause.ERROR, e);
      _call1.fail(e);
      _call2.fail(e);
      throw e;
    }
  }
Пример #5
0
  @Override
  protected void handleReinviteResponse(
      final SIPCallImpl call, final SipServletResponse res, final Map<String, String> headers) {

    if (res.getRequest().getAttribute(SIPCallDelegate.SIPCALL_HOLD_REQUEST) != null
        || res.getRequest().getAttribute(SIPCallDelegate.SIPCALL_UNHOLD_REQUEST) != null
        || res.getRequest().getAttribute(SIPCallDelegate.SIPCALL_DEAF_REQUEST) != null) {
      try {
        res.createAck().send();
        if (call.getHoldState() == HoldState.Holding) {
          call.setHoldState(HoldState.Held);
        } else if (call.getHoldState() == HoldState.UnHolding) {
          call.setHoldState(HoldState.None);
        } else if (call.getDeafState() == HoldState.Deafing) {
          call.setDeafState(HoldState.Deafed);
        } else if (call.getDeafState() == HoldState.Undeafing) {
          call.setDeafState(HoldState.None);
        }
      } catch (IOException e) {
        LOG.error("IOException when sending back ACK.", e);
        call.setHoldState(HoldState.None);
        call.setDeafState(HoldState.None);
        call.fail(e);
      } finally {
        call.notify();
      }
    } else if (res.getRequest().getAttribute(SIPCallDelegate.SIPCALL_MUTE_REQUEST) != null
        || res.getRequest().getAttribute(SIPCallDelegate.SIPCALL_UNMUTE_REQUEST) != null) {
      // send ACK.
      try {
        res.createAck().send();

        // send the received SDP to peer.
        final SIPCallImpl peer = (SIPCallImpl) call.getLastPeer();
        synchronized (peer) {
          if (call.getMuteState() == HoldState.Muting) {
            peer.setDeafState(HoldState.Deafing);
          } else {
            peer.setDeafState(HoldState.Undeafing);
          }

          SipServletRequest reInvite = peer.getSipSession().createRequest("INVITE");
          reInvite.setAttribute(SIPCallDelegate.SIPCALL_DEAF_REQUEST, "true");
          reInvite.setContent(res.getRawContent(), "application/sdp");
          reInvite.send();

          while (peer.getDeafState() != HoldState.Deafed && peer.getDeafState() != HoldState.None) {
            try {
              peer.wait();
            } catch (InterruptedException e) {
              LOG.warn(
                  "InterruptedException when wait make peer deaf, the peer's DeafState "
                      + peer.getDeafState());
            }
          }

          // set call deaf state
          if (call.getMuteState() == HoldState.Muting) {
            peer.setDeafState(HoldState.Deafed);
            call.setMuteState(HoldState.Muted);
          } else if (call.getMuteState() == HoldState.UnMuting) {
            peer.setDeafState(HoldState.None);
            call.setMuteState(HoldState.None);
          }
        }
      } catch (IOException e1) {
        LOG.error("IOException", e1);
        call.setMuteState(HoldState.None);
        call.fail(e1);
      } finally {
        call.notify();
      }
    } else {
      try {
        final SipServletRequest req = res.getRequest();
        final SipServletRequest newReq = (SipServletRequest) SIPHelper.getLinkSIPMessage(req);
        if (newReq != null) {
          SIPHelper.unlinkSIPMessage(req);
          final SipServletResponse newRes =
              newReq.createResponse(res.getStatus(), res.getReasonPhrase());
          SIPHelper.addHeaders(newRes, headers);
          SIPHelper.copyContent(res, newRes);
          if (SIPHelper.isReinvite(newRes)) {
            newRes.getSession().setAttribute(REINVITE_PEER_RES, res);
          }
          newRes.send();
        }
      } catch (final Exception e) {
        LOG.warn("", e);
        return;
      }
    }
  }