@openreplay/tracker-assist
v11.0.21
Published
Tracker plugin for screen assistance through the WebRTC
Readme
OpenReplay Assist
OpenReplay Assist Plugin 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.
Documentation
For launch options and available public methods, refer to the documentation
Installation
npm i @openreplay/tracker-assistOR
yarn add @openreplay/tracker-assistUsage
With NPM
Initialize the tracker then load the @openreplay/tracker-assist plugin.
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
// .start() returns a promise
tracker.start().then(sessionData => ... ).catch(e => ... )
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
// .start() returns a promise
tracker.start().then(sessionData => ... ).catch(e => ... )
}, [])
//...
}Options
trackerAssist({
onAgentConnect: StartEndCallback;
onCallStart: StartEndCallback;
onRemoteControlStart: StartEndCallback;
onRecordingRequest?: (agentInfo: Record<string, any>) => any;
onCallDeny?: () => any;
onRemoteControlDeny?: (agentInfo: Record<string, any>) => any;
onRecordingDeny?: (agentInfo: Record<string, any>) => any;
onSessionConfirmApprove?: (agentInfo: Record<string, any>) => any;
onSessionConfirmDeny?: (agentInfo: Record<string, any>) => any;
session_calling_peer_key: string;
session_control_peer_key: string;
callConfirm: ConfirmOptions;
controlConfirm: ConfirmOptions;
recordingConfirm: ConfirmOptions;
sessionConfirm: ConfirmOptions;
socketHost?: string;
config: RTCConfiguration;
serverURL: string
callUITemplate?: string;
agentShortNames?: boolean;
ignoreAnonymous?: boolean;
autostart?: Autostart; // 'disabled' | 'continuation' | 'auto'
requestConfirm?: boolean;
})agentShortNames: Whentrue, only the first part of an agent's name is shown in the call popup (e.g."John Doe"→"John"). Defaults tofalse.ignoreAnonymous: Whentrue, assist postpones connecting until auserIDis set on the session (viatracker.setUserID(...)). Anonymous sessions won't appear as live until identified. Defaults tofalse.autostart: Controls when assist connects. Import theAutostartenum from the package. Defaults toAutostart.Auto.Autostart.Auto: always connect ontracker.start()(legacy behavior).Autostart.Disabled: never connect automatically; callassist.start()yourself.Autostart.Continuation: connect only afterassist.start()is called, but remember that choice insessionStorageso assist auto-continues across page reloads untilassist.stop()is called.
requestConfirm: Whentrue, assist connects as usual but sends nothing to the agents until the user approves a confirmation popup, shown as soon as the first agent connects to the session. On approval, tracking restarts so agents receive a full snapshot; the approval is remembered per-tab (sessionStorage) untilassist.stop()is called. On denial, the session stays connected but silent, and the popup is shown again on the next agent connection. UsesessionConfirmto customize the popup andonSessionConfirmApprove/onSessionConfirmDenyfor callbacks. Defaults tofalse.
Public methods
tracker.use(trackerAssist(options)) returns the assist instance (or undefined when assist can't load — e.g. inside an iframe, unsupported browser, or tracker version mismatch), which exposes:
start(): connect assist. InAutostart.Continuationmode this also persists the flag used to auto-continue after reloads. No-op until the tracker itself is active.stop(): disconnect assist and tear down all live connections. It won't reconnect automatically untilstart()is called again; inAutostart.Continuationmode it clears the persisted flag.
import Tracker from '@openreplay/tracker';
import trackerAssist, { Autostart } from '@openreplay/tracker-assist';
const tracker = new Tracker({ projectKey: PROJECT_KEY });
const assist = tracker.use(trackerAssist({ autostart: Autostart.Continuation }));
tracker.start().then(() => {
// enable assist on demand; it will resume automatically on reload
assist?.start();
});
// later, to fully turn it off:
assist?.stop();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'})
}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.sessionConfirm: Customize the text and/or layout of the session view confirmation popup (requestConfirmmode).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 when someone from OpenReplay UI connects to the current live session. It can return another function. In this case, returned callback will be called when the same agent connection gets closed.
onAgentConnect = () => {
console.log("Live session started")
const onAgentDisconnect = () => console.log("Live session stopped")
return onAgentDisconnect
}onCallStart: () => (()=>void | void): This callback function is fired as soon as a call (webRTC) starts. It can also returnonCallEndwhich 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: () => (()=>void | void): This callback function is fired as soon as a remote control session starts. It can also returnonRemoteControlEndwhich will be called when the remote control permissions are revoked. Below is an example:
onCallStart: () => {
console.log("Remote control started")
const onCallEnd = () => console.log("Remote control ended")
return onCallEnd
}Troubleshooting
Critical dependency: the request of a dependency is an expression
Please apply this workaround if you face the below error when compiling:
Failed to compile.
./node_modules/peerjs/dist/peerjs.min.js
Critical dependency: the request of a dependency is an expressionIf you encounter any other issue, please connect to our Slack and get help from our community.
