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