@devops_gcalls/gcalls-sdk-react-native

1.1.4 • Public • Published

Gcalls-js-sdk (React Native)

Introduction

Installation

npm install gcalls-sdk-react-native

Getting Started

1.1 Import SDK when using on React Native

import Calllog from "gcalls-sdk-react-native"

2. Configuration

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) => {
      console.log('incoming call from user');
    },
    outgoing: (e) => {
      console.log('outgoing call from user');
    },
    onTrack: (e, session) => {
      console.log("On track audio");
    },
  },
  mediaConstraints: { audio: true, video: false },
  databaseConfigurations: {
    db: "example-db",
    username: "example-username",
    password: "example-password",
    host: "http://example-couchdb-domain",
  },
};

3.1 Initiate SDK for React Native

const calllog = new Calllog(options);
calllog.register();

Install CouchDB Server

1. Create file

  • 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
    

2. Start server

  • Open command line and run docker-compose.yml file
 docker-compose up -d

API Summary

calllog.call(phoneNumber)

Make a simple call

Parameters Description
phoneNumber A phone number that use to call
returns true

calllog.terminate(callback)

Terminate the current session

Parameters Description
callback Callback function when terminate call session (under-developing)

calllog.transfer(phoneNumber, callback)

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

calllog.isConnected()

Check connection with the current websocket

Parameters Description
returns boolean. Return true if the transport is connected, false otherwise

calllog.isRegistered()

Check the User Agent registration

Parameters Description
returns boolean. Return true if the UA is registered, false otherwise

calllog.enableDebugMode(option)

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

calllog.setMediaConstraints(mediaConstraints)

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

calllog.setConfiguration(configuration)

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.start() 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

calllog.setEventHandlers(eventHandlers)

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

calllog.start() (Deprecated)

Start apply all configs of user to User Agent then new User Agent and new connection to CouchDB base on the current configuration

calllog.register()

Start apply all configs of user to User Agent then new User Agent and new connection to CouchDB base on the current configuration

calllog.unregister(options=null)

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.

calllog.setDatabaseConfigurations(databaseConfigurations)

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

calllog.setCalllogTemplate(fields)

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

calllog.insertCalllog(data)

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

calllog.getCalllog(id)

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

calllog.getCalllogs()

Get all Calllogs in the PouchDB Example:

calllog.getCalllogs()
Parameters Description
selectors object
returns all the call logs from PouchDB if success, null otherwise

calllog.getCalllogsByIndex(selectors)

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.

calllog.createIndex(fields)

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.

calllog.muteCalls()

Mutes call sound of local, the remote will not hear what local say more

calllog.unmuteCalls()

Unmutes call sound of local, the remote will hear what local say again

calllog.muteAudio()

Mute the sound of remote, local will not hear remote say more

calllog.unmuteAudio()

Unmute the sound of remote, local will hear remote say again

calllog.answer()

Answer the incoming call

Readme

Keywords

none

Package Sidebar

Install

npm i @devops_gcalls/gcalls-sdk-react-native

Weekly Downloads

0

Version

1.1.4

License

ISC

Unpacked Size

92.9 kB

Total Files

21

Last publish

Collaborators

  • quangliem
  • gcalls_devops
  • hungthezorba