ringcentral-embeddable-extension-common

Cli tool to create a RingCentral Embeddable Voice chrome extension for sites.

Usage no npm install needed!

<script type="module">
  import ringcentralEmbeddableExtensionCommon from 'https://cdn.skypack.dev/ringcentral-embeddable-extension-common';
</script>

README

ringcentral-embeddable-extension-common

RingCentral Embeddable Voice Chrome/Firefox extension common files.

Use

Install

npm i -D -E ringcentral-embeddable-extension-common

In content.js for single page app


/**
 * content.js for chrome extension
 */

import createApp from 'ringcentral-embeddable-extension-common/src/spa/init'
//import * as config from './config'
import {ringCentralConfigs, thirdPartyConfigs, appVersion} from 'ringcentral-embeddable-extension-common/src/common/app-config'
import {isIframe} from 'ringcentral-embeddable-extension-common/src/common/helpers'
import 'ringcentral-embeddable-extension-common/src/spa/style.styl'
import './custom.styl'

let {
  clientID,
  appServer
} = ringCentralConfigs

let appConfigQuery = ''
let {serviceName} = thirdPartyConfigs
if (clientID || appServer) {
  appConfigQuery = `?prefix=${serviceName}-rc&newAdapterUI=1&userAgent=${serviceName}_extension%2F${appVersion}&disableActiveCallControl=false&appKey=${clientID}&appServer=${encodeURIComponent(appServer)}`
}

/* eslint-disable-next-line */
if (!isIframe) {
  ;(function() {
    console.log('import RingCentral Embeddable Voice to web page')
    var rcs = document.createElement('script')
    rcs.src = 'https://ringcentral.github.io/ringcentral-embeddable/adapter.js' + appConfigQuery
    var rcs0 = document.getElementsByTagName('script')[0]
    rcs0.parentNode.insertBefore(rcs, rcs0)
  })()
}

let config = {
  // config for insert click to call button, check ./config.js insertClickToCallButton  for detail
  insertClickToCallButton: [],

  // config for hover contact node to show click to dial tooltip, check ./config.js hoverShowClickToCallButton for detail
  hoverShowClickToCallButton: [],

  // config for modify phone number text to click-to-call link, check ./config.js phoneNumberSelectors for detail
  phoneNumberSelectors: [],

  // third party feature config, check ./config.js thirdPartyServiceConfig function for detail
  // should return
  /*
  {
    services: object,
    handleRCEvents: function
  }
  */
  thirdPartyServiceConfig: (serviceName) => console.log(serviceName),

  // after init callback function, can do some extra init here
  initThirdParty: () => null
}

window.addEventListener('load', createApp(config))


In content.js for not single page app


/**
 * content.js for chrome extension
 */

import createApp from 'ringcentral-embeddable-extension-common/src/no-spa/init'
// import * as config from './config'
import 'ringcentral-embeddable-extension-common/src/no-spa/style.styl'
import './custom.styl'

let config = {
  // config for insert click to call button, check ./config.js insertClickToCallButton  for detail
  insertClickToCallButton: [],

  // config for hover contact node to show click to dial tooltip, check ./config.js hoverShowClickToCallButton for detail
  hoverShowClickToCallButton: [],

  // config for modify phone number text to click-to-call link, check ./config.js phoneNumberSelectors for detail
  phoneNumberSelectors: [],

  // third party feature config, check ./config.js thirdPartyServiceConfig function for detail
  // should return
  /*
  {
    services: object,
    handleRCEvents: function
  }
  */
  thirdPartyServiceConfig: (serviceName) => console.log(serviceName),

  // after init callback function, can do some extra init here
  initThirdParty: () => null,

  // init call with ringcenntral button at page bottom
  // enbaled by default, change to false to disable it
  initCallButton: true
}

window.addEventListener('load', createApp(config))


Built-in oauth support

import getAuthCode from 'ringcentral-embeddable-extension-common/src/feat/browser-oauth'

async function auth() {
  let authCode = await getAuthCode(authUrl)
  // do something like get access code with auth code
}

License

MIT