SIP.js Documentation

repository·main·Indexed 24 days ago

https://github.com/onsip/sip.js

A JavaScript library for creating real-time peer-to-peer audio and video sessions via WebRTC using SIP over WebSockets. Compatible with standards-compliant servers like Asterisk and FreeSWITCH, it provides four levels of abstraction: the SimpleUser class for basic use, SessionManager for concurrent calls, a full API framework for complex applications, and a Core library for RFC-compliant foundational building blocks.

Tokens
192.9K
Snippets
663
Records
1.6K
Agent score
84%

What's inside sip.js

  1. Overview of the sip.js package

    main
    The sip.js package is a core library that implements low-level SIP (Session Initiation Protocol) elements. It provides the fundamental building blocks for creating SIP User Agents (Clients and Servers), managing transactions, and handling dialogs.
  2. Use the sip.js package for SIP and WebRTC

    main
    The sip.js package provides a high-level API for managing SIP signaling and WebRTC media sessions. It abstracts the complexities of SIP protocol handling and media negotiation, allowing developers to implement VoIP and video calling capabilities in JavaScript environments.
  3. Use the sip.js transport implementation for web browsers

    main
    The sip.js package provides a Transport implementation specifically designed for use in web browsers. This allows SIP communication to function within the constraints of browser environments (e.g., using WebSockets).
  4. Use the sip.js package for web browser SIP implementations

    main
    The sip.js package provides a simple SIP user implementation designed specifically for use in web browsers. It allows developers to implement SIP functionality (such as making and receiving calls) within a web application environment.
  5. What is a SIP Transaction?

    main

    SIP is a transactional protocol where interactions occur through independent message exchanges. A Transaction consists of a single request and its associated responses. This includes:

    • Zero or more provisional responses.
    • One or more final responses.

    Special Case: INVITE Transactions In an INVITE transaction, the ACK is included as part of the transaction only if the final response was not a 2xx response. If the response was 2xx, the ACK is not considered part of that transaction (per RFC 3261).

  6. What is SimpleUser and when to use it

    main

    The SimpleUser class provides a high-level, simplified interface for making audio and video calls in a web page. It is designed for single-page web browser applications where ease of use is prioritized over complex call management.

    When to use SimpleUser:

    • For standard audio/video calling in web apps.
    • When you only need to manage a single call at a time.
    • When you want a quick way to implement calling features without managing low-level SIP sessions.

    When to use alternatives:

    • If you need to manage multiple concurrent calls, use the SessionManager instead.
    • If you need full control over the SIP protocol and low-level signaling, use the core API directly.
  7. What is a Dialog in SIP.js

    main

    A Dialog represents a peer-to-peer SIP relationship between two user agents (UAs) that persists for a period of time. It provides the necessary context to interpret SIP messages, facilitates the sequencing of messages, and ensures proper routing of requests between the two agents.

    Key characteristics include:

    • Identification: A dialog is identified by a unique ID consisting of a Call-ID, a localTag, and a remoteTag.
    • States: A dialog can be in an early state (created with a provisional response) or a confirmed state (transitioned when a 2xx final response is received or sent).
    • Routing: It maintains a routeSet, which is an ordered list of URIs (servers) that must be traversed to reach the peer.
  8. What is UserAgentCore and how is it used?

    main

    The UserAgentCore class is the central engine for SIP entity processing in SIP.js. It implements the logic required for specific SIP roles, such as a User Agent (UAC/UAS), a Registrar, or a Stateful Proxy.

    In the SIP architecture, UserAgentCore resides above the transaction and transport layers. It manages the lifecycle of SIP dialogs, handles incoming requests and responses from the transport layer, and provides methods to initiate various SIP methods (like INVITE, REGISTER, or SUBSCRIBE).

    Key responsibilities include:

    • Managing dialogs (a Map of active SIP dialogs).
    • Managing userAgentClients (UACs) and userAgentServers (UASs).
    • Handling transport-level messages via receiveIncomingRequestFromTransport and receiveIncomingResponseFromTransport.
  9. What is the UserAgentClient class?

    main

    The UserAgentClient (UAC) is a logical entity responsible for initiating a new SIP request and managing its lifecycle using the client transaction state machinery.

    In the SIP protocol context, a software component acts as a UAC for the duration of a transaction it initiates. If that same software receives a request later, it transitions to the role of a User Agent Server (UAS) to process that transaction. This class implements the OutgoingRequest interface.

  10. What is a ServerTransaction?

    main

    A ServerTransaction is an abstraction responsible for delivering incoming SIP requests to the Transaction User (TU) and ensuring the reliable transmission of responses back to the sender. It operates as a state machine following the RFC 3261 specification.

    In sip.js, ServerTransaction instances are automatically created by the core when an incoming request is received and the system determines that transaction handling is required for that specific request.