@frejun/softphone-web-sdk

中文文档
2.0.1发布于 2026/11/07ISCES Module近 30 天下载 3193

This SDK provides a SIP based Softphone to make/receive calls on the browser using FreJun

原始使用文档
文档目录5 节
  1. Usage
  2. Softphone
  3. Session
  4. Event Listeners
  5. Logging & Error Handling

Table of contents


Overview

This SDK provides a SIP based Softphone to make/receive calls on the browser using FreJun.

Requirements

  1. FreJun Account
  2. OAuth 2.0 Access Token

Usage

import {Softphone} from "@frejun/softphone-web-sdk";

const softphone = new Softphone();

// Authenticating the softphone
const res = await softphone.login({
  type: "OAuth2.0",
  token: "<OAUTH_TOKEN>",
  email: "<USER_EMAIL>"
});

// Configuring Audio elements
const audioElements = {
  remote: document.getElementById("sip-remote-audio"),
  local: document.getElementById("sip-local-audio"),
}

// Configuring Listeners
const listeners = {
  onConnectionStateChange: (type, newState, attemptReconnection, error) => {
    // type : "UserAgentState" | "RegisterState"
    // if type is "UserAgentState", newState: "Started" | "Stopped"
    // if type is "RegisterState", newState: "Initial" | "Registered" | "Terminated" | "Unregistered"
  },
  
  onCallCreated: (type, details) => {
    // type: "Incoming" | "Outgoing"
    // details : Object {candidate: "+91936*******"}
  },

  onCallRinging: (type, details) => {
    // type: "Incoming" | "Outgoing"
    // details : Object {candidate: "+91936*******"}
    // show on call action buttons to user
  },

  onCallHangup: (type, details) => {
   // type: "Incoming" | "Outgoing"
   // details : Object {candidate: "+91936*******"}
   // show apt ui
  },
}

const options = {
  //End any ongoing call when user navigates away, default value is false
  endSessionOnNavigate: true,
  //Log out and end any ongoing call when user navigates away, default value is false
  logoutOnNavigate: true
}
//NOTE: Logout and termination of any ongoing call will always happen on page reload/refresh. This parameter is optional and is supported only on Chrome, Edge and Opera.

// Starting the Softphone
await softphone.start(listeners, audioElements, options);

// Initiating a call
const phoneNumber = "+919711******";
const virtualNumber = "+919368******"
const options = {
  metadata: {
    transactionId: "",
    candidateId: "",
    jobId: ""
  }
}
await softphone.makeCall(phoneNumber, virtualNumber, options);

// Ending a call
await softphone.getSession.end();

//Include HTML Elements
<audio controls id="sip-local-audio"></audio>
<audio autoPlay controls id="sip-remote-audio"></audio>

Softphone

The Softphone class provides the following methods.

login({type: String, token: String, email: String})

Authenticates the Softphone with FreJun. Value of type: "OAuth2.0".

start(listeners: Object, audioElements: Object, options: Object)

Registers the provided Audio elements, listeners and options. (Also prompts the user for mic permissions, if required.)

makeCall(phoneNumber: String, virtualNumber: String, options: Object)

Initiates a call and creates a new Session instance. virtualNumber and options parameters are optional. Metadata ids can be passed using options object as shown in sample implementation.

updateAccessToken(token: String)

Updates the OAuth access token, should be called on receiving an InvalidTokenException from methods other than login.

logout()

Handles data cleanup by dereferencing class variables.

reset()

Reconnects and re-registers the Softphone.

NOTE:

On disconnection, the softphone will automatically retry connecting to the server. If the attemptReconnection parameter of onConnectionStateChange listener is true, indicating that these (auto) reconnection attempts are exhausted, reset should be called to restore the calling service, based on the type as follows:

If type is UserAgentState, Softphone.reset(true) should be awaited.

If type is RegistererState, Softphone.reset() should be awaited.

Session

The Session object is accessed through Softphone.getSession and provides the following methods for managing the current session/call.

accept()

Accepts an incoming call.

end()

Rejects/Ends the call.

mute()

Mutes the call.

unmute()

Unmutes the call.

hold()

Puts the call on hold.

unhold()

Resumes the call if it was put on hold.

sendDTMF(signal: String)

Sends DTMF signal.

Event Listeners

The following listeners can be configured during Softphone initialization.

ListenerRequiredDescription
onConnectionStateChangeYesCalled when the softphone's connection state or registration state changes.
onCallCreatedYesCalled when a new session is created.
onCallRingingYesCalled when a session is connected.
onCallHangupYesCalled when a session is terminated.

Logging & Error Handling

The default logging level is debug. It is not customizable as of now.

Error classes

A complete list of Errors thrown by the SDK are described below.

ErrorReason
MissingParameterExceptionMethod called without one or more required parameters.
InvalidValueExceptionMethod called with invalid value for one or more parameters.
InvalidTokenExceptionThe token which login method was called with is INVALID or has EXPIRED
UnauthorizedExceptionMethod of Softphone or Session called when Softphone is not authenticated.
InvalidSessionTypeExceptionSession type is invalid for the method called.
InvalidSessionStateExceptionSession state is invalid for the method called.
PermissionDeniedExceptionUser doesn't have the permission required to perform the action.
UnknownExceptionError thrown for unknown reason.

版本与发布记录

@frejun/softphone-web-sdk 共发布 13 个版本,首次发布于 2024/05/24;过去 12 个月发布了 3 个版本。

版本发布日期距今
2.0.1latest2026/11/079 天前
2.0.02026/02/099 个月前
1.5.02026/02/049 个月前
1.4.02025/07/021.4 年前
1.3.02024/12/291.9 年前
1.2.12024/09/132 年前

关于 @frejun/softphone-web-sdk 的常见问题

@frejun/softphone-web-sdk 是什么?

This SDK provides a SIP based Softphone to make/receive calls on the browser using FreJun

如何安装 @frejun/softphone-web-sdk?

在项目目录运行 npm install @frejun/softphone-web-sdk,或使用 pnpm add / yarn add / bun add。

@frejun/softphone-web-sdk 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/frejun__softphone-web-sdk 是否存在。

@frejun/softphone-web-sdk 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@frejun/softphone-web-sdk 可以商用吗?

@frejun/softphone-web-sdk 使用 ISC 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@frejun/softphone-web-sdk 的下载量有多少?

根据 npm 官方下载统计,@frejun/softphone-web-sdk 在 2026/10/16 – 2026/11/14 这 30 天内被下载 3,193 次,日均约 106 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@frejun/softphone-web-sdk 还在维护吗?

最新版本 2.0.1 发布于 2026/11/07(9 天前);至今共发布 13 个版本,其中过去 12 个月发布了 3 个;首次发布于 2024/05/24。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。