@rongcloud/plugin-rtc 5.3.0-rtc-roompk.1 → 5.3.2-alpha.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/dist/index.d.ts +130 -52
- package/dist/index.esm.js +357 -157
- package/dist/index.js +357 -157
- package/dist/index.umd.js +357 -157
- package/package.json +3 -3
package/dist/index.umd.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* RCRTC - v5.3.
|
|
3
|
-
* CommitId -
|
|
4
|
-
*
|
|
2
|
+
* RCRTC - v5.3.2-alpha.1
|
|
3
|
+
* CommitId - db999e233480c8537357ef17495b0bbb67c692fe
|
|
4
|
+
* Mon Feb 14 2022 20:24:02 GMT+0800 (China Standard Time)
|
|
5
5
|
* ©2020 RongCloud, Inc. All rights reserved.
|
|
6
6
|
*/
|
|
7
7
|
(function (global, factory) {
|
|
@@ -6432,12 +6432,21 @@
|
|
|
6432
6432
|
/**
|
|
6433
6433
|
* 解析房间数据
|
|
6434
6434
|
*/
|
|
6435
|
-
const parseRoomData = (data) => {
|
|
6435
|
+
const parseRoomData = (data, mainRoomId) => {
|
|
6436
6436
|
const result = {};
|
|
6437
6437
|
const userIds = Object.keys(data.users);
|
|
6438
6438
|
userIds.length && userIds.forEach(userId => {
|
|
6439
6439
|
const tmp = [];
|
|
6440
6440
|
const userData = data.users[userId];
|
|
6441
|
+
/**
|
|
6442
|
+
* 过滤掉副房间身份的人员
|
|
6443
|
+
*/
|
|
6444
|
+
if (userData.extra) {
|
|
6445
|
+
const roomId = JSON.parse(userData.extra).roomId;
|
|
6446
|
+
if (mainRoomId !== roomId) {
|
|
6447
|
+
return;
|
|
6448
|
+
}
|
|
6449
|
+
}
|
|
6441
6450
|
if (userData.uris) {
|
|
6442
6451
|
try {
|
|
6443
6452
|
tmp.push(...JSON.parse(userData.uris));
|
|
@@ -6450,16 +6459,31 @@
|
|
|
6450
6459
|
});
|
|
6451
6460
|
return result;
|
|
6452
6461
|
};
|
|
6462
|
+
/**
|
|
6463
|
+
* 从加房间返回的数据中获取加入的副房间
|
|
6464
|
+
*/
|
|
6465
|
+
const getPKInfoByRoomData = (mainRoomId, roomInfo) => {
|
|
6466
|
+
const pkInfo = {};
|
|
6467
|
+
roomInfo.forEach((item) => {
|
|
6468
|
+
const PKValue = JSON.parse(item.value);
|
|
6469
|
+
const { inviterRoomId, inviteeRoomId } = PKValue;
|
|
6470
|
+
const roomId = (mainRoomId === inviterRoomId) ? inviteeRoomId : inviterRoomId;
|
|
6471
|
+
pkInfo[roomId] = JSON.parse(item.value);
|
|
6472
|
+
});
|
|
6473
|
+
return pkInfo;
|
|
6474
|
+
};
|
|
6453
6475
|
/**
|
|
6454
6476
|
* 解析观众加房间 kv 数据
|
|
6455
6477
|
* 远端无人员时,kvEntries 的 key 不包含 RC_ANCHOR_LIST
|
|
6456
6478
|
* 远端无资源时,key 不包含 RC_RES_、RC_CDN
|
|
6457
6479
|
* 远端有资源、无 CDN 资源时,key 不包含 RC_CDN
|
|
6480
|
+
* 服务端 bug,偶现无 RC_RTC_SESSIONID
|
|
6458
6481
|
*/
|
|
6459
6482
|
const parseAudienceRoomData = (roomId, kvEntries) => {
|
|
6460
|
-
const
|
|
6483
|
+
const session = kvEntries.filter((kvItem) => {
|
|
6461
6484
|
return kvItem.key === 'RC_RTC_SESSIONID';
|
|
6462
|
-
})[0]
|
|
6485
|
+
})[0];
|
|
6486
|
+
const sessionId = session ? session.value : '';
|
|
6463
6487
|
/**
|
|
6464
6488
|
* 房间内远端人员
|
|
6465
6489
|
*/
|
|
@@ -8462,7 +8486,7 @@
|
|
|
8462
8486
|
* 加入房间
|
|
8463
8487
|
*/
|
|
8464
8488
|
sendR1() {
|
|
8465
|
-
const rtcVersion = "5.3.
|
|
8489
|
+
const rtcVersion = "5.3.2-alpha.1";
|
|
8466
8490
|
const imVersion = this._context.getCoreVersion();
|
|
8467
8491
|
const platform = 'web';
|
|
8468
8492
|
const pcName = navigator.platform;
|
|
@@ -8610,6 +8634,9 @@
|
|
|
8610
8634
|
// 资源、人员变更消息需按队列逐个处理,确保内存状态不乱
|
|
8611
8635
|
this.msgTaskQueue = new AsyncTaskQueue();
|
|
8612
8636
|
this._appListener = null;
|
|
8637
|
+
/**
|
|
8638
|
+
* 存储连麦监听事件
|
|
8639
|
+
*/
|
|
8613
8640
|
this._onRecvPKMsg = null;
|
|
8614
8641
|
this._token = data.token;
|
|
8615
8642
|
this._sessionId = data.sessionId;
|
|
@@ -8622,7 +8649,7 @@
|
|
|
8622
8649
|
this._roomResources = {};
|
|
8623
8650
|
}
|
|
8624
8651
|
else {
|
|
8625
|
-
this._roomResources = parseRoomData(data);
|
|
8652
|
+
this._roomResources = parseRoomData(data, this._roomId);
|
|
8626
8653
|
}
|
|
8627
8654
|
// 根据解析出来的数据构建远端流
|
|
8628
8655
|
this._initRemoteTracks();
|
|
@@ -8833,7 +8860,8 @@
|
|
|
8833
8860
|
return;
|
|
8834
8861
|
}
|
|
8835
8862
|
const { uris, ignore } = content;
|
|
8836
|
-
|
|
8863
|
+
// 内置 CDN 为自动时,先收到 cdn_uris,无 uris 时,不用再对比资源
|
|
8864
|
+
if (ignore || !uris) {
|
|
8837
8865
|
return;
|
|
8838
8866
|
}
|
|
8839
8867
|
const publishedList = [];
|
|
@@ -8944,6 +8972,20 @@
|
|
|
8944
8972
|
if (users.length === 0) {
|
|
8945
8973
|
return;
|
|
8946
8974
|
}
|
|
8975
|
+
/**
|
|
8976
|
+
* 过滤掉副房间身份的人员
|
|
8977
|
+
*/
|
|
8978
|
+
for (let index = 0; index < users.length; index++) {
|
|
8979
|
+
const user = users[index];
|
|
8980
|
+
// 加入房间时
|
|
8981
|
+
if (user.extra && user.extra.roomId !== this._roomId) {
|
|
8982
|
+
return;
|
|
8983
|
+
}
|
|
8984
|
+
// 退出房间时
|
|
8985
|
+
if (+user.state === 1 && !this.getRemoteUserIds().includes(user.userId)) {
|
|
8986
|
+
return;
|
|
8987
|
+
}
|
|
8988
|
+
}
|
|
8947
8989
|
/**
|
|
8948
8990
|
* 主动加入房间
|
|
8949
8991
|
*/
|
|
@@ -9187,14 +9229,14 @@
|
|
|
9187
9229
|
if (quitRoom) {
|
|
9188
9230
|
// 退出 signal 房间
|
|
9189
9231
|
yield this._context.quitRTCRoom(this._roomId);
|
|
9190
|
-
// 退出主房间时,退出所有 PK 房间
|
|
9191
|
-
this._isMainRoom && this._quitPKRoom();
|
|
9192
9232
|
}
|
|
9233
|
+
// 退出主房间时,退出所有 PK 房间
|
|
9234
|
+
this._isMainRoom && this._quitAllPKRoom();
|
|
9193
9235
|
this._pc.removeAllLocalTrack();
|
|
9194
9236
|
// 停止 rtcPing 计时
|
|
9195
9237
|
this._pinger.stop();
|
|
9196
|
-
//
|
|
9197
|
-
yield this._service.exit(this._getRTCReqestHeaders());
|
|
9238
|
+
// 退出主房间时,中断与 MediaServer 的 UDP 连接
|
|
9239
|
+
this._isMainRoom && (yield this._service.exit(this._getRTCReqestHeaders()));
|
|
9198
9240
|
// 销毁 pc 连接
|
|
9199
9241
|
this._pc.destroy();
|
|
9200
9242
|
// 销毁 polarisReport 实例
|
|
@@ -9271,6 +9313,10 @@
|
|
|
9271
9313
|
}
|
|
9272
9314
|
__publish(tracks) {
|
|
9273
9315
|
return __awaiter(this, void 0, void 0, function* () {
|
|
9316
|
+
if (!this._isMainRoom && (this instanceof RCLivingRoom)) {
|
|
9317
|
+
logger.error('the `publish` is disabled in PK room ');
|
|
9318
|
+
return { code: exports.RCRTCCode.THE_FUNCTION_IS_DISABLED_IN_PKROOM };
|
|
9319
|
+
}
|
|
9274
9320
|
const roomStatusCode = this._assertRoomDestroyed();
|
|
9275
9321
|
if (roomStatusCode) {
|
|
9276
9322
|
logger.error(`publish failed, room has been destroyed. -> roomId: ${this._roomId}`);
|
|
@@ -9325,23 +9371,8 @@
|
|
|
9325
9371
|
/**
|
|
9326
9372
|
* 直播房间需携带 pushOtherRooms 信息
|
|
9327
9373
|
*/
|
|
9328
|
-
|
|
9329
|
-
|
|
9330
|
-
if (code === exports.RCRTCCode.SUCCESS && roomPKHandler) {
|
|
9331
|
-
const joinedPKRooms = roomPKHandler.getJoinedPKRooms();
|
|
9332
|
-
reqBody.pushOtherRooms = [];
|
|
9333
|
-
for (const roomId in joinedPKRooms) {
|
|
9334
|
-
const room = joinedPKRooms[roomId];
|
|
9335
|
-
const sessionId = room.getSessionId();
|
|
9336
|
-
const { inviterUserAutoMix: autoMix } = roomPKHandler.getPKInfo(roomId);
|
|
9337
|
-
reqBody.pushOtherRooms.push({
|
|
9338
|
-
roomId,
|
|
9339
|
-
sessionId,
|
|
9340
|
-
autoMix: autoMix
|
|
9341
|
-
});
|
|
9342
|
-
}
|
|
9343
|
-
}
|
|
9344
|
-
}
|
|
9374
|
+
const pushOtherRooms = this._getPushOtherRoomsParams();
|
|
9375
|
+
pushOtherRooms && (reqBody.pushOtherRooms = pushOtherRooms);
|
|
9345
9376
|
const resp = yield this._exchangeHandle(reqBody);
|
|
9346
9377
|
if (resp.code !== exports.RCRTCCode.SUCCESS) {
|
|
9347
9378
|
// TODO: 资源发送失败,需要移除已添加至 RTCPeerConnection 中的资源信息
|
|
@@ -9396,6 +9427,37 @@
|
|
|
9396
9427
|
return { code: exports.RCRTCCode.SUCCESS };
|
|
9397
9428
|
});
|
|
9398
9429
|
}
|
|
9430
|
+
/**
|
|
9431
|
+
* 获取跨房间连麦需携带参数 pushOtherRooms 的值
|
|
9432
|
+
*/
|
|
9433
|
+
_getPushOtherRoomsParams() {
|
|
9434
|
+
if (this instanceof RCLivingRoom) {
|
|
9435
|
+
const { code, roomPKHandler } = this.getRoomPKHandler();
|
|
9436
|
+
const pushOtherRooms = [];
|
|
9437
|
+
if (code === exports.RCRTCCode.SUCCESS && roomPKHandler) {
|
|
9438
|
+
const joinedPKRooms = roomPKHandler.getJoinedPKRooms();
|
|
9439
|
+
for (const roomId in joinedPKRooms) {
|
|
9440
|
+
const room = joinedPKRooms[roomId];
|
|
9441
|
+
const sessionId = room.getSessionId();
|
|
9442
|
+
/**
|
|
9443
|
+
* 直接加入 PK 房间,无连麦关系时,无 PKInfo 信息
|
|
9444
|
+
*/
|
|
9445
|
+
const PKInfo = roomPKHandler.getPKInfo(roomId);
|
|
9446
|
+
if (!PKInfo) {
|
|
9447
|
+
return;
|
|
9448
|
+
}
|
|
9449
|
+
const { inviterUserAutoMix, inviteeUserAutoMix, inviterUserId } = PKInfo;
|
|
9450
|
+
const isInviter = (this._context.getCurrentId() === inviterUserId);
|
|
9451
|
+
pushOtherRooms.push({
|
|
9452
|
+
roomId,
|
|
9453
|
+
sessionId,
|
|
9454
|
+
autoMix: isInviter ? !!inviterUserAutoMix : !!inviteeUserAutoMix
|
|
9455
|
+
});
|
|
9456
|
+
}
|
|
9457
|
+
}
|
|
9458
|
+
return pushOtherRooms;
|
|
9459
|
+
}
|
|
9460
|
+
}
|
|
9399
9461
|
/**
|
|
9400
9462
|
* ice 断线后,尝试重新走 exchange
|
|
9401
9463
|
*/
|
|
@@ -9403,6 +9465,11 @@
|
|
|
9403
9465
|
return __awaiter(this, void 0, void 0, function* () {
|
|
9404
9466
|
push(() => __awaiter(this, void 0, void 0, function* () {
|
|
9405
9467
|
const reqBody = yield this._createExchangeParams(this._subscribedList, true);
|
|
9468
|
+
/**
|
|
9469
|
+
* 直播房间需携带 pushOtherRooms 信息
|
|
9470
|
+
*/
|
|
9471
|
+
const pushOtherRooms = this._getPushOtherRoomsParams();
|
|
9472
|
+
pushOtherRooms && (reqBody.pushOtherRooms = pushOtherRooms);
|
|
9406
9473
|
// 发送 /exchange 请求
|
|
9407
9474
|
const resp = yield this._exchangeHandle(reqBody);
|
|
9408
9475
|
if (resp.code !== exports.RCRTCCode.SUCCESS) {
|
|
@@ -9487,6 +9554,10 @@
|
|
|
9487
9554
|
__unpublish(tracks) {
|
|
9488
9555
|
var _a;
|
|
9489
9556
|
return __awaiter(this, void 0, void 0, function* () {
|
|
9557
|
+
if (!this._isMainRoom && (this instanceof RCLivingRoom)) {
|
|
9558
|
+
logger.error('the `unpublish` is disabled in PK room ');
|
|
9559
|
+
return { code: exports.RCRTCCode.THE_FUNCTION_IS_DISABLED_IN_PKROOM };
|
|
9560
|
+
}
|
|
9490
9561
|
const roomStatusCode = this._assertRoomDestroyed();
|
|
9491
9562
|
if (roomStatusCode) {
|
|
9492
9563
|
logger.warn(`room has been destroyed, no need to unpublish tracks -> roomId: ${this._roomId}`);
|
|
@@ -9517,6 +9588,11 @@
|
|
|
9517
9588
|
// 客户端主动调用 api 发请求时,清除 ice 断线重连的定时器
|
|
9518
9589
|
this._pc.clearReTryExchangeTimer();
|
|
9519
9590
|
const reqBody = yield this._createExchangeParams(this._subscribedList, false);
|
|
9591
|
+
/**
|
|
9592
|
+
* 直播房间需携带 pushOtherRooms 信息
|
|
9593
|
+
*/
|
|
9594
|
+
const pushOtherRooms = this._getPushOtherRoomsParams();
|
|
9595
|
+
pushOtherRooms && (reqBody.pushOtherRooms = pushOtherRooms);
|
|
9520
9596
|
const result = yield this._exchangeHandle(reqBody);
|
|
9521
9597
|
if (result.code !== exports.RCRTCCode.SUCCESS) {
|
|
9522
9598
|
logger.error(`exchange failed -> code: ${result.code}`);
|
|
@@ -9750,6 +9826,11 @@
|
|
|
9750
9826
|
this._pc.clearReTryExchangeTimer();
|
|
9751
9827
|
this._pc.updateSubRemoteTracks(attrs.map(item => item.track));
|
|
9752
9828
|
const reqBody = yield this._createExchangeParams(attrs, false);
|
|
9829
|
+
/**
|
|
9830
|
+
* 直播房间需携带 pushOtherRooms 信息
|
|
9831
|
+
*/
|
|
9832
|
+
const pushOtherRooms = this._getPushOtherRoomsParams();
|
|
9833
|
+
pushOtherRooms && (reqBody.pushOtherRooms = pushOtherRooms);
|
|
9753
9834
|
const result = yield this._exchangeHandle(reqBody);
|
|
9754
9835
|
const subTrackIds = attrs.map((item) => { return item.track.getTrackId(); });
|
|
9755
9836
|
if (result.code !== exports.RCRTCCode.SUCCESS) {
|
|
@@ -9835,7 +9916,7 @@
|
|
|
9835
9916
|
// 状态变更的资源
|
|
9836
9917
|
const modified = {};
|
|
9837
9918
|
// 当前最新的房间资源数据
|
|
9838
|
-
const roomData = parseRoomData(data);
|
|
9919
|
+
const roomData = parseRoomData(data, this._roomId);
|
|
9839
9920
|
const nowUserIds = Object.keys(roomData);
|
|
9840
9921
|
const prevUserIds = Object.keys(this._roomResources);
|
|
9841
9922
|
for (let i = nowUserIds.length - 1; i >= 0; i -= 1) {
|
|
@@ -9940,7 +10021,7 @@
|
|
|
9940
10021
|
/**
|
|
9941
10022
|
* 退出 PK 房间
|
|
9942
10023
|
*/
|
|
9943
|
-
|
|
10024
|
+
_quitAllPKRoom() { }
|
|
9944
10025
|
}
|
|
9945
10026
|
|
|
9946
10027
|
/**
|
|
@@ -10496,7 +10577,7 @@
|
|
|
10496
10577
|
};
|
|
10497
10578
|
|
|
10498
10579
|
class RCLivingPKHandler {
|
|
10499
|
-
constructor(_context, _runtime, _service, _initOptions,
|
|
10580
|
+
constructor(_PKInfo, _context, _runtime, _service, _initOptions,
|
|
10500
10581
|
/**
|
|
10501
10582
|
* 主直播房间
|
|
10502
10583
|
*/
|
|
@@ -10509,6 +10590,7 @@
|
|
|
10509
10590
|
* 退出 PK 房间回调
|
|
10510
10591
|
*/
|
|
10511
10592
|
_onLeavePKRoom) {
|
|
10593
|
+
this._PKInfo = _PKInfo;
|
|
10512
10594
|
this._context = _context;
|
|
10513
10595
|
this._runtime = _runtime;
|
|
10514
10596
|
this._service = _service;
|
|
@@ -10518,13 +10600,13 @@
|
|
|
10518
10600
|
this._onJoinedPKRoom = _onJoinedPKRoom;
|
|
10519
10601
|
this._onLeavePKRoom = _onLeavePKRoom;
|
|
10520
10602
|
/**
|
|
10521
|
-
* PK
|
|
10603
|
+
* PK 邀请超时时间,默认 30s
|
|
10522
10604
|
*/
|
|
10523
|
-
this._inviteTimeout = 30
|
|
10605
|
+
this._inviteTimeout = 30;
|
|
10524
10606
|
/**
|
|
10525
10607
|
* PK 房间信息
|
|
10526
10608
|
*/
|
|
10527
|
-
|
|
10609
|
+
// private _PKInfo: IPKInfo = {}
|
|
10528
10610
|
this._appListener = null;
|
|
10529
10611
|
/**
|
|
10530
10612
|
* 跨房间连麦加入的 PK 房间
|
|
@@ -10546,6 +10628,9 @@
|
|
|
10546
10628
|
logger.error(error);
|
|
10547
10629
|
}
|
|
10548
10630
|
}
|
|
10631
|
+
/**
|
|
10632
|
+
* 收到连麦邀请
|
|
10633
|
+
*/
|
|
10549
10634
|
_onInvite(content) {
|
|
10550
10635
|
const inviteInfo = (content.inviteInfo || {});
|
|
10551
10636
|
const { inviterRoomId, inviterUserId, extra } = inviteInfo;
|
|
@@ -10557,6 +10642,9 @@
|
|
|
10557
10642
|
this._PKInfo[inviterRoomId] = inviteInfo;
|
|
10558
10643
|
this._callAppListener('onRequestJoinOtherRoom', info);
|
|
10559
10644
|
}
|
|
10645
|
+
/**
|
|
10646
|
+
* 收到取消连麦
|
|
10647
|
+
*/
|
|
10560
10648
|
_onCancelInvite(content) {
|
|
10561
10649
|
const { inviterRoomId, inviterUserId, extra } = (content.inviteInfo || {});
|
|
10562
10650
|
const cancelInfo = {
|
|
@@ -10570,9 +10658,12 @@
|
|
|
10570
10658
|
_onInviteTimeout(content) {
|
|
10571
10659
|
// 因服务计时不准,暂不处理。(与移动端一致)
|
|
10572
10660
|
}
|
|
10661
|
+
/**
|
|
10662
|
+
* 收到响应连麦
|
|
10663
|
+
*/
|
|
10573
10664
|
_onInviteAnswer(content) {
|
|
10574
|
-
const { answerCode,
|
|
10575
|
-
const { inviterUserId, inviterRoomId, inviteeUserId, inviteeRoomId, extra } = inviteContent;
|
|
10665
|
+
const { answerCode, inviteContent } = content;
|
|
10666
|
+
const { inviteSessionId, inviterUserId, inviterRoomId, inviteeUserId, inviterUserAutoMix, inviteeUserAutoMix, inviteeRoomId, extra } = inviteContent;
|
|
10576
10667
|
const answerInfo = {
|
|
10577
10668
|
agree: answerCode === 1,
|
|
10578
10669
|
inviterRoomId,
|
|
@@ -10580,19 +10671,35 @@
|
|
|
10580
10671
|
inviteeRoomId,
|
|
10581
10672
|
inviteeUserId
|
|
10582
10673
|
};
|
|
10674
|
+
/**
|
|
10675
|
+
* 收到非本人发起的邀请连麦时,需新组装 PKInfo
|
|
10676
|
+
*/
|
|
10677
|
+
this._PKInfo[inviteeRoomId] = this._PKInfo[inviteeRoomId] || {
|
|
10678
|
+
inviteSessionId,
|
|
10679
|
+
inviterRoomId,
|
|
10680
|
+
inviterUserId,
|
|
10681
|
+
inviterUserAutoMix,
|
|
10682
|
+
inviteeRoomId
|
|
10683
|
+
};
|
|
10583
10684
|
this._PKInfo[inviteeRoomId].inviteeUserAutoMix = inviteeUserAutoMix;
|
|
10584
10685
|
this._callAppListener('onResponseJoinOtherRoom', answerInfo);
|
|
10585
10686
|
}
|
|
10687
|
+
/**
|
|
10688
|
+
* 收到连麦结束
|
|
10689
|
+
*/
|
|
10586
10690
|
_onPKEnd(content) {
|
|
10587
|
-
|
|
10588
|
-
|
|
10589
|
-
|
|
10590
|
-
|
|
10591
|
-
|
|
10592
|
-
|
|
10593
|
-
|
|
10594
|
-
|
|
10595
|
-
|
|
10691
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
10692
|
+
const { inviteeRoomId, inviterRoomId, userId } = content.inviteInfo;
|
|
10693
|
+
const roomId = inviterRoomId === this._mainRoomId ? inviteeRoomId : inviterRoomId;
|
|
10694
|
+
const endInfo = {
|
|
10695
|
+
endRoomId: roomId,
|
|
10696
|
+
endUserId: userId
|
|
10697
|
+
};
|
|
10698
|
+
// 兼容先退出房间,再收到 pk 结束的情况
|
|
10699
|
+
this._joinedPKRooms[roomId] && (yield this.leaveOtherRoom(this._joinedPKRooms[roomId]));
|
|
10700
|
+
delete this._PKInfo[roomId];
|
|
10701
|
+
this._callAppListener('onFinishOtherRoom', endInfo);
|
|
10702
|
+
});
|
|
10596
10703
|
}
|
|
10597
10704
|
/**
|
|
10598
10705
|
* 处理跨房间连麦相关消息
|
|
@@ -10618,17 +10725,17 @@
|
|
|
10618
10725
|
}
|
|
10619
10726
|
}
|
|
10620
10727
|
/**
|
|
10621
|
-
*
|
|
10728
|
+
* 注册跨房间连麦监听事件
|
|
10622
10729
|
*/
|
|
10623
10730
|
registerRoomPKEventListener(listener) {
|
|
10624
10731
|
this._appListener = listener;
|
|
10625
10732
|
}
|
|
10626
10733
|
/**
|
|
10627
10734
|
* 发起跨房间连麦请求
|
|
10628
|
-
* @param inviteeRoomId 被邀请者所处的房间
|
|
10629
|
-
* @param inviteeUserId 被邀请者
|
|
10630
|
-
* @param options.autoMix
|
|
10631
|
-
* @param options.extra
|
|
10735
|
+
* @param inviteeRoomId 被邀请者所处的房间 roomId
|
|
10736
|
+
* @param inviteeUserId 被邀请者 userId
|
|
10737
|
+
* @param options.autoMix 是否要把邀请者发布的资源,合并到被邀请者房间内的 MCU 流中
|
|
10738
|
+
* @param options.extra 拓展字段,可随邀请连麦消息透传给被邀请者
|
|
10632
10739
|
*/
|
|
10633
10740
|
requestJoinOtherRoom(inviteeRoomId, inviteeUserId, options) {
|
|
10634
10741
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -10639,13 +10746,6 @@
|
|
|
10639
10746
|
logger.debug(`requestRoomPK -> inviteeRoomId: ${inviteeRoomId}; inviteeUserId: ${inviteeUserId}; options: ${JSON.stringify(options || {})}`);
|
|
10640
10747
|
const inviteSessionId = getUUID();
|
|
10641
10748
|
const autoMix = engine.isBoolean(options === null || options === void 0 ? void 0 : options.autoMix) ? options === null || options === void 0 ? void 0 : options.autoMix : true;
|
|
10642
|
-
this._PKInfo[inviteeRoomId] = {
|
|
10643
|
-
inviteSessionId,
|
|
10644
|
-
inviterRoomId: this._mainRoomId,
|
|
10645
|
-
inviterUserId: this._context.getCurrentId(),
|
|
10646
|
-
inviterUserAutoMix: autoMix,
|
|
10647
|
-
inviteeRoomId
|
|
10648
|
-
};
|
|
10649
10749
|
const inviteInfo = {
|
|
10650
10750
|
inviteSessionId,
|
|
10651
10751
|
inviterRoomId: this._mainRoomId,
|
|
@@ -10668,13 +10768,24 @@
|
|
|
10668
10768
|
const code = yield this._context.requestRoomPK(params);
|
|
10669
10769
|
if (code !== engine.ErrorCode.SUCCESS) {
|
|
10670
10770
|
logger.error(`requestRoomPK failed: ${code}`);
|
|
10671
|
-
return { code
|
|
10771
|
+
return { code };
|
|
10672
10772
|
}
|
|
10773
|
+
logger.debug('requestRoomPK success');
|
|
10774
|
+
this._PKInfo[inviteeRoomId] = {
|
|
10775
|
+
inviteSessionId,
|
|
10776
|
+
inviterRoomId: this._mainRoomId,
|
|
10777
|
+
inviterUserId: this._context.getCurrentId(),
|
|
10778
|
+
inviterUserAutoMix: autoMix,
|
|
10779
|
+
inviteeRoomId
|
|
10780
|
+
};
|
|
10673
10781
|
return { code: exports.RCRTCCode.SUCCESS };
|
|
10674
10782
|
});
|
|
10675
10783
|
}
|
|
10676
10784
|
/**
|
|
10677
|
-
*
|
|
10785
|
+
* 取消跨房间连麦请求
|
|
10786
|
+
* @param inviteeRoomId 被邀请者所处的房间 roomId
|
|
10787
|
+
* @param inviteeUserId 被邀请者 userId
|
|
10788
|
+
* @param extra 附加信息,可随取消邀请连麦消息透传给被邀请者
|
|
10678
10789
|
*/
|
|
10679
10790
|
cancelRequestJoinOtherRoom(inviteeRoomId, inviteeUserId, extra) {
|
|
10680
10791
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -10682,6 +10793,10 @@
|
|
|
10682
10793
|
engine.validate('inviteeUserId', inviteeUserId, engine.notEmptyString, true))) {
|
|
10683
10794
|
return { code: exports.RCRTCCode.PARAMS_ERROR };
|
|
10684
10795
|
}
|
|
10796
|
+
if (!this._PKInfo[inviteeRoomId]) {
|
|
10797
|
+
logger.error(`未发起过与 ${inviteeRoomId} 房间内 ${inviteeUserId} 连麦的请求`);
|
|
10798
|
+
return { code: exports.RCRTCCode.PARAMS_ERROR };
|
|
10799
|
+
}
|
|
10685
10800
|
logger.debug(`canceRequestJoinPK -> inviteeRoomId: ${inviteeRoomId}; inviteeUserId: ${inviteeUserId}; extra: ${extra}`);
|
|
10686
10801
|
const inviteInfo = {
|
|
10687
10802
|
inviterRoomId: this._mainRoomId,
|
|
@@ -10701,13 +10816,20 @@
|
|
|
10701
10816
|
const code = yield this._context.cancelRoomPK(params);
|
|
10702
10817
|
if (code !== engine.ErrorCode.SUCCESS) {
|
|
10703
10818
|
logger.error(`canceRequestJoinPK failed: ${code}`);
|
|
10704
|
-
return { code
|
|
10819
|
+
return { code };
|
|
10705
10820
|
}
|
|
10821
|
+
logger.debug('canceRequestJoinPK success');
|
|
10822
|
+
delete this._PKInfo[inviteeRoomId];
|
|
10706
10823
|
return { code: exports.RCRTCCode.SUCCESS };
|
|
10707
10824
|
});
|
|
10708
10825
|
}
|
|
10709
10826
|
/**
|
|
10710
|
-
*
|
|
10827
|
+
* 响应跨房间连麦请求
|
|
10828
|
+
* @param inviterRoomId 邀请者所处的房间 roomId
|
|
10829
|
+
* @param inviterUserId 邀请者 userId
|
|
10830
|
+
* @param agree 是否同意连麦
|
|
10831
|
+
* @param options.autoMix 是否要把被邀请者发布的资源,合并到邀请者房间内的 MCU 流中
|
|
10832
|
+
* @param options.extra 附加信息,可随响应连麦消息透传给邀请者
|
|
10711
10833
|
*/
|
|
10712
10834
|
responseJoinOtherRoom(inviterRoomId, inviterUserId, agree, options) {
|
|
10713
10835
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -10715,6 +10837,10 @@
|
|
|
10715
10837
|
engine.validate('inviterUserId', inviterUserId, engine.notEmptyString, true))) {
|
|
10716
10838
|
return { code: exports.RCRTCCode.PARAMS_ERROR };
|
|
10717
10839
|
}
|
|
10840
|
+
if (!this._PKInfo[inviterRoomId]) {
|
|
10841
|
+
logger.error(`${inviterRoomId} 房间内的 ${inviterUserId} 未发起过连麦请求`);
|
|
10842
|
+
return { code: exports.RCRTCCode.PARAMS_ERROR };
|
|
10843
|
+
}
|
|
10718
10844
|
logger.debug(`responseRoomPK -> inviterRoomId: ${inviterRoomId}; inviterUserId: ${inviterUserId}; agree: ${agree}; options: ${JSON.stringify(options || {})}`);
|
|
10719
10845
|
const { inviteSessionId, inviterUserAutoMix } = this._PKInfo[inviterRoomId];
|
|
10720
10846
|
const autoMix = engine.isBoolean(options === null || options === void 0 ? void 0 : options.autoMix) ? options === null || options === void 0 ? void 0 : options.autoMix : true;
|
|
@@ -10722,6 +10848,7 @@
|
|
|
10722
10848
|
inviteSessionId,
|
|
10723
10849
|
inviterRoomId,
|
|
10724
10850
|
inviterUserId,
|
|
10851
|
+
inviterUserAutoMix,
|
|
10725
10852
|
inviteeRoomId: this._mainRoomId,
|
|
10726
10853
|
inviteeUserId: this._context.getCurrentId(),
|
|
10727
10854
|
inviteeUserAutoMix: autoMix
|
|
@@ -10739,28 +10866,26 @@
|
|
|
10739
10866
|
inviteRoomId: inviterRoomId,
|
|
10740
10867
|
inviteUserId: inviterUserId,
|
|
10741
10868
|
content: JSON.stringify(content),
|
|
10742
|
-
key: `${inviterRoomId}|${
|
|
10869
|
+
key: `${inviterRoomId}|${this._mainRoomId}`,
|
|
10743
10870
|
value: JSON.stringify(value)
|
|
10744
10871
|
};
|
|
10745
10872
|
logger.debug(`responseRoomPK -> params: ${JSON.stringify(params)}`);
|
|
10746
10873
|
const code = yield this._context.responseRoomPK(params);
|
|
10747
10874
|
if (code !== engine.ErrorCode.SUCCESS) {
|
|
10748
10875
|
logger.error(`responseRoomPK failed: ${code}`);
|
|
10749
|
-
return { code
|
|
10876
|
+
return { code };
|
|
10750
10877
|
}
|
|
10878
|
+
logger.debug('responseRoomPK success');
|
|
10879
|
+
this._PKInfo[inviterRoomId].inviteeUserAutoMix = autoMix;
|
|
10751
10880
|
return { code: exports.RCRTCCode.SUCCESS };
|
|
10752
10881
|
});
|
|
10753
10882
|
}
|
|
10754
10883
|
/**
|
|
10755
|
-
* 结束跨房间连麦
|
|
10756
|
-
* @param roomId
|
|
10884
|
+
* 结束跨房间连麦
|
|
10885
|
+
* @param roomId 需要结束连麦的房间 roomId
|
|
10757
10886
|
*/
|
|
10758
10887
|
_quitRoomPK(roomId) {
|
|
10759
10888
|
return __awaiter(this, void 0, void 0, function* () {
|
|
10760
|
-
if (!(engine.validate('roomId', roomId, engine.notEmptyString, true))) {
|
|
10761
|
-
return { code: exports.RCRTCCode.PARAMS_ERROR };
|
|
10762
|
-
}
|
|
10763
|
-
logger.debug(`quitRoomPK -> roomId: ${roomId}`);
|
|
10764
10889
|
const { inviterRoomId, inviteeRoomId, inviterUserId } = this._PKInfo[roomId];
|
|
10765
10890
|
const content = {
|
|
10766
10891
|
inviteeRoomId,
|
|
@@ -10780,13 +10905,15 @@
|
|
|
10780
10905
|
logger.error(`quitRoomPK failed: ${code}`);
|
|
10781
10906
|
return { code: exports.RCRTCCode.SIGNAL_ERROR };
|
|
10782
10907
|
}
|
|
10908
|
+
logger.debug('quitRoomPK success');
|
|
10909
|
+
delete this._PKInfo[roomId];
|
|
10783
10910
|
return { code: exports.RCRTCCode.SUCCESS };
|
|
10784
10911
|
});
|
|
10785
10912
|
}
|
|
10786
10913
|
_relaseCrtRoom() { }
|
|
10787
10914
|
/**
|
|
10788
|
-
*
|
|
10789
|
-
* @roomId
|
|
10915
|
+
* 加入副直播房间
|
|
10916
|
+
* @roomId 副房间的 roomId
|
|
10790
10917
|
*/
|
|
10791
10918
|
joinOtherRoom(roomId) {
|
|
10792
10919
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -10796,11 +10923,19 @@
|
|
|
10796
10923
|
if (this._context.getConnectionStatus() !== engine.ConnectionStatus.CONNECTED) {
|
|
10797
10924
|
return { code: exports.RCRTCCode.SIGNAL_DISCONNECTED };
|
|
10798
10925
|
}
|
|
10799
|
-
logger.debug(`
|
|
10926
|
+
logger.debug(`JoinPKRoom, roomId: ${roomId}`);
|
|
10927
|
+
if (this._joinedPKRooms[roomId]) {
|
|
10928
|
+
return { code: exports.RCRTCCode.REPERT_JOIN_ROOM };
|
|
10929
|
+
}
|
|
10800
10930
|
const livingType = exports.RCLivingType.VIDEO; // signal 不处理 livingType 故写死 RCLivingType.VIDEO
|
|
10801
|
-
|
|
10931
|
+
// 加入副房间时,携带主房间 Id,用于在房间内区分人员身份
|
|
10932
|
+
const extraUserData = {
|
|
10933
|
+
key: 'extra',
|
|
10934
|
+
value: `{"roomId": "${this._mainRoomId}"}`
|
|
10935
|
+
};
|
|
10936
|
+
const { code, data } = yield this._context.joinRTCRoom(roomId, engine.RTCMode.LIVE, livingType, undefined, extraUserData);
|
|
10802
10937
|
if (code !== engine.ErrorCode.SUCCESS) {
|
|
10803
|
-
logger.error(`
|
|
10938
|
+
logger.error(`JoinPKRoom failed -> code: ${code}`);
|
|
10804
10939
|
return { code: code };
|
|
10805
10940
|
}
|
|
10806
10941
|
logger.debug(`JoinPKRoom success -> userId: ${this._context.getCurrentId()}, roomId: ${roomId}, data: ${JSON.stringify(data)}`);
|
|
@@ -10808,45 +10943,47 @@
|
|
|
10808
10943
|
// 回调主直播房间,已加入 PK 房间
|
|
10809
10944
|
this._joinedPKRooms[roomId] = room;
|
|
10810
10945
|
this._onJoinedPKRoom(roomId, room);
|
|
10811
|
-
|
|
10812
|
-
// 手动模式时,用户加入房间,需返回 CDN 开关状态
|
|
10813
|
-
if (room.__getCDNPushMode() === RCInnerCDNPushMode.MANUAL) {
|
|
10814
|
-
Object.assign(joinLivingResData, { CDNEnable: room.__getCDNEnable() });
|
|
10815
|
-
}
|
|
10816
|
-
return joinLivingResData;
|
|
10946
|
+
return { room, code: exports.RCRTCCode.SUCCESS, userIds: room.getRemoteUserIds(), tracks: room.getRemoteTracks() };
|
|
10817
10947
|
});
|
|
10818
10948
|
}
|
|
10819
10949
|
/**
|
|
10820
|
-
*
|
|
10821
|
-
* @param room
|
|
10950
|
+
* 退出副房间
|
|
10951
|
+
* @param room 要退出的副房间的 room 实例
|
|
10952
|
+
* @param isQuitPK 是否要结束连麦
|
|
10822
10953
|
*/
|
|
10823
10954
|
leaveOtherRoom(room, isQuitPK) {
|
|
10824
10955
|
return __awaiter(this, void 0, void 0, function* () {
|
|
10825
10956
|
return push(() => __awaiter(this, void 0, void 0, function* () {
|
|
10826
10957
|
const roomId = room.getRoomId();
|
|
10958
|
+
logger.debug(`leavePKRoom -> userId: ${this._context.getCurrentId()} , roomId: ${roomId}`);
|
|
10959
|
+
yield room.__destroy(true);
|
|
10960
|
+
// 回调主直播房间离开 PK 房间
|
|
10961
|
+
delete this._joinedPKRooms[roomId];
|
|
10962
|
+
this._onLeavePKRoom(roomId);
|
|
10827
10963
|
if (!this._PKInfo[roomId]) {
|
|
10828
10964
|
return { code: exports.RCRTCCode.SUCCESS };
|
|
10829
10965
|
}
|
|
10830
10966
|
// isQuitPK 为 true 时,结束连麦
|
|
10831
10967
|
isQuitPK && this._quitRoomPK(roomId);
|
|
10832
|
-
yield room.__destroy(true);
|
|
10833
|
-
logger.debug(`leavePKRoom -> userId: ${this._context.getCurrentId()} , roomId: ${roomId}`);
|
|
10834
|
-
// 回调主直播房间离开 PK 房间
|
|
10835
|
-
delete this._joinedPKRooms[roomId];
|
|
10836
|
-
this._onLeavePKRoom(roomId);
|
|
10837
|
-
delete this._PKInfo[roomId];
|
|
10838
10968
|
return { code: exports.RCRTCCode.SUCCESS };
|
|
10839
10969
|
}));
|
|
10840
10970
|
});
|
|
10841
10971
|
}
|
|
10842
10972
|
/**
|
|
10843
|
-
*
|
|
10973
|
+
* 获取连麦信息
|
|
10974
|
+
* @param roomId 连麦房间的 roomId
|
|
10844
10975
|
*/
|
|
10845
10976
|
getPKInfo(roomId) {
|
|
10846
10977
|
return this._PKInfo[roomId];
|
|
10847
10978
|
}
|
|
10848
10979
|
/**
|
|
10849
|
-
*
|
|
10980
|
+
* 获取所有连麦信息
|
|
10981
|
+
*/
|
|
10982
|
+
getAllPKInfo() {
|
|
10983
|
+
return this._PKInfo;
|
|
10984
|
+
}
|
|
10985
|
+
/**
|
|
10986
|
+
* 获取已加入的副房间
|
|
10850
10987
|
*/
|
|
10851
10988
|
getJoinedPKRooms() {
|
|
10852
10989
|
return this._joinedPKRooms;
|
|
@@ -10875,11 +11012,43 @@
|
|
|
10875
11012
|
this._mcuConfigBuilder = new RCMCUConfigBuilder(this._onMCUConfigFlush.bind(this), this._isValidResourceId.bind(this), this._sendCDNInfoSignal.bind(this));
|
|
10876
11013
|
// 初始化 RCLivingPKHandler
|
|
10877
11014
|
if (this._isMainRoom) {
|
|
10878
|
-
|
|
11015
|
+
const PKInfo = getPKInfoByRoomData(this._roomId, data.roomInfo);
|
|
11016
|
+
this._roomPKHandler = new RCLivingPKHandler(PKInfo, context, runtime, service, initOptions, this, super._registerPKMsgListener.bind(this), this._onJoinedPKRoom.bind(this), this._onLeavePKRoom.bind(this));
|
|
10879
11017
|
}
|
|
10880
11018
|
const CDNUris = (_a = data.roomInfo.filter((item) => { return item.key === 'cdn_uris'; })[0]) === null || _a === void 0 ? void 0 : _a.value;
|
|
10881
11019
|
CDNUris && (this._CDNUris = JSON.parse(CDNUris)[0]);
|
|
10882
11020
|
}
|
|
11021
|
+
/**
|
|
11022
|
+
* resourceId 有效性验证
|
|
11023
|
+
* @param resourceId
|
|
11024
|
+
*/
|
|
11025
|
+
_isValidResourceId(resourceId) {
|
|
11026
|
+
var _a;
|
|
11027
|
+
const { userId } = parseTrackId(resourceId);
|
|
11028
|
+
// 是否是主房间资源
|
|
11029
|
+
const isHostRoomResource = !!((_a = this._roomResources[userId]) === null || _a === void 0 ? void 0 : _a.find(item => getTrackId(item) === resourceId));
|
|
11030
|
+
// 是否是主房间资源
|
|
11031
|
+
let isPKRoomResource = false;
|
|
11032
|
+
/**
|
|
11033
|
+
* 无副房间时,只验证是否为主房间资源
|
|
11034
|
+
*/
|
|
11035
|
+
const { code, roomPKHandler } = this.getRoomPKHandler();
|
|
11036
|
+
if (code !== exports.RCRTCCode.SUCCESS || !roomPKHandler) {
|
|
11037
|
+
return isHostRoomResource;
|
|
11038
|
+
}
|
|
11039
|
+
/**
|
|
11040
|
+
* 有副房间时,需验证是否为主房间或副房间资源
|
|
11041
|
+
*/
|
|
11042
|
+
const joinedPKRooms = roomPKHandler.getJoinedPKRooms();
|
|
11043
|
+
const PKRoomRemoteTracks = [];
|
|
11044
|
+
Object.values(joinedPKRooms).map((room) => {
|
|
11045
|
+
PKRoomRemoteTracks.push(...room.getRemoteTracks());
|
|
11046
|
+
});
|
|
11047
|
+
isPKRoomResource = PKRoomRemoteTracks.some((track) => {
|
|
11048
|
+
return resourceId === track.getTrackId();
|
|
11049
|
+
});
|
|
11050
|
+
return isHostRoomResource || isPKRoomResource;
|
|
11051
|
+
}
|
|
10883
11052
|
getLivingType() {
|
|
10884
11053
|
return this._livingType;
|
|
10885
11054
|
}
|
|
@@ -10887,6 +11056,10 @@
|
|
|
10887
11056
|
* 获取 MCU 配置构建对象
|
|
10888
11057
|
*/
|
|
10889
11058
|
getMCUConfigBuilder() {
|
|
11059
|
+
if (!this._isMainRoom) {
|
|
11060
|
+
logger.error('the `getMCUConfigBuilder` is disabled in PK room ');
|
|
11061
|
+
return { code: exports.RCRTCCode.THE_FUNCTION_IS_DISABLED_IN_PKROOM };
|
|
11062
|
+
}
|
|
10890
11063
|
return this._mcuConfigBuilder;
|
|
10891
11064
|
}
|
|
10892
11065
|
/**
|
|
@@ -10943,6 +11116,10 @@
|
|
|
10943
11116
|
*/
|
|
10944
11117
|
enableInnerCDN(enable) {
|
|
10945
11118
|
return __awaiter(this, void 0, void 0, function* () {
|
|
11119
|
+
if (!this._isMainRoom) {
|
|
11120
|
+
logger.error('the `enableInnerCDN` is disabled in PK room ');
|
|
11121
|
+
return { code: exports.RCRTCCode.THE_FUNCTION_IS_DISABLED_IN_PKROOM };
|
|
11122
|
+
}
|
|
10946
11123
|
if (!engine.isBoolean(enable)) {
|
|
10947
11124
|
logger.error('`enable` is invalid');
|
|
10948
11125
|
return { code: exports.RCRTCCode.PARAMS_ERROR };
|
|
@@ -11066,7 +11243,7 @@
|
|
|
11066
11243
|
* 观众切换为主播后直接处理人员变更及资源变更
|
|
11067
11244
|
*/
|
|
11068
11245
|
_afterChangedRole(data) {
|
|
11069
|
-
const parseData = parseRoomData(data);
|
|
11246
|
+
const parseData = parseRoomData(data, this._roomId);
|
|
11070
11247
|
const currentUserId = this._context.getCurrentId();
|
|
11071
11248
|
const joinedAnchorList = Object.keys(parseData);
|
|
11072
11249
|
// 观众升级主播成功后返回房间实例,才可注册房间事件,需异步抛出
|
|
@@ -11116,33 +11293,46 @@
|
|
|
11116
11293
|
*/
|
|
11117
11294
|
_onJoinedPKRoom(roomId, room) {
|
|
11118
11295
|
/**
|
|
11119
|
-
*
|
|
11296
|
+
* 加入副房间之后,如果己方发布过资源,且参与连麦,
|
|
11120
11297
|
* 需携带 pushOtherRooms 与 mediaServer 重新交互
|
|
11121
11298
|
*/
|
|
11122
|
-
const
|
|
11123
|
-
if (
|
|
11124
|
-
|
|
11299
|
+
const { code, roomPKHandler } = this.getRoomPKHandler();
|
|
11300
|
+
if (code === exports.RCRTCCode.SUCCESS && roomPKHandler) {
|
|
11301
|
+
const PKInfo = roomPKHandler.getPKInfo(roomId);
|
|
11302
|
+
if (!PKInfo) {
|
|
11303
|
+
return;
|
|
11304
|
+
}
|
|
11305
|
+
this._exchangeWithPushOtherRoom();
|
|
11125
11306
|
}
|
|
11126
|
-
this._exchangeWithPushOtherRoom(roomId);
|
|
11127
11307
|
}
|
|
11308
|
+
/**
|
|
11309
|
+
* 离开 PK 房间后,如果参与过连麦,pushOtherRooms 需去掉退出的连麦房间配置,重新和 mediaServer 交互
|
|
11310
|
+
*/
|
|
11128
11311
|
_onLeavePKRoom(roomId) {
|
|
11312
|
+
const { code, roomPKHandler } = this.getRoomPKHandler();
|
|
11313
|
+
if (code === exports.RCRTCCode.SUCCESS && roomPKHandler) {
|
|
11314
|
+
const PKInfo = roomPKHandler.getPKInfo(roomId);
|
|
11315
|
+
if (!PKInfo) {
|
|
11316
|
+
return;
|
|
11317
|
+
}
|
|
11318
|
+
this._exchangeWithPushOtherRoom();
|
|
11319
|
+
}
|
|
11129
11320
|
}
|
|
11130
11321
|
/**
|
|
11131
11322
|
* 携带 pushOtherRooms 与 mediaServer 重新交互
|
|
11132
|
-
* @param roomId 副房间 roomId
|
|
11133
11323
|
*/
|
|
11134
|
-
_exchangeWithPushOtherRoom(
|
|
11324
|
+
_exchangeWithPushOtherRoom() {
|
|
11135
11325
|
return __awaiter(this, void 0, void 0, function* () {
|
|
11326
|
+
/**
|
|
11327
|
+
* 如果己方未发布过资源,无需发请求
|
|
11328
|
+
*/
|
|
11329
|
+
const pubTracks = this.getLocalTracks();
|
|
11330
|
+
if (!pubTracks.length) {
|
|
11331
|
+
return;
|
|
11332
|
+
}
|
|
11136
11333
|
const reqBody = yield this._createExchangeParams(this._subscribedList, false);
|
|
11137
|
-
const
|
|
11138
|
-
|
|
11139
|
-
const { inviterUserAutoMix: autoMix } = this._roomPKHandler.getPKInfo(roomId);
|
|
11140
|
-
const pushOtherRooms = {
|
|
11141
|
-
roomId,
|
|
11142
|
-
sessionId,
|
|
11143
|
-
autoMix: autoMix
|
|
11144
|
-
};
|
|
11145
|
-
reqBody.pushOtherRooms = [pushOtherRooms];
|
|
11334
|
+
const pushOtherRooms = this._getPushOtherRoomsParams();
|
|
11335
|
+
pushOtherRooms && (reqBody.pushOtherRooms = pushOtherRooms);
|
|
11146
11336
|
const resp = yield this._exchangeHandle(reqBody);
|
|
11147
11337
|
if (resp.code !== exports.RCRTCCode.SUCCESS) {
|
|
11148
11338
|
logger.error(`reTryExchange failed: ${resp.code}`);
|
|
@@ -11161,6 +11351,7 @@
|
|
|
11161
11351
|
}
|
|
11162
11352
|
/**
|
|
11163
11353
|
* 获取 PK 业务处理器
|
|
11354
|
+
* @since version 5.3.0
|
|
11164
11355
|
*/
|
|
11165
11356
|
getRoomPKHandler() {
|
|
11166
11357
|
if (!this._isMainRoom) {
|
|
@@ -11175,14 +11366,14 @@
|
|
|
11175
11366
|
};
|
|
11176
11367
|
}
|
|
11177
11368
|
/**
|
|
11178
|
-
*
|
|
11369
|
+
* 退出所有连麦房间
|
|
11179
11370
|
*/
|
|
11180
|
-
|
|
11371
|
+
_quitAllPKRoom() {
|
|
11181
11372
|
const PKRooms = this._roomPKHandler.getJoinedPKRooms();
|
|
11182
|
-
const
|
|
11183
|
-
|
|
11184
|
-
this.
|
|
11185
|
-
}
|
|
11373
|
+
for (const roomId in PKRooms) {
|
|
11374
|
+
const room = PKRooms[roomId];
|
|
11375
|
+
this._roomPKHandler.leaveOtherRoom(room);
|
|
11376
|
+
}
|
|
11186
11377
|
}
|
|
11187
11378
|
}
|
|
11188
11379
|
|
|
@@ -11199,7 +11390,7 @@
|
|
|
11199
11390
|
'Content-Type': 'application/json;charset=UTF-8',
|
|
11200
11391
|
'Cache-Control': 'no-cache',
|
|
11201
11392
|
ClientType: `web|${browserInfo.browser}|${browserInfo.version}`,
|
|
11202
|
-
ClientVersion: "5.3.
|
|
11393
|
+
ClientVersion: "5.3.2-alpha.1",
|
|
11203
11394
|
'Client-Session-Id': getUUID(),
|
|
11204
11395
|
'Request-Id': Date.now().toString()
|
|
11205
11396
|
});
|
|
@@ -12248,7 +12439,7 @@
|
|
|
12248
12439
|
/**
|
|
12249
12440
|
* CDN 资源减少: 上次 CDNUris 中有 url,变更后无 url
|
|
12250
12441
|
*/
|
|
12251
|
-
if (this._CDNUris.url && newCDNUris.url) {
|
|
12442
|
+
if (this._CDNUris.url && !newCDNUris.url) {
|
|
12252
12443
|
this._callAppListener('onCDNInfoDisable');
|
|
12253
12444
|
/**
|
|
12254
12445
|
* 更新内存中存储的 cdn_uris 数据
|
|
@@ -12607,13 +12798,35 @@
|
|
|
12607
12798
|
if (message.conversationType !== engine.ConversationType.RTC_ROOM) {
|
|
12608
12799
|
return false;
|
|
12609
12800
|
}
|
|
12610
|
-
|
|
12611
|
-
|
|
12612
|
-
|
|
12613
|
-
|
|
12801
|
+
// 给连麦房间增加消息处理器
|
|
12802
|
+
if (this._crtRoom instanceof RCLivingRoom) {
|
|
12803
|
+
const PKRooms = this._getJoinedPKRoomList();
|
|
12804
|
+
PKRooms.forEach((room) => {
|
|
12805
|
+
room.__parseInnerMessage(message);
|
|
12806
|
+
});
|
|
12807
|
+
}
|
|
12614
12808
|
(_a = this._crtRoom) === null || _a === void 0 ? void 0 : _a.__parseInnerMessage(message);
|
|
12615
12809
|
return true;
|
|
12616
12810
|
}
|
|
12811
|
+
/**
|
|
12812
|
+
* 获取加入的连麦房间
|
|
12813
|
+
*/
|
|
12814
|
+
_getJoinedPKRoomList() {
|
|
12815
|
+
const { code, roomPKHandler } = this._crtRoom.getRoomPKHandler();
|
|
12816
|
+
if (code === exports.RCRTCCode.SUCCESS && roomPKHandler) {
|
|
12817
|
+
const PKRooms = roomPKHandler.getJoinedPKRooms() || {};
|
|
12818
|
+
return Object.values(PKRooms);
|
|
12819
|
+
}
|
|
12820
|
+
return [];
|
|
12821
|
+
}
|
|
12822
|
+
_getPKRoomIds() {
|
|
12823
|
+
const { code, roomPKHandler } = this._crtRoom.getRoomPKHandler();
|
|
12824
|
+
if (code === exports.RCRTCCode.SUCCESS && roomPKHandler) {
|
|
12825
|
+
const PKInfo = roomPKHandler.getAllPKInfo();
|
|
12826
|
+
return Object.keys(PKInfo);
|
|
12827
|
+
}
|
|
12828
|
+
return [];
|
|
12829
|
+
}
|
|
12617
12830
|
/**
|
|
12618
12831
|
* 获取当前用户 Id,若 IM 未连接,这返回 `''`
|
|
12619
12832
|
* @returns
|
|
@@ -12697,7 +12910,7 @@
|
|
|
12697
12910
|
logger.debug(`JoinRoom success -> userId: ${this._context.getCurrentId()}, roomId: ${roomId}, data: ${JSON.stringify(data)}`);
|
|
12698
12911
|
const room = new RCLivingRoom(this._context, this._runtime, roomId, data, this._service, this._options, this._releaseCrtRoomObj.bind(this), livingType, false, true);
|
|
12699
12912
|
this._crtRoom = room;
|
|
12700
|
-
const joinLivingResData = { room, code: exports.RCRTCCode.SUCCESS, userIds: room.getRemoteUserIds(), tracks: room.getRemoteTracks() };
|
|
12913
|
+
const joinLivingResData = { room, code: exports.RCRTCCode.SUCCESS, userIds: room.getRemoteUserIds(), tracks: room.getRemoteTracks(), PKRoomIds: this._getPKRoomIds() };
|
|
12701
12914
|
// 手动模式时,用户加入房间,需返回 CDN 开关状态
|
|
12702
12915
|
if (room.__getCDNPushMode() === RCInnerCDNPushMode.MANUAL) {
|
|
12703
12916
|
Object.assign(joinLivingResData, { CDNEnable: room.__getCDNEnable() });
|
|
@@ -12714,25 +12927,18 @@
|
|
|
12714
12927
|
}
|
|
12715
12928
|
return this._audience;
|
|
12716
12929
|
}
|
|
12717
|
-
_getJoinedPKRooms() {
|
|
12718
|
-
if (this._crtRoom instanceof RCLivingRoom) {
|
|
12719
|
-
const { code, roomPKHandler } = this._crtRoom.getRoomPKHandler();
|
|
12720
|
-
if (code === exports.RCRTCCode.SUCCESS && roomPKHandler) {
|
|
12721
|
-
const PKRooms = roomPKHandler.getJoinedPKRooms();
|
|
12722
|
-
return Object.values(PKRooms);
|
|
12723
|
-
}
|
|
12724
|
-
}
|
|
12725
|
-
return [];
|
|
12726
|
-
}
|
|
12727
12930
|
_onIMStatusChange(status) {
|
|
12728
12931
|
logger.debug(`signal server connection state change: ${status}`);
|
|
12729
12932
|
if (status !== engine.ConnectionStatus.CONNECTED) {
|
|
12730
12933
|
return;
|
|
12731
12934
|
}
|
|
12732
|
-
|
|
12733
|
-
|
|
12734
|
-
|
|
12735
|
-
|
|
12935
|
+
// 给连麦房间增加重连处理
|
|
12936
|
+
if (this._crtRoom instanceof RCLivingRoom) {
|
|
12937
|
+
const PKRooms = this._getJoinedPKRoomList();
|
|
12938
|
+
PKRooms.forEach((room) => {
|
|
12939
|
+
room.__onReconnected();
|
|
12940
|
+
});
|
|
12941
|
+
}
|
|
12736
12942
|
this._crtRoom && this._crtRoom.__onReconnected();
|
|
12737
12943
|
}
|
|
12738
12944
|
_onIMDisconnect() {
|
|
@@ -12887,7 +13093,7 @@
|
|
|
12887
13093
|
* @param tag 屏幕共享视轨数据标识
|
|
12888
13094
|
* @param options
|
|
12889
13095
|
* @description
|
|
12890
|
-
* 支持 Electron 平台下通过制定 `
|
|
13096
|
+
* 支持 Electron 平台下通过制定 `chromeMediaSourceId` 的方式获取屏幕共享视频。
|
|
12891
13097
|
* 参考:https://www.electronjs.org/docs/api/desktop-capturer
|
|
12892
13098
|
*/
|
|
12893
13099
|
createScreenVideoTrack(tag = 'screenshare', options) {
|
|
@@ -13095,13 +13301,10 @@
|
|
|
13095
13301
|
return {
|
|
13096
13302
|
room,
|
|
13097
13303
|
code: exports.RCRTCCode.SUCCESS,
|
|
13098
|
-
|
|
13099
|
-
|
|
13100
|
-
|
|
13101
|
-
|
|
13102
|
-
remoteTracks: room.getRemoteTracks(),
|
|
13103
|
-
CDNUris: room.getCDNInfo()
|
|
13104
|
-
}
|
|
13304
|
+
userIds: room.getRemoteUserIds(),
|
|
13305
|
+
RTCTracks: room.getRemoteRTCTracks(),
|
|
13306
|
+
MCUTracks: room.getRemoteMCUTracks(),
|
|
13307
|
+
CDNUris: room.getCDNInfo()
|
|
13105
13308
|
};
|
|
13106
13309
|
});
|
|
13107
13310
|
}
|
|
@@ -13145,7 +13348,7 @@
|
|
|
13145
13348
|
this._crtRoom = crtRoom;
|
|
13146
13349
|
// 重置观众房间
|
|
13147
13350
|
this._crtAudienceLivingRoom = null;
|
|
13148
|
-
return { room: crtRoom, code: exports.RCRTCCode.SUCCESS };
|
|
13351
|
+
return { room: crtRoom, code: exports.RCRTCCode.SUCCESS, userIds: room.getRemoteUserIds(), tracks: crtRoom.getRemoteTracks() };
|
|
13149
13352
|
});
|
|
13150
13353
|
}
|
|
13151
13354
|
/**
|
|
@@ -13176,13 +13379,10 @@
|
|
|
13176
13379
|
return {
|
|
13177
13380
|
room: crtRoom,
|
|
13178
13381
|
code: exports.RCRTCCode.SUCCESS,
|
|
13179
|
-
|
|
13180
|
-
|
|
13181
|
-
|
|
13182
|
-
|
|
13183
|
-
remoteTracks: crtRoom.getRemoteTracks(),
|
|
13184
|
-
CDNUris: crtRoom.getCDNInfo()
|
|
13185
|
-
}
|
|
13382
|
+
userIds: crtRoom.getRemoteUserIds(),
|
|
13383
|
+
RTCTracks: crtRoom.getRemoteRTCTracks(),
|
|
13384
|
+
MCUTracks: crtRoom.getRemoteMCUTracks(),
|
|
13385
|
+
CDNUris: crtRoom.getCDNInfo()
|
|
13186
13386
|
};
|
|
13187
13387
|
});
|
|
13188
13388
|
}
|
|
@@ -13229,9 +13429,9 @@
|
|
|
13229
13429
|
logger.error('Please use the https protocol or use `http://localhost` to open the page!');
|
|
13230
13430
|
return false;
|
|
13231
13431
|
}
|
|
13232
|
-
engine.VersionManage.add('plugin-rtc', "5.3.
|
|
13233
|
-
if (!engine.VersionManage.validEngine("5.1.
|
|
13234
|
-
logger.error(`The current engine version '${engine.VersionManage.getInfo().engine}' error, plugin-rtc required engine version at least '${"5.1.
|
|
13432
|
+
engine.VersionManage.add('plugin-rtc', "5.3.2-alpha.1");
|
|
13433
|
+
if (!engine.VersionManage.validEngine("5.1.2-alpha.1")) {
|
|
13434
|
+
logger.error(`The current engine version '${engine.VersionManage.getInfo().engine}' error, plugin-rtc required engine version at least '${"5.1.2-alpha.1"}'.`);
|
|
13235
13435
|
return false;
|
|
13236
13436
|
}
|
|
13237
13437
|
return true;
|
|
@@ -13239,7 +13439,7 @@
|
|
|
13239
13439
|
setup(context, runtime, options = {}) {
|
|
13240
13440
|
logger.setLogLevel(options.logLevel);
|
|
13241
13441
|
logger.setLogStdout(options.logStdout);
|
|
13242
|
-
logger.warn(`RCRTC Version: ${"5.3.
|
|
13442
|
+
logger.warn(`RCRTC Version: ${"5.3.2-alpha.1"}, Commit: ${"db999e233480c8537357ef17495b0bbb67c692fe"}`);
|
|
13243
13443
|
logger.warn(`browserInfo.browser -> ${browserInfo.browser}`);
|
|
13244
13444
|
logger.warn(`browserInfo.supportsUnifiedPlan -> ${browserInfo.supportsUnifiedPlan}`);
|
|
13245
13445
|
logger.warn(`browserInfo.version -> ${browserInfo.version}`);
|