This SDK provides a SIP based Softphone to make/receive calls on the browser using FreJun.
- FreJun Account
- OAuth 2.0 Access Token
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: (newState, type) => {
},
onCallCreated: (type) => {
// notify user for inbound(Invitation), i.e. "answer" and "decline" options
},
onCallAnswered: (type) => {
// show on call action buttons to user
},
onCallHangup: (type) => {
// show apt ui
},
}
// Starting the Softphone
softphone.start(audioElements, listeners);
// Initiating a call
const phoneNumber = "+919711******";
softphone.makeCall(phoneNumber);
//Include HTML Elements
<audio controls id="sip-local-audio"></audio>
<audio autoPlay controls id="sip-remote-audio"></audio>
The Softphone
class provides the following methods.
Authenticates the Softphone with FreJun.
Registers the provided Audio elements and Listeners. (Also prompts the user for mic permissions, if required.)
Initiates a call and creates a new Session
instance.
Handles data cleanup by dereferencing class variables.
Reconnects and re-registers the Softphone.
On disconnection, the softphone will automatically retry connecting to the server upto 3 times.
The current attempt number will be passed onto the OnConnectionStateChange
listener.
In case all 3 attempts have failed, Softphone.reset()
should be called to reattempt the connection.
The Session
object is accessed through Softphone.getSession
and provides the following methods for
managing the current session/call.
Accepts an incoming call.
Rejects/Ends the call.
Mutes the call.
Unmutes the call.
Puts the call on hold.
Resumes the call if it was put on hold.
Sends DTMF signal.
The following listeners can be configured during Softphone
initialization.
Listener | Required | Description |
---|---|---|
onConnectionStateChange |
Yes | Called when the softphone's connection state or registration state changes. |
onCallCreated |
Yes | Called when a new session is created. |
onCallRinging |
Yes | Called when a session is connected. |
onCallHangup |
Yes | Called when a session is terminated. |
The default logging level is debug
. It is not customizable as of now.
A complete list of Errors thrown by the SDK are described below.
Error | Reason |
---|---|
MissingParameterException |
Method called without one or more required parameters. |
InvalidValueException |
Method called with invalid value for one or more parameters. |
InvalidTokenException |
login method called with INVALID or EXPIRED token
|
UnauthorizedException |
Method of Softphone or Session called when Softphone is not authenticated. |
InvalidSessionTypeException |
Session type is invalid for the method called. |
InvalidSessionStateException |
Session state is invalid for the method called. |
UnknownException |
Error thrown for unknown reason. |