src/net/java/sip/communicator/impl/protocol/jabber/CallJabberImpl.java
/**
     * Creates a new call peer and sends a RINGING response.
     *
     * @param jingleIQ the {@link JingleIQ} that created the session.
     *
     * @return the newly created {@link CallPeerJabberImpl} (the one that sent
     * the INVITE).
     */
Creates a new call peer and sends a RINGING response.
@param jingleIQ the  JingleIQ that created the session.

@return the newly created  CallPeerJabberImpl (the one that sent
the INVITE).
Creates a new call peer and sends a RINGING response . @param jingleIQ the JingleIQ that created the session . @return the newly created CallPeerJabberImpl ( the one that sent the INVITE ) .
public CallPeerJabberImpl processSessionInitiate(JingleIQ jingleIQ)
    {
        Jid remoteParty = jingleIQ.getFrom();
        boolean autoAnswer = false;
        CallPeerJabberImpl attendant = null;
        OperationSetBasicTelephonyJabberImpl basicTelephony = null;
        CallPeerJabberImpl callPeer
            = new CallPeerJabberImpl(remoteParty, this, jingleIQ);
        addCallPeer(callPeer);
        /*
         * We've already sent ack to the specified session-initiate so if it has
         * been sent as part of an attended transfer, we have to hang up on the
         * attendant.
         */
        try
        {
            TransferPacketExtension transfer
                = (TransferPacketExtension)
                    jingleIQ.getExtension(
                            TransferPacketExtension.ELEMENT_NAME,
                            TransferPacketExtension.NAMESPACE);
            if (transfer != null)
            {
                String sid = transfer.getSID();
                if (sid != null)
                {
                    ProtocolProviderServiceJabberImpl protocolProvider
                        = getProtocolProvider();
                    basicTelephony
                        = (OperationSetBasicTelephonyJabberImpl)
                            protocolProvider.getOperationSet(
                                    OperationSetBasicTelephony.class);
                    CallJabberImpl attendantCall
                        = basicTelephony
                            .getActiveCallsRepository()
                                .findSID(sid);
                    if (attendantCall != null)
                    {
                        attendant = attendantCall.getPeer(sid);
                        if ((attendant != null)
                                && basicTelephony
                                    .getFullCalleeURI(attendant.getAddress())
                                        .equals(transfer.getFrom())
                                && protocolProvider.getOurJID().equals(
                                        transfer.getTo()))
                        {
                            autoAnswer = true;
                        }
                    }
                }
            }
        }
        catch (Throwable t)
        {
            logger.error(
                    "Failed to hang up on attendant"
                        + " as part of session transfer",
                    t);
            if (t instanceof ThreadDeath)
                throw (ThreadDeath) t;
        }
        CoinPacketExtension coin
            = jingleIQ.getExtension(
                    CoinPacketExtension.ELEMENT_NAME,
                    CoinPacketExtension.NAMESPACE);
        if (coin != null)
        {
            boolean b
                = Boolean.parseBoolean(
                        (String)
                            coin.getAttribute(
                                    CoinPacketExtension.ISFOCUS_ATTR_NAME));
            callPeer.setConferenceFocus(b);
        }
        try
        {
            callPeer.processSessionInitiate(jingleIQ);
        }
        catch (SmackException.NotConnectedException | InterruptedException e)
        {
            callPeer.setState( CallPeerState.INCOMING_CALL );
            return null;
        }
        if (getProtocolProvider().getAccountID().getAccountPropertyBoolean(
                ProtocolProviderFactory.MODE_PARANOIA, false)
            && callPeer.getMediaHandler().getAdvertisedEncryptionMethods()
                    .length
                == 0)
        {
            String reasonText
                = JabberActivator.getResources().getI18NString(
                        "service.gui.security.encryption.required");
            JingleIQ errResp
                = JinglePacketFactory.createSessionTerminate(
                        jingleIQ.getTo(),
                        jingleIQ.getFrom(),
                        jingleIQ.getSID(),
                        Reason.SECURITY_ERROR,
                        reasonText);
            callPeer.setState(CallPeerState.FAILED, reasonText);
            try
            {
                getProtocolProvider().getConnection().sendStanza(errResp);
            }
            catch (SmackException.NotConnectedException | InterruptedException e)
            {
                logger.error("Could not send session terminate", e);
                return null;
            }
            return null;
        }
        if (callPeer.getState() == CallPeerState.FAILED)
            return null;
        callPeer.setState( CallPeerState.INCOMING_CALL );
        if (autoAnswer)
        {
            /* answer directly */
            try
            {
                callPeer.answer();
            }
            catch(Exception e)
            {
                logger.info(
                        "Exception occurred while answer transferred call",
                        e);
                callPeer = null;
            }
            try
            {
                basicTelephony.hangupCallPeer(attendant);
            }
            catch(OperationFailedException e)
            {
                logger.error(
                        "Failed to hang up on attendant as part of session"
                            + " transfer",
                        e);
            }
            return callPeer;
        }
        /* see if offer contains audio and video so that we can propose
         * option to the user (i.e. answer with video if it is a video call...)
         */
        List<ContentPacketExtension> offer
            = callPeer.getSessionIQ().getContentList();
        Map<MediaType, MediaDirection> directions
            = new HashMap<>();
        directions.put(MediaType.AUDIO, MediaDirection.INACTIVE);
        directions.put(MediaType.VIDEO, MediaDirection.INACTIVE);
        for (ContentPacketExtension c : offer)
        {
            String contentName = c.getName();
            MediaDirection remoteDirection
                = JingleUtils.getDirection(c, callPeer.isInitiator());
            if (MediaType.AUDIO.toString().equals(contentName))
                directions.put(MediaType.AUDIO, remoteDirection);
            else if (MediaType.VIDEO.toString().equals(contentName))
                directions.put(MediaType.VIDEO, remoteDirection);
        }
        if (getCallPeerCount() == 1)
        {
            parentOpSet.fireCallEvent(
                    CallEvent.CALL_RECEIVED,
                    this,
                    directions);
        }
        OperationSetAutoAnswerJabberImpl autoAnswerOpSet
            = (OperationSetAutoAnswerJabberImpl)
                getProtocolProvider().getOperationSet(
                        OperationSetBasicAutoAnswer.class);
        if (autoAnswerOpSet != null)
            autoAnswerOpSet.autoAnswer(this, directions);
        return callPeer;
    }
public CallPeerJabberImpl processSessionInitiate ( JingleIQ jingleIQ ) { Jid remoteParty = jingleIQ . getFrom ( ) ; boolean autoAnswer = false ; CallPeerJabberImpl attendant = null ; OperationSetBasicTelephonyJabberImpl basicTelephony = null ; CallPeerJabberImpl callPeer = new CallPeerJabberImpl ( remoteParty , this , jingleIQ ) ; addCallPeer ( callPeer ) ; /*
         * We've already sent ack to the specified session-initiate so if it has
         * been sent as part of an attended transfer, we have to hang up on the
         * attendant.
         */ try { TransferPacketExtension transfer = ( TransferPacketExtension ) jingleIQ . getExtension ( TransferPacketExtension . ELEMENT_NAME , TransferPacketExtension . NAMESPACE ) ; if ( transfer != null ) { String sid = transfer . getSID ( ) ; if ( sid != null ) { ProtocolProviderServiceJabberImpl protocolProvider = getProtocolProvider ( ) ; basicTelephony = ( OperationSetBasicTelephonyJabberImpl ) protocolProvider . getOperationSet ( OperationSetBasicTelephony . class ) ; CallJabberImpl attendantCall = basicTelephony . getActiveCallsRepository ( ) . findSID ( sid ) ; if ( attendantCall != null ) { attendant = attendantCall . getPeer ( sid ) ; if ( ( attendant != null ) && basicTelephony . getFullCalleeURI ( attendant . getAddress ( ) ) . equals ( transfer . getFrom ( ) ) && protocolProvider . getOurJID ( ) . equals ( transfer . getTo ( ) ) ) { autoAnswer = true ; } } } } } catch ( Throwable t ) { logger . error ( "Failed to hang up on attendant" + " as part of session transfer" , t ) ; if ( t instanceof ThreadDeath ) throw ( ThreadDeath ) t ; } CoinPacketExtension coin = jingleIQ . getExtension ( CoinPacketExtension . ELEMENT_NAME , CoinPacketExtension . NAMESPACE ) ; if ( coin != null ) { boolean b = Boolean . parseBoolean ( ( String ) coin . getAttribute ( CoinPacketExtension . ISFOCUS_ATTR_NAME ) ) ; callPeer . setConferenceFocus ( b ) ; } try { callPeer . processSessionInitiate ( jingleIQ ) ; } catch ( SmackException . NotConnectedException | InterruptedException e ) { callPeer . setState ( CallPeerState . INCOMING_CALL ) ; return null ; } if ( getProtocolProvider ( ) . getAccountID ( ) . getAccountPropertyBoolean ( ProtocolProviderFactory . MODE_PARANOIA , false ) && callPeer . getMediaHandler ( ) . getAdvertisedEncryptionMethods ( ) . length == 0 ) { String reasonText = JabberActivator . getResources ( ) . getI18NString ( "service.gui.security.encryption.required" ) ; JingleIQ errResp = JinglePacketFactory . createSessionTerminate ( jingleIQ . getTo ( ) , jingleIQ . getFrom ( ) , jingleIQ . getSID ( ) , Reason . SECURITY_ERROR , reasonText ) ; callPeer . setState ( CallPeerState . FAILED , reasonText ) ; try { getProtocolProvider ( ) . getConnection ( ) . sendStanza ( errResp ) ; } catch ( SmackException . NotConnectedException | InterruptedException e ) { logger . error ( "Could not send session terminate" , e ) ; return null ; } return null ; } if ( callPeer . getState ( ) == CallPeerState . FAILED ) return null ; callPeer . setState ( CallPeerState . INCOMING_CALL ) ; if ( autoAnswer ) { /* answer directly */ try { callPeer . answer ( ) ; } catch ( Exception e ) { logger . info ( "Exception occurred while answer transferred call" , e ) ; callPeer = null ; } try { basicTelephony . hangupCallPeer ( attendant ) ; } catch ( OperationFailedException e ) { logger . error ( "Failed to hang up on attendant as part of session" + " transfer" , e ) ; } return callPeer ; } /* see if offer contains audio and video so that we can propose
         * option to the user (i.e. answer with video if it is a video call...)
         */ List < ContentPacketExtension > offer = callPeer . getSessionIQ ( ) . getContentList ( ) ; Map < MediaType , MediaDirection > directions = new HashMap < > ( ) ; directions . put ( MediaType . AUDIO , MediaDirection . INACTIVE ) ; directions . put ( MediaType . VIDEO , MediaDirection . INACTIVE ) ; for ( ContentPacketExtension c : offer ) { String contentName = c . getName ( ) ; MediaDirection remoteDirection = JingleUtils . getDirection ( c , callPeer . isInitiator ( ) ) ; if ( MediaType . AUDIO . toString ( ) . equals ( contentName ) ) directions . put ( MediaType . AUDIO , remoteDirection ) ; else if ( MediaType . VIDEO . toString ( ) . equals ( contentName ) ) directions . put ( MediaType . VIDEO , remoteDirection ) ; } if ( getCallPeerCount ( ) == 1 ) { parentOpSet . fireCallEvent ( CallEvent . CALL_RECEIVED , this , directions ) ; } OperationSetAutoAnswerJabberImpl autoAnswerOpSet = ( OperationSetAutoAnswerJabberImpl ) getProtocolProvider ( ) . getOperationSet ( OperationSetBasicAutoAnswer . class ) ; if ( autoAnswerOpSet != null ) autoAnswerOpSet . autoAnswer ( this , directions ) ; return callPeer ; }
Creates a new call peer and sends a RINGING response.
Creates a new call peer and sends a RINGING response .
// Use the IQs 'from', instead of the jingle 'initiator' field, // because we want to make sure that following IQs are sent with the // correct 'to'. //basicTelephony.hangupCallPeer(attendant); //before notifying about this call, make sure that it looks alright // if paranoia is set, to accept the call we need to know that // the other party has support for media encryption //send an error response; // in case of attended transfer, auto answer the call // hang up now // If this was the first peer we added in this call, then the call is // new and we need to notify everyone of its creation. // Manages auto answer with "audio only", or "audio/video" answer.