Guides

End a Call

This guide uses the full SIP.js API. The Simple User is intended to help get beginners up and running quickly. This guide is adopted from the SIP.js Github API documentation.

Prerequisites

See the User Agent guide on how to create a user agent. This guide requires a registered user agent.

See the Make a Call guide on how to make a call.

See the Receive a Call guide on how to receive a call.

End Call

In SIP there are several ways to end a session depending on what state you are in. With SIP.js the application needs to be aware of the state of the session and call the proper method to end the session.

If it is an incoming SIP session that has not been established, you need to reject the session.

If it is an outgoing SIP session that has not been established, you need to cancel the session.

Lastly, on any established SIP session, you need to bye the session.

const session = ...

function endCall() {
  switch(session.state) {
    case SessionState.Initial:
    case SessionState.Establishing:
      if (session instanceOf Inviter) {
        // An unestablished outgoing session
        session.cancel();
      } else {
        // An unestablished incoming session
        session.reject();
      }
      break;
    case SessionState.Established:
      // An established session
      session.bye();
      break;
    case SessionState.Terminating:
    case SessionState.Terminated:
      // Cannot terminate a session that is already terminated
      break;
  }
}