@origonai/web-chat-sdk 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/origon-chat-sdk.js +456 -394
- package/dist/origon-chat-sdk.js.map +1 -1
- package/package.json +1 -1
- package/src/chat.js +17 -4
- package/src/http.js +125 -0
- package/src/index.js +8 -1
package/dist/origon-chat-sdk.js
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
import { fetchEventSource as
|
|
2
|
-
function
|
|
3
|
-
const e = Date.now(),
|
|
4
|
-
crypto.getRandomValues(
|
|
5
|
-
const
|
|
6
|
-
return `${
|
|
1
|
+
import { fetchEventSource as de } from "@microsoft/fetch-event-source";
|
|
2
|
+
function X() {
|
|
3
|
+
const e = Date.now(), n = new Uint8Array(16);
|
|
4
|
+
crypto.getRandomValues(n), n[0] = e >> 40 & 255, n[1] = e >> 32 & 255, n[2] = e >> 24 & 255, n[3] = e >> 16 & 255, n[4] = e >> 8 & 255, n[5] = e & 255, n[6] = n[6] & 15 | 112, n[8] = n[8] & 63 | 128;
|
|
5
|
+
const o = [...n].map((r) => r.toString(16).padStart(2, "0")).join("");
|
|
6
|
+
return `${o.slice(0, 8)}-${o.slice(8, 12)}-${o.slice(12, 16)}-${o.slice(
|
|
7
7
|
16,
|
|
8
8
|
20
|
|
9
|
-
)}-${
|
|
9
|
+
)}-${o.slice(20)}`;
|
|
10
10
|
}
|
|
11
|
-
function
|
|
11
|
+
function ue() {
|
|
12
12
|
if (localStorage.getItem("chatDeviceId"))
|
|
13
13
|
return localStorage.getItem("chatDeviceId");
|
|
14
|
-
const e =
|
|
14
|
+
const e = X();
|
|
15
15
|
return localStorage.setItem("chatDeviceId", e), e;
|
|
16
16
|
}
|
|
17
|
-
async function
|
|
18
|
-
return new Promise((
|
|
17
|
+
async function ge(e) {
|
|
18
|
+
return new Promise((n) => setTimeout(n, e));
|
|
19
19
|
}
|
|
20
|
-
function
|
|
21
|
-
let
|
|
20
|
+
function fe(e) {
|
|
21
|
+
let n;
|
|
22
22
|
try {
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
} catch (
|
|
23
|
+
const o = new URL(e);
|
|
24
|
+
n = `https://${o.hostname}${o.pathname}/sse`;
|
|
25
|
+
} catch (o) {
|
|
26
26
|
}
|
|
27
|
-
return
|
|
27
|
+
return n;
|
|
28
28
|
}
|
|
29
|
-
function
|
|
30
|
-
let
|
|
29
|
+
function pe(e) {
|
|
30
|
+
let n;
|
|
31
31
|
try {
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
} catch (
|
|
32
|
+
const o = new URL(e);
|
|
33
|
+
n = `wss://${o.hostname}${o.pathname}/wss`;
|
|
34
|
+
} catch (o) {
|
|
35
35
|
}
|
|
36
|
-
return
|
|
36
|
+
return n;
|
|
37
37
|
}
|
|
38
|
-
function
|
|
39
|
-
let
|
|
38
|
+
function me(e) {
|
|
39
|
+
let n;
|
|
40
40
|
try {
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
} catch (
|
|
41
|
+
const o = new URL(e);
|
|
42
|
+
n = `wss://${o.hostname}${o.pathname}/audio`;
|
|
43
|
+
} catch (o) {
|
|
44
44
|
}
|
|
45
|
-
return
|
|
45
|
+
return n;
|
|
46
46
|
}
|
|
47
|
-
const
|
|
47
|
+
const y = {
|
|
48
48
|
ASSISTANT: "assistant",
|
|
49
49
|
// this can be automated or LLM AI Agent response
|
|
50
50
|
USER: "user",
|
|
@@ -53,13 +53,13 @@ const w = {
|
|
|
53
53
|
// this is human supervisor (ex. Samespace Dock agent, or Resolve human agent)
|
|
54
54
|
SYSTEM: "system"
|
|
55
55
|
// this is system message, for ex "Agent joined" / "Agent left"
|
|
56
|
-
},
|
|
56
|
+
}, Z = 1e4, Se = 5e3, D = {
|
|
57
57
|
MESSAGE: "message",
|
|
58
58
|
TYPING: "typing",
|
|
59
59
|
TYPING_STOP: "typingOff",
|
|
60
60
|
END: "end"
|
|
61
61
|
};
|
|
62
|
-
function
|
|
62
|
+
function ke() {
|
|
63
63
|
return {
|
|
64
64
|
socket: null,
|
|
65
65
|
previouslyConnected: !1,
|
|
@@ -69,112 +69,112 @@ function fe() {
|
|
|
69
69
|
socketConnectionTimeout: null
|
|
70
70
|
};
|
|
71
71
|
}
|
|
72
|
-
let
|
|
73
|
-
function
|
|
74
|
-
|
|
72
|
+
let a = ke();
|
|
73
|
+
function M() {
|
|
74
|
+
a.pingInterval && (clearInterval(a.pingInterval), a.pingInterval = null);
|
|
75
75
|
}
|
|
76
|
-
function
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
},
|
|
76
|
+
function Ie() {
|
|
77
|
+
M(), a.pingInterval = setInterval(() => {
|
|
78
|
+
a.socket && a.socket.readyState === WebSocket.OPEN ? x({ type: "ping" }) : M();
|
|
79
|
+
}, Z);
|
|
80
80
|
}
|
|
81
|
-
function
|
|
82
|
-
|
|
81
|
+
function j() {
|
|
82
|
+
M(), a.socketDisconnectedTimeout && (clearTimeout(a.socketDisconnectedTimeout), a.socketDisconnectedTimeout = null), a.socketConnectionTimeout && (clearTimeout(a.socketConnectionTimeout), a.socketConnectionTimeout = null);
|
|
83
83
|
}
|
|
84
|
-
function
|
|
85
|
-
|
|
84
|
+
function ee() {
|
|
85
|
+
a.socketDisconnected = !1, O("socket");
|
|
86
86
|
}
|
|
87
|
-
function
|
|
88
|
-
|
|
87
|
+
function ne() {
|
|
88
|
+
a.socketDisconnected = !0, O("sse");
|
|
89
89
|
}
|
|
90
|
-
function
|
|
91
|
-
return new Promise((
|
|
92
|
-
if (
|
|
93
|
-
|
|
90
|
+
function he(e) {
|
|
91
|
+
return new Promise((n, o) => {
|
|
92
|
+
if (a.socket && (a.socket.readyState === WebSocket.CONNECTING || a.socket.readyState === WebSocket.OPEN)) {
|
|
93
|
+
n(a.socket.readyState === WebSocket.OPEN);
|
|
94
94
|
return;
|
|
95
95
|
}
|
|
96
|
-
const r =
|
|
96
|
+
const r = b();
|
|
97
97
|
if (!r || !r.endpoint) {
|
|
98
|
-
|
|
98
|
+
o(new Error("SDK not initialized. Please initialize SDK first."));
|
|
99
99
|
return;
|
|
100
100
|
}
|
|
101
|
-
const
|
|
102
|
-
if (!
|
|
103
|
-
|
|
101
|
+
const l = pe(r.endpoint);
|
|
102
|
+
if (!l) {
|
|
103
|
+
o(
|
|
104
104
|
new Error(
|
|
105
105
|
"Invalid endpoint while initializing SDK. Please check the endpoint and try again."
|
|
106
106
|
)
|
|
107
107
|
);
|
|
108
108
|
return;
|
|
109
109
|
}
|
|
110
|
-
const
|
|
111
|
-
externalId:
|
|
110
|
+
const d = P(), c = new URLSearchParams({
|
|
111
|
+
externalId: d
|
|
112
112
|
});
|
|
113
|
-
e.sessionId &&
|
|
114
|
-
const u = `${
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
},
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
},
|
|
121
|
-
|
|
122
|
-
},
|
|
123
|
-
|
|
113
|
+
e.sessionId && c.set("sessionId", e.sessionId), e.requestId && c.set("requestId", e.requestId), r.token && c.set("token", r.token);
|
|
114
|
+
const u = `${l}?${c.toString()}`;
|
|
115
|
+
a.socket = new WebSocket(u), a.socket.onopen = () => {
|
|
116
|
+
a.previouslyConnected = !0, ee(), x({ type: "ping" }), clearTimeout(a.socketConnectionTimeout), Ie(), n(!0);
|
|
117
|
+
}, a.socket.onmessage = (f) => {
|
|
118
|
+
const g = JSON.parse(f.data);
|
|
119
|
+
we(g);
|
|
120
|
+
}, a.socket.onerror = (f) => {
|
|
121
|
+
O("sse"), o(f);
|
|
122
|
+
}, a.socket.onclose = (f) => {
|
|
123
|
+
f.target === a.socket && (f.code === 1006 && (a.previouslyConnected ? ne() : h({
|
|
124
124
|
errorText: "Unable to establish connection",
|
|
125
125
|
done: !0,
|
|
126
126
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
127
|
-
}), clearTimeout(
|
|
128
|
-
},
|
|
129
|
-
|
|
127
|
+
}), clearTimeout(a.socketConnectionTimeout)), a.socket = null, j());
|
|
128
|
+
}, a.previouslyConnected || (a.socketConnectionTimeout = setTimeout(() => {
|
|
129
|
+
h({
|
|
130
130
|
errorText: "Unable to establish connection",
|
|
131
131
|
done: !0,
|
|
132
132
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
133
|
-
}),
|
|
134
|
-
},
|
|
133
|
+
}), o(new Error("Socket connection timed out"));
|
|
134
|
+
}, Se));
|
|
135
135
|
});
|
|
136
136
|
}
|
|
137
|
-
function
|
|
138
|
-
|
|
137
|
+
function x(e) {
|
|
138
|
+
a.socketDisconnected || !a.socket || a.socket.send(JSON.stringify({ ...e, eventId: e.eventId || X() }));
|
|
139
139
|
}
|
|
140
|
-
function
|
|
140
|
+
function we(e) {
|
|
141
141
|
switch (e.type) {
|
|
142
142
|
case "pong": {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
},
|
|
143
|
+
a.socketDisconnected && ee(), a.socketDisconnectedTimeout && clearTimeout(a.socketDisconnectedTimeout), a.socketDisconnectedTimeout = setTimeout(() => {
|
|
144
|
+
ne();
|
|
145
|
+
}, Z + 1e3);
|
|
146
146
|
break;
|
|
147
147
|
}
|
|
148
|
-
case
|
|
149
|
-
|
|
148
|
+
case D.TYPING: {
|
|
149
|
+
Q(!0);
|
|
150
150
|
break;
|
|
151
151
|
}
|
|
152
|
-
case
|
|
153
|
-
|
|
152
|
+
case D.TYPING_STOP: {
|
|
153
|
+
Q(!1);
|
|
154
154
|
break;
|
|
155
155
|
}
|
|
156
|
-
case
|
|
157
|
-
const { eventId:
|
|
158
|
-
|
|
159
|
-
...
|
|
156
|
+
case D.MESSAGE: {
|
|
157
|
+
const { eventId: n, data: o } = e;
|
|
158
|
+
n || h({
|
|
159
|
+
...o,
|
|
160
160
|
done: !0,
|
|
161
161
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
162
162
|
});
|
|
163
163
|
break;
|
|
164
164
|
}
|
|
165
|
-
case
|
|
166
|
-
|
|
165
|
+
case D.END: {
|
|
166
|
+
te();
|
|
167
167
|
break;
|
|
168
168
|
}
|
|
169
169
|
}
|
|
170
170
|
}
|
|
171
|
-
function
|
|
172
|
-
|
|
171
|
+
function te() {
|
|
172
|
+
a.socket && a.socket.close(1e3), a.previouslyConnected = !1, j(), a.socket = null, O("sse");
|
|
173
173
|
}
|
|
174
|
-
function
|
|
175
|
-
return
|
|
174
|
+
function Ce() {
|
|
175
|
+
return a.socket !== null && a.socket.readyState === WebSocket.OPEN && !a.socketDisconnected;
|
|
176
176
|
}
|
|
177
|
-
function
|
|
177
|
+
function oe(e = {}) {
|
|
178
178
|
return {
|
|
179
179
|
credentials: void 0,
|
|
180
180
|
authenticated: !1,
|
|
@@ -190,251 +190,310 @@ function X(e = {}) {
|
|
|
190
190
|
control: "agent"
|
|
191
191
|
};
|
|
192
192
|
}
|
|
193
|
-
let
|
|
194
|
-
function
|
|
195
|
-
|
|
193
|
+
let s = oe();
|
|
194
|
+
function ze(e) {
|
|
195
|
+
s.callbacks = { ...s.callbacks, ...e };
|
|
196
196
|
}
|
|
197
|
-
function
|
|
198
|
-
|
|
197
|
+
function Fe(e) {
|
|
198
|
+
s.credentials = e, e.token && (s.authenticated = !0);
|
|
199
199
|
}
|
|
200
|
-
function
|
|
201
|
-
return
|
|
200
|
+
function b() {
|
|
201
|
+
return s.credentials;
|
|
202
202
|
}
|
|
203
|
-
function
|
|
204
|
-
var
|
|
205
|
-
e && e !==
|
|
203
|
+
function Ee(e) {
|
|
204
|
+
var n, o;
|
|
205
|
+
e && e !== s.sessionId && (s.sessionId = e, (o = (n = s.callbacks).onSessionUpdate) == null || o.call(n, e));
|
|
206
206
|
}
|
|
207
|
-
async function
|
|
207
|
+
async function Ge(e = {}) {
|
|
208
208
|
try {
|
|
209
|
-
let
|
|
210
|
-
|
|
211
|
-
let
|
|
209
|
+
let n = null;
|
|
210
|
+
s.authenticated ? n = s.configData : (n = await Te(s.credentials), s.authenticated = !0, s.configData = n);
|
|
211
|
+
let o = [], r = "agent";
|
|
212
212
|
if (e.sessionId) {
|
|
213
|
-
const
|
|
214
|
-
|
|
213
|
+
const d = await ve(e.sessionId);
|
|
214
|
+
o = d.messages, r = d.control || "agent";
|
|
215
215
|
}
|
|
216
|
-
const
|
|
217
|
-
return
|
|
218
|
-
|
|
219
|
-
)}?${
|
|
216
|
+
const l = new URLSearchParams();
|
|
217
|
+
return s.credentials.token || l.set("externalId", P()), s.sseUrl = `${fe(
|
|
218
|
+
s.credentials.endpoint
|
|
219
|
+
)}?${l.toString()}`, s.sessionId = e.sessionId, s.messages = o, s.control = r, r === "human" && ye({ text: "", html: "" }).catch(() => {
|
|
220
220
|
}), {
|
|
221
|
-
sessionId:
|
|
222
|
-
messages:
|
|
221
|
+
sessionId: s.sessionId,
|
|
222
|
+
messages: o,
|
|
223
223
|
control: r,
|
|
224
|
-
configData:
|
|
224
|
+
configData: n
|
|
225
225
|
};
|
|
226
|
-
} catch (
|
|
227
|
-
throw
|
|
226
|
+
} catch (n) {
|
|
227
|
+
throw se(), n;
|
|
228
228
|
}
|
|
229
229
|
}
|
|
230
|
-
function
|
|
231
|
-
|
|
230
|
+
function Je() {
|
|
231
|
+
se();
|
|
232
232
|
}
|
|
233
|
-
function
|
|
234
|
-
|
|
235
|
-
const { callbacks: e, credentials:
|
|
236
|
-
|
|
233
|
+
function se() {
|
|
234
|
+
s.abortController && s.abortController.abort(), te();
|
|
235
|
+
const { callbacks: e, credentials: n } = s;
|
|
236
|
+
s = oe(e), s.credentials = n;
|
|
237
237
|
}
|
|
238
238
|
function P() {
|
|
239
239
|
var e;
|
|
240
|
-
return (e =
|
|
240
|
+
return (e = s.credentials) != null && e.externalId ? s.credentials.externalId : ue();
|
|
241
241
|
}
|
|
242
|
-
function
|
|
243
|
-
var
|
|
244
|
-
|
|
242
|
+
function h(e) {
|
|
243
|
+
var n, o;
|
|
244
|
+
s.messages = [...s.messages, e], (o = (n = s.callbacks).onMessageAdd) == null || o.call(n, e);
|
|
245
245
|
}
|
|
246
|
-
function
|
|
247
|
-
var
|
|
248
|
-
(
|
|
246
|
+
function Q(e) {
|
|
247
|
+
var n, o;
|
|
248
|
+
(o = (n = s.callbacks).onTyping) == null || o.call(n, e);
|
|
249
249
|
}
|
|
250
|
-
function
|
|
251
|
-
var
|
|
252
|
-
|
|
250
|
+
function O(e) {
|
|
251
|
+
var n, o;
|
|
252
|
+
s.transport = e, (o = (n = s.callbacks).onTransportUpdate) == null || o.call(n, e);
|
|
253
253
|
}
|
|
254
|
-
function
|
|
255
|
-
return new Promise((
|
|
254
|
+
function ye({ text: e, html: n, context: o, attachments: r }) {
|
|
255
|
+
return new Promise((l, d) => {
|
|
256
256
|
(async () => {
|
|
257
|
-
var
|
|
257
|
+
var c, u, f;
|
|
258
258
|
try {
|
|
259
|
-
const
|
|
260
|
-
if (!
|
|
261
|
-
const
|
|
262
|
-
role:
|
|
259
|
+
const g = !e && !n;
|
|
260
|
+
if (!g) {
|
|
261
|
+
const p = {
|
|
262
|
+
role: y.USER,
|
|
263
263
|
text: e,
|
|
264
|
-
html:
|
|
265
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
264
|
+
html: n,
|
|
265
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
266
|
+
attachments: r
|
|
266
267
|
};
|
|
267
|
-
|
|
268
|
+
h(p), await ge(200);
|
|
268
269
|
}
|
|
269
|
-
if (
|
|
270
|
-
|
|
270
|
+
if (s.transport === "socket" && Ce()) {
|
|
271
|
+
x({
|
|
271
272
|
type: "message",
|
|
272
273
|
data: {
|
|
273
274
|
text: e,
|
|
274
|
-
html:
|
|
275
|
+
html: n
|
|
275
276
|
}
|
|
276
|
-
}),
|
|
277
|
+
}), l(s.sessionId);
|
|
277
278
|
return;
|
|
278
279
|
}
|
|
279
|
-
if (
|
|
280
|
-
const
|
|
281
|
-
role:
|
|
280
|
+
if (s.control === "agent") {
|
|
281
|
+
const p = {
|
|
282
|
+
role: y.ASSISTANT,
|
|
282
283
|
text: "",
|
|
283
284
|
loading: !0
|
|
284
285
|
};
|
|
285
|
-
|
|
286
|
+
h(p);
|
|
286
287
|
}
|
|
287
|
-
const
|
|
288
|
-
|
|
288
|
+
const I = new URL(s.sseUrl);
|
|
289
|
+
s.sessionId && I.searchParams.set("sessionId", s.sessionId), s.requestId && I.searchParams.set("requestId", s.requestId), s.lastStreamId = void 0, s.abortController = new AbortController();
|
|
289
290
|
const C = {
|
|
290
291
|
"Content-Type": "application/json"
|
|
291
292
|
};
|
|
292
|
-
(
|
|
293
|
+
(c = s.credentials) != null && c.token && (C.Authorization = `Bearer ${s.credentials.token}`), await de(I.toString(), {
|
|
293
294
|
method: "POST",
|
|
294
295
|
headers: C,
|
|
295
|
-
body:
|
|
296
|
+
body: g ? void 0 : JSON.stringify({
|
|
296
297
|
message: e,
|
|
297
|
-
html:
|
|
298
|
-
context:
|
|
298
|
+
html: n,
|
|
299
|
+
context: o,
|
|
300
|
+
attachments: r
|
|
299
301
|
}),
|
|
300
|
-
signal:
|
|
302
|
+
signal: s.abortController.signal,
|
|
301
303
|
openWhenHidden: !0,
|
|
302
|
-
onopen: async (
|
|
303
|
-
if (!
|
|
304
|
+
onopen: async (p) => {
|
|
305
|
+
if (!p.ok)
|
|
304
306
|
throw new Error("Failed to send message");
|
|
305
307
|
},
|
|
306
|
-
onmessage: (
|
|
307
|
-
var
|
|
308
|
-
const
|
|
309
|
-
if (
|
|
310
|
-
|
|
311
|
-
else if (
|
|
312
|
-
|
|
313
|
-
sessionId:
|
|
314
|
-
requestId:
|
|
308
|
+
onmessage: (p) => {
|
|
309
|
+
var $, A, q, L, z, F, G, J, W, _, K, H, V, B, Y;
|
|
310
|
+
const i = JSON.parse(p.data);
|
|
311
|
+
if (p.event === "connected")
|
|
312
|
+
s.sessionId = i.sessionId, s.requestId = i.requestId, i.control && (s.control = i.control, (A = ($ = s.callbacks).onControlUpdate) == null || A.call($, i.control));
|
|
313
|
+
else if (p.event === "upgrade_to_websocket")
|
|
314
|
+
he({
|
|
315
|
+
sessionId: s.sessionId,
|
|
316
|
+
requestId: i.requestId
|
|
315
317
|
});
|
|
316
|
-
else if (
|
|
317
|
-
|
|
318
|
-
else if (
|
|
319
|
-
const
|
|
320
|
-
...
|
|
318
|
+
else if (p.event === "update")
|
|
319
|
+
i.control && (s.control = i.control, (L = (q = s.callbacks).onControlUpdate) == null || L.call(q, i.control));
|
|
320
|
+
else if (i.error) {
|
|
321
|
+
const m = i.error && typeof i.error == "string" ? i.error : "Failed to connect to the system", k = s.messages.length - 1, S = {
|
|
322
|
+
...s.messages[k],
|
|
321
323
|
loading: !1,
|
|
322
|
-
errorText:
|
|
324
|
+
errorText: m
|
|
323
325
|
};
|
|
324
|
-
|
|
325
|
-
(
|
|
326
|
-
), (
|
|
327
|
-
} else if (
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
326
|
+
s.messages = s.messages.map(
|
|
327
|
+
(v, le) => le === k ? S : v
|
|
328
|
+
), (F = (z = s.callbacks).onMessageUpdate) == null || F.call(z, k, S), d(new Error(m));
|
|
329
|
+
} else if (p.event === "done") {
|
|
330
|
+
const m = s.messages.length - 1, E = {
|
|
331
|
+
...s.messages[m],
|
|
332
|
+
loading: !1,
|
|
333
|
+
done: !0
|
|
334
|
+
};
|
|
335
|
+
s.messages = s.messages.map(
|
|
336
|
+
(S, v) => v === m ? E : S
|
|
337
|
+
), (J = (G = s.callbacks).onMessageUpdate) == null || J.call(G, m, E), l(s.sessionId);
|
|
338
|
+
} else if (i.message !== void 0) {
|
|
339
|
+
if (i.role === y.SUPERVISOR) {
|
|
340
|
+
const S = {
|
|
341
|
+
role: y.SUPERVISOR,
|
|
342
|
+
text: i.message,
|
|
343
|
+
sources: i.sources,
|
|
335
344
|
done: !0
|
|
336
345
|
};
|
|
337
|
-
|
|
346
|
+
h(S), l(s.sessionId), s.sessionId = (W = i.sessionId) != null ? W : s.sessionId, s.requestId = (_ = i.requestId) != null ? _ : s.requestId;
|
|
338
347
|
return;
|
|
339
348
|
}
|
|
340
|
-
if (
|
|
341
|
-
if (
|
|
342
|
-
|
|
343
|
-
else if (
|
|
344
|
-
|
|
345
|
-
const
|
|
346
|
-
role:
|
|
349
|
+
if (i.streamId !== void 0) {
|
|
350
|
+
if (s.lastStreamId === void 0)
|
|
351
|
+
s.lastStreamId = i.streamId;
|
|
352
|
+
else if (i.streamId !== s.lastStreamId) {
|
|
353
|
+
s.lastStreamId = i.streamId;
|
|
354
|
+
const S = {
|
|
355
|
+
role: y.ASSISTANT,
|
|
347
356
|
text: "",
|
|
348
357
|
loading: !0
|
|
349
358
|
};
|
|
350
|
-
|
|
359
|
+
h(S);
|
|
351
360
|
}
|
|
352
361
|
}
|
|
353
|
-
const
|
|
354
|
-
...
|
|
362
|
+
const m = s.messages.length - 1, k = s.messages[m], E = {
|
|
363
|
+
...k,
|
|
355
364
|
loading: !1,
|
|
356
|
-
text: (
|
|
357
|
-
sources:
|
|
358
|
-
done: (
|
|
365
|
+
text: (k.text || "") + i.message,
|
|
366
|
+
sources: i.sources,
|
|
367
|
+
done: (K = i.done) != null ? K : k.done
|
|
359
368
|
};
|
|
360
|
-
|
|
361
|
-
(
|
|
362
|
-
), (
|
|
369
|
+
s.messages = s.messages.map(
|
|
370
|
+
(S, v) => v === m ? E : S
|
|
371
|
+
), (V = (H = s.callbacks).onMessageUpdate) == null || V.call(H, m, E), i.done, s.sessionId = (B = i.sessionId) != null ? B : s.sessionId, s.requestId = (Y = i.requestId) != null ? Y : s.requestId;
|
|
363
372
|
}
|
|
364
373
|
},
|
|
365
|
-
onerror: (
|
|
366
|
-
throw
|
|
374
|
+
onerror: (p) => {
|
|
375
|
+
throw p;
|
|
367
376
|
},
|
|
368
377
|
openWhenHidden: !0
|
|
369
378
|
});
|
|
370
|
-
} catch (
|
|
371
|
-
const
|
|
372
|
-
...
|
|
379
|
+
} catch (g) {
|
|
380
|
+
const I = "Failed to connect to the system", C = s.messages.length - 1, p = s.messages[C], i = {
|
|
381
|
+
...p,
|
|
373
382
|
loading: !1,
|
|
374
|
-
errorText:
|
|
383
|
+
errorText: p.done ? void 0 : g.message || I,
|
|
375
384
|
done: !0
|
|
376
385
|
};
|
|
377
|
-
|
|
378
|
-
(
|
|
379
|
-
), (
|
|
386
|
+
s.messages = s.messages.map(
|
|
387
|
+
($, A) => A === C ? i : $
|
|
388
|
+
), (f = (u = s.callbacks).onMessageUpdate) == null || f.call(u, C, i), d(g);
|
|
380
389
|
}
|
|
381
390
|
})();
|
|
382
391
|
});
|
|
383
392
|
}
|
|
384
|
-
const
|
|
385
|
-
async function
|
|
386
|
-
const { endpoint:
|
|
393
|
+
const be = "Something went wrong initializing the chat", N = "Chat SDK not initialized";
|
|
394
|
+
async function Te(e) {
|
|
395
|
+
const { endpoint: n } = e, o = `${n}/config`, r = await fetch(o, {
|
|
387
396
|
method: "GET",
|
|
388
397
|
headers: {
|
|
389
398
|
"Content-Type": "application/json"
|
|
390
399
|
}
|
|
391
400
|
});
|
|
392
401
|
if (!r.ok) {
|
|
393
|
-
const
|
|
394
|
-
throw new Error((
|
|
402
|
+
const c = await r.json();
|
|
403
|
+
throw new Error((c == null ? void 0 : c.error) || be);
|
|
395
404
|
}
|
|
396
405
|
return (await r.json()).data;
|
|
397
406
|
}
|
|
398
|
-
async function
|
|
407
|
+
async function We() {
|
|
399
408
|
const e = new URLSearchParams({
|
|
400
409
|
externalId: P()
|
|
401
|
-
}),
|
|
402
|
-
if (!
|
|
410
|
+
}), n = await re(`/sessions?${e.toString()}`, "GET");
|
|
411
|
+
if (!n.ok)
|
|
403
412
|
throw new Error("Unable to load history, please try again later");
|
|
404
|
-
return
|
|
413
|
+
return n.json();
|
|
405
414
|
}
|
|
406
|
-
async function
|
|
407
|
-
var
|
|
408
|
-
const
|
|
415
|
+
async function ve(e) {
|
|
416
|
+
var c;
|
|
417
|
+
const n = new URLSearchParams({
|
|
409
418
|
sessionId: e
|
|
410
|
-
}),
|
|
411
|
-
if (!
|
|
419
|
+
}), o = await re(`/session?${n.toString()}`, "GET");
|
|
420
|
+
if (!o.ok)
|
|
412
421
|
throw new Error("Unable to load messages, please try again later");
|
|
413
|
-
const r = await
|
|
422
|
+
const r = await o.json(), l = r == null ? void 0 : r.control, d = ((c = r == null ? void 0 : r.history) != null ? c : []).map((u) => ({
|
|
414
423
|
id: u.id,
|
|
415
424
|
text: u.text,
|
|
416
|
-
role: u.youtubeVideo ?
|
|
425
|
+
role: u.youtubeVideo ? y.ASSISTANT : u.role,
|
|
417
426
|
timestamp: u.timestamp,
|
|
418
427
|
video: u.youtubeVideo,
|
|
419
428
|
channel: u.channel,
|
|
420
429
|
done: !0
|
|
421
430
|
}));
|
|
422
|
-
return { control:
|
|
431
|
+
return { control: l, messages: d };
|
|
423
432
|
}
|
|
424
|
-
|
|
425
|
-
const r =
|
|
426
|
-
if (!
|
|
427
|
-
|
|
428
|
-
|
|
433
|
+
function _e(e, n, o) {
|
|
434
|
+
const r = b(), { endpoint: l, token: d } = r || {};
|
|
435
|
+
if (!l) {
|
|
436
|
+
const g = new Error(N);
|
|
437
|
+
return o && o(g, null), null;
|
|
438
|
+
}
|
|
439
|
+
const c = new XMLHttpRequest(), u = new FormData();
|
|
440
|
+
u.append("file", e);
|
|
441
|
+
const f = `${l}/upload`;
|
|
442
|
+
return c.open("POST", f), d && c.setRequestHeader("Authorization", `Bearer ${d}`), n && c.upload.addEventListener("progress", (g) => {
|
|
443
|
+
if (g.lengthComputable) {
|
|
444
|
+
const I = g.loaded / g.total * 100;
|
|
445
|
+
n(I, g.loaded, g.total);
|
|
446
|
+
}
|
|
447
|
+
}), c.addEventListener("load", () => {
|
|
448
|
+
if (c.status >= 200 && c.status < 300)
|
|
449
|
+
try {
|
|
450
|
+
const g = JSON.parse(c.responseText);
|
|
451
|
+
o && o(null, g);
|
|
452
|
+
} catch (g) {
|
|
453
|
+
o && o(new Error("Failed to parse response"), null);
|
|
454
|
+
}
|
|
455
|
+
else
|
|
456
|
+
o && o(new Error(`Upload failed with status ${c.status}`), null);
|
|
457
|
+
}), c.addEventListener("error", () => {
|
|
458
|
+
o && o(new Error("Network error during upload"), null);
|
|
459
|
+
}), c.addEventListener("abort", () => {
|
|
460
|
+
o && o(new Error("Upload aborted"), null);
|
|
461
|
+
}), c.send(u), c;
|
|
462
|
+
}
|
|
463
|
+
async function Ke(e) {
|
|
464
|
+
const n = b(), { endpoint: o, token: r } = n || {};
|
|
465
|
+
if (!o)
|
|
466
|
+
throw new Error(N);
|
|
467
|
+
const l = `${o}/delete/${e}`, d = {};
|
|
468
|
+
r && (d.Authorization = `Bearer ${r}`);
|
|
469
|
+
const c = await fetch(l, {
|
|
470
|
+
method: "DELETE",
|
|
471
|
+
headers: d
|
|
472
|
+
});
|
|
473
|
+
if (!c.ok)
|
|
474
|
+
throw new Error(`Delete failed with status ${c.status}`);
|
|
475
|
+
return { success: !0 };
|
|
476
|
+
}
|
|
477
|
+
function He(e) {
|
|
478
|
+
const n = b(), { endpoint: o } = n || {};
|
|
479
|
+
if (!o)
|
|
480
|
+
throw new Error(N);
|
|
481
|
+
return `${o}/upload/${e}`;
|
|
482
|
+
}
|
|
483
|
+
async function re(e, n = "GET", o = null) {
|
|
484
|
+
const r = b(), { endpoint: l, token: d } = r || {};
|
|
485
|
+
if (!l)
|
|
486
|
+
throw new Error(N);
|
|
487
|
+
const c = `${l}${e}`, u = {
|
|
429
488
|
"Content-Type": "application/json"
|
|
430
489
|
};
|
|
431
|
-
return
|
|
490
|
+
return d && (u.Authorization = `Bearer ${d}`), fetch(c, {
|
|
432
491
|
headers: u,
|
|
433
|
-
method:
|
|
434
|
-
body:
|
|
492
|
+
method: n,
|
|
493
|
+
body: o ? JSON.stringify(o) : null
|
|
435
494
|
});
|
|
436
495
|
}
|
|
437
|
-
function
|
|
496
|
+
function ae(e = {}) {
|
|
438
497
|
return {
|
|
439
498
|
sessionId: void 0,
|
|
440
499
|
socket: null,
|
|
@@ -452,52 +511,52 @@ function te(e = {}) {
|
|
|
452
511
|
pendingRemoteIceCandidates: []
|
|
453
512
|
};
|
|
454
513
|
}
|
|
455
|
-
let
|
|
456
|
-
const
|
|
514
|
+
let t = ae();
|
|
515
|
+
const $e = {
|
|
457
516
|
iceServers: [{ urls: "stun:stun.l.google.com:19302" }, { urls: "stun:stun1.l.google.com:19302" }]
|
|
458
517
|
};
|
|
459
|
-
function
|
|
460
|
-
|
|
518
|
+
function Ve(e) {
|
|
519
|
+
t.callbacks = { ...t.callbacks, ...e };
|
|
461
520
|
}
|
|
462
|
-
function
|
|
463
|
-
|
|
464
|
-
const e =
|
|
465
|
-
|
|
521
|
+
function ce() {
|
|
522
|
+
t.peerConnection && (t.peerConnection.close(), t.peerConnection = null), t.localStream && (t.localStream.getTracks().forEach((n) => n.stop()), t.localStream = null), t.remoteStream && (t.remoteStream = null), t.remoteAudio && (t.remoteAudio.srcObject = null, t.remoteAudio.parentNode && t.remoteAudio.parentNode.removeChild(t.remoteAudio), t.remoteAudio = null), t.socket && (t.socket.close(), t.socket = null), U();
|
|
523
|
+
const e = t.callbacks;
|
|
524
|
+
t = ae(e);
|
|
466
525
|
}
|
|
467
|
-
function
|
|
468
|
-
var
|
|
469
|
-
|
|
526
|
+
function w(e) {
|
|
527
|
+
var n, o;
|
|
528
|
+
t.callStatus = e, (o = (n = t.callbacks).onCallStatus) == null || o.call(n, e);
|
|
470
529
|
}
|
|
471
|
-
function
|
|
472
|
-
var
|
|
473
|
-
(
|
|
530
|
+
function R(e) {
|
|
531
|
+
var n, o;
|
|
532
|
+
(o = (n = t.callbacks).onCallError) == null || o.call(n, e);
|
|
474
533
|
}
|
|
475
|
-
function
|
|
476
|
-
|
|
534
|
+
function U() {
|
|
535
|
+
t.pingInterval && (clearInterval(t.pingInterval), t.pingInterval = null);
|
|
477
536
|
}
|
|
478
|
-
function
|
|
479
|
-
|
|
480
|
-
if (
|
|
481
|
-
|
|
537
|
+
function Ae() {
|
|
538
|
+
U(), t.pingInterval = setInterval(() => {
|
|
539
|
+
if (t.socket && t.socket.readyState === WebSocket.OPEN) {
|
|
540
|
+
t.pingCount++;
|
|
482
541
|
const e = {
|
|
483
542
|
type: "ping",
|
|
484
543
|
timestamp: Date.now(),
|
|
485
|
-
count:
|
|
544
|
+
count: t.pingCount
|
|
486
545
|
};
|
|
487
|
-
|
|
546
|
+
T(e);
|
|
488
547
|
} else
|
|
489
|
-
|
|
548
|
+
U();
|
|
490
549
|
}, 1e4);
|
|
491
550
|
}
|
|
492
|
-
function
|
|
493
|
-
|
|
551
|
+
function De() {
|
|
552
|
+
t.lastPongTime = Date.now();
|
|
494
553
|
}
|
|
495
|
-
function
|
|
496
|
-
|
|
554
|
+
function T(e) {
|
|
555
|
+
t.socket && t.socket.readyState === WebSocket.OPEN && t.socket.send(JSON.stringify(e));
|
|
497
556
|
}
|
|
498
|
-
async function
|
|
557
|
+
async function Re() {
|
|
499
558
|
try {
|
|
500
|
-
|
|
559
|
+
t.localStream = await navigator.mediaDevices.getUserMedia({
|
|
501
560
|
audio: !0,
|
|
502
561
|
video: !1
|
|
503
562
|
});
|
|
@@ -505,233 +564,236 @@ async function De() {
|
|
|
505
564
|
throw e;
|
|
506
565
|
}
|
|
507
566
|
}
|
|
508
|
-
function
|
|
509
|
-
|
|
567
|
+
function Ue() {
|
|
568
|
+
t.peerConnection = new RTCPeerConnection($e), t.peerConnection.onicecandidate = (e) => {
|
|
510
569
|
if (e.candidate) {
|
|
511
|
-
const
|
|
512
|
-
|
|
570
|
+
const n = JSON.stringify(e.candidate);
|
|
571
|
+
t.peerConnection && t.peerConnection.remoteDescription ? T({
|
|
513
572
|
type: "ice",
|
|
514
573
|
data: {
|
|
515
|
-
candidate:
|
|
574
|
+
candidate: n
|
|
516
575
|
}
|
|
517
|
-
}) :
|
|
576
|
+
}) : t.localIceCandidates.push(n);
|
|
518
577
|
}
|
|
519
|
-
},
|
|
520
|
-
|
|
521
|
-
}).catch((
|
|
578
|
+
}, t.peerConnection.ontrack = (e) => {
|
|
579
|
+
t.remoteStream = e.streams[0], t.remoteAudio || (t.remoteAudio = document.createElement("audio"), t.remoteAudio.autoplay = !0, t.remoteAudio.controls = !1, document.body.appendChild(t.remoteAudio)), t.remoteAudio.srcObject = t.remoteStream, t.remoteAudio.play().then(() => {
|
|
580
|
+
}).catch((n) => {
|
|
522
581
|
});
|
|
523
|
-
},
|
|
524
|
-
const e =
|
|
525
|
-
e === "connected" ?
|
|
526
|
-
},
|
|
582
|
+
}, t.peerConnection.onconnectionstatechange = () => {
|
|
583
|
+
const e = t.peerConnection.connectionState;
|
|
584
|
+
e === "connected" ? w("connected") : (e === "disconnected" || e === "closed") && (w("disconnected"), ie());
|
|
585
|
+
}, t.peerConnection.oniceconnectionstatechange = () => {
|
|
527
586
|
};
|
|
528
587
|
}
|
|
529
|
-
function
|
|
530
|
-
return new Promise((
|
|
531
|
-
if (
|
|
532
|
-
t
|
|
588
|
+
function Pe(e) {
|
|
589
|
+
return new Promise((n, o) => {
|
|
590
|
+
if (t.socket && (t.socket.readyState === WebSocket.CONNECTING || t.socket.readyState === WebSocket.OPEN)) {
|
|
591
|
+
n(t.socket.readyState === WebSocket.OPEN);
|
|
533
592
|
return;
|
|
534
593
|
}
|
|
535
|
-
const r =
|
|
594
|
+
const r = b();
|
|
536
595
|
if (!r || !r.endpoint) {
|
|
537
|
-
|
|
596
|
+
o(new Error("SDK not initialized. Please initialize SDK first."));
|
|
538
597
|
return;
|
|
539
598
|
}
|
|
540
|
-
const
|
|
541
|
-
if (!
|
|
542
|
-
|
|
599
|
+
const l = me(r.endpoint);
|
|
600
|
+
if (!l) {
|
|
601
|
+
o(
|
|
543
602
|
new Error(
|
|
544
603
|
"Invalid endpoint while initializing SDK. Please check the endpoint and try again."
|
|
545
604
|
)
|
|
546
605
|
);
|
|
547
606
|
return;
|
|
548
607
|
}
|
|
549
|
-
const
|
|
550
|
-
externalId:
|
|
608
|
+
const d = P(), c = new URLSearchParams({
|
|
609
|
+
externalId: d
|
|
551
610
|
});
|
|
552
|
-
e.sessionId &&
|
|
553
|
-
const u = `${
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
},
|
|
557
|
-
const
|
|
558
|
-
|
|
559
|
-
},
|
|
560
|
-
|
|
561
|
-
},
|
|
562
|
-
|
|
611
|
+
e.sessionId && c.set("sessionId", e.sessionId), r.token && c.set("token", r.token);
|
|
612
|
+
const u = `${l}?${c.toString()}`;
|
|
613
|
+
t.socket = new WebSocket(u), t.socket.onopen = (f) => {
|
|
614
|
+
Ae(), n(!0);
|
|
615
|
+
}, t.socket.onmessage = (f) => {
|
|
616
|
+
const g = JSON.parse(f.data);
|
|
617
|
+
Oe(g);
|
|
618
|
+
}, t.socket.onerror = (f) => {
|
|
619
|
+
w("error"), R(f.message || "Unable to connect voice"), o(f);
|
|
620
|
+
}, t.socket.onclose = (f) => {
|
|
621
|
+
U();
|
|
563
622
|
};
|
|
564
623
|
});
|
|
565
624
|
}
|
|
566
|
-
function
|
|
625
|
+
function Oe(e) {
|
|
567
626
|
switch (e.type) {
|
|
568
627
|
case "pong":
|
|
569
|
-
|
|
628
|
+
De();
|
|
570
629
|
break;
|
|
571
630
|
case "answer":
|
|
572
|
-
|
|
631
|
+
Me(e.data);
|
|
573
632
|
break;
|
|
574
633
|
case "connected":
|
|
575
|
-
|
|
634
|
+
Ne(e.data);
|
|
576
635
|
break;
|
|
577
636
|
case "ice":
|
|
578
|
-
|
|
637
|
+
xe(e.data);
|
|
579
638
|
break;
|
|
580
639
|
case "renegotiationOffer":
|
|
581
|
-
|
|
640
|
+
qe(e.data);
|
|
582
641
|
break;
|
|
583
642
|
case "end":
|
|
584
|
-
|
|
643
|
+
ie();
|
|
585
644
|
break;
|
|
586
645
|
case "error":
|
|
587
|
-
|
|
646
|
+
w("error"), R(e.error || "Unable to connect voice");
|
|
588
647
|
break;
|
|
589
648
|
default:
|
|
590
649
|
break;
|
|
591
650
|
}
|
|
592
651
|
}
|
|
593
|
-
function
|
|
594
|
-
|
|
652
|
+
function Ne(e) {
|
|
653
|
+
t.sessionId = e.sessionId, Ee(e.sessionId);
|
|
595
654
|
}
|
|
596
|
-
async function
|
|
655
|
+
async function Me(e) {
|
|
597
656
|
try {
|
|
598
|
-
if (
|
|
599
|
-
const
|
|
657
|
+
if (t.peerConnection) {
|
|
658
|
+
const n = new RTCSessionDescription({
|
|
600
659
|
type: "answer",
|
|
601
660
|
sdp: e.sdp
|
|
602
661
|
});
|
|
603
|
-
await
|
|
604
|
-
for (const
|
|
605
|
-
|
|
662
|
+
await t.peerConnection.setRemoteDescription(n);
|
|
663
|
+
for (const o of t.localIceCandidates)
|
|
664
|
+
T({
|
|
606
665
|
type: "ice",
|
|
607
666
|
data: {
|
|
608
|
-
candidate:
|
|
667
|
+
candidate: o
|
|
609
668
|
}
|
|
610
669
|
});
|
|
611
|
-
|
|
612
|
-
for (const
|
|
670
|
+
t.localIceCandidates = [];
|
|
671
|
+
for (const o of t.pendingRemoteIceCandidates)
|
|
613
672
|
try {
|
|
614
|
-
const r = new RTCIceCandidate(JSON.parse(
|
|
615
|
-
await
|
|
673
|
+
const r = new RTCIceCandidate(JSON.parse(o));
|
|
674
|
+
await t.peerConnection.addIceCandidate(r);
|
|
616
675
|
} catch (r) {
|
|
617
676
|
}
|
|
618
|
-
|
|
677
|
+
t.pendingRemoteIceCandidates = [];
|
|
619
678
|
}
|
|
620
|
-
} catch (
|
|
679
|
+
} catch (n) {
|
|
621
680
|
}
|
|
622
681
|
}
|
|
623
|
-
async function
|
|
682
|
+
async function xe(e) {
|
|
624
683
|
try {
|
|
625
|
-
if (
|
|
626
|
-
if (!
|
|
627
|
-
|
|
684
|
+
if (t.peerConnection) {
|
|
685
|
+
if (!t.peerConnection.remoteDescription) {
|
|
686
|
+
t.pendingRemoteIceCandidates.push(e.candidate);
|
|
628
687
|
return;
|
|
629
688
|
}
|
|
630
|
-
const
|
|
631
|
-
await
|
|
689
|
+
const n = new RTCIceCandidate(JSON.parse(e.candidate));
|
|
690
|
+
await t.peerConnection.addIceCandidate(n);
|
|
632
691
|
}
|
|
633
|
-
} catch (
|
|
692
|
+
} catch (n) {
|
|
634
693
|
}
|
|
635
694
|
}
|
|
636
|
-
async function
|
|
695
|
+
async function qe(e) {
|
|
637
696
|
try {
|
|
638
|
-
if (
|
|
639
|
-
const
|
|
697
|
+
if (t.peerConnection) {
|
|
698
|
+
const n = new RTCSessionDescription({
|
|
640
699
|
type: "offer",
|
|
641
700
|
sdp: e.sdp
|
|
642
701
|
});
|
|
643
|
-
await
|
|
644
|
-
const
|
|
645
|
-
await
|
|
702
|
+
await t.peerConnection.setRemoteDescription(n);
|
|
703
|
+
const o = await t.peerConnection.createAnswer();
|
|
704
|
+
await t.peerConnection.setLocalDescription(o), T({
|
|
646
705
|
type: "renegotiationAnswer",
|
|
647
706
|
data: {
|
|
648
|
-
sdp:
|
|
707
|
+
sdp: o.sdp
|
|
649
708
|
}
|
|
650
709
|
});
|
|
651
710
|
}
|
|
652
|
-
} catch (
|
|
711
|
+
} catch (n) {
|
|
653
712
|
}
|
|
654
713
|
}
|
|
655
|
-
async function
|
|
714
|
+
async function Be(e = {}) {
|
|
656
715
|
try {
|
|
657
|
-
if (
|
|
716
|
+
if (t.callStatus === "connecting" || t.callStatus === "connected")
|
|
658
717
|
return;
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
}), await
|
|
662
|
-
const
|
|
663
|
-
await
|
|
718
|
+
w("connecting"), R(null), t.sessionId = e.sessionId, await Re(), Ue(), t.localStream.getTracks().forEach((o) => {
|
|
719
|
+
t.peerConnection.addTrack(o, t.localStream);
|
|
720
|
+
}), await Pe(e);
|
|
721
|
+
const n = await t.peerConnection.createOffer();
|
|
722
|
+
await t.peerConnection.setLocalDescription(n), T({
|
|
664
723
|
type: "offer",
|
|
665
724
|
data: {
|
|
666
|
-
sdp:
|
|
725
|
+
sdp: n.sdp
|
|
667
726
|
}
|
|
668
727
|
});
|
|
669
|
-
} catch (
|
|
670
|
-
|
|
728
|
+
} catch (n) {
|
|
729
|
+
w("error"), R(n.message || "Unable to connect voice"), ce();
|
|
671
730
|
}
|
|
672
731
|
}
|
|
673
|
-
function
|
|
674
|
-
|
|
732
|
+
function ie() {
|
|
733
|
+
T({
|
|
675
734
|
type: "end"
|
|
676
|
-
}),
|
|
735
|
+
}), t.socket && (t.socket.close(), t.socket = null), w("disconnected"), t.peerConnection && (t.peerConnection.close(), t.peerConnection = null), t.localStream && (t.localStream.getTracks().forEach((e) => e.stop()), t.localStream = null), ce();
|
|
677
736
|
}
|
|
678
|
-
function
|
|
679
|
-
if (
|
|
680
|
-
const e =
|
|
737
|
+
function Ye() {
|
|
738
|
+
if (t.localStream) {
|
|
739
|
+
const e = t.localStream.getAudioTracks()[0];
|
|
681
740
|
if (e)
|
|
682
|
-
return e.enabled = !e.enabled,
|
|
741
|
+
return e.enabled = !e.enabled, t.isMuted = !e.enabled, t.isMuted;
|
|
683
742
|
}
|
|
684
743
|
return !1;
|
|
685
744
|
}
|
|
686
|
-
function
|
|
687
|
-
return
|
|
745
|
+
function Qe() {
|
|
746
|
+
return t.localStream;
|
|
688
747
|
}
|
|
689
|
-
function
|
|
690
|
-
return new Promise((e,
|
|
691
|
-
if (!
|
|
692
|
-
|
|
748
|
+
function Xe() {
|
|
749
|
+
return new Promise((e, n) => {
|
|
750
|
+
if (!t.peerConnection) {
|
|
751
|
+
n(new Error("no peer connection"));
|
|
693
752
|
return;
|
|
694
753
|
}
|
|
695
|
-
|
|
696
|
-
|
|
754
|
+
t.peerConnection.getStats().then((o) => {
|
|
755
|
+
o.forEach((r) => {
|
|
697
756
|
r.type == "inbound-rtp" && e(r.totalAudioEnergy);
|
|
698
|
-
}),
|
|
699
|
-
}).catch((
|
|
700
|
-
|
|
757
|
+
}), n(new Error("no inbound-rtp stats found"));
|
|
758
|
+
}).catch((o) => {
|
|
759
|
+
n(o);
|
|
701
760
|
});
|
|
702
761
|
});
|
|
703
762
|
}
|
|
704
|
-
function
|
|
705
|
-
return new Promise((e,
|
|
706
|
-
if (!
|
|
707
|
-
|
|
763
|
+
function Ze() {
|
|
764
|
+
return new Promise((e, n) => {
|
|
765
|
+
if (!t.peerConnection) {
|
|
766
|
+
n(new Error("no peer connection"));
|
|
708
767
|
return;
|
|
709
768
|
}
|
|
710
|
-
|
|
711
|
-
|
|
769
|
+
t.peerConnection.getStats().then((o) => {
|
|
770
|
+
o.forEach((r) => {
|
|
712
771
|
r.type == "outbound-rtp" && e(r.totalAudioEnergy);
|
|
713
|
-
}),
|
|
714
|
-
}).catch((
|
|
715
|
-
|
|
772
|
+
}), n(new Error("no outbound-rtp stats found"));
|
|
773
|
+
}).catch((o) => {
|
|
774
|
+
n(o);
|
|
716
775
|
});
|
|
717
776
|
});
|
|
718
777
|
}
|
|
719
778
|
export {
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
Fe as
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
779
|
+
y as MESSAGE_ROLES,
|
|
780
|
+
Te as authenticate,
|
|
781
|
+
Ke as deleteAttachment,
|
|
782
|
+
Je as disconnect,
|
|
783
|
+
ie as disconnectCall,
|
|
784
|
+
He as getAttachment,
|
|
785
|
+
We as getHistory,
|
|
786
|
+
Xe as getInboundAudioEnergy,
|
|
787
|
+
Qe as getLocalStream,
|
|
788
|
+
Ze as getOutboundAudioEnergy,
|
|
789
|
+
ve as getSession,
|
|
790
|
+
Fe as initialize,
|
|
791
|
+
ye as sendMessage,
|
|
792
|
+
Ve as setCallCallbacks,
|
|
793
|
+
ze as setCallbacks,
|
|
794
|
+
Be as startCall,
|
|
795
|
+
Ge as startChat,
|
|
796
|
+
Ye as toggleMute,
|
|
797
|
+
_e as uploadAttachment
|
|
736
798
|
};
|
|
737
799
|
//# sourceMappingURL=origon-chat-sdk.js.map
|