diff --git a/tracker/tracker-assist/README.md b/tracker/tracker-assist/README.md index f679bd8f6..2ebac72d4 100644 --- a/tracker/tracker-assist/README.md +++ b/tracker/tracker-assist/README.md @@ -30,6 +30,9 @@ Options: { confirmText: string, confirmStyle: Object, + config: RTCConfiguration, + onAgentConnect: () => (()=>void | void), + onCallStart: () => (()=>void | void), } ``` Use `confirmText` option to specify a text in the call confirmation popup. @@ -41,4 +44,43 @@ You can specify its styles as well with `confirmStyle` style object. color: "orange" } -``` \ No newline at end of file +``` + +It is possible to pass `config` RTCConfiguration object in order to configure TURN server or other parameters. +```ts +config: { + iceServers: [{ + urls: "stun:stun.services.mozilla.com", + username: "louis@mozilla.com", + credential: "webrtcdemo" + }, { + urls: ["stun:stun.example.com", "stun:stun-1.example.com"] + }] +} + +``` + +You can pass `onAgentConnect` callback. It will be called 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. +```ts +onAgentConnect: () => { + console.log("Hello!") + const onAgentDisconnect = () => console.log("Bye!") + return onAgentDisconnect +} + +``` +Warning: it is possible for the same agent to be connected/disconnected several times during one session due to a bad network. Several agents may connect simultaneously. + + +A callback `onCallStart` will be fired when the end-user accepts the call. It can return another callback that will be called on call end. +```ts +onCallStart: () => { + console.log("Allo!") + const onCallEnd = () => console.log("short beeps...") + return onCallEnd +} + +``` + + + diff --git a/tracker/tracker-assist/package.json b/tracker/tracker-assist/package.json index 345d42ecb..97973d6dd 100644 --- a/tracker/tracker-assist/package.json +++ b/tracker/tracker-assist/package.json @@ -1,7 +1,7 @@ { "name": "@openreplay/tracker-assist", "description": "Tracker plugin for screen assistance through the WebRTC", - "version": "3.4.9", + "version": "3.4.11", "keywords": [ "WebRTC", "assistance", diff --git a/tracker/tracker-assist/src/CallWindow.ts b/tracker/tracker-assist/src/CallWindow.ts index f22aa6a7a..3499cf7ea 100644 --- a/tracker/tracker-assist/src/CallWindow.ts +++ b/tracker/tracker-assist/src/CallWindow.ts @@ -1,4 +1,4 @@ -import type { LocalStream } from './LocalStream'; +import type { LocalStream } from './LocalStream.js'; const SS_START_TS_KEY = "__openreplay_assist_call_start_ts" diff --git a/tracker/tracker-assist/src/index.ts b/tracker/tracker-assist/src/index.ts index c1e452a34..3ffd4671a 100644 --- a/tracker/tracker-assist/src/index.ts +++ b/tracker/tracker-assist/src/index.ts @@ -11,6 +11,8 @@ import ConfirmWindow from './ConfirmWindow.js'; import RequestLocalStream from './LocalStream.js'; export interface Options { + onAgentConnect: () => (()=>{} | void), + onCallStart: () => (()=>{} | void), confirmText: string, confirmStyle: Object, // Styles object session_calling_peer_key: string, @@ -40,6 +42,8 @@ export default function(opts?: Partial) { confirmStyle: {}, session_calling_peer_key: "__openreplay_calling_peer", config: null, + onCallStart: ()=>{}, + onAgentConnect: ()=>{}, }, opts, ); @@ -99,7 +103,10 @@ export default function(opts?: Partial) { assistDemandedRestart = true; app.stop(); openDataConnections[conn.peer] = new BufferingConnection(conn, options.__messages_per_send) + + const onAgentDisconnect = options.onAgentConnect(); conn.on('close', () => { + onAgentDisconnect?.(); log("Connection close: ", conn.peer) delete openDataConnections[conn.peer] // TODO: check if works properly }) @@ -136,8 +143,8 @@ export default function(opts?: Partial) { let confirmAnswer: Promise - const peerOnCall = sessionStorage.getItem(options.session_calling_peer_key) - if (peerOnCall === call.peer) { + const callingPeer = sessionStorage.getItem(options.session_calling_peer_key) + if (callingPeer === call.peer) { confirmAnswer = Promise.resolve(true) } else { setCallingState(CallingState.Requesting); @@ -161,10 +168,13 @@ export default function(opts?: Partial) { return } + const onCallEnd = options.onCallStart() + const mouse = new Mouse() let callUI = new CallWindow() - const onCallEnd = () => { + const handleCallEnd = () => { + onCallEnd?.() mouse.remove(); callUI.remove(); setCallingState(CallingState.False); @@ -173,10 +183,10 @@ export default function(opts?: Partial) { log("initiateCallEnd") call.close() notifyCallEnd(); - onCallEnd(); + handleCallEnd(); } RequestLocalStream().then(lStream => { - dataConn.on("close", onCallEnd); // For what case? + dataConn.on("close", handleCallEnd); // For what case? //call.on('close', onClose); // Works from time to time (peerjs bug) const checkConnInterval = setInterval(() => { if (!dataConn.open) { @@ -184,7 +194,7 @@ export default function(opts?: Partial) { clearInterval(checkConnInterval); } if (!call.open) { - onCallEnd(); + handleCallEnd(); clearInterval(checkConnInterval); } }, 3000); @@ -205,7 +215,7 @@ export default function(opts?: Partial) { if (!data) { return } if (data === "call_end") { log('"call_end" received') - onCallEnd(); + handleCallEnd(); return; } if (data.name === 'string') { @@ -262,7 +272,7 @@ export default function(opts?: Partial) { }) .catch(e => { warn("Audio mediadevice request error:", e) - onCallEnd() + handleCallEnd() }); }).catch(); // in case of Confirm.remove() without any confirmation });