1.0.16 • Published 3 years ago

gc-sdk v1.0.16

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

Gcalls-js-sdk

Introduction

Installation

npm install gc-sdk

Getting Started

1.1 Import SDK when using on Web

import Calllog from "gc-sdk"

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) => {},
    outgoing: (e) => {},
    onTrack: (e, session) => {
      console.log("steammmmmmmmmmmmmmmmmmm");
      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",
  },
};

3.1 Initiate SDK for Web

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

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

ParametersDescription
eventHandlersDefine handlers for each event (progress, failed, ended, confirmed). Each handler will be execute after the default handler

calllog.start()

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

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

1.0.16

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago