### Install Dependencies and Build Demo - npm Source: https://github.com/onsip/sip.js/blob/main/demo/README.md Use these npm commands to install project dependencies and build the demonstration files. ```bash npm install npm run build-demo ``` -------------------------------- ### Package and Test Installation Locally Source: https://github.com/onsip/sip.js/blob/main/RELEASE.md Use `npm pack` to create a tarball of the package, simulating the publishing process. Install this tarball in a separate project to verify that the package includes only the intended files and installs correctly. ```bash npm pack cd /path/to/project npm install /path/to/package.tgz ``` -------------------------------- ### Install SIP.js via npm Source: https://github.com/onsip/sip.js/blob/main/README.md Install the SIP.js library using npm for Node.js projects. ```sh npm install sip.js ``` -------------------------------- ### Install Node.js Dependencies Source: https://github.com/onsip/sip.js/blob/main/docs/BUILDING.md Install all the necessary Node.js packages required for development and building. ```bash $ npm install ``` -------------------------------- ### UserAgent.start() Source: https://github.com/onsip/sip.js/blob/main/docs/api/sip.js.useragent.start.md Starts the user agent. The promise resolves if the transport connects successfully, otherwise it rejects. Note that calling start() after stop() has been called will fail if stop() has not yet resolved. ```APIDOC ## UserAgent.start() ### Description Starts the user agent. The promise resolves if the transport connects successfully, otherwise it rejects. Calling `start()` after calling `stop()` will fail if `stop()` has yet to resolve. ### Method ```typescript start(): Promise; ``` ### Returns Promise ### Example ```typescript userAgent.start() .then(() => { // userAgent.isConnected() === true }) .catch((error: Error) => { // userAgent.isConnected() === false }); ``` ``` -------------------------------- ### Construct, Start, and Stop UserAgent (0.15.x) Source: https://github.com/onsip/sip.js/blob/main/docs/migration-0.15-0.16.md Illustrates the previous method of initializing, starting, and stopping the UA in version 0.15.x. ```typescript const uri = "sip:alice@example.com"; const options = { uri: uri // Set various other options }; const ua = new UA(options); ua.start(); ua.stop(); ``` -------------------------------- ### Construct, Start, and Stop UserAgent (0.16.x) Source: https://github.com/onsip/sip.js/blob/main/docs/migration-0.15-0.16.md Demonstrates the updated approach for initializing, starting, and stopping the UserAgent in version 0.16.x, which now uses Promises for asynchronous operations. ```typescript const uri = UserAgent.makeURI("sip:alice@example.com"); if (!uri) { // Failed to create URI } const options: UserAgentOptions = { uri: uri, // Set various other options }; const userAgent = new UserAgent(options); userAgent.start() .then(() => { console.log("Connected"); userAgent.stop() .then(() => { console.log("Stopped"); }) .catch((error) => { console.error("Failed to stop"); }); }) .catch((error) => { console.error("Failed to connect"); }); ``` -------------------------------- ### SimpleUser.connect() Source: https://github.com/onsip/sip.js/blob/main/docs/simple-user/sip.js.simpleuser.connect.md Connect starts the UserAgent's WebSocket Transport. ```APIDOC ## connect() ### Description Connect starts the UserAgent's WebSocket Transport. ### Method connect ### Returns Promise ``` -------------------------------- ### Build and Test SIP.js Source: https://github.com/onsip/sip.js/blob/main/README.md Build the project and run tests after cloning the repository. This command installs dependencies, builds the library, and executes tests. ```sh npm install npm run build-and-test ``` -------------------------------- ### SimpleUser Call Example Source: https://github.com/onsip/sip.js/blob/main/docs/simple-user.md Demonstrates making an audio call using SimpleUser. This includes setting up the audio element, configuring the SimpleUser instance, connecting to the server, and placing a call. It also shows how to handle incoming calls by providing a delegate. ```typescript import { Web } from "sip.js"; // Helper function to get an HTML audio element function getAudioElement(id: string): HTMLAudioElement { const el = document.getElementById(id); if (!(el instanceof HTMLAudioElement)) { throw new Error(`Element "${id}" not found or not an audio element.`); } return el; } // Helper function to wait async function wait(ms: number): Promise { return new Promise((resolve) => { setTimeout(resolve, ms); }); } // Main function async function main(): Promise { // SIP over WebSocket Server URL // The URL of a SIP over WebSocket server which will complete the call. // FreeSwitch is an example of a server which supports SIP over WebSocket. // SIP over WebSocket is an internet standard the details of which are // outside the scope of this documentation, but there are many resources // available. See: https://tools.ietf.org/html/rfc7118 for the specification. const server = "wss://sip.example.com"; // SIP Request URI // The SIP Request URI of the destination. It's "Who you wanna call?" // SIP is an internet standard the details of which are outside the // scope of this documentation, but there are many resources available. // See: https://tools.ietf.org/html/rfc3261 for the specification. const destination = "sip:bob@example.com"; // SIP Address of Record (AOR) // This is the user's SIP address. It's "Where people can reach you." // SIP is an internet standard the details of which are outside the // scope of this documentation, but there are many resources available. // See: https://tools.ietf.org/html/rfc3261 for the specification. const aor = "sip:alice@example.com"; // Configuration Options // These are configuration options for the `SimpleUser` instance. // Here we are setting the HTML audio element we want to use to // play the audio received from the remote end of the call. // An audio element is needed to play the audio received from the // remote end of the call. Once the call is established, a `MediaStream` // is attached to the provided audio element's `src` attribute. const options: Web.SimpleUserOptions = { aor, media: { remote: { audio: getAudioElement("remoteAudio") } } }; // Construct a SimpleUser instance const simpleUser = new Web.SimpleUser(server, options); // Supply delegate to handle inbound calls (optional) simpleUser.delegate = { onCallReceived: async () => { await simpleUser.answer(); } }; // Connect to server await simpleUser.connect(); // Register to receive inbound calls (optional) await simpleUser.register(); // Place call to the destination await simpleUser.call(destination); // Wait some number of milliseconds await wait(5000); // Hangup call await simpleUser.hangup(); } // Run it main() .then(() => console.log(`Success`)) .catch((error: Error) => console.error(`Failure`, error)); ``` -------------------------------- ### Implement UserAgent autoStart Behavior Source: https://github.com/onsip/sip.js/blob/main/docs/migration-0.20-0.21.md To replicate the removed 'autoStart' functionality, explicitly call the start() method on the UserAgent instance after construction. ```typescript // Construct the UserAgent userAgent = new UserAgent(/* options */); // Call start userAgent.start(); ``` -------------------------------- ### Full SimpleUser Lifecycle Example Source: https://context7.com/onsip/sip.js/llms.txt Demonstrates the complete lifecycle of a `SimpleUser` instance: connecting to the server, registering for calls, placing and answering calls, and finally hanging up and disconnecting. Includes event delegation for call status updates. ```typescript import { Web } from "sip.js"; const simpleUser = new Web.SimpleUser("wss://sip.example.com", { aor: "sip:alice@example.com", media: { remote: { audio: document.getElementById("remoteAudio") as HTMLAudioElement } } }); // Delegate: react to call events simpleUser.delegate = { onCallReceived: async () => { console.log("Incoming call – answering..."); await simpleUser.answer(); }, onCallAnswered: () => console.log("Call is established"), onCallHangup: () => console.log("Call ended"), onCallHold: (held: boolean) => console.log("Hold state:", held), onCallDTMFReceived: (tone: string, duration: number) => console.log(`DTMF received: ${tone} (${duration} ms)`), onMessageReceived: (message: string) => console.log("Message:", message), onRegistered: () => console.log("Registered"), onUnregistered: () => console.log("Unregistered"), onServerConnect: () => console.log("Connected to server"), onServerDisconnect: (error?: Error) => console.error("Disconnected", error) }; async function main() { await simpleUser.connect(); // open WebSocket transport await simpleUser.register(); // send REGISTER to receive inbound calls // Place an outbound call await simpleUser.call("sip:bob@example.com", { sessionDescriptionHandlerOptions: { constraints: { audio: true, video: false } } }); await new Promise(r => setTimeout(r, 10_000)); // wait while in call await simpleUser.hangup(); // send BYE / CANCEL / 480 await simpleUser.unregister(); await simpleUser.disconnect(); } main().catch(console.error); ``` -------------------------------- ### Start and End Call with Simple Source: https://github.com/onsip/sip.js/blob/main/docs/migration-simple.md Initiate a call and set up an event listener to hang up the call. ```javascript var endButton = document.getElementById('endCall'); endButton.addEventListener("click", function () { simple.hangup(); alert("Call Ended"); }, false); simple.call('welcome@onsip.com'); ``` -------------------------------- ### startLocalConference Source: https://github.com/onsip/sip.js/blob/main/etc/session-description-handler/sip.js.api.md Starts a local conference with the provided sessions. ```APIDOC ## startLocalConference ### Description Initiates a local conference call with multiple participants. ### Parameters - **conferenceSessions** (Array) - An array of Session objects to include in the conference. ``` -------------------------------- ### Handle Incoming INVITE with sip.js Source: https://context7.com/onsip/sip.js/llms.txt Handles incoming INVITE requests, tracks session state, rings the user, and accepts the call after a delay. Requires UserAgent setup. ```typescript import { Invitation, SessionState, UserAgent } from "sip.js"; const userAgent = new UserAgent({ uri: UserAgent.makeURI("sip:bob@example.com"), transportOptions: { server: "wss://sip.example.com" } }); userAgent.delegate = { onInvite(invitation: Invitation): void { console.log("Incoming call from:", invitation.remoteIdentity.displayName); // Track state invitation.stateChange.addListener((state: SessionState) => { if (state === SessionState.Established) console.log("Call established"); if (state === SessionState.Terminated) console.log("Call terminated"); }); // Ring: send 180 provisional response invitation.progress({ statusCode: 180, reasonPhrase: "Ringing" }); // Accept after 2 seconds setTimeout(async () => { try { await invitation.accept({ sessionDescriptionHandlerOptions: { constraints: { audio: true, video: false } } }); } catch (e) { console.error("Failed to accept:", e); } }, 2000); // Or reject the call (486 Busy Here) // await invitation.reject({ statusCode: 486 }); } }; await userAgent.start(); ``` -------------------------------- ### Start Local Conference with Sessions - TypeScript Source: https://github.com/onsip/sip.js/blob/main/docs/session-description-handler/sip.js.startlocalconference.md Use this function to start a conference by providing an array of sessions. This API is a preview and not recommended for production environments. ```typescript export declare function startLocalConference(conferenceSessions: Array): void; ``` -------------------------------- ### startLocalConference Source: https://github.com/onsip/sip.js/blob/main/docs/session-description-handler/sip.js.startlocalconference.md Starts a conference by taking an array of Session objects. This is a preview API and should not be used in production. ```APIDOC ## startLocalConference() ### Description Starts a conference by taking an array of Session objects. This is a preview API and should not be used in production. ### Signature ```typescript export declare function startLocalConference(conferenceSessions: Array): void; ``` ### Parameters #### Path Parameters - **conferenceSessions** (Array) - Required - The sessions to conference. ### Returns void ``` -------------------------------- ### UserAgent.userAgentCore Source: https://github.com/onsip/sip.js/blob/main/docs/api/sip.js.useragent.useragentcore.md Gets the user agent core instance. ```APIDOC ## UserAgent.userAgentCore property User agent core. ### Signature: ```typescript get userAgentCore(): UserAgentCore; ``` ### Description This property returns the UserAgentCore instance associated with the UserAgent. ### Returns - **UserAgentCore** - The UserAgentCore instance. ``` -------------------------------- ### Clone SIP.js Repository Source: https://github.com/onsip/sip.js/blob/main/docs/BUILDING.md Use this command to get a local copy of the SIP.js project from GitHub. ```bash $ git clone https://github.com/onsip/SIP.js.git ``` -------------------------------- ### Initialize and manage UserAgent Source: https://context7.com/onsip/sip.js/llms.txt Configure and start the UserAgent, which is the core SIP stack. It manages transport, authentication, and dispatches incoming requests. Handles connection events and graceful shutdown. ```typescript import { UserAgent, UserAgentOptions } from "sip.js"; const userAgentOptions: UserAgentOptions = { uri: UserAgent.makeURI("sip:alice@example.com"), transportOptions: { server: "wss://sip.example.com" }, displayName: "Alice", authorizationUsername: "alice", authorizationPassword: "s3cr3t", logLevel: "warn", // "debug" | "log" | "warn" | "error" // JWT auth alternative (takes precedence over digest): // authorizationJwt: () => myTokenStore.currentToken, sessionDescriptionHandlerFactoryOptions: { iceGatheringTimeout: 500 // ms to wait for ICE gathering } }; const userAgent = new UserAgent(userAgentOptions); // Delegate for incoming requests userAgent.delegate = { onInvite(invitation) { console.log("Incoming INVITE:", invitation.id); // Accept, reject, or defer invitation.accept({ sessionDescriptionHandlerOptions: { constraints: { audio: true, video: false } } }); }, onMessage(message) { message.accept(); console.log("Incoming MESSAGE:", message.request.body); }, onConnect() { console.log("Transport connected"); }, onDisconnect(error) { if (error) console.error("Disconnected with error:", error); } }; await userAgent.start(); // Reconnect after network loss await userAgent.reconnect(); // Graceful shutdown await userAgent.stop(); // Static helper – parse a SIP URI string const uri = UserAgent.makeURI("sip:bob@example.com"); if (!uri) throw new Error("Invalid URI"); ``` -------------------------------- ### Start Local Conference Source: https://github.com/onsip/sip.js/blob/main/etc/session-description-handler/sip.js.api.md Initiates a local conference with an array of provided sessions. This function is marked as beta, indicating potential changes. ```typescript startLocalConference(conferenceSessions: Array): void; ``` -------------------------------- ### HTML Audio Element Setup Source: https://github.com/onsip/sip.js/blob/main/docs/simple-user.md Defines an HTML audio element to play remote audio. Ensure this element exists in your HTML before initializing SimpleUser. ```html ``` -------------------------------- ### transportAccessor() Source: https://github.com/onsip/sip.js/blob/main/docs/core/sip.js.useragentcoreconfiguration.transportaccessor.md DEPRECATED: This is a hack to get around `Transport` requiring the `UA` to start for construction. Returns the transport accessor. ```APIDOC ## transportAccessor() ### Description DEPRECATED: This is a hack to get around `Transport` requiring the `UA` to start for construction. ### Method `transportAccessor(): Transport | undefined;` ### Returns [Transport](./sip.js.transport.md) | undefined ``` -------------------------------- ### Accessing SIP Message Header Attributes with IncomingMessage.s() Source: https://github.com/onsip/sip.js/blob/main/docs/core/sip.js.incomingmessage.s.md Use the `s()` method to retrieve a specific header attribute from a SIP message. Provide the header name and an optional index to get the desired value. This example shows how to access the port from the third 'Via' header. ```typescript message.s('via',3).port ``` -------------------------------- ### Create Simple Instance Source: https://github.com/onsip/sip.js/blob/main/docs/migration-simple.md Instantiate the Simple API with media and user agent options. ```javascript var options = { media: { local: { video: document.getElementById('localVideo') }, remote: { video: document.getElementById('remoteVideo'), // This is necessary to do an audio/video call as opposed to just a video call audio: document.getElementById('remoteVideo') } }, ua: { wsServers: "wss://sip.example.com" } }; var simple = new Simple(options); ``` -------------------------------- ### Create and Manage a Subscription Source: https://github.com/onsip/sip.js/blob/main/docs/api/sip.js.subscriber.md Demonstrates how to create a Subscriber instance, set up a delegate for handling notifications, monitor state changes, and initiate/terminate the subscription. ```typescript const targetURI = new URI("sip", "alice", "example.com"); const eventType = "example-name"; // https://www.iana.org/assignments/sip-events/sip-events.xhtml const subscriber = new Subscriber(userAgent, targetURI, eventType); // Add delegate to handle event notifications. subscriber.delegate = { onNotify: (notification: Notification) => { // send a response notification.accept(); // handle notification here } }; // Monitor subscription state changes. subscriber.stateChange.addListener((newState: SubscriptionState) => { if (newState === SubscriptionState.Terminated) { // handle state change here } }); // Attempt to establish the subscription subscriber.subscribe(); // Sometime later when done with subscription subscriber.unsubscribe(); ``` -------------------------------- ### Build and Test SIP.js Source: https://github.com/onsip/sip.js/blob/main/docs/BUILDING.md Execute this command to compile the library and run all associated tests. ```bash $ npm run build-and-test ``` -------------------------------- ### Override Local Media Acquisition with MediaStreamFactory Source: https://github.com/onsip/sip.js/blob/main/docs/session-description-handler.md This example demonstrates how to create a custom MediaStreamFactory to control how local media is obtained. The custom factory is then used to create a session description handler factory, which is finally passed to the UserAgent constructor. ```typescript import { UserAgent, UserAgentOptions, Web } from "sip.js"; // Create media stream factory const myMediaStreamFactory: Web.MediaStreamFactory = ( constraints: MediaStreamConstraints, sessionDescriptionHandler: Web.SessionDescriptionHandler ): Promise => { const mediaStream = new MediaStream(); // my custom media stream acquisition return Promise.resolve(mediaStream); }; // Create session description handler factory const mySessionDescriptionHandlerFactory: Web.SessionDescriptionHandlerFactory = Web.defaultSessionDescriptionHandlerFactory( myMediaStreamFactory ); // Create user agent const myUserAgent = new UserAgent({ sessionDescriptionHandlerFactory: mySessionDescriptionHandlerFactory }); ``` -------------------------------- ### Start UserAgent and handle connection status Source: https://github.com/onsip/sip.js/blob/main/docs/api/sip.js.useragent.start.md Initiates the UserAgent and checks its connection status upon resolution or rejection of the promise. This is useful for managing the UserAgent's lifecycle and reacting to connection events. ```typescript userAgent.start() .then(() => { // userAgent.isConnected() === true }) .catch((error: Error) => { // userAgent.isConnected() === false }); ``` -------------------------------- ### Navigate to Project Directory Source: https://github.com/onsip/sip.js/blob/main/docs/BUILDING.md Change your current directory to the root of the cloned SIP.js project. ```bash $ cd SIP.js ``` -------------------------------- ### SessionManager.connect() Source: https://github.com/onsip/sip.js/blob/main/docs/session-manager/sip.js.sessionmanager.connect.md Connects the UserAgent. If the UserAgent is not started, it starts it by connecting the WebSocket Transport. Otherwise, it reconnects the WebSocket Transport. Reconnection attempts will be made as needed. ```APIDOC ## connect() ### Description Connects the UserAgent. If the UserAgent is not started, it starts it by connecting the WebSocket Transport. Otherwise, it reconnects the WebSocket Transport. Reconnection attempts will be made as needed. ### Method connect ### Returns Promise ``` -------------------------------- ### Build Documentation Source: https://github.com/onsip/sip.js/blob/main/RELEASE.md Generate the project's documentation. Any changes to documentation should be committed, and may necessitate a return to the build and test step. ```bash npm run build-docs ``` -------------------------------- ### SessionManager.getRemoteAudioTrack() Source: https://github.com/onsip/sip.js/blob/main/docs/session-manager/sip.js.sessionmanager.getremoteaudiotrack.md This method is used to get the remote audio track from a session. It is marked as obsolete and users should prefer using `remoteMediaStream` and getting the track from the stream. ```APIDOC ## SessionManager.getRemoteAudioTrack() ### Description The remote audio track, if available. > Warning: This API is now obsolete. > > Use remoteMediaStream and get track from the stream. > ### Method Signature ```typescript getRemoteAudioTrack(session: Session): MediaStreamTrack | undefined; ``` ### Parameters #### Path Parameters - **session** (Session) - Required - Session to get track from. ### Returns - **MediaStreamTrack | undefined** - The remote audio track, if available. ``` -------------------------------- ### Get Session Description Handler on Creation Source: https://github.com/onsip/sip.js/blob/main/docs/session-description-handler.md Use the session delegate's `onSessionDescriptionHandler` callback to get a handle on the `SessionDescriptionHandler` as soon as it is created, even before it is utilized. This callback is invoked for both provisional and final handlers. ```typescript import { SessionDescriptionHandler } from "sip.js"; function handleSessionDescriptionHandlerCreated(session: Session): void { session.delegate = { onSessionDescriptionHandler: (sessionDescriptionHandler: SessionDescriptionHandler, provisional: boolean) => { console.log("A session description handler was created"); } }; } ``` -------------------------------- ### startLocalConference(conferenceSessions) Function Source: https://github.com/onsip/sip.js/blob/main/docs/session-description-handler/sip.js.md Start a conference. ```APIDOC ## Function: startLocalConference(conferenceSessions) ### Description Start a conference. ### Parameters #### conferenceSessions - **conferenceSessions** (Array) - ### See Also [sip.js](./sip.js.md) ``` -------------------------------- ### Dialog.remoteURI Source: https://github.com/onsip/sip.js/blob/main/docs/core/sip.js.dialog.remoteuri.md Gets the remote URI of the dialog. ```APIDOC ## Dialog.remoteURI ### Description Gets the remote URI of the dialog. ### Signature ```typescript get remoteURI(): URI; ``` ``` -------------------------------- ### connect() Source: https://github.com/onsip/sip.js/blob/main/docs/api/sip.js.transport.md Connect to the network. This method initiates the connection process and is expected to transition the transport to the 'Connecting' state, eventually leading to the 'Connected' state. ```APIDOC ## Method: connect() ### Description Connect to network. ### Endpoint N/A (Method call) ### Method N/A (Method call) ### Parameters None ``` -------------------------------- ### UserAgent.state Source: https://github.com/onsip/sip.js/blob/main/docs/api/sip.js.useragent.state.md Gets the current state of the User Agent. ```APIDOC ## UserAgent.state ### Description Gets the current state of the User Agent. ### Signature ```typescript get state(): UserAgentState; ``` ``` -------------------------------- ### Clean, Build, and Test Source: https://github.com/onsip/sip.js/blob/main/RELEASE.md Ensure a clean build environment and that all tests pass before proceeding with the release. This includes building the main project and the demo applications. ```bash git clean -xdf . npm i npm run build-and-test npm run build-demo ``` -------------------------------- ### Create SimpleUser Instance Source: https://github.com/onsip/sip.js/blob/main/docs/migration-simple.md Instantiate SimpleUser with server, media constraints, and user agent options. Note the use of HTMLVideoElement type assertion. ```typescript const server = "wss://sip.example.com"; const options: SimpleUserOptions = { media: { constraints: { audio: true, video: true }, local: { video: document.getElementById("localVideo") as HTMLVideoElement }, remote: { video: document.getElementById("remoteVideo") as HTMLVideoElement, } }, userAgentOptions: {} }; const simpleUser = new SimpleUser(server, options); ``` -------------------------------- ### getLocalSessionDescription() Source: https://github.com/onsip/sip.js/blob/main/docs/session-description-handler/sip.js.sessiondescriptionhandler.getlocalsessiondescription.md Gets the peer connection's local session description. ```APIDOC ## getLocalSessionDescription() ### Description Gets the peer connection's local session description. ### Method protected ### Returns Promise ``` -------------------------------- ### getDescription(options, modifiers) Source: https://github.com/onsip/sip.js/blob/main/docs/api/sip.js.sessiondescriptionhandler.md Gets the local description from the underlying media implementation. ```APIDOC ## getDescription(options, modifiers) ### Description Gets the local description from the underlying media implementation. ### Method getDescription ### Parameters #### Path Parameters - **options** (any) - Optional - - **modifiers** (any) - Optional - ### Response #### Success Response (200) - **description** (RTCSessionDescriptionInit) - The local description. ``` -------------------------------- ### Constructor Source: https://github.com/onsip/sip.js/blob/main/docs/api/sip.js.subscriber.md Initializes a new instance of the Subscriber class. ```APIDOC ## Constructors | Constructor | Modifiers | Description | | --- | --- | --- | | [(constructor)(userAgent, targetURI, eventType, options)](./sip.js.subscriber._constructor_.md) | | Constructor. | ``` -------------------------------- ### UserAgentState Enum Source: https://github.com/onsip/sip.js/blob/main/etc/api/sip.js.api.md Defines the possible states for a UserAgent, indicating whether it is started or stopped. ```typescript export enum UserAgentState { // (undocumented) Started = "Started", // (undocumented) Stopped = "Stopped" } ``` -------------------------------- ### Dialog.remoteSequenceNumber Source: https://github.com/onsip/sip.js/blob/main/docs/core/sip.js.dialog.remotesequencenumber.md Gets the remote sequence number, which is used to order requests from its peer to the UA. ```APIDOC ## Dialog.remoteSequenceNumber ### Description Gets the remote sequence number. This number is used to order requests originating from the peer User Agent (UA). ### Signature ```typescript get remoteSequenceNumber(): number | undefined; ``` ### Returns A number representing the remote sequence number, or undefined if it has not been set. ``` -------------------------------- ### Build Bundles for Release Notes Source: https://github.com/onsip/sip.js/blob/main/RELEASE.md Build the necessary bundle files that will be uploaded as part of the GitHub release notes. ```bash npm run build-bundles ``` -------------------------------- ### InviterOptions.earlyMedia Source: https://github.com/onsip/sip.js/blob/main/docs/api/sip.js.inviteroptions.earlymedia.md If true, the first answer to the local offer is immediately utilized for media. Requires that the INVITE request MUST NOT fork. Has no effect if `inviteWithoutSdp` is true. Default is false. ```APIDOC ## InviterOptions.earlyMedia property ### Description If true, the first answer to the local offer is immediately utilized for media. Requires that the INVITE request MUST NOT fork. Has no effect if `inviteWithoutSdp` is true. Default is false. ### Signature ```typescript earlyMedia?: boolean; ``` ``` -------------------------------- ### TransportOptions.server Source: https://github.com/onsip/sip.js/blob/main/docs/transport/sip.js.transportoptions.server.md The URL of the WebSocket server to connect with. For example, "wss://localhost:8080". ```APIDOC ## TransportOptions.server ### Description The URL of the WebSocket server to connect with. For example, "wss://localhost:8080". ### Signature ```typescript server: string; ``` ``` -------------------------------- ### invite Source: https://github.com/onsip/sip.js/blob/main/etc/api/sip.js.api.md Initiates an INVITE request to establish a new session. This is the primary method for starting a call. ```APIDOC ## invite ### Description Initiates an INVITE request to establish a new session. ### Method `invite(options?: SessionInviteOptions): Promise` ### Parameters #### Query Parameters - **options** (SessionInviteOptions) - Optional - Options for the INVITE request. ### Returns - `Promise`: A promise that resolves with the outgoing INVITE request. ``` -------------------------------- ### SimpleUserMedia Interface Source: https://github.com/onsip/sip.js/blob/main/etc/simple-user/sip.js.api.md The SimpleUserMedia interface defines media configuration options. ```APIDOC ## SimpleUserMedia ### Description Media configuration options. ### Properties #### `constraints?: SimpleUserMediaConstraints` Media constraints for audio and video. #### `local?: SimpleUserMediaLocal` Local media configuration. #### `remote?: SimpleUserMediaRemote` Remote media configuration. ``` -------------------------------- ### Tag, Push, and Publish Source: https://github.com/onsip/sip.js/blob/main/RELEASE.md Tag the release, push the tags to the remote repository, and publish the package to the npm registry. ```bash git tag git push git push --tags npm publish ``` -------------------------------- ### addListener Source: https://github.com/onsip/sip.js/blob/main/docs/api/sip.js.emitter.md Sets up a function that will be called whenever the target changes. ```APIDOC ## addListener(listener, options) ### Description Sets up a function that will be called whenever the target changes. ### Method (Not specified, likely a method of the Emitter interface) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ``` // Example usage (assuming Emitter instance is available) const emitter = new Emitter(); emitter.addListener(myListener, { once: false }); ``` ### Response #### Success Response (200) (Not specified) #### Response Example (Not specified) ``` -------------------------------- ### WebAudioSessionDescriptionHandler.initLocalMediaStream() Source: https://github.com/onsip/sip.js/blob/main/docs/session-description-handler/sip.js.webaudiosessiondescriptionhandler.initlocalmediastream.md Returns a WebRTC MediaStream proxying the provided audio media stream. This allows additional Web Audio media stream source nodes to be connected to the destination node associated with the returned stream so we can mix additional audio sources into the local media stream (e.g., for 3-way conferencing). **Note:** This API is provided as a preview and may change based on feedback. Do not use in a production environment. ```APIDOC ## WebAudioSessionDescriptionHandler.initLocalMediaStream() ### Description Returns a WebRTC MediaStream proxying the provided audio media stream. This allows additional Web Audio media stream source nodes to be connected to the destination node associated with the returned stream so we can mix aditional audio sorces into the local media stream (ie for 3-way conferencing). **Note:** This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. ### Method ```typescript initLocalMediaStream(stream: MediaStream): MediaStream; ``` ### Parameters #### Path Parameters - **stream** (MediaStream) - Required - The MediaStream to proxy. ### Returns - **MediaStream** - The proxied MediaStream. ``` -------------------------------- ### getLocalMediaStream Source: https://github.com/onsip/sip.js/blob/main/docs/session-manager/sip.js.sessionmanager.getlocalmediastream.md Gets the local media stream for a specific session. Returns `undefined` if the session has not been answered. ```APIDOC ## getLocalMediaStream(session: Session): MediaStream | undefined ### Description The local media stream. Undefined if call not answered. ### Parameters #### Path Parameters * **session** (Session) - Required - Session to get the media stream from. ### Returns MediaStream | undefined ``` -------------------------------- ### ReferUserAgentServer Constructor Source: https://github.com/onsip/sip.js/blob/main/docs/core/sip.js.referuseragentserver._constructor_.md Initializes a new instance of the ReferUserAgentServer class. This constructor is used to handle incoming REFER requests, either within an existing dialog or as a new UserAgentCore initiated request. ```APIDOC ## ReferUserAgentServer.(constructor) ### Description REFER UAS constructor. ### Signature ```typescript constructor(dialogOrCore: SessionDialog | UserAgentCore, message: IncomingRequestMessage, delegate?: IncomingRequestDelegate); ``` ### Parameters #### Path Parameters - **dialogOrCore** (SessionDialog | UserAgentCore) - Required - Dialog for in dialog REFER, UserAgentCore for out of dialog REFER. - **message** (IncomingRequestMessage) - Required - Incoming REFER request message. - **delegate** (IncomingRequestDelegate) - Optional - ``` -------------------------------- ### SubscriptionDialog.subscriptionRefresh Source: https://github.com/onsip/sip.js/blob/main/docs/core/sip.js.subscriptiondialog.subscriptionrefresh.md Gets the number of seconds until the subscription will be automatically refreshed. Returns undefined if auto-refresh is not configured. ```APIDOC ## SubscriptionDialog.subscriptionRefresh ### Description Number of seconds until subscription auto refresh. ### Signature ```typescript get subscriptionRefresh(): number | undefined; ``` ``` -------------------------------- ### SessionDescriptionHandlerOptions.dataChannel Source: https://github.com/onsip/sip.js/blob/main/docs/session-description-handler/sip.js.sessiondescriptionhandleroptions.datachannel.md If true, create a data channel when making initial offer. ```APIDOC ## SessionDescriptionHandlerOptions.dataChannel ### Description If true, create a data channel when making initial offer. ### Signature ```typescript dataChannel?: boolean; ``` ``` -------------------------------- ### Subscriber Class Overview Source: https://github.com/onsip/sip.js/blob/main/docs/api/sip.js.subscriber.md This snippet provides an overview of the Subscriber class, its inheritance, and a usage example. ```APIDOC ## Subscriber Class A subscriber establishes a [Subscription](./sip.js.subscription.md) (outgoing SUBSCRIBE). Signature: ```typescript export declare class Subscriber extends Subscription ``` ## Remarks This is (more or less) an implementation of a "subscriber" as defined in RFC 6665 "SIP-Specific Event Notifications". https://tools.ietf.org/html/rfc6665 ## Example ```ts // Create a new subscriber. const targetURI = new URI("sip", "alice", "example.com"); const eventType = "example-name"; // https://www.iana.org/assignments/sip-events/sip-events.xhtml const subscriber = new Subscriber(userAgent, targetURI, eventType); // Add delegate to handle event notifications. subscriber.delegate = { onNotify: (notification: Notification) => { // send a response notification.accept(); // handle notification here } }; // Monitor subscription state changes. subscriber.stateChange.addListener((newState: SubscriptionState) => { if (newState === SubscriptionState.Terminated) { // handle state change here } }); // Attempt to establish the subscription subscriber.subscribe(); // Sometime later when done with subscription subscriber.unsubscribe(); ``` ``` -------------------------------- ### getLocalMediaStream(options) Source: https://github.com/onsip/sip.js/blob/main/docs/session-description-handler/sip.js.sessiondescriptionhandler.md Get a media stream from the media stream factory and set the local media stream. ```APIDOC ## getLocalMediaStream(options) ### Description Retrieves a local media stream using the media stream factory and sets it as the local media stream for the session. ### Parameters #### Path Parameters - **options** (object) - Optional - Configuration options for obtaining the media stream. ### Method Not applicable (this is a method call within the SDK). ``` -------------------------------- ### InviteUserAgentServer Constructor Source: https://github.com/onsip/sip.js/blob/main/docs/core/sip.js.inviteuseragentserver._constructor_.md Constructs a new instance of the InviteUserAgentServer class. ```APIDOC ## InviteUserAgentServer.(constructor) ### Description Constructs a new instance of the `InviteUserAgentServer` class. ### Signature ```typescript constructor(core: UserAgentCore, message: IncomingRequestMessage, delegate?: IncomingRequestDelegate); ``` ### Parameters #### Path Parameters - **core** (UserAgentCore) - - **message** (IncomingRequestMessage) - - **delegate** (IncomingRequestDelegate) - Optional ``` -------------------------------- ### on Source: https://github.com/onsip/sip.js/blob/main/docs/api/sip.js.emitter.md Registers a listener. ```APIDOC ## on(listener) ### Description Registers a listener. ### Method (Not specified, likely a method of the Emitter interface) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ``` // Example usage (assuming Emitter instance) const emitter = new Emitter(); const myListener = () => { console.log('Event received!'); }; emitter.on(myListener); ``` ### Response #### Success Response (200) (Not specified) #### Response Example (Not specified) ``` -------------------------------- ### URI.host Source: https://github.com/onsip/sip.js/blob/main/docs/core/sip.js.uri.host.md The host property of a URI instance allows you to get or set the host component of the URI. It is represented as a string. ```APIDOC ## URI.host property ### Description Allows getting and setting the host part of a SIP URI. ### Signature ```typescript get host(): string; set host(value: string); ``` ### Usage **Getting the host:** ```javascript const uri = new SIP.URI('sip', 'example.com', 5060); const host = uri.host; console.log(host); // Output: "example.com" ``` **Setting the host:** ```javascript const uri = new SIP.URI('sip', 'old.com', 5060); uri.host = 'new.com'; console.log(uri.toString()); // Output: "sip:new.com:5060" ``` ``` -------------------------------- ### UserAgentCore Constructor Source: https://github.com/onsip/sip.js/blob/main/docs/core/sip.js.useragentcore._constructor_.md Initializes a new instance of the UserAgentCore class. ```APIDOC ## UserAgentCore.(constructor) ### Description Constructor. ### Signature ```typescript constructor(configuration: UserAgentCoreConfiguration, delegate?: UserAgentCoreDelegate); ``` ### Parameters #### Parameters - **configuration** (UserAgentCoreConfiguration) - Required - Configuration. - **delegate** (UserAgentCoreDelegate) - Optional - Delegate. ``` -------------------------------- ### Start and End Call with SimpleUser Source: https://github.com/onsip/sip.js/blob/main/docs/migration-simple.md Initiate a call and set up an async event listener to hang up the call using SimpleUser. ```typescript const endButton = document.getElementById("endCall"); endButton.addEventListener("click", async () => { await simpleUser.hangup(); alert("Call Ended"); }, false); simpleUser.call("welcome@onsip.com"); ``` -------------------------------- ### Registering a User Agent (Old API) Source: https://github.com/onsip/sip.js/blob/main/docs/migration-0.15-0.16.md Demonstrates the previous method of registering a User Agent using UA.register() and handling registration events. ```typescript const uri = "sip:alice@example.com"; const options = { authenticationUsername: "username", password: "password", uri: uri }; const ua = new UA(options); ua.on("registered", (response: any) => { console.log("Registered"); }); ua.on("registrationFailed", () => { console.log("Failed to register"); }); ua.on("unregistered", (response, cause) => { console.log("Unregistered"); }); ua.register(); if (ua.isRegistered()) { // Currently registered } ua.unregister(); ``` -------------------------------- ### Logger Class Source: https://github.com/onsip/sip.js/blob/main/etc/core/sip.js.api.md Provides logging capabilities with different levels. Users can set and get the logging level and log messages. ```APIDOC ## Logger ### Description Provides logging capabilities with different levels. Users can set and get the logging level and log messages. ### Properties - `level` (Levels): Gets or sets the current logging level. ### Methods - `log(content: string): void` - `warn(content: string): void` ``` -------------------------------- ### SubscribeUserAgentClient.waitNotifyStart() Source: https://github.com/onsip/sip.js/blob/main/docs/core/sip.js.subscribeuseragentclient.waitnotifystart.md The waitNotifyStart() method is used to initiate waiting for a NOTIFY request. It does not accept any parameters and returns void. ```APIDOC ## SubscribeUserAgentClient.waitNotifyStart() ### Description Initiates waiting for a NOTIFY request. ### Method `waitNotifyStart(): void;` ### Returns void ``` -------------------------------- ### SimpleUser.remoteVideoTrack Source: https://github.com/onsip/sip.js/blob/main/docs/simple-user/sip.js.simpleuser.remotevideotrack.md This property returns the remote video track if available. It is now obsolete and users should utilize remoteMediaStream to get tracks from the stream. ```APIDOC ## SimpleUser.remoteVideoTrack property > Warning: This API is now obsolete. > > Use remoteMediaStream and get track from the stream. > The remote video track, if available. Signature: ```typescript get remoteVideoTrack(): MediaStreamTrack | undefined; ``` ``` -------------------------------- ### SimpleUser.localAudioTrack Source: https://github.com/onsip/sip.js/blob/main/docs/simple-user/sip.js.simpleuser.localaudiotrack.md The local audio track, if available. This API is now obsolete and users should use localMediaStream and get the track from the stream instead. ```APIDOC ## SimpleUser.localAudioTrack property > Warning: This API is now obsolete. > > Use localMediaStream and get track from the stream. > The local audio track, if available. Signature: ```typescript get localAudioTrack(): MediaStreamTrack | undefined; ``` ``` -------------------------------- ### ReferUserAgentServer Constructor Source: https://github.com/onsip/sip.js/blob/main/docs/core/sip.js.referuseragentserver.md Initializes a new instance of the ReferUserAgentServer class. This constructor is used to create a server-side handler for incoming REFER requests. ```APIDOC ## ReferUserAgentServer Constructor ### Description REFER UAS constructor. ### Signature constructor(dialogOrCore: Core | Dialog, message: IncomingMessage, delegate?: ReferUserAgentServerDelegate) ### Parameters * **dialogOrCore** (Core | Dialog) - The core or dialog associated with the request. * **message** (IncomingMessage) - The incoming REFER message. * **delegate** (ReferUserAgentServerDelegate, optional) - The delegate for handling REFER events. ``` -------------------------------- ### SimpleUserOptions.delegate Source: https://github.com/onsip/sip.js/blob/main/docs/simple-user/sip.js.simpleuseroptions.delegate.md Delegate for SimpleUser. ```APIDOC ## SimpleUserOptions.delegate property Delegate for SimpleUser. ### Signature ```typescript delegate?: SimpleUserDelegate; ``` ``` -------------------------------- ### Run SIP.js Tests Source: https://github.com/onsip/sip.js/blob/main/docs/BUILDING.md Execute this command to run the unit and integration tests for SIP.js. ```bash $ npm run test ``` -------------------------------- ### LoggerFactory Class Source: https://github.com/onsip/sip.js/blob/main/etc/core/sip.js.api.md Factory for creating Logger instances. It manages the logging connector and provides a way to get loggers for specific categories. ```APIDOC ## LoggerFactory ### Description Factory for creating Logger instances. It manages the logging connector and provides a way to get loggers for specific categories. ### Properties - `builtinEnabled` (boolean): Indicates if built-in logging is enabled. - `connector` ((level: string, category: string, label: string | undefined, content: any) => void | undefined): Gets or sets the logging connector function. - `level` (Levels): Gets or sets the current logging level. ### Methods - `constructor()` - `genericLog(levelToLog: Levels, category: string, label: string | undefined, content: any): void`: Logs a message with a specific level, category, and label. - `getLogger(category: string, label?: string): Logger`: Retrieves a Logger instance for a given category and optional label. ``` -------------------------------- ### Get Local Audio Track Signature Source: https://github.com/onsip/sip.js/blob/main/docs/session-manager/sip.js.sessionmanager.getlocalaudiotrack.md This is the TypeScript signature for the getLocalAudioTrack method. It takes a Session object and returns a MediaStreamTrack or undefined. ```typescript getLocalAudioTrack(session: Session): MediaStreamTrack | undefined; ``` -------------------------------- ### Constructor Source: https://github.com/onsip/sip.js/blob/main/docs/api/sip.js.publisher.md Constructs a new instance of the Publisher class. ```APIDOC ## Constructors | Constructor | Modifiers | Description | | --- | --- | --- | | [(constructor)(userAgent, targetURI, eventType, options)](./sip.js.publisher._constructor_.md) | | Constructs a new instance of the Publisher class. | ``` -------------------------------- ### InfoUserAgentServer Constructor Source: https://github.com/onsip/sip.js/blob/main/docs/core/sip.js.infouseragentserver.md Constructs a new instance of the InfoUserAgentServer class. ```APIDOC ## InfoUserAgentServer Constructor ### Description Constructs a new instance of the `InfoUserAgentServer` class. ### Signature ```typescript constructor(dialog: Dialog, message: IncomingMessage, delegate?: InfoUserAgentServerDelegate) ``` ### Parameters * **dialog** (Dialog) - The dialog associated with the INFO request. * **message** (IncomingMessage) - The incoming INFO request message. * **delegate** (InfoUserAgentServerDelegate, optional) - The delegate for handling INFO request events. ``` -------------------------------- ### Accessing the Server Transaction Source: https://github.com/onsip/sip.js/blob/main/docs/core/sip.js.useragentserver.transaction.md Provides information on how to get the ServerTransaction associated with a UserAgentServer. This is useful for inspecting or interacting with the ongoing SIP transaction. ```APIDOC ## UserAgentServer.transaction property ### Description The transaction associated with this request. ### Signature ```typescript get transaction(): ServerTransaction; ``` ``` -------------------------------- ### SessionDescriptionHandler.getDescription() Source: https://github.com/onsip/sip.js/blob/main/docs/session-description-handler/sip.js.sessiondescriptionhandler.getdescription.md Creates an offer or answer. This method can be used to generate an SDP offer or answer, with optional configuration and modification. ```APIDOC ## SessionDescriptionHandler.getDescription() ### Description Creates an offer or answer. ### Method ```typescript getDescription(options?: SessionDescriptionHandlerOptions, modifiers?: Array): Promise; ``` ### Parameters #### Path Parameters - **options** (SessionDescriptionHandlerOptions) - Options bucket. - **modifiers** (Array) - Modifiers. ### Returns Promise<BodyAndContentType> ``` -------------------------------- ### UserAgentState Enum Source: https://github.com/onsip/sip.js/blob/main/docs/api/sip.js.useragentstate.md The UserAgentState enum defines the possible states for a UserAgent. It includes 'Started' and 'Stopped' states, with specific rules for state transitions. ```APIDOC ## UserAgentState Enum [UserAgent](./sip.js.useragent.md) state. Signature: ```typescript export declare enum UserAgentState ``` ## Enumeration Members | Member | Value | Description | | --- | --- | --- | | Started | "Started" | | | Stopped | "Stopped" | | ## Remarks Valid state transitions: ``` 1. "Started" --> "Stopped" 2. "Stopped" --> "Started" ``` ``` -------------------------------- ### InfoUserAgentServer Constructor Source: https://github.com/onsip/sip.js/blob/main/docs/core/sip.js.infouseragentserver._constructor_.md Constructs a new instance of the InfoUserAgentServer class. This is used to handle incoming INFO requests. ```APIDOC ## InfoUserAgentServer.(constructor) ### Description Constructs a new instance of the `InfoUserAgentServer` class. ### Signature ```typescript constructor(dialog: SessionDialog, message: IncomingRequestMessage, delegate?: IncomingRequestDelegate); ``` ### Parameters #### Path Parameters * **dialog** (`SessionDialog`) - Description not available. * **message** (`IncomingRequestMessage`) - Description not available. * **delegate** (`IncomingRequestDelegate`) - Optional. Description not available. ``` -------------------------------- ### SessionManager.getLocalAudioTrack() Source: https://github.com/onsip/sip.js/blob/main/docs/session-manager/sip.js.sessionmanager.getlocalaudiotrack.md Retrieves the local audio track for a given session. This method is obsolete and should not be used. Instead, use localMediaStream and get the track from the stream. ```APIDOC ## SessionManager.getLocalAudioTrack() ### Description The local audio track, if available. > Warning: This API is now obsolete. > > Use localMediaStream and get track from the stream. > ### Method Signature ```typescript getLocalAudioTrack(session: Session): MediaStreamTrack | undefined; ``` ### Parameters #### Path Parameters - **session** (Session) - Required - Session to get track from. ### Returns - **MediaStreamTrack | undefined** - The local audio track, or undefined if not available. ``` -------------------------------- ### Place SIP Call with SimpleUser Source: https://github.com/onsip/sip.js/blob/main/README.md Use the SimpleUser class for straightforward SIP call functionality. Configure audio constraints and remote audio playback. Requires an HTML audio element with a specific ID. ```typescript import { Web } from "sip.js"; // Helper function to get an HTML audio element function getAudioElement(id: string): HTMLAudioElement { const el = document.getElementById(id); if (!(el instanceof HTMLAudioElement)) { throw new Error(`Element "${id}" not found or not an audio element.`); } return el; } // Options for SimpleUser const options: Web.SimpleUserOptions = { aor: "sip:alice@example.com", // caller media: { constraints: { audio: true, video: false }, // audio only call remote: { audio: getAudioElement("remoteAudio") } // play remote audio } }; // WebSocket server to connect with const server = "wss://sip.example.com"; // Construct a SimpleUser instance const simpleUser = new Web.SimpleUser(server, options); // Connect to server and place call simpleUser.connect() .then(() => simpleUser.call("sip:bob@example.com")) .catch((error: Error) => { // Call failed }); ``` -------------------------------- ### Get Default Peer Connection Configuration Source: https://github.com/onsip/sip.js/blob/main/docs/session-description-handler/sip.js.defaultpeerconnectionconfiguration.md Call this function to obtain the default RTCConfiguration object. This configuration is used when initializing a new PeerConnection. ```typescript export declare function defaultPeerConnectionConfiguration(): RTCConfiguration; ``` -------------------------------- ### NameAddrHeader.displayName Source: https://github.com/onsip/sip.js/blob/main/docs/core/sip.js.nameaddrheader.displayname.md The displayName property of a NameAddrHeader instance is used to get or set the display name. The display name is a string that can be optionally included in a SIP address. ```APIDOC ## NameAddrHeader.displayName property ### Description Gets or sets the display name of the NameAddrHeader. ### Method ```typescript get displayName(): string; set displayName(value: string); ``` ### Parameters #### Setter Parameter - **value** (string) - The display name to set. ```