media-av 0.0.8 → 0.0.9
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/mediaAV.js +54 -54
- package/dist/mediaAV.umd.cjs +1 -1
- package/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/mediaAV.js
CHANGED
|
@@ -337,10 +337,10 @@ function Ye(t, e, r) {
|
|
|
337
337
|
if (d.endsWith(y, "{}"))
|
|
338
338
|
y = n ? y : y.slice(0, -2), h = JSON.stringify(h);
|
|
339
339
|
else if (d.isArray(h) && Li(h) || (d.isFileList(h) || d.endsWith(y, "[]")) && (S = d.toArray(h)))
|
|
340
|
-
return y = jr(y), S.forEach(function(x,
|
|
340
|
+
return y = jr(y), S.forEach(function(x, w) {
|
|
341
341
|
!(d.isUndefined(x) || x === null) && e.append(
|
|
342
342
|
// eslint-disable-next-line no-nested-ternary
|
|
343
|
-
s === !0 ? Kt([y],
|
|
343
|
+
s === !0 ? Kt([y], w, o) : s === null ? y : y + "[]",
|
|
344
344
|
c(x)
|
|
345
345
|
);
|
|
346
346
|
}), !1;
|
|
@@ -468,7 +468,7 @@ class Ni {
|
|
|
468
468
|
});
|
|
469
469
|
}
|
|
470
470
|
}
|
|
471
|
-
const Yt = Ni,
|
|
471
|
+
const Yt = Ni, wr = {
|
|
472
472
|
silentJSONParsing: !0,
|
|
473
473
|
forcedJSONParsing: !0,
|
|
474
474
|
clarifyTimeoutError: !1
|
|
@@ -494,10 +494,10 @@ function Hi(t, e) {
|
|
|
494
494
|
}
|
|
495
495
|
}, e));
|
|
496
496
|
}
|
|
497
|
-
function
|
|
497
|
+
function wi(t) {
|
|
498
498
|
return d.matchAll(/\w+|\[(\w*)]/g, t).map((e) => e[0] === "[]" ? "" : e[1] || e[0]);
|
|
499
499
|
}
|
|
500
|
-
function
|
|
500
|
+
function Gi(t) {
|
|
501
501
|
const e = {}, r = Object.keys(t);
|
|
502
502
|
let n;
|
|
503
503
|
const i = r.length;
|
|
@@ -506,16 +506,16 @@ function wi(t) {
|
|
|
506
506
|
o = r[n], e[o] = t[o];
|
|
507
507
|
return e;
|
|
508
508
|
}
|
|
509
|
-
function
|
|
509
|
+
function Gr(t) {
|
|
510
510
|
function e(r, n, i, o) {
|
|
511
511
|
let s = r[o++];
|
|
512
512
|
const a = Number.isFinite(+s), l = o >= r.length;
|
|
513
|
-
return s = !s && d.isArray(i) ? i.length : s, l ? (d.hasOwnProp(i, s) ? i[s] = [i[s], n] : i[s] = n, !a) : ((!i[s] || !d.isObject(i[s])) && (i[s] = []), e(r, n, i[s], o) && d.isArray(i[s]) && (i[s] =
|
|
513
|
+
return s = !s && d.isArray(i) ? i.length : s, l ? (d.hasOwnProp(i, s) ? i[s] = [i[s], n] : i[s] = n, !a) : ((!i[s] || !d.isObject(i[s])) && (i[s] = []), e(r, n, i[s], o) && d.isArray(i[s]) && (i[s] = Gi(i[s])), !a);
|
|
514
514
|
}
|
|
515
515
|
if (d.isFormData(t) && d.isFunction(t.entries)) {
|
|
516
516
|
const r = {};
|
|
517
517
|
return d.forEachEntry(t, (n, i) => {
|
|
518
|
-
e(
|
|
518
|
+
e(wi(n), i, r, 0);
|
|
519
519
|
}), r;
|
|
520
520
|
}
|
|
521
521
|
return null;
|
|
@@ -534,12 +534,12 @@ function Vi(t, e, r) {
|
|
|
534
534
|
return (r || JSON.stringify)(t);
|
|
535
535
|
}
|
|
536
536
|
const Xe = {
|
|
537
|
-
transitional:
|
|
537
|
+
transitional: wr,
|
|
538
538
|
adapter: ["xhr", "http"],
|
|
539
539
|
transformRequest: [function(e, r) {
|
|
540
540
|
const n = r.getContentType() || "", i = n.indexOf("application/json") > -1, o = d.isObject(e);
|
|
541
541
|
if (o && d.isHTMLForm(e) && (e = new FormData(e)), d.isFormData(e))
|
|
542
|
-
return i && i ? JSON.stringify(
|
|
542
|
+
return i && i ? JSON.stringify(Gr(e)) : e;
|
|
543
543
|
if (d.isArrayBuffer(e) || d.isBuffer(e) || d.isStream(e) || d.isFile(e) || d.isBlob(e))
|
|
544
544
|
return e;
|
|
545
545
|
if (d.isArrayBufferView(e))
|
|
@@ -958,7 +958,7 @@ const oo = typeof XMLHttpRequest < "u", so = oo && function(t) {
|
|
|
958
958
|
n(new C("Network Error", C.ERR_NETWORK, t, c)), c = null;
|
|
959
959
|
}, c.ontimeout = function() {
|
|
960
960
|
let h = t.timeout ? "timeout of " + t.timeout + "ms exceeded" : "timeout exceeded";
|
|
961
|
-
const y = t.transitional ||
|
|
961
|
+
const y = t.transitional || wr;
|
|
962
962
|
t.timeoutErrorMessage && (h = t.timeoutErrorMessage), n(new C(
|
|
963
963
|
h,
|
|
964
964
|
y.clarifyTimeoutError ? C.ETIMEDOUT : C.ECONNABORTED,
|
|
@@ -1148,7 +1148,7 @@ const yt = {
|
|
|
1148
1148
|
assertOptions: co,
|
|
1149
1149
|
validators: Mt
|
|
1150
1150
|
}, z = yt.validators;
|
|
1151
|
-
class
|
|
1151
|
+
class Ge {
|
|
1152
1152
|
constructor(e) {
|
|
1153
1153
|
this.defaults = e, this.interceptors = {
|
|
1154
1154
|
request: new Yt(),
|
|
@@ -1229,7 +1229,7 @@ class we {
|
|
|
1229
1229
|
}
|
|
1230
1230
|
}
|
|
1231
1231
|
d.forEach(["delete", "get", "head", "options"], function(e) {
|
|
1232
|
-
|
|
1232
|
+
Ge.prototype[e] = function(r, n) {
|
|
1233
1233
|
return this.request(le(n || {}, {
|
|
1234
1234
|
method: e,
|
|
1235
1235
|
url: r,
|
|
@@ -1250,9 +1250,9 @@ d.forEach(["post", "put", "patch"], function(e) {
|
|
|
1250
1250
|
}));
|
|
1251
1251
|
};
|
|
1252
1252
|
}
|
|
1253
|
-
|
|
1253
|
+
Ge.prototype[e] = r(), Ge.prototype[e + "Form"] = r(!0);
|
|
1254
1254
|
});
|
|
1255
|
-
const Me =
|
|
1255
|
+
const Me = Ge;
|
|
1256
1256
|
class Nt {
|
|
1257
1257
|
constructor(e) {
|
|
1258
1258
|
if (typeof e != "function")
|
|
@@ -1421,7 +1421,7 @@ E.spread = uo;
|
|
|
1421
1421
|
E.isAxiosError = fo;
|
|
1422
1422
|
E.mergeConfig = le;
|
|
1423
1423
|
E.AxiosHeaders = H;
|
|
1424
|
-
E.formToJSON = (t) =>
|
|
1424
|
+
E.formToJSON = (t) => Gr(d.isHTMLForm(t) ? new FormData(t) : t);
|
|
1425
1425
|
E.HttpStatusCode = po;
|
|
1426
1426
|
E.default = E;
|
|
1427
1427
|
const ho = E;
|
|
@@ -1751,13 +1751,13 @@ var Lo = function t(e) {
|
|
|
1751
1751
|
};
|
|
1752
1752
|
a ? a(t.exports, "apply", { value: c }) : t.exports.apply = c;
|
|
1753
1753
|
})(Qr);
|
|
1754
|
-
var $o = Qr.exports, Yr = Ut, Xr = $o, Ho = Xr(Yr("String.prototype.indexOf")),
|
|
1754
|
+
var $o = Qr.exports, Yr = Ut, Xr = $o, Ho = Xr(Yr("String.prototype.indexOf")), wo = function(e, r) {
|
|
1755
1755
|
var n = Yr(e, !!r);
|
|
1756
1756
|
return typeof n == "function" && Ho(e, ".prototype.") > -1 ? Xr(n) : n;
|
|
1757
1757
|
};
|
|
1758
|
-
const
|
|
1758
|
+
const Go = {}, zo = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
1759
1759
|
__proto__: null,
|
|
1760
|
-
default:
|
|
1760
|
+
default: Go
|
|
1761
1761
|
}, Symbol.toStringTag, { value: "Module" })), Vo = /* @__PURE__ */ mo(zo);
|
|
1762
1762
|
var Bt = typeof Map == "function" && Map.prototype, at = Object.getOwnPropertyDescriptor && Bt ? Object.getOwnPropertyDescriptor(Map.prototype, "size") : null, We = Bt && at && typeof at.get == "function" ? at.get : null, ar = Bt && Map.prototype.forEach, jt = typeof Set == "function" && Set.prototype, ct = Object.getOwnPropertyDescriptor && jt ? Object.getOwnPropertyDescriptor(Set.prototype, "size") : null, Je = jt && ct && typeof ct.get == "function" ? ct.get : null, cr = jt && Set.prototype.forEach, Wo = typeof WeakMap == "function" && WeakMap.prototype, ve = Wo ? WeakMap.prototype.has : null, Jo = typeof WeakSet == "function" && WeakSet.prototype, Ce = Jo ? WeakSet.prototype.has : null, qo = typeof WeakRef == "function" && WeakRef.prototype, lr = qo ? WeakRef.prototype.deref : null, Ko = Boolean.prototype.valueOf, Qo = Object.prototype.toString, Yo = Function.prototype.toString, Xo = String.prototype.match, $t = String.prototype.slice, W = String.prototype.replace, Zo = String.prototype.toUpperCase, ur = String.prototype.toLowerCase, Zr = RegExp.prototype.test, fr = Array.prototype.concat, N = Array.prototype.join, es = Array.prototype.slice, pr = Math.floor, St = typeof BigInt == "function" ? BigInt.prototype.valueOf : null, lt = Object.getOwnPropertySymbols, vt = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? Symbol.prototype.toString : null, fe = typeof Symbol == "function" && typeof Symbol.iterator == "object", _ = typeof Symbol == "function" && Symbol.toStringTag && (typeof Symbol.toStringTag === fe || "symbol") ? Symbol.toStringTag : null, en = Object.prototype.propertyIsEnumerable, dr = (typeof Reflect == "function" ? Reflect.getPrototypeOf : Object.getPrototypeOf) || ([].__proto__ === Array.prototype ? function(t) {
|
|
1763
1763
|
return t.__proto__;
|
|
@@ -1844,8 +1844,8 @@ var Ct = Vo, mr = Ct.custom, yr = rn(mr) ? mr : null, ts = function t(e, r, n, i
|
|
|
1844
1844
|
return f && !Ss(x) ? "[" + Rt(x, f) + "]" : "[ " + N.call(x, ", ") + " ]";
|
|
1845
1845
|
}
|
|
1846
1846
|
if (is(e)) {
|
|
1847
|
-
var
|
|
1848
|
-
return !("cause" in Error.prototype) && "cause" in e && !en.call(e, "cause") ? "{ [" + String(e) + "] " + N.call(fr.call("[cause]: " + p(e.cause),
|
|
1847
|
+
var w = Ie(e, p);
|
|
1848
|
+
return !("cause" in Error.prototype) && "cause" in e && !en.call(e, "cause") ? "{ [" + String(e) + "] " + N.call(fr.call("[cause]: " + p(e.cause), w), ", ") + " }" : w.length === 0 ? "[" + String(e) + "]" : "{ [" + String(e) + "] " + N.call(w, ", ") + " }";
|
|
1849
1849
|
}
|
|
1850
1850
|
if (typeof e == "object" && s) {
|
|
1851
1851
|
if (yr && typeof e[yr] == "function" && Ct)
|
|
@@ -1880,7 +1880,7 @@ var Ct = Vo, mr = Ct.custom, yr = rn(mr) ? mr : null, ts = function t(e, r, n, i
|
|
|
1880
1880
|
if (os(e))
|
|
1881
1881
|
return Se(p(String(e)));
|
|
1882
1882
|
if (!ns(e) && !gr(e)) {
|
|
1883
|
-
var q = Ie(e, p),
|
|
1883
|
+
var q = Ie(e, p), G = dr ? dr(e) === Object.prototype : e instanceof Object || e.constructor === Object, te = e instanceof Object ? "" : "null prototype", re = !G && _ && Object(e) === e && _ in e ? $t.call(J(e), 8, -1) : te ? "Object" : "", ye = G || typeof e.constructor != "function" ? "" : e.constructor.name ? e.constructor.name + " " : "", k = ye + (re || te ? "[" + N.call(fr.call([], re || [], te || []), ": ") + "] " : "");
|
|
1884
1884
|
return q.length === 0 ? k + "{}" : f ? k + "{" + Rt(q, f) + "}" : k + "{ " + N.call(q, ", ") + " }";
|
|
1885
1885
|
}
|
|
1886
1886
|
return String(e);
|
|
@@ -2106,15 +2106,15 @@ function Ie(t, e) {
|
|
|
2106
2106
|
en.call(t, o[c]) && n.push("[" + e(o[c]) + "]: " + e(t[o[c]], t));
|
|
2107
2107
|
return n;
|
|
2108
2108
|
}
|
|
2109
|
-
var Ht = Ut, he =
|
|
2109
|
+
var Ht = Ut, he = wo, Cs = ts, bs = Ht("%TypeError%"), _e = Ht("%WeakMap%", !0), xe = Ht("%Map%", !0), Rs = he("WeakMap.prototype.get", !0), Ts = he("WeakMap.prototype.set", !0), Es = he("WeakMap.prototype.has", !0), Ps = he("Map.prototype.get", !0), Os = he("Map.prototype.set", !0), As = he("Map.prototype.has", !0), wt = function(t, e) {
|
|
2110
2110
|
for (var r = t, n; (n = r.next) !== null; r = n)
|
|
2111
2111
|
if (n.key === e)
|
|
2112
2112
|
return r.next = n.next, n.next = t.next, t.next = n, n;
|
|
2113
2113
|
}, Is = function(t, e) {
|
|
2114
|
-
var r =
|
|
2114
|
+
var r = wt(t, e);
|
|
2115
2115
|
return r && r.value;
|
|
2116
2116
|
}, _s = function(t, e, r) {
|
|
2117
|
-
var n =
|
|
2117
|
+
var n = wt(t, e);
|
|
2118
2118
|
n ? n.value = r : t.next = {
|
|
2119
2119
|
// eslint-disable-line no-param-reassign
|
|
2120
2120
|
key: e,
|
|
@@ -2122,7 +2122,7 @@ var Ht = Ut, he = Go, Cs = ts, bs = Ht("%TypeError%"), _e = Ht("%WeakMap%", !0),
|
|
|
2122
2122
|
value: r
|
|
2123
2123
|
};
|
|
2124
2124
|
}, xs = function(t, e) {
|
|
2125
|
-
return !!
|
|
2125
|
+
return !!wt(t, e);
|
|
2126
2126
|
}, Ds = function() {
|
|
2127
2127
|
var e, r, n, i = {
|
|
2128
2128
|
assert: function(o) {
|
|
@@ -2158,7 +2158,7 @@ var Ht = Ut, he = Go, Cs = ts, bs = Ht("%TypeError%"), _e = Ht("%WeakMap%", !0),
|
|
|
2158
2158
|
}, Ls = String.prototype.replace, ks = /%20/g, ft = {
|
|
2159
2159
|
RFC1738: "RFC1738",
|
|
2160
2160
|
RFC3986: "RFC3986"
|
|
2161
|
-
},
|
|
2161
|
+
}, Gt = {
|
|
2162
2162
|
default: ft.RFC3986,
|
|
2163
2163
|
formatters: {
|
|
2164
2164
|
RFC1738: function(t) {
|
|
@@ -2170,7 +2170,7 @@ var Ht = Ut, he = Go, Cs = ts, bs = Ht("%TypeError%"), _e = Ht("%WeakMap%", !0),
|
|
|
2170
2170
|
},
|
|
2171
2171
|
RFC1738: ft.RFC1738,
|
|
2172
2172
|
RFC3986: ft.RFC3986
|
|
2173
|
-
}, Ms =
|
|
2173
|
+
}, Ms = Gt, pt = Object.prototype.hasOwnProperty, Y = Array.isArray, M = function() {
|
|
2174
2174
|
for (var t = [], e = 0; e < 256; ++e)
|
|
2175
2175
|
t.push("%" + ((e < 16 ? "0" : "") + e.toString(16)).toUpperCase());
|
|
2176
2176
|
return t;
|
|
@@ -2263,9 +2263,9 @@ var Ht = Ut, he = Go, Cs = ts, bs = Ht("%TypeError%"), _e = Ht("%WeakMap%", !0),
|
|
|
2263
2263
|
return Ns(r), e;
|
|
2264
2264
|
}, Hs = function(e) {
|
|
2265
2265
|
return Object.prototype.toString.call(e) === "[object RegExp]";
|
|
2266
|
-
},
|
|
2266
|
+
}, ws = function(e) {
|
|
2267
2267
|
return !e || typeof e != "object" ? !1 : !!(e.constructor && e.constructor.isBuffer && e.constructor.isBuffer(e));
|
|
2268
|
-
},
|
|
2268
|
+
}, Gs = function(e, r) {
|
|
2269
2269
|
return [].concat(e, r);
|
|
2270
2270
|
}, zs = function(e, r) {
|
|
2271
2271
|
if (Y(e)) {
|
|
@@ -2277,15 +2277,15 @@ var Ht = Ut, he = Go, Cs = ts, bs = Ht("%TypeError%"), _e = Ht("%WeakMap%", !0),
|
|
|
2277
2277
|
}, an = {
|
|
2278
2278
|
arrayToObject: sn,
|
|
2279
2279
|
assign: Us,
|
|
2280
|
-
combine:
|
|
2280
|
+
combine: Gs,
|
|
2281
2281
|
compact: $s,
|
|
2282
2282
|
decode: Bs,
|
|
2283
2283
|
encode: js,
|
|
2284
|
-
isBuffer:
|
|
2284
|
+
isBuffer: ws,
|
|
2285
2285
|
isRegExp: Hs,
|
|
2286
2286
|
maybeMap: zs,
|
|
2287
2287
|
merge: Fs
|
|
2288
|
-
}, cn = Ds, Ne = an, be =
|
|
2288
|
+
}, cn = Ds, Ne = an, be = Gt, Vs = Object.prototype.hasOwnProperty, vr = {
|
|
2289
2289
|
brackets: function(e) {
|
|
2290
2290
|
return e + "[]";
|
|
2291
2291
|
},
|
|
@@ -2319,12 +2319,12 @@ var Ht = Ut, he = Go, Cs = ts, bs = Ht("%TypeError%"), _e = Ht("%WeakMap%", !0),
|
|
|
2319
2319
|
}, qs = function(e) {
|
|
2320
2320
|
return typeof e == "string" || typeof e == "number" || typeof e == "boolean" || typeof e == "symbol" || typeof e == "bigint";
|
|
2321
2321
|
}, dt = {}, Ks = function t(e, r, n, i, o, s, a, l, c, u, f, p, m, h, y, T) {
|
|
2322
|
-
for (var S = e, A = T, x = 0,
|
|
2322
|
+
for (var S = e, A = T, x = 0, w = !1; (A = A.get(dt)) !== void 0 && !w; ) {
|
|
2323
2323
|
var me = A.get(e);
|
|
2324
2324
|
if (x += 1, typeof me < "u") {
|
|
2325
2325
|
if (me === x)
|
|
2326
2326
|
throw new RangeError("Cyclic object value");
|
|
2327
|
-
|
|
2327
|
+
w = !0;
|
|
2328
2328
|
}
|
|
2329
2329
|
typeof A.get(dt) > "u" && (x = 0);
|
|
2330
2330
|
}
|
|
@@ -2345,17 +2345,17 @@ var Ht = Ut, he = Go, Cs = ts, bs = Ht("%TypeError%"), _e = Ht("%WeakMap%", !0),
|
|
|
2345
2345
|
var q = [];
|
|
2346
2346
|
if (typeof S > "u")
|
|
2347
2347
|
return q;
|
|
2348
|
-
var
|
|
2348
|
+
var G;
|
|
2349
2349
|
if (n === "comma" && $(S))
|
|
2350
|
-
h && a && (S = Ne.maybeMap(S, a)),
|
|
2350
|
+
h && a && (S = Ne.maybeMap(S, a)), G = [{ value: S.length > 0 ? S.join(",") || null : void 0 }];
|
|
2351
2351
|
else if ($(l))
|
|
2352
|
-
|
|
2352
|
+
G = l;
|
|
2353
2353
|
else {
|
|
2354
2354
|
var te = Object.keys(S);
|
|
2355
|
-
|
|
2355
|
+
G = c ? te.sort(c) : te;
|
|
2356
2356
|
}
|
|
2357
|
-
for (var re = i && $(S) && S.length === 1 ? r + "[]" : r, ye = 0; ye <
|
|
2358
|
-
var k =
|
|
2357
|
+
for (var re = i && $(S) && S.length === 1 ? r + "[]" : r, ye = 0; ye < G.length; ++ye) {
|
|
2358
|
+
var k = G[ye], j = typeof k == "object" && typeof k.value < "u" ? k.value : S[k];
|
|
2359
2359
|
if (!(s && j === null)) {
|
|
2360
2360
|
var ne = $(S) ? typeof n == "function" ? n(re, k) : re : re + (u ? "." + k : "[" + k + "]");
|
|
2361
2361
|
T.set(e, x);
|
|
@@ -2552,7 +2552,7 @@ var Ht = Ut, he = Go, Cs = ts, bs = Ht("%TypeError%"), _e = Ht("%WeakMap%", !0),
|
|
|
2552
2552
|
i = pe.merge(i, l, r);
|
|
2553
2553
|
}
|
|
2554
2554
|
return r.allowSparse === !0 ? i : pe.compact(i);
|
|
2555
|
-
}, aa = Ys, ca = sa, la =
|
|
2555
|
+
}, aa = Ys, ca = sa, la = Gt, ua = {
|
|
2556
2556
|
formats: la,
|
|
2557
2557
|
parse: ca,
|
|
2558
2558
|
stringify: aa
|
|
@@ -3569,7 +3569,7 @@ function Hn(t) {
|
|
|
3569
3569
|
}
|
|
3570
3570
|
});
|
|
3571
3571
|
}
|
|
3572
|
-
function
|
|
3572
|
+
function wn(t) {
|
|
3573
3573
|
const e = t.RTCPeerConnection.prototype.createOffer;
|
|
3574
3574
|
t.RTCPeerConnection.prototype.createOffer = function(n) {
|
|
3575
3575
|
if (n) {
|
|
@@ -3582,15 +3582,15 @@ function Gn(t) {
|
|
|
3582
3582
|
return e.apply(this, arguments);
|
|
3583
3583
|
};
|
|
3584
3584
|
}
|
|
3585
|
-
function
|
|
3585
|
+
function Gn(t) {
|
|
3586
3586
|
typeof t != "object" || t.AudioContext || (t.AudioContext = t.webkitAudioContext);
|
|
3587
3587
|
}
|
|
3588
3588
|
const Or = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
3589
3589
|
__proto__: null,
|
|
3590
|
-
shimAudioContext:
|
|
3590
|
+
shimAudioContext: Gn,
|
|
3591
3591
|
shimCallbacksAPI: Un,
|
|
3592
3592
|
shimConstraints: jn,
|
|
3593
|
-
shimCreateOfferLegacy:
|
|
3593
|
+
shimCreateOfferLegacy: wn,
|
|
3594
3594
|
shimGetUserMedia: Bn,
|
|
3595
3595
|
shimLocalStreamsAPI: Nn,
|
|
3596
3596
|
shimRTCIceServerUrls: $n,
|
|
@@ -4243,7 +4243,7 @@ function Ca({ window: t } = {}, e = {
|
|
|
4243
4243
|
case "safari":
|
|
4244
4244
|
if (!Or || !e.shimSafari)
|
|
4245
4245
|
return r("Safari shim is not included in this adapter release."), i;
|
|
4246
|
-
r("adapter.js shimming safari."), i.browserShim = Or, $e(t, n), He(t), $n(t),
|
|
4246
|
+
r("adapter.js shimming safari."), i.browserShim = Or, $e(t, n), He(t), $n(t), wn(t), Un(t), Nn(t), Fn(t), Hn(t), Bn(t), Gn(t), Ue(t), At(t), Be(t, n), je(t), _t(t, n);
|
|
4247
4247
|
break;
|
|
4248
4248
|
default:
|
|
4249
4249
|
r("Unsupported browser!");
|
|
@@ -4609,18 +4609,18 @@ class Ta {
|
|
|
4609
4609
|
}
|
|
4610
4610
|
onStartSuccess(e) {
|
|
4611
4611
|
console.debug("rtsp offer:", e.sdp), this.httpClient.Post(Ra, new Wn(this.rtspUrl, e.sdp ?? "")).then((r) => {
|
|
4612
|
-
var n, i, o;
|
|
4612
|
+
var n, i, o, s;
|
|
4613
4613
|
if (r.code != 200) {
|
|
4614
4614
|
this.stop(), this.sessionListener.onError(new Error(r.message));
|
|
4615
4615
|
return;
|
|
4616
4616
|
}
|
|
4617
|
-
console.debug("rtsp answer", (n = r.data) == null ? void 0 : n.sdp), this.webrtcSession.setRemoteSdp(((
|
|
4617
|
+
console.debug("rtsp answer", (n = r.data) == null ? void 0 : n.sdp), console.debug("rtsp answer", (i = r.data) == null ? void 0 : i.candidateList), this.webrtcSession.setRemoteSdp(((o = r.data) == null ? void 0 : o.sdp) ?? ""), this.webrtcSession.addRemoteCandidate(((s = r.data) == null ? void 0 : s.candidateList) ?? []);
|
|
4618
4618
|
}).catch((r) => {
|
|
4619
4619
|
this.stop(), this.sessionListener.onError(r);
|
|
4620
4620
|
});
|
|
4621
4621
|
}
|
|
4622
4622
|
}
|
|
4623
|
-
var R = /* @__PURE__ */ ((t) => (t[t.OFFLINE = -1] = "OFFLINE", t[t.IDLE = 0] = "IDLE", t[t.TRY = 1] = "TRY", t[t.RING = 2] = "RING", t[t.TALK = 3] = "TALK", t))(R || {}), F = /* @__PURE__ */ ((t) => (t.VIDEO = "video", t.AUDIO = "audio", t))(F || {}),
|
|
4623
|
+
var R = /* @__PURE__ */ ((t) => (t[t.OFFLINE = -1] = "OFFLINE", t[t.IDLE = 0] = "IDLE", t[t.TRY = 1] = "TRY", t[t.RING = 2] = "RING", t[t.TALK = 3] = "TALK", t))(R || {}), F = /* @__PURE__ */ ((t) => (t.VIDEO = "video", t.AUDIO = "audio", t))(F || {}), we = /* @__PURE__ */ ((t) => (t.FULL = "full-duplex", t.HALF = "half-duplex", t))(we || {}), Q = /* @__PURE__ */ ((t) => (t.IN = "in", t.OUT = "out", t))(Q || {}), D = /* @__PURE__ */ ((t) => (t.LOGIN = "login", t.LOGOUT = "logout", t.Invite = "invite", t.RING = "ring", t.ANSWER = "answer", t.HANGUP = "hangup", t.DTMF = "dtmf", t))(D || {});
|
|
4624
4624
|
function Ir() {
|
|
4625
4625
|
try {
|
|
4626
4626
|
return !!(navigator.mediaDevices && navigator.mediaDevices.getUserMedia);
|
|
@@ -4721,7 +4721,7 @@ class _a {
|
|
|
4721
4721
|
g(this, "tel", "");
|
|
4722
4722
|
g(this, "status", R.OFFLINE);
|
|
4723
4723
|
g(this, "mediaType", F.AUDIO);
|
|
4724
|
-
g(this, "callMode",
|
|
4724
|
+
g(this, "callMode", we.FULL);
|
|
4725
4725
|
g(this, "callDirect", Q.OUT);
|
|
4726
4726
|
g(this, "called", "");
|
|
4727
4727
|
g(this, "callId");
|
|
@@ -4744,7 +4744,7 @@ class _a {
|
|
|
4744
4744
|
init() {
|
|
4745
4745
|
this.websocketInit(this.wsUrl);
|
|
4746
4746
|
}
|
|
4747
|
-
makeCall(e, r = F.AUDIO, n =
|
|
4747
|
+
makeCall(e, r = F.AUDIO, n = we.FULL) {
|
|
4748
4748
|
var i;
|
|
4749
4749
|
try {
|
|
4750
4750
|
if (this.status == R.OFFLINE) {
|
|
@@ -4942,9 +4942,9 @@ class _a {
|
|
|
4942
4942
|
e.callId != this.callId && (console.debug("receive invite, but busy."), this.sendHangup(e.callId, 486));
|
|
4943
4943
|
return;
|
|
4944
4944
|
}
|
|
4945
|
-
this.callId = e.callId, this.mediaType = e.mediaType ?? F.AUDIO, this.callMode = e.callMode ??
|
|
4945
|
+
this.callId = e.callId, this.mediaType = e.mediaType ?? F.AUDIO, this.callMode = e.callMode ?? we.FULL, this.called = e.from ?? "", this.callDirect = Q.IN, this.remoteSdp = e.sdp, this.candidate = e.candidate, this.sendRing(), this.ringtone.currentTime = 0, this.ringtone.play().then(() => {
|
|
4946
4946
|
}).catch(() => {
|
|
4947
|
-
});
|
|
4947
|
+
}), this.sessionListener.onNewCall(new Aa(this.called, this.mediaType, this.callMode));
|
|
4948
4948
|
}
|
|
4949
4949
|
ringHandler(e) {
|
|
4950
4950
|
var r;
|
package/dist/mediaAV.umd.cjs
CHANGED
|
@@ -37,4 +37,4 @@ t=0 0\r
|
|
|
37
37
|
`},e.getDirection=function(r,n){const i=e.splitLines(r);for(let o=0;o<i.length;o++)switch(i[o]){case"a=sendrecv":case"a=sendonly":case"a=recvonly":case"a=inactive":return i[o].substring(2)}return n?e.getDirection(n):"sendrecv"},e.getKind=function(r){return e.splitLines(r)[0].split(" ")[0].substring(2)},e.isRejected=function(r){return r.split(" ",2)[1]==="0"},e.parseMLine=function(r){const i=e.splitLines(r)[0].substring(2).split(" ");return{kind:i[0],port:parseInt(i[1],10),protocol:i[2],fmt:i.slice(3).join(" ")}},e.parseOLine=function(r){const i=e.matchPrefix(r,"o=")[0].substring(2).split(" ");return{username:i[0],sessionId:i[1],sessionVersion:parseInt(i[2],10),netType:i[3],addressType:i[4],address:i[5]}},e.isValidSDP=function(r){if(typeof r!="string"||r.length===0)return!1;const n=e.splitLines(r);for(let i=0;i<n.length;i++)if(n[i].length<2||n[i].charAt(1)!=="=")return!1;return!0},t.exports=e})(zn);var Vn=zn.exports;const de=Er(Vn),pa=D({__proto__:null,default:de},[Vn]);function Ke(t){if(!t.RTCIceCandidate||t.RTCIceCandidate&&"foundation"in t.RTCIceCandidate.prototype)return;const e=t.RTCIceCandidate;t.RTCIceCandidate=function(n){if(typeof n=="object"&&n.candidate&&n.candidate.indexOf("a=")===0&&(n=JSON.parse(JSON.stringify(n)),n.candidate=n.candidate.substring(2)),n.candidate&&n.candidate.length){const i=new e(n),o=de.parseCandidate(n.candidate);for(const s in o)s in i||Object.defineProperty(i,s,{value:o[s]});return i.toJSON=function(){return{candidate:i.candidate,sdpMid:i.sdpMid,sdpMLineIndex:i.sdpMLineIndex,usernameFragment:i.usernameFragment}},i}return new e(n)},t.RTCIceCandidate.prototype=e.prototype,te(t,"icecandidate",r=>(r.candidate&&Object.defineProperty(r,"candidate",{value:new t.RTCIceCandidate(r.candidate),writable:"false"}),r))}function zt(t){!t.RTCIceCandidate||t.RTCIceCandidate&&"relayProtocol"in t.RTCIceCandidate.prototype||te(t,"icecandidate",e=>{if(e.candidate){const r=de.parseCandidate(e.candidate.candidate);r.type==="relay"&&(e.candidate.relayProtocol={0:"tls",1:"tcp",2:"udp"}[r.priority>>24])}return e})}function Qe(t,e){if(!t.RTCPeerConnection)return;"sctp"in t.RTCPeerConnection.prototype||Object.defineProperty(t.RTCPeerConnection.prototype,"sctp",{get(){return typeof this._sctp>"u"?null:this._sctp}});const r=function(a){if(!a||!a.sdp)return!1;const l=de.splitSections(a.sdp);return l.shift(),l.some(c=>{const u=de.parseMLine(c);return u&&u.kind==="application"&&u.protocol.indexOf("SCTP")!==-1})},n=function(a){const l=a.sdp.match(/mozilla...THIS_IS_SDPARTA-(\d+)/);if(l===null||l.length<2)return-1;const c=parseInt(l[1],10);return c!==c?-1:c},i=function(a){let l=65536;return e.browser==="firefox"&&(e.version<57?a===-1?l=16384:l=2147483637:e.version<60?l=e.version===57?65535:65536:l=2147483637),l},o=function(a,l){let c=65536;e.browser==="firefox"&&e.version===57&&(c=65535);const u=de.matchPrefix(a.sdp,"a=max-message-size:");return u.length>0?c=parseInt(u[0].substring(19),10):e.browser==="firefox"&&l!==-1&&(c=2147483637),c},s=t.RTCPeerConnection.prototype.setRemoteDescription;t.RTCPeerConnection.prototype.setRemoteDescription=function(){if(this._sctp=null,e.browser==="chrome"&&e.version>=76){const{sdpSemantics:l}=this.getConfiguration();l==="plan-b"&&Object.defineProperty(this,"sctp",{get(){return typeof this._sctp>"u"?null:this._sctp},enumerable:!0,configurable:!0})}if(r(arguments[0])){const l=n(arguments[0]),c=i(l),u=o(arguments[0],l);let f;c===0&&u===0?f=Number.POSITIVE_INFINITY:c===0||u===0?f=Math.max(c,u):f=Math.min(c,u);const p={};Object.defineProperty(p,"maxMessageSize",{get(){return f}}),this._sctp=p}return s.apply(this,arguments)}}function Ye(t){if(!(t.RTCPeerConnection&&"createDataChannel"in t.RTCPeerConnection.prototype))return;function e(n,i){const o=n.send;n.send=function(){const a=arguments[0],l=a.length||a.size||a.byteLength;if(n.readyState==="open"&&i.sctp&&l>i.sctp.maxMessageSize)throw new TypeError("Message too large (can send a maximum of "+i.sctp.maxMessageSize+" bytes)");return o.apply(n,arguments)}}const r=t.RTCPeerConnection.prototype.createDataChannel;t.RTCPeerConnection.prototype.createDataChannel=function(){const i=r.apply(this,arguments);return e(i,this),i},te(t,"datachannel",n=>(e(n.channel,n.target),n))}function Vt(t){if(!t.RTCPeerConnection||"connectionState"in t.RTCPeerConnection.prototype)return;const e=t.RTCPeerConnection.prototype;Object.defineProperty(e,"connectionState",{get(){return{completed:"connected",checking:"connecting"}[this.iceConnectionState]||this.iceConnectionState},enumerable:!0,configurable:!0}),Object.defineProperty(e,"onconnectionstatechange",{get(){return this._onconnectionstatechange||null},set(r){this._onconnectionstatechange&&(this.removeEventListener("connectionstatechange",this._onconnectionstatechange),delete this._onconnectionstatechange),r&&this.addEventListener("connectionstatechange",this._onconnectionstatechange=r)},enumerable:!0,configurable:!0}),["setLocalDescription","setRemoteDescription"].forEach(r=>{const n=e[r];e[r]=function(){return this._connectionstatechangepoly||(this._connectionstatechangepoly=i=>{const o=i.target;if(o._lastConnectionState!==o.connectionState){o._lastConnectionState=o.connectionState;const s=new Event("connectionstatechange",i);o.dispatchEvent(s)}return i},this.addEventListener("iceconnectionstatechange",this._connectionstatechangepoly)),n.apply(this,arguments)}})}function Wt(t,e){if(!t.RTCPeerConnection||e.browser==="chrome"&&e.version>=71||e.browser==="safari"&&e.version>=605)return;const r=t.RTCPeerConnection.prototype.setRemoteDescription;t.RTCPeerConnection.prototype.setRemoteDescription=function(i){if(i&&i.sdp&&i.sdp.indexOf(`
|
|
38
38
|
a=extmap-allow-mixed`)!==-1){const o=i.sdp.split(`
|
|
39
39
|
`).filter(s=>s.trim()!=="a=extmap-allow-mixed").join(`
|
|
40
|
-
`);t.RTCSessionDescription&&i instanceof t.RTCSessionDescription?arguments[0]=new t.RTCSessionDescription({type:i.type,sdp:o}):i.sdp=o}return r.apply(this,arguments)}}function Xe(t,e){if(!(t.RTCPeerConnection&&t.RTCPeerConnection.prototype))return;const r=t.RTCPeerConnection.prototype.addIceCandidate;!r||r.length===0||(t.RTCPeerConnection.prototype.addIceCandidate=function(){return arguments[0]?(e.browser==="chrome"&&e.version<78||e.browser==="firefox"&&e.version<68||e.browser==="safari")&&arguments[0]&&arguments[0].candidate===""?Promise.resolve():r.apply(this,arguments):(arguments[1]&&arguments[1].apply(null),Promise.resolve())})}function Ze(t,e){if(!(t.RTCPeerConnection&&t.RTCPeerConnection.prototype))return;const r=t.RTCPeerConnection.prototype.setLocalDescription;!r||r.length===0||(t.RTCPeerConnection.prototype.setLocalDescription=function(){let i=arguments[0]||{};if(typeof i!="object"||i.type&&i.sdp)return r.apply(this,arguments);if(i={type:i.type,sdp:i.sdp},!i.type)switch(this.signalingState){case"stable":case"have-local-offer":case"have-remote-pranswer":i.type="offer";break;default:i.type="answer";break}return i.sdp||i.type!=="offer"&&i.type!=="answer"?r.apply(this,[i]):(i.type==="offer"?this.createOffer:this.createAnswer).apply(this).then(s=>r.apply(this,[s]))})}const da=Object.freeze(Object.defineProperty({__proto__:null,removeExtmapAllowMixed:Wt,shimAddIceCandidateNullOrEmpty:Xe,shimConnectionState:Vt,shimMaxMessageSize:Qe,shimParameterlessSetLocalDescription:Ze,shimRTCIceCandidate:Ke,shimRTCIceCandidateRelayProtocol:zt,shimSendThrowTypeError:Ye},Symbol.toStringTag,{value:"Module"}));function ha({window:t}={},e={shimChrome:!0,shimFirefox:!0,shimSafari:!0}){const r=cn,n=la(t),i={browserDetails:n,commonShim:da,extractVersion:qe,disableLog:aa,disableWarnings:ca,sdp:pa};switch(n.browser){case"chrome":if(!Rn||!wt||!e.shimChrome)return r("Chrome shim is not included in this adapter release."),i;if(n.version===null)return r("Chrome shim can not determine version, not shimming."),i;r("adapter.js shimming chrome."),i.browserShim=Rn,Xe(t,n),Ze(t),dn(t,n),hn(t),wt(t,n),mn(t),Cn(t,n),yn(t),gn(t),Sn(t),bn(t,n),Ke(t),zt(t),Vt(t),Qe(t,n),Ye(t),Wt(t,n);break;case"firefox":if(!kn||!Gt||!e.shimFirefox)return r("Firefox shim is not included in this adapter release."),i;r("adapter.js shimming firefox."),i.browserShim=kn,Xe(t,n),Ze(t),Tn(t,n),Gt(t,n),En(t),An(t),Pn(t),On(t),In(t),_n(t),xn(t),Dn(t),Ln(t),Ke(t),Vt(t),Qe(t,n),Ye(t);break;case"safari":if(!Gn||!e.shimSafari)return r("Safari shim is not included in this adapter release."),i;r("adapter.js shimming safari."),i.browserShim=Gn,Xe(t,n),Ze(t),jn(t),Hn(t),Fn(t),Mn(t),Nn(t),$n(t),Un(t),wn(t),Ke(t),zt(t),Qe(t,n),Ye(t),Wt(t,n);break;default:r("Unsupported browser!");break}return i}const Wn=ha({window:typeof window>"u"?void 0:window});class Jt{constructor(e){g(this,"peerConnection");g(this,"sessionListener",new sa);g(this,"isCallOut",!1);g(this,"sessionType",b.UNKNOWN);g(this,"localStream");g(this,"remoteStream");g(this,"hasSetRemoteSdp",!1);g(this,"facingMode",ee.FRONT_FACING);g(this,"facingChanging",!1);g(this,"muted",!1);g(this,"openCamera",!1);this.sessionType=e,console.debug(Wn.browserDetails.browser+" "+Wn.browserDetails.version)}setListener(e){this.sessionListener=e}start(e,r){if(!e&&!r){this.error(new Error("start failed, remoteSdp is null."));return}switch(this.isCallOut=e,this.hasSetRemoteSdp=!1,this.facingMode=ee.FRONT_FACING,this.facingChanging=!1,this.muted=!1,this.peerConnection=new RTCPeerConnection({iceServers:[]}),this.peerConnection.onnegotiationneeded=()=>{e?this.peerConnection.createOffer().then(n=>{this.peerConnection.setLocalDescription(n).then(()=>{}).catch(i=>{this.error(i)})}).catch(n=>{this.error(n)}):(console.debug(r),this.peerConnection.setRemoteDescription(new RTCSessionDescription({type:"offer",sdp:r})).then(()=>{this.peerConnection.createAnswer().then(n=>{this.peerConnection.setLocalDescription(n).then(()=>{}).catch(i=>{this.error(i)})}).catch(n=>{this.error(n)})}).catch(n=>{this.error(n)}))},this.peerConnection.onicecandidate=n=>{},this.peerConnection.onicegatheringstatechange=()=>{this.peerConnection&&this.peerConnection.iceGatheringState=="complete"&&this.peerConnection.localDescription&&this.sessionListener.onStartSuccess(this.peerConnection.localDescription)},this.peerConnection.ontrack=n=>{for(let i=0;i<n.streams.length;i++)this.remoteStream?n.streams[i].getTracks().forEach(o=>{var s;(s=this.remoteStream)==null||s.addTrack(o)}):this.remoteStream=new MediaStream(n.streams[i]);this.sessionListener.onAddRemoteStream(this.remoteStream)},this.peerConnection.oniceconnectionstatechange=n=>{var i,o,s,a,l;console.debug("oniceconnectionstatechange",(i=this.peerConnection)==null?void 0:i.iceConnectionState),(((o=this.peerConnection)==null?void 0:o.iceConnectionState)=="completed"||((s=this.peerConnection)==null?void 0:s.iceConnectionState)=="disconnected"||((a=this.peerConnection)==null?void 0:a.iceConnectionState)=="failed"||((l=this.peerConnection)==null?void 0:l.iceConnectionState)=="closed")&&(this.stop(),this.sessionListener.onError(new Error("session closed.")))},this.sessionType){case b.RTSP_PULL:this.addTransceivers();break;case b.VIDEO:case b.AUDIO:case b.AUDIO_PUSH:case b.VIDEO_PUSH:this.gotLocalMedia();break;default:this.error(new Error("session type unknown: "+this.sessionType));break}}setRemoteSdp(e){if(this.peerConnection&&this.isCallOut){if(this.hasSetRemoteSdp)return;this.hasSetRemoteSdp=!0,this.peerConnection.setRemoteDescription(new RTCSessionDescription({type:"answer",sdp:e})).then(()=>{}).catch(r=>{this.error(r)})}}addRemoteCandidate(e){this.peerConnection&&e.forEach(r=>{this.peerConnection.addIceCandidate(r).then(()=>{}).catch(n=>console.log(n))})}stop(){this.peerConnection&&(this.peerConnection.close(),this.peerConnection=void 0),this.localStream&&(this.localStream.getTracks().forEach(e=>{this.localStream.removeTrack(e),e.stop()}),this.localStream=void 0),this.remoteStream=void 0}changeFacing(){return new Promise((e,r)=>{if(this.sessionType!==b.VIDEO&&this.sessionType!==b.VIDEO_PUSH){r(new Error("not video call"));return}if(!this.localStream||this.localStream.getVideoTracks().length<=0){r(new Error("not in calling or not video call"));return}if(this.facingChanging){r(new Error("camera switching in progress"));return}if(!/mobile/i.test(navigator.userAgent)){r(new Error("not mobile device"));return}this.facingChanging=!0,this.changeCameraLocalMedia().then(()=>e(this.facingMode)).catch(n=>r(n))})}changeMuted(){return new Promise((e,r)=>{!this.localStream||this.localStream.getAudioTracks().length<=0?r(new Error("not in calling")):(this.localStream.getAudioTracks().forEach(n=>{n.enabled=!n.enabled,this.muted=!n.enabled}),e(this.muted))})}changeCameraOpened(){return new Promise((e,r)=>{!this.localStream||this.localStream.getVideoTracks().length<=0?r(new Error("not in video calling")):(this.localStream.getVideoTracks().forEach(n=>{n.enabled=!n.enabled,this.openCamera=!n.enabled}),e(this.openCamera))})}error(e){this.stop(),this.sessionListener.onError(e)}addTransceivers(){this.peerConnection.addTransceiver("audio",{direction:"recvonly"}),this.peerConnection.addTransceiver("video",{direction:"recvonly"})}gotLocalMedia(){let e;switch(this.sessionType){case b.AUDIO:case b.AUDIO_PUSH:e={audio:{echoCancellation:!0,noiseSuppression:!0},video:!1};break;case b.VIDEO:case b.VIDEO_PUSH:e={audio:{echoCancellation:!0,noiseSuppression:!0},video:{height:{exact:720},width:{exact:1280}}};break;default:this.error(new Error("session type unknown."));return}navigator.mediaDevices&&navigator.mediaDevices.getUserMedia?navigator.mediaDevices.getUserMedia(e).then(r=>{this.getMediaSuccess(r)}).catch(r=>{this.getMediaFailed(r)}):this.error(new Error("Browser does not support WebRTC"))}getMediaSuccess(e){this.localStream=e,(this.sessionType===b.VIDEO||this.sessionType===b.VIDEO_PUSH)&&this.sessionListener.onAddLocalStream(e),e.getTracks().forEach(r=>{switch(this.sessionType){case b.VIDEO:case b.AUDIO:this.peerConnection.addTrack(r,e);break;case b.AUDIO_PUSH:case b.VIDEO_PUSH:this.peerConnection.addTransceiver(r,{direction:"sendonly",streams:[e]});break}}),this.muted=!1}getMediaFailed(e){if(this.sessionType===b.VIDEO){console.error("get video media failed. maybe not found camera.",e),this.sessionType=b.AUDIO,this.gotLocalMedia();return}else if(this.sessionType===b.VIDEO_PUSH){console.error("get video media failed. maybe not found camera.",e),this.sessionType=b.AUDIO_PUSH,this.gotLocalMedia();return}this.error(e)}changeCameraLocalMedia(){return new Promise((e,r)=>{let n;if(this.facingMode===ee.FRONT_FACING?n={audio:{echoCancellation:!0,noiseSuppression:!0},video:{height:{exact:1280},width:{exact:720},facingMode:"environment"}}:n={audio:{echoCancellation:!0,noiseSuppression:!0},video:{height:{exact:720},width:{exact:1280},facingMode:"user"}},navigator.mediaDevices&&navigator.mediaDevices.getUserMedia)navigator.mediaDevices.getUserMedia(n).then(i=>{this.changeCameraSuccess(i),e()}).catch(i=>{this.changeCameraFailed(i),r(i)});else{let i=new Error("Browser does not support WebRTC");this.changeCameraFailed(i),r(new Error("Browser does not support WebRTC"))}})}changeCameraSuccess(e){if(!this.localStream){e.getTracks().forEach(r=>{r.stop()}),this.facingChanging=!1;return}this.localStream.getVideoTracks().forEach(r=>{this.localStream.removeTrack(r),r.stop()}),e.getVideoTracks().forEach(r=>{this.localStream.addTrack(r)}),this.peerConnection.getSenders().forEach(r=>{r.track&&r.track.kind==="video"&&r.replaceTrack(e.getVideoTracks()[0]).then(()=>{}).catch(n=>{console.log(n)})}),this.facingMode===ee.FRONT_FACING?this.facingMode=ee.BACK_FACING:this.facingMode=ee.FRONT_FACING,this.facingChanging=!1}changeCameraFailed(e){console.log(e),this.facingChanging=!1}}class ma{onAddRemoteStream(e){console.debug("onAddRemoteStream:",e)}onError(e){console.debug("onError:",e)}}class Jn{constructor(e,r){g(this,"url");g(this,"offerSdp");this.url=e,this.offerSdp=r}}const ya="/media-server/video-play/webrtc";class ga{constructor(e,r){g(this,"rtspUrl");g(this,"webrtcSession",new Jt(b.RTSP_PULL));g(this,"sessionListener",new ma);g(this,"httpClient");this.rtspUrl=e,this.httpClient=r,this.webrtcSession.setListener(this)}setRtspPullSessionListener(e){this.sessionListener=e}start(){this.webrtcSession.start(!0)}stop(){this.webrtcSession.stop()}onAddLocalStream(e){}onAddRemoteStream(e){this.sessionListener.onAddRemoteStream(e)}onError(e){this.sessionListener.onError(e)}onStartSuccess(e){console.debug("rtsp offer:",e.sdp),this.httpClient.Post(ya,new Jn(this.rtspUrl,e.sdp??"")).then(r=>{var n,i,o;if(r.code!=200){this.stop(),this.sessionListener.onError(new Error(r.message));return}console.debug("rtsp answer",(n=r.data)==null?void 0:n.sdp),this.webrtcSession.setRemoteSdp(((i=r.data)==null?void 0:i.sdp)??""),this.webrtcSession.addRemoteCandidate(((o=r.data)==null?void 0:o.candidateList)??[])}).catch(r=>{this.stop(),this.sessionListener.onError(r)})}}var R=(t=>(t[t.OFFLINE=-1]="OFFLINE",t[t.IDLE=0]="IDLE",t[t.TRY=1]="TRY",t[t.RING=2]="RING",t[t.TALK=3]="TALK",t))(R||{}),$=(t=>(t.VIDEO="video",t.AUDIO="audio",t))($||{}),et=(t=>(t.FULL="full-duplex",t.HALF="half-duplex",t))(et||{}),re=(t=>(t.IN="in",t.OUT="out",t))(re||{}),L=(t=>(t.LOGIN="login",t.LOGOUT="logout",t.Invite="invite",t.RING="ring",t.ANSWER="answer",t.HANGUP="hangup",t.DTMF="dtmf",t))(L||{});function qn(){try{return!!(navigator.mediaDevices&&navigator.mediaDevices.getUserMedia)}catch{return!1}}function Sa(){return"browser-"+va()+Ca(6)}function va(){let t=new Date;return`${t.getFullYear()}${t.getMonth()}${t.getDate()}${t.getHours()}${t.getMinutes()}${t.getSeconds()}`}function Ca(t){let e="",r=["0","1","2","3","4","5","6","7","8","9","0","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"];for(let n=0;n<t;n++)e+=r[Math.floor(Math.random()*(r.length-1))];return e}class ba{constructor(e,r,n){g(this,"tel");g(this,"mediaType");g(this,"callMode");this.tel=e,this.callMode=n,this.mediaType=r}}class Ra{onAddLocalStream(e){console.debug("onAddLocalStream:",e)}onAddRemoteStream(e){console.debug("onAddRemoteStream:",e)}onAnswer(){console.debug("onAnswer")}onClose(e){console.debug("onClose:",e)}onError(e){console.debug("onError:",e)}onHangup(e){console.debug("onHangup:",e)}onNewCall(e){console.debug("onNewCall:",e)}onRing(){console.debug("onRing")}onInitResult(e){console.debug("onInitResult: ",e)}}class Ta{constructor(e,r){g(this,"tel","");g(this,"status",R.OFFLINE);g(this,"mediaType",$.AUDIO);g(this,"callMode",et.FULL);g(this,"callDirect",re.OUT);g(this,"called","");g(this,"callId");g(this,"remoteSdp");g(this,"candidate");g(this,"ringBackTone",new Audio("sound/ringbacktone.wav"));g(this,"ringtone",new Audio("sound/ringtone.wav"));g(this,"dtmfAudio",new Audio("sound/dtmf.wav"));g(this,"ws");g(this,"wsConnected",!1);g(this,"closeBySelf",!1);g(this,"webrtcSession");g(this,"sessionListener",new Ra);g(this,"wsUrl");this.tel=r??"",this.wsUrl=e,this.ringBackTone.loop=!0,this.ringtone.loop=!0}setCallSessionListener(e){this.sessionListener=e}init(){this.websocketInit(this.wsUrl)}makeCall(e,r=$.AUDIO,n=et.FULL){var i;try{if(this.status==R.OFFLINE){console.debug("The initialization has not been completed yet. Please try again later"),this.sessionListener.onError(new Error("The initialization has not been completed yet. Please try again later"));return}if(this.status>R.IDLE){console.debug("Another call is currently in progress"),this.sessionListener.onError(new Error("Another call is currently in progress"));return}if(!qn()){console.debug("Browser does not support WEBRTC"),this.sessionListener.onError(new Error("Browser does not support WEBRTC"));return}this.mediaType=r,this.callMode=n,this.called=e,this.callDirect=re.OUT,this.callId=Sa(),this.webrtcCreate($.VIDEO==r?b.VIDEO:b.AUDIO),(i=this.webrtcSession)==null||i.start(!0),this.status=R.TRY}catch(o){this.status=R.IDLE,this.sessionListener.onError(new Error(""+o))}}answer(){var e;if(this.status!=R.RING){console.debug("session is not ring state");return}if(this.callDirect!=re.IN){console.debug("session is call out, not allow answer");return}this.webrtcCreate($.VIDEO==this.mediaType?b.VIDEO:b.AUDIO),(e=this.webrtcSession)==null||e.start(!1,this.remoteSdp)}hangup(){this.status<=R.IDLE||(this.status==R.TALK?this.sendHangup(this.callId??""):this.callDirect==re.IN?this.sendHangup(this.callId??"",488):this.sendHangup(this.callId??"",801),this.close())}dtmf(e){return this.status!==R.TALK?!1:(this.sendDtmf(e),!0)}changeCamera(){return new Promise((e,r)=>{var n;this.webrtcSession||r(new Error("webrtc session not start")),(n=this.webrtcSession)==null||n.changeFacing().then(i=>e(i)).catch(i=>r(i))})}changeMuted(){return new Promise((e,r)=>{this.webrtcSession||r(new Error("webrtc session not start")),this.webrtcSession.changeMuted().then(n=>e(n)).catch(n=>r(n))})}changeCameraOpened(){return new Promise((e,r)=>{this.webrtcSession||r(new Error("webrtc session not start")),this.webrtcSession.changeCameraOpened().then(n=>e(n)).catch(n=>r(n))})}destroy(){var e;this.closeBySelf=!0,this.hangup(),this.close(),(e=this.ws)==null||e.close()}close(){this.webrtcClose();try{this.ringtone.pause(),this.ringBackTone.pause()}catch(e){console.debug("FullSession.close: ",e)}this.status=R.IDLE}websocketInit(e){this.ws=new WebSocket(e),this.closeBySelf=!1,this.ws.onopen=()=>{console.debug("ws connect success"),this.wsConnected=!0,this.sendLogin()},this.ws.onclose=r=>{console.error("ws on close: ",r),this.wsConnected=!1,this.close(),this.status=R.OFFLINE,this.closeBySelf||this.sessionListener.onClose(new Error(r.reason)),this.ws=void 0},this.ws.onmessage=r=>{try{let n=JSON.parse(r.data);switch(console.debug("receive msg from server <<<<<<<<<<<<<<<",n),n.type){case L.Invite:this.inviteHandler(n);break;case L.ANSWER:this.answerHandler(n);break;case L.RING:this.ringHandler(n);break;case L.HANGUP:this.hangupHandler(n);break;case L.LOGIN:this.loginHandler(n);break}}catch(n){console.error("receive msg from server, but process error: ",n,r)}},this.ws.onerror=r=>{console.error("ws on error: ",r)}}sendTo(e){var r;try{this.wsConnected?(console.debug("send msg to server >>>>>>>>>>>>>>>>>> ",e),(r=this.ws)==null||r.send(JSON.stringify(e))):console.error("ws not connected.")}catch(n){console.debug("FullSession sendTo error: ",n)}}sendLogin(){this.sendTo({type:L.LOGIN,username:this.tel,userAgent:this.getUserAgent()})}sendLogout(){this.sendTo({type:L.LOGOUT,username:this.tel}),this.status=R.OFFLINE}sendInvite(e){this.sendTo({callId:this.callId,type:L.Invite,from:this.tel,to:this.called,callMode:this.callMode,mediaType:this.mediaType,sdp:e}),this.status=R.TRY}sendRing(){this.sendTo({type:L.RING,callId:this.callId,code:180}),this.status=R.RING}sendAnswer(e){this.sendTo({type:L.ANSWER,callId:this.callId,mediaType:this.mediaType,sdp:e}),this.status=R.TALK,this.ringtone.pause(),this.ringBackTone.pause()}sendDtmf(e){this.sendTo({type:L.DTMF,callId:this.callId,callInfo:"dtmf="+e}),this.dtmfAudio.play().then(()=>{}).catch(r=>console.debug(r))}sendHangup(e,r=800){this.sendTo({type:L.HANGUP,callId:e,code:r}),e==this.callId&&(this.status=R.IDLE,this.callId=void 0)}loginHandler(e){var r;if(e.code!=200){(r=this.ws)==null||r.close(),this.wsConnected=!1,this.ws=void 0,this.status=R.OFFLINE,this.sessionListener.onInitResult(!1);return}this.tel=e.username??"",this.status=R.IDLE,this.sessionListener.onInitResult(!0)}inviteHandler(e){if(!e.callId){console.debug("receive invite, but callId is null.");return}if(!qn()){console.debug("receive invite, but unsupported webrtc."),this.sendHangup(e.callId,803);return}if(this.status>R.IDLE){e.callId!=this.callId&&(console.debug("receive invite, but busy."),this.sendHangup(e.callId,486));return}this.callId=e.callId,this.mediaType=e.mediaType??$.AUDIO,this.callMode=e.callMode??et.FULL,this.called=e.from??"",this.callDirect=re.IN,this.remoteSdp=e.sdp,this.candidate=e.candidate,this.sessionListener.onNewCall(new ba(this.called,this.mediaType,this.callMode)),this.sendRing(),this.ringtone.currentTime=0,this.ringtone.play().then(()=>{}).catch(()=>{})}ringHandler(e){var r;!e.callId||e.callId!=this.callId||(e.code==183?((r=this.webrtcSession)==null||r.setRemoteSdp(e.sdp??""),this.ringBackTone.pause()):(this.ringBackTone.currentTime=0,this.ringBackTone.play().then(()=>{}).catch(()=>{})),this.sessionListener.onRing(),this.status=R.RING)}answerHandler(e){var r,n;!e.callId||e.callId!=this.callId||(this.ringBackTone.pause(),(r=this.webrtcSession)==null||r.setRemoteSdp(e.sdp??""),(n=this.webrtcSession)==null||n.addRemoteCandidate(e.candidate??[]),this.sessionListener.onAnswer(),this.status=R.TALK)}hangupHandler(e){!e.callId||e.callId!=this.callId||(this.close(),this.sessionListener.onHangup(e.code))}getUserAgent(){return navigator.platform.indexOf("Win")>=0?"windows":"phone"}webrtcCreate(e){this.webrtcClose(),this.webrtcSession=new Jt(e),this.webrtcSession.setListener(this)}webrtcClose(){var e;(e=this.webrtcSession)==null||e.stop(),this.webrtcSession=void 0}onAddLocalStream(e){this.sessionListener.onAddLocalStream(e)}onAddRemoteStream(e){this.sessionListener.onAddRemoteStream(e)}onError(e){this.close(),this.callDirect==re.OUT&&this.hangup(),this.sessionListener.onError(e)}onStartSuccess(e){var r;e.type=="answer"?(this.sendAnswer(e.sdp??""),(r=this.webrtcSession)==null||r.addRemoteCandidate(this.candidate??[])):e.type=="offer"&&this.sendInvite(e.sdp??"")}}class Ea{onError(e){console.debug("onError:",e)}onAddLocalStream(e){console.debug("onAddLocalStream:",e)}}const Pa="/media-server/broadcast/webrtc";class Oa{constructor(e,r,n){g(this,"tel");g(this,"mediaType");g(this,"webrtcSession");g(this,"sessionListener",new Ea);g(this,"httpClient");this.tel=e,this.httpClient=r,this.mediaType=n===$.VIDEO?$.VIDEO:$.AUDIO,this.webrtcSession=new Jt(n==$.VIDEO?b.VIDEO_PUSH:b.AUDIO_PUSH),this.webrtcSession.setListener(this)}setBroadcastSessionListener(e){this.sessionListener=e}start(){this.webrtcSession.start(!0)}stop(){this.webrtcSession.stop()}onAddLocalStream(e){this.sessionListener.onAddLocalStream(e)}onAddRemoteStream(e){}onError(e){this.sessionListener.onError(e)}onStartSuccess(e){console.debug("offer:",e.sdp),this.httpClient.Post(Pa,new Jn(this.tel,e.sdp??"")).then(r=>{var n,i,o;if(r.code!=200){this.stop(),this.sessionListener.onError(new Error(r.message));return}console.debug("answer",(n=r.data)==null?void 0:n.sdp),this.webrtcSession.setRemoteSdp(((i=r.data)==null?void 0:i.sdp)??""),this.webrtcSession.addRemoteCandidate(((o=r.data)==null?void 0:o.candidateList)??[])}).catch(r=>{this.stop(),this.sessionListener.onError(r)})}}let qt=new on("/"),Kn="/media-server/ws/voip",Kt=new URL((location.protocol=="https:"?"wss://":"ws://")+location.host+Kn);function Aa(t){qt=new on(t)}function Ia(t){return new ga(t,qt)}function _a(t,e){return new Oa(t,qt,e)}function xa(t){Kt=new URL(t),Kt.pathname=Kn}function Da(t){return new Ta(Kt.toString(),t)}A.createBroadcastSession=_a,A.createCallSession=Da,A.createRtspPullSession=Ia,A.videoModuleInit=Aa,A.voipModuleInit=xa,Object.defineProperty(A,Symbol.toStringTag,{value:"Module"})});
|
|
40
|
+
`);t.RTCSessionDescription&&i instanceof t.RTCSessionDescription?arguments[0]=new t.RTCSessionDescription({type:i.type,sdp:o}):i.sdp=o}return r.apply(this,arguments)}}function Xe(t,e){if(!(t.RTCPeerConnection&&t.RTCPeerConnection.prototype))return;const r=t.RTCPeerConnection.prototype.addIceCandidate;!r||r.length===0||(t.RTCPeerConnection.prototype.addIceCandidate=function(){return arguments[0]?(e.browser==="chrome"&&e.version<78||e.browser==="firefox"&&e.version<68||e.browser==="safari")&&arguments[0]&&arguments[0].candidate===""?Promise.resolve():r.apply(this,arguments):(arguments[1]&&arguments[1].apply(null),Promise.resolve())})}function Ze(t,e){if(!(t.RTCPeerConnection&&t.RTCPeerConnection.prototype))return;const r=t.RTCPeerConnection.prototype.setLocalDescription;!r||r.length===0||(t.RTCPeerConnection.prototype.setLocalDescription=function(){let i=arguments[0]||{};if(typeof i!="object"||i.type&&i.sdp)return r.apply(this,arguments);if(i={type:i.type,sdp:i.sdp},!i.type)switch(this.signalingState){case"stable":case"have-local-offer":case"have-remote-pranswer":i.type="offer";break;default:i.type="answer";break}return i.sdp||i.type!=="offer"&&i.type!=="answer"?r.apply(this,[i]):(i.type==="offer"?this.createOffer:this.createAnswer).apply(this).then(s=>r.apply(this,[s]))})}const da=Object.freeze(Object.defineProperty({__proto__:null,removeExtmapAllowMixed:Wt,shimAddIceCandidateNullOrEmpty:Xe,shimConnectionState:Vt,shimMaxMessageSize:Qe,shimParameterlessSetLocalDescription:Ze,shimRTCIceCandidate:Ke,shimRTCIceCandidateRelayProtocol:zt,shimSendThrowTypeError:Ye},Symbol.toStringTag,{value:"Module"}));function ha({window:t}={},e={shimChrome:!0,shimFirefox:!0,shimSafari:!0}){const r=cn,n=la(t),i={browserDetails:n,commonShim:da,extractVersion:qe,disableLog:aa,disableWarnings:ca,sdp:pa};switch(n.browser){case"chrome":if(!Rn||!wt||!e.shimChrome)return r("Chrome shim is not included in this adapter release."),i;if(n.version===null)return r("Chrome shim can not determine version, not shimming."),i;r("adapter.js shimming chrome."),i.browserShim=Rn,Xe(t,n),Ze(t),dn(t,n),hn(t),wt(t,n),mn(t),Cn(t,n),yn(t),gn(t),Sn(t),bn(t,n),Ke(t),zt(t),Vt(t),Qe(t,n),Ye(t),Wt(t,n);break;case"firefox":if(!kn||!Gt||!e.shimFirefox)return r("Firefox shim is not included in this adapter release."),i;r("adapter.js shimming firefox."),i.browserShim=kn,Xe(t,n),Ze(t),Tn(t,n),Gt(t,n),En(t),An(t),Pn(t),On(t),In(t),_n(t),xn(t),Dn(t),Ln(t),Ke(t),Vt(t),Qe(t,n),Ye(t);break;case"safari":if(!Gn||!e.shimSafari)return r("Safari shim is not included in this adapter release."),i;r("adapter.js shimming safari."),i.browserShim=Gn,Xe(t,n),Ze(t),jn(t),Hn(t),Fn(t),Mn(t),Nn(t),$n(t),Un(t),wn(t),Ke(t),zt(t),Qe(t,n),Ye(t),Wt(t,n);break;default:r("Unsupported browser!");break}return i}const Wn=ha({window:typeof window>"u"?void 0:window});class Jt{constructor(e){g(this,"peerConnection");g(this,"sessionListener",new sa);g(this,"isCallOut",!1);g(this,"sessionType",b.UNKNOWN);g(this,"localStream");g(this,"remoteStream");g(this,"hasSetRemoteSdp",!1);g(this,"facingMode",ee.FRONT_FACING);g(this,"facingChanging",!1);g(this,"muted",!1);g(this,"openCamera",!1);this.sessionType=e,console.debug(Wn.browserDetails.browser+" "+Wn.browserDetails.version)}setListener(e){this.sessionListener=e}start(e,r){if(!e&&!r){this.error(new Error("start failed, remoteSdp is null."));return}switch(this.isCallOut=e,this.hasSetRemoteSdp=!1,this.facingMode=ee.FRONT_FACING,this.facingChanging=!1,this.muted=!1,this.peerConnection=new RTCPeerConnection({iceServers:[]}),this.peerConnection.onnegotiationneeded=()=>{e?this.peerConnection.createOffer().then(n=>{this.peerConnection.setLocalDescription(n).then(()=>{}).catch(i=>{this.error(i)})}).catch(n=>{this.error(n)}):(console.debug(r),this.peerConnection.setRemoteDescription(new RTCSessionDescription({type:"offer",sdp:r})).then(()=>{this.peerConnection.createAnswer().then(n=>{this.peerConnection.setLocalDescription(n).then(()=>{}).catch(i=>{this.error(i)})}).catch(n=>{this.error(n)})}).catch(n=>{this.error(n)}))},this.peerConnection.onicecandidate=n=>{},this.peerConnection.onicegatheringstatechange=()=>{this.peerConnection&&this.peerConnection.iceGatheringState=="complete"&&this.peerConnection.localDescription&&this.sessionListener.onStartSuccess(this.peerConnection.localDescription)},this.peerConnection.ontrack=n=>{for(let i=0;i<n.streams.length;i++)this.remoteStream?n.streams[i].getTracks().forEach(o=>{var s;(s=this.remoteStream)==null||s.addTrack(o)}):this.remoteStream=new MediaStream(n.streams[i]);this.sessionListener.onAddRemoteStream(this.remoteStream)},this.peerConnection.oniceconnectionstatechange=n=>{var i,o,s,a,l;console.debug("oniceconnectionstatechange",(i=this.peerConnection)==null?void 0:i.iceConnectionState),(((o=this.peerConnection)==null?void 0:o.iceConnectionState)=="completed"||((s=this.peerConnection)==null?void 0:s.iceConnectionState)=="disconnected"||((a=this.peerConnection)==null?void 0:a.iceConnectionState)=="failed"||((l=this.peerConnection)==null?void 0:l.iceConnectionState)=="closed")&&(this.stop(),this.sessionListener.onError(new Error("session closed.")))},this.sessionType){case b.RTSP_PULL:this.addTransceivers();break;case b.VIDEO:case b.AUDIO:case b.AUDIO_PUSH:case b.VIDEO_PUSH:this.gotLocalMedia();break;default:this.error(new Error("session type unknown: "+this.sessionType));break}}setRemoteSdp(e){if(this.peerConnection&&this.isCallOut){if(this.hasSetRemoteSdp)return;this.hasSetRemoteSdp=!0,this.peerConnection.setRemoteDescription(new RTCSessionDescription({type:"answer",sdp:e})).then(()=>{}).catch(r=>{this.error(r)})}}addRemoteCandidate(e){this.peerConnection&&e.forEach(r=>{this.peerConnection.addIceCandidate(r).then(()=>{}).catch(n=>console.log(n))})}stop(){this.peerConnection&&(this.peerConnection.close(),this.peerConnection=void 0),this.localStream&&(this.localStream.getTracks().forEach(e=>{this.localStream.removeTrack(e),e.stop()}),this.localStream=void 0),this.remoteStream=void 0}changeFacing(){return new Promise((e,r)=>{if(this.sessionType!==b.VIDEO&&this.sessionType!==b.VIDEO_PUSH){r(new Error("not video call"));return}if(!this.localStream||this.localStream.getVideoTracks().length<=0){r(new Error("not in calling or not video call"));return}if(this.facingChanging){r(new Error("camera switching in progress"));return}if(!/mobile/i.test(navigator.userAgent)){r(new Error("not mobile device"));return}this.facingChanging=!0,this.changeCameraLocalMedia().then(()=>e(this.facingMode)).catch(n=>r(n))})}changeMuted(){return new Promise((e,r)=>{!this.localStream||this.localStream.getAudioTracks().length<=0?r(new Error("not in calling")):(this.localStream.getAudioTracks().forEach(n=>{n.enabled=!n.enabled,this.muted=!n.enabled}),e(this.muted))})}changeCameraOpened(){return new Promise((e,r)=>{!this.localStream||this.localStream.getVideoTracks().length<=0?r(new Error("not in video calling")):(this.localStream.getVideoTracks().forEach(n=>{n.enabled=!n.enabled,this.openCamera=!n.enabled}),e(this.openCamera))})}error(e){this.stop(),this.sessionListener.onError(e)}addTransceivers(){this.peerConnection.addTransceiver("audio",{direction:"recvonly"}),this.peerConnection.addTransceiver("video",{direction:"recvonly"})}gotLocalMedia(){let e;switch(this.sessionType){case b.AUDIO:case b.AUDIO_PUSH:e={audio:{echoCancellation:!0,noiseSuppression:!0},video:!1};break;case b.VIDEO:case b.VIDEO_PUSH:e={audio:{echoCancellation:!0,noiseSuppression:!0},video:{height:{exact:720},width:{exact:1280}}};break;default:this.error(new Error("session type unknown."));return}navigator.mediaDevices&&navigator.mediaDevices.getUserMedia?navigator.mediaDevices.getUserMedia(e).then(r=>{this.getMediaSuccess(r)}).catch(r=>{this.getMediaFailed(r)}):this.error(new Error("Browser does not support WebRTC"))}getMediaSuccess(e){this.localStream=e,(this.sessionType===b.VIDEO||this.sessionType===b.VIDEO_PUSH)&&this.sessionListener.onAddLocalStream(e),e.getTracks().forEach(r=>{switch(this.sessionType){case b.VIDEO:case b.AUDIO:this.peerConnection.addTrack(r,e);break;case b.AUDIO_PUSH:case b.VIDEO_PUSH:this.peerConnection.addTransceiver(r,{direction:"sendonly",streams:[e]});break}}),this.muted=!1}getMediaFailed(e){if(this.sessionType===b.VIDEO){console.error("get video media failed. maybe not found camera.",e),this.sessionType=b.AUDIO,this.gotLocalMedia();return}else if(this.sessionType===b.VIDEO_PUSH){console.error("get video media failed. maybe not found camera.",e),this.sessionType=b.AUDIO_PUSH,this.gotLocalMedia();return}this.error(e)}changeCameraLocalMedia(){return new Promise((e,r)=>{let n;if(this.facingMode===ee.FRONT_FACING?n={audio:{echoCancellation:!0,noiseSuppression:!0},video:{height:{exact:1280},width:{exact:720},facingMode:"environment"}}:n={audio:{echoCancellation:!0,noiseSuppression:!0},video:{height:{exact:720},width:{exact:1280},facingMode:"user"}},navigator.mediaDevices&&navigator.mediaDevices.getUserMedia)navigator.mediaDevices.getUserMedia(n).then(i=>{this.changeCameraSuccess(i),e()}).catch(i=>{this.changeCameraFailed(i),r(i)});else{let i=new Error("Browser does not support WebRTC");this.changeCameraFailed(i),r(new Error("Browser does not support WebRTC"))}})}changeCameraSuccess(e){if(!this.localStream){e.getTracks().forEach(r=>{r.stop()}),this.facingChanging=!1;return}this.localStream.getVideoTracks().forEach(r=>{this.localStream.removeTrack(r),r.stop()}),e.getVideoTracks().forEach(r=>{this.localStream.addTrack(r)}),this.peerConnection.getSenders().forEach(r=>{r.track&&r.track.kind==="video"&&r.replaceTrack(e.getVideoTracks()[0]).then(()=>{}).catch(n=>{console.log(n)})}),this.facingMode===ee.FRONT_FACING?this.facingMode=ee.BACK_FACING:this.facingMode=ee.FRONT_FACING,this.facingChanging=!1}changeCameraFailed(e){console.log(e),this.facingChanging=!1}}class ma{onAddRemoteStream(e){console.debug("onAddRemoteStream:",e)}onError(e){console.debug("onError:",e)}}class Jn{constructor(e,r){g(this,"url");g(this,"offerSdp");this.url=e,this.offerSdp=r}}const ya="/media-server/video-play/webrtc";class ga{constructor(e,r){g(this,"rtspUrl");g(this,"webrtcSession",new Jt(b.RTSP_PULL));g(this,"sessionListener",new ma);g(this,"httpClient");this.rtspUrl=e,this.httpClient=r,this.webrtcSession.setListener(this)}setRtspPullSessionListener(e){this.sessionListener=e}start(){this.webrtcSession.start(!0)}stop(){this.webrtcSession.stop()}onAddLocalStream(e){}onAddRemoteStream(e){this.sessionListener.onAddRemoteStream(e)}onError(e){this.sessionListener.onError(e)}onStartSuccess(e){console.debug("rtsp offer:",e.sdp),this.httpClient.Post(ya,new Jn(this.rtspUrl,e.sdp??"")).then(r=>{var n,i,o,s;if(r.code!=200){this.stop(),this.sessionListener.onError(new Error(r.message));return}console.debug("rtsp answer",(n=r.data)==null?void 0:n.sdp),console.debug("rtsp answer",(i=r.data)==null?void 0:i.candidateList),this.webrtcSession.setRemoteSdp(((o=r.data)==null?void 0:o.sdp)??""),this.webrtcSession.addRemoteCandidate(((s=r.data)==null?void 0:s.candidateList)??[])}).catch(r=>{this.stop(),this.sessionListener.onError(r)})}}var R=(t=>(t[t.OFFLINE=-1]="OFFLINE",t[t.IDLE=0]="IDLE",t[t.TRY=1]="TRY",t[t.RING=2]="RING",t[t.TALK=3]="TALK",t))(R||{}),$=(t=>(t.VIDEO="video",t.AUDIO="audio",t))($||{}),et=(t=>(t.FULL="full-duplex",t.HALF="half-duplex",t))(et||{}),re=(t=>(t.IN="in",t.OUT="out",t))(re||{}),L=(t=>(t.LOGIN="login",t.LOGOUT="logout",t.Invite="invite",t.RING="ring",t.ANSWER="answer",t.HANGUP="hangup",t.DTMF="dtmf",t))(L||{});function qn(){try{return!!(navigator.mediaDevices&&navigator.mediaDevices.getUserMedia)}catch{return!1}}function Sa(){return"browser-"+va()+Ca(6)}function va(){let t=new Date;return`${t.getFullYear()}${t.getMonth()}${t.getDate()}${t.getHours()}${t.getMinutes()}${t.getSeconds()}`}function Ca(t){let e="",r=["0","1","2","3","4","5","6","7","8","9","0","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"];for(let n=0;n<t;n++)e+=r[Math.floor(Math.random()*(r.length-1))];return e}class ba{constructor(e,r,n){g(this,"tel");g(this,"mediaType");g(this,"callMode");this.tel=e,this.callMode=n,this.mediaType=r}}class Ra{onAddLocalStream(e){console.debug("onAddLocalStream:",e)}onAddRemoteStream(e){console.debug("onAddRemoteStream:",e)}onAnswer(){console.debug("onAnswer")}onClose(e){console.debug("onClose:",e)}onError(e){console.debug("onError:",e)}onHangup(e){console.debug("onHangup:",e)}onNewCall(e){console.debug("onNewCall:",e)}onRing(){console.debug("onRing")}onInitResult(e){console.debug("onInitResult: ",e)}}class Ta{constructor(e,r){g(this,"tel","");g(this,"status",R.OFFLINE);g(this,"mediaType",$.AUDIO);g(this,"callMode",et.FULL);g(this,"callDirect",re.OUT);g(this,"called","");g(this,"callId");g(this,"remoteSdp");g(this,"candidate");g(this,"ringBackTone",new Audio("sound/ringbacktone.wav"));g(this,"ringtone",new Audio("sound/ringtone.wav"));g(this,"dtmfAudio",new Audio("sound/dtmf.wav"));g(this,"ws");g(this,"wsConnected",!1);g(this,"closeBySelf",!1);g(this,"webrtcSession");g(this,"sessionListener",new Ra);g(this,"wsUrl");this.tel=r??"",this.wsUrl=e,this.ringBackTone.loop=!0,this.ringtone.loop=!0}setCallSessionListener(e){this.sessionListener=e}init(){this.websocketInit(this.wsUrl)}makeCall(e,r=$.AUDIO,n=et.FULL){var i;try{if(this.status==R.OFFLINE){console.debug("The initialization has not been completed yet. Please try again later"),this.sessionListener.onError(new Error("The initialization has not been completed yet. Please try again later"));return}if(this.status>R.IDLE){console.debug("Another call is currently in progress"),this.sessionListener.onError(new Error("Another call is currently in progress"));return}if(!qn()){console.debug("Browser does not support WEBRTC"),this.sessionListener.onError(new Error("Browser does not support WEBRTC"));return}this.mediaType=r,this.callMode=n,this.called=e,this.callDirect=re.OUT,this.callId=Sa(),this.webrtcCreate($.VIDEO==r?b.VIDEO:b.AUDIO),(i=this.webrtcSession)==null||i.start(!0),this.status=R.TRY}catch(o){this.status=R.IDLE,this.sessionListener.onError(new Error(""+o))}}answer(){var e;if(this.status!=R.RING){console.debug("session is not ring state");return}if(this.callDirect!=re.IN){console.debug("session is call out, not allow answer");return}this.webrtcCreate($.VIDEO==this.mediaType?b.VIDEO:b.AUDIO),(e=this.webrtcSession)==null||e.start(!1,this.remoteSdp)}hangup(){this.status<=R.IDLE||(this.status==R.TALK?this.sendHangup(this.callId??""):this.callDirect==re.IN?this.sendHangup(this.callId??"",488):this.sendHangup(this.callId??"",801),this.close())}dtmf(e){return this.status!==R.TALK?!1:(this.sendDtmf(e),!0)}changeCamera(){return new Promise((e,r)=>{var n;this.webrtcSession||r(new Error("webrtc session not start")),(n=this.webrtcSession)==null||n.changeFacing().then(i=>e(i)).catch(i=>r(i))})}changeMuted(){return new Promise((e,r)=>{this.webrtcSession||r(new Error("webrtc session not start")),this.webrtcSession.changeMuted().then(n=>e(n)).catch(n=>r(n))})}changeCameraOpened(){return new Promise((e,r)=>{this.webrtcSession||r(new Error("webrtc session not start")),this.webrtcSession.changeCameraOpened().then(n=>e(n)).catch(n=>r(n))})}destroy(){var e;this.closeBySelf=!0,this.hangup(),this.close(),(e=this.ws)==null||e.close()}close(){this.webrtcClose();try{this.ringtone.pause(),this.ringBackTone.pause()}catch(e){console.debug("FullSession.close: ",e)}this.status=R.IDLE}websocketInit(e){this.ws=new WebSocket(e),this.closeBySelf=!1,this.ws.onopen=()=>{console.debug("ws connect success"),this.wsConnected=!0,this.sendLogin()},this.ws.onclose=r=>{console.error("ws on close: ",r),this.wsConnected=!1,this.close(),this.status=R.OFFLINE,this.closeBySelf||this.sessionListener.onClose(new Error(r.reason)),this.ws=void 0},this.ws.onmessage=r=>{try{let n=JSON.parse(r.data);switch(console.debug("receive msg from server <<<<<<<<<<<<<<<",n),n.type){case L.Invite:this.inviteHandler(n);break;case L.ANSWER:this.answerHandler(n);break;case L.RING:this.ringHandler(n);break;case L.HANGUP:this.hangupHandler(n);break;case L.LOGIN:this.loginHandler(n);break}}catch(n){console.error("receive msg from server, but process error: ",n,r)}},this.ws.onerror=r=>{console.error("ws on error: ",r)}}sendTo(e){var r;try{this.wsConnected?(console.debug("send msg to server >>>>>>>>>>>>>>>>>> ",e),(r=this.ws)==null||r.send(JSON.stringify(e))):console.error("ws not connected.")}catch(n){console.debug("FullSession sendTo error: ",n)}}sendLogin(){this.sendTo({type:L.LOGIN,username:this.tel,userAgent:this.getUserAgent()})}sendLogout(){this.sendTo({type:L.LOGOUT,username:this.tel}),this.status=R.OFFLINE}sendInvite(e){this.sendTo({callId:this.callId,type:L.Invite,from:this.tel,to:this.called,callMode:this.callMode,mediaType:this.mediaType,sdp:e}),this.status=R.TRY}sendRing(){this.sendTo({type:L.RING,callId:this.callId,code:180}),this.status=R.RING}sendAnswer(e){this.sendTo({type:L.ANSWER,callId:this.callId,mediaType:this.mediaType,sdp:e}),this.status=R.TALK,this.ringtone.pause(),this.ringBackTone.pause()}sendDtmf(e){this.sendTo({type:L.DTMF,callId:this.callId,callInfo:"dtmf="+e}),this.dtmfAudio.play().then(()=>{}).catch(r=>console.debug(r))}sendHangup(e,r=800){this.sendTo({type:L.HANGUP,callId:e,code:r}),e==this.callId&&(this.status=R.IDLE,this.callId=void 0)}loginHandler(e){var r;if(e.code!=200){(r=this.ws)==null||r.close(),this.wsConnected=!1,this.ws=void 0,this.status=R.OFFLINE,this.sessionListener.onInitResult(!1);return}this.tel=e.username??"",this.status=R.IDLE,this.sessionListener.onInitResult(!0)}inviteHandler(e){if(!e.callId){console.debug("receive invite, but callId is null.");return}if(!qn()){console.debug("receive invite, but unsupported webrtc."),this.sendHangup(e.callId,803);return}if(this.status>R.IDLE){e.callId!=this.callId&&(console.debug("receive invite, but busy."),this.sendHangup(e.callId,486));return}this.callId=e.callId,this.mediaType=e.mediaType??$.AUDIO,this.callMode=e.callMode??et.FULL,this.called=e.from??"",this.callDirect=re.IN,this.remoteSdp=e.sdp,this.candidate=e.candidate,this.sendRing(),this.ringtone.currentTime=0,this.ringtone.play().then(()=>{}).catch(()=>{}),this.sessionListener.onNewCall(new ba(this.called,this.mediaType,this.callMode))}ringHandler(e){var r;!e.callId||e.callId!=this.callId||(e.code==183?((r=this.webrtcSession)==null||r.setRemoteSdp(e.sdp??""),this.ringBackTone.pause()):(this.ringBackTone.currentTime=0,this.ringBackTone.play().then(()=>{}).catch(()=>{})),this.sessionListener.onRing(),this.status=R.RING)}answerHandler(e){var r,n;!e.callId||e.callId!=this.callId||(this.ringBackTone.pause(),(r=this.webrtcSession)==null||r.setRemoteSdp(e.sdp??""),(n=this.webrtcSession)==null||n.addRemoteCandidate(e.candidate??[]),this.sessionListener.onAnswer(),this.status=R.TALK)}hangupHandler(e){!e.callId||e.callId!=this.callId||(this.close(),this.sessionListener.onHangup(e.code))}getUserAgent(){return navigator.platform.indexOf("Win")>=0?"windows":"phone"}webrtcCreate(e){this.webrtcClose(),this.webrtcSession=new Jt(e),this.webrtcSession.setListener(this)}webrtcClose(){var e;(e=this.webrtcSession)==null||e.stop(),this.webrtcSession=void 0}onAddLocalStream(e){this.sessionListener.onAddLocalStream(e)}onAddRemoteStream(e){this.sessionListener.onAddRemoteStream(e)}onError(e){this.close(),this.callDirect==re.OUT&&this.hangup(),this.sessionListener.onError(e)}onStartSuccess(e){var r;e.type=="answer"?(this.sendAnswer(e.sdp??""),(r=this.webrtcSession)==null||r.addRemoteCandidate(this.candidate??[])):e.type=="offer"&&this.sendInvite(e.sdp??"")}}class Ea{onError(e){console.debug("onError:",e)}onAddLocalStream(e){console.debug("onAddLocalStream:",e)}}const Pa="/media-server/broadcast/webrtc";class Oa{constructor(e,r,n){g(this,"tel");g(this,"mediaType");g(this,"webrtcSession");g(this,"sessionListener",new Ea);g(this,"httpClient");this.tel=e,this.httpClient=r,this.mediaType=n===$.VIDEO?$.VIDEO:$.AUDIO,this.webrtcSession=new Jt(n==$.VIDEO?b.VIDEO_PUSH:b.AUDIO_PUSH),this.webrtcSession.setListener(this)}setBroadcastSessionListener(e){this.sessionListener=e}start(){this.webrtcSession.start(!0)}stop(){this.webrtcSession.stop()}onAddLocalStream(e){this.sessionListener.onAddLocalStream(e)}onAddRemoteStream(e){}onError(e){this.sessionListener.onError(e)}onStartSuccess(e){console.debug("offer:",e.sdp),this.httpClient.Post(Pa,new Jn(this.tel,e.sdp??"")).then(r=>{var n,i,o;if(r.code!=200){this.stop(),this.sessionListener.onError(new Error(r.message));return}console.debug("answer",(n=r.data)==null?void 0:n.sdp),this.webrtcSession.setRemoteSdp(((i=r.data)==null?void 0:i.sdp)??""),this.webrtcSession.addRemoteCandidate(((o=r.data)==null?void 0:o.candidateList)??[])}).catch(r=>{this.stop(),this.sessionListener.onError(r)})}}let qt=new on("/"),Kn="/media-server/ws/voip",Kt=new URL((location.protocol=="https:"?"wss://":"ws://")+location.host+Kn);function Aa(t){qt=new on(t)}function Ia(t){return new ga(t,qt)}function _a(t,e){return new Oa(t,qt,e)}function xa(t){Kt=new URL(t),Kt.pathname=Kn}function Da(t){return new Ta(Kt.toString(),t)}A.createBroadcastSession=_a,A.createCallSession=Da,A.createRtspPullSession=Ia,A.videoModuleInit=Aa,A.voipModuleInit=xa,Object.defineProperty(A,Symbol.toStringTag,{value:"Module"})});
|
package/index.d.ts
CHANGED
|
@@ -269,4 +269,4 @@ export declare function createRtspPullSession(rtspUrl: string): IRtspPullSession
|
|
|
269
269
|
* @param tel 广播号码
|
|
270
270
|
* @param mediaType 广播类型, 默认 audio
|
|
271
271
|
*/
|
|
272
|
-
export declare function createBroadcastSession(tel: string, mediaType?: MediaType): IBroadcastSession
|
|
272
|
+
export declare function createBroadcastSession(tel: string, mediaType?: MediaType): IBroadcastSession;
|