@fctv/js
Version:
Call SDK for JavaScript
136 lines (106 loc) • 4.02 kB
Markdown
## Introductions:
The JavaScript SDK for WebRTC call.
## SDK usage guidelines:
Main components:
- **UserSession**: For initializing session from client to Call server.
- **Constructor**:
UserSession(user)
- `user` options:
+ wssUrl: Socket URL to the Call Server
+ extension: Extenstion name
+ domain: Domain name
+ password: Plain password
+ callOptions: {
callerIdName: Caller Id Name
callerIdNumber: Call Id Number
}
+ userInfo: {
// Other info here. Ex. email
}
+ autoReconnect: Default: true
+ autoRecoveryCall: Auto recovery the call when browser tab closed unexpectedly. Default: true
- **Properties**:
- isLoggedIn: Whether user logged in.
- **Methods**:
- connect(): Connect to the Call server with `user` options
- close(): Close the connection to the Call server.
- on(EVENT_NAME, callback): Start listening a **UserSessionEvent**:
+ EVENT_NAME: UserSessionEvent event
+ callback(err, data): Callback function for handling the event.
- off(EVENT_NAME[, callback]): Stop listening a **UserSessionEvent**
- testSpeed(): Test connection speed to the Call server. The data will be returned into Promise object or sent to **UserSessionEvent.ON_SPEED_CHANGE**.
+ Return: `Promise({ upDur, downDur, upKps, downKps })`
+ `on(UserSessionEvent.ON_SPEED_CHANGE, (err, { upDur, downDur, upKps, downKps } ))`
- newCall(options):
+ options:
{
destinationNumber: (required) Extension or number
callerIdName: (optional)
callerIdNumber: (optional)
}
- **UserSessionEvent**: Events will be emitted during the Call Session.
We can catch those events with callback functions:
**- Ex:**
const session = new UserSession(user);
session.on(UserSessionEvent.<EVENT_NAME>, (err, data) => {
console.log(err, data);
})
- ON_READY
- ON_CLOSED
- ON_ERROR
- ON_RETRYING
- ON_LOGIN_ERROR
- ON_LOGIN_SUCCESS
- ON_SPEED_CHANGE:
- ON_USER_MEDIA_ERROR
- ON_USER_PEER_ERROR
- ON_INCOMING_CALL
- ON_RECOVERY_CALL
- ON_CALL_LOCAL_STREAM
- ON_CALL_REMOTE_STREAM
- ON_CALL_STATE_UPDATE
- **CallState**:
- NEW
- REQUESTING
- TRYING
- RECOVERING
- RINGING
- ANSWERING
- EARLY
- ACTIVE
- HELD
- HANGUP
- DESTROYED
- PURGE
- **Util**: Some utility functions:
- mediaDevices:
- enumerateDevices(kind)
+ kind: `audioinput`, `videoinput`, `audiooutput`
- checkUserMediaPermission(constraints):
+ constraints: Refer to [MediaStreamConstraints](https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamConstraints)
- **Call**:
- **Properties**:
+ id
+ localStream
+ remoteStream
+ state: **CallState**
+ activeTime: Active time in milliseconds since January 1, 1970 (midnight UTC/GMT).
+ callType: inbound/outbound
+ options
- **Functions**
+ answer(options)
+ hangup(options)
+ toggleMuteMic()
+ muteMic()
+ unmuteMic()
+ toggleMuteCam()
+ muteCam()
+ unmuteCam()
+ sendDtmf()
+ toggleHold()
+ hold()
+ unhold()
##Examples:
Please refer to [examples](https://unpkg.com/@fctv/js@latest/examples/) for detailed usage.
##
*** **TypeScript** support: Currently the SDK does not support TypeScript.