media-av 0.0.14 → 0.0.15

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/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  3. 支持软电话,实现音视频呼叫
6
6
  4. 支持音视频全双工半/双工呼叫
7
7
 
8
- 2024/01/26 0.0.13
8
+ 2024/01/29 0.0.15
9
9
  1. 新增app代理, 支持音视频全双工/半双工呼叫
10
10
 
11
11
  2023/09/04
package/dist/mediaAV.js CHANGED
@@ -17,7 +17,7 @@ function ti(t, e) {
17
17
  }
18
18
  return Object.freeze(Object.defineProperty(t, Symbol.toStringTag, { value: "Module" }));
19
19
  }
20
- function xr(t, e) {
20
+ function Lr(t, e) {
21
21
  return function() {
22
22
  return t.apply(e, arguments);
23
23
  };
@@ -29,12 +29,12 @@ const { toString: ri } = Object.prototype, { getPrototypeOf: kt } = Object, qe =
29
29
  function ni(t) {
30
30
  return t !== null && !Te(t) && t.constructor !== null && !Te(t.constructor) && k(t.constructor.isBuffer) && t.constructor.isBuffer(t);
31
31
  }
32
- const Lr = j("ArrayBuffer");
32
+ const xr = j("ArrayBuffer");
33
33
  function ii(t) {
34
34
  let e;
35
- return typeof ArrayBuffer < "u" && ArrayBuffer.isView ? e = ArrayBuffer.isView(t) : e = t && t.buffer && Lr(t.buffer), e;
35
+ return typeof ArrayBuffer < "u" && ArrayBuffer.isView ? e = ArrayBuffer.isView(t) : e = t && t.buffer && xr(t.buffer), e;
36
36
  }
37
- const oi = Ke("string"), k = Ke("function"), kr = Ke("number"), Qe = (t) => t !== null && typeof t == "object", si = (t) => t === !0 || t === !1, Le = (t) => {
37
+ const oi = Ke("string"), k = Ke("function"), kr = Ke("number"), Qe = (t) => t !== null && typeof t == "object", si = (t) => t === !0 || t === !1, xe = (t) => {
38
38
  if (qe(t) !== "object")
39
39
  return !1;
40
40
  const e = kt(t);
@@ -71,14 +71,14 @@ const Fr = (() => typeof globalThis < "u" ? globalThis : typeof self < "u" ? sel
71
71
  function ht() {
72
72
  const { caseless: t } = Nr(this) && this || {}, e = {}, r = (n, i) => {
73
73
  const o = t && Mr(e, i) || i;
74
- Le(e[o]) && Le(n) ? e[o] = ht(e[o], n) : Le(n) ? e[o] = ht({}, n) : he(n) ? e[o] = n.slice() : e[o] = n;
74
+ xe(e[o]) && xe(n) ? e[o] = ht(e[o], n) : xe(n) ? e[o] = ht({}, n) : he(n) ? e[o] = n.slice() : e[o] = n;
75
75
  };
76
76
  for (let n = 0, i = arguments.length; n < i; n++)
77
77
  arguments[n] && Ee(arguments[n], r);
78
78
  return e;
79
79
  }
80
80
  const mi = (t, e, r, { allOwnKeys: n } = {}) => (Ee(e, (i, o) => {
81
- r && k(i) ? t[o] = xr(i, r) : t[o] = i;
81
+ r && k(i) ? t[o] = Lr(i, r) : t[o] = i;
82
82
  }, { allOwnKeys: n }), t), yi = (t) => (t.charCodeAt(0) === 65279 && (t = t.slice(1)), t), gi = (t, e, r, n) => {
83
83
  t.prototype = Object.create(e.prototype, n), t.prototype.constructor = t, Object.defineProperty(t, "super", {
84
84
  value: e.prototype
@@ -160,14 +160,14 @@ const mi = (t, e, r, { allOwnKeys: n } = {}) => (Ee(e, (i, o) => {
160
160
  DIGIT: Qt,
161
161
  ALPHA: et,
162
162
  ALPHA_DIGIT: et + et.toUpperCase() + Qt
163
- }, xi = (t = 16, e = Br.ALPHA_DIGIT) => {
163
+ }, Li = (t = 16, e = Br.ALPHA_DIGIT) => {
164
164
  let r = "";
165
165
  const { length: n } = e;
166
166
  for (; t--; )
167
167
  r += e[Math.random() * n | 0];
168
168
  return r;
169
169
  };
170
- function Li(t) {
170
+ function xi(t) {
171
171
  return !!(t && k(t.append) && t[Symbol.toStringTag] === "FormData" && t[Symbol.iterator]);
172
172
  }
173
173
  const ki = (t) => {
@@ -189,7 +189,7 @@ const ki = (t) => {
189
189
  return r(t, 0);
190
190
  }, Mi = j("AsyncFunction"), Fi = (t) => t && (Qe(t) || k(t)) && k(t.then) && k(t.catch), d = {
191
191
  isArray: he,
192
- isArrayBuffer: Lr,
192
+ isArrayBuffer: xr,
193
193
  isBuffer: ni,
194
194
  isFormData: pi,
195
195
  isArrayBufferView: ii,
@@ -197,7 +197,7 @@ const ki = (t) => {
197
197
  isNumber: kr,
198
198
  isBoolean: si,
199
199
  isObject: Qe,
200
- isPlainObject: Le,
200
+ isPlainObject: xe,
201
201
  isUndefined: Te,
202
202
  isDate: ai,
203
203
  isFile: ci,
@@ -235,8 +235,8 @@ const ki = (t) => {
235
235
  global: Fr,
236
236
  isContextDefined: Nr,
237
237
  ALPHABET: Br,
238
- generateString: xi,
239
- isSpecCompliantForm: Li,
238
+ generateString: Li,
239
+ isSpecCompliantForm: xi,
240
240
  toJSONObject: ki,
241
241
  isAsyncFn: Mi,
242
242
  isThenable: Fi
@@ -332,16 +332,16 @@ function Ye(t, e, r) {
332
332
  return d.isArrayBuffer(h) || d.isTypedArray(h) ? l && typeof Blob == "function" ? new Blob([h]) : Buffer.from(h) : h;
333
333
  }
334
334
  function u(h, y, T) {
335
- let S = h;
335
+ let v = h;
336
336
  if (h && !T && typeof h == "object") {
337
337
  if (d.endsWith(y, "{}"))
338
338
  y = n ? y : y.slice(0, -2), h = JSON.stringify(h);
339
- else if (d.isArray(h) && Ui(h) || (d.isFileList(h) || d.endsWith(y, "[]")) && (S = d.toArray(h)))
340
- return y = Hr(y), S.forEach(function(x, G) {
341
- !(d.isUndefined(x) || x === null) && e.append(
339
+ else if (d.isArray(h) && Ui(h) || (d.isFileList(h) || d.endsWith(y, "[]")) && (v = d.toArray(h)))
340
+ return y = Hr(y), v.forEach(function(L, G) {
341
+ !(d.isUndefined(L) || L === null) && e.append(
342
342
  // eslint-disable-next-line no-nested-ternary
343
343
  s === !0 ? Yt([y], G, o) : s === null ? y : y + "[]",
344
- c(x)
344
+ c(L)
345
345
  );
346
346
  }), !1;
347
347
  }
@@ -356,14 +356,14 @@ function Ye(t, e, r) {
356
356
  if (!d.isUndefined(h)) {
357
357
  if (f.indexOf(h) !== -1)
358
358
  throw Error("Circular reference detected in " + y.join("."));
359
- f.push(h), d.forEach(h, function(S, A) {
360
- (!(d.isUndefined(S) || S === null) && i.call(
359
+ f.push(h), d.forEach(h, function(v, A) {
360
+ (!(d.isUndefined(v) || v === null) && i.call(
361
361
  e,
362
- S,
362
+ v,
363
363
  d.isString(A) ? A.trim() : A,
364
364
  y,
365
365
  p
366
- )) === !0 && m(S, y ? y.concat(A) : [A]);
366
+ )) === !0 && m(v, y ? y.concat(A) : [A]);
367
367
  }), f.pop();
368
368
  }
369
369
  }
@@ -944,10 +944,10 @@ const uo = typeof XMLHttpRequest < "u", fo = uo && function(t) {
944
944
  config: t,
945
945
  request: c
946
946
  };
947
- no(function(S) {
948
- r(S), l();
949
- }, function(S) {
950
- n(S), l();
947
+ no(function(v) {
948
+ r(v), l();
949
+ }, function(v) {
950
+ n(v), l();
951
951
  }, y), c = null;
952
952
  }
953
953
  if ("onloadend" in c ? c.onloadend = f : c.onreadystatechange = function() {
@@ -1400,7 +1400,7 @@ Object.entries(gt).forEach(([t, e]) => {
1400
1400
  });
1401
1401
  const So = gt;
1402
1402
  function Kr(t) {
1403
- const e = new Fe(t), r = xr(Fe.prototype.request, e);
1403
+ const e = new Fe(t), r = Lr(Fe.prototype.request, e);
1404
1404
  return d.extend(r, Fe.prototype, e, { allOwnKeys: !0 }), d.extend(r, e, null, { allOwnKeys: !0 }), r.create = function(i) {
1405
1405
  return Kr(ue(t, i));
1406
1406
  }, r;
@@ -1502,7 +1502,7 @@ var bo = function() {
1502
1502
  c.prototype = r.prototype, i.prototype = new c(), c.prototype = null;
1503
1503
  }
1504
1504
  return i;
1505
- }, Do = Io, Bt = Function.prototype.bind || Do, xo = Bt, Lo = xo.call(Function.call, Object.prototype.hasOwnProperty), C, fe = SyntaxError, Yr = Function, ce = TypeError, ot = function(t) {
1505
+ }, Do = Io, Bt = Function.prototype.bind || Do, Lo = Bt, xo = Lo.call(Function.call, Object.prototype.hasOwnProperty), C, fe = SyntaxError, Yr = Function, ce = TypeError, ot = function(t) {
1506
1506
  try {
1507
1507
  return Yr('"use strict"; return (' + t + ").constructor;")();
1508
1508
  } catch {
@@ -1672,7 +1672,7 @@ var Uo = function t(e) {
1672
1672
  "%URIErrorPrototype%": ["URIError", "prototype"],
1673
1673
  "%WeakMapPrototype%": ["WeakMap", "prototype"],
1674
1674
  "%WeakSetPrototype%": ["WeakSet", "prototype"]
1675
- }, Oe = Bt, Ve = Lo, Bo = Oe.call(Function.call, Array.prototype.concat), jo = Oe.call(Function.apply, Array.prototype.splice), cr = Oe.call(Function.call, String.prototype.replace), ze = Oe.call(Function.call, String.prototype.slice), $o = Oe.call(Function.call, RegExp.prototype.exec), Ho = /[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g, wo = /\\(\\)?/g, Go = function(e) {
1675
+ }, Oe = Bt, Ve = xo, Bo = Oe.call(Function.call, Array.prototype.concat), jo = Oe.call(Function.apply, Array.prototype.splice), cr = Oe.call(Function.call, String.prototype.replace), ze = Oe.call(Function.call, String.prototype.slice), $o = Oe.call(Function.call, RegExp.prototype.exec), Ho = /[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g, wo = /\\(\\)?/g, Go = function(e) {
1676
1676
  var r = ze(e, 0, 1), n = ze(e, -1);
1677
1677
  if (r === "%" && n !== "%")
1678
1678
  throw new fe("invalid intrinsic syntax, expected closing `%`");
@@ -1833,15 +1833,15 @@ var Ct = Qo, gr = Ct.custom, Sr = on(gr) ? gr : null, ss = function t(e, r, n, i
1833
1833
  return typeof e == "object" && !pe ? ve(y) : y;
1834
1834
  }
1835
1835
  if (bs(e)) {
1836
- for (var T = "<" + pr.call(String(e.nodeName)), S = e.attributes || [], A = 0; A < S.length; A++)
1837
- T += " " + S[A].name + "=" + nn(as(S[A].value), "double", o);
1836
+ for (var T = "<" + pr.call(String(e.nodeName)), v = e.attributes || [], A = 0; A < v.length; A++)
1837
+ T += " " + v[A].name + "=" + nn(as(v[A].value), "double", o);
1838
1838
  return T += ">", e.childNodes && e.childNodes.length && (T += "..."), T += "</" + pr.call(String(e.nodeName)) + ">", T;
1839
1839
  }
1840
1840
  if (bt(e)) {
1841
1841
  if (e.length === 0)
1842
1842
  return "[]";
1843
- var x = Ie(e, p);
1844
- return f && !Ts(x) ? "[" + Rt(x, f) + "]" : "[ " + N.call(x, ", ") + " ]";
1843
+ var L = Ie(e, p);
1844
+ return f && !Ts(L) ? "[" + Rt(L, f) + "]" : "[ " + N.call(L, ", ") + " ]";
1845
1845
  }
1846
1846
  if (ls(e)) {
1847
1847
  var G = Ie(e, p);
@@ -2106,7 +2106,7 @@ function Ie(t, e) {
2106
2106
  rn.call(t, o[c]) && n.push("[" + e(o[c]) + "]: " + e(t[o[c]], t));
2107
2107
  return n;
2108
2108
  }
2109
- var Gt = jt, me = Wo, Ps = ss, Os = Gt("%TypeError%"), De = Gt("%WeakMap%", !0), xe = Gt("%Map%", !0), As = me("WeakMap.prototype.get", !0), _s = me("WeakMap.prototype.set", !0), Is = me("WeakMap.prototype.has", !0), Ds = me("Map.prototype.get", !0), xs = me("Map.prototype.set", !0), Ls = me("Map.prototype.has", !0), Vt = function(t, e) {
2109
+ var Gt = jt, me = Wo, Ps = ss, Os = Gt("%TypeError%"), De = Gt("%WeakMap%", !0), Le = Gt("%Map%", !0), As = me("WeakMap.prototype.get", !0), _s = me("WeakMap.prototype.set", !0), Is = me("WeakMap.prototype.has", !0), Ds = me("Map.prototype.get", !0), Ls = me("Map.prototype.set", !0), xs = me("Map.prototype.has", !0), Vt = 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;
@@ -2133,7 +2133,7 @@ var Gt = jt, me = Wo, Ps = ss, Os = Gt("%TypeError%"), De = Gt("%WeakMap%", !0),
2133
2133
  if (De && o && (typeof o == "object" || typeof o == "function")) {
2134
2134
  if (e)
2135
2135
  return As(e, o);
2136
- } else if (xe) {
2136
+ } else if (Le) {
2137
2137
  if (r)
2138
2138
  return Ds(r, o);
2139
2139
  } else if (n)
@@ -2143,15 +2143,15 @@ var Gt = jt, me = Wo, Ps = ss, Os = Gt("%TypeError%"), De = Gt("%WeakMap%", !0),
2143
2143
  if (De && o && (typeof o == "object" || typeof o == "function")) {
2144
2144
  if (e)
2145
2145
  return Is(e, o);
2146
- } else if (xe) {
2146
+ } else if (Le) {
2147
2147
  if (r)
2148
- return Ls(r, o);
2148
+ return xs(r, o);
2149
2149
  } else if (n)
2150
2150
  return Fs(n, o);
2151
2151
  return !1;
2152
2152
  },
2153
2153
  set: function(o, s) {
2154
- De && o && (typeof o == "object" || typeof o == "function") ? (e || (e = new De()), _s(e, o, s)) : xe ? (r || (r = new xe()), xs(r, o, s)) : (n || (n = { key: {}, next: null }), Ms(n, o, s));
2154
+ De && o && (typeof o == "object" || typeof o == "function") ? (e || (e = new De()), _s(e, o, s)) : Le ? (r || (r = new Le()), Ls(r, o, s)) : (n || (n = { key: {}, next: null }), Ms(n, o, s));
2155
2155
  }
2156
2156
  };
2157
2157
  return i;
@@ -2319,46 +2319,46 @@ var Gt = jt, me = Wo, Ps = ss, Os = Gt("%TypeError%"), De = Gt("%WeakMap%", !0),
2319
2319
  }, Zs = function(e) {
2320
2320
  return typeof e == "string" || typeof e == "number" || typeof e == "boolean" || typeof e == "symbol" || typeof e == "bigint";
2321
2321
  }, dt = {}, ea = 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, G = !1; (A = A.get(dt)) !== void 0 && !G; ) {
2322
+ for (var v = e, A = T, L = 0, G = !1; (A = A.get(dt)) !== void 0 && !G; ) {
2323
2323
  var ye = A.get(e);
2324
- if (x += 1, typeof ye < "u") {
2325
- if (ye === x)
2324
+ if (L += 1, typeof ye < "u") {
2325
+ if (ye === L)
2326
2326
  throw new RangeError("Cyclic object value");
2327
2327
  G = !0;
2328
2328
  }
2329
- typeof A.get(dt) > "u" && (x = 0);
2329
+ typeof A.get(dt) > "u" && (L = 0);
2330
2330
  }
2331
- if (typeof l == "function" ? S = l(r, S) : S instanceof Date ? S = f(S) : n === "comma" && H(S) && (S = Ne.maybeMap(S, function(oe) {
2331
+ if (typeof l == "function" ? v = l(r, v) : v instanceof Date ? v = f(v) : n === "comma" && H(v) && (v = Ne.maybeMap(v, function(oe) {
2332
2332
  return oe instanceof Date ? f(oe) : oe;
2333
- })), S === null) {
2333
+ })), v === null) {
2334
2334
  if (o)
2335
2335
  return a && !h ? a(r, _.encoder, y, "key", p) : r;
2336
- S = "";
2336
+ v = "";
2337
2337
  }
2338
- if (Zs(S) || Ne.isBuffer(S)) {
2338
+ if (Zs(v) || Ne.isBuffer(v)) {
2339
2339
  if (a) {
2340
2340
  var Ae = h ? r : a(r, _.encoder, y, "key", p);
2341
- return [m(Ae) + "=" + m(a(S, _.encoder, y, "value", p))];
2341
+ return [m(Ae) + "=" + m(a(v, _.encoder, y, "value", p))];
2342
2342
  }
2343
- return [m(r) + "=" + m(String(S))];
2343
+ return [m(r) + "=" + m(String(v))];
2344
2344
  }
2345
2345
  var K = [];
2346
- if (typeof S > "u")
2346
+ if (typeof v > "u")
2347
2347
  return K;
2348
2348
  var V;
2349
- if (n === "comma" && H(S))
2350
- h && a && (S = Ne.maybeMap(S, a)), V = [{ value: S.length > 0 ? S.join(",") || null : void 0 }];
2349
+ if (n === "comma" && H(v))
2350
+ h && a && (v = Ne.maybeMap(v, a)), V = [{ value: v.length > 0 ? v.join(",") || null : void 0 }];
2351
2351
  else if (H(l))
2352
2352
  V = l;
2353
2353
  else {
2354
- var re = Object.keys(S);
2354
+ var re = Object.keys(v);
2355
2355
  V = c ? re.sort(c) : re;
2356
2356
  }
2357
- for (var ne = i && H(S) && S.length === 1 ? r + "[]" : r, ge = 0; ge < V.length; ++ge) {
2358
- var M = V[ge], $ = typeof M == "object" && typeof M.value < "u" ? M.value : S[M];
2357
+ for (var ne = i && H(v) && v.length === 1 ? r + "[]" : r, ge = 0; ge < V.length; ++ge) {
2358
+ var M = V[ge], $ = typeof M == "object" && typeof M.value < "u" ? M.value : v[M];
2359
2359
  if (!(s && $ === null)) {
2360
- var ie = H(S) ? typeof n == "function" ? n(ne, M) : ne : ne + (u ? "." + M : "[" + M + "]");
2361
- T.set(e, x);
2360
+ var ie = H(v) ? typeof n == "function" ? n(ne, M) : ne : ne + (u ? "." + M : "[" + M + "]");
2361
+ T.set(e, L);
2362
2362
  var _e = un();
2363
2363
  _e.set(dt, T), fn(K, t(
2364
2364
  $,
@@ -2367,7 +2367,7 @@ var Gt = jt, me = Wo, Ps = ss, Os = Gt("%TypeError%"), De = Gt("%WeakMap%", !0),
2367
2367
  i,
2368
2368
  o,
2369
2369
  s,
2370
- n === "comma" && h && H(S) ? null : a,
2370
+ n === "comma" && h && H(v) ? null : a,
2371
2371
  l,
2372
2372
  c,
2373
2373
  u,
@@ -2613,7 +2613,7 @@ class ga {
2613
2613
  console.debug("onDataChannelMessage:", e);
2614
2614
  }
2615
2615
  }
2616
- var v = /* @__PURE__ */ ((t) => (t[t.UNKNOWN = 0] = "UNKNOWN", t[t.AUDIO = 1] = "AUDIO", t[t.VIDEO = 2] = "VIDEO", t[t.RTSP_PULL = 3] = "RTSP_PULL", t[t.AUDIO_PUSH = 4] = "AUDIO_PUSH", t[t.VIDEO_PUSH = 5] = "VIDEO_PUSH", t[t.AUDIO_HALF = 6] = "AUDIO_HALF", t[t.VIDEO_HALF = 7] = "VIDEO_HALF", t))(v || {}), Q = /* @__PURE__ */ ((t) => (t.FRONT_FACING = "user", t.BACK_FACING = "environment", t))(Q || {});
2616
+ var S = /* @__PURE__ */ ((t) => (t[t.UNKNOWN = 0] = "UNKNOWN", t[t.AUDIO = 1] = "AUDIO", t[t.VIDEO = 2] = "VIDEO", t[t.RTSP_PULL = 3] = "RTSP_PULL", t[t.AUDIO_PUSH = 4] = "AUDIO_PUSH", t[t.VIDEO_PUSH = 5] = "VIDEO_PUSH", t[t.AUDIO_HALF = 6] = "AUDIO_HALF", t[t.VIDEO_HALF = 7] = "VIDEO_HALF", t))(S || {}), Q = /* @__PURE__ */ ((t) => (t.FRONT_FACING = "user", t.BACK_FACING = "environment", t))(Q || {});
2617
2617
  let hn = !0, mn = !0;
2618
2618
  function Ue(t, e, r) {
2619
2619
  const n = t.match(e);
@@ -3349,14 +3349,14 @@ function Dn(t) {
3349
3349
  return this._pc.getStats(this.track);
3350
3350
  };
3351
3351
  }
3352
- function xn(t) {
3352
+ function Ln(t) {
3353
3353
  !t.RTCPeerConnection || "removeStream" in t.RTCPeerConnection.prototype || (t.RTCPeerConnection.prototype.removeStream = function(r) {
3354
3354
  Jt("removeStream", "removeTrack"), this.getSenders().forEach((n) => {
3355
3355
  n.track && r.getTracks().includes(n.track) && this.removeTrack(n);
3356
3356
  });
3357
3357
  });
3358
3358
  }
3359
- function Ln(t) {
3359
+ function xn(t) {
3360
3360
  t.DataChannel && !t.RTCDataChannel && (t.RTCDataChannel = t.DataChannel);
3361
3361
  }
3362
3362
  function kn(t) {
@@ -3430,9 +3430,9 @@ const Ar = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
3430
3430
  shimGetUserMedia: An,
3431
3431
  shimOnTrack: _n,
3432
3432
  shimPeerConnection: Ot,
3433
- shimRTCDataChannel: Ln,
3433
+ shimRTCDataChannel: xn,
3434
3434
  shimReceiverGetStats: Dn,
3435
- shimRemoveStream: xn,
3435
+ shimRemoveStream: Ln,
3436
3436
  shimSenderGetStats: In
3437
3437
  }, Symbol.toStringTag, { value: "Module" }));
3438
3438
  function Un(t) {
@@ -4241,7 +4241,7 @@ function Pa({ window: t } = {}, e = {
4241
4241
  case "firefox":
4242
4242
  if (!Ar || !Ot || !e.shimFirefox)
4243
4243
  return r("Firefox shim is not included in this adapter release."), i;
4244
- r("adapter.js shimming firefox."), i.browserShim = Ar, He(t, n), we(t), An(t, n), Ot(t, n), _n(t), xn(t), In(t), Dn(t), Ln(t), kn(t), Mn(t), Fn(t), Nn(t), Be(t), _t(t), je(t, n), $e(t);
4244
+ r("adapter.js shimming firefox."), i.browserShim = Ar, He(t, n), we(t), An(t, n), Ot(t, n), _n(t), Ln(t), In(t), Dn(t), xn(t), kn(t), Mn(t), Fn(t), Nn(t), Be(t), _t(t), je(t, n), $e(t);
4245
4245
  break;
4246
4246
  case "safari":
4247
4247
  if (!_r || !e.shimSafari)
@@ -4265,7 +4265,7 @@ class Wt {
4265
4265
  // 呼叫方向
4266
4266
  g(this, "isCallOut", !1);
4267
4267
  // 会话类型
4268
- g(this, "sessionType", v.UNKNOWN);
4268
+ g(this, "sessionType", S.UNKNOWN);
4269
4269
  // 本地媒体流
4270
4270
  g(this, "localStream");
4271
4271
  // 对端媒体流
@@ -4304,10 +4304,10 @@ class Wt {
4304
4304
  }
4305
4305
  switch (this.isCallOut = e, this.hasSetRemoteSdp = !1, this.facingMode = Q.FRONT_FACING, this.facingChanging = !1, this.muted = !1, this.peerConnection = new RTCPeerConnection({ iceServers: [] }), this.peerConnection.onnegotiationneeded = () => {
4306
4306
  switch (this.sessionType) {
4307
- case v.AUDIO_PUSH:
4308
- case v.VIDEO_PUSH:
4309
- case v.AUDIO_HALF:
4310
- case v.VIDEO_HALF:
4307
+ case S.AUDIO_PUSH:
4308
+ case S.VIDEO_PUSH:
4309
+ case S.AUDIO_HALF:
4310
+ case S.VIDEO_HALF:
4311
4311
  this.createDataChannel();
4312
4312
  }
4313
4313
  e ? (console.debug("webrtc call out"), this.peerConnection.createOffer().then((n) => {
@@ -4348,15 +4348,15 @@ class Wt {
4348
4348
  var i, o, s, a, l;
4349
4349
  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.")));
4350
4350
  }, this.sessionType) {
4351
- case v.RTSP_PULL:
4351
+ case S.RTSP_PULL:
4352
4352
  this.addTransceivers(), this.createDataChannel();
4353
4353
  break;
4354
- case v.AUDIO_PUSH:
4355
- case v.VIDEO_PUSH:
4356
- case v.AUDIO_HALF:
4357
- case v.VIDEO_HALF:
4358
- case v.VIDEO:
4359
- case v.AUDIO:
4354
+ case S.AUDIO_PUSH:
4355
+ case S.VIDEO_PUSH:
4356
+ case S.AUDIO_HALF:
4357
+ case S.VIDEO_HALF:
4358
+ case S.VIDEO:
4359
+ case S.AUDIO:
4360
4360
  this.gotLocalMedia();
4361
4361
  break;
4362
4362
  default:
@@ -4394,7 +4394,7 @@ class Wt {
4394
4394
  */
4395
4395
  stop() {
4396
4396
  var e;
4397
- console.debug("webrtc stop"), (this.sessionType == v.VIDEO_PUSH || this.sessionType == v.AUDIO_PUSH || this.sessionType == v.RTSP_PULL) && this.sendStringData("close"), (e = this.peerConnection) == null || e.close(), this.peerConnection = void 0, this.localStream && (this.localStream.getTracks().forEach((r) => {
4397
+ console.debug("webrtc stop"), (this.sessionType == S.VIDEO_PUSH || this.sessionType == S.AUDIO_PUSH || this.sessionType == S.RTSP_PULL) && this.sendStringData("close"), (e = this.peerConnection) == null || e.close(), this.peerConnection = void 0, this.localStream && (this.localStream.getTracks().forEach((r) => {
4398
4398
  this.localStream.removeTrack(r), r.stop();
4399
4399
  }), this.localStream = void 0), this.remoteStream = void 0;
4400
4400
  }
@@ -4405,7 +4405,7 @@ class Wt {
4405
4405
  */
4406
4406
  changeFacing() {
4407
4407
  return new Promise((e, r) => {
4408
- if (this.sessionType !== v.VIDEO && this.sessionType !== v.VIDEO_PUSH) {
4408
+ if (this.sessionType !== S.VIDEO && this.sessionType !== S.VIDEO_PUSH) {
4409
4409
  r(new Error("not video call"));
4410
4410
  return;
4411
4411
  }
@@ -4463,9 +4463,9 @@ class Wt {
4463
4463
  audio: { echoCancellation: !0, noiseSuppression: !0 }
4464
4464
  };
4465
4465
  switch (this.sessionType) {
4466
- case v.VIDEO:
4467
- case v.VIDEO_PUSH:
4468
- case v.VIDEO_HALF:
4466
+ case S.VIDEO:
4467
+ case S.VIDEO_PUSH:
4468
+ case S.VIDEO_HALF:
4469
4469
  e.video = { height: { exact: 720 }, width: { exact: 1280 } };
4470
4470
  break;
4471
4471
  }
@@ -4476,10 +4476,10 @@ class Wt {
4476
4476
  }) : this.error(new Error("Browser does not support WebRTC"));
4477
4477
  }
4478
4478
  getMediaSuccess(e) {
4479
- console.debug("webrtc getMediaSuccess"), this.localStream = e, (this.sessionType === v.VIDEO || this.sessionType === v.VIDEO_PUSH) && this.sessionListener.onAddLocalStream(e), e.getTracks().forEach((r) => {
4479
+ console.debug("webrtc getMediaSuccess"), this.localStream = e, (this.sessionType === S.VIDEO || this.sessionType === S.VIDEO_PUSH || this.sessionType === S.VIDEO_HALF) && this.sessionListener.onAddLocalStream(e), e.getTracks().forEach((r) => {
4480
4480
  switch (this.sessionType) {
4481
- case v.AUDIO_PUSH:
4482
- case v.VIDEO_PUSH:
4481
+ case S.AUDIO_PUSH:
4482
+ case S.VIDEO_PUSH:
4483
4483
  this.peerConnection.addTransceiver(r, { direction: "sendonly", streams: [e] });
4484
4484
  break;
4485
4485
  default:
@@ -4488,11 +4488,14 @@ class Wt {
4488
4488
  }), this.muted = !1;
4489
4489
  }
4490
4490
  getMediaFailed(e) {
4491
- if (console.debug("webrtc getMediaFailed failed"), this.sessionType === v.VIDEO) {
4492
- console.error("get video media failed. maybe not found camera.", e), this.sessionType = v.AUDIO, this.gotLocalMedia();
4491
+ if (console.debug("webrtc getMediaFailed failed"), this.sessionType === S.VIDEO) {
4492
+ console.error("get video media failed. maybe not found camera.", e), this.sessionType = S.AUDIO, this.gotLocalMedia();
4493
+ return;
4494
+ } else if (this.sessionType === S.VIDEO_PUSH) {
4495
+ console.error("get video media failed. maybe not found camera.", e), this.sessionType = S.AUDIO_PUSH, this.gotLocalMedia();
4493
4496
  return;
4494
- } else if (this.sessionType === v.VIDEO_PUSH) {
4495
- console.error("get video media failed. maybe not found camera.", e), this.sessionType = v.AUDIO_PUSH, this.gotLocalMedia();
4497
+ } else if (this.sessionType === S.VIDEO_HALF) {
4498
+ console.error("get video media failed. maybe not found camera.", e), this.sessionType = S.AUDIO_HALF, this.gotLocalMedia();
4496
4499
  return;
4497
4500
  }
4498
4501
  this.error(e);
@@ -4511,7 +4514,7 @@ class Wt {
4511
4514
  console.debug("data channel receive from server: close"), this.dataChannel = void 0, this.stop();
4512
4515
  return;
4513
4516
  }
4514
- (this.sessionType == v.VIDEO_HALF || this.sessionType == v.AUDIO_HALF) && this.sessionListener.onDataChannelMessage(e);
4517
+ (this.sessionType == S.VIDEO_HALF || this.sessionType == S.AUDIO_HALF) && this.sessionListener.onDataChannelMessage(e);
4515
4518
  }
4516
4519
  changeCameraLocalMedia() {
4517
4520
  return new Promise((e, r) => {
@@ -4580,7 +4583,7 @@ class _a {
4580
4583
  */
4581
4584
  constructor(e, r) {
4582
4585
  g(this, "rtspUrl");
4583
- g(this, "webrtcSession", new Wt(v.RTSP_PULL));
4586
+ g(this, "webrtcSession", new Wt(S.RTSP_PULL));
4584
4587
  g(this, "sessionListener", new Oa());
4585
4588
  g(this, "httpClient");
4586
4589
  this.rtspUrl = e, this.httpClient = r, this.webrtcSession.setListener(this);
@@ -4618,7 +4621,7 @@ class _a {
4618
4621
  onDataChannelMessage(e) {
4619
4622
  }
4620
4623
  }
4621
- 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 || {}), D = /* @__PURE__ */ ((t) => (t.VIDEO = "video", t.AUDIO = "audio", t))(D || {}), U = /* @__PURE__ */ ((t) => (t.FULL = "full-duplex", t.HALF = "half-duplex", t))(U || {}), Y = /* @__PURE__ */ ((t) => (t.IN = "in", t.OUT = "out", t))(Y || {}), L = /* @__PURE__ */ ((t) => (t.LOGIN = "login", t.LOGOUT = "logout", t.Invite = "invite", t.RING = "ring", t.ANSWER = "answer", t.HANGUP = "hangup", t.DTMF = "dtmf", t))(L || {});
4624
+ 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 || {}), D = /* @__PURE__ */ ((t) => (t.VIDEO = "video", t.AUDIO = "audio", t))(D || {}), U = /* @__PURE__ */ ((t) => (t.FULL = "full-duplex", t.HALF = "half-duplex", t))(U || {}), Y = /* @__PURE__ */ ((t) => (t.IN = "in", t.OUT = "out", t))(Y || {}), x = /* @__PURE__ */ ((t) => (t.LOGIN = "login", t.LOGOUT = "logout", t.Invite = "invite", t.RING = "ring", t.ANSWER = "answer", t.HANGUP = "hangup", t.DTMF = "dtmf", t))(x || {});
4622
4625
  function Dr() {
4623
4626
  try {
4624
4627
  return !!(navigator.mediaDevices && navigator.mediaDevices.getUserMedia);
@@ -4627,13 +4630,13 @@ function Dr() {
4627
4630
  }
4628
4631
  }
4629
4632
  function Ia() {
4630
- return "browser-" + Da() + xa(6);
4633
+ return "browser-" + Da() + La(6);
4631
4634
  }
4632
4635
  function Da() {
4633
4636
  let t = /* @__PURE__ */ new Date();
4634
4637
  return `${t.getFullYear()}${t.getMonth()}${t.getDate()}${t.getHours()}${t.getMinutes()}${t.getSeconds()}`;
4635
4638
  }
4636
- function xa(t) {
4639
+ function La(t) {
4637
4640
  let e = "", r = [
4638
4641
  "0",
4639
4642
  "1",
@@ -4677,7 +4680,7 @@ function xa(t) {
4677
4680
  e += r[Math.floor(Math.random() * (r.length - 1))];
4678
4681
  return e;
4679
4682
  }
4680
- class La {
4683
+ class xa {
4681
4684
  constructor(e, r, n) {
4682
4685
  g(this, "tel");
4683
4686
  g(this, "mediaType");
@@ -4760,7 +4763,7 @@ class Qn {
4760
4763
  return;
4761
4764
  }
4762
4765
  let e;
4763
- this.callMode == U.HALF ? e = D.VIDEO == this.mediaType ? v.VIDEO_HALF : v.AUDIO_HALF : e = D.VIDEO == this.mediaType ? v.VIDEO : v.AUDIO, this.webrtcCreate(e), (r = this.webrtcSession) == null || r.start(!1, this.remoteSdp);
4766
+ this.callMode == U.HALF ? e = D.VIDEO == this.mediaType ? S.VIDEO_HALF : S.AUDIO_HALF : e = D.VIDEO == this.mediaType ? S.VIDEO : S.AUDIO, this.webrtcCreate(e), (r = this.webrtcSession) == null || r.start(!1, this.remoteSdp);
4764
4767
  }
4765
4768
  hangup() {
4766
4769
  this.status <= R.IDLE || (this.status == R.TALK ? this.sendHangup(this.callId ?? "") : this.callDirect == Y.IN ? this.sendHangup(this.callId ?? "", 488) : this.sendHangup(this.callId ?? "", 801), this.close());
@@ -4816,7 +4819,7 @@ class Qn {
4816
4819
  }
4817
4820
  this.status > R.IDLE && (console.debug("Another call is currently in progress, hangup it"), this.hangup()), this.mediaType = r, this.callMode = n, this.called = e, this.callDirect = Y.OUT, this.callId = Ia();
4818
4821
  let o;
4819
- this.callMode == U.HALF ? o = D.VIDEO == r ? v.VIDEO_HALF : v.AUDIO_HALF : o = D.VIDEO == r ? v.VIDEO : v.AUDIO, this.webrtcCreate(o), (i = this.webrtcSession) == null || i.start(!0), this.status = R.TRY;
4822
+ this.callMode == U.HALF ? o = D.VIDEO == r ? S.VIDEO_HALF : S.AUDIO_HALF : o = D.VIDEO == r ? S.VIDEO : S.AUDIO, this.webrtcCreate(o), (i = this.webrtcSession) == null || i.start(!0), this.status = R.TRY;
4820
4823
  } catch (o) {
4821
4824
  this.status = R.IDLE, this.sessionListener.onError(new Error("" + o));
4822
4825
  }
@@ -4840,19 +4843,19 @@ class Qn {
4840
4843
  try {
4841
4844
  let n = JSON.parse(r.data);
4842
4845
  switch (console.debug("receive msg from server <<<<<<<<<<<<<<<", n), n.type) {
4843
- case L.Invite:
4846
+ case x.Invite:
4844
4847
  this.inviteHandler(n);
4845
4848
  break;
4846
- case L.ANSWER:
4849
+ case x.ANSWER:
4847
4850
  this.answerHandler(n);
4848
4851
  break;
4849
- case L.RING:
4852
+ case x.RING:
4850
4853
  this.ringHandler(n);
4851
4854
  break;
4852
- case L.HANGUP:
4855
+ case x.HANGUP:
4853
4856
  this.hangupHandler(n);
4854
4857
  break;
4855
- case L.LOGIN:
4858
+ case x.LOGIN:
4856
4859
  this.loginHandler(n);
4857
4860
  break;
4858
4861
  }
@@ -4873,7 +4876,7 @@ class Qn {
4873
4876
  }
4874
4877
  sendLogin() {
4875
4878
  this.sendTo({
4876
- type: L.LOGIN,
4879
+ type: x.LOGIN,
4877
4880
  username: this.tel,
4878
4881
  userAgent: this.getUserAgent(),
4879
4882
  accountId: this.accountId
@@ -4881,14 +4884,14 @@ class Qn {
4881
4884
  }
4882
4885
  sendLogout() {
4883
4886
  this.sendTo({
4884
- type: L.LOGOUT,
4887
+ type: x.LOGOUT,
4885
4888
  username: this.tel
4886
4889
  }), this.status = R.OFFLINE;
4887
4890
  }
4888
4891
  sendInvite(e) {
4889
4892
  this.sendTo({
4890
4893
  callId: this.callId,
4891
- type: L.Invite,
4894
+ type: x.Invite,
4892
4895
  from: this.tel,
4893
4896
  to: this.called,
4894
4897
  callMode: this.callMode,
@@ -4898,14 +4901,14 @@ class Qn {
4898
4901
  }
4899
4902
  sendRing() {
4900
4903
  this.sendTo({
4901
- type: L.RING,
4904
+ type: x.RING,
4902
4905
  callId: this.callId,
4903
4906
  code: 180
4904
4907
  }), this.status = R.RING;
4905
4908
  }
4906
4909
  sendAnswer(e) {
4907
4910
  this.sendTo({
4908
- type: L.ANSWER,
4911
+ type: x.ANSWER,
4909
4912
  callId: this.callId,
4910
4913
  mediaType: this.mediaType,
4911
4914
  sdp: e
@@ -4913,7 +4916,7 @@ class Qn {
4913
4916
  }
4914
4917
  sendDtmf(e) {
4915
4918
  this.sendTo({
4916
- type: L.DTMF,
4919
+ type: x.DTMF,
4917
4920
  callId: this.callId,
4918
4921
  callInfo: "dtmf=" + e
4919
4922
  }), this.dtmfAudio.play().then(() => {
@@ -4921,7 +4924,7 @@ class Qn {
4921
4924
  }
4922
4925
  sendHangup(e, r = 800) {
4923
4926
  this.sendTo({
4924
- type: L.HANGUP,
4927
+ type: x.HANGUP,
4925
4928
  callId: e,
4926
4929
  code: r
4927
4930
  }), e == this.callId && (this.status = R.IDLE, this.callId = void 0);
@@ -4949,7 +4952,7 @@ class Qn {
4949
4952
  }
4950
4953
  this.callId = e.callId, this.mediaType = e.mediaType ?? D.AUDIO, this.callMode = e.callMode ?? U.FULL, this.called = e.from ?? "", this.callDirect = Y.IN, this.remoteSdp = e.sdp, this.candidate = e.candidate, this.sendRing(), this.ringtone.currentTime = 0, this.ringtone.play().then(() => {
4951
4954
  }).catch(() => {
4952
- }), this.sessionListener.onNewCall(new La(this.called, this.mediaType, this.callMode));
4955
+ }), this.sessionListener.onNewCall(new xa(this.called, this.mediaType, this.callMode));
4953
4956
  }
4954
4957
  ringHandler(e) {
4955
4958
  var r, n;
@@ -5014,7 +5017,7 @@ class Fa {
5014
5017
  g(this, "webrtcSession");
5015
5018
  g(this, "sessionListener", new ka());
5016
5019
  g(this, "httpClient");
5017
- this.tel = e, this.httpClient = r, this.mediaType = n === D.VIDEO ? D.VIDEO : D.AUDIO, this.webrtcSession = new Wt(n == D.VIDEO ? v.VIDEO_PUSH : v.AUDIO_PUSH), this.webrtcSession.setListener(this);
5020
+ this.tel = e, this.httpClient = r, this.mediaType = n === D.VIDEO ? D.VIDEO : D.AUDIO, this.webrtcSession = new Wt(n == D.VIDEO ? S.VIDEO_PUSH : S.AUDIO_PUSH), this.webrtcSession.setListener(this);
5018
5021
  }
5019
5022
  setBroadcastSessionListener(e) {
5020
5023
  this.sessionListener = e;
@@ -5089,7 +5092,7 @@ class Ua extends Qn {
5089
5092
  }
5090
5093
  }
5091
5094
  }
5092
- let qt = new dn("/"), Yn = "/media-server/ws/voip", Xn = "/media-server/ws/b-trun-c", xt = new URL((location.protocol == "https:" ? "wss://" : "ws://") + location.host + Yn), Lt = new URL((location.protocol == "https:" ? "wss://" : "ws://") + location.host + Xn);
5095
+ let qt = new dn("/"), Yn = "/media-server/ws/voip", Xn = "/media-server/ws/b-trun-c", Lt = new URL((location.protocol == "https:" ? "wss://" : "ws://") + location.host + Yn), xt = new URL((location.protocol == "https:" ? "wss://" : "ws://") + location.host + Xn);
5093
5096
  function ja(t) {
5094
5097
  qt = new dn(t);
5095
5098
  }
@@ -5100,13 +5103,13 @@ function Ha(t, e) {
5100
5103
  return new Fa(t, qt, e);
5101
5104
  }
5102
5105
  function wa(t) {
5103
- xt = new URL(t), xt.pathname = Yn, Lt = new URL(t), Lt.pathname = Xn;
5106
+ Lt = new URL(t), Lt.pathname = Yn, xt = new URL(t), xt.pathname = Xn;
5104
5107
  }
5105
5108
  function Ga(t) {
5106
- return new Qn(xt.toString(), t);
5109
+ return new Qn(Lt.toString(), t);
5107
5110
  }
5108
5111
  function Va(t, e) {
5109
- return new Ua(Lt.toString(), t, e);
5112
+ return new Ua(xt.toString(), t, e);
5110
5113
  }
5111
5114
  export {
5112
5115
  Va as createAppCallSession,
@@ -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})(Jn);var Wn=Jn.exports;const he=Or(Wn),ga=x({__proto__:null,default:he},[Wn]);function Qe(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=he.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,re(t,"icecandidate",r=>(r.candidate&&Object.defineProperty(r,"candidate",{value:new t.RTCIceCandidate(r.candidate),writable:"false"}),r))}function Vt(t){!t.RTCIceCandidate||t.RTCIceCandidate&&"relayProtocol"in t.RTCIceCandidate.prototype||re(t,"icecandidate",e=>{if(e.candidate){const r=he.parseCandidate(e.candidate.candidate);r.type==="relay"&&(e.candidate.relayProtocol={0:"tls",1:"tcp",2:"udp"}[r.priority>>24])}return e})}function Ye(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=he.splitSections(a.sdp);return l.shift(),l.some(c=>{const u=he.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=he.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 Xe(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},re(t,"datachannel",n=>(e(n.channel,n.target),n))}function zt(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 Jt(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 Ze(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 et(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 Sa=Object.freeze(Object.defineProperty({__proto__:null,removeExtmapAllowMixed:Jt,shimAddIceCandidateNullOrEmpty:Ze,shimConnectionState:zt,shimMaxMessageSize:Ye,shimParameterlessSetLocalDescription:et,shimRTCIceCandidate:Qe,shimRTCIceCandidateRelayProtocol:Vt,shimSendThrowTypeError:Xe},Symbol.toStringTag,{value:"Module"}));function va({window:t}={},e={shimChrome:!0,shimFirefox:!0,shimSafari:!0}){const r=un,n=ha(t),i={browserDetails:n,commonShim:Sa,extractVersion:Ke,disableLog:pa,disableWarnings:da,sdp:ga};switch(n.browser){case"chrome":if(!En||!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=En,Ze(t,n),et(t),mn(t,n),yn(t),wt(t,n),gn(t),Rn(t,n),Sn(t),vn(t),Cn(t),Tn(t,n),Qe(t),Vt(t),zt(t),Ye(t,n),Xe(t),Jt(t,n);break;case"firefox":if(!Fn||!Gt||!e.shimFirefox)return r("Firefox shim is not included in this adapter release."),i;r("adapter.js shimming firefox."),i.browserShim=Fn,Ze(t,n),et(t),Pn(t,n),Gt(t,n),On(t),In(t),An(t),_n(t),Dn(t),Ln(t),xn(t),Mn(t),kn(t),Qe(t),zt(t),Ye(t,n),Xe(t);break;case"safari":if(!zn||!e.shimSafari)return r("Safari shim is not included in this adapter release."),i;r("adapter.js shimming safari."),i.browserShim=zn,Ze(t,n),et(t),Hn(t),Gn(t),Bn(t),Nn(t),Un(t),wn(t),jn(t),Vn(t),Qe(t),Vt(t),Ye(t,n),Xe(t),Jt(t,n);break;default:r("Unsupported browser!");break}return i}const qn=va({window:typeof window>"u"?void 0:window});class Wt{constructor(e){g(this,"peerConnection");g(this,"sessionListener",new fa);g(this,"isCallOut",!1);g(this,"sessionType",S.UNKNOWN);g(this,"localStream");g(this,"remoteStream");g(this,"dataChannel");g(this,"hasSetRemoteSdp",!1);g(this,"facingMode",te.FRONT_FACING);g(this,"facingChanging",!1);g(this,"muted",!1);g(this,"openCamera",!1);this.sessionType=e,console.debug(qn.browserDetails.browser+" "+qn.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=te.FRONT_FACING,this.facingChanging=!1,this.muted=!1,this.peerConnection=new RTCPeerConnection({iceServers:[]}),this.peerConnection.onnegotiationneeded=()=>{switch(this.sessionType){case S.AUDIO_PUSH:case S.VIDEO_PUSH:case S.AUDIO_HALF:case S.VIDEO_HALF:this.createDataChannel()}e?(console.debug("webrtc call out"),this.peerConnection.createOffer().then(n=>{console.debug("webrtc createOffer success"),this.peerConnection.setLocalDescription(n).then(()=>{console.debug("webrtc setLocalDescription success")}).catch(i=>{this.error(i)})}).catch(n=>{this.error(n)})):(console.debug("webrtc call in: ",r),this.peerConnection.setRemoteDescription(new RTCSessionDescription({type:"offer",sdp:r})).then(()=>{console.debug("webrtc setRemoteDescription success"),this.peerConnection.createAnswer().then(n=>{console.debug("webrtc createAnswer success"),this.peerConnection.setLocalDescription(n).then(()=>{console.debug("webrtc setLocalDescription success")}).catch(i=>{this.error(i)})}).catch(n=>{this.error(n)})}).catch(n=>{this.error(n)}))},this.peerConnection.onicegatheringstatechange=()=>{var n;console.debug("webrtc onicegatheringstatechange",(n=this.peerConnection)==null?void 0:n.iceGatheringState),this.peerConnection&&this.peerConnection.iceGatheringState=="complete"&&this.peerConnection.localDescription&&this.sessionListener.onStartSuccess(this.peerConnection.localDescription)},this.peerConnection.ontrack=n=>{console.debug("webrtc ontrack");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 S.RTSP_PULL:this.addTransceivers(),this.createDataChannel();break;case S.AUDIO_PUSH:case S.VIDEO_PUSH:case S.AUDIO_HALF:case S.VIDEO_HALF:case S.VIDEO:case S.AUDIO:this.gotLocalMedia();break;default:this.error(new Error("session type unknown: "+this.sessionType));break}}setRemoteSdp(e){e&&e!==""&&this.peerConnection&&this.isCallOut&&!this.hasSetRemoteSdp&&(this.hasSetRemoteSdp=!0,this.peerConnection.setRemoteDescription(new RTCSessionDescription({type:"answer",sdp:e})).then(()=>{console.debug("webrtc setRemoteDescription success")}).catch(r=>{this.error(r),this.hasSetRemoteSdp=!1}))}addRemoteCandidate(e){this.peerConnection&&e.forEach(r=>{this.peerConnection.addIceCandidate(r).then(()=>{console.debug("webrtc addIceCandidate success")}).catch(n=>console.log(n))})}sendStringData(e){this.dataChannel&&this.dataChannel.send(e)}stop(){var e;console.debug("webrtc stop"),(this.sessionType==S.VIDEO_PUSH||this.sessionType==S.AUDIO_PUSH||this.sessionType==S.RTSP_PULL)&&this.sendStringData("close"),(e=this.peerConnection)==null||e.close(),this.peerConnection=void 0,this.localStream&&(this.localStream.getTracks().forEach(r=>{this.localStream.removeTrack(r),r.stop()}),this.localStream=void 0),this.remoteStream=void 0}changeFacing(){return new Promise((e,r)=>{if(this.sessionType!==S.VIDEO&&this.sessionType!==S.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){console.debug("webrtc error: ",e),this.stop(),this.sessionListener.onError(e)}addTransceivers(){this.peerConnection.addTransceiver("audio",{direction:"recvonly"}),this.peerConnection.addTransceiver("video",{direction:"recvonly"})}gotLocalMedia(){let e={audio:{echoCancellation:!0,noiseSuppression:!0}};switch(this.sessionType){case S.VIDEO:case S.VIDEO_PUSH:case S.VIDEO_HALF:e.video={height:{exact:720},width:{exact:1280}};break}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){console.debug("webrtc getMediaSuccess"),this.localStream=e,(this.sessionType===S.VIDEO||this.sessionType===S.VIDEO_PUSH)&&this.sessionListener.onAddLocalStream(e),e.getTracks().forEach(r=>{switch(this.sessionType){case S.AUDIO_PUSH:case S.VIDEO_PUSH:this.peerConnection.addTransceiver(r,{direction:"sendonly",streams:[e]});break;default:this.peerConnection.addTrack(r,e)}}),this.muted=!1}getMediaFailed(e){if(console.debug("webrtc getMediaFailed failed"),this.sessionType===S.VIDEO){console.error("get video media failed. maybe not found camera.",e),this.sessionType=S.AUDIO,this.gotLocalMedia();return}else if(this.sessionType===S.VIDEO_PUSH){console.error("get video media failed. maybe not found camera.",e),this.sessionType=S.AUDIO_PUSH,this.gotLocalMedia();return}this.error(e)}createDataChannel(){this.peerConnection&&(this.isCallOut?(this.dataChannel=this.peerConnection.createDataChannel("command_channel"),this.dataChannel.onmessage=e=>{this.onDataChannelReceive(e.data)}):this.peerConnection.ondatachannel=e=>{this.dataChannel=e.channel,this.dataChannel.onmessage=r=>{this.onDataChannelReceive(r.data)}})}onDataChannelReceive(e){if(e==="close"){console.debug("data channel receive from server: close"),this.dataChannel=void 0,this.stop();return}(this.sessionType==S.VIDEO_HALF||this.sessionType==S.AUDIO_HALF)&&this.sessionListener.onDataChannelMessage(e)}changeCameraLocalMedia(){return new Promise((e,r)=>{let n;if(this.facingMode===te.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===te.FRONT_FACING?this.facingMode=te.BACK_FACING:this.facingMode=te.FRONT_FACING,this.facingChanging=!1}changeCameraFailed(e){console.log(e),this.facingChanging=!1}}class Ca{onAddRemoteStream(e){console.debug("onAddRemoteStream:",e)}onError(e){console.debug("onError:",e)}}class Kn{constructor(e,r){g(this,"url");g(this,"offerSdp");this.url=e,this.offerSdp=r}}const ba="/media-server/video-play/webrtc";class Ra{constructor(e,r){g(this,"rtspUrl");g(this,"webrtcSession",new Wt(S.RTSP_PULL));g(this,"sessionListener",new Ca);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(ba,new Kn(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)})}onDataChannelMessage(e){}}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||{}),L=(t=>(t.VIDEO="video",t.AUDIO="audio",t))(L||{}),H=(t=>(t.FULL="full-duplex",t.HALF="half-duplex",t))(H||{}),ne=(t=>(t.IN="in",t.OUT="out",t))(ne||{}),M=(t=>(t.LOGIN="login",t.LOGOUT="logout",t.Invite="invite",t.RING="ring",t.ANSWER="answer",t.HANGUP="hangup",t.DTMF="dtmf",t))(M||{});function Qn(){try{return!!(navigator.mediaDevices&&navigator.mediaDevices.getUserMedia)}catch{return!1}}function Ta(){return"browser-"+Ea()+Pa(6)}function Ea(){let t=new Date;return`${t.getFullYear()}${t.getMonth()}${t.getDate()}${t.getHours()}${t.getMinutes()}${t.getSeconds()}`}function Pa(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 Oa{constructor(e,r,n){g(this,"tel");g(this,"mediaType");g(this,"callMode");this.tel=e,this.callMode=n,this.mediaType=r}}class Yn{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 Xn{constructor(e,r,n){g(this,"tel","");g(this,"status",R.OFFLINE);g(this,"mediaType",L.AUDIO);g(this,"callMode",H.FULL);g(this,"callDirect",ne.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 Yn);g(this,"wsUrl");g(this,"accountId");this.tel=r??"",this.wsUrl=e,this.accountId=n,this.ringBackTone.loop=!0,this.ringtone.loop=!0}setCallSessionListener(e){this.sessionListener=e}init(){this.websocketInit(this.wsUrl)}audioCall(e){this.makeCall(e)}videoCall(e){this.makeCall(e,L.VIDEO)}answer(){var r;if(this.status!=R.RING){console.debug("session is not ring state");return}if(this.callDirect!=ne.IN){console.debug("session is call out, not allow answer");return}let e;this.callMode==H.HALF?e=L.VIDEO==this.mediaType?S.VIDEO_HALF:S.AUDIO_HALF:e=L.VIDEO==this.mediaType?S.VIDEO:S.AUDIO,this.webrtcCreate(e),(r=this.webrtcSession)==null||r.start(!1,this.remoteSdp)}hangup(){this.status<=R.IDLE||(this.status==R.TALK?this.sendHangup(this.callId??""):this.callDirect==ne.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()}makeCall(e,r=L.AUDIO,n=H.FULL){var i;try{if(!Qn()){console.debug("Browser does not support WEBRTC"),this.sessionListener.onError(new Error("Browser does not support WEBRTC"));return}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}this.status>R.IDLE&&(console.debug("Another call is currently in progress, hangup it"),this.hangup()),this.mediaType=r,this.callMode=n,this.called=e,this.callDirect=ne.OUT,this.callId=Ta();let o;this.callMode==H.HALF?o=L.VIDEO==r?S.VIDEO_HALF:S.AUDIO_HALF:o=L.VIDEO==r?S.VIDEO:S.AUDIO,this.webrtcCreate(o),(i=this.webrtcSession)==null||i.start(!0),this.status=R.TRY}catch(o){this.status=R.IDLE,this.sessionListener.onError(new Error(""+o))}}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 M.Invite:this.inviteHandler(n);break;case M.ANSWER:this.answerHandler(n);break;case M.RING:this.ringHandler(n);break;case M.HANGUP:this.hangupHandler(n);break;case M.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:M.LOGIN,username:this.tel,userAgent:this.getUserAgent(),accountId:this.accountId})}sendLogout(){this.sendTo({type:M.LOGOUT,username:this.tel}),this.status=R.OFFLINE}sendInvite(e){this.sendTo({callId:this.callId,type:M.Invite,from:this.tel,to:this.called,callMode:this.callMode,mediaType:this.mediaType,sdp:e}),this.status=R.TRY}sendRing(){this.sendTo({type:M.RING,callId:this.callId,code:180}),this.status=R.RING}sendAnswer(e){this.sendTo({type:M.ANSWER,callId:this.callId,mediaType:this.mediaType,sdp:e}),this.status=R.TALK,this.ringtone.pause(),this.ringBackTone.pause()}sendDtmf(e){this.sendTo({type:M.DTMF,callId:this.callId,callInfo:"dtmf="+e}),this.dtmfAudio.play().then(()=>{}).catch(r=>console.debug(r))}sendHangup(e,r=800){this.sendTo({type:M.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)):console.debug("receive re invite. not process");return}this.callId=e.callId,this.mediaType=e.mediaType??L.AUDIO,this.callMode=e.callMode??H.FULL,this.called=e.from??"",this.callDirect=ne.IN,this.remoteSdp=e.sdp,this.candidate=e.candidate,this.sendRing(),this.ringtone.currentTime=0,this.ringtone.play().then(()=>{}).catch(()=>{}),this.sessionListener.onNewCall(new Oa(this.called,this.mediaType,this.callMode))}ringHandler(e){var r,n;!e.callId||e.callId!=this.callId||(e.code==183?(this.ringBackTone.pause(),(r=this.webrtcSession)==null||r.setRemoteSdp(e.sdp??""),(n=this.webrtcSession)==null||n.addRemoteCandidate(e.candidate??[])):(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 Wt(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==ne.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??"")}onDataChannelMessage(e){}}class Aa{onError(e){console.debug("onError:",e)}onAddLocalStream(e){console.debug("onAddLocalStream:",e)}}const _a="/media-server/broadcast/webrtc";class Ia{constructor(e,r,n){g(this,"tel");g(this,"mediaType");g(this,"webrtcSession");g(this,"sessionListener",new Aa);g(this,"httpClient");this.tel=e,this.httpClient=r,this.mediaType=n===L.VIDEO?L.VIDEO:L.AUDIO,this.webrtcSession=new Wt(n==L.VIDEO?S.VIDEO_PUSH:S.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(_a,new Kn(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)})}onDataChannelMessage(e){}}var qt=(t=>(t.TB_REQUEST="tb_request",t.TB_GRANTED="tb_granted",t.TB_TAKEN="tb_taken",t.TB_DENY="tb_deny",t.TB_RELEASE="tb_release",t.TB_IDLE="tb_idle",t.TB_REVOKE="tb_revoke",t))(qt||{});class Da extends Yn{onTbcpMessage(e){console.debug("onTbcpMessage:",e)}}class La extends Xn{constructor(r,n,i){super(r,n,i);g(this,"sessionListener",new Da)}setCallSessionListener(r){this.sessionListener=r}audioHalfCall(r){this.makeCall(r,L.AUDIO,H.HALF)}videoHalfCall(r){this.makeCall(r,L.VIDEO,H.HALF)}tbcpRequest(){var r;this.callMode==H.HALF&&this.status==R.TALK&&((r=this.webrtcSession)==null||r.sendStringData(JSON.stringify({type:qt.TB_REQUEST})))}tbcpRelease(){var r;this.callMode==H.HALF&&this.status==R.TALK&&((r=this.webrtcSession)==null||r.sendStringData(JSON.stringify({type:qt.TB_RELEASE})))}onDataChannelMessage(r){try{this.sessionListener.onTbcpMessage(JSON.parse(r))}catch(n){console.debug("onDataChannelMessage err: ",n,r)}}}let Kt=new an("/"),Zn="/media-server/ws/voip",ei="/media-server/ws/b-trun-c",Qt=new URL((location.protocol=="https:"?"wss://":"ws://")+location.host+Zn),Yt=new URL((location.protocol=="https:"?"wss://":"ws://")+location.host+ei);function xa(t){Kt=new an(t)}function Ma(t){return new Ra(t,Kt)}function ka(t,e){return new Ia(t,Kt,e)}function Fa(t){Qt=new URL(t),Qt.pathname=Zn,Yt=new URL(t),Yt.pathname=ei}function Na(t){return new Xn(Qt.toString(),t)}function Ua(t,e){return new La(Yt.toString(),t,e)}A.createAppCallSession=Ua,A.createBroadcastSession=ka,A.createCallSession=Na,A.createRtspPullSession=Ma,A.videoModuleInit=xa,A.voipModuleInit=Fa,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 Ze(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 et(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 Sa=Object.freeze(Object.defineProperty({__proto__:null,removeExtmapAllowMixed:Jt,shimAddIceCandidateNullOrEmpty:Ze,shimConnectionState:zt,shimMaxMessageSize:Ye,shimParameterlessSetLocalDescription:et,shimRTCIceCandidate:Qe,shimRTCIceCandidateRelayProtocol:Vt,shimSendThrowTypeError:Xe},Symbol.toStringTag,{value:"Module"}));function va({window:t}={},e={shimChrome:!0,shimFirefox:!0,shimSafari:!0}){const r=un,n=ha(t),i={browserDetails:n,commonShim:Sa,extractVersion:Ke,disableLog:pa,disableWarnings:da,sdp:ga};switch(n.browser){case"chrome":if(!En||!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=En,Ze(t,n),et(t),mn(t,n),yn(t),wt(t,n),gn(t),Rn(t,n),Sn(t),vn(t),Cn(t),Tn(t,n),Qe(t),Vt(t),zt(t),Ye(t,n),Xe(t),Jt(t,n);break;case"firefox":if(!Fn||!Gt||!e.shimFirefox)return r("Firefox shim is not included in this adapter release."),i;r("adapter.js shimming firefox."),i.browserShim=Fn,Ze(t,n),et(t),Pn(t,n),Gt(t,n),On(t),In(t),An(t),_n(t),Dn(t),Ln(t),xn(t),Mn(t),kn(t),Qe(t),zt(t),Ye(t,n),Xe(t);break;case"safari":if(!zn||!e.shimSafari)return r("Safari shim is not included in this adapter release."),i;r("adapter.js shimming safari."),i.browserShim=zn,Ze(t,n),et(t),Hn(t),Gn(t),Bn(t),Nn(t),Un(t),wn(t),jn(t),Vn(t),Qe(t),Vt(t),Ye(t,n),Xe(t),Jt(t,n);break;default:r("Unsupported browser!");break}return i}const qn=va({window:typeof window>"u"?void 0:window});class Wt{constructor(e){g(this,"peerConnection");g(this,"sessionListener",new fa);g(this,"isCallOut",!1);g(this,"sessionType",S.UNKNOWN);g(this,"localStream");g(this,"remoteStream");g(this,"dataChannel");g(this,"hasSetRemoteSdp",!1);g(this,"facingMode",te.FRONT_FACING);g(this,"facingChanging",!1);g(this,"muted",!1);g(this,"openCamera",!1);this.sessionType=e,console.debug(qn.browserDetails.browser+" "+qn.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=te.FRONT_FACING,this.facingChanging=!1,this.muted=!1,this.peerConnection=new RTCPeerConnection({iceServers:[]}),this.peerConnection.onnegotiationneeded=()=>{switch(this.sessionType){case S.AUDIO_PUSH:case S.VIDEO_PUSH:case S.AUDIO_HALF:case S.VIDEO_HALF:this.createDataChannel()}e?(console.debug("webrtc call out"),this.peerConnection.createOffer().then(n=>{console.debug("webrtc createOffer success"),this.peerConnection.setLocalDescription(n).then(()=>{console.debug("webrtc setLocalDescription success")}).catch(i=>{this.error(i)})}).catch(n=>{this.error(n)})):(console.debug("webrtc call in: ",r),this.peerConnection.setRemoteDescription(new RTCSessionDescription({type:"offer",sdp:r})).then(()=>{console.debug("webrtc setRemoteDescription success"),this.peerConnection.createAnswer().then(n=>{console.debug("webrtc createAnswer success"),this.peerConnection.setLocalDescription(n).then(()=>{console.debug("webrtc setLocalDescription success")}).catch(i=>{this.error(i)})}).catch(n=>{this.error(n)})}).catch(n=>{this.error(n)}))},this.peerConnection.onicegatheringstatechange=()=>{var n;console.debug("webrtc onicegatheringstatechange",(n=this.peerConnection)==null?void 0:n.iceGatheringState),this.peerConnection&&this.peerConnection.iceGatheringState=="complete"&&this.peerConnection.localDescription&&this.sessionListener.onStartSuccess(this.peerConnection.localDescription)},this.peerConnection.ontrack=n=>{console.debug("webrtc ontrack");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 S.RTSP_PULL:this.addTransceivers(),this.createDataChannel();break;case S.AUDIO_PUSH:case S.VIDEO_PUSH:case S.AUDIO_HALF:case S.VIDEO_HALF:case S.VIDEO:case S.AUDIO:this.gotLocalMedia();break;default:this.error(new Error("session type unknown: "+this.sessionType));break}}setRemoteSdp(e){e&&e!==""&&this.peerConnection&&this.isCallOut&&!this.hasSetRemoteSdp&&(this.hasSetRemoteSdp=!0,this.peerConnection.setRemoteDescription(new RTCSessionDescription({type:"answer",sdp:e})).then(()=>{console.debug("webrtc setRemoteDescription success")}).catch(r=>{this.error(r),this.hasSetRemoteSdp=!1}))}addRemoteCandidate(e){this.peerConnection&&e.forEach(r=>{this.peerConnection.addIceCandidate(r).then(()=>{console.debug("webrtc addIceCandidate success")}).catch(n=>console.log(n))})}sendStringData(e){this.dataChannel&&this.dataChannel.send(e)}stop(){var e;console.debug("webrtc stop"),(this.sessionType==S.VIDEO_PUSH||this.sessionType==S.AUDIO_PUSH||this.sessionType==S.RTSP_PULL)&&this.sendStringData("close"),(e=this.peerConnection)==null||e.close(),this.peerConnection=void 0,this.localStream&&(this.localStream.getTracks().forEach(r=>{this.localStream.removeTrack(r),r.stop()}),this.localStream=void 0),this.remoteStream=void 0}changeFacing(){return new Promise((e,r)=>{if(this.sessionType!==S.VIDEO&&this.sessionType!==S.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){console.debug("webrtc error: ",e),this.stop(),this.sessionListener.onError(e)}addTransceivers(){this.peerConnection.addTransceiver("audio",{direction:"recvonly"}),this.peerConnection.addTransceiver("video",{direction:"recvonly"})}gotLocalMedia(){let e={audio:{echoCancellation:!0,noiseSuppression:!0}};switch(this.sessionType){case S.VIDEO:case S.VIDEO_PUSH:case S.VIDEO_HALF:e.video={height:{exact:720},width:{exact:1280}};break}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){console.debug("webrtc getMediaSuccess"),this.localStream=e,(this.sessionType===S.VIDEO||this.sessionType===S.VIDEO_PUSH||this.sessionType===S.VIDEO_HALF)&&this.sessionListener.onAddLocalStream(e),e.getTracks().forEach(r=>{switch(this.sessionType){case S.AUDIO_PUSH:case S.VIDEO_PUSH:this.peerConnection.addTransceiver(r,{direction:"sendonly",streams:[e]});break;default:this.peerConnection.addTrack(r,e)}}),this.muted=!1}getMediaFailed(e){if(console.debug("webrtc getMediaFailed failed"),this.sessionType===S.VIDEO){console.error("get video media failed. maybe not found camera.",e),this.sessionType=S.AUDIO,this.gotLocalMedia();return}else if(this.sessionType===S.VIDEO_PUSH){console.error("get video media failed. maybe not found camera.",e),this.sessionType=S.AUDIO_PUSH,this.gotLocalMedia();return}else if(this.sessionType===S.VIDEO_HALF){console.error("get video media failed. maybe not found camera.",e),this.sessionType=S.AUDIO_HALF,this.gotLocalMedia();return}this.error(e)}createDataChannel(){this.peerConnection&&(this.isCallOut?(this.dataChannel=this.peerConnection.createDataChannel("command_channel"),this.dataChannel.onmessage=e=>{this.onDataChannelReceive(e.data)}):this.peerConnection.ondatachannel=e=>{this.dataChannel=e.channel,this.dataChannel.onmessage=r=>{this.onDataChannelReceive(r.data)}})}onDataChannelReceive(e){if(e==="close"){console.debug("data channel receive from server: close"),this.dataChannel=void 0,this.stop();return}(this.sessionType==S.VIDEO_HALF||this.sessionType==S.AUDIO_HALF)&&this.sessionListener.onDataChannelMessage(e)}changeCameraLocalMedia(){return new Promise((e,r)=>{let n;if(this.facingMode===te.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===te.FRONT_FACING?this.facingMode=te.BACK_FACING:this.facingMode=te.FRONT_FACING,this.facingChanging=!1}changeCameraFailed(e){console.log(e),this.facingChanging=!1}}class Ca{onAddRemoteStream(e){console.debug("onAddRemoteStream:",e)}onError(e){console.debug("onError:",e)}}class Kn{constructor(e,r){g(this,"url");g(this,"offerSdp");this.url=e,this.offerSdp=r}}const ba="/media-server/video-play/webrtc";class Ra{constructor(e,r){g(this,"rtspUrl");g(this,"webrtcSession",new Wt(S.RTSP_PULL));g(this,"sessionListener",new Ca);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(ba,new Kn(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)})}onDataChannelMessage(e){}}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||{}),L=(t=>(t.VIDEO="video",t.AUDIO="audio",t))(L||{}),H=(t=>(t.FULL="full-duplex",t.HALF="half-duplex",t))(H||{}),ne=(t=>(t.IN="in",t.OUT="out",t))(ne||{}),M=(t=>(t.LOGIN="login",t.LOGOUT="logout",t.Invite="invite",t.RING="ring",t.ANSWER="answer",t.HANGUP="hangup",t.DTMF="dtmf",t))(M||{});function Qn(){try{return!!(navigator.mediaDevices&&navigator.mediaDevices.getUserMedia)}catch{return!1}}function Ta(){return"browser-"+Ea()+Pa(6)}function Ea(){let t=new Date;return`${t.getFullYear()}${t.getMonth()}${t.getDate()}${t.getHours()}${t.getMinutes()}${t.getSeconds()}`}function Pa(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 Oa{constructor(e,r,n){g(this,"tel");g(this,"mediaType");g(this,"callMode");this.tel=e,this.callMode=n,this.mediaType=r}}class Yn{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 Xn{constructor(e,r,n){g(this,"tel","");g(this,"status",R.OFFLINE);g(this,"mediaType",L.AUDIO);g(this,"callMode",H.FULL);g(this,"callDirect",ne.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 Yn);g(this,"wsUrl");g(this,"accountId");this.tel=r??"",this.wsUrl=e,this.accountId=n,this.ringBackTone.loop=!0,this.ringtone.loop=!0}setCallSessionListener(e){this.sessionListener=e}init(){this.websocketInit(this.wsUrl)}audioCall(e){this.makeCall(e)}videoCall(e){this.makeCall(e,L.VIDEO)}answer(){var r;if(this.status!=R.RING){console.debug("session is not ring state");return}if(this.callDirect!=ne.IN){console.debug("session is call out, not allow answer");return}let e;this.callMode==H.HALF?e=L.VIDEO==this.mediaType?S.VIDEO_HALF:S.AUDIO_HALF:e=L.VIDEO==this.mediaType?S.VIDEO:S.AUDIO,this.webrtcCreate(e),(r=this.webrtcSession)==null||r.start(!1,this.remoteSdp)}hangup(){this.status<=R.IDLE||(this.status==R.TALK?this.sendHangup(this.callId??""):this.callDirect==ne.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()}makeCall(e,r=L.AUDIO,n=H.FULL){var i;try{if(!Qn()){console.debug("Browser does not support WEBRTC"),this.sessionListener.onError(new Error("Browser does not support WEBRTC"));return}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}this.status>R.IDLE&&(console.debug("Another call is currently in progress, hangup it"),this.hangup()),this.mediaType=r,this.callMode=n,this.called=e,this.callDirect=ne.OUT,this.callId=Ta();let o;this.callMode==H.HALF?o=L.VIDEO==r?S.VIDEO_HALF:S.AUDIO_HALF:o=L.VIDEO==r?S.VIDEO:S.AUDIO,this.webrtcCreate(o),(i=this.webrtcSession)==null||i.start(!0),this.status=R.TRY}catch(o){this.status=R.IDLE,this.sessionListener.onError(new Error(""+o))}}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 M.Invite:this.inviteHandler(n);break;case M.ANSWER:this.answerHandler(n);break;case M.RING:this.ringHandler(n);break;case M.HANGUP:this.hangupHandler(n);break;case M.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:M.LOGIN,username:this.tel,userAgent:this.getUserAgent(),accountId:this.accountId})}sendLogout(){this.sendTo({type:M.LOGOUT,username:this.tel}),this.status=R.OFFLINE}sendInvite(e){this.sendTo({callId:this.callId,type:M.Invite,from:this.tel,to:this.called,callMode:this.callMode,mediaType:this.mediaType,sdp:e}),this.status=R.TRY}sendRing(){this.sendTo({type:M.RING,callId:this.callId,code:180}),this.status=R.RING}sendAnswer(e){this.sendTo({type:M.ANSWER,callId:this.callId,mediaType:this.mediaType,sdp:e}),this.status=R.TALK,this.ringtone.pause(),this.ringBackTone.pause()}sendDtmf(e){this.sendTo({type:M.DTMF,callId:this.callId,callInfo:"dtmf="+e}),this.dtmfAudio.play().then(()=>{}).catch(r=>console.debug(r))}sendHangup(e,r=800){this.sendTo({type:M.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)):console.debug("receive re invite. not process");return}this.callId=e.callId,this.mediaType=e.mediaType??L.AUDIO,this.callMode=e.callMode??H.FULL,this.called=e.from??"",this.callDirect=ne.IN,this.remoteSdp=e.sdp,this.candidate=e.candidate,this.sendRing(),this.ringtone.currentTime=0,this.ringtone.play().then(()=>{}).catch(()=>{}),this.sessionListener.onNewCall(new Oa(this.called,this.mediaType,this.callMode))}ringHandler(e){var r,n;!e.callId||e.callId!=this.callId||(e.code==183?(this.ringBackTone.pause(),(r=this.webrtcSession)==null||r.setRemoteSdp(e.sdp??""),(n=this.webrtcSession)==null||n.addRemoteCandidate(e.candidate??[])):(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 Wt(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==ne.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??"")}onDataChannelMessage(e){}}class Aa{onError(e){console.debug("onError:",e)}onAddLocalStream(e){console.debug("onAddLocalStream:",e)}}const _a="/media-server/broadcast/webrtc";class Ia{constructor(e,r,n){g(this,"tel");g(this,"mediaType");g(this,"webrtcSession");g(this,"sessionListener",new Aa);g(this,"httpClient");this.tel=e,this.httpClient=r,this.mediaType=n===L.VIDEO?L.VIDEO:L.AUDIO,this.webrtcSession=new Wt(n==L.VIDEO?S.VIDEO_PUSH:S.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(_a,new Kn(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)})}onDataChannelMessage(e){}}var qt=(t=>(t.TB_REQUEST="tb_request",t.TB_GRANTED="tb_granted",t.TB_TAKEN="tb_taken",t.TB_DENY="tb_deny",t.TB_RELEASE="tb_release",t.TB_IDLE="tb_idle",t.TB_REVOKE="tb_revoke",t))(qt||{});class Da extends Yn{onTbcpMessage(e){console.debug("onTbcpMessage:",e)}}class La extends Xn{constructor(r,n,i){super(r,n,i);g(this,"sessionListener",new Da)}setCallSessionListener(r){this.sessionListener=r}audioHalfCall(r){this.makeCall(r,L.AUDIO,H.HALF)}videoHalfCall(r){this.makeCall(r,L.VIDEO,H.HALF)}tbcpRequest(){var r;this.callMode==H.HALF&&this.status==R.TALK&&((r=this.webrtcSession)==null||r.sendStringData(JSON.stringify({type:qt.TB_REQUEST})))}tbcpRelease(){var r;this.callMode==H.HALF&&this.status==R.TALK&&((r=this.webrtcSession)==null||r.sendStringData(JSON.stringify({type:qt.TB_RELEASE})))}onDataChannelMessage(r){try{this.sessionListener.onTbcpMessage(JSON.parse(r))}catch(n){console.debug("onDataChannelMessage err: ",n,r)}}}let Kt=new an("/"),Zn="/media-server/ws/voip",ei="/media-server/ws/b-trun-c",Qt=new URL((location.protocol=="https:"?"wss://":"ws://")+location.host+Zn),Yt=new URL((location.protocol=="https:"?"wss://":"ws://")+location.host+ei);function xa(t){Kt=new an(t)}function Ma(t){return new Ra(t,Kt)}function ka(t,e){return new Ia(t,Kt,e)}function Fa(t){Qt=new URL(t),Qt.pathname=Zn,Yt=new URL(t),Yt.pathname=ei}function Na(t){return new Xn(Qt.toString(),t)}function Ua(t,e){return new La(Yt.toString(),t,e)}A.createAppCallSession=Ua,A.createBroadcastSession=ka,A.createCallSession=Na,A.createRtspPullSession=Ma,A.videoModuleInit=xa,A.voipModuleInit=Fa,Object.defineProperty(A,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "media-av",
3
3
  "private": false,
4
- "version": "0.0.14",
4
+ "version": "0.0.15",
5
5
  "type": "module",
6
6
  "author": "W.w.",
7
7
  "license": "MIT",