1.1.4 • Published 3 years ago

@devops_gcalls/gcalls-sdk-react-native v1.1.4

Weekly downloads
-
License
ISC
Repository
gitlab
Last release
3 years ago

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
  • Access url http://localhost:5984/_utils. If login page appear, server started successful!

API Summary

calllog.call(phoneNumber)

Make a simple call

ParametersDescription
phoneNumberA phone number that use to call
returnstrue

calllog.terminate(callback)

Terminate the current session

ParametersDescription
callbackCallback 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

ParametersDescription
phoneNumberA phone number that call will be transfered to
callbackCallback function that will call before transfer call
returnsboolean. true if in call with other, else false

calllog.isConnected()

Check connection with the current websocket

ParametersDescription
returnsboolean. Return true if the transport is connected, false otherwise

calllog.isRegistered()

Check the User Agent registration

ParametersDescription
returnsboolean. 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

ParametersDescription
optionboolean
returnsboolean. Return true if the UA is registered, false otherwise

calllog.setMediaConstraints(mediaConstraints)

Set new option for mediaConstraints. example fields : { audio: true, video:false }

ParametersDescription
mediaConstraintsObject 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", }

ParametersDescription
configurationAn 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()

ParametersDescription
eventHandlersDefine 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)
ParametersDescription
databaseConfigurationsA 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)
ParametersDescription
fieldsObject 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

ParametersDescription
dataObject contain new record that you want to save into pouchdb
returnsReturn 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')
ParametersDescription
selectorsobject
returnsthe call log object from PouchDB if success, null otherwise

calllog.getCalllogs()

Get all Calllogs in the PouchDB Example:

calllog.getCalllogs()
ParametersDescription
selectorsobject
returnsall 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)
ParametersDescription
selectorsobject
returnsarray 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)
ParametersDescription
fieldarray 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