module-develop-kit 1.0.0 → 1.0.2

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.
@@ -1,7 +1,5 @@
1
- import { getDefaultExportFromCjs as r } from "./_commonjsHelpers.js";
2
- import { __require as o } from "../vendor/sdp-transform/lib/index.js";
3
- var t = o();
4
- const a = /* @__PURE__ */ r(t);
1
+ import { __require as r } from "../vendor/gm-crypt/index.js";
2
+ var p = r();
5
3
  export {
6
- a as default
4
+ p as g
7
5
  };
@@ -1,5 +1,7 @@
1
- import { __require as r } from "../vendor/gm-crypt/index.js";
2
- var p = r();
1
+ import { getDefaultExportFromCjs as r } from "./_commonjsHelpers.js";
2
+ import { __require as o } from "../vendor/sdp-transform/lib/index.js";
3
+ var t = o();
4
+ const a = /* @__PURE__ */ r(t);
3
5
  export {
4
- p as g
6
+ a as default
5
7
  };
@@ -1,4 +1,4 @@
1
- var r = {};
1
+ var e = { exports: {} };
2
2
  export {
3
- r as __exports
3
+ e as __module
4
4
  };
@@ -1,4 +1,4 @@
1
- var e = { exports: {} };
1
+ var r = {};
2
2
  export {
3
- e as __module
3
+ r as __exports
4
4
  };
package/dist/main.d.ts CHANGED
@@ -181,8 +181,13 @@ export declare interface ICallConfig extends SipAccount {
181
181
  credential: string;
182
182
  };
183
183
  };
184
+ /**
185
+ * ice 传输策略
186
+ */
187
+ iceTransportPolicy?: string;
184
188
  /**
185
189
  * 是否开发环境
190
+ * @deprecated 该属性已废弃,所有情况都会传递 iceConfig
186
191
  */
187
192
  isDev?: boolean;
188
193
  /**
@@ -199,6 +204,9 @@ export declare interface ICallConfig extends SipAccount {
199
204
  * 用于拨打电话的相关信息
200
205
  */
201
206
  export declare interface ICallOptions {
207
+ /**
208
+ * 外呼需要拨打的号码
209
+ */
202
210
  call: string;
203
211
  }
204
212
 
@@ -3,7 +3,7 @@ import { C as l } from "../../commonjs-virtual-dir/Constants.js";
3
3
  import { ECallStatus as r, EMIT_EVENT_NAME as S } from "./constants.js";
4
4
  import { CallLogger as s, getIceServersByCallConfig as p, formatSdp as f } from "./utils.js";
5
5
  import { EventBus as m } from "../utils/eventBus.js";
6
- class g {
6
+ class D {
7
7
  ua = null;
8
8
  session = null;
9
9
  eventBus;
@@ -59,8 +59,8 @@ class g {
59
59
  s.log("WebSocket已连接");
60
60
  }), this.ua.on("disconnected", () => {
61
61
  s.warn("WebSocket已断开"), r.PENDING === this.callStatus && this.updateStatus(r.RECONNECT, l.causes.CONNECTION_ERROR);
62
- }), this.ua.on("registrationFailed", (u) => {
63
- this.updateStatus(r.FAILED, u.cause, u.response.status_code), s.error(`SIP 注册失败 cause: ${u?.cause} status_code: ${u?.response?.status_code}`), this.stop();
62
+ }), this.ua.on("registrationFailed", (c) => {
63
+ this.updateStatus(r.FAILED, c.cause, c.response.status_code), s.error(`SIP 注册失败 cause: ${c?.cause} status_code: ${c?.response?.status_code}`), this.stop();
64
64
  }), this.ua.start(), this.updateStatus(r.PENDING);
65
65
  } catch (e) {
66
66
  s.error("SIP 初始化失败", e?.message), this.stop(), this.updateStatus(r.FAILED, l.causes.SIP_FAILURE_CODE);
@@ -84,10 +84,10 @@ class g {
84
84
  */
85
85
  audioCheck(o) {
86
86
  try {
87
- const t = new (Reflect.get(window, "AudioContext") || Reflect.get(window, "webkitAudioContext"))(), e = t.createAnalyser(), u = t.createMediaStreamSource(o.streams[0]);
88
- u.connect(e), e.fftSize = 256;
87
+ const t = new (Reflect.get(window, "AudioContext") || Reflect.get(window, "webkitAudioContext"))(), e = t.createAnalyser(), c = t.createMediaStreamSource(o.streams[0]);
88
+ c.connect(e), e.fftSize = 256;
89
89
  const a = e.frequencyBinCount, i = new Uint8Array(a), n = () => {
90
- e.getByteTimeDomainData(i), i.some((d) => Math.abs(d - 128) > 2) && (s.log("【音频分析】检测到有效声音"), u.disconnect(), this.stopPlayTipAudio()), requestAnimationFrame(n);
90
+ e.getByteTimeDomainData(i), i.some((d) => Math.abs(d - 128) > 2) && (s.log("【音频分析】检测到有效声音"), c.disconnect(), this.stopPlayTipAudio()), requestAnimationFrame(n);
91
91
  };
92
92
  n();
93
93
  } catch (t) {
@@ -102,8 +102,8 @@ class g {
102
102
  */
103
103
  getSessionEventHandlers(o, t) {
104
104
  let e = !1;
105
- const u = o.call.split("").slice(-4).join("");
106
- return s.log("开始呼叫(尾号):", `sip:${u}@${t.sipIp}`), {
105
+ const c = o.call.split("").slice(-4).join("");
106
+ return s.log("开始呼叫(尾号):", `sip:${c}@${t.sipIp}`), {
107
107
  sdp: (a) => {
108
108
  a.sdp = f(a.sdp);
109
109
  },
@@ -124,12 +124,12 @@ class g {
124
124
  this.stop();
125
125
  },
126
126
  failed: (a) => {
127
- const { cause: i, message: n = {} } = a, c = i === "Canceled";
127
+ const { cause: i, message: n = {} } = a, u = i === "Canceled";
128
128
  this.updateStatus(
129
- c ? r.CANCELLED : r.FAILED,
129
+ u ? r.CANCELLED : r.FAILED,
130
130
  i,
131
131
  n?.status_code
132
- ), c ? s.warn(
132
+ ), u ? s.warn(
133
133
  `通话已取消 cause: ${i} status_code: ${n?.status_code || ""}`
134
134
  ) : s.error(
135
135
  `通话失败 cause: ${i} status_code: ${n?.status_code || ""}`
@@ -149,10 +149,10 @@ class g {
149
149
  s.log("RTCPeerConnection 已创建或更新,正在设置 ontrack 监听器"), i.ontrack = (n) => {
150
150
  if (n.track.kind === "audio" && n.streams[0]) {
151
151
  s.log(n.track, "track"), s.log(`接收到远程媒体轨道 (track): ${n.track.kind}`);
152
- const c = n.streams[0];
152
+ const u = n.streams[0];
153
153
  this.stopPlayTipAudio();
154
154
  const d = document.getElementById(t.playAudioId);
155
- d ? (d.srcObject = c, d.play().catch((E) => {
155
+ d ? (d.srcObject = u, d.play().catch((E) => {
156
156
  s.error("播放远程音频失败 (来自 ontrack)", E);
157
157
  })) : s.error("无法播放远程音频,播放元素不存在", `${t.playAudioId}`), this.audioCheck(n);
158
158
  }
@@ -172,7 +172,7 @@ class g {
172
172
  return;
173
173
  }
174
174
  try {
175
- const u = {
175
+ const c = {
176
176
  eventHandlers: this.getSessionEventHandlers(o, t),
177
177
  mediaConstraints: { audio: !0, video: !1 },
178
178
  rtcOfferConstraints: {
@@ -182,11 +182,12 @@ class g {
182
182
  rtcConfiguration: {
183
183
  iceServers: p(t)
184
184
  },
185
- sessionTimersExpires: 180
185
+ sessionTimersExpires: 180,
186
+ pcConfig: {
187
+ iceServers: p(t)
188
+ }
186
189
  };
187
- t.isDev || (u.pcConfig = {
188
- iceServers: p(t)
189
- }), this.session = this.ua.call(`sip:${o.call}@${t.sipIp}`, u);
190
+ t.iceTransportPolicy && c.pcConfig && (s.log("iceTransportPolicy", t.iceTransportPolicy), c.pcConfig.iceTransportPolicy = t.iceTransportPolicy), this.session = this.ua.call(`sip:${o.call}@${t.sipIp}`, c);
190
191
  } catch (e) {
191
192
  s.error("SIP 会话创建失败", e?.message), this.stop();
192
193
  }
@@ -203,14 +204,14 @@ class g {
203
204
  t = new (window.AudioContext || Reflect.get(window, "webkitAudioContext"))(), await t.suspend();
204
205
  const n = await t.decodeAudioData(i);
205
206
  e = t.createBufferSource(), e.buffer = n, e.connect(t.destination), e.loop = !0, e.loopStart = 0, e.loopEnd = n.duration;
206
- const c = t.currentTime;
207
- s.log("音频播放开始时间:", c), await t.resume(), e.start(c);
207
+ const u = t.currentTime;
208
+ s.log("音频播放开始时间:", u), await t.resume(), e.start(u);
208
209
  } catch (a) {
209
210
  s.error("播放音频失败", a?.message);
210
211
  }
211
- let u = !1;
212
+ let c = !1;
212
213
  this.stopPlayTipAudio = () => {
213
- u || (s.log("停止播放提示音"), u = !0, e.stop(), e.disconnect(), t.close().finally(() => {
214
+ c || (s.log("停止播放提示音"), c = !0, e.stop(), e.disconnect(), t.close().finally(() => {
214
215
  e = null, t = null, this.stopPlayTipAudio = () => {
215
216
  };
216
217
  }));
@@ -245,5 +246,5 @@ class g {
245
246
  }
246
247
  }
247
248
  export {
248
- g as CallManagement
249
+ D as CallManagement
249
250
  };
@@ -1,5 +1,5 @@
1
- import a from "../../commonjs-virtual-dir/index2.js";
2
- const u = {
1
+ import c from "../../commonjs-virtual-dir/index3.js";
2
+ const g = {
3
3
  log(e, ...r) {
4
4
  console.log(`%c【${(/* @__PURE__ */ new Date()).toLocaleString()}】`, "color: green; font-weight: bold;", e, ...r);
5
5
  },
@@ -9,42 +9,39 @@ const u = {
9
9
  error(e, ...r) {
10
10
  console.log(`%c【${(/* @__PURE__ */ new Date()).toLocaleString()}】`, "color: red; font-weight: bold;", e, ...r);
11
11
  }
12
+ }, a = /* @__PURE__ */ new Map([
13
+ ["PCMA", 1],
14
+ ["G729", 2],
15
+ ["G722", 3],
16
+ ["PCMU", 4]
17
+ ]), s = (e) => (e.type === "audio" && (e.rtp.sort((r, o) => {
18
+ const t = a.get(r.codec) || 1 / 0, n = a.get(o.codec) || 1 / 0;
19
+ return t - n;
20
+ }), e.payloads = e.rtp.map((r) => r.payload).join(" ")), e), p = (e) => {
21
+ const r = c.parse(e);
22
+ return r.media = r.media.map(s), c.write(r);
12
23
  }, S = (e) => {
13
- const r = a.parse(e);
14
- return r.media = r.media.map((t) => {
15
- if (t.type === "audio") {
16
- const n = t.payloads;
17
- if (n?.includes("8")) {
18
- const o = n.split(" "), s = o.findIndex((c) => c === "8");
19
- o.splice(s, 1), o.unshift("8"), t.payloads = o.join(" ");
20
- const i = t.rtp, l = i.find((c) => c.codec === "PCMA"), d = i.findIndex((c) => c.codec === "PCMA");
21
- i.splice(d, 1), l && i.unshift(l);
22
- }
23
- }
24
- return t;
25
- }), a.write(r);
26
- }, f = (e) => {
27
24
  if (typeof e != "number" || Number.isNaN(e))
28
25
  throw new TypeError("输入必须是数字类型");
29
26
  if (e < 0 || !Number.isInteger(e))
30
27
  throw new RangeError("请输入非负整数");
31
- const r = e / 1e3, t = Math.floor(r / 60), n = Math.floor(r % 60), o = String(t).padStart(2, "0"), s = String(n).padStart(2, "0");
32
- return `${o}:${s}`;
33
- }, g = (e) => {
28
+ const r = e / 1e3, o = Math.floor(r / 60), t = Math.floor(r % 60), n = String(o).padStart(2, "0"), i = String(t).padStart(2, "0");
29
+ return `${n}:${i}`;
30
+ }, d = (e) => {
34
31
  const r = [
35
32
  {
36
33
  urls: [e.iceService.stunServerUrl]
37
34
  }
38
35
  ];
39
36
  if (e.iceService.turnServer) {
40
- const { urls: t, username: n, credential: o } = e.iceService.turnServer;
41
- t && n && o && r.push(e.iceService.turnServer);
37
+ const { urls: o, username: t, credential: n } = e.iceService.turnServer;
38
+ o && t && n && r.push(e.iceService.turnServer);
42
39
  }
43
40
  return r;
44
41
  };
45
42
  export {
46
- u as CallLogger,
47
- S as formatSdp,
48
- f as formatSeconds,
49
- g as getIceServersByCallConfig
43
+ g as CallLogger,
44
+ p as formatSdp,
45
+ S as formatSeconds,
46
+ d as getIceServersByCallConfig
50
47
  };
@@ -1,4 +1,4 @@
1
- import { g as o } from "../../../commonjs-virtual-dir/index3.js";
1
+ import { g as o } from "../../../commonjs-virtual-dir/index2.js";
2
2
  import { dataToStr as r } from "./util.js";
3
3
  const c = "cbc", n = (t, e) => new o.sm4({
4
4
  key: t.key,
@@ -1,24 +1,24 @@
1
1
  import c from "@vitejs/plugin-legacy";
2
2
  import { vitePluginCompatibilityDetection as l } from "./vitePluginCompatibilityDetection.js";
3
3
  const f = {
4
- targets: "since 2021 and > 0.1% in CN",
4
+ targets: "since 2020",
5
5
  renderModernChunks: !1,
6
6
  modernPolyfills: !1
7
- }, g = (o) => {
7
+ }, a = (n) => {
8
8
  const e = {
9
9
  open: !0,
10
10
  openDetection: !0,
11
- ...o || {}
12
- }, i = e.detectionConfig?.platform === "h5", t = [], { open: s, openDetection: r, detectionConfig: p, ...n } = e;
11
+ ...n || {}
12
+ }, i = e.detectionConfig?.platform === "h5", t = [], { open: s, openDetection: r, detectionConfig: p, ...o } = e;
13
13
  return s && (t.push(
14
14
  c(
15
15
  i ? {
16
16
  ...f,
17
- ...n || {}
18
- } : n
17
+ ...o || {}
18
+ } : o
19
19
  )
20
20
  ), r && t.push(l(p))), t;
21
21
  };
22
22
  export {
23
- g as getCompatibilityPlugins
23
+ a as getCompatibilityPlugins
24
24
  };
@@ -1,4 +1,4 @@
1
- import { __module as C } from "../../commonjs-virtual-dir/index5.js";
1
+ import { __module as C } from "../../commonjs-virtual-dir/index4.js";
2
2
  var $i = C.exports, Y;
3
3
  function Qi() {
4
4
  return Y ? C.exports : (Y = 1, function(x, Hi) {
@@ -1,4 +1,4 @@
1
- import { __exports as r } from "../../../commonjs-virtual-dir/index4.js";
1
+ import { __exports as r } from "../../../commonjs-virtual-dir/index5.js";
2
2
  import { __require as t } from "./parser.js";
3
3
  import { __require as m } from "./writer.js";
4
4
  import { __require as p } from "./grammar.js";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "module-develop-kit",
3
3
  "author": "Front-End team",
4
- "version": "1.0.0",
4
+ "version": "1.0.2",
5
5
  "type": "module",
6
6
  "description": "前端项目通用工具包",
7
7
  "module": "dist/main.js",