目录
概览
SDK 提供了基于 SIP 的 软电话 在浏览器上使用 弗雷琼。 。 。 .
所需资源
- FreJun 账户
- OAuth 2.0 访问托肯
使用量
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 类提供了以下方法.
login({type: String, token: String, email: String})
用 FreJun 认证软手机。 类型值 : "OAuth2.0" .
start(listeners: Object, audioElements: Object, options: Object)
注册所提供的音频元素、听众和选项。 (如果需要,还提示用户使用麦克风权限)
makeCall(phoneNumber: String, virtualNumber: String, options: Object)
启动呼叫并创建新 Session 举个例子. virtualNumber 财务报告和审定财务报表 options 参数是可选的。 元数据ID可以使用样本执行中显示的选项对象来传递.
updateAccessToken(token: String)
更新 OAuth 访问令牌, 应在接收时调用 InvalidTokenException 调自除 login。 。 。 .
logout()
通过去引用类变量处理数据清理.
reset()
重新连接并重新注册了"软手机".
注:
断开时,软手机会自动重试连接到服务器. 如果尝试重新连接参数为 onConnectionStateChange 听者是真实的,表示这些(自动)重联尝试已经用尽, reset 应呼吁恢复电话服务,基于 type 内容如下:
若为 type 实值 UserAgentState, (中文(简体) ), Softphone.reset(true) 应等待.
若为 type 实值 RegistererState, (中文(简体) ), Softphone.reset() 应等待.
会议
这个 Session 对象通过 Softphone.getSession 并提供下列方法:
管理本届会议/电话会议.
accept()
接受接通电话.
end()
拒绝/结束呼叫 .
mute()
停止通话.
unmute()
释出召相.
hold()
暂时搁置电话.
unhold()
如果被搁置,就恢复通话.
sendDTMF(signal: String)
发送DTMF信号.
活动听众
下列收听器可以在 Softphone 初始化.
| 听众 | 需求 | 说明 |
|---|---|---|
onConnectionStateChange | 对 | 当软手机的连接状态或注册状态发生变化时调用. |
onCallCreated | 对 | 创建新会话时调用 . |
onCallRinging | 对 | 当一个会话连接时调用 . |
onCallHangup | 对 | 当会话结束时调用 . |
日志处理出错( E)
默认日志级别是 debug。它现在不习惯.
错误类别
SDK所抛出的错误的完整列表介绍如下.
| 错误 | 原因 |
|---|---|
MissingParameterException | 方法调用时没有一个或多个必要的参数. |
InvalidValueException | 方法调用一个或多个参数的无效值 . |
InvalidTokenException | 这个 token 哪个 login 被调用的方法是 INVALID 或 EXPIRED |
UnauthorizedException | 方法 Softphone 或者说 Session 当Softphone没有认证时调用. |
InvalidSessionTypeException | 对调用的方法来说会话类型无效 . |
InvalidSessionStateException | 对调用的方法来说, 会话状态无效 . |
PermissionDeniedException | 用户没有执行动作所需的权限. |
UnknownException | 因不明原因出错 . |