feat(tracker-assist): 3.4.11: onAgentConnect onCallStart + README update
This commit is contained in:
parent
5a201ea42a
commit
749d30f74e
4 changed files with 63 additions and 11 deletions
|
|
@ -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"
|
||||
}
|
||||
|
||||
```
|
||||
```
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
||||
|
|
|
|||
|
|
@ -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<Options>) {
|
|||
confirmStyle: {},
|
||||
session_calling_peer_key: "__openreplay_calling_peer",
|
||||
config: null,
|
||||
onCallStart: ()=>{},
|
||||
onAgentConnect: ()=>{},
|
||||
},
|
||||
opts,
|
||||
);
|
||||
|
|
@ -99,7 +103,10 @@ export default function(opts?: Partial<Options>) {
|
|||
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<Options>) {
|
|||
|
||||
|
||||
let confirmAnswer: Promise<boolean>
|
||||
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<Options>) {
|
|||
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<Options>) {
|
|||
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<Options>) {
|
|||
clearInterval(checkConnInterval);
|
||||
}
|
||||
if (!call.open) {
|
||||
onCallEnd();
|
||||
handleCallEnd();
|
||||
clearInterval(checkConnInterval);
|
||||
}
|
||||
}, 3000);
|
||||
|
|
@ -205,7 +215,7 @@ export default function(opts?: Partial<Options>) {
|
|||
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<Options>) {
|
|||
})
|
||||
.catch(e => {
|
||||
warn("Audio mediadevice request error:", e)
|
||||
onCallEnd()
|
||||
handleCallEnd()
|
||||
});
|
||||
}).catch(); // in case of Confirm.remove() without any confirmation
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue