2015-10-12 56 views
1

我已經嘗試過Mobisents中的jainsip示例restcomm-android-sdk.Its爲我工作,但我無法正確地從客戶端創建再見消息。如何在jainsip android中創建併發送從客戶端到服務器的再見消息?

我創建了一個BYE消息類這樣

public class Bye { 

public Request MakeRequest(SipManager sipManager) throws ParseException, 
     InvalidArgumentException { 

    AddressFactory addressFactory = sipManager.addressFactory; 
    SipProvider sipProvider = sipManager.sipProvider; 
    MessageFactory messageFactory = sipManager.messageFactory; 
    HeaderFactory headerFactory = sipManager.headerFactory; 
    // Create addresses and via header for the request 
    Address fromAddress = addressFactory.createAddress("sip:" 
      + sipManager.getSipProfile().getSipUserName() + "@" 
      + sipManager.getSipProfile().getRemoteIp()); 
    fromAddress.setDisplayName(sipManager.getSipProfile().getSipUserName()); 
    Address toAddress = addressFactory.createAddress("sip:" 
      + sipManager.getSipProfile().getSipUserName() + "@" 
      + sipManager.getSipProfile().getRemoteIp()); 
    toAddress.setDisplayName(sipManager.getSipProfile().getSipUserName()); 

    Address contactAddress = sipManager.createContactAddress(); 
    ArrayList<ViaHeader> viaHeaders = sipManager.createViaHeader(); 
    URI requestURI = addressFactory.createAddress(
      "sip:" + sipManager.getSipProfile().getRemoteEndpoint()) 
      .getURI(); 
    // Build the request 
    CallIdHeader callIdHeader = sipManager.sipProvider.; 
    final Request request = messageFactory.createRequest(requestURI, 
      Request.BYE, sipProvider.getNewCallId(), 
      headerFactory.createCSeqHeader(1l, Request.BYE), 
      headerFactory.createFromHeader(fromAddress, "c3ff411e"), 
      headerFactory.createToHeader(toAddress, null), viaHeaders, 
      headerFactory.createMaxForwardsHeader(70)); 

    // Add the contact header 
    request.addHeader(headerFactory.createContactHeader(contactAddress)); 
    ExpiresHeader eh = headerFactory.createExpiresHeader(300); 
    request.addHeader(eh); 
    // Print the request 
    System.out.println(request.toString()); 
    return request; 
    // Send the request --- triggers an IOException 
    // sipProvider.sendRequest(request); 
    // ClientTransaction transaction = sipProvider 
    // .getNewClientTransaction(request); 
    // Send the request statefully, through the client transaction. 
    // transaction.sendRequest(); 

} 
} 

說它從SipManager類作爲

public void disconnectCall() throws NotInitializedException { 
    // TODO Auto-generated method stub 
    if (!initialized) 
     throw new NotInitializedException("Sip Stack not initialized"); 
    this.sipManagerState = SipManagerState.BYE; 
    Bye byeRequest = new Bye(); 
    Request r=null ; 
    try{ 
    r = byeRequest.MakeRequest(this);//byeRequest.MakeRequest(SipManager.this); 

     final ClientTransaction transaction = this.sipProvider 
       .getNewClientTransaction(r); 
     Thread thread = new Thread() { 
      public void run() { 
       try { 
        transaction.sendRequest(); 
       } catch (SipException e) { 
        e.printStackTrace(); 
       } 
      } 
     }; 
     thread.start(); 
    } catch (TransactionUnavailableException e) { 
     e.printStackTrace(); 
    }catch (InvalidArgumentException e) { 
     e.printStackTrace(); 
    } catch (ParseException e) { 
     e.printStackTrace(); 
    } 

} 

我有481錯誤代碼response.I想我已經錯過了當前呼叫字段中的再見消息。我已經搜索過它,但沒有從sipmanager class.pls幫助中找到。

回答

3

Nidhin,

BYE的消息始終是一個SIP對話裏面,這樣你就不必從頭開始創建一個新的消息。相反,您只需要查看要終止的對話框,從中創建一個類型爲BYE的請求併發送它。 JAIN將負責其餘的事情。

舉個例子,你可以檢查在Mobicents restcomm-Android的SDK回購的代碼,方法sendByeClient():

https://github.com/Mobicents/restcomm-android-sdk/blob/master/sipua/src/main/java/org/mobicents/restcomm/android/sipua/impl/SipManager.java#L931

也請記住,在JAIN SIP例子已過時通過使用Restcomm Android客戶端SDK的Messenger例子,它提供了一個更簡單的API。以下代碼供您參考:

https://github.com/Mobicents/restcomm-android-sdk/tree/master/Examples/restcomm-messenger

相關問題