usc-rtc-client 2.2.0 → 2.2.1
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 +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.es.js +150 -138
- package/dist/index.umd.js +4 -4
- package/package.json +4 -5
package/Readme.md
CHANGED
|
@@ -471,7 +471,11 @@ export function playRemote(
|
|
|
471
471
|
autoPlay?: boolean
|
|
472
472
|
muted?: boolean
|
|
473
473
|
}
|
|
474
|
-
): Promise<{
|
|
474
|
+
): Promise<{
|
|
475
|
+
destroy: () => void;
|
|
476
|
+
on: (event: string, callback: Function) => void;
|
|
477
|
+
off: (event: string, callback: Function) => void;
|
|
478
|
+
}>
|
|
475
479
|
|
|
476
480
|
export function renderStreamToContainer(stream: MediaStream, container: HTMLVideoElement | HTMLAudioElement): void
|
|
477
481
|
|
package/dist/index.d.ts
CHANGED
|
@@ -17,7 +17,11 @@ export declare const createRtcClient: (config: {
|
|
|
17
17
|
export declare const playRemote: (server: string, remoteNumber: string, container: HTMLVideoElement, option?: {
|
|
18
18
|
expireTime?: number;
|
|
19
19
|
heartTime?: number;
|
|
20
|
-
}) => Promise<
|
|
20
|
+
}) => Promise<{
|
|
21
|
+
destroy: () => void;
|
|
22
|
+
on: (event: string, callback: (...args: any[]) => void) => void;
|
|
23
|
+
off: (event: string, callback: (...args: any[]) => void) => void;
|
|
24
|
+
}>;
|
|
21
25
|
/**
|
|
22
26
|
* 获取webrtc授权, 只需要调用一次,在合适的场景下使用就可以了
|
|
23
27
|
*/
|
package/dist/index.es.js
CHANGED
|
@@ -45,16 +45,16 @@ var x = { exports: {} }, H;
|
|
|
45
45
|
function pe() {
|
|
46
46
|
if (H) return x.exports;
|
|
47
47
|
H = 1;
|
|
48
|
-
var i = typeof Reflect == "object" ? Reflect : null, e = i && typeof i.apply == "function" ? i.apply : function(o, d,
|
|
49
|
-
return Function.prototype.apply.call(o, d,
|
|
48
|
+
var i = typeof Reflect == "object" ? Reflect : null, e = i && typeof i.apply == "function" ? i.apply : function(o, d, l) {
|
|
49
|
+
return Function.prototype.apply.call(o, d, l);
|
|
50
50
|
}, t;
|
|
51
51
|
i && typeof i.ownKeys == "function" ? t = i.ownKeys : Object.getOwnPropertySymbols ? t = function(o) {
|
|
52
52
|
return Object.getOwnPropertyNames(o).concat(Object.getOwnPropertySymbols(o));
|
|
53
53
|
} : t = function(o) {
|
|
54
54
|
return Object.getOwnPropertyNames(o);
|
|
55
55
|
};
|
|
56
|
-
function s(
|
|
57
|
-
console && console.warn && console.warn(
|
|
56
|
+
function s(c) {
|
|
57
|
+
console && console.warn && console.warn(c);
|
|
58
58
|
}
|
|
59
59
|
var n = Number.isNaN || function(o) {
|
|
60
60
|
return o !== o;
|
|
@@ -63,20 +63,20 @@ function pe() {
|
|
|
63
63
|
r.init.call(this);
|
|
64
64
|
}
|
|
65
65
|
x.exports = r, x.exports.once = le, r.EventEmitter = r, r.prototype._events = void 0, r.prototype._eventsCount = 0, r.prototype._maxListeners = void 0;
|
|
66
|
-
var
|
|
67
|
-
function
|
|
68
|
-
if (typeof
|
|
69
|
-
throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof
|
|
66
|
+
var a = 10;
|
|
67
|
+
function u(c) {
|
|
68
|
+
if (typeof c != "function")
|
|
69
|
+
throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof c);
|
|
70
70
|
}
|
|
71
71
|
Object.defineProperty(r, "defaultMaxListeners", {
|
|
72
72
|
enumerable: !0,
|
|
73
73
|
get: function() {
|
|
74
|
-
return
|
|
74
|
+
return a;
|
|
75
75
|
},
|
|
76
|
-
set: function(
|
|
77
|
-
if (typeof
|
|
78
|
-
throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' +
|
|
79
|
-
|
|
76
|
+
set: function(c) {
|
|
77
|
+
if (typeof c != "number" || c < 0 || n(c))
|
|
78
|
+
throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + c + ".");
|
|
79
|
+
a = c;
|
|
80
80
|
}
|
|
81
81
|
}), r.init = function() {
|
|
82
82
|
(this._events === void 0 || this._events === Object.getPrototypeOf(this)._events) && (this._events = /* @__PURE__ */ Object.create(null), this._eventsCount = 0), this._maxListeners = this._maxListeners || void 0;
|
|
@@ -85,13 +85,13 @@ function pe() {
|
|
|
85
85
|
throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received ' + o + ".");
|
|
86
86
|
return this._maxListeners = o, this;
|
|
87
87
|
};
|
|
88
|
-
function k(
|
|
89
|
-
return
|
|
88
|
+
function k(c) {
|
|
89
|
+
return c._maxListeners === void 0 ? r.defaultMaxListeners : c._maxListeners;
|
|
90
90
|
}
|
|
91
91
|
r.prototype.getMaxListeners = function() {
|
|
92
92
|
return k(this);
|
|
93
93
|
}, r.prototype.emit = function(o) {
|
|
94
|
-
for (var d = [],
|
|
94
|
+
for (var d = [], l = 1; l < arguments.length; l++) d.push(arguments[l]);
|
|
95
95
|
var h = o === "error", v = this._events;
|
|
96
96
|
if (v !== void 0)
|
|
97
97
|
h = h && v.error === void 0;
|
|
@@ -110,24 +110,24 @@ function pe() {
|
|
|
110
110
|
if (typeof O == "function")
|
|
111
111
|
e(O, this, d);
|
|
112
112
|
else
|
|
113
|
-
for (var J = O.length, fe = $(O, J),
|
|
114
|
-
e(fe[
|
|
113
|
+
for (var J = O.length, fe = $(O, J), l = 0; l < J; ++l)
|
|
114
|
+
e(fe[l], this, d);
|
|
115
115
|
return !0;
|
|
116
116
|
};
|
|
117
|
-
function w(
|
|
117
|
+
function w(c, o, d, l) {
|
|
118
118
|
var h, v, f;
|
|
119
|
-
if (
|
|
119
|
+
if (u(d), v = c._events, v === void 0 ? (v = c._events = /* @__PURE__ */ Object.create(null), c._eventsCount = 0) : (v.newListener !== void 0 && (c.emit(
|
|
120
120
|
"newListener",
|
|
121
121
|
o,
|
|
122
122
|
d.listener ? d.listener : d
|
|
123
|
-
), v =
|
|
124
|
-
f = v[o] = d, ++
|
|
125
|
-
else if (typeof f == "function" ? f = v[o] =
|
|
123
|
+
), v = c._events), f = v[o]), f === void 0)
|
|
124
|
+
f = v[o] = d, ++c._eventsCount;
|
|
125
|
+
else if (typeof f == "function" ? f = v[o] = l ? [d, f] : [f, d] : l ? f.unshift(d) : f.push(d), h = k(c), h > 0 && f.length > h && !f.warned) {
|
|
126
126
|
f.warned = !0;
|
|
127
127
|
var C = new Error("Possible EventEmitter memory leak detected. " + f.length + " " + String(o) + " listeners added. Use emitter.setMaxListeners() to increase limit");
|
|
128
|
-
C.name = "MaxListenersExceededWarning", C.emitter =
|
|
128
|
+
C.name = "MaxListenersExceededWarning", C.emitter = c, C.type = o, C.count = f.length, s(C);
|
|
129
129
|
}
|
|
130
|
-
return
|
|
130
|
+
return c;
|
|
131
131
|
}
|
|
132
132
|
r.prototype.addListener = function(o, d) {
|
|
133
133
|
return w(this, o, d, !1);
|
|
@@ -138,70 +138,70 @@ function pe() {
|
|
|
138
138
|
if (!this.fired)
|
|
139
139
|
return this.target.removeListener(this.type, this.wrapFn), this.fired = !0, arguments.length === 0 ? this.listener.call(this.target) : this.listener.apply(this.target, arguments);
|
|
140
140
|
}
|
|
141
|
-
function L(
|
|
142
|
-
var
|
|
143
|
-
return h.listener = d,
|
|
141
|
+
function L(c, o, d) {
|
|
142
|
+
var l = { fired: !1, wrapFn: void 0, target: c, type: o, listener: d }, h = A.bind(l);
|
|
143
|
+
return h.listener = d, l.wrapFn = h, h;
|
|
144
144
|
}
|
|
145
145
|
r.prototype.once = function(o, d) {
|
|
146
|
-
return
|
|
146
|
+
return u(d), this.on(o, L(this, o, d)), this;
|
|
147
147
|
}, r.prototype.prependOnceListener = function(o, d) {
|
|
148
|
-
return
|
|
148
|
+
return u(d), this.prependListener(o, L(this, o, d)), this;
|
|
149
149
|
}, r.prototype.removeListener = function(o, d) {
|
|
150
|
-
var
|
|
151
|
-
if (
|
|
150
|
+
var l, h, v, f, C;
|
|
151
|
+
if (u(d), h = this._events, h === void 0)
|
|
152
152
|
return this;
|
|
153
|
-
if (
|
|
153
|
+
if (l = h[o], l === void 0)
|
|
154
154
|
return this;
|
|
155
|
-
if (
|
|
156
|
-
--this._eventsCount === 0 ? this._events = /* @__PURE__ */ Object.create(null) : (delete h[o], h.removeListener && this.emit("removeListener", o,
|
|
157
|
-
else if (typeof
|
|
158
|
-
for (v = -1, f =
|
|
159
|
-
if (
|
|
160
|
-
C =
|
|
155
|
+
if (l === d || l.listener === d)
|
|
156
|
+
--this._eventsCount === 0 ? this._events = /* @__PURE__ */ Object.create(null) : (delete h[o], h.removeListener && this.emit("removeListener", o, l.listener || d));
|
|
157
|
+
else if (typeof l != "function") {
|
|
158
|
+
for (v = -1, f = l.length - 1; f >= 0; f--)
|
|
159
|
+
if (l[f] === d || l[f].listener === d) {
|
|
160
|
+
C = l[f].listener, v = f;
|
|
161
161
|
break;
|
|
162
162
|
}
|
|
163
163
|
if (v < 0)
|
|
164
164
|
return this;
|
|
165
|
-
v === 0 ?
|
|
165
|
+
v === 0 ? l.shift() : de(l, v), l.length === 1 && (h[o] = l[0]), h.removeListener !== void 0 && this.emit("removeListener", o, C || d);
|
|
166
166
|
}
|
|
167
167
|
return this;
|
|
168
168
|
}, r.prototype.off = r.prototype.removeListener, r.prototype.removeAllListeners = function(o) {
|
|
169
|
-
var d,
|
|
170
|
-
if (
|
|
169
|
+
var d, l, h;
|
|
170
|
+
if (l = this._events, l === void 0)
|
|
171
171
|
return this;
|
|
172
|
-
if (
|
|
173
|
-
return arguments.length === 0 ? (this._events = /* @__PURE__ */ Object.create(null), this._eventsCount = 0) :
|
|
172
|
+
if (l.removeListener === void 0)
|
|
173
|
+
return arguments.length === 0 ? (this._events = /* @__PURE__ */ Object.create(null), this._eventsCount = 0) : l[o] !== void 0 && (--this._eventsCount === 0 ? this._events = /* @__PURE__ */ Object.create(null) : delete l[o]), this;
|
|
174
174
|
if (arguments.length === 0) {
|
|
175
|
-
var v = Object.keys(
|
|
175
|
+
var v = Object.keys(l), f;
|
|
176
176
|
for (h = 0; h < v.length; ++h)
|
|
177
177
|
f = v[h], f !== "removeListener" && this.removeAllListeners(f);
|
|
178
178
|
return this.removeAllListeners("removeListener"), this._events = /* @__PURE__ */ Object.create(null), this._eventsCount = 0, this;
|
|
179
179
|
}
|
|
180
|
-
if (d =
|
|
180
|
+
if (d = l[o], typeof d == "function")
|
|
181
181
|
this.removeListener(o, d);
|
|
182
182
|
else if (d !== void 0)
|
|
183
183
|
for (h = d.length - 1; h >= 0; h--)
|
|
184
184
|
this.removeListener(o, d[h]);
|
|
185
185
|
return this;
|
|
186
186
|
};
|
|
187
|
-
function F(
|
|
188
|
-
var
|
|
189
|
-
if (
|
|
187
|
+
function F(c, o, d) {
|
|
188
|
+
var l = c._events;
|
|
189
|
+
if (l === void 0)
|
|
190
190
|
return [];
|
|
191
|
-
var h =
|
|
191
|
+
var h = l[o];
|
|
192
192
|
return h === void 0 ? [] : typeof h == "function" ? d ? [h.listener || h] : [h] : d ? ue(h) : $(h, h.length);
|
|
193
193
|
}
|
|
194
194
|
r.prototype.listeners = function(o) {
|
|
195
195
|
return F(this, o, !0);
|
|
196
196
|
}, r.prototype.rawListeners = function(o) {
|
|
197
197
|
return F(this, o, !1);
|
|
198
|
-
}, r.listenerCount = function(
|
|
199
|
-
return typeof
|
|
198
|
+
}, r.listenerCount = function(c, o) {
|
|
199
|
+
return typeof c.listenerCount == "function" ? c.listenerCount(o) : Y.call(c, o);
|
|
200
200
|
}, r.prototype.listenerCount = Y;
|
|
201
|
-
function Y(
|
|
201
|
+
function Y(c) {
|
|
202
202
|
var o = this._events;
|
|
203
203
|
if (o !== void 0) {
|
|
204
|
-
var d = o[
|
|
204
|
+
var d = o[c];
|
|
205
205
|
if (typeof d == "function")
|
|
206
206
|
return 1;
|
|
207
207
|
if (d !== void 0)
|
|
@@ -212,44 +212,44 @@ function pe() {
|
|
|
212
212
|
r.prototype.eventNames = function() {
|
|
213
213
|
return this._eventsCount > 0 ? t(this._events) : [];
|
|
214
214
|
};
|
|
215
|
-
function $(
|
|
216
|
-
for (var d = new Array(o),
|
|
217
|
-
d[
|
|
215
|
+
function $(c, o) {
|
|
216
|
+
for (var d = new Array(o), l = 0; l < o; ++l)
|
|
217
|
+
d[l] = c[l];
|
|
218
218
|
return d;
|
|
219
219
|
}
|
|
220
|
-
function de(
|
|
221
|
-
for (; o + 1 <
|
|
222
|
-
|
|
223
|
-
|
|
220
|
+
function de(c, o) {
|
|
221
|
+
for (; o + 1 < c.length; o++)
|
|
222
|
+
c[o] = c[o + 1];
|
|
223
|
+
c.pop();
|
|
224
224
|
}
|
|
225
|
-
function ue(
|
|
226
|
-
for (var o = new Array(
|
|
227
|
-
o[d] =
|
|
225
|
+
function ue(c) {
|
|
226
|
+
for (var o = new Array(c.length), d = 0; d < o.length; ++d)
|
|
227
|
+
o[d] = c[d].listener || c[d];
|
|
228
228
|
return o;
|
|
229
229
|
}
|
|
230
|
-
function le(
|
|
231
|
-
return new Promise(function(d,
|
|
230
|
+
function le(c, o) {
|
|
231
|
+
return new Promise(function(d, l) {
|
|
232
232
|
function h(f) {
|
|
233
|
-
|
|
233
|
+
c.removeListener(o, v), l(f);
|
|
234
234
|
}
|
|
235
235
|
function v() {
|
|
236
|
-
typeof
|
|
236
|
+
typeof c.removeListener == "function" && c.removeListener("error", h), d([].slice.call(arguments));
|
|
237
237
|
}
|
|
238
|
-
K(
|
|
238
|
+
K(c, o, v, { once: !0 }), o !== "error" && he(c, h, { once: !0 });
|
|
239
239
|
});
|
|
240
240
|
}
|
|
241
|
-
function he(
|
|
242
|
-
typeof
|
|
241
|
+
function he(c, o, d) {
|
|
242
|
+
typeof c.on == "function" && K(c, "error", o, d);
|
|
243
243
|
}
|
|
244
|
-
function K(
|
|
245
|
-
if (typeof
|
|
246
|
-
|
|
247
|
-
else if (typeof
|
|
248
|
-
|
|
249
|
-
|
|
244
|
+
function K(c, o, d, l) {
|
|
245
|
+
if (typeof c.on == "function")
|
|
246
|
+
l.once ? c.once(o, d) : c.on(o, d);
|
|
247
|
+
else if (typeof c.addEventListener == "function")
|
|
248
|
+
c.addEventListener(o, function h(v) {
|
|
249
|
+
l.once && c.removeEventListener(o, h), d(v);
|
|
250
250
|
});
|
|
251
251
|
else
|
|
252
|
-
throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type ' + typeof
|
|
252
|
+
throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type ' + typeof c);
|
|
253
253
|
}
|
|
254
254
|
return x.exports;
|
|
255
255
|
}
|
|
@@ -425,13 +425,13 @@ class ke extends ge {
|
|
|
425
425
|
preferCodec(e = "H264", t = "PCMA") {
|
|
426
426
|
this.videoCodecs = [];
|
|
427
427
|
let s = RTCRtpSender.getCapabilities("video");
|
|
428
|
-
s !== null && this.videoCodecs.push(...s.codecs.filter((
|
|
428
|
+
s !== null && this.videoCodecs.push(...s.codecs.filter((u) => u.mimeType === `video/${e}`));
|
|
429
429
|
let n = RTCRtpReceiver.getCapabilities("video");
|
|
430
|
-
n !== null && this.videoCodecs.push(...n.codecs.filter((
|
|
430
|
+
n !== null && this.videoCodecs.push(...n.codecs.filter((u) => u.mimeType === `video/${e}`)), this.audioCodecs = [];
|
|
431
431
|
let r = RTCRtpSender.getCapabilities("audio");
|
|
432
|
-
r !== null && this.audioCodecs.push(...r.codecs.filter((
|
|
433
|
-
let
|
|
434
|
-
|
|
432
|
+
r !== null && this.audioCodecs.push(...r.codecs.filter((u) => u.mimeType === `audio/${t}`));
|
|
433
|
+
let a = RTCRtpReceiver.getCapabilities("audio");
|
|
434
|
+
a !== null && this.audioCodecs.push(...a.codecs.filter((u) => u.mimeType === `audio/${t}`));
|
|
435
435
|
}
|
|
436
436
|
trackIsInPeerConnection(e) {
|
|
437
437
|
return this.peerConnection?.getSenders().some((t) => t.track?.id === e.id) ?? !1;
|
|
@@ -584,8 +584,8 @@ class ie extends ke {
|
|
|
584
584
|
const { audioOnly: s = !1, muted: n = !1 } = t || {};
|
|
585
585
|
n && (e.muted = !0), this.on(S.stream, (r) => {
|
|
586
586
|
if (console.log("远程流", r), r.stream) {
|
|
587
|
-
const
|
|
588
|
-
ee(
|
|
587
|
+
const a = s ? new MediaStream(r.stream.getAudioTracks()) : r.stream;
|
|
588
|
+
ee(a, e);
|
|
589
589
|
}
|
|
590
590
|
}), this.on(S.bye, () => {
|
|
591
591
|
e && (e.pause(), e.srcObject = null);
|
|
@@ -604,9 +604,9 @@ class Q extends ie {
|
|
|
604
604
|
let [e, t] = this.checkIsNotUndefined(this.rtcClient, this.remoteNumber), s = await this.createOffer(), { status: n, sdp: r } = await e.invite(t, this.sessionId, s.sdp);
|
|
605
605
|
if (n === N.ok) {
|
|
606
606
|
await this.setAnswer(r);
|
|
607
|
-
const
|
|
608
|
-
`),
|
|
609
|
-
this.responseCallType =
|
|
607
|
+
const a = r.split(`\r
|
|
608
|
+
`), u = a.find((w) => w.startsWith("m=audio")), k = a.find((w) => w.startsWith("m=video"));
|
|
609
|
+
this.responseCallType = u && k ? y.audioVideo : u ? y.audio : k ? y.video : y.unknown;
|
|
610
610
|
}
|
|
611
611
|
return n;
|
|
612
612
|
}
|
|
@@ -701,12 +701,12 @@ class Ee extends q.EventEmitter {
|
|
|
701
701
|
async testWs(e) {
|
|
702
702
|
return e.reduce((t, s) => t.then(
|
|
703
703
|
(n) => Promise.resolve(n),
|
|
704
|
-
(n) => new Promise((r,
|
|
705
|
-
const
|
|
706
|
-
|
|
707
|
-
n.push(s),
|
|
708
|
-
},
|
|
709
|
-
|
|
704
|
+
(n) => new Promise((r, a) => {
|
|
705
|
+
const u = new WebSocket(s);
|
|
706
|
+
u.onopen = () => {
|
|
707
|
+
n.push(s), u.close(), r(n);
|
|
708
|
+
}, u.onclose = () => {
|
|
709
|
+
a(n);
|
|
710
710
|
};
|
|
711
711
|
})
|
|
712
712
|
), Promise.reject([])).then(
|
|
@@ -732,9 +732,9 @@ class Ee extends q.EventEmitter {
|
|
|
732
732
|
);
|
|
733
733
|
r.on(R.connected, () => {
|
|
734
734
|
this.socketWorker = r, this.onConnected(), s();
|
|
735
|
-
}), r.on(R.disconnected, (
|
|
736
|
-
this.socketWorker = void 0, this.onDisConnected(
|
|
737
|
-
}), r.on(R.message, (
|
|
735
|
+
}), r.on(R.disconnected, (a) => {
|
|
736
|
+
this.socketWorker = void 0, this.onDisConnected(a), n("socketWorker connecion failed");
|
|
737
|
+
}), r.on(R.message, (a) => this.onReviceMessage(a)), r.connect();
|
|
738
738
|
} else
|
|
739
739
|
n("server is empty");
|
|
740
740
|
});
|
|
@@ -883,34 +883,34 @@ function Le(i, e, t, s) {
|
|
|
883
883
|
if (e)
|
|
884
884
|
i.call(t, s);
|
|
885
885
|
else
|
|
886
|
-
for (var n = i.length, r = M(i, n),
|
|
887
|
-
r[
|
|
886
|
+
for (var n = i.length, r = M(i, n), a = 0; a < n; ++a)
|
|
887
|
+
r[a].call(t, s);
|
|
888
888
|
}
|
|
889
889
|
function _e(i, e, t, s, n) {
|
|
890
890
|
if (e)
|
|
891
891
|
i.call(t, s, n);
|
|
892
892
|
else
|
|
893
|
-
for (var r = i.length,
|
|
894
|
-
|
|
893
|
+
for (var r = i.length, a = M(i, r), u = 0; u < r; ++u)
|
|
894
|
+
a[u].call(t, s, n);
|
|
895
895
|
}
|
|
896
896
|
function Re(i, e, t, s, n, r) {
|
|
897
897
|
if (e)
|
|
898
898
|
i.call(t, s, n, r);
|
|
899
899
|
else
|
|
900
|
-
for (var
|
|
901
|
-
|
|
900
|
+
for (var a = i.length, u = M(i, a), k = 0; k < a; ++k)
|
|
901
|
+
u[k].call(t, s, n, r);
|
|
902
902
|
}
|
|
903
903
|
function Ie(i, e, t, s) {
|
|
904
904
|
if (e)
|
|
905
905
|
i.apply(t, s);
|
|
906
906
|
else
|
|
907
|
-
for (var n = i.length, r = M(i, n),
|
|
908
|
-
r[
|
|
907
|
+
for (var n = i.length, r = M(i, n), a = 0; a < n; ++a)
|
|
908
|
+
r[a].apply(t, s);
|
|
909
909
|
}
|
|
910
910
|
m.prototype.emit = function(e) {
|
|
911
|
-
var t, s, n, r,
|
|
912
|
-
if (
|
|
913
|
-
w = w &&
|
|
911
|
+
var t, s, n, r, a, u, k, w = e === "error";
|
|
912
|
+
if (u = this._events, u)
|
|
913
|
+
w = w && u.error == null;
|
|
914
914
|
else if (!w)
|
|
915
915
|
return !1;
|
|
916
916
|
if (k = this.domain, w) {
|
|
@@ -924,7 +924,7 @@ m.prototype.emit = function(e) {
|
|
|
924
924
|
}
|
|
925
925
|
return !1;
|
|
926
926
|
}
|
|
927
|
-
if (s =
|
|
927
|
+
if (s = u[e], !s)
|
|
928
928
|
return !1;
|
|
929
929
|
var L = typeof s == "function";
|
|
930
930
|
switch (n = arguments.length, n) {
|
|
@@ -943,26 +943,26 @@ m.prototype.emit = function(e) {
|
|
|
943
943
|
break;
|
|
944
944
|
// slower
|
|
945
945
|
default:
|
|
946
|
-
for (r = new Array(n - 1),
|
|
947
|
-
r[
|
|
946
|
+
for (r = new Array(n - 1), a = 1; a < n; a++)
|
|
947
|
+
r[a - 1] = arguments[a];
|
|
948
948
|
Ie(s, L, this, r);
|
|
949
949
|
}
|
|
950
950
|
return !0;
|
|
951
951
|
};
|
|
952
952
|
function re(i, e, t, s) {
|
|
953
|
-
var n, r,
|
|
953
|
+
var n, r, a;
|
|
954
954
|
if (typeof t != "function")
|
|
955
955
|
throw new TypeError('"listener" argument must be a function');
|
|
956
956
|
if (r = i._events, r ? (r.newListener && (i.emit(
|
|
957
957
|
"newListener",
|
|
958
958
|
e,
|
|
959
959
|
t.listener ? t.listener : t
|
|
960
|
-
), r = i._events),
|
|
961
|
-
|
|
962
|
-
else if (typeof
|
|
963
|
-
|
|
964
|
-
var
|
|
965
|
-
|
|
960
|
+
), r = i._events), a = r[e]) : (r = i._events = new _(), i._eventsCount = 0), !a)
|
|
961
|
+
a = r[e] = t, ++i._eventsCount;
|
|
962
|
+
else if (typeof a == "function" ? a = r[e] = s ? [t, a] : [a, t] : s ? a.unshift(t) : a.push(t), !a.warned && (n = ne(i), n && n > 0 && a.length > n)) {
|
|
963
|
+
a.warned = !0;
|
|
964
|
+
var u = new Error("Possible EventEmitter memory leak detected. " + a.length + " " + e + " listeners added. Use emitter.setMaxListeners() to increase limit");
|
|
965
|
+
u.name = "MaxListenersExceededWarning", u.emitter = i, u.type = e, u.count = a.length, Ne(u);
|
|
966
966
|
}
|
|
967
967
|
return i;
|
|
968
968
|
}
|
|
@@ -994,7 +994,7 @@ m.prototype.prependOnceListener = function(e, t) {
|
|
|
994
994
|
return this.prependListener(e, oe(this, e, t)), this;
|
|
995
995
|
};
|
|
996
996
|
m.prototype.removeListener = function(e, t) {
|
|
997
|
-
var s, n, r,
|
|
997
|
+
var s, n, r, a, u;
|
|
998
998
|
if (typeof t != "function")
|
|
999
999
|
throw new TypeError('"listener" argument must be a function');
|
|
1000
1000
|
if (n = this._events, !n)
|
|
@@ -1004,9 +1004,9 @@ m.prototype.removeListener = function(e, t) {
|
|
|
1004
1004
|
if (s === t || s.listener && s.listener === t)
|
|
1005
1005
|
--this._eventsCount === 0 ? this._events = new _() : (delete n[e], n.removeListener && this.emit("removeListener", e, s.listener || t));
|
|
1006
1006
|
else if (typeof s != "function") {
|
|
1007
|
-
for (r = -1,
|
|
1008
|
-
if (s[
|
|
1009
|
-
|
|
1007
|
+
for (r = -1, a = s.length; a-- > 0; )
|
|
1008
|
+
if (s[a] === t || s[a].listener && s[a].listener === t) {
|
|
1009
|
+
u = s[a].listener, r = a;
|
|
1010
1010
|
break;
|
|
1011
1011
|
}
|
|
1012
1012
|
if (r < 0)
|
|
@@ -1017,7 +1017,7 @@ m.prototype.removeListener = function(e, t) {
|
|
|
1017
1017
|
delete n[e];
|
|
1018
1018
|
} else
|
|
1019
1019
|
Oe(s, r);
|
|
1020
|
-
n.removeListener && this.emit("removeListener", e,
|
|
1020
|
+
n.removeListener && this.emit("removeListener", e, u || t);
|
|
1021
1021
|
}
|
|
1022
1022
|
return this;
|
|
1023
1023
|
};
|
|
@@ -1031,8 +1031,8 @@ m.prototype.removeAllListeners = function(e) {
|
|
|
1031
1031
|
if (!s.removeListener)
|
|
1032
1032
|
return arguments.length === 0 ? (this._events = new _(), this._eventsCount = 0) : s[e] && (--this._eventsCount === 0 ? this._events = new _() : delete s[e]), this;
|
|
1033
1033
|
if (arguments.length === 0) {
|
|
1034
|
-
for (var n = Object.keys(s), r = 0,
|
|
1035
|
-
|
|
1034
|
+
for (var n = Object.keys(s), r = 0, a; r < n.length; ++r)
|
|
1035
|
+
a = n[r], a !== "removeListener" && this.removeAllListeners(a);
|
|
1036
1036
|
return this.removeAllListeners("removeListener"), this._events = new _(), this._eventsCount = 0, this;
|
|
1037
1037
|
}
|
|
1038
1038
|
if (t = s[e], typeof t == "function")
|
|
@@ -1284,9 +1284,9 @@ class Ge extends ie {
|
|
|
1284
1284
|
//invite seq
|
|
1285
1285
|
constructor(e, t, s, n, r) {
|
|
1286
1286
|
super(e, t, s), this.callType = y.unknown, this.inviteSeq = r, this.inviteOffer = n;
|
|
1287
|
-
const
|
|
1288
|
-
`),
|
|
1289
|
-
this.callType =
|
|
1287
|
+
const a = n.split(`\r
|
|
1288
|
+
`), u = a.find((w) => w.startsWith("m=audio")), k = a.find((w) => w.startsWith("m=video"));
|
|
1289
|
+
this.callType = u && k ? y.audioVideo : u ? y.audio : k ? y.video : y.unknown;
|
|
1290
1290
|
}
|
|
1291
1291
|
}
|
|
1292
1292
|
class ce extends W {
|
|
@@ -1302,16 +1302,16 @@ class ce extends W {
|
|
|
1302
1302
|
playRemote(e, t, s) {
|
|
1303
1303
|
return new Promise((n, r) => {
|
|
1304
1304
|
try {
|
|
1305
|
-
let
|
|
1306
|
-
this.allSession.push(
|
|
1307
|
-
p("playRemote start status",
|
|
1308
|
-
}).catch((
|
|
1309
|
-
r(
|
|
1310
|
-
}),
|
|
1311
|
-
this.removeSession(
|
|
1305
|
+
let a = new Q(this, B(), e);
|
|
1306
|
+
this.allSession.push(a), a.playRemoteStream(t, s), a.start().then((u) => {
|
|
1307
|
+
p("playRemote start status", u), u === N.ok ? n(a) : r(new Error(`Failed to start session, status: ${u}`));
|
|
1308
|
+
}).catch((u) => {
|
|
1309
|
+
r(u);
|
|
1310
|
+
}), a.on(S.bye, () => {
|
|
1311
|
+
this.removeSession(a);
|
|
1312
1312
|
});
|
|
1313
|
-
} catch (
|
|
1314
|
-
r(
|
|
1313
|
+
} catch (a) {
|
|
1314
|
+
r(a);
|
|
1315
1315
|
}
|
|
1316
1316
|
});
|
|
1317
1317
|
}
|
|
@@ -1354,7 +1354,19 @@ const We = async (i) => {
|
|
|
1354
1354
|
}, Ue = async (i, e, t, s) => {
|
|
1355
1355
|
T.random = String(Date.now());
|
|
1356
1356
|
let n = new ce({ server: i, localNumber: "anonymous", ...s });
|
|
1357
|
-
|
|
1357
|
+
await n.reConnect();
|
|
1358
|
+
const r = await n.playRemote(e, t);
|
|
1359
|
+
return {
|
|
1360
|
+
destroy: () => {
|
|
1361
|
+
r.destroy(), n.destroy();
|
|
1362
|
+
},
|
|
1363
|
+
on: (a, u) => {
|
|
1364
|
+
r.on(a, u);
|
|
1365
|
+
},
|
|
1366
|
+
off: (a, u) => {
|
|
1367
|
+
r.off(a, u);
|
|
1368
|
+
}
|
|
1369
|
+
};
|
|
1358
1370
|
}, qe = async () => {
|
|
1359
1371
|
await navigator.mediaDevices.getUserMedia({ audio: !0, video: !0 });
|
|
1360
1372
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
(function(g,C){typeof exports=="object"&&typeof module<"u"?C(exports):typeof define=="function"&&define.amd?define(["exports"],C):(g=typeof globalThis<"u"?globalThis:g||self,C(g.UscRtc={}))})(this,(function(g){"use strict";var C=(i=>(i.bye="bye",i.stream="stream",i.reInvite="reInvite",i.localAudioChange="localAudioChange",i.localVideoChange="localVideoChange",i.localStreamChange="localStreamChange",i))(C||{}),P=(i=>(i.connected="connected",i.disconnected="disconnected",i.invite="invite",i))(P||{}),x=(i=>(i.PTTInfo="PTTInfo",i.FPREInfo="FPREInfo",i.IMSInfo="IMSInfo",i.ERROR="error",i.SPEAKER="speaker",i.TALKING="talking",i.ACTIVE_GROUP="activeGroup",i.JOIN_INFO="joinInfo",i))(x||{}),y=(i=>(i.MESSAGE_TYPE_REGISTER="REGISTER",i.MESSAGE_TYPE_INVITE="INVITE",i.MESSAGE_TYPE_REINVITE="reINVITE",i.MESSAGE_TYPE_ICE="ICE",i.MESSAGE_TYPE_INFO="INFO",i.MESSAGE_TYPE_BYE="BYE",i))(y||{}),W=(i=>(i.FPRE="fpre",i.IMS="ims",i.PTT_QUERY_ONLINE_USER="15",i.PTT_ANSWER_ONLINE_USER="115",i.PTT_QUERY_INFO="16",i.PTT_QUERY_INFO_CONFIRM="116",i))(W||{});let B=(i=21)=>crypto.getRandomValues(new Uint8Array(i)).reduce((e,t)=>(t&=63,t<36?e+=t.toString(36):t<62?e+=(t-26).toString(36).toUpperCase():t>62?e+="-":e+="_",e),"");const le=i=>{i!==void 0&&(i.pause(),i.removeAttribute("src"),i.removeAttribute("srcObject"))},q=(i,e)=>{i!==void 0&&e!==void 0&&(e.srcObject=i,e.play())},F=i=>{i.onaddtrack=null,i.onremovetrack=null,i.getTracks().forEach(e=>{i?.removeTrack(e),e.onended=null,e.onmute=null,e.onunmute=null,e.stop()})};let G=!1;const p=(i,...e)=>{G&&console.log(`%c usc-rtc-devtools %c ${i} %c `,"background:#35495e ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff","background:#41b883 ; padding: 1px; border-radius: 0 3px 3px 0; color: #fff","background:transparent",...e)},he=(i,...e)=>{G&&console.log(`%c usc-rtc-devtools %c ${i} %c `,"background:#35495e ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff","background:#ff0000 ; padding: 1px; border-radius: 0 3px 3px 0; color: #fff","background:transparent",...e)},fe=()=>{G=!1},me=()=>{G=!0};class ve{static formatOffer(e){let{sdp:t}=e;if(t===void 0)throw new Error("offer sdp is empty");return t=t.split(`\r
|
|
2
2
|
`).filter(s=>s.indexOf("a=group:BUNDLE")===-1).join(`\r
|
|
3
|
-
`),e.sdp=t,e}}var D={exports:{}},H;function pe(){if(H)return D.exports;H=1;var i=typeof Reflect=="object"?Reflect:null,e=i&&typeof i.apply=="function"?i.apply:function(o,d,u){return Function.prototype.apply.call(o,d,u)},t;i&&typeof i.ownKeys=="function"?t=i.ownKeys:Object.getOwnPropertySymbols?t=function(o){return Object.getOwnPropertyNames(o).concat(Object.getOwnPropertySymbols(o))}:t=function(o){return Object.getOwnPropertyNames(o)};function s(a){console&&console.warn&&console.warn(a)}var n=Number.isNaN||function(o){return o!==o};function r(){r.init.call(this)}D.exports=r,D.exports.once=We,r.EventEmitter=r,r.prototype._events=void 0,r.prototype._eventsCount=0,r.prototype._maxListeners=void 0;var c=10;function l(a){if(typeof a!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof a)}Object.defineProperty(r,"defaultMaxListeners",{enumerable:!0,get:function(){return c},set:function(a){if(typeof a!="number"||a<0||n(a))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+a+".");c=a}}),r.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},r.prototype.setMaxListeners=function(o){if(typeof o!="number"||o<0||n(o))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+o+".");return this._maxListeners=o,this};function w(a){return a._maxListeners===void 0?r.defaultMaxListeners:a._maxListeners}r.prototype.getMaxListeners=function(){return w(this)},r.prototype.emit=function(o){for(var d=[],u=1;u<arguments.length;u++)d.push(arguments[u]);var h=o==="error",v=this._events;if(v!==void 0)h=h&&v.error===void 0;else if(!h)return!1;if(h){var f;if(d.length>0&&(f=d[0]),f instanceof Error)throw f;var S=new Error("Unhandled error."+(f?" ("+f.message+")":""));throw S.context=f,S}var A=v[o];if(A===void 0)return!1;if(typeof A=="function")e(A,this,d);else for(var ue=A.length,Fe=ce(A,ue),u=0;u<ue;++u)e(Fe[u],this,d);return!0};function E(a,o,d,u){var h,v,f;if(l(d),v=a._events,v===void 0?(v=a._events=Object.create(null),a._eventsCount=0):(v.newListener!==void 0&&(a.emit("newListener",o,d.listener?d.listener:d),v=a._events),f=v[o]),f===void 0)f=v[o]=d,++a._eventsCount;else if(typeof f=="function"?f=v[o]=u?[d,f]:[f,d]:u?f.unshift(d):f.push(d),h=w(a),h>0&&f.length>h&&!f.warned){f.warned=!0;var S=new Error("Possible EventEmitter memory leak detected. "+f.length+" "+String(o)+" listeners added. Use emitter.setMaxListeners() to increase limit");S.name="MaxListenersExceededWarning",S.emitter=a,S.type=o,S.count=f.length,s(S)}return a}r.prototype.addListener=function(o,d){return E(this,o,d,!1)},r.prototype.on=r.prototype.addListener,r.prototype.prependListener=function(o,d){return E(this,o,d,!0)};function U(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function R(a,o,d){var u={fired:!1,wrapFn:void 0,target:a,type:o,listener:d},h=U.bind(u);return h.listener=d,u.wrapFn=h,h}r.prototype.once=function(o,d){return l(d),this.on(o,R(this,o,d)),this},r.prototype.prependOnceListener=function(o,d){return l(d),this.prependListener(o,R(this,o,d)),this},r.prototype.removeListener=function(o,d){var u,h,v,f,S;if(l(d),h=this._events,h===void 0)return this;if(u=h[o],u===void 0)return this;if(u===d||u.listener===d)--this._eventsCount===0?this._events=Object.create(null):(delete h[o],h.removeListener&&this.emit("removeListener",o,u.listener||d));else if(typeof u!="function"){for(v=-1,f=u.length-1;f>=0;f--)if(u[f]===d||u[f].listener===d){S=u[f].listener,v=f;break}if(v<0)return this;v===0?u.shift():Ve(u,v),u.length===1&&(h[o]=u[0]),h.removeListener!==void 0&&this.emit("removeListener",o,S||d)}return this},r.prototype.off=r.prototype.removeListener,r.prototype.removeAllListeners=function(o){var d,u,h;if(u=this._events,u===void 0)return this;if(u.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):u[o]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete u[o]),this;if(arguments.length===0){var v=Object.keys(u),f;for(h=0;h<v.length;++h)f=v[h],f!=="removeListener"&&this.removeAllListeners(f);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(d=u[o],typeof d=="function")this.removeListener(o,d);else if(d!==void 0)for(h=d.length-1;h>=0;h--)this.removeListener(o,d[h]);return this};function oe(a,o,d){var u=a._events;if(u===void 0)return[];var h=u[o];return h===void 0?[]:typeof h=="function"?d?[h.listener||h]:[h]:d?Ue(h):ce(h,h.length)}r.prototype.listeners=function(o){return oe(this,o,!0)},r.prototype.rawListeners=function(o){return oe(this,o,!1)},r.listenerCount=function(a,o){return typeof a.listenerCount=="function"?a.listenerCount(o):ae.call(a,o)},r.prototype.listenerCount=ae;function ae(a){var o=this._events;if(o!==void 0){var d=o[a];if(typeof d=="function")return 1;if(d!==void 0)return d.length}return 0}r.prototype.eventNames=function(){return this._eventsCount>0?t(this._events):[]};function ce(a,o){for(var d=new Array(o),u=0;u<o;++u)d[u]=a[u];return d}function Ve(a,o){for(;o+1<a.length;o++)a[o]=a[o+1];a.pop()}function Ue(a){for(var o=new Array(a.length),d=0;d<o.length;++d)o[d]=a[d].listener||a[d];return o}function We(a,o){return new Promise(function(d,u){function h(f){a.removeListener(o,v),u(f)}function v(){typeof a.removeListener=="function"&&a.removeListener("error",h),d([].slice.call(arguments))}de(a,o,v,{once:!0}),o!=="error"&&qe(a,h,{once:!0})})}function qe(a,o,d){typeof a.on=="function"&&de(a,"error",o,d)}function de(a,o,d,u){if(typeof a.on=="function")u.once?a.once(o,d):a.on(o,d);else if(typeof a.addEventListener=="function")a.addEventListener(o,function h(v){u.once&&a.removeEventListener(o,h),d(v)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof a)}return D.exports}var Y=pe();class ge extends Y.EventEmitter{constructor(){super(),this.localMediaStream=new MediaStream,this.videoConstrains={width:{ideal:1920},height:{ideal:1080},frameRate:{ideal:20,max:30},aspectRatio:{ideal:16/9}},this.audioConstrants={noiseSuppression:!0,echoCancellation:!0,autoGainControl:!0},super.setMaxListeners(0)}releaseTrack(e){e!==void 0&&(this.localMediaStream?.removeTrack(e),e.stop())}addDeviceChangeListener(e){navigator.mediaDevices.addEventListener("devicechange",e)}removeDeviceChangeListener(e){navigator.mediaDevices.removeEventListener("devicechange",e)}setVideoTrack(e){this.emit(C.localVideoChange,{from:this.videoTrack,to:e}),this.videoTrack!==e&&(this.localMediaStream?.addTrack(e),this.localTractChange(this.videoTrack,e)),this.videoTrack=e}setAudioTrack(e){this.emit(C.localAudioChange,{from:this.audioTrack,to:e}),this.audioTrack!==e&&(this.localMediaStream?.addTrack(e),this.localTractChange(this.audioTrack,e)),this.audioTrack=e}renderLocalStreamToContainer(e){q(this.localMediaStream,e)}async getAllInputResource(){let e=await navigator.mediaDevices.enumerateDevices();return{audio:e.filter(t=>t.kind==="audioinput"),video:e.filter(t=>t.kind==="videoinput")}}async useDefaultDevice(e){let t={audio:!0,video:!0},s=await navigator.mediaDevices.getUserMedia(t);this.setAudioTrack(s.getAudioTracks()[0]),this.setVideoTrack(s.getVideoTracks()[0]),this.renderLocalStreamToContainer(e)}async useAudio(e){let t=e===void 0?{audio:{...this.audioConstrants},video:!1}:{video:!1,audio:{deviceId:e,...this.audioConstrants}},s=await navigator.mediaDevices.getUserMedia(t);return this.setAudioTrack(s.getAudioTracks()[0]),s.getAudioTracks()[0]}async useDeviceVideo(e){let t=e===void 0?{audio:!1,video:{...this.videoConstrains}}:{audio:!1,video:{deviceId:e,...this.videoConstrains}},s=await navigator.mediaDevices.getUserMedia(t);return this.setVideoTrack(s.getVideoTracks()[0]),s.getVideoTracks()[0]}async useDeskTopVideo(){let e=await navigator.mediaDevices.getDisplayMedia({video:{...this.videoConstrains},audio:!1});return this.setVideoTrack(e.getVideoTracks()[0]),e.getVideoTracks()[0]}disableAudio(){this.audioTrack!==void 0&&this.audioTrack.enabled&&(p("local audio status change",this.audioTrack),this.audioTrack.enabled=!1,this.setAudioTrack(this.audioTrack))}enableAudio(){this.audioTrack!==void 0&&!this.audioTrack.enabled&&(p("local audio status change",this.audioTrack),this.audioTrack.enabled=!0,this.setAudioTrack(this.audioTrack))}disableVideo(){this.videoTrack!==void 0&&this.videoTrack.enabled&&(p("local video status change",this.videoTrack),this.videoTrack.enabled=!1,this.setVideoTrack(this.videoTrack))}enableVideo(){this.videoTrack!==void 0&&!this.videoTrack.enabled&&(p("local video status change",this.videoTrack),this.videoTrack.enabled=!0,this.setVideoTrack(this.videoTrack))}close(){this.releaseTrack(this.audioTrack),this.releaseTrack(this.videoTrack),this.audioTrack=void 0,this.videoTrack=void 0,this.localMediaStream=void 0}}class ke extends ge{constructor(){super(),this.videoCodecs=[],this.audioCodecs=[],this.audioReciveCodecs=[],this.preferCodec(),this.peerConnection=this.buildConnection()}buildConnection(){let e=new RTCPeerConnection;return e.addEventListener("connectionstatechange",t=>p("connectionstatechange",t)),e.addEventListener("icecandidate",t=>{p("icecandidate",t),this.onIceCandidate(t)}),e.addEventListener("datachannel",t=>p("datachannel",t)),e.addEventListener("icecandidateerror",t=>p("icecandidateerror",t)),e.addEventListener("iceconnectionstatechange",t=>p("iceconnectionstatechange",t)),e.addEventListener("icegatheringstatechange",t=>p("icegatheringstatechange",t)),e.addEventListener("negotiationneeded",t=>p("negotiationneeded",t)),e.addEventListener("signalingstatechange",t=>p("signalingstatechange",t)),e.addEventListener("track",t=>this.reciveTrack(t)),e}async localTractChange(e,t){if(this.remoteStream!==void 0&&this.peerConnection!==void 0)if(t!==void 0){let s=this.peerConnection.getSenders().find(n=>n.track?.kind===t.kind);s!==void 0&&s.replaceTrack(t)}else{let s=this.peerConnection.getSenders().find(n=>n.track?.kind===e?.kind);s!==void 0&&this.peerConnection.removeTrack(s)}t!==void 0&&(t.onended=s=>p("local track end",s),t.onmute=s=>{p("local mute",s),this.emitLocalStreamChange()},t.onunmute=s=>{p("local unmute",s),this.emitLocalStreamChange()}),this.releaseTrack(e),this.emitLocalStreamChange()}isInMeeting(){return this.remoteStream!==void 0}hasRemoteVideo(e){return e?.getVideoTracks().some(t=>t.muted===!1&&t.readyState==="live")??!1}emitLocalStreamChange(){this.emit(C.localStreamChange,{audioOnly:!this.hasRemoteVideo(this.localMediaStream),stream:this.localMediaStream})}emitRemoteStreamChange(){this.emit(C.stream,{audioOnly:!this.hasRemoteVideo(this.remoteStream),stream:this.remoteStream})}trigerStreamChange(e=100){this.emitStreamTimeout!==void 0&&clearTimeout(this.emitStreamTimeout),this.emitStreamTimeout=setTimeout(()=>{this.emitRemoteStreamChange(),this.emitStreamTimeout=void 0},e)}reciveTrack(e){p("recive track",e),this.remoteStream===void 0&&(this.remoteStream=new MediaStream),e.track.addEventListener("ended",()=>this.trigerStreamChange()),e.track.addEventListener("mute",()=>this.trigerStreamChange(3e3)),e.track.addEventListener("unmute",()=>this.trigerStreamChange(10)),this.remoteStream.addTrack(e.track),this.trigerStreamChange()}preferCodec(e="H264",t="PCMA"){this.videoCodecs=[];let s=RTCRtpSender.getCapabilities("video");s!==null&&this.videoCodecs.push(...s.codecs.filter(l=>l.mimeType===`video/${e}`));let n=RTCRtpReceiver.getCapabilities("video");n!==null&&this.videoCodecs.push(...n.codecs.filter(l=>l.mimeType===`video/${e}`)),this.audioCodecs=[];let r=RTCRtpSender.getCapabilities("audio");r!==null&&this.audioCodecs.push(...r.codecs.filter(l=>l.mimeType===`audio/${t}`));let c=RTCRtpReceiver.getCapabilities("audio");c!==null&&this.audioCodecs.push(...c.codecs.filter(l=>l.mimeType===`audio/${t}`))}trackIsInPeerConnection(e){return this.peerConnection?.getSenders().some(t=>t.track?.id===e.id)??!1}updateTracks(){if(this.peerConnection===void 0||this.peerConnection.signalingState==="closed")throw new Error("session is closed !");if(this.audioTrack===void 0&&this.videoTrack===void 0){this.peerConnection.addTransceiver("audio",{direction:"recvonly"}),this.peerConnection.addTransceiver("video",{direction:"recvonly"});return}if(this.audioTrack!==void 0&&!this.trackIsInPeerConnection(this.audioTrack))try{this.peerConnection.addTrack(this.audioTrack)}catch{}if(this.videoTrack!==void 0&&!this.trackIsInPeerConnection(this.videoTrack))try{this.peerConnection.addTrack(this.videoTrack)}catch{}try{this.peerConnection.getTransceivers().forEach(e=>{e.sender.track!==null&&(e.sender.track.kind==="video"?e.setCodecPreferences([...this.videoCodecs]):e.sender.track.kind==="audio"&&e.setCodecPreferences([...this.audioCodecs]))})}catch(e){he("preferCodec error",e,this.audioCodecs,this.videoCodecs)}}async createOffer(){if(this.peerConnection===void 0)throw new Error("session is closed !");this.updateTracks();let e=await this.peerConnection.createOffer();return e=ve.formatOffer(e),await this.peerConnection.setLocalDescription(e),e}async setOffer(e){if(this.peerConnection===void 0)throw new Error("session is closed !");this.updateTracks(),await this.peerConnection.setRemoteDescription({type:"offer",sdp:e})}async createAnswer(){if(this.peerConnection===void 0)throw new Error("session is closed !");this.updateTracks();let e=await this.peerConnection.createAnswer();return this.peerConnection.setLocalDescription(e),e}async setAnswer(e){if(this.peerConnection===void 0)throw new Error("session is closed !");await this.peerConnection.setRemoteDescription({type:"answer",sdp:e})}setRemoteIce(e){if(this.peerConnection===void 0)throw new Error("session is closed !");let t=new RTCIceCandidate(e);this.peerConnection.addIceCandidate(t)}closeConnection(e){e.close(),e.ontrack=null,e.onicecandidate=null,e.oniceconnectionstatechange=null,e.onsignalingstatechange=null,e.onicegatheringstatechange=null,e.onnegotiationneeded=null,e.onicecandidateerror=null,e.ondatachannel=null,e.onconnectionstatechange=null}close(){super.close(),this.peerConnection!==void 0&&(this.closeConnection(this.peerConnection),this.peerConnection=void 0),this.remoteStream!==void 0&&F(this.remoteStream)}}var I=(i=>(i[i.timeout=408]="timeout",i[i.reject=488]="reject",i[i.busy=486]="busy",i[i.notfound=404]="notfound",i[i.notAllowedMedia=415]="notAllowedMedia",i[i.ok=200]="ok",i))(I||{});class Q extends ke{constructor(e,t,s){super(),this.sessionId=t,this.rtcClient=e,this.remoteNumber=s}reciveIceRequest({ice:e}){this.setRemoteIce(JSON.parse(e))}getRemoteNumber(){return this.remoteNumber}onIceCandidate(e){}destroy(e=!0){this.removeAllListeners(),this.rtcClient!==void 0&&(this.remoteNumber!==void 0&&(e&&this.rtcClient.sendBye(this.remoteNumber,this.sessionId),this.remoteNumber=void 0),this.rtcClient.removeSession(this)),this.rtcClient=void 0,super.close()}rejectCall(){let[e,t,s]=this.checkIsNotUndefined(this.rtcClient,this.remoteNumber,this.inviteSeq);e.answer(I.reject,s,t,this.sessionId),this.destroy()}async acceptCall(){if(this.inviteOffer!==void 0){await this.setOffer(this.inviteOffer);let[e,t,s]=this.checkIsNotUndefined(this.rtcClient,this.remoteNumber,this.inviteSeq),{sdp:n}=await this.createAnswer();e.answer(I.ok,s,t,this.sessionId,n)}}async pickNewConnection(){this.peerConnection!==void 0&&this.closeConnection(this.peerConnection),this.peerConnection=this.buildConnection(),this.remoteStream!==void 0&&(F(this.remoteStream),this.remoteStream=void 0,this.acceptCall())}checkIsNotUndefined(...e){for(const t of e)if(t===void 0)throw new Error("someone is undefined");return e}async sendDtmf(e){this.rtcClient?.sendDtmf(this.remoteNumber,this.sessionId,e)}playRemoteStream(e,t){const{audioOnly:s=!1,muted:n=!1}=t||{};n&&(e.muted=!0),this.on(C.stream,r=>{if(console.log("远程流",r),r.stream){const c=s?new MediaStream(r.stream.getAudioTracks()):r.stream;q(c,e)}}),this.on(C.bye,()=>{e&&(e.pause(),e.srcObject=null)})}}var b=(i=>(i.audio="audio",i.video="video",i.audioVideo="audioVideo",i.unknown="unknown",i))(b||{});class $ extends Q{constructor(){super(...arguments),this.responseCallType=b.unknown}async start(){let[e,t]=this.checkIsNotUndefined(this.rtcClient,this.remoteNumber),s=await this.createOffer(),{status:n,sdp:r}=await e.invite(t,this.sessionId,s.sdp);if(n===I.ok){await this.setAnswer(r);const c=r.split(`\r
|
|
4
|
-
`),
|
|
5
|
-
`,X=typeof self<"u"&&self.Blob&&new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",z],{type:"text/javascript;charset=utf-8"});function we(i){let e;try{if(e=X&&(self.URL||self.webkitURL).createObjectURL(X),!e)throw"";const t=new Worker(e,{name:i?.name});return t.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(e)}),t}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(z),{name:i?.name})}}class Ce extends Y.EventEmitter{constructor(e,t,s){super(),this.server=e,this.ws=new we,this.configHeartBeat(t,s)}connect(){this.initWebsocket(),this.ws.onmessage=e=>{const{type:t,data:s}=e.data;switch(t){case"webSocket":p("websocket recive message ",s),this.emit(N.message,s);return;case"open":p("websocket connected ",this.server),this.emit(N.connected);return}}}configHeartBeat(e,t){p("websocket heartBeat",e),p("websocket heartTime",t),this.ws.postMessage({cmd:"config",heartBeat:e,heartTime:t})}initWebsocket(){this.ws.postMessage({cmd:"start",url:this.server})}send(e){this.ws.postMessage({cmd:"msg",data:e})}close(){this.ws.postMessage({cmd:"close"})}sendMessage(e){p("websocket send message ",e),e!==void 0&&this.ws!==void 0&&this.ws.postMessage({cmd:"msg",data:e})}}class Ee extends Y.EventEmitter{constructor(e,t,s,n){super(),this.activeServer="",this.server=e,this.localNumber=t,this.expireTime=s,this.heartTime=n,super.setMaxListeners(0)}async testWs(e){return e.reduce((t,s)=>t.then(n=>Promise.resolve(n),n=>new Promise((r,c)=>{const l=new WebSocket(s);l.onopen=()=>{n.push(s),l.close(),r(n)},l.onclose=()=>{c(n)}})),Promise.reject([])).then(t=>Promise.resolve(t),t=>Promise.resolve(t))}async reConnect(){this.destroy();let e=[];this.server!==void 0&&(typeof this.server=="string"?e=[this.server]:e=this.server);const t=await this.testWs(e);return new Promise((s,n)=>{if(t.length>0){this.activeServer=t[0];let r=new Ce(this.activeServer,new L(y.MESSAGE_TYPE_REGISTER,this.localNumber,this.localNumber,{expire:this.expireTime}),this.heartTime);r.on(N.connected,()=>{this.socketWorker=r,this.onConnected(),s()}),r.on(N.disconnected,c=>{this.socketWorker=void 0,this.onDisConnected(c),n("socketWorker connecion failed")}),r.on(N.message,c=>this.onReviceMessage(c)),r.connect()}else n("server is empty")})}sendMessage(e){if(this.socketWorker!==void 0)this.socketWorker.sendMessage(e);else throw new Error("socketWorker is closed")}destroy(){this.socketWorker!==void 0&&(this.unRegister(),this.socketWorker.close(),this.socketWorker=void 0)}}class be extends Ee{constructor(){super(...arguments),this.asyncProducer=new Map}async sendRespondableMessage(e){return this.sendMessage(e),new Promise(t=>this.asyncProducer.set(e.seq,t))}getAsyncResolve(e){let t=this.asyncProducer.get(e);return t!==void 0&&this.asyncProducer.delete(e),t}onDisConnected(e){this.asyncProducer.clear(),this.emit(P.disconnected,e)}onReviceMessage(e){let{status:t,seq:s}=e;t!==void 0?this.getAsyncResolve(s)?.call(void 0,e):this.processMessage(e)}}class ye extends be{async register(){let e=new L(y.MESSAGE_TYPE_REGISTER,this.localNumber,this.localNumber,{expire:this.expireTime});return this.sendRespondableMessage(e)}unRegister(){let e=new L(y.MESSAGE_TYPE_REGISTER,this.localNumber,this.localNumber,{expire:0});this.sendMessage(e)}async invite(e,t,s){return this.sendRespondableMessage(new L(y.MESSAGE_TYPE_INVITE,this.localNumber,e,{cid:t,sdp:s}))}sendIce(e,t,s){}sendBye(e,t){return this.sendMessage(new L(y.MESSAGE_TYPE_BYE,this.localNumber,e,{cid:t}))}answer(e,t,s,n,r){this.sendMessage({status:e,seq:t,from:s,to:this.localNumber,cid:n,sdp:r})}sendPttMessage(e){this.sendMessage(e)}async sendDtmf(e,t,s){return this.sendMessage(new L(y.MESSAGE_TYPE_INFO,this.localNumber,e,{cid:t,info:{msg:"dtmf",dtmf:s}}))}}var Te;function _(){}_.prototype=Object.create(null);function m(){m.init.call(this)}m.EventEmitter=m,m.usingDomains=!1,m.prototype.domain=void 0,m.prototype._events=void 0,m.prototype._maxListeners=void 0,m.defaultMaxListeners=10,m.init=function(){this.domain=null,m.usingDomains&&Te.active,(!this._events||this._events===Object.getPrototypeOf(this)._events)&&(this._events=new _,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},m.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||isNaN(e))throw new TypeError('"n" argument must be a positive number');return this._maxListeners=e,this};function Z(i){return i._maxListeners===void 0?m.defaultMaxListeners:i._maxListeners}m.prototype.getMaxListeners=function(){return Z(this)};function Se(i,e,t){if(e)i.call(t);else for(var s=i.length,n=M(i,s),r=0;r<s;++r)n[r].call(t)}function Le(i,e,t,s){if(e)i.call(t,s);else for(var n=i.length,r=M(i,n),c=0;c<n;++c)r[c].call(t,s)}function _e(i,e,t,s,n){if(e)i.call(t,s,n);else for(var r=i.length,c=M(i,r),l=0;l<r;++l)c[l].call(t,s,n)}function Re(i,e,t,s,n,r){if(e)i.call(t,s,n,r);else for(var c=i.length,l=M(i,c),w=0;w<c;++w)l[w].call(t,s,n,r)}function Ie(i,e,t,s){if(e)i.apply(t,s);else for(var n=i.length,r=M(i,n),c=0;c<n;++c)r[c].apply(t,s)}m.prototype.emit=function(e){var t,s,n,r,c,l,w,E=e==="error";if(l=this._events,l)E=E&&l.error==null;else if(!E)return!1;if(w=this.domain,E){if(t=arguments[1],w)t||(t=new Error('Uncaught, unspecified "error" event')),t.domainEmitter=this,t.domain=w,t.domainThrown=!1,w.emit("error",t);else{if(t instanceof Error)throw t;var U=new Error('Uncaught, unspecified "error" event. ('+t+")");throw U.context=t,U}return!1}if(s=l[e],!s)return!1;var R=typeof s=="function";switch(n=arguments.length,n){case 1:Se(s,R,this);break;case 2:Le(s,R,this,arguments[1]);break;case 3:_e(s,R,this,arguments[1],arguments[2]);break;case 4:Re(s,R,this,arguments[1],arguments[2],arguments[3]);break;default:for(r=new Array(n-1),c=1;c<n;c++)r[c-1]=arguments[c];Ie(s,R,this,r)}return!0};function ee(i,e,t,s){var n,r,c;if(typeof t!="function")throw new TypeError('"listener" argument must be a function');if(r=i._events,r?(r.newListener&&(i.emit("newListener",e,t.listener?t.listener:t),r=i._events),c=r[e]):(r=i._events=new _,i._eventsCount=0),!c)c=r[e]=t,++i._eventsCount;else if(typeof c=="function"?c=r[e]=s?[t,c]:[c,t]:s?c.unshift(t):c.push(t),!c.warned&&(n=Z(i),n&&n>0&&c.length>n)){c.warned=!0;var l=new Error("Possible EventEmitter memory leak detected. "+c.length+" "+e+" listeners added. Use emitter.setMaxListeners() to increase limit");l.name="MaxListenersExceededWarning",l.emitter=i,l.type=e,l.count=c.length,Ne(l)}return i}function Ne(i){typeof console.warn=="function"?console.warn(i):console.log(i)}m.prototype.addListener=function(e,t){return ee(this,e,t,!1)},m.prototype.on=m.prototype.addListener,m.prototype.prependListener=function(e,t){return ee(this,e,t,!0)};function te(i,e,t){var s=!1;function n(){i.removeListener(e,n),s||(s=!0,t.apply(i,arguments))}return n.listener=t,n}m.prototype.once=function(e,t){if(typeof t!="function")throw new TypeError('"listener" argument must be a function');return this.on(e,te(this,e,t)),this},m.prototype.prependOnceListener=function(e,t){if(typeof t!="function")throw new TypeError('"listener" argument must be a function');return this.prependListener(e,te(this,e,t)),this},m.prototype.removeListener=function(e,t){var s,n,r,c,l;if(typeof t!="function")throw new TypeError('"listener" argument must be a function');if(n=this._events,!n)return this;if(s=n[e],!s)return this;if(s===t||s.listener&&s.listener===t)--this._eventsCount===0?this._events=new _:(delete n[e],n.removeListener&&this.emit("removeListener",e,s.listener||t));else if(typeof s!="function"){for(r=-1,c=s.length;c-- >0;)if(s[c]===t||s[c].listener&&s[c].listener===t){l=s[c].listener,r=c;break}if(r<0)return this;if(s.length===1){if(s[0]=void 0,--this._eventsCount===0)return this._events=new _,this;delete n[e]}else Oe(s,r);n.removeListener&&this.emit("removeListener",e,l||t)}return this},m.prototype.off=function(i,e){return this.removeListener(i,e)},m.prototype.removeAllListeners=function(e){var t,s;if(s=this._events,!s)return this;if(!s.removeListener)return arguments.length===0?(this._events=new _,this._eventsCount=0):s[e]&&(--this._eventsCount===0?this._events=new _:delete s[e]),this;if(arguments.length===0){for(var n=Object.keys(s),r=0,c;r<n.length;++r)c=n[r],c!=="removeListener"&&this.removeAllListeners(c);return this.removeAllListeners("removeListener"),this._events=new _,this._eventsCount=0,this}if(t=s[e],typeof t=="function")this.removeListener(e,t);else if(t)do this.removeListener(e,t[t.length-1]);while(t[0]);return this},m.prototype.listeners=function(e){var t,s,n=this._events;return n?(t=n[e],t?typeof t=="function"?s=[t.listener||t]:s=Me(t):s=[]):s=[],s},m.listenerCount=function(i,e){return typeof i.listenerCount=="function"?i.listenerCount(e):ie.call(i,e)},m.prototype.listenerCount=ie;function ie(i){var e=this._events;if(e){var t=e[i];if(typeof t=="function")return 1;if(t)return t.length}return 0}m.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};function Oe(i,e){for(var t=e,s=t+1,n=i.length;s<n;t+=1,s+=1)i[t]=i[s];i.pop()}function M(i,e){for(var t=new Array(e);e--;)t[e]=i[e];return t}function Me(i){for(var e=new Array(i.length),t=0;t<e.length;++t)e[t]=i[t].listener||i[t];return e}const k={ERROR:"error",SPEAKER:"speaker",TALKING:"talking",ACTIVE_GROUP:"activeGroup",JOIN_INFO:"joinInfo",DISCONNECTED:"disConnected"},se={400:"消息不符规范",401:"验证不通过",403:"无权利操作",404:"不存在该用户",415:"错误参数",405:"无法操作",424:"不存在XD群",425:"管理员没有",426:"已存在管理员",427:"以前被拒绝过,或者删除过",428:"超出所配置的下属管理员的数量",429:"群内无用户",430:"管理员的索引号冲突",431:"还有子管理员存在"},O={connected:"connected",disconnected:"disconnected",message:"message"},T=(i,...e)=>{console.log(`%c usc-ptt-devtools %c ${i} %c `,"background:#16aae0 ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff","background:#14e04e ; padding: 1px; border-radius: 0 3px 3px 0; color: #fff","background:transparent",...e)},ne=(i,...e)=>{console.log(`%c usc-ptt-devtools %c ${i} %c `,"background:#16aae0 ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff","background:#e02514 ; padding: 1px; border-radius: 0 3px 3px 0; color: #fff","background:transparent",...e)};class Ae extends m{server="";ws=null;constructor(e){super(),this.server=e}connect(){this.ws=new WebSocket(this.server),this.ws.onopen=()=>{T("websocket connected ",this.server),this.emit(O.connected)},this.ws.onclose=()=>{T("websocket disconnected ",this.server),this.ws=void 0,this.emit(O.disconnected)},this.ws.onmessage=({data:e})=>{let t=JSON.parse(e);T("websocket recive message ",t),this.emit(O.message,t)}}close(){this.ws!==void 0&&(this.ws.close(),this.ws=void 0)}sendMessage(e){T("websocket send message ",e),e!==void 0&&this.ws!==void 0&&this.ws.readyState===1&&this.ws.send(JSON.stringify(e))}}class Pe extends m{socket=void 0;timer=void 0;waitinggroup=void 0;speaker="";activeGroup="";talking=!1;constructor(e,t=20,s=!0){if(super(),!e)return ne("服务器地址为空!");this.server=e,this.heartTime=t,this.autoReconnect=s}async initClient(){return this.destorySocket(),new Promise((e,t)=>{if(this.server!==void 0){let s=new Ae(this.server);s.on(O.connected,()=>{this.socket=s,this.timer=setInterval(()=>{this.sendMessage({req:0})},this.heartTime*1e3),e()}),s.on(O.disconnected,()=>{this.socket=void 0,this.autoReconnect?setTimeout(()=>{this.initClient()},3e3):this.emit(k.DISCONNECTED),t("socket connecion failed")}),s.on(O.message,n=>this.onReviceMessage(n)),s.connect()}else t("server is empty")})}onReviceMessage(e){T(e);const{info:t,msg:s,res:n}=e;if(t===10&&(this.speaker=`${s.speaker}`,T(`${this.speaker}正在说话`),this.emit(k.SPEAKER,this.speaker)),t===11&&(n.code===200?(this.activeGroup=this.waitinggroup,T(`加入组${this.activeGroup}`)):(this.activeGroup="",ne(se[n.code]),this.emit(k.ERROR,se[n.code])),this.emit(k.ACTIVE_GROUP,this.activeGroup)),t===13&&(n.code===200?this.talking=!0:this.talking=!1,T(`talking:${this.talking}`),this.emit(k.TALKING,this.talking)),t===14&&(this.speaker="",T(`${this.speaker}停止说话`),this.emit(k.SPEAKER,this.speaker)),t===15){const r={user:s.number,group:s.g_num,code:s.status};T(`${r}进入组`),this.emit(k.JOIN_INFO,r)}}joinGroup(e,t,s,n){this.socket&&(this.waitinggroup=e,this.sendMessage({req:1,group:e,user:t,ptts:s,port:n}))}quitGroup(){this.socket&&(this.activeGroup="",this.emit(k.ACTIVE_GROUP,this.activeGroup),this.sendMessage({req:2}))}talk(){this.socket&&this.sendMessage({req:3})}stop(){this.talking=!1,T(`talking:${this.talking}`),this.emit(k.TALKING,this.talking),this.socket&&this.sendMessage({req:4})}sendMessage(e){if(this.socket!==void 0)this.socket.sendMessage(e);else throw new Error("socket is closed")}destorySocket(){this.socket!==void 0&&(this.socket.close(),this.socket=void 0)}destory(){this.destorySocket()}}const xe=async(i,e=20,t=!0)=>{let s=new Pe(i,e,t);return await s.initClient(),s},V=class V extends ye{constructor(e){let t=e.expireTime||V.defaultExpireTime;super(e.server,e.localNumber,t,e.heartTime||(e.localNumber?5:0)),this.enablePtt=e.enablePtt,this.pttServer=e.pttServer}async initPttClient(){if(this.enablePtt)if(this.pttServer){const e=await xe(this.pttServer);if(!e)return Promise.reject("ptt客户端初始化失败!");e.on(k.ACTIVE_GROUP,t=>{this.emit(k.ACTIVE_GROUP,t)}),e.on(k.SPEAKER,t=>{this.emit(k.SPEAKER,t)}),e.on(k.TALKING,t=>{this.emit(k.TALKING,t)}),e.on(k.JOIN_INFO,t=>{this.emit(k.JOIN_INFO,t)}),e.on(k.DISCONNECTED,t=>{this.emit(k.DISCONNECTED,t)}),this.pttClient=e}else return Promise.reject("pttServer不存在")}joinGroup(e,t,s,n){this.pttClient?.joinGroup(e,t,s,n)}quitGroup(){this.pttClient?.quitGroup()}talk(){this.pttClient?.talk()}stop(){this.pttClient?.stop()}onConnected(){}onDisConnected(){super.onDisConnected()}};V.defaultExpireTime=60;let K=V;class re extends Q{constructor(e,t,s,n,r){super(e,t,s),this.callType=b.unknown,this.inviteSeq=r,this.inviteOffer=n;const c=n.split(`\r
|
|
6
|
-
`),
|
|
3
|
+
`),e.sdp=t,e}}var D={exports:{}},H;function pe(){if(H)return D.exports;H=1;var i=typeof Reflect=="object"?Reflect:null,e=i&&typeof i.apply=="function"?i.apply:function(o,d,l){return Function.prototype.apply.call(o,d,l)},t;i&&typeof i.ownKeys=="function"?t=i.ownKeys:Object.getOwnPropertySymbols?t=function(o){return Object.getOwnPropertyNames(o).concat(Object.getOwnPropertySymbols(o))}:t=function(o){return Object.getOwnPropertyNames(o)};function s(c){console&&console.warn&&console.warn(c)}var n=Number.isNaN||function(o){return o!==o};function r(){r.init.call(this)}D.exports=r,D.exports.once=We,r.EventEmitter=r,r.prototype._events=void 0,r.prototype._eventsCount=0,r.prototype._maxListeners=void 0;var a=10;function u(c){if(typeof c!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof c)}Object.defineProperty(r,"defaultMaxListeners",{enumerable:!0,get:function(){return a},set:function(c){if(typeof c!="number"||c<0||n(c))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+c+".");a=c}}),r.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},r.prototype.setMaxListeners=function(o){if(typeof o!="number"||o<0||n(o))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+o+".");return this._maxListeners=o,this};function w(c){return c._maxListeners===void 0?r.defaultMaxListeners:c._maxListeners}r.prototype.getMaxListeners=function(){return w(this)},r.prototype.emit=function(o){for(var d=[],l=1;l<arguments.length;l++)d.push(arguments[l]);var h=o==="error",v=this._events;if(v!==void 0)h=h&&v.error===void 0;else if(!h)return!1;if(h){var f;if(d.length>0&&(f=d[0]),f instanceof Error)throw f;var S=new Error("Unhandled error."+(f?" ("+f.message+")":""));throw S.context=f,S}var A=v[o];if(A===void 0)return!1;if(typeof A=="function")e(A,this,d);else for(var ue=A.length,Fe=ce(A,ue),l=0;l<ue;++l)e(Fe[l],this,d);return!0};function E(c,o,d,l){var h,v,f;if(u(d),v=c._events,v===void 0?(v=c._events=Object.create(null),c._eventsCount=0):(v.newListener!==void 0&&(c.emit("newListener",o,d.listener?d.listener:d),v=c._events),f=v[o]),f===void 0)f=v[o]=d,++c._eventsCount;else if(typeof f=="function"?f=v[o]=l?[d,f]:[f,d]:l?f.unshift(d):f.push(d),h=w(c),h>0&&f.length>h&&!f.warned){f.warned=!0;var S=new Error("Possible EventEmitter memory leak detected. "+f.length+" "+String(o)+" listeners added. Use emitter.setMaxListeners() to increase limit");S.name="MaxListenersExceededWarning",S.emitter=c,S.type=o,S.count=f.length,s(S)}return c}r.prototype.addListener=function(o,d){return E(this,o,d,!1)},r.prototype.on=r.prototype.addListener,r.prototype.prependListener=function(o,d){return E(this,o,d,!0)};function U(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function R(c,o,d){var l={fired:!1,wrapFn:void 0,target:c,type:o,listener:d},h=U.bind(l);return h.listener=d,l.wrapFn=h,h}r.prototype.once=function(o,d){return u(d),this.on(o,R(this,o,d)),this},r.prototype.prependOnceListener=function(o,d){return u(d),this.prependListener(o,R(this,o,d)),this},r.prototype.removeListener=function(o,d){var l,h,v,f,S;if(u(d),h=this._events,h===void 0)return this;if(l=h[o],l===void 0)return this;if(l===d||l.listener===d)--this._eventsCount===0?this._events=Object.create(null):(delete h[o],h.removeListener&&this.emit("removeListener",o,l.listener||d));else if(typeof l!="function"){for(v=-1,f=l.length-1;f>=0;f--)if(l[f]===d||l[f].listener===d){S=l[f].listener,v=f;break}if(v<0)return this;v===0?l.shift():Ve(l,v),l.length===1&&(h[o]=l[0]),h.removeListener!==void 0&&this.emit("removeListener",o,S||d)}return this},r.prototype.off=r.prototype.removeListener,r.prototype.removeAllListeners=function(o){var d,l,h;if(l=this._events,l===void 0)return this;if(l.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):l[o]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete l[o]),this;if(arguments.length===0){var v=Object.keys(l),f;for(h=0;h<v.length;++h)f=v[h],f!=="removeListener"&&this.removeAllListeners(f);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(d=l[o],typeof d=="function")this.removeListener(o,d);else if(d!==void 0)for(h=d.length-1;h>=0;h--)this.removeListener(o,d[h]);return this};function oe(c,o,d){var l=c._events;if(l===void 0)return[];var h=l[o];return h===void 0?[]:typeof h=="function"?d?[h.listener||h]:[h]:d?Ue(h):ce(h,h.length)}r.prototype.listeners=function(o){return oe(this,o,!0)},r.prototype.rawListeners=function(o){return oe(this,o,!1)},r.listenerCount=function(c,o){return typeof c.listenerCount=="function"?c.listenerCount(o):ae.call(c,o)},r.prototype.listenerCount=ae;function ae(c){var o=this._events;if(o!==void 0){var d=o[c];if(typeof d=="function")return 1;if(d!==void 0)return d.length}return 0}r.prototype.eventNames=function(){return this._eventsCount>0?t(this._events):[]};function ce(c,o){for(var d=new Array(o),l=0;l<o;++l)d[l]=c[l];return d}function Ve(c,o){for(;o+1<c.length;o++)c[o]=c[o+1];c.pop()}function Ue(c){for(var o=new Array(c.length),d=0;d<o.length;++d)o[d]=c[d].listener||c[d];return o}function We(c,o){return new Promise(function(d,l){function h(f){c.removeListener(o,v),l(f)}function v(){typeof c.removeListener=="function"&&c.removeListener("error",h),d([].slice.call(arguments))}de(c,o,v,{once:!0}),o!=="error"&&qe(c,h,{once:!0})})}function qe(c,o,d){typeof c.on=="function"&&de(c,"error",o,d)}function de(c,o,d,l){if(typeof c.on=="function")l.once?c.once(o,d):c.on(o,d);else if(typeof c.addEventListener=="function")c.addEventListener(o,function h(v){l.once&&c.removeEventListener(o,h),d(v)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof c)}return D.exports}var Y=pe();class ge extends Y.EventEmitter{constructor(){super(),this.localMediaStream=new MediaStream,this.videoConstrains={width:{ideal:1920},height:{ideal:1080},frameRate:{ideal:20,max:30},aspectRatio:{ideal:16/9}},this.audioConstrants={noiseSuppression:!0,echoCancellation:!0,autoGainControl:!0},super.setMaxListeners(0)}releaseTrack(e){e!==void 0&&(this.localMediaStream?.removeTrack(e),e.stop())}addDeviceChangeListener(e){navigator.mediaDevices.addEventListener("devicechange",e)}removeDeviceChangeListener(e){navigator.mediaDevices.removeEventListener("devicechange",e)}setVideoTrack(e){this.emit(C.localVideoChange,{from:this.videoTrack,to:e}),this.videoTrack!==e&&(this.localMediaStream?.addTrack(e),this.localTractChange(this.videoTrack,e)),this.videoTrack=e}setAudioTrack(e){this.emit(C.localAudioChange,{from:this.audioTrack,to:e}),this.audioTrack!==e&&(this.localMediaStream?.addTrack(e),this.localTractChange(this.audioTrack,e)),this.audioTrack=e}renderLocalStreamToContainer(e){q(this.localMediaStream,e)}async getAllInputResource(){let e=await navigator.mediaDevices.enumerateDevices();return{audio:e.filter(t=>t.kind==="audioinput"),video:e.filter(t=>t.kind==="videoinput")}}async useDefaultDevice(e){let t={audio:!0,video:!0},s=await navigator.mediaDevices.getUserMedia(t);this.setAudioTrack(s.getAudioTracks()[0]),this.setVideoTrack(s.getVideoTracks()[0]),this.renderLocalStreamToContainer(e)}async useAudio(e){let t=e===void 0?{audio:{...this.audioConstrants},video:!1}:{video:!1,audio:{deviceId:e,...this.audioConstrants}},s=await navigator.mediaDevices.getUserMedia(t);return this.setAudioTrack(s.getAudioTracks()[0]),s.getAudioTracks()[0]}async useDeviceVideo(e){let t=e===void 0?{audio:!1,video:{...this.videoConstrains}}:{audio:!1,video:{deviceId:e,...this.videoConstrains}},s=await navigator.mediaDevices.getUserMedia(t);return this.setVideoTrack(s.getVideoTracks()[0]),s.getVideoTracks()[0]}async useDeskTopVideo(){let e=await navigator.mediaDevices.getDisplayMedia({video:{...this.videoConstrains},audio:!1});return this.setVideoTrack(e.getVideoTracks()[0]),e.getVideoTracks()[0]}disableAudio(){this.audioTrack!==void 0&&this.audioTrack.enabled&&(p("local audio status change",this.audioTrack),this.audioTrack.enabled=!1,this.setAudioTrack(this.audioTrack))}enableAudio(){this.audioTrack!==void 0&&!this.audioTrack.enabled&&(p("local audio status change",this.audioTrack),this.audioTrack.enabled=!0,this.setAudioTrack(this.audioTrack))}disableVideo(){this.videoTrack!==void 0&&this.videoTrack.enabled&&(p("local video status change",this.videoTrack),this.videoTrack.enabled=!1,this.setVideoTrack(this.videoTrack))}enableVideo(){this.videoTrack!==void 0&&!this.videoTrack.enabled&&(p("local video status change",this.videoTrack),this.videoTrack.enabled=!0,this.setVideoTrack(this.videoTrack))}close(){this.releaseTrack(this.audioTrack),this.releaseTrack(this.videoTrack),this.audioTrack=void 0,this.videoTrack=void 0,this.localMediaStream=void 0}}class ke extends ge{constructor(){super(),this.videoCodecs=[],this.audioCodecs=[],this.audioReciveCodecs=[],this.preferCodec(),this.peerConnection=this.buildConnection()}buildConnection(){let e=new RTCPeerConnection;return e.addEventListener("connectionstatechange",t=>p("connectionstatechange",t)),e.addEventListener("icecandidate",t=>{p("icecandidate",t),this.onIceCandidate(t)}),e.addEventListener("datachannel",t=>p("datachannel",t)),e.addEventListener("icecandidateerror",t=>p("icecandidateerror",t)),e.addEventListener("iceconnectionstatechange",t=>p("iceconnectionstatechange",t)),e.addEventListener("icegatheringstatechange",t=>p("icegatheringstatechange",t)),e.addEventListener("negotiationneeded",t=>p("negotiationneeded",t)),e.addEventListener("signalingstatechange",t=>p("signalingstatechange",t)),e.addEventListener("track",t=>this.reciveTrack(t)),e}async localTractChange(e,t){if(this.remoteStream!==void 0&&this.peerConnection!==void 0)if(t!==void 0){let s=this.peerConnection.getSenders().find(n=>n.track?.kind===t.kind);s!==void 0&&s.replaceTrack(t)}else{let s=this.peerConnection.getSenders().find(n=>n.track?.kind===e?.kind);s!==void 0&&this.peerConnection.removeTrack(s)}t!==void 0&&(t.onended=s=>p("local track end",s),t.onmute=s=>{p("local mute",s),this.emitLocalStreamChange()},t.onunmute=s=>{p("local unmute",s),this.emitLocalStreamChange()}),this.releaseTrack(e),this.emitLocalStreamChange()}isInMeeting(){return this.remoteStream!==void 0}hasRemoteVideo(e){return e?.getVideoTracks().some(t=>t.muted===!1&&t.readyState==="live")??!1}emitLocalStreamChange(){this.emit(C.localStreamChange,{audioOnly:!this.hasRemoteVideo(this.localMediaStream),stream:this.localMediaStream})}emitRemoteStreamChange(){this.emit(C.stream,{audioOnly:!this.hasRemoteVideo(this.remoteStream),stream:this.remoteStream})}trigerStreamChange(e=100){this.emitStreamTimeout!==void 0&&clearTimeout(this.emitStreamTimeout),this.emitStreamTimeout=setTimeout(()=>{this.emitRemoteStreamChange(),this.emitStreamTimeout=void 0},e)}reciveTrack(e){p("recive track",e),this.remoteStream===void 0&&(this.remoteStream=new MediaStream),e.track.addEventListener("ended",()=>this.trigerStreamChange()),e.track.addEventListener("mute",()=>this.trigerStreamChange(3e3)),e.track.addEventListener("unmute",()=>this.trigerStreamChange(10)),this.remoteStream.addTrack(e.track),this.trigerStreamChange()}preferCodec(e="H264",t="PCMA"){this.videoCodecs=[];let s=RTCRtpSender.getCapabilities("video");s!==null&&this.videoCodecs.push(...s.codecs.filter(u=>u.mimeType===`video/${e}`));let n=RTCRtpReceiver.getCapabilities("video");n!==null&&this.videoCodecs.push(...n.codecs.filter(u=>u.mimeType===`video/${e}`)),this.audioCodecs=[];let r=RTCRtpSender.getCapabilities("audio");r!==null&&this.audioCodecs.push(...r.codecs.filter(u=>u.mimeType===`audio/${t}`));let a=RTCRtpReceiver.getCapabilities("audio");a!==null&&this.audioCodecs.push(...a.codecs.filter(u=>u.mimeType===`audio/${t}`))}trackIsInPeerConnection(e){return this.peerConnection?.getSenders().some(t=>t.track?.id===e.id)??!1}updateTracks(){if(this.peerConnection===void 0||this.peerConnection.signalingState==="closed")throw new Error("session is closed !");if(this.audioTrack===void 0&&this.videoTrack===void 0){this.peerConnection.addTransceiver("audio",{direction:"recvonly"}),this.peerConnection.addTransceiver("video",{direction:"recvonly"});return}if(this.audioTrack!==void 0&&!this.trackIsInPeerConnection(this.audioTrack))try{this.peerConnection.addTrack(this.audioTrack)}catch{}if(this.videoTrack!==void 0&&!this.trackIsInPeerConnection(this.videoTrack))try{this.peerConnection.addTrack(this.videoTrack)}catch{}try{this.peerConnection.getTransceivers().forEach(e=>{e.sender.track!==null&&(e.sender.track.kind==="video"?e.setCodecPreferences([...this.videoCodecs]):e.sender.track.kind==="audio"&&e.setCodecPreferences([...this.audioCodecs]))})}catch(e){he("preferCodec error",e,this.audioCodecs,this.videoCodecs)}}async createOffer(){if(this.peerConnection===void 0)throw new Error("session is closed !");this.updateTracks();let e=await this.peerConnection.createOffer();return e=ve.formatOffer(e),await this.peerConnection.setLocalDescription(e),e}async setOffer(e){if(this.peerConnection===void 0)throw new Error("session is closed !");this.updateTracks(),await this.peerConnection.setRemoteDescription({type:"offer",sdp:e})}async createAnswer(){if(this.peerConnection===void 0)throw new Error("session is closed !");this.updateTracks();let e=await this.peerConnection.createAnswer();return this.peerConnection.setLocalDescription(e),e}async setAnswer(e){if(this.peerConnection===void 0)throw new Error("session is closed !");await this.peerConnection.setRemoteDescription({type:"answer",sdp:e})}setRemoteIce(e){if(this.peerConnection===void 0)throw new Error("session is closed !");let t=new RTCIceCandidate(e);this.peerConnection.addIceCandidate(t)}closeConnection(e){e.close(),e.ontrack=null,e.onicecandidate=null,e.oniceconnectionstatechange=null,e.onsignalingstatechange=null,e.onicegatheringstatechange=null,e.onnegotiationneeded=null,e.onicecandidateerror=null,e.ondatachannel=null,e.onconnectionstatechange=null}close(){super.close(),this.peerConnection!==void 0&&(this.closeConnection(this.peerConnection),this.peerConnection=void 0),this.remoteStream!==void 0&&F(this.remoteStream)}}var I=(i=>(i[i.timeout=408]="timeout",i[i.reject=488]="reject",i[i.busy=486]="busy",i[i.notfound=404]="notfound",i[i.notAllowedMedia=415]="notAllowedMedia",i[i.ok=200]="ok",i))(I||{});class Q extends ke{constructor(e,t,s){super(),this.sessionId=t,this.rtcClient=e,this.remoteNumber=s}reciveIceRequest({ice:e}){this.setRemoteIce(JSON.parse(e))}getRemoteNumber(){return this.remoteNumber}onIceCandidate(e){}destroy(e=!0){this.removeAllListeners(),this.rtcClient!==void 0&&(this.remoteNumber!==void 0&&(e&&this.rtcClient.sendBye(this.remoteNumber,this.sessionId),this.remoteNumber=void 0),this.rtcClient.removeSession(this)),this.rtcClient=void 0,super.close()}rejectCall(){let[e,t,s]=this.checkIsNotUndefined(this.rtcClient,this.remoteNumber,this.inviteSeq);e.answer(I.reject,s,t,this.sessionId),this.destroy()}async acceptCall(){if(this.inviteOffer!==void 0){await this.setOffer(this.inviteOffer);let[e,t,s]=this.checkIsNotUndefined(this.rtcClient,this.remoteNumber,this.inviteSeq),{sdp:n}=await this.createAnswer();e.answer(I.ok,s,t,this.sessionId,n)}}async pickNewConnection(){this.peerConnection!==void 0&&this.closeConnection(this.peerConnection),this.peerConnection=this.buildConnection(),this.remoteStream!==void 0&&(F(this.remoteStream),this.remoteStream=void 0,this.acceptCall())}checkIsNotUndefined(...e){for(const t of e)if(t===void 0)throw new Error("someone is undefined");return e}async sendDtmf(e){this.rtcClient?.sendDtmf(this.remoteNumber,this.sessionId,e)}playRemoteStream(e,t){const{audioOnly:s=!1,muted:n=!1}=t||{};n&&(e.muted=!0),this.on(C.stream,r=>{if(console.log("远程流",r),r.stream){const a=s?new MediaStream(r.stream.getAudioTracks()):r.stream;q(a,e)}}),this.on(C.bye,()=>{e&&(e.pause(),e.srcObject=null)})}}var b=(i=>(i.audio="audio",i.video="video",i.audioVideo="audioVideo",i.unknown="unknown",i))(b||{});class $ extends Q{constructor(){super(...arguments),this.responseCallType=b.unknown}async start(){let[e,t]=this.checkIsNotUndefined(this.rtcClient,this.remoteNumber),s=await this.createOffer(),{status:n,sdp:r}=await e.invite(t,this.sessionId,s.sdp);if(n===I.ok){await this.setAnswer(r);const a=r.split(`\r
|
|
4
|
+
`),u=a.find(E=>E.startsWith("m=audio")),w=a.find(E=>E.startsWith("m=video"));this.responseCallType=u&&w?b.audioVideo:u?b.audio:w?b.video:b.unknown}return n}addRemote(e){this.remoteNumber=e}}const j=class j{constructor(e,t,s,n){this.req=e,this.seq=0,this.from=t,this.to=s,this.registerid=`${j.random}@${t}`,n!==void 0&&Object.assign(this,n)}};j.random=String(Date.now());let L=j;var N=(i=>(i.connected="connected",i.disconnected="disconnected",i.message="message",i))(N||{});const z=`(function(){"use strict";let e,n=!1;const o=self,a={},r={timeout:5*1e3,timeoutObj:null,reset(){return clearInterval(this.timeoutObj),this},sendOnline(){e.readyState===1&&e.send(JSON.stringify(Object.assign(a,{seq:++a.seq})))},start(){this.timeout!==0&&(this.timeoutObj=setInterval(()=>{this.sendOnline()},this.timeout))}};self.addEventListener("message",function(s){const t=s.data;switch(t.cmd){case"config":Object.assign(a,t.heartBeat),r.timeout=t.heartTime*1e3;break;case"start":self.postMessage({type:"webWorker",data:"启动webWorker"}),i(t.url);break;case"close":n=!0,e.close(),self.postMessage({type:"webWorker",data:"停止webWorker"}),self.postMessage({type:"close",data:"close"+new Date().toTimeString()}),self.close();break;case"msg":e.readyState===1&&e.send(JSON.stringify(t.data))}},!1);const i=function(s){e||(e=new WebSocket(s),e.onerror=function(t){c(s)},e.onclose=function(t){c(s)},e.onopen=t=>{o.postMessage({type:"open",data:"start"+new Date().toTimeString()}),r.reset().start()},e.onmessage=t=>{const l=JSON.parse(t.data);o.postMessage({type:"webSocket",data:l})})};function c(s){n||(n=!0,setTimeout(function(){e=null,i(s),n=!1},2e3))}})();
|
|
5
|
+
`,X=typeof self<"u"&&self.Blob&&new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",z],{type:"text/javascript;charset=utf-8"});function we(i){let e;try{if(e=X&&(self.URL||self.webkitURL).createObjectURL(X),!e)throw"";const t=new Worker(e,{name:i?.name});return t.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(e)}),t}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(z),{name:i?.name})}}class Ce extends Y.EventEmitter{constructor(e,t,s){super(),this.server=e,this.ws=new we,this.configHeartBeat(t,s)}connect(){this.initWebsocket(),this.ws.onmessage=e=>{const{type:t,data:s}=e.data;switch(t){case"webSocket":p("websocket recive message ",s),this.emit(N.message,s);return;case"open":p("websocket connected ",this.server),this.emit(N.connected);return}}}configHeartBeat(e,t){p("websocket heartBeat",e),p("websocket heartTime",t),this.ws.postMessage({cmd:"config",heartBeat:e,heartTime:t})}initWebsocket(){this.ws.postMessage({cmd:"start",url:this.server})}send(e){this.ws.postMessage({cmd:"msg",data:e})}close(){this.ws.postMessage({cmd:"close"})}sendMessage(e){p("websocket send message ",e),e!==void 0&&this.ws!==void 0&&this.ws.postMessage({cmd:"msg",data:e})}}class Ee extends Y.EventEmitter{constructor(e,t,s,n){super(),this.activeServer="",this.server=e,this.localNumber=t,this.expireTime=s,this.heartTime=n,super.setMaxListeners(0)}async testWs(e){return e.reduce((t,s)=>t.then(n=>Promise.resolve(n),n=>new Promise((r,a)=>{const u=new WebSocket(s);u.onopen=()=>{n.push(s),u.close(),r(n)},u.onclose=()=>{a(n)}})),Promise.reject([])).then(t=>Promise.resolve(t),t=>Promise.resolve(t))}async reConnect(){this.destroy();let e=[];this.server!==void 0&&(typeof this.server=="string"?e=[this.server]:e=this.server);const t=await this.testWs(e);return new Promise((s,n)=>{if(t.length>0){this.activeServer=t[0];let r=new Ce(this.activeServer,new L(y.MESSAGE_TYPE_REGISTER,this.localNumber,this.localNumber,{expire:this.expireTime}),this.heartTime);r.on(N.connected,()=>{this.socketWorker=r,this.onConnected(),s()}),r.on(N.disconnected,a=>{this.socketWorker=void 0,this.onDisConnected(a),n("socketWorker connecion failed")}),r.on(N.message,a=>this.onReviceMessage(a)),r.connect()}else n("server is empty")})}sendMessage(e){if(this.socketWorker!==void 0)this.socketWorker.sendMessage(e);else throw new Error("socketWorker is closed")}destroy(){this.socketWorker!==void 0&&(this.unRegister(),this.socketWorker.close(),this.socketWorker=void 0)}}class be extends Ee{constructor(){super(...arguments),this.asyncProducer=new Map}async sendRespondableMessage(e){return this.sendMessage(e),new Promise(t=>this.asyncProducer.set(e.seq,t))}getAsyncResolve(e){let t=this.asyncProducer.get(e);return t!==void 0&&this.asyncProducer.delete(e),t}onDisConnected(e){this.asyncProducer.clear(),this.emit(P.disconnected,e)}onReviceMessage(e){let{status:t,seq:s}=e;t!==void 0?this.getAsyncResolve(s)?.call(void 0,e):this.processMessage(e)}}class ye extends be{async register(){let e=new L(y.MESSAGE_TYPE_REGISTER,this.localNumber,this.localNumber,{expire:this.expireTime});return this.sendRespondableMessage(e)}unRegister(){let e=new L(y.MESSAGE_TYPE_REGISTER,this.localNumber,this.localNumber,{expire:0});this.sendMessage(e)}async invite(e,t,s){return this.sendRespondableMessage(new L(y.MESSAGE_TYPE_INVITE,this.localNumber,e,{cid:t,sdp:s}))}sendIce(e,t,s){}sendBye(e,t){return this.sendMessage(new L(y.MESSAGE_TYPE_BYE,this.localNumber,e,{cid:t}))}answer(e,t,s,n,r){this.sendMessage({status:e,seq:t,from:s,to:this.localNumber,cid:n,sdp:r})}sendPttMessage(e){this.sendMessage(e)}async sendDtmf(e,t,s){return this.sendMessage(new L(y.MESSAGE_TYPE_INFO,this.localNumber,e,{cid:t,info:{msg:"dtmf",dtmf:s}}))}}var Te;function _(){}_.prototype=Object.create(null);function m(){m.init.call(this)}m.EventEmitter=m,m.usingDomains=!1,m.prototype.domain=void 0,m.prototype._events=void 0,m.prototype._maxListeners=void 0,m.defaultMaxListeners=10,m.init=function(){this.domain=null,m.usingDomains&&Te.active,(!this._events||this._events===Object.getPrototypeOf(this)._events)&&(this._events=new _,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},m.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||isNaN(e))throw new TypeError('"n" argument must be a positive number');return this._maxListeners=e,this};function Z(i){return i._maxListeners===void 0?m.defaultMaxListeners:i._maxListeners}m.prototype.getMaxListeners=function(){return Z(this)};function Se(i,e,t){if(e)i.call(t);else for(var s=i.length,n=M(i,s),r=0;r<s;++r)n[r].call(t)}function Le(i,e,t,s){if(e)i.call(t,s);else for(var n=i.length,r=M(i,n),a=0;a<n;++a)r[a].call(t,s)}function _e(i,e,t,s,n){if(e)i.call(t,s,n);else for(var r=i.length,a=M(i,r),u=0;u<r;++u)a[u].call(t,s,n)}function Re(i,e,t,s,n,r){if(e)i.call(t,s,n,r);else for(var a=i.length,u=M(i,a),w=0;w<a;++w)u[w].call(t,s,n,r)}function Ie(i,e,t,s){if(e)i.apply(t,s);else for(var n=i.length,r=M(i,n),a=0;a<n;++a)r[a].apply(t,s)}m.prototype.emit=function(e){var t,s,n,r,a,u,w,E=e==="error";if(u=this._events,u)E=E&&u.error==null;else if(!E)return!1;if(w=this.domain,E){if(t=arguments[1],w)t||(t=new Error('Uncaught, unspecified "error" event')),t.domainEmitter=this,t.domain=w,t.domainThrown=!1,w.emit("error",t);else{if(t instanceof Error)throw t;var U=new Error('Uncaught, unspecified "error" event. ('+t+")");throw U.context=t,U}return!1}if(s=u[e],!s)return!1;var R=typeof s=="function";switch(n=arguments.length,n){case 1:Se(s,R,this);break;case 2:Le(s,R,this,arguments[1]);break;case 3:_e(s,R,this,arguments[1],arguments[2]);break;case 4:Re(s,R,this,arguments[1],arguments[2],arguments[3]);break;default:for(r=new Array(n-1),a=1;a<n;a++)r[a-1]=arguments[a];Ie(s,R,this,r)}return!0};function ee(i,e,t,s){var n,r,a;if(typeof t!="function")throw new TypeError('"listener" argument must be a function');if(r=i._events,r?(r.newListener&&(i.emit("newListener",e,t.listener?t.listener:t),r=i._events),a=r[e]):(r=i._events=new _,i._eventsCount=0),!a)a=r[e]=t,++i._eventsCount;else if(typeof a=="function"?a=r[e]=s?[t,a]:[a,t]:s?a.unshift(t):a.push(t),!a.warned&&(n=Z(i),n&&n>0&&a.length>n)){a.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+a.length+" "+e+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=i,u.type=e,u.count=a.length,Ne(u)}return i}function Ne(i){typeof console.warn=="function"?console.warn(i):console.log(i)}m.prototype.addListener=function(e,t){return ee(this,e,t,!1)},m.prototype.on=m.prototype.addListener,m.prototype.prependListener=function(e,t){return ee(this,e,t,!0)};function te(i,e,t){var s=!1;function n(){i.removeListener(e,n),s||(s=!0,t.apply(i,arguments))}return n.listener=t,n}m.prototype.once=function(e,t){if(typeof t!="function")throw new TypeError('"listener" argument must be a function');return this.on(e,te(this,e,t)),this},m.prototype.prependOnceListener=function(e,t){if(typeof t!="function")throw new TypeError('"listener" argument must be a function');return this.prependListener(e,te(this,e,t)),this},m.prototype.removeListener=function(e,t){var s,n,r,a,u;if(typeof t!="function")throw new TypeError('"listener" argument must be a function');if(n=this._events,!n)return this;if(s=n[e],!s)return this;if(s===t||s.listener&&s.listener===t)--this._eventsCount===0?this._events=new _:(delete n[e],n.removeListener&&this.emit("removeListener",e,s.listener||t));else if(typeof s!="function"){for(r=-1,a=s.length;a-- >0;)if(s[a]===t||s[a].listener&&s[a].listener===t){u=s[a].listener,r=a;break}if(r<0)return this;if(s.length===1){if(s[0]=void 0,--this._eventsCount===0)return this._events=new _,this;delete n[e]}else Oe(s,r);n.removeListener&&this.emit("removeListener",e,u||t)}return this},m.prototype.off=function(i,e){return this.removeListener(i,e)},m.prototype.removeAllListeners=function(e){var t,s;if(s=this._events,!s)return this;if(!s.removeListener)return arguments.length===0?(this._events=new _,this._eventsCount=0):s[e]&&(--this._eventsCount===0?this._events=new _:delete s[e]),this;if(arguments.length===0){for(var n=Object.keys(s),r=0,a;r<n.length;++r)a=n[r],a!=="removeListener"&&this.removeAllListeners(a);return this.removeAllListeners("removeListener"),this._events=new _,this._eventsCount=0,this}if(t=s[e],typeof t=="function")this.removeListener(e,t);else if(t)do this.removeListener(e,t[t.length-1]);while(t[0]);return this},m.prototype.listeners=function(e){var t,s,n=this._events;return n?(t=n[e],t?typeof t=="function"?s=[t.listener||t]:s=Me(t):s=[]):s=[],s},m.listenerCount=function(i,e){return typeof i.listenerCount=="function"?i.listenerCount(e):ie.call(i,e)},m.prototype.listenerCount=ie;function ie(i){var e=this._events;if(e){var t=e[i];if(typeof t=="function")return 1;if(t)return t.length}return 0}m.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};function Oe(i,e){for(var t=e,s=t+1,n=i.length;s<n;t+=1,s+=1)i[t]=i[s];i.pop()}function M(i,e){for(var t=new Array(e);e--;)t[e]=i[e];return t}function Me(i){for(var e=new Array(i.length),t=0;t<e.length;++t)e[t]=i[t].listener||i[t];return e}const k={ERROR:"error",SPEAKER:"speaker",TALKING:"talking",ACTIVE_GROUP:"activeGroup",JOIN_INFO:"joinInfo",DISCONNECTED:"disConnected"},se={400:"消息不符规范",401:"验证不通过",403:"无权利操作",404:"不存在该用户",415:"错误参数",405:"无法操作",424:"不存在XD群",425:"管理员没有",426:"已存在管理员",427:"以前被拒绝过,或者删除过",428:"超出所配置的下属管理员的数量",429:"群内无用户",430:"管理员的索引号冲突",431:"还有子管理员存在"},O={connected:"connected",disconnected:"disconnected",message:"message"},T=(i,...e)=>{console.log(`%c usc-ptt-devtools %c ${i} %c `,"background:#16aae0 ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff","background:#14e04e ; padding: 1px; border-radius: 0 3px 3px 0; color: #fff","background:transparent",...e)},ne=(i,...e)=>{console.log(`%c usc-ptt-devtools %c ${i} %c `,"background:#16aae0 ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff","background:#e02514 ; padding: 1px; border-radius: 0 3px 3px 0; color: #fff","background:transparent",...e)};class Ae extends m{server="";ws=null;constructor(e){super(),this.server=e}connect(){this.ws=new WebSocket(this.server),this.ws.onopen=()=>{T("websocket connected ",this.server),this.emit(O.connected)},this.ws.onclose=()=>{T("websocket disconnected ",this.server),this.ws=void 0,this.emit(O.disconnected)},this.ws.onmessage=({data:e})=>{let t=JSON.parse(e);T("websocket recive message ",t),this.emit(O.message,t)}}close(){this.ws!==void 0&&(this.ws.close(),this.ws=void 0)}sendMessage(e){T("websocket send message ",e),e!==void 0&&this.ws!==void 0&&this.ws.readyState===1&&this.ws.send(JSON.stringify(e))}}class Pe extends m{socket=void 0;timer=void 0;waitinggroup=void 0;speaker="";activeGroup="";talking=!1;constructor(e,t=20,s=!0){if(super(),!e)return ne("服务器地址为空!");this.server=e,this.heartTime=t,this.autoReconnect=s}async initClient(){return this.destorySocket(),new Promise((e,t)=>{if(this.server!==void 0){let s=new Ae(this.server);s.on(O.connected,()=>{this.socket=s,this.timer=setInterval(()=>{this.sendMessage({req:0})},this.heartTime*1e3),e()}),s.on(O.disconnected,()=>{this.socket=void 0,this.autoReconnect?setTimeout(()=>{this.initClient()},3e3):this.emit(k.DISCONNECTED),t("socket connecion failed")}),s.on(O.message,n=>this.onReviceMessage(n)),s.connect()}else t("server is empty")})}onReviceMessage(e){T(e);const{info:t,msg:s,res:n}=e;if(t===10&&(this.speaker=`${s.speaker}`,T(`${this.speaker}正在说话`),this.emit(k.SPEAKER,this.speaker)),t===11&&(n.code===200?(this.activeGroup=this.waitinggroup,T(`加入组${this.activeGroup}`)):(this.activeGroup="",ne(se[n.code]),this.emit(k.ERROR,se[n.code])),this.emit(k.ACTIVE_GROUP,this.activeGroup)),t===13&&(n.code===200?this.talking=!0:this.talking=!1,T(`talking:${this.talking}`),this.emit(k.TALKING,this.talking)),t===14&&(this.speaker="",T(`${this.speaker}停止说话`),this.emit(k.SPEAKER,this.speaker)),t===15){const r={user:s.number,group:s.g_num,code:s.status};T(`${r}进入组`),this.emit(k.JOIN_INFO,r)}}joinGroup(e,t,s,n){this.socket&&(this.waitinggroup=e,this.sendMessage({req:1,group:e,user:t,ptts:s,port:n}))}quitGroup(){this.socket&&(this.activeGroup="",this.emit(k.ACTIVE_GROUP,this.activeGroup),this.sendMessage({req:2}))}talk(){this.socket&&this.sendMessage({req:3})}stop(){this.talking=!1,T(`talking:${this.talking}`),this.emit(k.TALKING,this.talking),this.socket&&this.sendMessage({req:4})}sendMessage(e){if(this.socket!==void 0)this.socket.sendMessage(e);else throw new Error("socket is closed")}destorySocket(){this.socket!==void 0&&(this.socket.close(),this.socket=void 0)}destory(){this.destorySocket()}}const xe=async(i,e=20,t=!0)=>{let s=new Pe(i,e,t);return await s.initClient(),s},V=class V extends ye{constructor(e){let t=e.expireTime||V.defaultExpireTime;super(e.server,e.localNumber,t,e.heartTime||(e.localNumber?5:0)),this.enablePtt=e.enablePtt,this.pttServer=e.pttServer}async initPttClient(){if(this.enablePtt)if(this.pttServer){const e=await xe(this.pttServer);if(!e)return Promise.reject("ptt客户端初始化失败!");e.on(k.ACTIVE_GROUP,t=>{this.emit(k.ACTIVE_GROUP,t)}),e.on(k.SPEAKER,t=>{this.emit(k.SPEAKER,t)}),e.on(k.TALKING,t=>{this.emit(k.TALKING,t)}),e.on(k.JOIN_INFO,t=>{this.emit(k.JOIN_INFO,t)}),e.on(k.DISCONNECTED,t=>{this.emit(k.DISCONNECTED,t)}),this.pttClient=e}else return Promise.reject("pttServer不存在")}joinGroup(e,t,s,n){this.pttClient?.joinGroup(e,t,s,n)}quitGroup(){this.pttClient?.quitGroup()}talk(){this.pttClient?.talk()}stop(){this.pttClient?.stop()}onConnected(){}onDisConnected(){super.onDisConnected()}};V.defaultExpireTime=60;let K=V;class re extends Q{constructor(e,t,s,n,r){super(e,t,s),this.callType=b.unknown,this.inviteSeq=r,this.inviteOffer=n;const a=n.split(`\r
|
|
6
|
+
`),u=a.find(E=>E.startsWith("m=audio")),w=a.find(E=>E.startsWith("m=video"));this.callType=u&&w?b.audioVideo:u?b.audio:w?b.video:b.unknown}}class J extends K{constructor(){super(...arguments),this.allSession=[]}createSession(e){let t=new $(this,B(),e);return this.allSession.push(t),t}playRemote(e,t,s){return new Promise((n,r)=>{try{let a=new $(this,B(),e);this.allSession.push(a),a.playRemoteStream(t,s),a.start().then(u=>{p("playRemote start status",u),u===I.ok?n(a):r(new Error(`Failed to start session, status: ${u}`))}).catch(u=>{r(u)}),a.on(C.bye,()=>{this.removeSession(a)})}catch(a){r(a)}})}processMessage(e){let{req:t}=e;if(t===y.MESSAGE_TYPE_INVITE){let s=new re(this,e.cid,e.from,e.sdp,e.seq);this.allSession.push(s),this.emit(P.invite,s)}else if(t===y.MESSAGE_TYPE_REINVITE){let s=this.allSession.find(n=>n.sessionId==e.cid);s!==void 0&&(s.inviteSeq=e.seq,s.inviteOffer=e.sdp,s.acceptCall(),s.emit(C.reInvite,s))}else if(t===y.MESSAGE_TYPE_ICE)this.allSession.find(s=>s.sessionId===e.cid)?.reciveIceRequest(e);else if(t===y.MESSAGE_TYPE_BYE){let s=this.allSession.find(n=>n.sessionId===e.cid);s!==void 0&&(s.emit(C.bye),s.destroy(!1))}t==W.FPRE&&this.emit(x.FPREInfo,e),t==W.IMS&&this.emit(x.IMSInfo,e)}destroy(){this.allSession!==void 0&&this.allSession.forEach(e=>{e.destroy()}),super.destroy()}removeSession(e){this.allSession!==void 0&&(this.allSession=this.allSession.filter(t=>t.sessionId!==e.sessionId))}onDisConnected(){super.onDisConnected(),this.destroy()}}const Ge=async i=>{let e=new J(i);await e.reConnect(),await e.initPttClient().catch(s=>{console.error(s)}),L.random=String(Date.now());let t=await e.register();return t.status===I.ok?e:(e.destroy(),Promise.reject(t))},De=async(i,e,t,s)=>{L.random=String(Date.now());let n=new J({server:i,localNumber:"anonymous",...s});await n.reConnect();const r=await n.playRemote(e,t);return{destroy:()=>{r.destroy(),n.destroy()},on:(a,u)=>{r.on(a,u)},off:(a,u)=>{r.off(a,u)}}},je=async()=>{await navigator.mediaDevices.getUserMedia({audio:!0,video:!0})};g.PTTEvent=x,g.RtcCalledSession=re,g.RtcCalledType=b,g.RtcClient=J,g.RtcClientEvent=P,g.RtcInviteStatus=I,g.RtcSession=$,g.RtcSessionEvent=C,g.authDevice=je,g.closeStreamAndTrack=F,g.createRtcClient=Ge,g.disableLog=fe,g.enableLog=me,g.playRemote=De,g.releaseStreamFromContainer=le,g.renderStreamToContainer=q,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "usc-rtc-client",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"description": "usc rtc client",
|
|
5
5
|
"main": "./dist/index.umd.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "vite build && cp dist/index.es.js test/",
|
|
9
|
-
"
|
|
10
|
-
"release:
|
|
11
|
-
"release:
|
|
12
|
-
"release:major": "pnpm version major && pnpm run publish"
|
|
9
|
+
"release:patch": "pnpm version patch && pnpm run build && npm publish",
|
|
10
|
+
"release:minor": "pnpm version minor && pnpm run build && npm publish",
|
|
11
|
+
"release:major": "pnpm version major && pnpm run build && npm publish"
|
|
13
12
|
},
|
|
14
13
|
"exports": {
|
|
15
14
|
"import": {
|