pjsip-android icon indicating copy to clipboard operation
pjsip-android copied to clipboard

Sample application based on this SIPService. How to use this ?

Open zackbugti opened this issue 6 years ago • 8 comments

I have downloaded this and built, but it isn't running and I am facing difficulty understanding the code. So please somebody help me out how to make an application based on this. I need to develop just a simple application that could send/receive messages and calls. Please help me out somebody.

zackbugti avatar Aug 22 '19 23:08 zackbugti

Hi zackbugti I am also looking for any supporting information “how to start” or simple demo app. Cheers.

rrymm avatar Oct 25 '19 02:10 rrymm

Any update for this thread anyone??

janolaskar avatar Dec 04 '19 07:12 janolaskar

Any sample app??

shadowwalkersteam avatar Apr 06 '20 05:04 shadowwalkersteam

SipAccountData sipAccount = new SipAccountData();
SipServiceCommand.setEncryption(appContext, true, "alias");
// identifer of current call
int callId;
// identifer of current account
String accountId;

BroadcastEventReceiver event = new BroadcastEventReceiver(){
  @Override
  public void onStackStatus(boolean started) {
      if( ! started) {
          // something went wrong
      }
  }

  @Override
  public void onRegistration(String accountID, pjsip_status_code registrationStateCode) {
      if (registrationStateCode == pjsip_status_code.PJSIP_SC_OK) {
        Uri sipUri = Uri.parse(String.format("sip:%d@%s:%d", sipPayload.getCallId(), sipAccount.getHost(), sipAccount.getPort()));
        SipServiceCommand.makeCall(appContext, accountId, sipUri.toString());
      }
  }

  @Override
  public void onCallState(String accountID, int callID, pjsip_inv_state callStateCode, pjsip_status_code callStatusCode,
            long connectTimestamp, boolean isLocalHold, boolean isLocalMute, boolean isLocalVideoMute) {

      if(callStateCode == pjsip_inv_state.PJSIP_INV_STATE_CALLING){
          // current outgoing call
          callId = callID;
      }

      if(callStateCode == pjsip_inv_state.PJSIP_INV_STATE_DISCONNECTED){
          // end of call
      }
  }
});

// register events
event.register(appContext);
// init account 
sipAccount.setHost(sipPayload.getHost())
      .setPort(sipPayload.getPort())
      .setTcpTransport(true)
      .setUsername(sipPayload.getUser())
      .setPassword(sipPayload.getPassword())
      .setRealm(sipPayload.getHost())
      .setContactUriParams("")
;
// add account to the service
accountId = SipServiceCommand.setAccount(appContext, sipAccount);

...

// after end, unregister event
event.unregister(appContext);

jackkum avatar Apr 06 '20 07:04 jackkum

what is the format to dial a number or to make a call? I was using sip:#####@server_address But this is not working

shadowwalkersteam avatar Apr 07 '20 17:04 shadowwalkersteam

I have asterisk sip server with user context client, so dialplan for this user looks like that:

[client]
; ${EXTEN} here is a sipPayload.getCallId() from sip:1000@server:port
exten => _X.,1,SomeWorkWith(${EXTEN})
exten => _X.,2,MeetMe(${ROOM})

If you want to dial some phone number you should configure that on your sip server. Asterisk dialplan should be looks like that:

[client_context]
exten => _X.,1,SomeCheckExten(${EXTEN})
exten => _X.,2,Dial(SIP/CHANNEL_THROUGH/EXTEN)
; or dial some sip user
; exten => _X.,2,Dial(SIP/USER/USER)

jackkum avatar Apr 07 '20 23:04 jackkum

A simple sample project can see Here. Just replace the sip configuration with your own. Hope it helps you!

fengfeilong0529 avatar Nov 24 '20 02:11 fengfeilong0529

Thank you very much!

SachithKasthuriarachchi avatar Nov 24 '20 13:11 SachithKasthuriarachchi