@whereby.com/media 1.25.1 → 1.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +219 -249
- package/dist/index.d.cts +0 -2
- package/dist/index.d.mts +0 -2
- package/dist/index.d.ts +0 -2
- package/dist/index.mjs +219 -249
- package/dist/legacy-esm.js +219 -249
- package/package.json +1 -1
package/dist/legacy-esm.js
CHANGED
|
@@ -2528,7 +2528,7 @@ const VIDEO_SETTINGS_VP9 = {
|
|
|
2528
2528
|
codecOptions: {
|
|
2529
2529
|
videoGoogleStartBitrate: 500,
|
|
2530
2530
|
},
|
|
2531
|
-
encodings: [{ scalabilityMode: "L3T2_KEY" }],
|
|
2531
|
+
encodings: [{ scalabilityMode: "L3T2_KEY", maxBitrate: 1650000 }],
|
|
2532
2532
|
};
|
|
2533
2533
|
const VIDEO_SETTINGS_VP9_LOW_BANDWIDTH = {
|
|
2534
2534
|
codecOptions: {
|
|
@@ -4202,215 +4202,6 @@ class P2pRtcManager {
|
|
|
4202
4202
|
}
|
|
4203
4203
|
}
|
|
4204
4204
|
|
|
4205
|
-
class SfuV2Parser {
|
|
4206
|
-
static parse(raw) {
|
|
4207
|
-
let object;
|
|
4208
|
-
try {
|
|
4209
|
-
object = JSON.parse(raw);
|
|
4210
|
-
}
|
|
4211
|
-
catch (error) {
|
|
4212
|
-
return;
|
|
4213
|
-
}
|
|
4214
|
-
if (typeof object !== "object" || Array.isArray(object)) {
|
|
4215
|
-
return;
|
|
4216
|
-
}
|
|
4217
|
-
if (object.request) {
|
|
4218
|
-
return SfuV2Parser._handleRequest(object);
|
|
4219
|
-
}
|
|
4220
|
-
else if (object.response) {
|
|
4221
|
-
return SfuV2Parser._handleResponse(object);
|
|
4222
|
-
}
|
|
4223
|
-
else if (object.message) {
|
|
4224
|
-
return SfuV2Parser._handleMessage(object);
|
|
4225
|
-
}
|
|
4226
|
-
else {
|
|
4227
|
-
return;
|
|
4228
|
-
}
|
|
4229
|
-
}
|
|
4230
|
-
static _handleRequest(rawMessage) {
|
|
4231
|
-
const message = {};
|
|
4232
|
-
message.request = true;
|
|
4233
|
-
if (typeof rawMessage.method !== "string") {
|
|
4234
|
-
return;
|
|
4235
|
-
}
|
|
4236
|
-
if (typeof rawMessage.id !== "number") {
|
|
4237
|
-
return;
|
|
4238
|
-
}
|
|
4239
|
-
message.id = rawMessage.id;
|
|
4240
|
-
message.method = rawMessage.method;
|
|
4241
|
-
message.data = rawMessage.data || {};
|
|
4242
|
-
return message;
|
|
4243
|
-
}
|
|
4244
|
-
static _handleResponse(rawMessage) {
|
|
4245
|
-
const message = {};
|
|
4246
|
-
message.response = true;
|
|
4247
|
-
if (typeof rawMessage.id !== "number") {
|
|
4248
|
-
return;
|
|
4249
|
-
}
|
|
4250
|
-
message.id = rawMessage.id;
|
|
4251
|
-
if (rawMessage.ok) {
|
|
4252
|
-
message.ok = true;
|
|
4253
|
-
message.data = rawMessage.data || {};
|
|
4254
|
-
}
|
|
4255
|
-
else {
|
|
4256
|
-
message.ok = false;
|
|
4257
|
-
message.errorCode = rawMessage.errorCode;
|
|
4258
|
-
message.errorReason = rawMessage.errorReason;
|
|
4259
|
-
}
|
|
4260
|
-
return message;
|
|
4261
|
-
}
|
|
4262
|
-
static _handleMessage(rawMessage) {
|
|
4263
|
-
const message = {};
|
|
4264
|
-
message.message = true;
|
|
4265
|
-
if (typeof rawMessage.method !== "string") {
|
|
4266
|
-
return;
|
|
4267
|
-
}
|
|
4268
|
-
message.method = rawMessage.method;
|
|
4269
|
-
message.data = rawMessage.data || {};
|
|
4270
|
-
return message;
|
|
4271
|
-
}
|
|
4272
|
-
static createRequest(method, data) {
|
|
4273
|
-
return {
|
|
4274
|
-
request: true,
|
|
4275
|
-
id: Math.round(Math.random() * 10000000),
|
|
4276
|
-
method,
|
|
4277
|
-
data: data || {},
|
|
4278
|
-
};
|
|
4279
|
-
}
|
|
4280
|
-
static createSuccessResponse(request, data) {
|
|
4281
|
-
return {
|
|
4282
|
-
response: true,
|
|
4283
|
-
id: request.id,
|
|
4284
|
-
ok: true,
|
|
4285
|
-
data: data || {},
|
|
4286
|
-
};
|
|
4287
|
-
}
|
|
4288
|
-
static createErrorResponse(request, errorCode, errorReason) {
|
|
4289
|
-
return {
|
|
4290
|
-
response: true,
|
|
4291
|
-
id: request.id,
|
|
4292
|
-
errorCode,
|
|
4293
|
-
errorReason,
|
|
4294
|
-
};
|
|
4295
|
-
}
|
|
4296
|
-
static createMessage(method, data) {
|
|
4297
|
-
return {
|
|
4298
|
-
message: true,
|
|
4299
|
-
method,
|
|
4300
|
-
data: data || {},
|
|
4301
|
-
};
|
|
4302
|
-
}
|
|
4303
|
-
}
|
|
4304
|
-
|
|
4305
|
-
const logger$6 = new Logger();
|
|
4306
|
-
class VegaConnection extends EventEmitter$1 {
|
|
4307
|
-
constructor(wsUrl, protocol = "whereby-sfu#v4") {
|
|
4308
|
-
super();
|
|
4309
|
-
this.socket = null;
|
|
4310
|
-
this.wsUrl = wsUrl;
|
|
4311
|
-
this.protocol = protocol;
|
|
4312
|
-
this.sents = new Map();
|
|
4313
|
-
this._setupSocket();
|
|
4314
|
-
}
|
|
4315
|
-
_setupSocket() {
|
|
4316
|
-
this.socket = new WebSocket(this.wsUrl, this.protocol);
|
|
4317
|
-
this.socket.onopen = this._onOpen.bind(this);
|
|
4318
|
-
this.socket.onmessage = this._onMessage.bind(this);
|
|
4319
|
-
this.socket.onclose = this._onClose.bind(this);
|
|
4320
|
-
this.socket.onerror = this._onError.bind(this);
|
|
4321
|
-
}
|
|
4322
|
-
_tearDown() {
|
|
4323
|
-
if (this.socket === null)
|
|
4324
|
-
return;
|
|
4325
|
-
this.socket.onopen = null;
|
|
4326
|
-
this.socket.onmessage = null;
|
|
4327
|
-
this.socket.onclose = null;
|
|
4328
|
-
this.socket.onerror = null;
|
|
4329
|
-
this.socket = null;
|
|
4330
|
-
this.sents.forEach((sent) => sent.close());
|
|
4331
|
-
this.emit("close");
|
|
4332
|
-
}
|
|
4333
|
-
close() {
|
|
4334
|
-
var _a;
|
|
4335
|
-
(_a = this.socket) === null || _a === void 0 ? void 0 : _a.close();
|
|
4336
|
-
}
|
|
4337
|
-
_onOpen() {
|
|
4338
|
-
logger$6.info("Connected");
|
|
4339
|
-
this.emit("open");
|
|
4340
|
-
}
|
|
4341
|
-
_onMessage(event) {
|
|
4342
|
-
const socketMessage = SfuV2Parser.parse(event.data);
|
|
4343
|
-
logger$6.info("Received message", socketMessage);
|
|
4344
|
-
if (socketMessage === null || socketMessage === void 0 ? void 0 : socketMessage.response) {
|
|
4345
|
-
this._handleResponse(socketMessage);
|
|
4346
|
-
}
|
|
4347
|
-
else if (socketMessage === null || socketMessage === void 0 ? void 0 : socketMessage.message) {
|
|
4348
|
-
this.emit("message", socketMessage);
|
|
4349
|
-
}
|
|
4350
|
-
}
|
|
4351
|
-
_onClose() {
|
|
4352
|
-
logger$6.info("Disconnected");
|
|
4353
|
-
this._tearDown();
|
|
4354
|
-
}
|
|
4355
|
-
_onError(error) {
|
|
4356
|
-
logger$6.info("Error", error);
|
|
4357
|
-
}
|
|
4358
|
-
_handleResponse(socketMessage) {
|
|
4359
|
-
const sent = this.sents.get(socketMessage.id);
|
|
4360
|
-
if (socketMessage.ok) {
|
|
4361
|
-
sent.resolve(socketMessage.data);
|
|
4362
|
-
}
|
|
4363
|
-
else {
|
|
4364
|
-
const error = new Error(socketMessage.errorReason);
|
|
4365
|
-
sent.reject(error);
|
|
4366
|
-
}
|
|
4367
|
-
}
|
|
4368
|
-
send(message) {
|
|
4369
|
-
try {
|
|
4370
|
-
if (this.socket) {
|
|
4371
|
-
this.socket.send(JSON.stringify(message));
|
|
4372
|
-
}
|
|
4373
|
-
}
|
|
4374
|
-
catch (error) { }
|
|
4375
|
-
}
|
|
4376
|
-
message(method, data = {}) {
|
|
4377
|
-
const message = SfuV2Parser.createMessage(method, data);
|
|
4378
|
-
this.send(message);
|
|
4379
|
-
}
|
|
4380
|
-
request(method, data = {}, timeout = 1500 * (15 + 0.1 * this.sents.size)) {
|
|
4381
|
-
const request = SfuV2Parser.createRequest(method, data);
|
|
4382
|
-
this.send(request);
|
|
4383
|
-
return new Promise((pResolve, pReject) => {
|
|
4384
|
-
const sent = {
|
|
4385
|
-
id: request.id,
|
|
4386
|
-
method: request.method,
|
|
4387
|
-
resolve: (data2) => {
|
|
4388
|
-
if (!this.sents.delete(request.id))
|
|
4389
|
-
return;
|
|
4390
|
-
clearTimeout(sent.timer);
|
|
4391
|
-
pResolve(data2);
|
|
4392
|
-
},
|
|
4393
|
-
reject: (error) => {
|
|
4394
|
-
if (!this.sents.delete(request.id))
|
|
4395
|
-
return;
|
|
4396
|
-
clearTimeout(sent.timer);
|
|
4397
|
-
pReject(error);
|
|
4398
|
-
},
|
|
4399
|
-
timer: setTimeout(() => {
|
|
4400
|
-
if (!this.sents.delete(request.id))
|
|
4401
|
-
return;
|
|
4402
|
-
pReject(new Error("request timeout"));
|
|
4403
|
-
}, timeout),
|
|
4404
|
-
close: () => {
|
|
4405
|
-
clearTimeout(sent.timer);
|
|
4406
|
-
pReject(new Error("transport closed"));
|
|
4407
|
-
},
|
|
4408
|
-
};
|
|
4409
|
-
this.sents.set(request.id, sent);
|
|
4410
|
-
});
|
|
4411
|
-
}
|
|
4412
|
-
}
|
|
4413
|
-
|
|
4414
4205
|
class KalmanFilter {
|
|
4415
4206
|
constructor({ R = 0.01, Q = 2, A = 1.1, B = 1, C = 1.2 } = { R: 0.01, Q: 2, A: 1.1, B: 1, C: 1.2 }) {
|
|
4416
4207
|
this.R = R;
|
|
@@ -4519,7 +4310,7 @@ const defaultParams = {
|
|
|
4519
4310
|
scoreFormula: "300 * bands[1].avg / Math.max(bands[1].avg + bands[0].avg, 0.01)",
|
|
4520
4311
|
outFormula: "score",
|
|
4521
4312
|
};
|
|
4522
|
-
const logger$
|
|
4313
|
+
const logger$6 = new Logger();
|
|
4523
4314
|
function createMicAnalyser({ micTrack, params, onScoreUpdated, }) {
|
|
4524
4315
|
const audioCtx = new AudioContext();
|
|
4525
4316
|
let analyser = null;
|
|
@@ -4541,7 +4332,7 @@ function createMicAnalyser({ micTrack, params, onScoreUpdated, }) {
|
|
|
4541
4332
|
lastTrackWasOurs = true;
|
|
4542
4333
|
}
|
|
4543
4334
|
catch (ex) {
|
|
4544
|
-
logger$
|
|
4335
|
+
logger$6.warn("unable to fetch new track for colocation speaker analysis, using current", ex);
|
|
4545
4336
|
}
|
|
4546
4337
|
}
|
|
4547
4338
|
lastTrack = track;
|
|
@@ -4628,7 +4419,7 @@ function createMicAnalyser({ micTrack, params, onScoreUpdated, }) {
|
|
|
4628
4419
|
};
|
|
4629
4420
|
}
|
|
4630
4421
|
|
|
4631
|
-
const logger$
|
|
4422
|
+
const logger$5 = new Logger();
|
|
4632
4423
|
const MEDIA_QUALITY = Object.freeze({
|
|
4633
4424
|
ok: "ok",
|
|
4634
4425
|
warning: "warning",
|
|
@@ -4698,7 +4489,7 @@ class VegaMediaQualityMonitor extends EventEmitter {
|
|
|
4698
4489
|
}
|
|
4699
4490
|
addProducer(clientId, producerId) {
|
|
4700
4491
|
if (!clientId || !producerId || !(typeof clientId === "string" && typeof producerId === "string")) {
|
|
4701
|
-
logger$
|
|
4492
|
+
logger$5.warn("Missing clientId or producerId");
|
|
4702
4493
|
return;
|
|
4703
4494
|
}
|
|
4704
4495
|
if (!this._producers[clientId]) {
|
|
@@ -4714,7 +4505,7 @@ class VegaMediaQualityMonitor extends EventEmitter {
|
|
|
4714
4505
|
}
|
|
4715
4506
|
addConsumer(clientId, consumerId) {
|
|
4716
4507
|
if (!clientId || !consumerId) {
|
|
4717
|
-
logger$
|
|
4508
|
+
logger$5.warn("Missing clientId or consumerId");
|
|
4718
4509
|
return;
|
|
4719
4510
|
}
|
|
4720
4511
|
if (!this._producers[clientId]) {
|
|
@@ -4732,14 +4523,14 @@ class VegaMediaQualityMonitor extends EventEmitter {
|
|
|
4732
4523
|
if (!Array.isArray(score) ||
|
|
4733
4524
|
score.length === 0 ||
|
|
4734
4525
|
score.some((s) => !s || !s.hasOwnProperty("score") || typeof s.score !== "number" || isNaN(s.score))) {
|
|
4735
|
-
logger$
|
|
4526
|
+
logger$5.warn("Unexpected producer score format");
|
|
4736
4527
|
return;
|
|
4737
4528
|
}
|
|
4738
4529
|
this._producers[clientId][producerId] = { kind, score: this._calcAvgProducerScore(score.map((s) => s.score)) };
|
|
4739
4530
|
}
|
|
4740
4531
|
addConsumerScore(clientId, consumerId, kind, score) {
|
|
4741
4532
|
if (!score || !score.hasOwnProperty("producerScores") || !Array.isArray(score.producerScores)) {
|
|
4742
|
-
logger$
|
|
4533
|
+
logger$5.warn("Unexpected consumer score format");
|
|
4743
4534
|
return;
|
|
4744
4535
|
}
|
|
4745
4536
|
this._producers[clientId][consumerId] = { kind, score: this._calcAvgProducerScore(score.producerScores) };
|
|
@@ -4776,7 +4567,7 @@ class VegaMediaQualityMonitor extends EventEmitter {
|
|
|
4776
4567
|
}
|
|
4777
4568
|
}
|
|
4778
4569
|
catch (error) {
|
|
4779
|
-
logger$
|
|
4570
|
+
logger$5.error(error);
|
|
4780
4571
|
return 0;
|
|
4781
4572
|
}
|
|
4782
4573
|
}
|
|
@@ -4817,6 +4608,215 @@ function getNumberOfTemporalLayers(consumer) {
|
|
|
4817
4608
|
return /T3/.test(((_c = (_b = (_a = consumer._rtpParameters) === null || _a === void 0 ? void 0 : _a.encodings) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.scalabilityMode) || "") ? 3 : 2;
|
|
4818
4609
|
}
|
|
4819
4610
|
|
|
4611
|
+
class SfuV2Parser {
|
|
4612
|
+
static parse(raw) {
|
|
4613
|
+
let object;
|
|
4614
|
+
try {
|
|
4615
|
+
object = JSON.parse(raw);
|
|
4616
|
+
}
|
|
4617
|
+
catch (error) {
|
|
4618
|
+
return;
|
|
4619
|
+
}
|
|
4620
|
+
if (typeof object !== "object" || Array.isArray(object)) {
|
|
4621
|
+
return;
|
|
4622
|
+
}
|
|
4623
|
+
if (object.request) {
|
|
4624
|
+
return SfuV2Parser._handleRequest(object);
|
|
4625
|
+
}
|
|
4626
|
+
else if (object.response) {
|
|
4627
|
+
return SfuV2Parser._handleResponse(object);
|
|
4628
|
+
}
|
|
4629
|
+
else if (object.message) {
|
|
4630
|
+
return SfuV2Parser._handleMessage(object);
|
|
4631
|
+
}
|
|
4632
|
+
else {
|
|
4633
|
+
return;
|
|
4634
|
+
}
|
|
4635
|
+
}
|
|
4636
|
+
static _handleRequest(rawMessage) {
|
|
4637
|
+
const message = {};
|
|
4638
|
+
message.request = true;
|
|
4639
|
+
if (typeof rawMessage.method !== "string") {
|
|
4640
|
+
return;
|
|
4641
|
+
}
|
|
4642
|
+
if (typeof rawMessage.id !== "number") {
|
|
4643
|
+
return;
|
|
4644
|
+
}
|
|
4645
|
+
message.id = rawMessage.id;
|
|
4646
|
+
message.method = rawMessage.method;
|
|
4647
|
+
message.data = rawMessage.data || {};
|
|
4648
|
+
return message;
|
|
4649
|
+
}
|
|
4650
|
+
static _handleResponse(rawMessage) {
|
|
4651
|
+
const message = {};
|
|
4652
|
+
message.response = true;
|
|
4653
|
+
if (typeof rawMessage.id !== "number") {
|
|
4654
|
+
return;
|
|
4655
|
+
}
|
|
4656
|
+
message.id = rawMessage.id;
|
|
4657
|
+
if (rawMessage.ok) {
|
|
4658
|
+
message.ok = true;
|
|
4659
|
+
message.data = rawMessage.data || {};
|
|
4660
|
+
}
|
|
4661
|
+
else {
|
|
4662
|
+
message.ok = false;
|
|
4663
|
+
message.errorCode = rawMessage.errorCode;
|
|
4664
|
+
message.errorReason = rawMessage.errorReason;
|
|
4665
|
+
}
|
|
4666
|
+
return message;
|
|
4667
|
+
}
|
|
4668
|
+
static _handleMessage(rawMessage) {
|
|
4669
|
+
const message = {};
|
|
4670
|
+
message.message = true;
|
|
4671
|
+
if (typeof rawMessage.method !== "string") {
|
|
4672
|
+
return;
|
|
4673
|
+
}
|
|
4674
|
+
message.method = rawMessage.method;
|
|
4675
|
+
message.data = rawMessage.data || {};
|
|
4676
|
+
return message;
|
|
4677
|
+
}
|
|
4678
|
+
static createRequest(method, data) {
|
|
4679
|
+
return {
|
|
4680
|
+
request: true,
|
|
4681
|
+
id: Math.round(Math.random() * 10000000),
|
|
4682
|
+
method,
|
|
4683
|
+
data: data || {},
|
|
4684
|
+
};
|
|
4685
|
+
}
|
|
4686
|
+
static createSuccessResponse(request, data) {
|
|
4687
|
+
return {
|
|
4688
|
+
response: true,
|
|
4689
|
+
id: request.id,
|
|
4690
|
+
ok: true,
|
|
4691
|
+
data: data || {},
|
|
4692
|
+
};
|
|
4693
|
+
}
|
|
4694
|
+
static createErrorResponse(request, errorCode, errorReason) {
|
|
4695
|
+
return {
|
|
4696
|
+
response: true,
|
|
4697
|
+
id: request.id,
|
|
4698
|
+
errorCode,
|
|
4699
|
+
errorReason,
|
|
4700
|
+
};
|
|
4701
|
+
}
|
|
4702
|
+
static createMessage(method, data) {
|
|
4703
|
+
return {
|
|
4704
|
+
message: true,
|
|
4705
|
+
method,
|
|
4706
|
+
data: data || {},
|
|
4707
|
+
};
|
|
4708
|
+
}
|
|
4709
|
+
}
|
|
4710
|
+
|
|
4711
|
+
const logger$4 = new Logger();
|
|
4712
|
+
class VegaConnection extends EventEmitter$1 {
|
|
4713
|
+
constructor(wsUrl, protocol = "whereby-sfu#v4") {
|
|
4714
|
+
super();
|
|
4715
|
+
this.socket = null;
|
|
4716
|
+
this.wsUrl = wsUrl;
|
|
4717
|
+
this.protocol = protocol;
|
|
4718
|
+
this.sents = new Map();
|
|
4719
|
+
this._setupSocket();
|
|
4720
|
+
}
|
|
4721
|
+
_setupSocket() {
|
|
4722
|
+
this.socket = new WebSocket(this.wsUrl, this.protocol);
|
|
4723
|
+
this.socket.onopen = this._onOpen.bind(this);
|
|
4724
|
+
this.socket.onmessage = this._onMessage.bind(this);
|
|
4725
|
+
this.socket.onclose = this._onClose.bind(this);
|
|
4726
|
+
this.socket.onerror = this._onError.bind(this);
|
|
4727
|
+
}
|
|
4728
|
+
_tearDown() {
|
|
4729
|
+
if (this.socket === null)
|
|
4730
|
+
return;
|
|
4731
|
+
this.socket.onopen = null;
|
|
4732
|
+
this.socket.onmessage = null;
|
|
4733
|
+
this.socket.onclose = null;
|
|
4734
|
+
this.socket.onerror = null;
|
|
4735
|
+
this.socket = null;
|
|
4736
|
+
this.sents.forEach((sent) => sent.close());
|
|
4737
|
+
this.emit("close");
|
|
4738
|
+
}
|
|
4739
|
+
close() {
|
|
4740
|
+
var _a;
|
|
4741
|
+
(_a = this.socket) === null || _a === void 0 ? void 0 : _a.close();
|
|
4742
|
+
}
|
|
4743
|
+
_onOpen() {
|
|
4744
|
+
logger$4.info("Connected");
|
|
4745
|
+
this.emit("open");
|
|
4746
|
+
}
|
|
4747
|
+
_onMessage(event) {
|
|
4748
|
+
const socketMessage = SfuV2Parser.parse(event.data);
|
|
4749
|
+
logger$4.info("Received message", socketMessage);
|
|
4750
|
+
if (socketMessage === null || socketMessage === void 0 ? void 0 : socketMessage.response) {
|
|
4751
|
+
this._handleResponse(socketMessage);
|
|
4752
|
+
}
|
|
4753
|
+
else if (socketMessage === null || socketMessage === void 0 ? void 0 : socketMessage.message) {
|
|
4754
|
+
this.emit("message", socketMessage);
|
|
4755
|
+
}
|
|
4756
|
+
}
|
|
4757
|
+
_onClose() {
|
|
4758
|
+
logger$4.info("Disconnected");
|
|
4759
|
+
this._tearDown();
|
|
4760
|
+
}
|
|
4761
|
+
_onError(error) {
|
|
4762
|
+
logger$4.info("Error", error);
|
|
4763
|
+
}
|
|
4764
|
+
_handleResponse(socketMessage) {
|
|
4765
|
+
const sent = this.sents.get(socketMessage.id);
|
|
4766
|
+
if (socketMessage.ok) {
|
|
4767
|
+
sent.resolve(socketMessage.data);
|
|
4768
|
+
}
|
|
4769
|
+
else {
|
|
4770
|
+
const error = new Error(socketMessage.errorReason);
|
|
4771
|
+
sent.reject(error);
|
|
4772
|
+
}
|
|
4773
|
+
}
|
|
4774
|
+
send(message) {
|
|
4775
|
+
try {
|
|
4776
|
+
if (this.socket) {
|
|
4777
|
+
this.socket.send(JSON.stringify(message));
|
|
4778
|
+
}
|
|
4779
|
+
}
|
|
4780
|
+
catch (error) { }
|
|
4781
|
+
}
|
|
4782
|
+
message(method, data = {}) {
|
|
4783
|
+
const message = SfuV2Parser.createMessage(method, data);
|
|
4784
|
+
this.send(message);
|
|
4785
|
+
}
|
|
4786
|
+
request(method, data = {}, timeout = 1500 * (15 + 0.1 * this.sents.size)) {
|
|
4787
|
+
const request = SfuV2Parser.createRequest(method, data);
|
|
4788
|
+
this.send(request);
|
|
4789
|
+
return new Promise((pResolve, pReject) => {
|
|
4790
|
+
const sent = {
|
|
4791
|
+
id: request.id,
|
|
4792
|
+
method: request.method,
|
|
4793
|
+
resolve: (data2) => {
|
|
4794
|
+
if (!this.sents.delete(request.id))
|
|
4795
|
+
return;
|
|
4796
|
+
clearTimeout(sent.timer);
|
|
4797
|
+
pResolve(data2);
|
|
4798
|
+
},
|
|
4799
|
+
reject: (error) => {
|
|
4800
|
+
if (!this.sents.delete(request.id))
|
|
4801
|
+
return;
|
|
4802
|
+
clearTimeout(sent.timer);
|
|
4803
|
+
pReject(error);
|
|
4804
|
+
},
|
|
4805
|
+
timer: setTimeout(() => {
|
|
4806
|
+
if (!this.sents.delete(request.id))
|
|
4807
|
+
return;
|
|
4808
|
+
pReject(new Error("request timeout"));
|
|
4809
|
+
}, timeout),
|
|
4810
|
+
close: () => {
|
|
4811
|
+
clearTimeout(sent.timer);
|
|
4812
|
+
pReject(new Error("transport closed"));
|
|
4813
|
+
},
|
|
4814
|
+
};
|
|
4815
|
+
this.sents.set(request.id, sent);
|
|
4816
|
+
});
|
|
4817
|
+
}
|
|
4818
|
+
}
|
|
4819
|
+
|
|
4820
4820
|
const timeNextServer = 500;
|
|
4821
4821
|
const minTimeNextServerSameDC = 2000;
|
|
4822
4822
|
const timeToWaitForEarlyServerClose = 100;
|
|
@@ -5066,7 +5066,6 @@ class VegaRtcManager {
|
|
|
5066
5066
|
this._socketListenerDeregisterFunctions = [];
|
|
5067
5067
|
this._reconnect = true;
|
|
5068
5068
|
this._reconnectTimeOut = null;
|
|
5069
|
-
this._hasVegaConnection = false;
|
|
5070
5069
|
this._isConnectingOrConnected = false;
|
|
5071
5070
|
this._qualityMonitor = new VegaMediaQualityMonitor();
|
|
5072
5071
|
this._qualityMonitor.on(PROTOCOL_EVENTS.MEDIA_QUALITY_CHANGED, (payload) => {
|
|
@@ -5136,7 +5135,7 @@ class VegaRtcManager {
|
|
|
5136
5135
|
}
|
|
5137
5136
|
if (this._screenVideoTrack)
|
|
5138
5137
|
this._emitScreenshareStarted();
|
|
5139
|
-
if (this._features.sfuReconnectV2On &&
|
|
5138
|
+
if (this._features.sfuReconnectV2On && this._reconnect) {
|
|
5140
5139
|
this._connect();
|
|
5141
5140
|
}
|
|
5142
5141
|
}), this._serverSocket.on("connect", () => this._onNetworkIsDetectedUpBySignal()), this._serverSocket.onEngineEvent("packet", () => this._onNetworkIsDetectedUpBySignal()), this._serverSocket.on("disconnect", () => this._onNetworkIsDetectedPossiblyDownBySignal()));
|
|
@@ -5149,34 +5148,6 @@ class VegaRtcManager {
|
|
|
5149
5148
|
});
|
|
5150
5149
|
}
|
|
5151
5150
|
_connect() {
|
|
5152
|
-
if (this._features.sfuConnectionManagerOn)
|
|
5153
|
-
return this._connect_v2();
|
|
5154
|
-
if (this._features.sfuReconnectV2On) {
|
|
5155
|
-
if (this._hasVegaConnection)
|
|
5156
|
-
return;
|
|
5157
|
-
if (!this._serverSocket.isConnected()) {
|
|
5158
|
-
const reconnectThresholdInMs = this._serverSocket.getReconnectThreshold();
|
|
5159
|
-
if (!reconnectThresholdInMs)
|
|
5160
|
-
return;
|
|
5161
|
-
if (Date.now() > (this._serverSocket.disconnectTimestamp || 0) + reconnectThresholdInMs)
|
|
5162
|
-
return;
|
|
5163
|
-
}
|
|
5164
|
-
if (this._reconnectTimeOut)
|
|
5165
|
-
clearTimeout(this._reconnectTimeOut);
|
|
5166
|
-
}
|
|
5167
|
-
const host = this._features.sfuServerOverrideHost || [this._sfuServer.url];
|
|
5168
|
-
const searchParams = new URLSearchParams(Object.assign({ clientId: this._selfId, organizationId: this._room.organizationId, roomName: this._room.name, eventClaim: this._room.isClaimed ? this._eventClaim : null, lowBw: "true" }, Object.keys(this._features || {})
|
|
5169
|
-
.filter((featureKey) => this._features[featureKey] && /^sfu/.test(featureKey))
|
|
5170
|
-
.reduce((prev, current) => (Object.assign(Object.assign({}, prev), { [current]: this._features[current] })), {})));
|
|
5171
|
-
const queryString = searchParams.toString();
|
|
5172
|
-
const wsUrl = `wss://${host}?${queryString}`;
|
|
5173
|
-
this._vegaConnection = new VegaConnection(wsUrl);
|
|
5174
|
-
this._hasVegaConnection = true;
|
|
5175
|
-
this._vegaConnection.on("open", () => this._join());
|
|
5176
|
-
this._vegaConnection.on("close", () => this._onClose());
|
|
5177
|
-
this._vegaConnection.on("message", (message) => this._onMessage(message));
|
|
5178
|
-
}
|
|
5179
|
-
_connect_v2() {
|
|
5180
5151
|
if (this._features.sfuReconnectV2On) {
|
|
5181
5152
|
if (this._isConnectingOrConnected)
|
|
5182
5153
|
return;
|
|
@@ -5229,7 +5200,6 @@ class VegaRtcManager {
|
|
|
5229
5200
|
_onClose() {
|
|
5230
5201
|
var _a, _b;
|
|
5231
5202
|
logger$3.info("_onClose()");
|
|
5232
|
-
this._hasVegaConnection = false;
|
|
5233
5203
|
(_a = this._sendTransport) === null || _a === void 0 ? void 0 : _a.close();
|
|
5234
5204
|
(_b = this._receiveTransport) === null || _b === void 0 ? void 0 : _b.close();
|
|
5235
5205
|
this._sendTransport = null;
|