npm install @devops_gcalls/gcalls-web-sdk
import Calllog from "@devops_gcalls/gcalls-web-sdk"
const options = {
configuration: {
sockets: ["wss://example:6969"],
proxy: "example.vn:1234",
sip: "101",
password: "101",
},
eventHandlers: {
progress: function (e) {
console.log("call is in progress from user");
},
failed: function (e) {
console.log("call failed with cause from user: " + e.cause);
},
ended: (e) => {
console.log("call ended with cause from user: " + e.cause);
},
confirmed: function (e) {
console.log("call confirmed from user");
},
incoming: (e) => {},
outgoing: (e) => {},
onTrack: (e, session) => {
var audio = document.createElement("audio");
audio.srcObject = e.streams[0];
audio.play();
},
},
mediaConstraints: { audio: true, video: false },
databaseConfigurations: {
db: "example-db",
username: "example-username",
password: "example-password",
host: "http://example-couchdb-domain",
},
};
const calllog = new Calllog(options);
calllog.register();
- Require docker, docker-compose
-
Create docker-compose.yml file and change COUCHDB_PASSWORD={your password}
version: "3.3" services: couchdb: image: couchdb:latest container_name: couchdb environment: - COUCHDB_USER=admin - COUCHDB_PASSWORD={your password} ports: - '5984:5984' - '4369:4369' - '9100:9100' volumes: - couchdb_data:/apache/couchdb - ./local.ini:/opt/couchdb/etc/local.d/local.ini volumes: couchdb_data: driver: local
-
create file local.ini in same folder with docker-compose.yml file
[httpd] enable_cors = true [cors] origins = * credentials = true methods = GET, PUT, POST, HEAD, DELETE headers = accept, authorization, content-type, origin, referer
- Open command line and run docker-compose.yml file
docker-compose up -d
- Access url http://localhost:5984/_utils. If login page appear, server started successful!
Make a simple call
Parameters | Description |
---|---|
phoneNumber | A phone number that use to call |
returns | true |
Terminate the current session
Parameters | Description |
---|---|
callback | Callback function when terminate call session (under-developing ) |
Transfer current session to another phone number. If callback is a function, it will invoke along with param input is the session phoneNumber: string
Parameters | Description |
---|---|
phoneNumber | A phone number that call will be transfered to |
callback | Callback function that will call before transfer call |
returns |
boolean . true if in call with other, else false |
Check connection with the current websocket
Parameters | Description |
---|---|
returns |
boolean . Return true if the transport is connected, false otherwise |
Check the User Agent registration
Parameters | Description |
---|---|
returns |
boolean . Return true if the UA is registered, false otherwise |
Set debug mode for SDK. If true, debug mode is on and will console.log events
Parameters | Description |
---|---|
option | boolean |
returns |
boolean . Return true if the UA is registered, false otherwise |
Set new option for mediaConstraints. example fields : { audio: true, video:false }
Parameters | Description |
---|---|
mediaConstraints | Object with two valid fields(audio and video) that accept only boolean values. The object will tell the sesion to use audio and/or video |
Reset the configuration for User Agent. After use setConfiguration, if you want to using new configuration for the current User Agent, it is require to call calllog.register() Example fields : { sockets: ["wss://example:6969"], proxy: "example.vn:1234", sip: "101", password: "101", }
Parameters | Description |
---|---|
configuration | An object contain fields (sockets, sip, proxy, password) to configure user agent |
Reset the event handler for the emitted event. eventHandler: Object contains many functions: progress, confirmed, ended, accepted, onTrack , incoming , outgoing , and failed. Example
const eventHandlers = {
progress: function (e) {
console.log("call is in progress from user");
},
failed: function (e) {
console.log("call failed with cause from user: " + e.cause);
},
ended: (e) => {
console.log("call ended with cause from user: " + e.cause);
},
confirmed: function (e) {
console.log("call confirmed from user");
},
incoming: function (e) {
console.log("call incoming from user");
},
outgoing: function (e) {
console.log("call outgoing from user");
},
}
calllog.setEventHandlers(eventHandlers);
if you want to using new eventHandlers for the current User Agent, it is require to call calllog.register()
Parameters | Description |
---|---|
eventHandlers | Define handlers for each event (progress, failed, ended, confirmed). Each handler will be execute after the default handler |
Start apply all configs of user to User Agent then new User Agent and new connection to CouchDB base on the current configuration
Stop connection to websocket server and remove session on pbx.
Parameters | Description |
---|---|
options | Optional object with a field 'all' that takes in a boolean value to unregistering all bindings of the same SIP user. |
Config for database
Example:
const config = {
db: "example-db",
username: "example-username",
password: "example-password",
host: "http://example-domain",
}
calllog.setDatabaseConfigurations(config)
Parameters | Description |
---|---|
databaseConfigurations | A Configuration for database. Field db contains name of the collection, username and password is configure for the user in the couchdb database, host is the remote couchdb server that you want to connect |
Add new fields to the call log default template. fields: Object contains new defined fields.
Example:
const fields = {
name: 'example',
gender: ''
}
calllog.setCalllogTemplate(fields)
Parameters | Description |
---|---|
fields | Object contain new fields that you want to add to the default template callLog |
Insert a new record to the CouchDB. data: Object with any field but id field is required in the object. Return true if success, null otherwise
Parameters | Description |
---|---|
data | Object contain new record that you want to save into pouchdb |
returns | Return the result of the inserted record, otherwise null if data is false (null, undefined) or catch the error when inserting new record |
Get a specific call log with call log ID in PouchDB Example:
calllog.getCalllog('123')
Parameters | Description |
---|---|
selectors | object |
returns | the call log object from PouchDB if success, null otherwise |
Get all Calllogs in the PouchDB Example:
calllog.getCalllogs()
Parameters | Description |
---|---|
selectors | object |
returns | all the call logs from PouchDB if success, null otherwise |
Get call log by defined index fields. This function utilize the PouchDB.find(), read more here -> https://pouchdb.com/guides/mango-queries.html selectors: Object contain index key and query value Return array of call log object(s) that match the condition selectors
Example:
const selectors = {
name: 'mario',
...
}
calllog.getCalllogsByIndex(selectors)
Parameters | Description |
---|---|
selectors | object |
returns | array of objects if success, null otherwise. |
Create new index(es) for the collection. This function utilize the PouchDB.createIndex(), read more here -> https://pouchdb.com/api.html#create_index fields: Array contains string value represent as field in the collection
Example:
const fields = ['name']
calllog.createIndex(fields)
Parameters | Description |
---|---|
field | array of string |
returns | {result: 'created'} if success, null otherwise. |
Mute all the local's streams audio
Unmute all the local's streams audio
Mute all the remote's streams audio
Unmute all the remote's streams audio
Answer the incoming call using session
Set event handlers for websocket's events.
Parameters | Description |
---|---|
options | Object contains function to handle websocket's event |
Fields in options object | Description |
---|---|
onMessage | event handler websocket.onmessage |
onClose | event handler websocket.onclose |
onOpen | event handler websocket.onopen |
Example:
let socketEventHandlers = {
onMessage: (e) => {
console.log(e);
},
onClose: (e) => {
console.log(e);
},
onOpen: (e) => {
console.log(e);
}
}
calllog.setSocketEventHandlers(socketEventHandlers);
Reconfig one or more SDK options. After calling setOptions, to let the SDK behave the new settings, it is required to run sdk.registered().
Parameters | Description |
---|---|
options | Object contains fields to reconfig SDK |
Fields in options object | Description |
---|---|
configuration | Object contains configuration for a User Agent |
eventHandlers | Object event handler call's events |
databaseConfigurations | Object contains database configuration |
Return the current calllog saved in SDK
Update the current calllog saved in SDK
Parameters | Description |
---|---|
data | Object data to update the current calllog |
returns | true if successfully updated. Throw error otherwise |
Insert a calllog in PouchDB. If data is not specified, the current calllog in SDK will be inserted by default
Parameters | Description |
---|---|
data | Object data to update the current calllog |
returns | the calllog object if successfully insert. Throw error otherwise |
Reset the current calllog in SDK to initial state.
Phan Anh Tu
Le Phan Minh Thai
Nguyen Ngoc Dang Hung