Assist

OpenReplay Assist allows you to support your users by seeing their live screen and instantly hopping on call (WebRTC) with them without requiring any 3rd-party screen sharing software.

npm i @openreplay/tracker-assist

If your OpenReplay tracker is set up using the JS snippet, then simply replace the .../openreplay.js occurrence with .../openreplay-assist.js. Below is an example of how the script should like after the change:

<!-- OpenReplay Tracking Code -->
<script>
var initOpts = { projectKey: "GxPpaDARdn2345fgt321" };
var startOpts = { userID: "" };
(function(A,s,a,y,e,r){
  r=window.OpenReplay=[e,r,y,[s-1, e]];
  s=document.createElement('script');s.src=A;s.async=!a;
  ...
})("//static.openreplay.com/latest/openreplay-assist.js", 1, 0, initOpts, startOpts);
</script>

Initialize the tracker then load the @openreplay/tracker-assist plugin.

If your website is a Single Page Application (SPA)

Section titled If your website is a Single Page Application (SPA)
import Tracker from '@openreplay/tracker';
import trackerAssist from '@openreplay/tracker-assist';

const tracker = new Tracker({
  projectKey: PROJECT_KEY,
});
tracker.use(trackerAssist(options)); // check the list of available options below

tracker.start();

If your web app is Server-Side-Rendered (SSR)

Section titled If your web app is Server-Side-Rendered (SSR)

Follow the below example if your app is SSR. Ensure tracker.start() is called once the app is started (in useEffect or componentDidMount).

import OpenReplay from '@openreplay/tracker/cjs';
import trackerFetch from '@openreplay/tracker-assist/cjs';

const tracker = new OpenReplay({
  projectKey: PROJECT_KEY
});
tracker.use(trackerAssist(options)); // check the list of available options below

//...
function MyApp() {
  useEffect(() => { // use componentDidMount in case of React Class Component
    tracker.start();
  }, [])
//...
}

The assist plugin supports the below options:

trackerAssist({
  callConfirm?: string|ConfirmOptions;
  controlConfirm?: string|ConfirmOptions;
  config?: object;
  onAgentConnect?: () => (()=>void | void);
  onCallStart?: () => (()=>void | void);
  onRemoteControlStart?: () => (()=>void | void);
  onCallDeny?: () => any;
  onRemoteControlDeny?: (agentInfo: Record<string, any>) => any;
  onRecordingDeny?: (agentInfo: Record<string, any>) => any;
  callUITemplate?: string
  /** 
   * enables gzip compression for big batches on client side
   * */
  compressionEnabled: boolean;
  /**
   * Minimum amount of MESSAGES in a batch to trigger compression run
   * @default 5000
   * */
  compressionMinBatchSize: number
})

The remote control as well as the call widgets, those seen by the end user, can be fully customized.

type ConfirmOptions = {
  text?:string,
  style?: StyleObject, // style object (i.e {color: 'red', borderRadius: '10px'})
  confirmBtn?: ButtonOptions, 
  declineBtn?: ButtonOptions
}

type ButtonOptions = HTMLButtonElement | string | {
  innerHTML?: string, // to pass an svg string or text
  style?: StyleObject, // style object (i.e {color: 'red', borderRadius: '10px'})
}

It’s possible to customize every aspect of this widget via the below set of ids and classes. Ids serve as anchors for individual buttons/elements whereas classes can be used for group containers.

HTML TypeName(s)Description
idor-assistWidget container
classcard, border-dark, shadow and drag-areaStyles for the card’s border and shadow
idcontrolsContainer for the calling part inside the widget
classcard-headerStyles for card header of the call widget (the one showing the agent name next to a timer)
idagent-nameContainer for agent’s name
iddurationContainer for timer
idvideo-containerUser’s own video feed container
idremote-streamAgent’s video feed
classcard-footerContainer for buttons Mute, Video, End Call
idaudio-btnMute button
idvideo-btnVideo button
idend-call-btnEnd call button
idremote-control-rowRow for remote controls
idend-control-btnId for the end control button

Here is the list of all callbacks:

  • callConfirm: Customize the text and/or layout of the call request popup.
  • controlConfirm: Customize the text and/or layout of the remote control request popup.
  • config: Contains any custom ICE/TURN server configuration. Defaults to { 'iceServers': [{ 'urls': 'stun:stun.l.google.com:19302' }], 'sdpSemantics': 'unified-plan' }.
  • onAgentConnect: () => (()=>void | void): This callback function is fired as soon as a live session starts and sends back the agent’s details (email, name and query). It can also return onAgentDisconnect which will be called when the session is disconnected. In case of an unstable connection, this may be called several times. Below is an example:
onAgentConnect = ({ email, name, query }) => {
  console.log("Live session started")
  const onAgentDisconnect =  () => console.log("Live session stopped")
  return onAgentDisconnect
}
  • onCallStart: ({ email, name, query }) => (()=>void | void): This callback function is fired as soon as a call (webRTC) starts and sends back the agent’s details (email, name and query). It can also return onCallEnd which will be called when the call ends. In case of an unstable connection, this may be called several times. Below is an example:
onCallStart: () => {
  console.log("Call started")
  const onCallEnd = () => console.log("Call ended")
  return onCallEnd
}
  • onRemoteControlStart: ({ email, name, query }) => (()=>void | void): This callback function is fired as soon as a remote control session starts and sends back the agent’s details (email, name and query). It can also return onRemoteControlEnd which will be called when the remote control permissions are revoked. Below is an example:
onRemoteControlStart: () => {
  console.log("Remote control started")
  const onControlEnd = () => console.log("Remote control ended")
  return onControlEnd
}
  • onCallDeny?: () => any;: This callback function is fired when call was denied by a user during requesting phase.
onCallDeny: () => {
  console.log("Call denied")
}
  • onRemoteControlDeny?: (agentInfo: Record<string, any>) => any;: This callback function is fired when remote control session was denied by a user during requesting phase and sends back the agent’s details (email, name and query).
onRemoteControlDeny: ({ email, name, query }) => {
  console.log("Remote control request denied for", email)
}
  • onRecordingDeny?: (agentInfo: Record<string, any>) => any;: This callback function is fired when recording session was denied by a user during requesting phase and sends back the agent’s details (email, name and query).
onRecordingDeny: ({ email, name, query }) => {
  console.log("Recording session denied")
 
}

Having trouble setting up this plugin? Please connect to our Slack or check out our Forum and get help from our community.