Beyond Click-to-Call: How Developers Integrate Real-Time Voice via OnSIP APIs

Traditional PSTN setups and standalone softphones often force users out of your application into external tools. By leveraging OnSIP's developer ecosystem—including SIP.js for WebSocket signaling, direct WebRTC media streaming, and REST APIs for call control—developers can build native, context-aware voice and video calling directly into web and mobile interfaces. Discover how to set up browser-to-browser audio, handle SIP sessions in JavaScript, and sync call events with your application backend seamlessly.

person holding black android smartphone

Basic click-to-call buttons served their purpose in the early days of web telephony, but today’s web applications demand deeply embedded, context-aware real-time communication. By tapping into OnSIP’s developer ecosystem—combining SIP.js over WebSockets with powerful REST APIs—developers can transform standard browser windows into fully functioning softphones and custom telephony channels.


1. The Paradigm Shift: From Call Buttons to In-App Telephony

Traditional click-to-call solutions operate on a simple premise: a user clicks a link, and the backend triggers a PSTN (Public Switched Telephone Network) dial-out to the user’s mobile or landline phone. While simple, this approach context-switches the user away from your web app, increases latency, and incurs legacy telephony routing costs.

Modern developer workflows leverage SIP over WebSockets alongside WebRTC. By using OnSIP as the signaling and routing engine, your frontend application maintains direct control over session initiation, media streams, and real-time state management—keeping users engaged entirely within your digital product.

Core Architecture Components

  • SIP.js Engine: Handles SIP signaling (INVITE, BYE, REGISTER) directly in JavaScript via secure WebSockets (`wss://`).
  • WebRTC Media Pipeline: Establishes peer-to-peer audio and video encrypted streams (`SRTP`) between the browser and OnSIP media servers.
  • OnSIP REST API & Webhooks: Manages account provisioning, agent routing rules, call logging, and real-time event webhooks for your backend server.

2. Getting Started with SIP.js & WebRTC

To establish a session, the browser connects to OnSIP’s WebSocket edge via SIP.js. Below is a foundational implementation pattern showing how to instantiate a User Agent and initiate an outbound browser call:

JavaScript — SIP.js UserAgent Setup
import { UserAgent, Registerer, UserAgentOptions } from 'sip.js';

const targetDomain = "yourdomain.onsip.com";
const uri = UserAgent.makeURI(`sip:user@${targetDomain}`);

const options: UserAgentOptions = {
  uri,
  transportOptions: {
    server: "wss://edge.onsip.com"
  },
  authorizationUsername: "user_auth_id",
  authorizationPassword: "secure_password",
};

const userAgent = new UserAgent(options);

// Start the user agent and register with OnSIP SIP Proxy
await userAgent.start();
const registerer = new Registerer(userAgent);
await registerer.register();

// Triggering an In-App Call
function makeCall(destinationSipUri) {
  const target = UserAgent.makeURI(destinationSipUri);
  const inviter = new UserAgent.Inviter(userAgent, target, {
    inviterOptions: {
      sessionDescriptionHandlerOptions: {
        constraints: { audio: true, video: false }
      }
    }
  });

  inviter.invite();
}

3. Synchronizing Call Events with CRM & App State

Voice integration reaches its full potential when call events trigger real-time updates inside your web application—such as popping up a customer profile when an incoming call rings or logging call duration automatically.

Inbound Call Pops

Catch the incoming INVITE event in SIP.js, parse the caller’s SIP ID or PSTN phone number, and query your REST API to immediately open relevant client records before answering.

Automated Call Logging

Use OnSIP backend Webhooks to stream Call Detail Records (CDRs) directly to your database, capturing duration, recording links, and agent routing metrics without manual entry.

4. Best Practices for Enterprise Deployment

  1. Configure Fallback TURN Servers: WebRTC requires STUN/TURN servers to traverse strict enterprise firewalls and symmetric NATs. Always ensure TURN relay infrastructure is enabled in your media configuration.
  2. Handle Microphone Permissions Gracefully: Prompt users for media device access before initiating or accepting a call session to avoid dropped INVITE requests.
  3. Secure SIP Credentials: Never expose primary admin credentials in client-side code. Generate temporary session tokens or user-specific SIP credentials on your backend server.

Ready to Embed Voice in Your Web Application?

Explore our specialized network and VoIP integration services to ensure optimal latency, security, and WebRTC throughput for your developer builds.

Contact Our Integration Engineering Team

// Our consultation can be done via phone or email

Book A FREE Consultation

Talk to our team